BGP

RFC 4271 BGP-4

exception ryu.lib.packet.bgp.AdminShutdown(data='')

Error to indicate Administrative shutdown.

RFC says: If a BGP speaker decides to administratively shut down its peering with a neighbor, then the speaker SHOULD send a NOTIFICATION message with the Error Code Cease and the Error Subcode 'Administrative Shutdown'.

exception ryu.lib.packet.bgp.AttrFlagError(data='')

Error to indicate recognized path attributes have incorrect flags.

RFC says: If any recognized attribute has Attribute Flags that conflict with the Attribute Type Code, then the Error Subcode MUST be set to Attribute Flags Error. The Data field MUST contain the erroneous attribute (type, length, and value).

class ryu.lib.packet.bgp.BGPEvpnEsImportRTExtendedCommunity(**kwargs)

ES-Import Route Target Extended Community

class ryu.lib.packet.bgp.BGPEvpnEsiLabelExtendedCommunity(label=None, mpls_label=None, vni=None, **kwargs)

ESI Label Extended Community

class ryu.lib.packet.bgp.BGPEvpnMacMobilityExtendedCommunity(**kwargs)

MAC Mobility Extended Community

class ryu.lib.packet.bgp.BGPFlowSpecRedirectCommunity(**kwargs)

Flow Specification Traffic Filtering Actions for Redirect.

Attribute Description
as_number Autonomous System number.
local_administrator Local Administrator.
class ryu.lib.packet.bgp.BGPFlowSpecTrafficActionCommunity(**kwargs)

Flow Specification Traffic Filtering Actions for Traffic Action.

Attribute Description
action Apply action. The supported action are SAMPLE and TERMINAL.
class ryu.lib.packet.bgp.BGPFlowSpecTrafficMarkingCommunity(**kwargs)

Flow Specification Traffic Filtering Actions for Traffic Marking.

Attribute Description
dscp Differentiated Services Code Point.
class ryu.lib.packet.bgp.BGPFlowSpecTrafficRateCommunity(**kwargs)

Flow Specification Traffic Filtering Actions for Traffic Rate.

Attribute Description
as_number Autonomous System number.
rate_info rate information.
class ryu.lib.packet.bgp.BGPKeepAlive(type_=4, len_=None, marker=None)

BGP-4 KEEPALIVE Message encoder/decoder class.

An instance has the following attributes at least. Most of them are same to the on-wire counterparts but in host byte order. __init__ takes the corresponding args in this order.

Attribute Description
marker Marker field. Ignored when encoding.
len Length field. Ignored when encoding.
type Type field. The default is BGP_MSG_KEEPALIVE.
class ryu.lib.packet.bgp.BGPMessage(marker=None, len_=None, type_=None)

Base class for BGP-4 messages.

An instance has the following attributes at least. Most of them are same to the on-wire counterparts but in host byte order. __init__ takes the corresponding args in this order.

Attribute Description
marker Marker field. Ignored when encoding.
len Length field. Ignored when encoding.
type Type field. one of BGP_MSG_* constants.
class ryu.lib.packet.bgp.BGPNotification(error_code, error_subcode, data='', type_=3, len_=None, marker=None)

BGP-4 NOTIFICATION Message encoder/decoder class.

An instance has the following attributes at least. Most of them are same to the on-wire counterparts but in host byte order. __init__ takes the corresponding args in this order.

Attribute Description
marker Marker field. Ignored when encoding.
len Length field. Ignored when encoding.
type Type field. The default is BGP_MSG_NOTIFICATION.
error_code Error code field.
error_subcode Error subcode field.
data Data field. The default is ''.
class ryu.lib.packet.bgp.BGPOpen(my_as, bgp_identifier, type_=1, opt_param_len=0, opt_param=None, version=4, hold_time=0, len_=None, marker=None)

BGP-4 OPEN Message encoder/decoder class.

An instance has the following attributes at least. Most of them are same to the on-wire counterparts but in host byte order. __init__ takes the corresponding args in this order.

Attribute Description
marker Marker field. Ignored when encoding.
len Length field. Ignored when encoding.
type Type field. The default is BGP_MSG_OPEN.
version Version field. The default is 4.
my_as My Autonomous System field. 2 octet unsigned integer.
hold_time Hold Time field. 2 octet unsigned integer. The default is 0.
bgp_identifier BGP Identifier field. An IPv4 address. For example, '192.0.2.1'
opt_param_len Optional Parameters Length field. Ignored when encoding.
opt_param Optional Parameters field. A list of BGPOptParam instances. The default is [].
class ryu.lib.packet.bgp.BGPPathAttributePmsiTunnel(pmsi_flags, tunnel_type, mpls_label=None, label=None, vni=None, tunnel_id=None, flags=0, type_=None, length=None)

