class Ipv4Path(Path):
    """Represents a way of reaching an VPNv4 destination."""
    ROUTE_FAMILY = RF_IPv4_UC
    VRF_PATH_CLASS = None  # defined in init - anti cyclic import hack
    NLRI_CLASS = IPAddrPrefix

    def __init__(self, *args, **kwargs):
        super(Ipv4Path, self).__init__(*args, **kwargs)
        from ryu.services.protocols.bgp.info_base.vrf4 import Vrf4Path
        self.VRF_PATH_CLASS = Vrf4Path class Ipv4Table(Table):
    """Global table to store IPv4 routing information.

    Uses `IPv4Dest` to store destination information for each known vpnv4
    paths.
    """
    ROUTE_FAMILY = RF_IPv4_UC
    VPN_DEST_CLASS = IPv4Dest

    def __init__(self, core_service, signal_bus):
        super(Ipv4Table, self).__init__(None, core_service, signal_bus)

    def _table_key(self, nlri):
        """Return a key that will uniquely identify this NLRI inside
        this table.
        """
        return nlri.prefix

    def _create_dest(self, nlri):
        return self.VPN_DEST_CLASS(self, nlri)

    def __str__(self):
        return '%s(scope_id: %s, rf: %s)' % (
            self.__class__.__name__, self.scope_id, self.route_family
        ) LOG = logging.getLogger('bgpspeaker.rtconf.vrfs')
ROUTE_DISTINGUISHER = 'route_dist'
IMPORT_RTS = 'import_rts'
EXPORT_RTS = 'export_rts'
VRF_NAME = 'vrf_name'
VRF_DESC = 'vrf_desc'
VRF_RF = 'route_family'
IMPORT_MAPS = 'import_maps'
VRF_RF_IPV6 = 'ipv6'
VRF_RF_IPV4 = 'ipv4'
SUPPORTED_VRF_RF = (VRF_RF_IPV4, VRF_RF_IPV6)
DEFAULT_VRF_NAME = 'no-vrf-name'
DEFAULT_VRF_DESC = 'no-vrf-desc'
    VRF_CHG_EVT = 'vrf_chg_evt'
    VALID_EVT = frozenset([VRF_CHG_EVT])
    REQUIRED_SETTINGS = frozenset([ROUTE_DISTINGUISHER,
                                   IMPORT_RTS,
                                   EXPORT_RTS])
    OPTIONAL_SETTINGS = frozenset(
        [VRF_NAME, MULTI_EXIT_DISC, SITE_OF_ORIGINS, VRF_RF, IMPORT_MAPS]
    )
    ADD_VRF_CONF_EVT, REMOVE_VRF_CONF_EVT = range(2)
    VALID_EVT = frozenset([ADD_VRF_CONF_EVT, REMOVE_VRF_CONF_EVT])
def validate_import_rts(import_rts):
def validate_export_rts(export_rts):
def validate_rd(route_dist):
def validate_vrf_rf(vrf_rf):
    def __init__(self, **kwargs):
    def _init_opt_settings(self, **kwargs):
    def route_dist(self):
    def import_rts(self):
    def export_rts(self):
    def soo_list(self):
    def multi_exit_disc(self):
    def route_family(self):
    def rd_rf_id(self):
    def import_maps(self):
    def create_rd_rf_id(route_dist, route_family):
    def vrf_rf_2_rf(vrf_rf):
    def rf_2_vrf_rf(route_family):
    def settings(self):
    def get_opt_settings(cls):
    def get_req_settings(cls):
    def get_valid_evts(cls):
    def update(self, **kwargs):
    def _update_import_rts(self, **kwargs):
    def _update_export_rts(self, **kwargs):
    def _update_soo_list(self, **kwargs):
    def _update_med(self, **kwargs):
    def _update_importmaps(self, import_maps):
    def __repr__(self):
    def __str__(self):
    def __init__(self):
    def _init_opt_settings(self, **kwargs):
    def vrf_confs(self):
    def vrf_interested_rts(self):
    def update(self, **kwargs):
    def add_vrf_conf(self, vrf_conf):
    def remove_vrf_conf(self, route_dist=None, vrf_id=None,
                        vrf_rf=None):
    def get_vrf_conf(self, route_dist, vrf_rf, vrf_id=None):
    def vrfs_by_rd_rf_id(self):
    def get_valid_evts(self):
    def __repr__(self):
    def settings(self):
    def __init__(self, vrf_conf):
    def on_chg_vrf_conf(self, evt):
    def __init__(self, vrfs_conf):
    def on_add_vrf_conf(self, evt):
    def on_remove_vrf_conf(self, evt):
class VrfConf(ConfWithId, ConfWithStats):
class VrfsConf(BaseConf):
class VrfConfListener(ConfWithIdListener, ConfWithStatsListener):
class VrfsConfListener(BaseConfListener): VRF_RF_IPV4 = 'ipv4' VRF_RF_IPV6 = 'ipv6' BGP_MSG_OPEN = 1
BGP_MSG_UPDATE = 2
BGP_MSG_NOTIFICATION = 3
BGP_MSG_KEEPALIVE = 4
BGP_MSG_ROUTE_REFRESH = 5  # RFC 2918
_VERSION = 4
_MARKER = 16 * b'\xff'
BGP_OPT_CAPABILITY = 2  # RFC 5492
BGP_CAP_MULTIPROTOCOL = 1  # RFC 4760
BGP_CAP_ROUTE_REFRESH = 2  # RFC 2918
BGP_CAP_CARRYING_LABEL_INFO = 4  # RFC 3107
BGP_CAP_GRACEFUL_RESTART = 64  # RFC 4724
BGP_CAP_FOUR_OCTET_AS_NUMBER = 65  # RFC 4893
BGP_CAP_ENHANCED_ROUTE_REFRESH = 70  # https://tools.ietf.org/html/\
BGP_CAP_ROUTE_REFRESH_CISCO = 128  # in cisco routers, there are two\
BGP_ATTR_FLAG_OPTIONAL = 1 << 7
BGP_ATTR_FLAG_TRANSITIVE = 1 << 6
BGP_ATTR_FLAG_PARTIAL = 1 << 5
BGP_ATTR_FLAG_EXTENDED_LENGTH = 1 << 4
BGP_ATTR_TYPE_ORIGIN = 1  # 0,1,2 (1 byte)
BGP_ATTR_TYPE_AS_PATH = 2  # a list of AS_SET/AS_SEQUENCE  eg. {1 2 3} 4 5
BGP_ATTR_TYPE_NEXT_HOP = 3  # an IPv4 address
BGP_ATTR_TYPE_MULTI_EXIT_DISC = 4  # uint32 metric
BGP_ATTR_TYPE_LOCAL_PREF = 5  # uint32
BGP_ATTR_TYPE_ATOMIC_AGGREGATE = 6  # 0 bytes
BGP_ATTR_TYPE_AGGREGATOR = 7  # AS number and IPv4 address
BGP_ATTR_TYPE_COMMUNITIES = 8  # RFC 1997
BGP_ATTR_TYPE_ORIGINATOR_ID = 9  # RFC 4456
BGP_ATTR_TYPE_CLUSTER_LIST = 10  # RFC 4456
BGP_ATTR_TYPE_MP_REACH_NLRI = 14  # RFC 4760
BGP_ATTR_TYPE_MP_UNREACH_NLRI = 15  # RFC 4760
BGP_ATTR_TYPE_EXTENDED_COMMUNITIES = 16  # RFC 4360
BGP_ATTR_TYPE_AS4_PATH = 17  # RFC 4893
BGP_ATTR_TYPE_AS4_AGGREGATOR = 18  # RFC 4893
BGP_ATTR_ORIGIN_IGP = 0x00
BGP_ATTR_ORIGIN_EGP = 0x01
BGP_ATTR_ORIGIN_INCOMPLETE = 0x02
AS_TRANS = 23456  # RFC 4893
BGP_COMMUNITY_NO_EXPORT = 0xffffff01
BGP_COMMUNITY_NO_ADVERTISE = 0xffffff02
BGP_COMMUNITY_NO_EXPORT_SUBCONFED = 0xffffff03
BGP_EXTENDED_COMMUNITY_ROUTE_TARGET = 0x02
BGP_EXTENDED_COMMUNITY_ROUTE_ORIGIN = 0x03
BGP_ERROR_MESSAGE_HEADER_ERROR = 1
BGP_ERROR_OPEN_MESSAGE_ERROR = 2
BGP_ERROR_UPDATE_MESSAGE_ERROR = 3
BGP_ERROR_HOLD_TIMER_EXPIRED = 4
BGP_ERROR_FSM_ERROR = 5
BGP_ERROR_CEASE = 6
BGP_ERROR_SUB_CONNECTION_NOT_SYNCHRONIZED = 1
BGP_ERROR_SUB_BAD_MESSAGE_LENGTH = 2  # Data: the erroneous Length field
BGP_ERROR_SUB_BAD_MESSAGE_TYPE = 3  # Data: the erroneous Type field
BGP_ERROR_SUB_UNSUPPORTED_VERSION_NUMBER = 1  # Data: 2 octet version number
BGP_ERROR_SUB_BAD_PEER_AS = 2
BGP_ERROR_SUB_BAD_BGP_IDENTIFIER = 3
BGP_ERROR_SUB_UNSUPPORTED_OPTIONAL_PARAMETER = 4
BGP_ERROR_SUB_AUTHENTICATION_FAILURE = 5  # deprecated RFC 1771
BGP_ERROR_SUB_UNACCEPTABLE_HOLD_TIME = 6
BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST = 1
BGP_ERROR_SUB_UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE = 2  # Data: type of the attr
BGP_ERROR_SUB_MISSING_WELL_KNOWN_ATTRIBUTE = 3  # Data: ditto
BGP_ERROR_SUB_ATTRIBUTE_FLAGS_ERROR = 4  # Data: the attr (type, len, value)
BGP_ERROR_SUB_ATTRIBUTE_LENGTH_ERROR = 5  # Data: ditto
BGP_ERROR_SUB_INVALID_ORIGIN_ATTRIBUTE = 6  # Data: ditto
BGP_ERROR_SUB_ROUTING_LOOP = 7  # deprecated RFC 1771 AS Routing Loop
BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE = 8  # Data: ditto
BGP_ERROR_SUB_OPTIONAL_ATTRIBUTE_ERROR = 9  # Data: ditto
BGP_ERROR_SUB_INVALID_NETWORK_FIELD = 10
BGP_ERROR_SUB_MALFORMED_AS_PATH = 11
BGP_ERROR_SUB_HOLD_TIMER_EXPIRED = 1
BGP_ERROR_SUB_FSM_ERROR = 1
BGP_ERROR_SUB_MAXIMUM_NUMBER_OF_PREFIXES_REACHED = 1  # Data: optional
BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN = 2
BGP_ERROR_SUB_PEER_DECONFIGURED = 3
BGP_ERROR_SUB_ADMINISTRATIVE_RESET = 4
BGP_ERROR_SUB_CONNECTION_RESET = 5
BGP_ERROR_SUB_OTHER_CONFIGURATION_CHANGE = 6
BGP_ERROR_SUB_CONNECTION_COLLISION_RESOLUTION = 7
BGP_ERROR_SUB_OUT_OF_RESOURCES = 8
    _VALUE_PACK_STR = None
    _VALUE_FIELDS = ['value']
    _TYPES = {}
    _REV_TYPES = None
    _UNKNOWN_TYPE = None
    CODE = 0
    SUB_CODE = 0
    SEND_ERROR = True
    SEND_ERROR = False
    CODE = BGP_ERROR_MESSAGE_HEADER_ERROR
    SUB_CODE = BGP_ERROR_SUB_CONNECTION_NOT_SYNCHRONIZED
    CODE = BGP_ERROR_MESSAGE_HEADER_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_MESSAGE_LENGTH
    CODE = BGP_ERROR_MESSAGE_HEADER_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_MESSAGE_TYPE
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = 0
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNSUPPORTED_VERSION_NUMBER
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_PEER_AS
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_BGP_IDENTIFIER
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNSUPPORTED_OPTIONAL_PARAMETER
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_AUTHENTICATION_FAILURE
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNACCEPTABLE_HOLD_TIME
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_MISSING_WELL_KNOWN_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_ATTRIBUTE_FLAGS_ERROR
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_ATTRIBUTE_LENGTH_ERROR
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_INVALID_ORIGIN_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_ROUTING_LOOP
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_OPTIONAL_ATTRIBUTE_ERROR
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_INVALID_NETWORK_FIELD
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_MALFORMED_AS_PATH
    CODE = BGP_ERROR_HOLD_TIMER_EXPIRED
    SUB_CODE = BGP_ERROR_SUB_HOLD_TIMER_EXPIRED
    CODE = BGP_ERROR_FSM_ERROR
    SUB_CODE = BGP_ERROR_SUB_FSM_ERROR
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_MAXIMUM_NUMBER_OF_PREFIXES_REACHED
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_PEER_DECONFIGURED
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_ADMINISTRATIVE_RESET
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_CONNECTION_RESET
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_OTHER_CONFIGURATION_CHANGE
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_CONNECTION_COLLISION_RESOLUTION
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_OUT_OF_RESOURCES
RF_RTC_UC = RouteFamily(addr_family.IP,
                        subaddr_family.ROUTE_TARGET_CONSTRTAINS)
    _PACK_STR = '!H'
    TWO_OCTET_AS = 0
    IPV4_ADDRESS = 1
    FOUR_OCTET_AS = 2
    _VALUE_PACK_STR = '!HI'
    _VALUE_FIELDS = ['admin', 'assigned']
    _VALUE_PACK_STR = '!4sH'
    _VALUE_FIELDS = ['admin', 'assigned']
    _TYPE = {
        'ascii': [
            'admin'
        ]
    }
    _VALUE_PACK_STR = '!IH'
    _VALUE_FIELDS = ['admin', 'assigned']
    _PACK_STR = '!B'  # length
    _LABEL_PACK_STR = '!3B'
    _WITHDRAW_LABEL = 0x800000
    _RD_PACK_STR = '!Q'
    ROUTE_FAMILY = RF_IPv4_UC
    _TYPE = {
        'ascii': [
            'addr'
        ]
    }
    ROUTE_FAMILY = RF_IPv6_UC
    _TYPE = {
        'ascii': [
            'addr'
        ]
    }
    ROUTE_FAMILY = RF_IPv4_MPLS
    ROUTE_FAMILY = RF_IPv6_MPLS
    ROUTE_FAMILY = RF_IPv4_VPN
    ROUTE_FAMILY = RF_IPv6_VPN
    ROUTE_FAMILY = RF_RTC_UC
    DEFAULT_AS = '0:0'
    DEFAULT_RT = '0:0'
