ipmininet.router.config.exabgp module

class ipmininet.router.config.exabgp.BGPAttribute(attr_type: Union[str, int], val: Union[HexRepresentable, int, str], flags: Optional[BGPAttributeFlags] = None)

Bases: ipmininet.router.config.exabgp.Representable

A BGP attribute as represented in ExaBGP. Either the Attribute is known from ExaBGP and so the class uses its string representation. Or the attribute is not known, then the class uses its hexadecimal representation. The latter representation is also useful to modify flags of already known attributes. For example the MED value is a known attribute which is not transitive. By passing a BGPAttributeFlags object to the constructor, it is now possible to make is transitive with BGPAttributeFlags(1, 1, 0, 0) (both optional and transitive bits are set to 1)

Constructs an Attribute known from ExaBGP or an unknown attribute if flags is not None. It raises a ValueError if the initialisation of BGPAttribute fails. Either because type_attr is not an int (for an unknown attribute), or the string of type_attr is not recognised by ExaBGP (for a known attribute)

Parameters:
  • attr_type – In the case of a Known attribute, attr_type is a valid string recognised by ExaBGP. In the case of an unknown attribute, attr_type is the integer ID of the attribute. If attr_type is a string it must be a valid string recognized by ExaBGP. Valid strings are: ‘next-hop’, ‘origin’, ‘med’, ‘as-path’, ‘local-preference’, ‘atomic-aggregate’, ‘aggregator’, ‘originator-id’, ‘cluster-list’,’community’, ‘large-community’, ‘extended-community’, ‘name’, ‘aigp’
  • val – The actual value of the attribute
  • flags – If None, the BGPAttribute object contains a known attribute from ExaBGP. In this case, the representation of this attribute will be a string. If flags is an instance of BGPAttribute, the hexadecimal representation will be used
hex_repr() → str
str_repr() → str
class ipmininet.router.config.exabgp.BGPAttributeFlags(optional, transitive, partial, extended)

Bases: ipmininet.router.config.exabgp.HexRepresentable

Represents the flags part of a BGP attribute (RFC 4271 section 4.3) The flags are an 8-bits integer value in the form O T P E 0 0 0 0. When :

  • bit O is set to 0: the attribute is Well-Known. If 1, it is optional
  • bit T is set to 0: the attribute is not Transitive. If 1, it is transitive
  • bit P is set to 0: the attribute is complete; If 1, partial
  • bit E is set to 0: the attribute is of length < 256 bits. If set to 1: 256 <= length < 2^{16}

The last 4 bits are unused

This class is notably used to define new attributes unknown from ExaBGP or change the flags of a already known attribute. For example, the MED value is not transitive. To make it transitive, put the transitive bit to 1.

hex_repr()
Returns:The Hexadecimal representation of an BGP attribute value
static to_hex_flags(a, b, c, d)
class ipmininet.router.config.exabgp.BGPRoute(network: ipmininet.router.config.exabgp.Representable, attributes: Sequence[BGPAttribute])

Bases: ipmininet.router.config.exabgp.Representable

A BGP route as represented in ExaBGP

class ipmininet.router.config.exabgp.ExaBGPDaemon(node, port=179, *args, **kwargs)

Bases: ipmininet.router.config.bgp.AbstractBGP

KILL_PATTERNS = ('exabgp',)
NAME = 'exabgp'
STARTUP_LINE_EXTRA
build()

Build the configuration tree for this daemon

Returns:ConfigDict-like object describing this configuration
cfg_filenames

Return the list of filenames in which this daemon config should be stored

dry_run

The startup line to use to check that the daemon is well-configured

env_filename
set_defaults(defaults)

Modifies the default configuration of this ExaBGP daemon

Parameters:
  • env

    a dictionary of all the environment variables that configure ExaBGP. Type “exabgp –help” to take a look on every environment variable. env.tcp.delay is set by default to 2 min as FRRouting BGPD daemon seems to reject routes if ExaBGP injects routes to early. Each environment variable is either a string or an int.

    The following environment variable are set :

    • daemon.user = ‘root’
    • daemon.drop = ‘false’
    • daemon.daemonize = ‘false’
    • daemon.pid = <default configuration folder /tmp/exabgp_<node>.pid>
    • log.level = ‘CRIT’
    • log.destination = <default configuration folder /tmp/exabgp_<node>.log>
    • log.reactor = ‘false’
    • log.processes = false’
    • log.network = ‘false’
    • api.cli = ‘false’
    • tcp.delay = 2 # waits at most 2 minutes
  • address_families – the routes to inject for both IPv4 and IPv6 unicast AFI.
  • passive – Tells to ExaBGP to not send active BGP Open messages. The daemon waits until the remote peer sends first the Open message to start the BGP session. Its default value is set to True.
startup_line

Return the corresponding startup_line for this daemon

template_filenames
class ipmininet.router.config.exabgp.ExaList(lst: List[Union[str, int]])

Bases: ipmininet.router.config.exabgp.HexRepresentable

List that can be represented in a form of string for BGP routes attributes. This class is only used for string representable attribute. That is attribute already defined and known from ExaBGP. If the list is used for an hexadecimal attribute, it raises a ValueError

hex_repr() → str
Returns:The Hexadecimal representation of an BGP attribute value
val
class ipmininet.router.config.exabgp.HexRepresentable

Bases: ipmininet.router.config.exabgp.Representable

Representation of an hexadecimal value for ExaBGP.

In the case of an unknown ExaBGP attribute, the value cannot be interpreted by ExaBGP. Then it is needed to use its hexadecimal representation. This Abstract class must be implemented by any “unrepresentable” BGP attribute.

Example

Imagine you want to represent a new 64-bits attribute. All you have to do is to extend the HexRepresentable class and then create a new BGPAttribute as usual. The following code shows an example:

class LongAttr(HexRepresentable):
    _uint64_max = 18446744073709551615

    def __init__(self, my_long):
        assert 0 <= my_long < LongAttr._uint64_max
        self.val = my_long

    def hex_repr(self):
        return '{0:#0{1}X}'.format(self.val, 18)

    def __str__(self):
        return self.hex_repr()

# your new attribute
my_new_attr = BGPAttribute(42, LongAttr(2658), BGPAttributesFlags(1,1,0,0))
hex_repr() → str
Returns:The Hexadecimal representation of an BGP attribute value
class ipmininet.router.config.exabgp.Representable

Bases: abc.ABC

String representation for ExaBGP configuration Each sub-part of any ExaBGP route must be representable and must override the default __str__ function