P-Multicast Service Interface Tunnel (PMSI Tunnel) attribute

class ryu.lib.packet.bgp.BGPRouteRefresh(afi, safi, demarcation=0, type_=5, len_=None, marker=None)

BGP-4 ROUTE REFRESH Message (RFC 2918) encoder/decoder class.

An instance has the following attributes at least. Most of them are same to the on-wire counterparts but in host byte order. __init__ takes the corresponding args in this order.

Attribute Description
marker Marker field. Ignored when encoding.
len Length field. Ignored when encoding.
type Type field. The default is BGP_MSG_ROUTE_REFRESH.
afi Address Family Identifier
safi Subsequent Address Family Identifier
class ryu.lib.packet.bgp.BGPUpdate(type_=2, withdrawn_routes_len=None, withdrawn_routes=None, total_path_attribute_len=None, path_attributes=None, nlri=None, len_=None, marker=None)

BGP-4 UPDATE Message encoder/decoder class.

An instance has the following attributes at least. Most of them are same to the on-wire counterparts but in host byte order. __init__ takes the corresponding args in this order.

Attribute Description
marker Marker field. Ignored when encoding.
len Length field. Ignored when encoding.
type Type field. The default is BGP_MSG_UPDATE.
withdrawn_routes_len Withdrawn Routes Length field. Ignored when encoding.
withdrawn_routes Withdrawn Routes field. A list of BGPWithdrawnRoute instances. The default is [].
total_path_attribute_len Total Path Attribute Length field. Ignored when encoding.
path_attributes Path Attributes field. A list of BGPPathAttribute instances. The default is [].
nlri Network Layer Reachability Information field. A list of BGPNLRI instances. The default is [].
exception ryu.lib.packet.bgp.BadBgpId(data='')

Error to indicate incorrect BGP Identifier.

RFC says: If the BGP Identifier field of the OPEN message is syntactically incorrect, then the Error Subcode MUST be set to Bad BGP Identifier. Syntactic correctness means that the BGP Identifier field represents a valid unicast IP host address.

exception ryu.lib.packet.bgp.BadMsg(msg_type)

Error to indicate un-recognized message type.

RFC says: If the Type field of the message header is not recognized, then the Error Subcode MUST be set to Bad Message Type. The Data field MUST contain the erroneous Type field.

exception ryu.lib.packet.bgp.BadPeerAs(data='')

Error to indicate open message has incorrect AS number.

RFC says: If the Autonomous System field of the OPEN message is unacceptable, then the Error Subcode MUST be set to Bad Peer AS. The determination of acceptable Autonomous System numbers is configure peer AS.

exception ryu.lib.packet.bgp.BgpExc(data='')

Base bgp exception.

CODE = 0

BGP error code.

SEND_ERROR = True

Flag if set indicates Notification message should be sent to peer.

SUB_CODE = 0

BGP error sub-code.

exception ryu.lib.packet.bgp.CollisionResolution(data='')

Error to indicate Connection Collision Resolution.

RFC says: If a BGP speaker decides to send a NOTIFICATION message with the Error Code Cease as a result of the collision resolution procedure (as described in [BGP-4]), then the subcode SHOULD be set to "Connection Collision Resolution".

exception ryu.lib.packet.bgp.ConnRejected(data='')

Error to indicate Connection Rejected.

RFC says: If a BGP speaker decides to disallow a BGP connection (e.g., the peer is not configured locally) after the speaker accepts a transport protocol connection, then the BGP speaker SHOULD send a NOTIFICATION message with the Error Code Cease and the Error Subcode "Connection Rejected".

class ryu.lib.packet.bgp.EvpnASBasedEsi(as_number, local_disc, type_=None)

AS based ESI value

This type indicates an Autonomous System(AS)-based ESI Value that can be auto-generated or configured by the operator.

class ryu.lib.packet.bgp.EvpnArbitraryEsi(value, type_=None)

Arbitrary 9-octet ESI value

This type indicates an arbitrary 9-octet ESI value, which is managed and configured by the operator.

class ryu.lib.packet.bgp.EvpnEsi(type_=None)

Ethernet Segment Identifier