_ADDR_CLASSES = {
    _addr_class_key(RF_IPv4_UC): IPAddrPrefix,
    _addr_class_key(RF_IPv6_UC): IP6AddrPrefix,
    _addr_class_key(RF_IPv4_MPLS): LabelledIPAddrPrefix,
    _addr_class_key(RF_IPv6_MPLS): LabelledIP6AddrPrefix,
    _addr_class_key(RF_IPv4_VPN): LabelledVPNIPAddrPrefix,
    _addr_class_key(RF_IPv6_VPN): LabelledVPNIP6AddrPrefix,
    _addr_class_key(RF_RTC_UC): RouteTargetMembershipNLRI,
}
    _PACK_STR = '!BB'  # type, length
    _CAP_HDR_PACK_STR = '!BB'
    _CAP_PACK_STR = "!H"
    _CAP_PACK_STR = '!I'
    _CAP_PACK_STR = '!HBB'  # afi, reserved, safi
    _PACK_STR = '!BB'  # flags, type
    _PACK_STR_LEN = '!B'  # length
    _PACK_STR_EXT_LEN = '!H'  # length w/ BGP_ATTR_FLAG_EXTENDED_LENGTH
    _ATTR_FLAGS = None
    _VALUE_PACK_STR = '!I'
    _VALUE_PACK_STR = '!B'
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _AS_SET = 1
    _AS_SEQUENCE = 2
    _SEG_HDR_PACK_STR = '!BB'
    _AS_PACK_STR = None
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _AS_PACK_STR = '!H'
    _AS_PACK_STR = '!I'
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE | BGP_ATTR_FLAG_OPTIONAL
    _VALUE_PACK_STR = '!4s'
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _TYPE = {
        'ascii': [
            'value'
        ]
    }
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _VALUE_PACK_STR = None
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE
    _TYPE = {
        'ascii': [
            'addr'
        ]
    }
    _VALUE_PACK_STR = '!H4s'
    _VALUE_PACK_STR = '!I4s'
    _VALUE_PACK_STR = '!I'
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE
    NO_EXPORT = int('0xFFFFFF01', 16)
    NO_ADVERTISE = int('0xFFFFFF02', 16)
    NO_EXPORT_SUBCONFED = int('0xFFFFFF03', 16)
    WELL_KNOW_COMMUNITIES = (NO_EXPORT, NO_ADVERTISE, NO_EXPORT_SUBCONFED)
    _VALUE_PACK_STR = '!4s'
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _TYPE = {
        'ascii': [
            'value'
        ]
    }
    _VALUE_PACK_STR = '!4s'
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _TYPE = {
        'ascii': [
            'value'
        ]
    }
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE
    _PACK_STR = '!B7s'  # type high (+ type low) + value
    IANA_AUTHORITY = 0x80
    TRANSITIVE = 0x40
    _TYPE_HIGH_MASK = ~TRANSITIVE
    TWO_OCTET_AS_SPECIFIC = 0x00
    IPV4_ADDRESS_SPECIFIC = 0x01
    FOUR_OCTET_AS_SPECIFIC = 0x02
    OPAQUE = 0x03
    _VALUE_PACK_STR = '!BHI'  # sub type, as number, local adm
    _VALUE_FIELDS = ['subtype', 'as_number', 'local_administrator']
    _VALUE_PACK_STR = '!B4sH'  # sub type, IPv4 address, local adm
    _VALUE_FIELDS = ['subtype', 'ipv4_address', 'local_administrator']
    _TYPE = {
        'ascii': [
            'ipv4_address'
        ]
    }
    _VALUE_PACK_STR = '!BIH'  # sub type, as number, local adm
    _VALUE_FIELDS = ['subtype', 'as_number', 'local_administrator']
    _VALUE_PACK_STR = '!7s'  # opaque value
    _VALUE_FIELDS = ['opaque']
    _VALUE_PACK_STR = '!7s'  # opaque value
    _VALUE_PACK_STR = '!HBB'  # afi, safi, next hop len
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _TYPE = {
        'ascii': [
            'next_hop'
        ]
    }
    _VALUE_PACK_STR = '!HB'  # afi, safi
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _HDR_PACK_STR = '!16sHB'  # marker, len, type
    _HDR_LEN = struct.calcsize(_HDR_PACK_STR)
    _PACK_STR = '!BHH4sB'
    _MIN_LEN = BGPMessage._HDR_LEN + struct.calcsize(_PACK_STR)
    _TYPE = {
        'ascii': [
            'bgp_identifier'
        ]
    }
    _MIN_LEN = BGPMessage._HDR_LEN
    _MIN_LEN = BGPMessage._HDR_LEN
    _PACK_STR = '!BB'
    _MIN_LEN = BGPMessage._HDR_LEN + struct.calcsize(_PACK_STR)
    _REASONS = {
        (1, 1): 'Message Header Error: not synchronised',
        (1, 2): 'Message Header Error: bad message len',
        (1, 3): 'Message Header Error: bad message type',
        (2, 1): 'Open Message Error: unsupported version',
        (2, 2): 'Open Message Error: bad peer AS',
        (2, 3): 'Open Message Error: bad BGP identifier',
        (2, 4): 'Open Message Error: unsupported optional param',
        (2, 5): 'Open Message Error: authentication failure',
        (2, 6): 'Open Message Error: unacceptable hold time',
        (2, 7): 'Open Message Error: Unsupported Capability',
        (2, 8): 'Open Message Error: Unassigned',
        (3, 1): 'Update Message Error: malformed attribute list',
        (3, 2): 'Update Message Error: unrecognized well-known attr',
        (3, 3): 'Update Message Error: missing well-known attr',
        (3, 4): 'Update Message Error: attribute flags error',
        (3, 5): 'Update Message Error: attribute length error',
        (3, 6): 'Update Message Error: invalid origin attr',
        (3, 7): 'Update Message Error: as routing loop',
        (3, 8): 'Update Message Error: invalid next hop attr',
        (3, 9): 'Update Message Error: optional attribute error',
        (3, 10): 'Update Message Error: invalid network field',
        (3, 11): 'Update Message Error: malformed AS_PATH',
        (4, 1): 'Hold Timer Expired',
        (5, 1): 'Finite State Machine Error',
        (6, 1): 'Cease: Maximum Number of Prefixes Reached',
        (6, 2): 'Cease: Administrative Shutdown',
        (6, 3): 'Cease: Peer De-configured',
        (6, 4): 'Cease: Administrative Reset',
        (6, 5): 'Cease: Connection Rejected',
        (6, 6): 'Cease: Other Configuration Change',
        (6, 7): 'Cease: Connection Collision Resolution',
        (6, 8): 'Cease: Out of Resources',
    }
    _PACK_STR = '!HBB'
    _MIN_LEN = BGPMessage._HDR_LEN + struct.calcsize(_PACK_STR)
class _Value(object):
class _TypeDisp(object):
class BgpExc(Exception):
class BadNotification(BgpExc):
class NotSync(BgpExc):
class BadLen(BgpExc):
class BadMsg(BgpExc):
class MalformedOptionalParam(BgpExc):
class UnsupportedVersion(BgpExc):
class BadPeerAs(BgpExc):
class BadBgpId(BgpExc):
class UnsupportedOptParam(BgpExc):
class AuthFailure(BgpExc):
class UnacceptableHoldTime(BgpExc):
class MalformedAttrList(BgpExc):
class UnRegWellKnowAttr(BgpExc):
class MissingWellKnown(BgpExc):
class AttrFlagError(BgpExc):
class AttrLenError(BgpExc):
class InvalidOriginError(BgpExc):
class RoutingLoop(BgpExc):
class InvalidNextHop(BgpExc):
class OptAttrError(BgpExc):
class InvalidNetworkField(BgpExc):
class MalformedAsPath(BgpExc):
class HoldTimerExpired(BgpExc):
class FiniteStateMachineError(BgpExc):
class MaxPrefixReached(BgpExc):
class AdminShutdown(BgpExc):
class PeerDeConfig(BgpExc):
class AdminReset(BgpExc):
class ConnRejected(BgpExc):
class OtherConfChange(BgpExc):
class CollisionResolution(BgpExc):
class OutOfResource(BgpExc):
class RouteFamily(StringifyMixin):
class _RouteDistinguisher(StringifyMixin, _TypeDisp, _Value):
class BGPTwoOctetAsRD(_RouteDistinguisher):
class BGPIPv4AddressRD(_RouteDistinguisher):
class BGPFourOctetAsRD(_RouteDistinguisher):
class _AddrPrefix(StringifyMixin):
class _BinAddrPrefix(_AddrPrefix):
class _LabelledAddrPrefix(_AddrPrefix):
class _UnlabelledAddrPrefix(_AddrPrefix):
class _IPAddrPrefix(_AddrPrefix):
class _IP6AddrPrefix(_AddrPrefix):
class _VPNAddrPrefix(_AddrPrefix):
class IPAddrPrefix(_UnlabelledAddrPrefix, _IPAddrPrefix):
class IP6AddrPrefix(_UnlabelledAddrPrefix, _IP6AddrPrefix):
class LabelledIPAddrPrefix(_LabelledAddrPrefix, _IPAddrPrefix):
class LabelledIP6AddrPrefix(_LabelledAddrPrefix, _IP6AddrPrefix):
class LabelledVPNIPAddrPrefix(_LabelledAddrPrefix, _VPNAddrPrefix,
                              _IPAddrPrefix):
class LabelledVPNIP6AddrPrefix(_LabelledAddrPrefix, _VPNAddrPrefix,
                               _IP6AddrPrefix):
class RouteTargetMembershipNLRI(StringifyMixin):
class _OptParam(StringifyMixin, _TypeDisp, _Value):
class BGPOptParamUnknown(_OptParam):
class _OptParamCapability(_OptParam, _TypeDisp):
class _OptParamEmptyCapability(_OptParamCapability):
class BGPOptParamCapabilityUnknown(_OptParamCapability):
class BGPOptParamCapabilityRouteRefresh(_OptParamEmptyCapability):
class BGPOptParamCapabilityCiscoRouteRefresh(_OptParamEmptyCapability):
class BGPOptParamCapabilityEnhancedRouteRefresh(_OptParamEmptyCapability):
class BGPOptParamCapabilityGracefulRestart(_OptParamCapability):
class BGPOptParamCapabilityFourOctetAsNumber(_OptParamCapability):
class BGPOptParamCapabilityMultiprotocol(_OptParamCapability):
class BGPOptParamCapabilityCarryingLabelInfo(_OptParamEmptyCapability):
class BGPWithdrawnRoute(IPAddrPrefix):
class _PathAttribute(StringifyMixin, _TypeDisp, _Value):
class BGPPathAttributeUnknown(_PathAttribute):
class _PathAttributeUint32(_PathAttribute):
class BGPPathAttributeOrigin(_PathAttribute):
class _BGPPathAttributeAsPathCommon(_PathAttribute):
class BGPPathAttributeAsPath(_BGPPathAttributeAsPathCommon):
class BGPPathAttributeAs4Path(_BGPPathAttributeAsPathCommon):
class BGPPathAttributeNextHop(_PathAttribute):
class BGPPathAttributeMultiExitDisc(_PathAttributeUint32):
class BGPPathAttributeLocalPref(_PathAttributeUint32):
class BGPPathAttributeAtomicAggregate(_PathAttribute):
class _BGPPathAttributeAggregatorCommon(_PathAttribute):
class BGPPathAttributeAggregator(_BGPPathAttributeAggregatorCommon):
class BGPPathAttributeAs4Aggregator(_BGPPathAttributeAggregatorCommon):
class BGPPathAttributeCommunities(_PathAttribute):
class BGPPathAttributeOriginatorId(_PathAttribute):
class BGPPathAttributeClusterList(_PathAttribute):
class BGPPathAttributeExtendedCommunities(_PathAttribute):
class _ExtendedCommunity(StringifyMixin, _TypeDisp, _Value):
class BGPTwoOctetAsSpecificExtendedCommunity(_ExtendedCommunity):
class BGPIPv4AddressSpecificExtendedCommunity(_ExtendedCommunity):
class BGPFourOctetAsSpecificExtendedCommunity(_ExtendedCommunity):
class BGPOpaqueExtendedCommunity(_ExtendedCommunity):
class BGPUnknownExtendedCommunity(_ExtendedCommunity):
class BGPPathAttributeMpReachNLRI(_PathAttribute):
class BGPPathAttributeMpUnreachNLRI(_PathAttribute):
class BGPNLRI(IPAddrPrefix):
class BGPMessage(packet_base.PacketBase, _TypeDisp):
class BGPOpen(BGPMessage):
class BGPUpdate(BGPMessage):
class BGPKeepAlive(BGPMessage):
class BGPNotification(BGPMessage):
class BGPRouteRefresh(BGPMessage):
class StreamParser(stream_parser.StreamParser):
    def do_init(cls, self, kwargs, **extra_kwargs):
    def parse_value(cls, buf):
    def serialize_value(self):
    def register_unknown_type(cls):
        def _register_type(subcls):
    def register_type(cls, type_):
        def _register_type(subcls):
    def _lookup_type(cls, type_):
    def _rev_lookup_type(cls, targ_cls):
    def __init__(self, data=''):
    def __str__(self):
    def __init__(self, msg_type_code, message_length):
    def __str__(self):
    def __init__(self, msg_type):
    def __str__(self):
    def __init__(self, locally_support_version):
    def __init__(self, pattr_type_code):
    def __init__(self, afi, safi):
    def __cmp__(self, other):
def get_rf(afi, safi):
def pad(bin, len_):
    def __init__(self, type_, admin=0, assigned=0):
    def parser(cls, buf):
    def from_str(cls, str_):
    def serialize(self):
    def formatted_str(self):
    def __init__(self, type_=_RouteDistinguisher.TWO_OCTET_AS, **kwargs):
    def __init__(self, type_=_RouteDistinguisher.IPV4_ADDRESS, **kwargs):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, type_=_RouteDistinguisher.FOUR_OCTET_AS,
                 **kwargs):
    def __init__(self, length, addr, prefixes=None):
    def _to_bin(addr):
    def _from_bin(addr):
    def parser(cls, buf):
    def serialize(self):
    def _to_bin(addr):
    def _from_bin(addr):
    def __init__(self, length, addr, labels=[], **kwargs):
    def _label_to_bin(cls, label):
    def _label_from_bin(cls, bin):
    def _to_bin(cls, addr):
    def _has_no_label(cls, bin_):
    def _from_bin(cls, addr):
    def _to_bin(cls, addr):
    def _from_bin(cls, binaddr):
    def _prefix_to_bin(addr):
    def _prefix_from_bin(addr):
    def _prefix_to_bin(addr):
    def _prefix_from_bin(addr):
    def __init__(self, length, addr, prefixes=(), route_dist=0):
    def _prefix_to_bin(cls, addr):
    def _prefix_from_bin(cls, binaddr):
    def prefix(self):
    def formatted_nlri_str(self):
    def prefix(self):
    def formatted_nlri_str(self):
    def prefix(self):
    def route_dist(self):
    def label_list(self):
    def formatted_nlri_str(self):
    def prefix(self):
    def route_dist(self):
    def label_list(self):
    def formatted_nlri_str(self):
    def __init__(self, origin_as, route_target):
    def _is_valid_old_asn(self, asn):
    def _is_valid_ext_comm_attr(self, attr):
    def formatted_nlri_str(self):
    def is_default_rtnlri(self):
    def __cmp__(self, other):
    def parser(cls, buf):
    def serialize(self):
