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 BGPOptParamCapabilityEnhancedRouteRefresh(_OptParamEmptyCapability):
    pass class BGPOptParamCapabilityMultiprotocol(_OptParamCapability):
    _CAP_PACK_STR = '!HBB'  # afi, reserved, safi

    def __init__(self, afi, safi, reserved=0, **kwargs):
        super(BGPOptParamCapabilityMultiprotocol, self).__init__(**kwargs)
        self.afi = afi
        self.reserved = reserved
        self.safi = safi

    @classmethod
    def parse_cap_value(cls, buf):
        (afi, reserved, safi,) = struct.unpack_from(cls._CAP_PACK_STR,
                                                    six.binary_type(buf))
        return {
            'afi': afi,
            'reserved': reserved,
            'safi': safi,
        }

    def serialize_cap_value(self):
        # fixup
        self.reserved = 0

        buf = bytearray()
        msg_pack_into(self._CAP_PACK_STR, buf, 0,
                      self.afi, self.reserved, self.safi)
        return buf class BGPOptParamCapabilityRouteRefresh(_OptParamEmptyCapability):
    pass BGP_CAP_ENHANCED_ROUTE_REFRESH = 70  # https://tools.ietf.org/html/\ BGP_CAP_MULTIPROTOCOL = 1  # RFC 4760 BGP_CAP_ROUTE_REFRESH = 2  # RFC 2918
from abc import abstractmethod
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 BGPOptParamCapabilityEnhancedRouteRefresh
from ryu.lib.packet.bgp import BGPOptParamCapabilityMultiprotocol
from ryu.lib.packet.bgp import BGPOptParamCapabilityRouteRefresh
from ryu.lib.packet.bgp import BGP_CAP_ENHANCED_ROUTE_REFRESH
from ryu.lib.packet.bgp import BGP_CAP_MULTIPROTOCOL
from ryu.lib.packet.bgp import BGP_CAP_ROUTE_REFRESH
from ryu.services.protocols.bgp.base import OrderedDict
from ryu.services.protocols.bgp.rtconf.base import ADVERTISE_PEER_AS
from ryu.services.protocols.bgp.rtconf.base import BaseConf
from ryu.services.protocols.bgp.rtconf.base import BaseConfListener
from ryu.services.protocols.bgp.rtconf.base import CAP_ENHANCED_REFRESH
from ryu.services.protocols.bgp.rtconf.base import CAP_MBGP_IPV4
from ryu.services.protocols.bgp.rtconf.base import CAP_MBGP_IPV6
from ryu.services.protocols.bgp.rtconf.base import CAP_MBGP_VPNV4
from ryu.services.protocols.bgp.rtconf.base import CAP_MBGP_VPNV6
from ryu.services.protocols.bgp.rtconf.base import CAP_REFRESH
from ryu.services.protocols.bgp.rtconf.base import CAP_RTC
from ryu.services.protocols.bgp.rtconf.base import compute_optional_conf
from ryu.services.protocols.bgp.rtconf.base import ConfigTypeError
from ryu.services.protocols.bgp.rtconf.base import ConfigValueError
from ryu.services.protocols.bgp.rtconf.base import ConfWithId
from ryu.services.protocols.bgp.rtconf.base import ConfWithIdListener
from ryu.services.protocols.bgp.rtconf.base import ConfWithStats
from ryu.services.protocols.bgp.rtconf.base import ConfWithStatsListener
from ryu.services.protocols.bgp.rtconf.base import HOLD_TIME
from ryu.services.protocols.bgp.rtconf.base import MAX_PREFIXES
from ryu.services.protocols.bgp.rtconf.base import MULTI_EXIT_DISC
from ryu.services.protocols.bgp.rtconf.base import RTC_AS
from ryu.services.protocols.bgp.rtconf.base import RuntimeConfigError
from ryu.services.protocols.bgp.rtconf.base import SITE_OF_ORIGINS
from ryu.services.protocols.bgp.rtconf.base import validate
from ryu.services.protocols.bgp.rtconf.base import validate_med
from ryu.services.protocols.bgp.rtconf.base import validate_soo_list
from ryu.services.protocols.bgp.utils.validation import is_valid_ipv4
from ryu.services.protocols.bgp.utils.validation import is_valid_old_asn
from ryu.services.protocols.bgp.info_base.base import Filter
from ryu.services.protocols.bgp.info_base.base import PrefixFilter
from ryu.services.protocols.bgp.info_base.base import AttributeMap
        from ryu.services.protocols.bgp.core_manager import \
            CORE_MANAGER