The supported ESI Types:

  • EvpnEsi.ARBITRARY indicates EvpnArbitraryEsi.
  • EvpnEsi.LACP indicates EvpnLACPEsi.
  • EvpnEsi.L2_BRIDGE indicates EvpnL2BridgeEsi.
  • EvpnEsi.MAC_BASED indicates EvpnMacBasedEsi.
  • EvpnEsi.ROUTER_ID indicates EvpnRouterIDEsi.
  • EvpnEsi.AS_BASED indicates EvpnASBasedEsi.
class ryu.lib.packet.bgp.EvpnEthernetAutoDiscoveryNLRI(route_dist, esi, ethernet_tag_id, mpls_label=None, vni=None, label=None, type_=None, length=None)

Ethernet A-D route type specific EVPN NLRI

class ryu.lib.packet.bgp.EvpnEthernetSegmentNLRI(route_dist, esi, ip_addr, ip_addr_len=None, type_=None, length=None)

Ethernet Segment route type specific EVPN NLRI

class ryu.lib.packet.bgp.EvpnInclusiveMulticastEthernetTagNLRI(route_dist, ethernet_tag_id, ip_addr, ip_addr_len=None, type_=None, length=None)

Inclusive Multicast Ethernet Tag route type specific EVPN NLRI

class ryu.lib.packet.bgp.EvpnIpPrefixNLRI(route_dist, ethernet_tag_id, ip_prefix, esi=None, gw_ip_addr=None, mpls_label=None, vni=None, label=None, type_=None, length=None)

IP Prefix advertisement route NLRI

class ryu.lib.packet.bgp.EvpnL2BridgeEsi(mac_addr, priority, type_=None)

ESI value for Layer 2 Bridge

This type is used in the case of indirectly connected hosts via a bridged LAN between the CEs and the PEs. The ESI Value is auto-generated and determined based on the Layer 2 bridge protocol.

class ryu.lib.packet.bgp.EvpnLACPEsi(mac_addr, port_key, type_=None)

ESI value for LACP

When IEEE 802.1AX LACP is used between the PEs and CEs, this ESI type indicates an auto-generated ESI value determined from LACP.

class ryu.lib.packet.bgp.EvpnMacBasedEsi(mac_addr, local_disc, type_=None)

MAC-based ESI Value

This type indicates a MAC-based ESI Value that can be auto-generated or configured by the operator.

class ryu.lib.packet.bgp.EvpnMacIPAdvertisementNLRI(route_dist, ethernet_tag_id, mac_addr, ip_addr, esi=None, mpls_labels=None, vni=None, labels=None, mac_addr_len=None, ip_addr_len=None, type_=None, length=None)

MAC/IP Advertisement route type specific EVPN NLRI

class ryu.lib.packet.bgp.EvpnNLRI(type_=None, length=None)

BGP Network Layer Reachability Information (NLRI) for EVPN

class ryu.lib.packet.bgp.EvpnRouterIDEsi(router_id, local_disc, type_=None)

Router-ID ESI Value

This type indicates a router-ID ESI Value that can be auto-generated or configured by the operator.

class ryu.lib.packet.bgp.EvpnUnknownEsi(value, type_=None)

ESI value for unknown type

class ryu.lib.packet.bgp.EvpnUnknownNLRI(value, type_, length=None)

Unknown route type specific EVPN NLRI

exception ryu.lib.packet.bgp.FiniteStateMachineError(data='')

Error to indicate any Finite State Machine Error.

RFC says: Any error detected by the BGP Finite State Machine (e.g., receipt of an unexpected event) is indicated by sending the NOTIFICATION message with the Error Code Finite State Machine Error.

class ryu.lib.packet.bgp.FlowSpecComponentUnknown(buf, type_=None)

Unknown component type for Flow Specification NLRI component

class ryu.lib.packet.bgp.FlowSpecDSCP(operator, value, type_=None)

Diffserv Code Point for Flow Specification NLRI component

Set the 6-bit DSCP field at value. [RFC2474]

class ryu.lib.packet.bgp.FlowSpecDestPort(operator, value, type_=None)

Destination port number for Flow Specification NLRI component

Set the destination port of a TCP or UDP packet at value.

class ryu.lib.packet.bgp.FlowSpecDestPrefix(length, addr, type_=None)

Destination Prefix for Flow Specification NLRI component

class ryu.lib.packet.bgp.FlowSpecFragment(operator, value, type_=None)

Fragment for Flow Specification NLRI component

Set the bitmask for operand format at value. The following values are supported.