def _get_addr_class(afi, safi):
    def __init__(self, type_, value=None, length=None):
    def parser(cls, buf):
    def serialize(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, cap_code=None, cap_value=None, cap_length=None,
                 type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, flags, time, tuples, **kwargs):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, as_number, **kwargs):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, afi, safi, reserved=0, **kwargs):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, value=None, flags=0, type_=None, length=None):
    def parser(cls, buf):
    def serialize(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, value, as_pack_str=None, flags=0, type_=None,
                 length=None):
    def path_seg_list(self):
    def get_as_path_len(self):
    def has_local_as(self, local_as):
    def has_matching_leftmost(self, remote_as):
    def _is_valid_16bit_as_path(cls, buf):
    def parse_value(cls, buf):
    def serialize_value(self):
    def _is_valid_16bit_as_path(cls, buf):
    def parse_value(cls, buf):
    def serialize_value(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, as_number, addr, flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, communities,
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def is_no_export(comm_attr):
    def is_no_advertise(comm_attr):
    def is_no_export_subconfed(comm_attr):
    def has_comm_attr(self, attr):
    def parse_value(cls, buf):
    def serialize_value(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, communities,
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def _community_list(self, subtype):
    def rt_list(self):
    def soo_list(self):
    def __init__(self, type_):
    def parse(cls, buf):
    def serialize(self):
    def __init__(self, type_=_ExtendedCommunity.TWO_OCTET_AS_SPECIFIC,
                 **kwargs):
    def __init__(self, type_=_ExtendedCommunity.IPV4_ADDRESS_SPECIFIC,
                 **kwargs):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, type_=_ExtendedCommunity.FOUR_OCTET_AS_SPECIFIC,
                 **kwargs):
    def __init__(self, type_=_ExtendedCommunity.OPAQUE,
                 **kwargs):
    def __init__(self, **kwargs):
    def __init__(self, afi, safi, next_hop, nlri,
                 next_hop_len=0, reserved='\0',
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def route_family(self):
    def __init__(self, afi, safi, withdrawn_routes,
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def route_family(self):
    def __init__(self, type_, len_=None, marker=None):
    def parser(cls, buf):
    def serialize(self):
    def __len__(self):
    def __init__(self, my_as, bgp_identifier, type_=BGP_MSG_OPEN,
                 opt_param_len=0, opt_param=[],
                 version=_VERSION, hold_time=0, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def __init__(self, type_=BGP_MSG_UPDATE,
                 withdrawn_routes_len=None,
                 withdrawn_routes=[],
                 total_path_attribute_len=None,
                 path_attributes=[],
                 nlri=[],
                 len_=None, marker=None):
    def pathattr_map(self):
    def get_path_attr(self, attr_name):
    def parser(cls, buf):
    def serialize_tail(self):
    def __init__(self, type_=BGP_MSG_KEEPALIVE, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def __init__(self,
                 error_code,
                 error_subcode,
                 data='',
                 type_=BGP_MSG_NOTIFICATION, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def reason(self):
    def __init__(self,
                 afi, safi, demarcation=0,
                 type_=BGP_MSG_ROUTE_REFRESH, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def try_parse(self, data): BGP_MSG_OPEN = 1
BGP_MSG_UPDATE = 2
BGP_MSG_NOTIFICATION = 3
BGP_MSG_KEEPALIVE = 4
BGP_MSG_ROUTE_REFRESH = 5  # RFC 2918
_VERSION = 4
_MARKER = 16 * b'\xff'
BGP_OPT_CAPABILITY = 2  # RFC 5492
BGP_CAP_MULTIPROTOCOL = 1  # RFC 4760
BGP_CAP_ROUTE_REFRESH = 2  # RFC 2918
BGP_CAP_CARRYING_LABEL_INFO = 4  # RFC 3107
BGP_CAP_GRACEFUL_RESTART = 64  # RFC 4724
BGP_CAP_FOUR_OCTET_AS_NUMBER = 65  # RFC 4893
BGP_CAP_ENHANCED_ROUTE_REFRESH = 70  # https://tools.ietf.org/html/\
BGP_CAP_ROUTE_REFRESH_CISCO = 128  # in cisco routers, there are two\
BGP_ATTR_FLAG_OPTIONAL = 1 << 7
BGP_ATTR_FLAG_TRANSITIVE = 1 << 6
BGP_ATTR_FLAG_PARTIAL = 1 << 5
BGP_ATTR_FLAG_EXTENDED_LENGTH = 1 << 4
BGP_ATTR_TYPE_ORIGIN = 1  # 0,1,2 (1 byte)
BGP_ATTR_TYPE_AS_PATH = 2  # a list of AS_SET/AS_SEQUENCE  eg. {1 2 3} 4 5
BGP_ATTR_TYPE_NEXT_HOP = 3  # an IPv4 address
BGP_ATTR_TYPE_MULTI_EXIT_DISC = 4  # uint32 metric
BGP_ATTR_TYPE_LOCAL_PREF = 5  # uint32
BGP_ATTR_TYPE_ATOMIC_AGGREGATE = 6  # 0 bytes
BGP_ATTR_TYPE_AGGREGATOR = 7  # AS number and IPv4 address
BGP_ATTR_TYPE_COMMUNITIES = 8  # RFC 1997
BGP_ATTR_TYPE_ORIGINATOR_ID = 9  # RFC 4456
BGP_ATTR_TYPE_CLUSTER_LIST = 10  # RFC 4456
BGP_ATTR_TYPE_MP_REACH_NLRI = 14  # RFC 4760
BGP_ATTR_TYPE_MP_UNREACH_NLRI = 15  # RFC 4760
BGP_ATTR_TYPE_EXTENDED_COMMUNITIES = 16  # RFC 4360
BGP_ATTR_TYPE_AS4_PATH = 17  # RFC 4893
BGP_ATTR_TYPE_AS4_AGGREGATOR = 18  # RFC 4893
BGP_ATTR_ORIGIN_IGP = 0x00
BGP_ATTR_ORIGIN_EGP = 0x01
BGP_ATTR_ORIGIN_INCOMPLETE = 0x02
AS_TRANS = 23456  # RFC 4893
BGP_COMMUNITY_NO_EXPORT = 0xffffff01
BGP_COMMUNITY_NO_ADVERTISE = 0xffffff02
BGP_COMMUNITY_NO_EXPORT_SUBCONFED = 0xffffff03
BGP_EXTENDED_COMMUNITY_ROUTE_TARGET = 0x02
BGP_EXTENDED_COMMUNITY_ROUTE_ORIGIN = 0x03
BGP_ERROR_MESSAGE_HEADER_ERROR = 1
BGP_ERROR_OPEN_MESSAGE_ERROR = 2
BGP_ERROR_UPDATE_MESSAGE_ERROR = 3
BGP_ERROR_HOLD_TIMER_EXPIRED = 4
BGP_ERROR_FSM_ERROR = 5
BGP_ERROR_CEASE = 6
BGP_ERROR_SUB_CONNECTION_NOT_SYNCHRONIZED = 1
BGP_ERROR_SUB_BAD_MESSAGE_LENGTH = 2  # Data: the erroneous Length field
BGP_ERROR_SUB_BAD_MESSAGE_TYPE = 3  # Data: the erroneous Type field
BGP_ERROR_SUB_UNSUPPORTED_VERSION_NUMBER = 1  # Data: 2 octet version number
BGP_ERROR_SUB_BAD_PEER_AS = 2
BGP_ERROR_SUB_BAD_BGP_IDENTIFIER = 3
BGP_ERROR_SUB_UNSUPPORTED_OPTIONAL_PARAMETER = 4
BGP_ERROR_SUB_AUTHENTICATION_FAILURE = 5  # deprecated RFC 1771
BGP_ERROR_SUB_UNACCEPTABLE_HOLD_TIME = 6
BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST = 1
BGP_ERROR_SUB_UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE = 2  # Data: type of the attr
BGP_ERROR_SUB_MISSING_WELL_KNOWN_ATTRIBUTE = 3  # Data: ditto
BGP_ERROR_SUB_ATTRIBUTE_FLAGS_ERROR = 4  # Data: the attr (type, len, value)
BGP_ERROR_SUB_ATTRIBUTE_LENGTH_ERROR = 5  # Data: ditto
BGP_ERROR_SUB_INVALID_ORIGIN_ATTRIBUTE = 6  # Data: ditto
BGP_ERROR_SUB_ROUTING_LOOP = 7  # deprecated RFC 1771 AS Routing Loop
BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE = 8  # Data: ditto
BGP_ERROR_SUB_OPTIONAL_ATTRIBUTE_ERROR = 9  # Data: ditto
BGP_ERROR_SUB_INVALID_NETWORK_FIELD = 10
BGP_ERROR_SUB_MALFORMED_AS_PATH = 11
BGP_ERROR_SUB_HOLD_TIMER_EXPIRED = 1
BGP_ERROR_SUB_FSM_ERROR = 1
BGP_ERROR_SUB_MAXIMUM_NUMBER_OF_PREFIXES_REACHED = 1  # Data: optional
BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN = 2
BGP_ERROR_SUB_PEER_DECONFIGURED = 3
BGP_ERROR_SUB_ADMINISTRATIVE_RESET = 4
BGP_ERROR_SUB_CONNECTION_RESET = 5
BGP_ERROR_SUB_OTHER_CONFIGURATION_CHANGE = 6
BGP_ERROR_SUB_CONNECTION_COLLISION_RESOLUTION = 7
BGP_ERROR_SUB_OUT_OF_RESOURCES = 8
    _VALUE_PACK_STR = None
    _VALUE_FIELDS = ['value']
    _TYPES = {}
    _REV_TYPES = None
    _UNKNOWN_TYPE = None
    CODE = 0
    SUB_CODE = 0
    SEND_ERROR = True
    SEND_ERROR = False
    CODE = BGP_ERROR_MESSAGE_HEADER_ERROR
    SUB_CODE = BGP_ERROR_SUB_CONNECTION_NOT_SYNCHRONIZED
    CODE = BGP_ERROR_MESSAGE_HEADER_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_MESSAGE_LENGTH
    CODE = BGP_ERROR_MESSAGE_HEADER_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_MESSAGE_TYPE
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = 0
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNSUPPORTED_VERSION_NUMBER
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_PEER_AS
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_BGP_IDENTIFIER
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNSUPPORTED_OPTIONAL_PARAMETER
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_AUTHENTICATION_FAILURE
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNACCEPTABLE_HOLD_TIME
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_MISSING_WELL_KNOWN_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_ATTRIBUTE_FLAGS_ERROR
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_ATTRIBUTE_LENGTH_ERROR
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_INVALID_ORIGIN_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_ROUTING_LOOP
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_OPTIONAL_ATTRIBUTE_ERROR
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_INVALID_NETWORK_FIELD
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_MALFORMED_AS_PATH
    CODE = BGP_ERROR_HOLD_TIMER_EXPIRED
    SUB_CODE = BGP_ERROR_SUB_HOLD_TIMER_EXPIRED
    CODE = BGP_ERROR_FSM_ERROR
    SUB_CODE = BGP_ERROR_SUB_FSM_ERROR
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_MAXIMUM_NUMBER_OF_PREFIXES_REACHED
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_PEER_DECONFIGURED
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_ADMINISTRATIVE_RESET
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_CONNECTION_RESET
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_OTHER_CONFIGURATION_CHANGE
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_CONNECTION_COLLISION_RESOLUTION
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_OUT_OF_RESOURCES
RF_RTC_UC = RouteFamily(addr_family.IP,
                        subaddr_family.ROUTE_TARGET_CONSTRTAINS)
    _PACK_STR = '!H'
    TWO_OCTET_AS = 0
    IPV4_ADDRESS = 1
    FOUR_OCTET_AS = 2
    _VALUE_PACK_STR = '!HI'
    _VALUE_FIELDS = ['admin', 'assigned']
    _VALUE_PACK_STR = '!4sH'
    _VALUE_FIELDS = ['admin', 'assigned']
    _TYPE = {
        'ascii': [
            'admin'
        ]
    }
    _VALUE_PACK_STR = '!IH'
    _VALUE_FIELDS = ['admin', 'assigned']
    _PACK_STR = '!B'  # length
    _LABEL_PACK_STR = '!3B'
    _WITHDRAW_LABEL = 0x800000
    _RD_PACK_STR = '!Q'
    ROUTE_FAMILY = RF_IPv4_UC
    _TYPE = {
        'ascii': [
            'addr'
        ]
    }
    ROUTE_FAMILY = RF_IPv6_UC
    _TYPE = {
        'ascii': [
            'addr'
        ]
    }
    ROUTE_FAMILY = RF_IPv4_MPLS
    ROUTE_FAMILY = RF_IPv6_MPLS
    ROUTE_FAMILY = RF_IPv4_VPN
    ROUTE_FAMILY = RF_IPv6_VPN
    ROUTE_FAMILY = RF_RTC_UC
    DEFAULT_AS = '0:0'
    DEFAULT_RT = '0:0'
_ADDR_CLASSES = {
    _addr_class_key(RF_IPv4_UC): IPAddrPrefix,
    _addr_class_key(RF_IPv6_UC): IP6AddrPrefix,
    _addr_class_key(RF_IPv4_MPLS): LabelledIPAddrPrefix,
    _addr_class_key(RF_IPv6_MPLS): LabelledIP6AddrPrefix,
    _addr_class_key(RF_IPv4_VPN): LabelledVPNIPAddrPrefix,
    _addr_class_key(RF_IPv6_VPN): LabelledVPNIP6AddrPrefix,
    _addr_class_key(RF_RTC_UC): RouteTargetMembershipNLRI,
}
    _PACK_STR = '!BB'  # type, length
    _CAP_HDR_PACK_STR = '!BB'
    _CAP_PACK_STR = "!H"
    _CAP_PACK_STR = '!I'
    _CAP_PACK_STR = '!HBB'  # afi, reserved, safi
    _PACK_STR = '!BB'  # flags, type
    _PACK_STR_LEN = '!B'  # length
    _PACK_STR_EXT_LEN = '!H'  # length w/ BGP_ATTR_FLAG_EXTENDED_LENGTH
    _ATTR_FLAGS = None
    _VALUE_PACK_STR = '!I'
    _VALUE_PACK_STR = '!B'
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _AS_SET = 1
    _AS_SEQUENCE = 2
    _SEG_HDR_PACK_STR = '!BB'
    _AS_PACK_STR = None
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _AS_PACK_STR = '!H'
    _AS_PACK_STR = '!I'
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE | BGP_ATTR_FLAG_OPTIONAL
    _VALUE_PACK_STR = '!4s'
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _TYPE = {
        'ascii': [
            'value'
        ]
    }
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _VALUE_PACK_STR = None
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE
    _TYPE = {
        'ascii': [
            'addr'
        ]
    }
    _VALUE_PACK_STR = '!H4s'
    _VALUE_PACK_STR = '!I4s'
    _VALUE_PACK_STR = '!I'
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE
    NO_EXPORT = int('0xFFFFFF01', 16)
    NO_ADVERTISE = int('0xFFFFFF02', 16)
    NO_EXPORT_SUBCONFED = int('0xFFFFFF03', 16)
    WELL_KNOW_COMMUNITIES = (NO_EXPORT, NO_ADVERTISE, NO_EXPORT_SUBCONFED)
    _VALUE_PACK_STR = '!4s'
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _TYPE = {
        'ascii': [
            'value'
        ]
    }
    _VALUE_PACK_STR = '!4s'
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _TYPE = {
        'ascii': [
            'value'
        ]
    }
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE
    _PACK_STR = '!B7s'  # type high (+ type low) + value
    IANA_AUTHORITY = 0x80
    TRANSITIVE = 0x40
    _TYPE_HIGH_MASK = ~TRANSITIVE
    TWO_OCTET_AS_SPECIFIC = 0x00
    IPV4_ADDRESS_SPECIFIC = 0x01
    FOUR_OCTET_AS_SPECIFIC = 0x02
    OPAQUE = 0x03
    _VALUE_PACK_STR = '!BHI'  # sub type, as number, local adm
    _VALUE_FIELDS = ['subtype', 'as_number', 'local_administrator']
    _VALUE_PACK_STR = '!B4sH'  # sub type, IPv4 address, local adm
    _VALUE_FIELDS = ['subtype', 'ipv4_address', 'local_administrator']
    _TYPE = {
        'ascii': [
            'ipv4_address'
        ]
    }
    _VALUE_PACK_STR = '!BIH'  # sub type, as number, local adm
    _VALUE_FIELDS = ['subtype', 'as_number', 'local_administrator']
    _VALUE_PACK_STR = '!7s'  # opaque value
    _VALUE_FIELDS = ['opaque']
    _VALUE_PACK_STR = '!7s'  # opaque value
    _VALUE_PACK_STR = '!HBB'  # afi, safi, next hop len
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _TYPE = {
        'ascii': [
            'next_hop'
        ]
    }
    _VALUE_PACK_STR = '!HB'  # afi, safi
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _HDR_PACK_STR = '!16sHB'  # marker, len, type
    _HDR_LEN = struct.calcsize(_HDR_PACK_STR)
    _PACK_STR = '!BHH4sB'
    _MIN_LEN = BGPMessage._HDR_LEN + struct.calcsize(_PACK_STR)
    _TYPE = {
        'ascii': [
            'bgp_identifier'
        ]
    }
    _MIN_LEN = BGPMessage._HDR_LEN
    _MIN_LEN = BGPMessage._HDR_LEN
    _PACK_STR = '!BB'
    _MIN_LEN = BGPMessage._HDR_LEN + struct.calcsize(_PACK_STR)
    _REASONS = {
        (1, 1): 'Message Header Error: not synchronised',
        (1, 2): 'Message Header Error: bad message len',
        (1, 3): 'Message Header Error: bad message type',
        (2, 1): 'Open Message Error: unsupported version',
        (2, 2): 'Open Message Error: bad peer AS',
        (2, 3): 'Open Message Error: bad BGP identifier',
        (2, 4): 'Open Message Error: unsupported optional param',
        (2, 5): 'Open Message Error: authentication failure',
        (2, 6): 'Open Message Error: unacceptable hold time',
        (2, 7): 'Open Message Error: Unsupported Capability',
        (2, 8): 'Open Message Error: Unassigned',
        (3, 1): 'Update Message Error: malformed attribute list',
        (3, 2): 'Update Message Error: unrecognized well-known attr',
        (3, 3): 'Update Message Error: missing well-known attr',
        (3, 4): 'Update Message Error: attribute flags error',
        (3, 5): 'Update Message Error: attribute length error',
        (3, 6): 'Update Message Error: invalid origin attr',
        (3, 7): 'Update Message Error: as routing loop',
        (3, 8): 'Update Message Error: invalid next hop attr',
        (3, 9): 'Update Message Error: optional attribute error',
        (3, 10): 'Update Message Error: invalid network field',
        (3, 11): 'Update Message Error: malformed AS_PATH',
        (4, 1): 'Hold Timer Expired',
        (5, 1): 'Finite State Machine Error',
        (6, 1): 'Cease: Maximum Number of Prefixes Reached',
        (6, 2): 'Cease: Administrative Shutdown',
        (6, 3): 'Cease: Peer De-configured',
        (6, 4): 'Cease: Administrative Reset',
        (6, 5): 'Cease: Connection Rejected',
        (6, 6): 'Cease: Other Configuration Change',
        (6, 7): 'Cease: Connection Collision Resolution',
        (6, 8): 'Cease: Out of Resources',
    }
    _PACK_STR = '!HBB'
    _MIN_LEN = BGPMessage._HDR_LEN + struct.calcsize(_PACK_STR)
class _Value(object):
class _TypeDisp(object):
class BgpExc(Exception):
class BadNotification(BgpExc):
class NotSync(BgpExc):
class BadLen(BgpExc):
class BadMsg(BgpExc):
class MalformedOptionalParam(BgpExc):
class UnsupportedVersion(BgpExc):
class BadPeerAs(BgpExc):
class BadBgpId(BgpExc):
class UnsupportedOptParam(BgpExc):
class AuthFailure(BgpExc):
class UnacceptableHoldTime(BgpExc):
class MalformedAttrList(BgpExc):
class UnRegWellKnowAttr(BgpExc):
class MissingWellKnown(BgpExc):
class AttrFlagError(BgpExc):
class AttrLenError(BgpExc):
class InvalidOriginError(BgpExc):
class RoutingLoop(BgpExc):
class InvalidNextHop(BgpExc):
class OptAttrError(BgpExc):
class InvalidNetworkField(BgpExc):
class MalformedAsPath(BgpExc):
class HoldTimerExpired(BgpExc):
class FiniteStateMachineError(BgpExc):
class MaxPrefixReached(BgpExc):
class AdminShutdown(BgpExc):
class PeerDeConfig(BgpExc):
class AdminReset(BgpExc):
class ConnRejected(BgpExc):
class OtherConfChange(BgpExc):
class CollisionResolution(BgpExc):
class OutOfResource(BgpExc):
class RouteFamily(StringifyMixin):
class _RouteDistinguisher(StringifyMixin, _TypeDisp, _Value):
class BGPTwoOctetAsRD(_RouteDistinguisher):
class BGPIPv4AddressRD(_RouteDistinguisher):
class BGPFourOctetAsRD(_RouteDistinguisher):
class _AddrPrefix(StringifyMixin):
class _BinAddrPrefix(_AddrPrefix):
class _LabelledAddrPrefix(_AddrPrefix):
class _UnlabelledAddrPrefix(_AddrPrefix):
class _IPAddrPrefix(_AddrPrefix):
class _IP6AddrPrefix(_AddrPrefix):
class _VPNAddrPrefix(_AddrPrefix):
class IPAddrPrefix(_UnlabelledAddrPrefix, _IPAddrPrefix):
class IP6AddrPrefix(_UnlabelledAddrPrefix, _IP6AddrPrefix):
class LabelledIPAddrPrefix(_LabelledAddrPrefix, _IPAddrPrefix):
class LabelledIP6AddrPrefix(_LabelledAddrPrefix, _IP6AddrPrefix):
class LabelledVPNIPAddrPrefix(_LabelledAddrPrefix, _VPNAddrPrefix,
                              _IPAddrPrefix):
class LabelledVPNIP6AddrPrefix(_LabelledAddrPrefix, _VPNAddrPrefix,
                               _IP6AddrPrefix):
class RouteTargetMembershipNLRI(StringifyMixin):
class _OptParam(StringifyMixin, _TypeDisp, _Value):
class BGPOptParamUnknown(_OptParam):
class _OptParamCapability(_OptParam, _TypeDisp):
class _OptParamEmptyCapability(_OptParamCapability):
class BGPOptParamCapabilityUnknown(_OptParamCapability):
class BGPOptParamCapabilityRouteRefresh(_OptParamEmptyCapability):
class BGPOptParamCapabilityCiscoRouteRefresh(_OptParamEmptyCapability):
class BGPOptParamCapabilityEnhancedRouteRefresh(_OptParamEmptyCapability):
class BGPOptParamCapabilityGracefulRestart(_OptParamCapability):
class BGPOptParamCapabilityFourOctetAsNumber(_OptParamCapability):
class BGPOptParamCapabilityMultiprotocol(_OptParamCapability):
class BGPOptParamCapabilityCarryingLabelInfo(_OptParamEmptyCapability):
class BGPWithdrawnRoute(IPAddrPrefix):
class _PathAttribute(StringifyMixin, _TypeDisp, _Value):
class BGPPathAttributeUnknown(_PathAttribute):
class _PathAttributeUint32(_PathAttribute):
class BGPPathAttributeOrigin(_PathAttribute):
class _BGPPathAttributeAsPathCommon(_PathAttribute):
class BGPPathAttributeAsPath(_BGPPathAttributeAsPathCommon):
class BGPPathAttributeAs4Path(_BGPPathAttributeAsPathCommon):
class BGPPathAttributeNextHop(_PathAttribute):
class BGPPathAttributeMultiExitDisc(_PathAttributeUint32):
class BGPPathAttributeLocalPref(_PathAttributeUint32):
class BGPPathAttributeAtomicAggregate(_PathAttribute):
class _BGPPathAttributeAggregatorCommon(_PathAttribute):
class BGPPathAttributeAggregator(_BGPPathAttributeAggregatorCommon):
class BGPPathAttributeAs4Aggregator(_BGPPathAttributeAggregatorCommon):
class BGPPathAttributeCommunities(_PathAttribute):
class BGPPathAttributeOriginatorId(_PathAttribute):
class BGPPathAttributeClusterList(_PathAttribute):
class BGPPathAttributeExtendedCommunities(_PathAttribute):
class _ExtendedCommunity(StringifyMixin, _TypeDisp, _Value):
class BGPTwoOctetAsSpecificExtendedCommunity(_ExtendedCommunity):
class BGPIPv4AddressSpecificExtendedCommunity(_ExtendedCommunity):
class BGPFourOctetAsSpecificExtendedCommunity(_ExtendedCommunity):
class BGPOpaqueExtendedCommunity(_ExtendedCommunity):
class BGPUnknownExtendedCommunity(_ExtendedCommunity):
class BGPPathAttributeMpReachNLRI(_PathAttribute):
class BGPPathAttributeMpUnreachNLRI(_PathAttribute):
class BGPNLRI(IPAddrPrefix):
class BGPMessage(packet_base.PacketBase, _TypeDisp):
class BGPOpen(BGPMessage):
class BGPUpdate(BGPMessage):
class BGPKeepAlive(BGPMessage):
class BGPNotification(BGPMessage):
class BGPRouteRefresh(BGPMessage):
class StreamParser(stream_parser.StreamParser):
    def do_init(cls, self, kwargs, **extra_kwargs):
    def parse_value(cls, buf):
    def serialize_value(self):
    def register_unknown_type(cls):
        def _register_type(subcls):
    def register_type(cls, type_):
        def _register_type(subcls):
    def _lookup_type(cls, type_):
    def _rev_lookup_type(cls, targ_cls):
    def __init__(self, data=''):
    def __str__(self):
    def __init__(self, msg_type_code, message_length):
    def __str__(self):
    def __init__(self, msg_type):
    def __str__(self):
    def __init__(self, locally_support_version):
    def __init__(self, pattr_type_code):
    def __init__(self, afi, safi):
    def __cmp__(self, other):
def get_rf(afi, safi):
def pad(bin, len_):
    def __init__(self, type_, admin=0, assigned=0):
    def parser(cls, buf):
    def from_str(cls, str_):
    def serialize(self):
    def formatted_str(self):
    def __init__(self, type_=_RouteDistinguisher.TWO_OCTET_AS, **kwargs):
    def __init__(self, type_=_RouteDistinguisher.IPV4_ADDRESS, **kwargs):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, type_=_RouteDistinguisher.FOUR_OCTET_AS,
                 **kwargs):
    def __init__(self, length, addr, prefixes=None):
    def _to_bin(addr):
    def _from_bin(addr):
    def parser(cls, buf):
    def serialize(self):
    def _to_bin(addr):
    def _from_bin(addr):
    def __init__(self, length, addr, labels=[], **kwargs):
    def _label_to_bin(cls, label):
    def _label_from_bin(cls, bin):
    def _to_bin(cls, addr):
    def _has_no_label(cls, bin_):
    def _from_bin(cls, addr):
    def _to_bin(cls, addr):
    def _from_bin(cls, binaddr):
    def _prefix_to_bin(addr):
    def _prefix_from_bin(addr):
    def _prefix_to_bin(addr):
    def _prefix_from_bin(addr):
    def __init__(self, length, addr, prefixes=(), route_dist=0):
    def _prefix_to_bin(cls, addr):
    def _prefix_from_bin(cls, binaddr):
    def prefix(self):
    def formatted_nlri_str(self):
    def prefix(self):
    def formatted_nlri_str(self):
    def prefix(self):
    def route_dist(self):
    def label_list(self):
    def formatted_nlri_str(self):
    def prefix(self):
    def route_dist(self):
    def label_list(self):
    def formatted_nlri_str(self):
    def __init__(self, origin_as, route_target):
    def _is_valid_old_asn(self, asn):
    def _is_valid_ext_comm_attr(self, attr):
    def formatted_nlri_str(self):
    def is_default_rtnlri(self):
    def __cmp__(self, other):
    def parser(cls, buf):
    def serialize(self):
def _get_addr_class(afi, safi):
    def __init__(self, type_, value=None, length=None):
    def parser(cls, buf):
    def serialize(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, cap_code=None, cap_value=None, cap_length=None,
                 type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, flags, time, tuples, **kwargs):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, as_number, **kwargs):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, afi, safi, reserved=0, **kwargs):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, value=None, flags=0, type_=None, length=None):
    def parser(cls, buf):
    def serialize(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, value, as_pack_str=None, flags=0, type_=None,
                 length=None):
    def path_seg_list(self):
    def get_as_path_len(self):
    def has_local_as(self, local_as):
    def has_matching_leftmost(self, remote_as):
    def _is_valid_16bit_as_path(cls, buf):
    def parse_value(cls, buf):
    def serialize_value(self):
    def _is_valid_16bit_as_path(cls, buf):
    def parse_value(cls, buf):
    def serialize_value(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, as_number, addr, flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, communities,
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def is_no_export(comm_attr):
    def is_no_advertise(comm_attr):
    def is_no_export_subconfed(comm_attr):
    def has_comm_attr(self, attr):
    def parse_value(cls, buf):
    def serialize_value(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, communities,
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def _community_list(self, subtype):
    def rt_list(self):
    def soo_list(self):
    def __init__(self, type_):
    def parse(cls, buf):
    def serialize(self):
    def __init__(self, type_=_ExtendedCommunity.TWO_OCTET_AS_SPECIFIC,
                 **kwargs):
    def __init__(self, type_=_ExtendedCommunity.IPV4_ADDRESS_SPECIFIC,
                 **kwargs):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, type_=_ExtendedCommunity.FOUR_OCTET_AS_SPECIFIC,
                 **kwargs):
    def __init__(self, type_=_ExtendedCommunity.OPAQUE,
                 **kwargs):
    def __init__(self, **kwargs):
    def __init__(self, afi, safi, next_hop, nlri,
                 next_hop_len=0, reserved='\0',
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def route_family(self):
    def __init__(self, afi, safi, withdrawn_routes,
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def route_family(self):
    def __init__(self, type_, len_=None, marker=None):
    def parser(cls, buf):
    def serialize(self):
    def __len__(self):
    def __init__(self, my_as, bgp_identifier, type_=BGP_MSG_OPEN,
                 opt_param_len=0, opt_param=[],
                 version=_VERSION, hold_time=0, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def __init__(self, type_=BGP_MSG_UPDATE,
                 withdrawn_routes_len=None,
                 withdrawn_routes=[],
                 total_path_attribute_len=None,
                 path_attributes=[],
                 nlri=[],
                 len_=None, marker=None):
    def pathattr_map(self):
    def get_path_attr(self, attr_name):
    def parser(cls, buf):
    def serialize_tail(self):
    def __init__(self, type_=BGP_MSG_KEEPALIVE, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def __init__(self,
                 error_code,
                 error_subcode,
                 data='',
                 type_=BGP_MSG_NOTIFICATION, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def reason(self):
    def __init__(self,
                 afi, safi, demarcation=0,
                 type_=BGP_MSG_ROUTE_REFRESH, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def try_parse(self, data): BGP_MSG_OPEN = 1
BGP_MSG_UPDATE = 2
BGP_MSG_NOTIFICATION = 3
BGP_MSG_KEEPALIVE = 4
BGP_MSG_ROUTE_REFRESH = 5  # RFC 2918
_VERSION = 4
_MARKER = 16 * b'\xff'
BGP_OPT_CAPABILITY = 2  # RFC 5492
BGP_CAP_MULTIPROTOCOL = 1  # RFC 4760
BGP_CAP_ROUTE_REFRESH = 2  # RFC 2918
BGP_CAP_CARRYING_LABEL_INFO = 4  # RFC 3107
BGP_CAP_GRACEFUL_RESTART = 64  # RFC 4724
BGP_CAP_FOUR_OCTET_AS_NUMBER = 65  # RFC 4893
BGP_CAP_ENHANCED_ROUTE_REFRESH = 70  # https://tools.ietf.org/html/\
BGP_CAP_ROUTE_REFRESH_CISCO = 128  # in cisco routers, there are two\
BGP_ATTR_FLAG_OPTIONAL = 1 << 7
BGP_ATTR_FLAG_TRANSITIVE = 1 << 6
BGP_ATTR_FLAG_PARTIAL = 1 << 5
BGP_ATTR_FLAG_EXTENDED_LENGTH = 1 << 4
BGP_ATTR_TYPE_ORIGIN = 1  # 0,1,2 (1 byte)
BGP_ATTR_TYPE_AS_PATH = 2  # a list of AS_SET/AS_SEQUENCE  eg. {1 2 3} 4 5
BGP_ATTR_TYPE_NEXT_HOP = 3  # an IPv4 address
BGP_ATTR_TYPE_MULTI_EXIT_DISC = 4  # uint32 metric
BGP_ATTR_TYPE_LOCAL_PREF = 5  # uint32
BGP_ATTR_TYPE_ATOMIC_AGGREGATE = 6  # 0 bytes
BGP_ATTR_TYPE_AGGREGATOR = 7  # AS number and IPv4 address
BGP_ATTR_TYPE_COMMUNITIES = 8  # RFC 1997
BGP_ATTR_TYPE_ORIGINATOR_ID = 9  # RFC 4456
BGP_ATTR_TYPE_CLUSTER_LIST = 10  # RFC 4456
BGP_ATTR_TYPE_MP_REACH_NLRI = 14  # RFC 4760
BGP_ATTR_TYPE_MP_UNREACH_NLRI = 15  # RFC 4760
BGP_ATTR_TYPE_EXTENDED_COMMUNITIES = 16  # RFC 4360
BGP_ATTR_TYPE_AS4_PATH = 17  # RFC 4893
BGP_ATTR_TYPE_AS4_AGGREGATOR = 18  # RFC 4893
BGP_ATTR_ORIGIN_IGP = 0x00
BGP_ATTR_ORIGIN_EGP = 0x01
BGP_ATTR_ORIGIN_INCOMPLETE = 0x02
AS_TRANS = 23456  # RFC 4893
BGP_COMMUNITY_NO_EXPORT = 0xffffff01
BGP_COMMUNITY_NO_ADVERTISE = 0xffffff02
BGP_COMMUNITY_NO_EXPORT_SUBCONFED = 0xffffff03
BGP_EXTENDED_COMMUNITY_ROUTE_TARGET = 0x02
BGP_EXTENDED_COMMUNITY_ROUTE_ORIGIN = 0x03
BGP_ERROR_MESSAGE_HEADER_ERROR = 1
BGP_ERROR_OPEN_MESSAGE_ERROR = 2
BGP_ERROR_UPDATE_MESSAGE_ERROR = 3
BGP_ERROR_HOLD_TIMER_EXPIRED = 4
BGP_ERROR_FSM_ERROR = 5
BGP_ERROR_CEASE = 6
BGP_ERROR_SUB_CONNECTION_NOT_SYNCHRONIZED = 1
BGP_ERROR_SUB_BAD_MESSAGE_LENGTH = 2  # Data: the erroneous Length field
BGP_ERROR_SUB_BAD_MESSAGE_TYPE = 3  # Data: the erroneous Type field
BGP_ERROR_SUB_UNSUPPORTED_VERSION_NUMBER = 1  # Data: 2 octet version number
BGP_ERROR_SUB_BAD_PEER_AS = 2
BGP_ERROR_SUB_BAD_BGP_IDENTIFIER = 3
BGP_ERROR_SUB_UNSUPPORTED_OPTIONAL_PARAMETER = 4
BGP_ERROR_SUB_AUTHENTICATION_FAILURE = 5  # deprecated RFC 1771
BGP_ERROR_SUB_UNACCEPTABLE_HOLD_TIME = 6
BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST = 1
BGP_ERROR_SUB_UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE = 2  # Data: type of the attr
BGP_ERROR_SUB_MISSING_WELL_KNOWN_ATTRIBUTE = 3  # Data: ditto
BGP_ERROR_SUB_ATTRIBUTE_FLAGS_ERROR = 4  # Data: the attr (type, len, value)
BGP_ERROR_SUB_ATTRIBUTE_LENGTH_ERROR = 5  # Data: ditto
BGP_ERROR_SUB_INVALID_ORIGIN_ATTRIBUTE = 6  # Data: ditto
BGP_ERROR_SUB_ROUTING_LOOP = 7  # deprecated RFC 1771 AS Routing Loop
BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE = 8  # Data: ditto
BGP_ERROR_SUB_OPTIONAL_ATTRIBUTE_ERROR = 9  # Data: ditto
BGP_ERROR_SUB_INVALID_NETWORK_FIELD = 10
BGP_ERROR_SUB_MALFORMED_AS_PATH = 11
BGP_ERROR_SUB_HOLD_TIMER_EXPIRED = 1
BGP_ERROR_SUB_FSM_ERROR = 1
BGP_ERROR_SUB_MAXIMUM_NUMBER_OF_PREFIXES_REACHED = 1  # Data: optional
BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN = 2
BGP_ERROR_SUB_PEER_DECONFIGURED = 3
BGP_ERROR_SUB_ADMINISTRATIVE_RESET = 4
BGP_ERROR_SUB_CONNECTION_RESET = 5
BGP_ERROR_SUB_OTHER_CONFIGURATION_CHANGE = 6
BGP_ERROR_SUB_CONNECTION_COLLISION_RESOLUTION = 7
BGP_ERROR_SUB_OUT_OF_RESOURCES = 8
    _VALUE_PACK_STR = None
    _VALUE_FIELDS = ['value']
    _TYPES = {}
    _REV_TYPES = None
    _UNKNOWN_TYPE = None
    CODE = 0
    SUB_CODE = 0
    SEND_ERROR = True
    SEND_ERROR = False
    CODE = BGP_ERROR_MESSAGE_HEADER_ERROR
    SUB_CODE = BGP_ERROR_SUB_CONNECTION_NOT_SYNCHRONIZED
    CODE = BGP_ERROR_MESSAGE_HEADER_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_MESSAGE_LENGTH
    CODE = BGP_ERROR_MESSAGE_HEADER_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_MESSAGE_TYPE
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = 0
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNSUPPORTED_VERSION_NUMBER
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_PEER_AS
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_BGP_IDENTIFIER
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNSUPPORTED_OPTIONAL_PARAMETER
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_AUTHENTICATION_FAILURE
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNACCEPTABLE_HOLD_TIME
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_MISSING_WELL_KNOWN_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_ATTRIBUTE_FLAGS_ERROR
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_ATTRIBUTE_LENGTH_ERROR
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_INVALID_ORIGIN_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_ROUTING_LOOP
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_OPTIONAL_ATTRIBUTE_ERROR
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_INVALID_NETWORK_FIELD
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_MALFORMED_AS_PATH
    CODE = BGP_ERROR_HOLD_TIMER_EXPIRED
    SUB_CODE = BGP_ERROR_SUB_HOLD_TIMER_EXPIRED
    CODE = BGP_ERROR_FSM_ERROR
    SUB_CODE = BGP_ERROR_SUB_FSM_ERROR
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_MAXIMUM_NUMBER_OF_PREFIXES_REACHED
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_PEER_DECONFIGURED
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_ADMINISTRATIVE_RESET
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_CONNECTION_RESET
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_OTHER_CONFIGURATION_CHANGE
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_CONNECTION_COLLISION_RESOLUTION
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_OUT_OF_RESOURCES
RF_RTC_UC = RouteFamily(addr_family.IP,
                        subaddr_family.ROUTE_TARGET_CONSTRTAINS)
    _PACK_STR = '!H'
    TWO_OCTET_AS = 0
    IPV4_ADDRESS = 1
    FOUR_OCTET_AS = 2
    _VALUE_PACK_STR = '!HI'
    _VALUE_FIELDS = ['admin', 'assigned']
    _VALUE_PACK_STR = '!4sH'
    _VALUE_FIELDS = ['admin', 'assigned']
    _TYPE = {
        'ascii': [
            'admin'
        ]
    }
    _VALUE_PACK_STR = '!IH'
    _VALUE_FIELDS = ['admin', 'assigned']
    _PACK_STR = '!B'  # length
    _LABEL_PACK_STR = '!3B'
    _WITHDRAW_LABEL = 0x800000
    _RD_PACK_STR = '!Q'
    ROUTE_FAMILY = RF_IPv4_UC
    _TYPE = {
        'ascii': [
            'addr'
        ]
    }
    ROUTE_FAMILY = RF_IPv6_UC
    _TYPE = {
        'ascii': [
            'addr'
        ]
    }
    ROUTE_FAMILY = RF_IPv4_MPLS
    ROUTE_FAMILY = RF_IPv6_MPLS
    ROUTE_FAMILY = RF_IPv4_VPN
    ROUTE_FAMILY = RF_IPv6_VPN
    ROUTE_FAMILY = RF_RTC_UC
    DEFAULT_AS = '0:0'
    DEFAULT_RT = '0:0'
_ADDR_CLASSES = {
    _addr_class_key(RF_IPv4_UC): IPAddrPrefix,
    _addr_class_key(RF_IPv6_UC): IP6AddrPrefix,
    _addr_class_key(RF_IPv4_MPLS): LabelledIPAddrPrefix,
    _addr_class_key(RF_IPv6_MPLS): LabelledIP6AddrPrefix,
    _addr_class_key(RF_IPv4_VPN): LabelledVPNIPAddrPrefix,
    _addr_class_key(RF_IPv6_VPN): LabelledVPNIP6AddrPrefix,
    _addr_class_key(RF_RTC_UC): RouteTargetMembershipNLRI,
}
    _PACK_STR = '!BB'  # type, length
    _CAP_HDR_PACK_STR = '!BB'
    _CAP_PACK_STR = "!H"
    _CAP_PACK_STR = '!I'
    _CAP_PACK_STR = '!HBB'  # afi, reserved, safi
    _PACK_STR = '!BB'  # flags, type
    _PACK_STR_LEN = '!B'  # length
    _PACK_STR_EXT_LEN = '!H'  # length w/ BGP_ATTR_FLAG_EXTENDED_LENGTH
    _ATTR_FLAGS = None
    _VALUE_PACK_STR = '!I'
    _VALUE_PACK_STR = '!B'
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _AS_SET = 1
    _AS_SEQUENCE = 2
    _SEG_HDR_PACK_STR = '!BB'
    _AS_PACK_STR = None
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _AS_PACK_STR = '!H'
    _AS_PACK_STR = '!I'
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE | BGP_ATTR_FLAG_OPTIONAL
    _VALUE_PACK_STR = '!4s'
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _TYPE = {
        'ascii': [
            'value'
        ]
    }
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _VALUE_PACK_STR = None
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE
    _TYPE = {
        'ascii': [
            'addr'
        ]
    }
    _VALUE_PACK_STR = '!H4s'
    _VALUE_PACK_STR = '!I4s'
    _VALUE_PACK_STR = '!I'
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE
    NO_EXPORT = int('0xFFFFFF01', 16)
    NO_ADVERTISE = int('0xFFFFFF02', 16)
    NO_EXPORT_SUBCONFED = int('0xFFFFFF03', 16)
    WELL_KNOW_COMMUNITIES = (NO_EXPORT, NO_ADVERTISE, NO_EXPORT_SUBCONFED)
    _VALUE_PACK_STR = '!4s'
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _TYPE = {
        'ascii': [
            'value'
        ]
    }
    _VALUE_PACK_STR = '!4s'
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _TYPE = {
        'ascii': [
            'value'
        ]
    }
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE
    _PACK_STR = '!B7s'  # type high (+ type low) + value
    IANA_AUTHORITY = 0x80
    TRANSITIVE = 0x40
    _TYPE_HIGH_MASK = ~TRANSITIVE
    TWO_OCTET_AS_SPECIFIC = 0x00
    IPV4_ADDRESS_SPECIFIC = 0x01
    FOUR_OCTET_AS_SPECIFIC = 0x02
    OPAQUE = 0x03
    _VALUE_PACK_STR = '!BHI'  # sub type, as number, local adm
    _VALUE_FIELDS = ['subtype', 'as_number', 'local_administrator']
    _VALUE_PACK_STR = '!B4sH'  # sub type, IPv4 address, local adm
    _VALUE_FIELDS = ['subtype', 'ipv4_address', 'local_administrator']
    _TYPE = {
        'ascii': [
            'ipv4_address'
        ]
    }
    _VALUE_PACK_STR = '!BIH'  # sub type, as number, local adm
    _VALUE_FIELDS = ['subtype', 'as_number', 'local_administrator']
    _VALUE_PACK_STR = '!7s'  # opaque value
    _VALUE_FIELDS = ['opaque']
    _VALUE_PACK_STR = '!7s'  # opaque value
    _VALUE_PACK_STR = '!HBB'  # afi, safi, next hop len
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _TYPE = {
        'ascii': [
            'next_hop'
        ]
    }
    _VALUE_PACK_STR = '!HB'  # afi, safi
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _HDR_PACK_STR = '!16sHB'  # marker, len, type
    _HDR_LEN = struct.calcsize(_HDR_PACK_STR)
    _PACK_STR = '!BHH4sB'
    _MIN_LEN = BGPMessage._HDR_LEN + struct.calcsize(_PACK_STR)
    _TYPE = {
        'ascii': [
            'bgp_identifier'
        ]
    }
    _MIN_LEN = BGPMessage._HDR_LEN
    _MIN_LEN = BGPMessage._HDR_LEN
    _PACK_STR = '!BB'
    _MIN_LEN = BGPMessage._HDR_LEN + struct.calcsize(_PACK_STR)
    _REASONS = {
        (1, 1): 'Message Header Error: not synchronised',
        (1, 2): 'Message Header Error: bad message len',
        (1, 3): 'Message Header Error: bad message type',
        (2, 1): 'Open Message Error: unsupported version',
        (2, 2): 'Open Message Error: bad peer AS',
        (2, 3): 'Open Message Error: bad BGP identifier',
        (2, 4): 'Open Message Error: unsupported optional param',
        (2, 5): 'Open Message Error: authentication failure',
        (2, 6): 'Open Message Error: unacceptable hold time',
        (2, 7): 'Open Message Error: Unsupported Capability',
        (2, 8): 'Open Message Error: Unassigned',
        (3, 1): 'Update Message Error: malformed attribute list',
        (3, 2): 'Update Message Error: unrecognized well-known attr',
        (3, 3): 'Update Message Error: missing well-known attr',
        (3, 4): 'Update Message Error: attribute flags error',
        (3, 5): 'Update Message Error: attribute length error',
        (3, 6): 'Update Message Error: invalid origin attr',
        (3, 7): 'Update Message Error: as routing loop',
        (3, 8): 'Update Message Error: invalid next hop attr',
        (3, 9): 'Update Message Error: optional attribute error',
        (3, 10): 'Update Message Error: invalid network field',
        (3, 11): 'Update Message Error: malformed AS_PATH',
        (4, 1): 'Hold Timer Expired',
        (5, 1): 'Finite State Machine Error',
        (6, 1): 'Cease: Maximum Number of Prefixes Reached',
        (6, 2): 'Cease: Administrative Shutdown',
        (6, 3): 'Cease: Peer De-configured',
        (6, 4): 'Cease: Administrative Reset',
        (6, 5): 'Cease: Connection Rejected',
        (6, 6): 'Cease: Other Configuration Change',
        (6, 7): 'Cease: Connection Collision Resolution',
        (6, 8): 'Cease: Out of Resources',
    }
    _PACK_STR = '!HBB'
    _MIN_LEN = BGPMessage._HDR_LEN + struct.calcsize(_PACK_STR)
class _Value(object):
class _TypeDisp(object):
class BgpExc(Exception):
class BadNotification(BgpExc):
class NotSync(BgpExc):
class BadLen(BgpExc):
class BadMsg(BgpExc):
class MalformedOptionalParam(BgpExc):
class UnsupportedVersion(BgpExc):
class BadPeerAs(BgpExc):
class BadBgpId(BgpExc):
class UnsupportedOptParam(BgpExc):
class AuthFailure(BgpExc):
class UnacceptableHoldTime(BgpExc):
class MalformedAttrList(BgpExc):
class UnRegWellKnowAttr(BgpExc):
class MissingWellKnown(BgpExc):
class AttrFlagError(BgpExc):
class AttrLenError(BgpExc):
class InvalidOriginError(BgpExc):
class RoutingLoop(BgpExc):
class InvalidNextHop(BgpExc):
class OptAttrError(BgpExc):
class InvalidNetworkField(BgpExc):
class MalformedAsPath(BgpExc):
class HoldTimerExpired(BgpExc):
class FiniteStateMachineError(BgpExc):
class MaxPrefixReached(BgpExc):
class AdminShutdown(BgpExc):
class PeerDeConfig(BgpExc):
class AdminReset(BgpExc):
class ConnRejected(BgpExc):
class OtherConfChange(BgpExc):
class CollisionResolution(BgpExc):
class OutOfResource(BgpExc):
class RouteFamily(StringifyMixin):
class _RouteDistinguisher(StringifyMixin, _TypeDisp, _Value):
class BGPTwoOctetAsRD(_RouteDistinguisher):
class BGPIPv4AddressRD(_RouteDistinguisher):
class BGPFourOctetAsRD(_RouteDistinguisher):
class _AddrPrefix(StringifyMixin):
class _BinAddrPrefix(_AddrPrefix):
class _LabelledAddrPrefix(_AddrPrefix):
class _UnlabelledAddrPrefix(_AddrPrefix):
class _IPAddrPrefix(_AddrPrefix):
class _IP6AddrPrefix(_AddrPrefix):
class _VPNAddrPrefix(_AddrPrefix):
class IPAddrPrefix(_UnlabelledAddrPrefix, _IPAddrPrefix):
class IP6AddrPrefix(_UnlabelledAddrPrefix, _IP6AddrPrefix):
class LabelledIPAddrPrefix(_LabelledAddrPrefix, _IPAddrPrefix):
class LabelledIP6AddrPrefix(_LabelledAddrPrefix, _IP6AddrPrefix):
class LabelledVPNIPAddrPrefix(_LabelledAddrPrefix, _VPNAddrPrefix,
                              _IPAddrPrefix):
class LabelledVPNIP6AddrPrefix(_LabelledAddrPrefix, _VPNAddrPrefix,
                               _IP6AddrPrefix):
class RouteTargetMembershipNLRI(StringifyMixin):
class _OptParam(StringifyMixin, _TypeDisp, _Value):
class BGPOptParamUnknown(_OptParam):
class _OptParamCapability(_OptParam, _TypeDisp):
class _OptParamEmptyCapability(_OptParamCapability):
class BGPOptParamCapabilityUnknown(_OptParamCapability):
class BGPOptParamCapabilityRouteRefresh(_OptParamEmptyCapability):
class BGPOptParamCapabilityCiscoRouteRefresh(_OptParamEmptyCapability):
class BGPOptParamCapabilityEnhancedRouteRefresh(_OptParamEmptyCapability):
class BGPOptParamCapabilityGracefulRestart(_OptParamCapability):
class BGPOptParamCapabilityFourOctetAsNumber(_OptParamCapability):
class BGPOptParamCapabilityMultiprotocol(_OptParamCapability):
class BGPOptParamCapabilityCarryingLabelInfo(_OptParamEmptyCapability):
class BGPWithdrawnRoute(IPAddrPrefix):
class _PathAttribute(StringifyMixin, _TypeDisp, _Value):
class BGPPathAttributeUnknown(_PathAttribute):
class _PathAttributeUint32(_PathAttribute):
class BGPPathAttributeOrigin(_PathAttribute):
class _BGPPathAttributeAsPathCommon(_PathAttribute):
class BGPPathAttributeAsPath(_BGPPathAttributeAsPathCommon):
class BGPPathAttributeAs4Path(_BGPPathAttributeAsPathCommon):
class BGPPathAttributeNextHop(_PathAttribute):
class BGPPathAttributeMultiExitDisc(_PathAttributeUint32):
class BGPPathAttributeLocalPref(_PathAttributeUint32):
class BGPPathAttributeAtomicAggregate(_PathAttribute):
class _BGPPathAttributeAggregatorCommon(_PathAttribute):
class BGPPathAttributeAggregator(_BGPPathAttributeAggregatorCommon):
class BGPPathAttributeAs4Aggregator(_BGPPathAttributeAggregatorCommon):
class BGPPathAttributeCommunities(_PathAttribute):
class BGPPathAttributeOriginatorId(_PathAttribute):
class BGPPathAttributeClusterList(_PathAttribute):
class BGPPathAttributeExtendedCommunities(_PathAttribute):
class _ExtendedCommunity(StringifyMixin, _TypeDisp, _Value):
class BGPTwoOctetAsSpecificExtendedCommunity(_ExtendedCommunity):
class BGPIPv4AddressSpecificExtendedCommunity(_ExtendedCommunity):
class BGPFourOctetAsSpecificExtendedCommunity(_ExtendedCommunity):
class BGPOpaqueExtendedCommunity(_ExtendedCommunity):
class BGPUnknownExtendedCommunity(_ExtendedCommunity):
class BGPPathAttributeMpReachNLRI(_PathAttribute):
class BGPPathAttributeMpUnreachNLRI(_PathAttribute):
class BGPNLRI(IPAddrPrefix):
class BGPMessage(packet_base.PacketBase, _TypeDisp):
class BGPOpen(BGPMessage):
class BGPUpdate(BGPMessage):
class BGPKeepAlive(BGPMessage):
class BGPNotification(BGPMessage):
class BGPRouteRefresh(BGPMessage):
class StreamParser(stream_parser.StreamParser):
    def do_init(cls, self, kwargs, **extra_kwargs):
    def parse_value(cls, buf):
    def serialize_value(self):
    def register_unknown_type(cls):
        def _register_type(subcls):
    def register_type(cls, type_):
        def _register_type(subcls):
    def _lookup_type(cls, type_):
    def _rev_lookup_type(cls, targ_cls):
    def __init__(self, data=''):
    def __str__(self):
    def __init__(self, msg_type_code, message_length):
    def __str__(self):
    def __init__(self, msg_type):
    def __str__(self):
    def __init__(self, locally_support_version):
    def __init__(self, pattr_type_code):
    def __init__(self, afi, safi):
    def __cmp__(self, other):
def get_rf(afi, safi):
def pad(bin, len_):
    def __init__(self, type_, admin=0, assigned=0):
    def parser(cls, buf):
    def from_str(cls, str_):
    def serialize(self):
    def formatted_str(self):
    def __init__(self, type_=_RouteDistinguisher.TWO_OCTET_AS, **kwargs):
    def __init__(self, type_=_RouteDistinguisher.IPV4_ADDRESS, **kwargs):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, type_=_RouteDistinguisher.FOUR_OCTET_AS,
                 **kwargs):
    def __init__(self, length, addr, prefixes=None):
    def _to_bin(addr):
    def _from_bin(addr):
    def parser(cls, buf):
    def serialize(self):
    def _to_bin(addr):
    def _from_bin(addr):
    def __init__(self, length, addr, labels=[], **kwargs):
    def _label_to_bin(cls, label):
    def _label_from_bin(cls, bin):
    def _to_bin(cls, addr):
    def _has_no_label(cls, bin_):
    def _from_bin(cls, addr):
    def _to_bin(cls, addr):
    def _from_bin(cls, binaddr):
    def _prefix_to_bin(addr):
    def _prefix_from_bin(addr):
    def _prefix_to_bin(addr):
    def _prefix_from_bin(addr):
    def __init__(self, length, addr, prefixes=(), route_dist=0):
    def _prefix_to_bin(cls, addr):
    def _prefix_from_bin(cls, binaddr):
    def prefix(self):
    def formatted_nlri_str(self):
    def prefix(self):
    def formatted_nlri_str(self):
    def prefix(self):
    def route_dist(self):
    def label_list(self):
    def formatted_nlri_str(self):
    def prefix(self):
    def route_dist(self):
    def label_list(self):
    def formatted_nlri_str(self):
    def __init__(self, origin_as, route_target):
    def _is_valid_old_asn(self, asn):
    def _is_valid_ext_comm_attr(self, attr):
    def formatted_nlri_str(self):
    def is_default_rtnlri(self):
    def __cmp__(self, other):
    def parser(cls, buf):
    def serialize(self):
def _get_addr_class(afi, safi):
    def __init__(self, type_, value=None, length=None):
    def parser(cls, buf):
    def serialize(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, cap_code=None, cap_value=None, cap_length=None,
                 type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, flags, time, tuples, **kwargs):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, as_number, **kwargs):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, afi, safi, reserved=0, **kwargs):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, value=None, flags=0, type_=None, length=None):
    def parser(cls, buf):
    def serialize(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, value, as_pack_str=None, flags=0, type_=None,
                 length=None):
    def path_seg_list(self):
    def get_as_path_len(self):
    def has_local_as(self, local_as):
    def has_matching_leftmost(self, remote_as):
    def _is_valid_16bit_as_path(cls, buf):
    def parse_value(cls, buf):
    def serialize_value(self):
    def _is_valid_16bit_as_path(cls, buf):
    def parse_value(cls, buf):
    def serialize_value(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, as_number, addr, flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, communities,
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def is_no_export(comm_attr):
    def is_no_advertise(comm_attr):
    def is_no_export_subconfed(comm_attr):
    def has_comm_attr(self, attr):
    def parse_value(cls, buf):
    def serialize_value(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, communities,
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def _community_list(self, subtype):
    def rt_list(self):
    def soo_list(self):
    def __init__(self, type_):
    def parse(cls, buf):
    def serialize(self):
    def __init__(self, type_=_ExtendedCommunity.TWO_OCTET_AS_SPECIFIC,
                 **kwargs):
    def __init__(self, type_=_ExtendedCommunity.IPV4_ADDRESS_SPECIFIC,
                 **kwargs):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, type_=_ExtendedCommunity.FOUR_OCTET_AS_SPECIFIC,
                 **kwargs):
    def __init__(self, type_=_ExtendedCommunity.OPAQUE,
                 **kwargs):
    def __init__(self, **kwargs):
    def __init__(self, afi, safi, next_hop, nlri,
                 next_hop_len=0, reserved='\0',
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def route_family(self):
    def __init__(self, afi, safi, withdrawn_routes,
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def route_family(self):
    def __init__(self, type_, len_=None, marker=None):
    def parser(cls, buf):
    def serialize(self):
    def __len__(self):
    def __init__(self, my_as, bgp_identifier, type_=BGP_MSG_OPEN,
                 opt_param_len=0, opt_param=[],
                 version=_VERSION, hold_time=0, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def __init__(self, type_=BGP_MSG_UPDATE,
                 withdrawn_routes_len=None,
                 withdrawn_routes=[],
                 total_path_attribute_len=None,
                 path_attributes=[],
                 nlri=[],
                 len_=None, marker=None):
    def pathattr_map(self):
    def get_path_attr(self, attr_name):
    def parser(cls, buf):
    def serialize_tail(self):
    def __init__(self, type_=BGP_MSG_KEEPALIVE, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def __init__(self,
                 error_code,
                 error_subcode,
                 data='',
                 type_=BGP_MSG_NOTIFICATION, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def reason(self):
    def __init__(self,
                 afi, safi, demarcation=0,
                 type_=BGP_MSG_ROUTE_REFRESH, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def try_parse(self, data): BGP_MSG_OPEN = 1
BGP_MSG_UPDATE = 2
BGP_MSG_NOTIFICATION = 3
BGP_MSG_KEEPALIVE = 4
BGP_MSG_ROUTE_REFRESH = 5  # RFC 2918
_VERSION = 4
_MARKER = 16 * b'\xff'
BGP_OPT_CAPABILITY = 2  # RFC 5492
BGP_CAP_MULTIPROTOCOL = 1  # RFC 4760
BGP_CAP_ROUTE_REFRESH = 2  # RFC 2918
BGP_CAP_CARRYING_LABEL_INFO = 4  # RFC 3107
BGP_CAP_GRACEFUL_RESTART = 64  # RFC 4724
BGP_CAP_FOUR_OCTET_AS_NUMBER = 65  # RFC 4893
BGP_CAP_ENHANCED_ROUTE_REFRESH = 70  # https://tools.ietf.org/html/\
BGP_CAP_ROUTE_REFRESH_CISCO = 128  # in cisco routers, there are two\
BGP_ATTR_FLAG_OPTIONAL = 1 << 7
BGP_ATTR_FLAG_TRANSITIVE = 1 << 6
BGP_ATTR_FLAG_PARTIAL = 1 << 5
BGP_ATTR_FLAG_EXTENDED_LENGTH = 1 << 4
BGP_ATTR_TYPE_ORIGIN = 1  # 0,1,2 (1 byte)
BGP_ATTR_TYPE_AS_PATH = 2  # a list of AS_SET/AS_SEQUENCE  eg. {1 2 3} 4 5
BGP_ATTR_TYPE_NEXT_HOP = 3  # an IPv4 address
BGP_ATTR_TYPE_MULTI_EXIT_DISC = 4  # uint32 metric
BGP_ATTR_TYPE_LOCAL_PREF = 5  # uint32
BGP_ATTR_TYPE_ATOMIC_AGGREGATE = 6  # 0 bytes
BGP_ATTR_TYPE_AGGREGATOR = 7  # AS number and IPv4 address
BGP_ATTR_TYPE_COMMUNITIES = 8  # RFC 1997
BGP_ATTR_TYPE_ORIGINATOR_ID = 9  # RFC 4456
BGP_ATTR_TYPE_CLUSTER_LIST = 10  # RFC 4456
BGP_ATTR_TYPE_MP_REACH_NLRI = 14  # RFC 4760
BGP_ATTR_TYPE_MP_UNREACH_NLRI = 15  # RFC 4760
BGP_ATTR_TYPE_EXTENDED_COMMUNITIES = 16  # RFC 4360
BGP_ATTR_TYPE_AS4_PATH = 17  # RFC 4893
BGP_ATTR_TYPE_AS4_AGGREGATOR = 18  # RFC 4893
BGP_ATTR_ORIGIN_IGP = 0x00
BGP_ATTR_ORIGIN_EGP = 0x01
BGP_ATTR_ORIGIN_INCOMPLETE = 0x02
AS_TRANS = 23456  # RFC 4893
BGP_COMMUNITY_NO_EXPORT = 0xffffff01
BGP_COMMUNITY_NO_ADVERTISE = 0xffffff02
BGP_COMMUNITY_NO_EXPORT_SUBCONFED = 0xffffff03
BGP_EXTENDED_COMMUNITY_ROUTE_TARGET = 0x02
BGP_EXTENDED_COMMUNITY_ROUTE_ORIGIN = 0x03
BGP_ERROR_MESSAGE_HEADER_ERROR = 1
BGP_ERROR_OPEN_MESSAGE_ERROR = 2
BGP_ERROR_UPDATE_MESSAGE_ERROR = 3
BGP_ERROR_HOLD_TIMER_EXPIRED = 4
BGP_ERROR_FSM_ERROR = 5
BGP_ERROR_CEASE = 6
BGP_ERROR_SUB_CONNECTION_NOT_SYNCHRONIZED = 1
BGP_ERROR_SUB_BAD_MESSAGE_LENGTH = 2  # Data: the erroneous Length field
BGP_ERROR_SUB_BAD_MESSAGE_TYPE = 3  # Data: the erroneous Type field
BGP_ERROR_SUB_UNSUPPORTED_VERSION_NUMBER = 1  # Data: 2 octet version number
BGP_ERROR_SUB_BAD_PEER_AS = 2
BGP_ERROR_SUB_BAD_BGP_IDENTIFIER = 3
BGP_ERROR_SUB_UNSUPPORTED_OPTIONAL_PARAMETER = 4
BGP_ERROR_SUB_AUTHENTICATION_FAILURE = 5  # deprecated RFC 1771
BGP_ERROR_SUB_UNACCEPTABLE_HOLD_TIME = 6
BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST = 1
BGP_ERROR_SUB_UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE = 2  # Data: type of the attr
BGP_ERROR_SUB_MISSING_WELL_KNOWN_ATTRIBUTE = 3  # Data: ditto
BGP_ERROR_SUB_ATTRIBUTE_FLAGS_ERROR = 4  # Data: the attr (type, len, value)
BGP_ERROR_SUB_ATTRIBUTE_LENGTH_ERROR = 5  # Data: ditto
BGP_ERROR_SUB_INVALID_ORIGIN_ATTRIBUTE = 6  # Data: ditto
BGP_ERROR_SUB_ROUTING_LOOP = 7  # deprecated RFC 1771 AS Routing Loop
BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE = 8  # Data: ditto
BGP_ERROR_SUB_OPTIONAL_ATTRIBUTE_ERROR = 9  # Data: ditto
BGP_ERROR_SUB_INVALID_NETWORK_FIELD = 10
BGP_ERROR_SUB_MALFORMED_AS_PATH = 11
BGP_ERROR_SUB_HOLD_TIMER_EXPIRED = 1
BGP_ERROR_SUB_FSM_ERROR = 1
BGP_ERROR_SUB_MAXIMUM_NUMBER_OF_PREFIXES_REACHED = 1  # Data: optional
BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN = 2
BGP_ERROR_SUB_PEER_DECONFIGURED = 3
BGP_ERROR_SUB_ADMINISTRATIVE_RESET = 4
BGP_ERROR_SUB_CONNECTION_RESET = 5
BGP_ERROR_SUB_OTHER_CONFIGURATION_CHANGE = 6
BGP_ERROR_SUB_CONNECTION_COLLISION_RESOLUTION = 7
BGP_ERROR_SUB_OUT_OF_RESOURCES = 8
    _VALUE_PACK_STR = None
    _VALUE_FIELDS = ['value']
    _TYPES = {}
    _REV_TYPES = None
    _UNKNOWN_TYPE = None
    CODE = 0
    SUB_CODE = 0
    SEND_ERROR = True
    SEND_ERROR = False
    CODE = BGP_ERROR_MESSAGE_HEADER_ERROR
    SUB_CODE = BGP_ERROR_SUB_CONNECTION_NOT_SYNCHRONIZED
    CODE = BGP_ERROR_MESSAGE_HEADER_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_MESSAGE_LENGTH
    CODE = BGP_ERROR_MESSAGE_HEADER_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_MESSAGE_TYPE
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = 0
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNSUPPORTED_VERSION_NUMBER
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_PEER_AS
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_BAD_BGP_IDENTIFIER
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNSUPPORTED_OPTIONAL_PARAMETER
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_AUTHENTICATION_FAILURE
    CODE = BGP_ERROR_OPEN_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNACCEPTABLE_HOLD_TIME
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_MISSING_WELL_KNOWN_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_ATTRIBUTE_FLAGS_ERROR
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_ATTRIBUTE_LENGTH_ERROR
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_INVALID_ORIGIN_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_ROUTING_LOOP
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_INVALID_NEXT_HOP_ATTRIBUTE
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_OPTIONAL_ATTRIBUTE_ERROR
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_INVALID_NETWORK_FIELD
    CODE = BGP_ERROR_UPDATE_MESSAGE_ERROR
    SUB_CODE = BGP_ERROR_SUB_MALFORMED_AS_PATH
    CODE = BGP_ERROR_HOLD_TIMER_EXPIRED
    SUB_CODE = BGP_ERROR_SUB_HOLD_TIMER_EXPIRED
    CODE = BGP_ERROR_FSM_ERROR
    SUB_CODE = BGP_ERROR_SUB_FSM_ERROR
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_MAXIMUM_NUMBER_OF_PREFIXES_REACHED
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_PEER_DECONFIGURED
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_ADMINISTRATIVE_RESET
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_CONNECTION_RESET
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_OTHER_CONFIGURATION_CHANGE
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_CONNECTION_COLLISION_RESOLUTION
    CODE = BGP_ERROR_CEASE
    SUB_CODE = BGP_ERROR_SUB_OUT_OF_RESOURCES
RF_RTC_UC = RouteFamily(addr_family.IP,
                        subaddr_family.ROUTE_TARGET_CONSTRTAINS)
    _PACK_STR = '!H'
    TWO_OCTET_AS = 0
    IPV4_ADDRESS = 1
    FOUR_OCTET_AS = 2
    _VALUE_PACK_STR = '!HI'
    _VALUE_FIELDS = ['admin', 'assigned']
    _VALUE_PACK_STR = '!4sH'
    _VALUE_FIELDS = ['admin', 'assigned']
    _TYPE = {
        'ascii': [
            'admin'
        ]
    }
    _VALUE_PACK_STR = '!IH'
    _VALUE_FIELDS = ['admin', 'assigned']
    _PACK_STR = '!B'  # length
    _LABEL_PACK_STR = '!3B'
    _WITHDRAW_LABEL = 0x800000
    _RD_PACK_STR = '!Q'
    ROUTE_FAMILY = RF_IPv4_UC
    _TYPE = {
        'ascii': [
            'addr'
        ]
    }
    ROUTE_FAMILY = RF_IPv6_UC
    _TYPE = {
        'ascii': [
            'addr'
        ]
    }
    ROUTE_FAMILY = RF_IPv4_MPLS
    ROUTE_FAMILY = RF_IPv6_MPLS
    ROUTE_FAMILY = RF_IPv4_VPN
    ROUTE_FAMILY = RF_IPv6_VPN
    ROUTE_FAMILY = RF_RTC_UC
    DEFAULT_AS = '0:0'
    DEFAULT_RT = '0:0'
_ADDR_CLASSES = {
    _addr_class_key(RF_IPv4_UC): IPAddrPrefix,
    _addr_class_key(RF_IPv6_UC): IP6AddrPrefix,
    _addr_class_key(RF_IPv4_MPLS): LabelledIPAddrPrefix,
    _addr_class_key(RF_IPv6_MPLS): LabelledIP6AddrPrefix,
    _addr_class_key(RF_IPv4_VPN): LabelledVPNIPAddrPrefix,
    _addr_class_key(RF_IPv6_VPN): LabelledVPNIP6AddrPrefix,
    _addr_class_key(RF_RTC_UC): RouteTargetMembershipNLRI,
}
    _PACK_STR = '!BB'  # type, length
    _CAP_HDR_PACK_STR = '!BB'
    _CAP_PACK_STR = "!H"
    _CAP_PACK_STR = '!I'
    _CAP_PACK_STR = '!HBB'  # afi, reserved, safi
    _PACK_STR = '!BB'  # flags, type
    _PACK_STR_LEN = '!B'  # length
    _PACK_STR_EXT_LEN = '!H'  # length w/ BGP_ATTR_FLAG_EXTENDED_LENGTH
    _ATTR_FLAGS = None
    _VALUE_PACK_STR = '!I'
    _VALUE_PACK_STR = '!B'
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _AS_SET = 1
    _AS_SEQUENCE = 2
    _SEG_HDR_PACK_STR = '!BB'
    _AS_PACK_STR = None
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _AS_PACK_STR = '!H'
    _AS_PACK_STR = '!I'
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE | BGP_ATTR_FLAG_OPTIONAL
    _VALUE_PACK_STR = '!4s'
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _TYPE = {
        'ascii': [
            'value'
        ]
    }
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE
    _VALUE_PACK_STR = None
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE
    _TYPE = {
        'ascii': [
            'addr'
        ]
    }
    _VALUE_PACK_STR = '!H4s'
    _VALUE_PACK_STR = '!I4s'
    _VALUE_PACK_STR = '!I'
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE
    NO_EXPORT = int('0xFFFFFF01', 16)
    NO_ADVERTISE = int('0xFFFFFF02', 16)
    NO_EXPORT_SUBCONFED = int('0xFFFFFF03', 16)
    WELL_KNOW_COMMUNITIES = (NO_EXPORT, NO_ADVERTISE, NO_EXPORT_SUBCONFED)
    _VALUE_PACK_STR = '!4s'
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _TYPE = {
        'ascii': [
            'value'
        ]
    }
    _VALUE_PACK_STR = '!4s'
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _TYPE = {
        'ascii': [
            'value'
        ]
    }
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE
    _PACK_STR = '!B7s'  # type high (+ type low) + value
    IANA_AUTHORITY = 0x80
    TRANSITIVE = 0x40
    _TYPE_HIGH_MASK = ~TRANSITIVE
    TWO_OCTET_AS_SPECIFIC = 0x00
    IPV4_ADDRESS_SPECIFIC = 0x01
    FOUR_OCTET_AS_SPECIFIC = 0x02
    OPAQUE = 0x03
    _VALUE_PACK_STR = '!BHI'  # sub type, as number, local adm
    _VALUE_FIELDS = ['subtype', 'as_number', 'local_administrator']
    _VALUE_PACK_STR = '!B4sH'  # sub type, IPv4 address, local adm
    _VALUE_FIELDS = ['subtype', 'ipv4_address', 'local_administrator']
    _TYPE = {
        'ascii': [
            'ipv4_address'
        ]
    }
    _VALUE_PACK_STR = '!BIH'  # sub type, as number, local adm
    _VALUE_FIELDS = ['subtype', 'as_number', 'local_administrator']
    _VALUE_PACK_STR = '!7s'  # opaque value
    _VALUE_FIELDS = ['opaque']
    _VALUE_PACK_STR = '!7s'  # opaque value
    _VALUE_PACK_STR = '!HBB'  # afi, safi, next hop len
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _TYPE = {
        'ascii': [
            'next_hop'
        ]
    }
    _VALUE_PACK_STR = '!HB'  # afi, safi
    _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
    _HDR_PACK_STR = '!16sHB'  # marker, len, type
    _HDR_LEN = struct.calcsize(_HDR_PACK_STR)
    _PACK_STR = '!BHH4sB'
    _MIN_LEN = BGPMessage._HDR_LEN + struct.calcsize(_PACK_STR)
    _TYPE = {
        'ascii': [
            'bgp_identifier'
        ]
    }
    _MIN_LEN = BGPMessage._HDR_LEN
    _MIN_LEN = BGPMessage._HDR_LEN
    _PACK_STR = '!BB'
    _MIN_LEN = BGPMessage._HDR_LEN + struct.calcsize(_PACK_STR)
    _REASONS = {
        (1, 1): 'Message Header Error: not synchronised',
        (1, 2): 'Message Header Error: bad message len',
        (1, 3): 'Message Header Error: bad message type',
        (2, 1): 'Open Message Error: unsupported version',
        (2, 2): 'Open Message Error: bad peer AS',
        (2, 3): 'Open Message Error: bad BGP identifier',
        (2, 4): 'Open Message Error: unsupported optional param',
        (2, 5): 'Open Message Error: authentication failure',
        (2, 6): 'Open Message Error: unacceptable hold time',
        (2, 7): 'Open Message Error: Unsupported Capability',
        (2, 8): 'Open Message Error: Unassigned',
        (3, 1): 'Update Message Error: malformed attribute list',
        (3, 2): 'Update Message Error: unrecognized well-known attr',
        (3, 3): 'Update Message Error: missing well-known attr',
        (3, 4): 'Update Message Error: attribute flags error',
        (3, 5): 'Update Message Error: attribute length error',
        (3, 6): 'Update Message Error: invalid origin attr',
        (3, 7): 'Update Message Error: as routing loop',
        (3, 8): 'Update Message Error: invalid next hop attr',
        (3, 9): 'Update Message Error: optional attribute error',
        (3, 10): 'Update Message Error: invalid network field',
        (3, 11): 'Update Message Error: malformed AS_PATH',
        (4, 1): 'Hold Timer Expired',
        (5, 1): 'Finite State Machine Error',
        (6, 1): 'Cease: Maximum Number of Prefixes Reached',
        (6, 2): 'Cease: Administrative Shutdown',
        (6, 3): 'Cease: Peer De-configured',
        (6, 4): 'Cease: Administrative Reset',
        (6, 5): 'Cease: Connection Rejected',
        (6, 6): 'Cease: Other Configuration Change',
        (6, 7): 'Cease: Connection Collision Resolution',
        (6, 8): 'Cease: Out of Resources',
    }
    _PACK_STR = '!HBB'
    _MIN_LEN = BGPMessage._HDR_LEN + struct.calcsize(_PACK_STR)
class _Value(object):
class _TypeDisp(object):
class BgpExc(Exception):
class BadNotification(BgpExc):
class NotSync(BgpExc):
class BadLen(BgpExc):
class BadMsg(BgpExc):
class MalformedOptionalParam(BgpExc):
class UnsupportedVersion(BgpExc):
class BadPeerAs(BgpExc):
class BadBgpId(BgpExc):
class UnsupportedOptParam(BgpExc):
class AuthFailure(BgpExc):
class UnacceptableHoldTime(BgpExc):
class MalformedAttrList(BgpExc):
class UnRegWellKnowAttr(BgpExc):
class MissingWellKnown(BgpExc):
class AttrFlagError(BgpExc):
class AttrLenError(BgpExc):
class InvalidOriginError(BgpExc):
class RoutingLoop(BgpExc):
class InvalidNextHop(BgpExc):
class OptAttrError(BgpExc):
class InvalidNetworkField(BgpExc):
class MalformedAsPath(BgpExc):
class HoldTimerExpired(BgpExc):
class FiniteStateMachineError(BgpExc):
class MaxPrefixReached(BgpExc):
class AdminShutdown(BgpExc):
class PeerDeConfig(BgpExc):
class AdminReset(BgpExc):
class ConnRejected(BgpExc):
class OtherConfChange(BgpExc):
class CollisionResolution(BgpExc):
class OutOfResource(BgpExc):
class RouteFamily(StringifyMixin):
class _RouteDistinguisher(StringifyMixin, _TypeDisp, _Value):
class BGPTwoOctetAsRD(_RouteDistinguisher):
class BGPIPv4AddressRD(_RouteDistinguisher):
class BGPFourOctetAsRD(_RouteDistinguisher):
class _AddrPrefix(StringifyMixin):
class _BinAddrPrefix(_AddrPrefix):
class _LabelledAddrPrefix(_AddrPrefix):
class _UnlabelledAddrPrefix(_AddrPrefix):
class _IPAddrPrefix(_AddrPrefix):
class _IP6AddrPrefix(_AddrPrefix):
class _VPNAddrPrefix(_AddrPrefix):
class IPAddrPrefix(_UnlabelledAddrPrefix, _IPAddrPrefix):
class IP6AddrPrefix(_UnlabelledAddrPrefix, _IP6AddrPrefix):
class LabelledIPAddrPrefix(_LabelledAddrPrefix, _IPAddrPrefix):
class LabelledIP6AddrPrefix(_LabelledAddrPrefix, _IP6AddrPrefix):
class LabelledVPNIPAddrPrefix(_LabelledAddrPrefix, _VPNAddrPrefix,
                              _IPAddrPrefix):
class LabelledVPNIP6AddrPrefix(_LabelledAddrPrefix, _VPNAddrPrefix,
                               _IP6AddrPrefix):
class RouteTargetMembershipNLRI(StringifyMixin):
class _OptParam(StringifyMixin, _TypeDisp, _Value):
class BGPOptParamUnknown(_OptParam):
class _OptParamCapability(_OptParam, _TypeDisp):
class _OptParamEmptyCapability(_OptParamCapability):
class BGPOptParamCapabilityUnknown(_OptParamCapability):
class BGPOptParamCapabilityRouteRefresh(_OptParamEmptyCapability):
class BGPOptParamCapabilityCiscoRouteRefresh(_OptParamEmptyCapability):
class BGPOptParamCapabilityEnhancedRouteRefresh(_OptParamEmptyCapability):
class BGPOptParamCapabilityGracefulRestart(_OptParamCapability):
class BGPOptParamCapabilityFourOctetAsNumber(_OptParamCapability):
class BGPOptParamCapabilityMultiprotocol(_OptParamCapability):
class BGPOptParamCapabilityCarryingLabelInfo(_OptParamEmptyCapability):
class BGPWithdrawnRoute(IPAddrPrefix):
class _PathAttribute(StringifyMixin, _TypeDisp, _Value):
class BGPPathAttributeUnknown(_PathAttribute):
class _PathAttributeUint32(_PathAttribute):
class BGPPathAttributeOrigin(_PathAttribute):
class _BGPPathAttributeAsPathCommon(_PathAttribute):
class BGPPathAttributeAsPath(_BGPPathAttributeAsPathCommon):
class BGPPathAttributeAs4Path(_BGPPathAttributeAsPathCommon):
class BGPPathAttributeNextHop(_PathAttribute):
class BGPPathAttributeMultiExitDisc(_PathAttributeUint32):
class BGPPathAttributeLocalPref(_PathAttributeUint32):
class BGPPathAttributeAtomicAggregate(_PathAttribute):
class _BGPPathAttributeAggregatorCommon(_PathAttribute):
class BGPPathAttributeAggregator(_BGPPathAttributeAggregatorCommon):
class BGPPathAttributeAs4Aggregator(_BGPPathAttributeAggregatorCommon):
class BGPPathAttributeCommunities(_PathAttribute):
class BGPPathAttributeOriginatorId(_PathAttribute):
class BGPPathAttributeClusterList(_PathAttribute):
class BGPPathAttributeExtendedCommunities(_PathAttribute):
class _ExtendedCommunity(StringifyMixin, _TypeDisp, _Value):
class BGPTwoOctetAsSpecificExtendedCommunity(_ExtendedCommunity):
class BGPIPv4AddressSpecificExtendedCommunity(_ExtendedCommunity):
class BGPFourOctetAsSpecificExtendedCommunity(_ExtendedCommunity):
class BGPOpaqueExtendedCommunity(_ExtendedCommunity):
class BGPUnknownExtendedCommunity(_ExtendedCommunity):
class BGPPathAttributeMpReachNLRI(_PathAttribute):
class BGPPathAttributeMpUnreachNLRI(_PathAttribute):
class BGPNLRI(IPAddrPrefix):
class BGPMessage(packet_base.PacketBase, _TypeDisp):
class BGPOpen(BGPMessage):
class BGPUpdate(BGPMessage):
class BGPKeepAlive(BGPMessage):
class BGPNotification(BGPMessage):
class BGPRouteRefresh(BGPMessage):
class StreamParser(stream_parser.StreamParser):
    def do_init(cls, self, kwargs, **extra_kwargs):
    def parse_value(cls, buf):
    def serialize_value(self):
    def register_unknown_type(cls):
        def _register_type(subcls):
    def register_type(cls, type_):
        def _register_type(subcls):
    def _lookup_type(cls, type_):
    def _rev_lookup_type(cls, targ_cls):
    def __init__(self, data=''):
    def __str__(self):
    def __init__(self, msg_type_code, message_length):
    def __str__(self):
    def __init__(self, msg_type):
    def __str__(self):
    def __init__(self, locally_support_version):
    def __init__(self, pattr_type_code):
    def __init__(self, afi, safi):
    def __cmp__(self, other):
def get_rf(afi, safi):
def pad(bin, len_):
    def __init__(self, type_, admin=0, assigned=0):
    def parser(cls, buf):
    def from_str(cls, str_):
    def serialize(self):
    def formatted_str(self):
    def __init__(self, type_=_RouteDistinguisher.TWO_OCTET_AS, **kwargs):
    def __init__(self, type_=_RouteDistinguisher.IPV4_ADDRESS, **kwargs):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, type_=_RouteDistinguisher.FOUR_OCTET_AS,
                 **kwargs):
    def __init__(self, length, addr, prefixes=None):
    def _to_bin(addr):
    def _from_bin(addr):
    def parser(cls, buf):
    def serialize(self):
    def _to_bin(addr):
    def _from_bin(addr):
    def __init__(self, length, addr, labels=[], **kwargs):
    def _label_to_bin(cls, label):
    def _label_from_bin(cls, bin):
    def _to_bin(cls, addr):
    def _has_no_label(cls, bin_):
    def _from_bin(cls, addr):
    def _to_bin(cls, addr):
    def _from_bin(cls, binaddr):
    def _prefix_to_bin(addr):
    def _prefix_from_bin(addr):
    def _prefix_to_bin(addr):
    def _prefix_from_bin(addr):
    def __init__(self, length, addr, prefixes=(), route_dist=0):
    def _prefix_to_bin(cls, addr):
    def _prefix_from_bin(cls, binaddr):
    def prefix(self):
    def formatted_nlri_str(self):
    def prefix(self):
    def formatted_nlri_str(self):
    def prefix(self):
    def route_dist(self):
    def label_list(self):
    def formatted_nlri_str(self):
    def prefix(self):
    def route_dist(self):
    def label_list(self):
    def formatted_nlri_str(self):
    def __init__(self, origin_as, route_target):
    def _is_valid_old_asn(self, asn):
    def _is_valid_ext_comm_attr(self, attr):
    def formatted_nlri_str(self):
    def is_default_rtnlri(self):
    def __cmp__(self, other):
    def parser(cls, buf):
    def serialize(self):
def _get_addr_class(afi, safi):
    def __init__(self, type_, value=None, length=None):
    def parser(cls, buf):
    def serialize(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, cap_code=None, cap_value=None, cap_length=None,
                 type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, flags, time, tuples, **kwargs):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, as_number, **kwargs):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, afi, safi, reserved=0, **kwargs):
    def parse_cap_value(cls, buf):
    def serialize_cap_value(self):
    def __init__(self, value=None, flags=0, type_=None, length=None):
    def parser(cls, buf):
    def serialize(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, value, as_pack_str=None, flags=0, type_=None,
                 length=None):
    def path_seg_list(self):
    def get_as_path_len(self):
    def has_local_as(self, local_as):
    def has_matching_leftmost(self, remote_as):
    def _is_valid_16bit_as_path(cls, buf):
    def parse_value(cls, buf):
    def serialize_value(self):
    def _is_valid_16bit_as_path(cls, buf):
    def parse_value(cls, buf):
    def serialize_value(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, as_number, addr, flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, communities,
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def is_no_export(comm_attr):
    def is_no_advertise(comm_attr):
    def is_no_export_subconfed(comm_attr):
    def has_comm_attr(self, attr):
    def parse_value(cls, buf):
    def serialize_value(self):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, communities,
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def _community_list(self, subtype):
    def rt_list(self):
    def soo_list(self):
    def __init__(self, type_):
    def parse(cls, buf):
    def serialize(self):
    def __init__(self, type_=_ExtendedCommunity.TWO_OCTET_AS_SPECIFIC,
                 **kwargs):
    def __init__(self, type_=_ExtendedCommunity.IPV4_ADDRESS_SPECIFIC,
                 **kwargs):
    def parse_value(cls, buf):
    def serialize_value(self):
    def __init__(self, type_=_ExtendedCommunity.FOUR_OCTET_AS_SPECIFIC,
                 **kwargs):
    def __init__(self, type_=_ExtendedCommunity.OPAQUE,
                 **kwargs):
    def __init__(self, **kwargs):
    def __init__(self, afi, safi, next_hop, nlri,
                 next_hop_len=0, reserved='\0',
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def route_family(self):
    def __init__(self, afi, safi, withdrawn_routes,
                 flags=0, type_=None, length=None):
    def parse_value(cls, buf):
    def serialize_value(self):
    def route_family(self):
    def __init__(self, type_, len_=None, marker=None):
    def parser(cls, buf):
    def serialize(self):
    def __len__(self):
    def __init__(self, my_as, bgp_identifier, type_=BGP_MSG_OPEN,
                 opt_param_len=0, opt_param=[],
                 version=_VERSION, hold_time=0, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def __init__(self, type_=BGP_MSG_UPDATE,
                 withdrawn_routes_len=None,
                 withdrawn_routes=[],
                 total_path_attribute_len=None,
                 path_attributes=[],
                 nlri=[],
                 len_=None, marker=None):
    def pathattr_map(self):
    def get_path_attr(self, attr_name):
    def parser(cls, buf):
    def serialize_tail(self):
    def __init__(self, type_=BGP_MSG_KEEPALIVE, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def __init__(self,
                 error_code,
                 error_subcode,
                 data='',
                 type_=BGP_MSG_NOTIFICATION, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def reason(self):
    def __init__(self,
                 afi, safi, demarcation=0,
                 type_=BGP_MSG_ROUTE_REFRESH, len_=None, marker=None):
    def parser(cls, buf):
    def serialize_tail(self):
    def try_parse(self, data): RF_RTC_UC = RouteFamily(addr_family.IP,
                        subaddr_family.ROUTE_TARGET_CONSTRTAINS) class BGPPathAttributeOrigin(_PathAttribute):
    _VALUE_PACK_STR = '!B'
    _ATTR_FLAGS = BGP_ATTR_FLAG_TRANSITIVE class BGPPathAttributeAsPath(_BGPPathAttributeAsPathCommon):
    # XXX depends on negotiated capability, AS numbers can be 32 bit.
    # while wireshark seems to attempt auto-detect, it seems that
    # there's no way to detect it reliably.  for example, the
    # following byte sequence can be interpreted in two ways.
    #   01 02 99 88 77 66 02 01 55 44
    #   AS_SET num=2 9988 7766 AS_SEQUENCE num=1 5544
    #   AS_SET num=2 99887766 02015544
    # we first check whether AS path can be parsed in 16bit format and if
    # it fails, we try to parse as 32bit
    _AS_PACK_STR = '!H' BGP_ATTR_TYPE_ORIGIN = 1  # 0,1,2 (1 byte) BGP_ATTR_TYPE_AS_PATH = 2  # a list of AS_SET/AS_SEQUENCE  eg. {1 2 3} 4 5 BGP_ATTR_ORIGIN_IGP = 0x00 class IPAddrPrefix(_UnlabelledAddrPrefix, _IPAddrPrefix):
    ROUTE_FAMILY = RF_IPv4_UC
    _TYPE = {
        'ascii': [
            'addr'
        ]
    }

    @property
    def prefix(self):
        return self.addr + '/{0}'.format(self.length)

    @property
    def formatted_nlri_str(self):
        return self.prefix class IP6AddrPrefix(_UnlabelledAddrPrefix, _IP6AddrPrefix):
    ROUTE_FAMILY = RF_IPv6_UC
    _TYPE = {
        'ascii': [
            'addr'
        ]
    }

    @property
    def prefix(self):
        return self.addr + '/{0}'.format(self.length)

    @property
    def formatted_nlri_str(self):
        return self.prefix
import logging
import netaddr
from collections import OrderedDict
from ryu.services.protocols.bgp.base import SUPPORTED_GLOBAL_RF
from ryu.services.protocols.bgp.info_base.rtc import RtcTable
from ryu.services.protocols.bgp.info_base.ipv4 import Ipv4Path
from ryu.services.protocols.bgp.info_base.ipv4 import Ipv4Table
from ryu.services.protocols.bgp.info_base.ipv6 import Ipv6Path
from ryu.services.protocols.bgp.info_base.ipv6 import Ipv6Table
from ryu.services.protocols.bgp.info_base.vpnv4 import Vpnv4Path
from ryu.services.protocols.bgp.info_base.vpnv4 import Vpnv4Table
from ryu.services.protocols.bgp.info_base.vpnv6 import Vpnv6Path
from ryu.services.protocols.bgp.info_base.vpnv6 import Vpnv6Table
from ryu.services.protocols.bgp.info_base.vrf4 import Vrf4Table
from ryu.services.protocols.bgp.info_base.vrf6 import Vrf6Table
from ryu.services.protocols.bgp.rtconf import vrfs
from ryu.services.protocols.bgp.rtconf.vrfs import VRF_RF_IPV4
from ryu.services.protocols.bgp.rtconf.vrfs import VRF_RF_IPV6
from ryu.lib.packet.bgp import RF_IPv4_UC
from ryu.lib.packet.bgp import RF_IPv6_UC
from ryu.lib.packet.bgp import RF_IPv4_VPN
from ryu.lib.packet.bgp import RF_IPv6_VPN
from ryu.lib.packet.bgp import RF_RTC_UC
from ryu.lib.packet.bgp import BGPPathAttributeOrigin
from ryu.lib.packet.bgp import BGPPathAttributeAsPath
from ryu.lib.packet.bgp import BGP_ATTR_TYPE_ORIGIN
from ryu.lib.packet.bgp import BGP_ATTR_TYPE_AS_PATH
from ryu.lib.packet.bgp import BGP_ATTR_ORIGIN_IGP
from ryu.lib.packet.bgp import IPAddrPrefix
from ryu.lib.packet.bgp import IP6AddrPrefix
from ryu.services.protocols.bgp.utils.validation import is_valid_ipv4
from ryu.services.protocols.bgp.utils.validation import is_valid_ipv4_prefix
from ryu.services.protocols.bgp.utils.validation import is_valid_ipv6
from ryu.services.protocols.bgp.utils.validation import is_valid_ipv6_prefix
        from ryu.services.protocols.bgp.core import BgpCoreError
        from ryu.services.protocols.bgp.core import BgpCoreError





LOG = logging.getLogger('bgpspeaker.core_managers.table_mixin')


class TableCoreManager(object):
    """Methods performing core operations on tables."""

    def __init__(self, core_service, common_conf):

        self._tables = {}
        self._rt_mgr = core_service.rt_manager
        self._signal_bus = core_service.signal_bus

        # (VRF) Tables to which the routes with a given route target
        # should be imported.
        #
        # Key: RouteTarget
        # Value: List of tables.
        self._tables_for_rt = {}

        # Global/Default tables, keyed by RouteFamily.
        self._global_tables = {}

        self._core_service = core_service
        self._signal_bus = self._core_service.signal_bus

        # VPN label range
        self._asbr_label_range = common_conf.label_range

        self._next_vpnv4_label = int(self._asbr_label_range[0])

        self._next_hop_label = {}

    @property
    def global_tables(self):
        return self._global_tables

    def remove_vrf_by_vrf_conf(self, vrf_conf):

        route_family = vrf_conf.route_family

        assert route_family in (vrfs.VRF_RF_IPV4, vrfs.VRF_RF_IPV6)