generic_vm_objects
This MC contains objects representing generic capability interfaces that may be realized by multiple other Model Components.
Currently, the only object represented in this MC is a generic router object which provides interfaces common to most router platforms.
- Model Component Dependencies::
Available Objects
This module contains MC objects representing generic capability interfaces that may be realized by multiple concrete/image MC objects.
A good example of this is routers. Different types of routers may realize BGP and OSPF connections, so the GenericRouter object is located here.
- class generic_vm_objects.GenericRouter(*args, **kwargs)[source]
Bases:
objectThis MC object represents interfaces common to many/all router platforms. This mostly takes the form of defining routing protocol connections, where the interconnection between routers is formed by a
<protocol>_connect()method that takes the place of the typicalconnect()method.Currently supported protocols are:
By default, routes from one protocol will not propagate to peers using other protocols. However, this object supports explicit definition of route redistribution. “In a router, route redistribution allows a network that uses one routing protocol to route traffic dynamically based on information learned from another routing protocol.” [1] Currently supported redistributions include:
- __annotate_func__ = None
- __annotations_cache__ = {}
- __firstlineno__ = 15
- __init__(*args, **kwargs)
- __static_attributes__ = ('name', 'routing', 'type')
- add_bgp_network(network)[source]
Add a subnet to be advertised by BGP from this router.
- Parameters:
network (str) – The subnet to be advertised, this string can also be a
netaddr.IPNetwork. The format of the string should be in the format of<Network IP>/<netmask>wherenetmaskcan either be CIDR or decimal dot notation. (e.g."192.168.0.0/24"or"192.168.0.0/255.255.255.0")
- enable_dhcp_server(switch)[source]
Enable a DHCP server listening on the interface to the specified Switch.
- Parameters:
switch (base_objects.Switch) – The switch representing the network which will have DHCP.
- get_all_bgp_networks()[source]
Retrieve the list of subnets advertised by BGP on this router.
- Returns:
List of the subnets advertised by BGP.
- Return type:
- get_bgp_as()[source]
Retrieve the ASN used by BGP on this router.
- Returns:
The AS number or a negative value if an error occurred.
- Return type:
- link_bgp(neighbor, switch, neighbor_switch=None)[source]
Connect this router to another as BGP peers.
switchandneighbor_switchare used to determine the IP address of the peers by identifying a single interface. This means they should be the first-hop for this router and neighbor, respectively, so the IP that is on the correct link is addressed in BGP.- Parameters:
neighbor (generic_vm_objects.GenericRouter) – The
Vertexto configure as a BGP peer.switch (base_objects.Switch) – First-hop switch for this router’s connection to neighbor.
neighbor_switch (base_objects.Switch, optional) – First-hop switch for neighbor’s connection to this router. Defaults to
None.
- Raises:
ValueError – Parameters incorrectly typed.
RuntimeError – Trying to establish a BGP connection without an ASN.
RuntimeError – Unable to determine IP address for self or peer.
Exception – Unable to get interfaces for BGP connection.
- ospf_connect(switch, ip, netmask, delay=None, rate=None, rate_unit=None, packet_loss=None, area='0')[source]
Connect this router to a switch, and define OSPF on the connection.
Note
The rate is set as a multiple of bits not bytes. That is, a rate of
1 kbitwould equal 1000 bits, not 1000 bytes. For bytes, multiply the rate by 8 (e.g. 64 KBytes = 8 * 64 = 512 kbit).- Parameters:
switch (base_objects.Switch) – Switch instance to connect to.
ip (str or netaddr.IPAddress) – IP address to use on the connecting interface.
netmask (str or netaddr.IPAddress) – The netmask for the connecting interface. The netmask can either be in Dotted Decimal or CIDR (without the slash) notation. That is, both
"255.255.255.0"and"24"would represent the same netmask.delay (str) – The amount of egress delay to add for the link. This should be formatted like
<delay><unit of delay>. For example,100ms. You must add this in the opposing direction if you want it to be bidirectional.rate (int) – The maximum egress transmission rate (e.g. bandwidth of this link) as a multiple of bits. The
rate_unitshould also be set if the unit is notmbit.rate_unit (str) – The bandwidth unit (one of
{'kbit', 'mbit', 'gbit'}). Defaults to"mbit".packet_loss (int) – Percent of packet loss on the link. For example,
packet_loss = 25is 25% packet loss.area (str) – The OSPF area. Defaults to
"0".
- redistribute_bgp_into_ospf()[source]
Enable redistributing routes from BGP peers to OSPF peers.
- Raises:
Exception – If some unknown error occurs while trying to redistribute routes.
- redistribute_ospf_connected()[source]
Redistribute routes for directly connected subnets to OSPF peers.
- redistribute_ospf_into_bgp()[source]
Enable redistributing routes from OSPF peers to BGP peers.
- Raises:
Exception – If some unknown error occurs while trying to redistribute routes.
- set_bgp_as(as_num)[source]
Set the Autonomous System Number (ASN) used by BGP for this router.
- Parameters:
as_num (str) – AS number, convertible to an integer. Must be valid according to
valid_as().- Raises:
RuntimeError – If the ASN is not valid.