Attribute Description
LF Last fragment
FF First fragment
ISF Is a fragment
DF Don't fragment
class ryu.lib.packet.bgp.FlowSpecIPProtocol(operator, value, type_=None)

IP Protocol for Flow Specification NLRI component

Set the IP protocol number at value.

class ryu.lib.packet.bgp.FlowSpecIPv4NLRI(length=0, rules=None)

Flow Specification NLRI class for IPv4 [RFC 5575]

classmethod from_user(**kwargs)

Utility method for creating a NLRI instance.

This function returns a NLRI instance from human readable format value.

Parameters:kwargs -- The following arguments are available.
Argument Value Operator Description
dst_prefix IPv4 Prefix Nothing Destination Prefix.
src_prefix IPv4 Prefix Nothing Source Prefix.
ip_proto Integer Numeric IP Protocol.
port Integer Numeric Port number.
dst_port Integer Numeric Destination port number.
src_port Integer Numeric Source port number.
icmp_type Integer Numeric ICMP type.
icmp_code Integer Numeric ICMP code.
tcp_flags Fixed string Bitmask TCP flags. Supported values are CWR, ECN, URGENT, ACK, PUSH, RST, SYN and FIN.
packet_len Integer Numeric Packet length.
dscp Integer Numeric Differentiated Services Code Point.
fragment Fixed string Bitmask Fragment. Supported values are DF (Don't fragment), ISF (Is a fragment), FF (First fragment) and LF (Last fragment)

Example:

>>> msg = bgp.FlowSpecIPv4NLRI.from_user(
...     dst_prefix='10.0.0.0/24',
...     src_prefix='20.0.0.1/24',
...     ip_proto=6,
...     port='80 | 8000',
...     dst_port='>9000 & <9050',
...     src_port='>=8500 & <=9000',
...     icmp_type=0,
...     icmp_code=6,
...     tcp_flags='SYN+ACK & !=URGENT',
...     packet_len=1000,
...     dscp='22 | 24',
...     fragment='LF | ==FF')
>>>

You can specify conditions with the following keywords.

The following keywords can be used when the operator type is Numeric.

Keyword Description
< Less than comparison between data and value.
<= Less than or equal to comparison between data and value.
> Greater than comparison between data and value.
>= Greater than or equal to comparison between data and value.
== Equality between data and value. This operator can be omitted.

The following keywords can be used when the operator type is Bitmask.

Keyword Description
!= Not equal operation.
== Exact match operation if specified. Otherwise partial match operation.
+ Used for the summation of bitmask values. (e.g., SYN+ACK)

You can combine the multiple conditions with the following operators.

Keyword Description
| Logical OR operation
& Logical AND operation
Returns:A instance of FlowSpecVPNv4NLRI.
class ryu.lib.packet.bgp.FlowSpecIcmpCode(operator, value, type_=None)

ICMP code Flow Specification NLRI component

Set the code field of an ICMP packet at value.

class ryu.lib.packet.bgp.FlowSpecIcmpType(operator, value, type_=None)

ICMP type for Flow Specification NLRI component

Set the type field of an ICMP packet at value.

class ryu.lib.packet.bgp.FlowSpecPacketLen(operator, value, type_=None)

Packet length for Flow Specification NLRI component

Set the total IP packet length at value.

class ryu.lib.packet.bgp.FlowSpecPort(operator, value, type_=None)

Port number for Flow Specification NLRI component

Set the source or destination TCP/UDP ports at value.

class ryu.lib.packet.bgp.FlowSpecSrcPort(operator, value, type_=None)

Source port number for Flow Specification NLRI component

Set the source port of a TCP or UDP packet at value.

class ryu.lib.packet.bgp.FlowSpecSrcPrefix(length, addr, type_=None)

Source Prefix for Flow Specification NLRI component

class ryu.lib.packet.bgp.FlowSpecTCPFlags(operator, value, type_=None)

TCP flags for Flow Specification NLRI component

Supported TCP flags are CWR, ECN, URGENT, ACK, PUSH, RST, SYN and FIN.

class ryu.lib.packet.bgp.FlowSpecVPNv4NLRI(length=0, route_dist=None, rules=None)

Flow Specification NLRI class for VPNv4 [RFC 5575]

classmethod from_user(route_dist, **kwargs)

Utility method for creating a NLRI instance.

This function returns a NLRI instance from human readable format value.

Parameters:

Example:

>>> msg = bgp.FlowSpecIPv4NLRI.from_user(
...     route_dist='65000:1000',
...     dst_prefix='10.0.0.0/24',
...     src_prefix='20.0.0.1/24',
...     ip_proto=6,
...     port='80 | 8000',
...     dst_port='>9000 & <9050',
...     src_port='>=8500 & <=9000',
...     icmp_type=0,
...     icmp_code=6,
...     tcp_flags='SYN+ACK & !=URGENT',
...     packet_len=1000,
...     dscp='22 | 24',
...     fragment='LF | ==FF')
>>>
exception ryu.lib.packet.bgp.HoldTimerExpired(data='')

Error to indicate Hold Timer expired.

RFC says: If a system does not receive successive KEEPALIVE, UPDATE, and/or NOTIFICATION messages within the period specified in the Hold Time field of the OPEN message, then the NOTIFICATION message with the Hold Timer Expired Error Code is sent and the BGP connection is closed.

exception ryu.lib.packet.bgp.InvalidOriginError(data='')

Error indicates undefined Origin attribute value.

RFC says: If the ORIGIN attribute has an undefined value, then the Error Sub- code MUST be set to Invalid Origin Attribute. The Data field MUST contain the unrecognized attribute (type, length, and value).

exception ryu.lib.packet.bgp.MalformedAsPath(data='')

Error to indicate if AP_PATH attribute is syntactically incorrect.

RFC says: The AS_PATH attribute is checked for syntactic correctness. If the path is syntactically incorrect, then the Error Subcode MUST be set to Malformed AS_PATH.

exception ryu.lib.packet.bgp.MalformedAttrList(data='')

Error to indicate UPDATE message is malformed.

RFC says: Error checking of an UPDATE message begins by examining the path attributes. If the Withdrawn Routes Length or Total Attribute Length is too large (i.e., if Withdrawn Routes Length + Total Attribute Length + 23 exceeds the message Length), then the Error Subcode MUST be set to Malformed Attribute List.

exception ryu.lib.packet.bgp.MalformedOptionalParam(data='')

If recognized optional parameters are malformed.

RFC says: If one of the Optional Parameters in the OPEN message is recognized, but is malformed, then the Error Subcode MUST be set to 0 (Unspecific).

exception ryu.lib.packet.bgp.MissingWellKnown(pattr_type_code)

Error to indicate missing well-known attribute.

RFC says: If any of the well-known mandatory attributes are not present, then the Error Subcode MUST be set to Missing Well-known Attribute. The Data field MUST contain the Attribute Type Code of the missing, well-known attribute.

exception ryu.lib.packet.bgp.OptAttrError(data='')

Error indicates Optional Attribute is malformed.

RFC says: If an optional attribute is recognized, then the value of this attribute MUST be checked. If an error is detected, the attribute MUST be discarded, and the Error Subcode MUST be set to Optional Attribute Error. The Data field MUST contain the attribute (type, length, and value).

class ryu.lib.packet.bgp.PmsiTunnelIdUnknown(value)

Unknown route type specific _PmsiTunnelId

class ryu.lib.packet.bgp.RouteTargetMembershipNLRI(origin_as, route_target)

Route Target Membership NLRI.

Route Target membership NLRI is advertised in BGP UPDATE messages using the MP_REACH_NLRI and MP_UNREACH_NLRI attributes.

class ryu.lib.packet.bgp.StreamParser

Streaming parser for BGP-4 messages.

This is a subclass of ryu.lib.packet.stream_parser.StreamParser. Its parse method returns a list of BGPMessage subclass instances.

exception ryu.lib.packet.bgp.UnacceptableHoldTime(data='')

Error to indicate Unacceptable Hold Time in open message.

RFC says: If the Hold Time field of the OPEN message is unacceptable, then the Error Subcode MUST be set to Unacceptable Hold Time.

exception ryu.lib.packet.bgp.UnsupportedOptParam(data='')

Error to indicate unsupported optional parameters.

RFC says: If one of the Optional Parameters in the OPEN message is not recognized, then the Error Subcode MUST be set to Unsupported Optional Parameters.

exception ryu.lib.packet.bgp.UnsupportedVersion(locally_support_version)

Error to indicate unsupport bgp version number.

RFC says: If the version number in the Version field of the received OPEN message is not supported, then the Error Subcode MUST be set to Unsupported Version Number. The Data field is a 2-octet unsigned integer, which indicates the largest, locally-supported version number less than the version the remote BGP peer bid (as indicated in the received OPEN message), or if the smallest, locally-supported version number is greater than the version the remote BGP peer bid, then the smallest, locally- supported version number.