import logging
import netaddr
import numbers

    @property
    def cap_mbgp_ipv6(self):
        return self._settings[CAP_MBGP_IPV6]

    @property
    def cap_mbgp_vpnv4(self):
        return self._settings[CAP_MBGP_VPNV4]

    @property
    def cap_mbgp_vpnv6(self):
        return self._settings[CAP_MBGP_VPNV6]

    @property
    def cap_rtc(self):
        return self._settings[CAP_RTC]

    @property
    def enabled(self):
        return self._settings[ENABLED]

    @enabled.setter
    def enabled(self, enable):
        # Update enabled flag and notify listeners.
        if self._settings[ENABLED] != enable:
            self._settings[ENABLED] = enable
            self._notify_listeners(NeighborConf.UPDATE_ENABLED_EVT,
                                   enable)

    # =========================================================================
    # Optional attributes with no valid defaults.
    # =========================================================================

    @property
    def multi_exit_disc(self):
        # This property does not have any valid default. Hence if not set we
        # return None.
        return self._settings.get(MULTI_EXIT_DISC)

    @multi_exit_disc.setter
    def multi_exit_disc(self, value):
        if self._settings.get(MULTI_EXIT_DISC) != value:
            self._settings[MULTI_EXIT_DISC] = value
            self._notify_listeners(NeighborConf.UPDATE_MED_EVT, value)

    @property
    def soo_list(self):
        soos = self._settings.get(SITE_OF_ORIGINS)
        if soos:
            soos = list(soos)
        else:
            soos = []
        return soos

    @property
    def rtc_as(self):
        return self._settings[RTC_AS]

    @property
    def in_filter(self):
        return self._settings[IN_FILTER]

    @property
    def out_filter(self):
        return self._settings[OUT_FILTER]

    @property
    def is_route_server_client(self):
        return self._settings[IS_ROUTE_SERVER_CLIENT]

    @property
    def check_first_as(self):
        return self._settings[CHECK_FIRST_AS]

    @property
    def is_next_hop_self(self):
        return self._settings[IS_NEXT_HOP_SELF]

    @property
    def connect_mode(self):
        return self._settings[CONNECT_MODE]

    @connect_mode.setter
    def connect_mode(self, mode):
        self._settings[CONNECT_MODE] = mode
        self._notify_listeners(NeighborConf.UPDATE_CONNECT_MODE_EVT, mode)

    def exceeds_max_prefix_allowed(self, prefix_count):
        allowed_max = self._settings[MAX_PREFIXES]
        does_exceed = False
        # Check if allowed max. is unlimited.
        if allowed_max != 0:
            # If max. prefix is limited, check if given exceeds this limit.
            if prefix_count > allowed_max:
                does_exceed = True

        return does_exceed

    def get_configured_capabilites(self):
        """Returns configured capabilities."""

        capabilities = OrderedDict()
        mbgp_caps = []
        if self.cap_mbgp_ipv4:
            mbgp_caps.append(
                BGPOptParamCapabilityMultiprotocol(
                    RF_IPv4_UC.afi, RF_IPv4_UC.safi))

        if self.cap_mbgp_ipv6:
            mbgp_caps.append(
                BGPOptParamCapabilityMultiprotocol(
                    RF_IPv6_UC.afi, RF_IPv6_UC.safi))

        if self.cap_mbgp_vpnv4:
            mbgp_caps.append(
                BGPOptParamCapabilityMultiprotocol(
                    RF_IPv4_VPN.afi, RF_IPv4_VPN.safi))

        if self.cap_mbgp_vpnv6:
            mbgp_caps.append(

                BGPOptParamCapabilityMultiprotocol(