IPMininet’s documentation!¶
This is a python library, extending Mininet, in order to support emulation of (complex) IP networks. As such it provides new classes, such as Routers, auto-configures all properties not set by the user, such as IP addresses or router configuration files, …
Installation¶
IPMininet needs at minimum:
IPMininet needs some daemon executables to be installed and accessible through the PATH environment variable:
You can either download them by hand or rely on one the following methods:
Virtual Machine¶
We maintain a vagrant box packaged with all the daemons. To use it, first install Vagrant and Virtualbox and then, execute the following commands:
$ vagrant init ipmininet/ubuntu-16.04
$ vagrant up
This will create the VM. To access the VM with SSH, just issue the following command in the same directory as the two previous one:
$ vagrant ssh
Manual installation from PyPI¶
You can download and install IPMininet. If you have pip above 18.1, execute:
$ sudo pip install ipmininet
If you have an older version of pip, use:
$ sudo pip install --process-dependency-links ipmininet
Then, you can install all the daemons:
$ sudo python -m ipmininet.install -af
You can choose to install only a subset of the daemons
by changing the options on the installation script.
For the option documentations, use the -h
option.
Manual installation from sources¶
To manually install IPMininet from source, first get the source code:
$ git clone https://github.com/cnp3/ipmininet.git
$ cd ipmininet
$ git checkout <version>
Then, install IPMininet. If you have pip above 18.1, execute:
$ sudo pip install .
If you have an older version of pip, use:
$ sudo pip install --process-dependency-links .
Finally, you can install all the daemons:
$ sudo python -m ipmininet.install -af
You can choose to install only a subset of the daemons
by changing the options on the installation script.
For the option documentations, use the -h
option.
Getting started¶
To start your network, you need to do two things:
- Creating a topology
- Running the network
Topology creation¶
To create a new topology, we need to declare a class
that extends IPTopo
.
from ipmininet.iptopo import IPTopo
class MyTopology(IPTopo):
pass
Then we extend in its build method to add switches, hosts, routers and links between the nodes.
from ipmininet.iptopo import IPTopo
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
r1 = self.addRouter("r1")
r2 = self.addRouter("r2")
s1 = self.addSwitch("s1")
s2 = self.addSwitch("s2")
h1 = self.addHost("h1")
h2 = self.addHost("h2")
self.addLink(r1, r2)
self.addLink(s1, r1)
self.addLink(h1, s1)
self.addLink(s2, r2)
self.addLink(h2, s2)
super(MyTopology, self).build(*args, **kwargs)
We can add daemons to the routers as well.
from ipmininet.iptopo import IPTopo
from ipmininet.router.config import SSHd
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
r1 = self.addRouter("r1")
r1.addDaemon(SSHd)
# [...]
super(MyTopology, self).build(*args, **kwargs)
By default, OSPF and OSPF6 are launched on each router. This means that your network has basic routing working by default. To change that, we have to modify the router configuration class.
from ipmininet.iptopo import IPTopo
from ipmininet.router.config import SSHd, RouterConfig
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
r1 = self.addRouter("r1", config=RouterConfig)
r1.addDaemon(SSHd)
# [...]
super(MyTopology, self).build(*args, **kwargs)
We can customize the daemons configuration by passing options to them. In the following code snippet, we change the hello interval of the OSPF daemon. You can find the configuration options in Configuring daemons
from ipmininet.iptopo import IPTopo
from ipmininet.router.config import OSPF, RouterConfig
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
r1 = self.addRouter("r1", config=RouterConfig)
r1.addDaemon(OSPF, hello_int=1)
# [...]
super(MyTopology, self).build(*args, **kwargs)
Network run¶
We run the topology by using the following code. The IPCLI object creates a extended Mininet CLI. More details can be found in Command-Line interface As for Mininet, IPMininet networks need root access to be executed.
from ipmininet.ipnet import IPNet
from ipmininet.cli import IPCLI
net = IPNet(topo=MyTopology())
try:
net.start()
IPCLI(net)
finally:
net.stop()
Examples¶
A few documented examples are in examples in the IPMininet repository. More of them can be found in this repository.
Mininet compatibility¶
IPMininet is an upper layer above Mininet. Therefore, everything that works in Mininet, also works in IPMininet. Feel free to consult the Mininet documentation as well.
Command-Line interface¶
Most of the IPMininet CLI functionality is similar to Mininet CLI. We extended it to support IPv6 addressing and routers. For instance, the pingall command will test both IPv4 and IPv6 connectivity between all hosts.
You can find more documentation (valid for both CLIs) on:
However, the mn command won’t start a IPMininet topology but a Mininet one. If you want to try the IPMininet CLI, you can launch the following command:
$ sudo python -m ipmininet.examples --topo simple_ospf_network
To get the complete list of commands, when in the CLI, run:
mininet> help
To get details about a specific command, run:
mininet> help <command>
Configuring daemons¶
We can add daemons to the routers and pass options to them. In the following code snippet, we add BGP daemon to r1.
from ipmininet.iptopo import IPTopo
from ipmininet.router.config import OSPF, OSPF6, RouterConfig
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
r1 = self.addRouter("r1", config=RouterConfig)
r1.addDaemon(OSPF, hello_int=1)
r1.addDaemon(OSPF6, hello_int=1)
# [...]
super(MyTopology, self).build(*args, **kwargs)
This page presents how to configure each daemon.
BGP¶
When adding BGP to a router with router.addDaemon(BGP, **kargs)
, we change the following default parameters:
-
BGP.
set_defaults
(defaults) Parameters: - debug – the set of debug events that should be logged
- address_families – The set of AddressFamily to use
We can declare a set of routers in the same AS by using the overlay AS:
The overlay iBGPFullMesh extends the AS class and allows us to establish iBGP sessions in full mesh between BGP routers.
There are also three helper functions:
- bgp_fullmesh(topo, routers): Establish a full-mesh set of BGP peerings between routers
- bgp_peering(topo, r1, r2): Register a BGP peering between two routers
- ebgp_session(topo, r1, r2): Register an eBGP peering between two routers, and disable IGP adjacencies between them
The following code shows how to use all these abstractions:
from ipmininet.iptopo import IPTopo
from ipmininet.router.config import BGP, bgp_fullmesh, bgp_peering, ebgp_session, RouterConfig
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
# AS1 routers
as1r1 = self.addRouter("as1r1", config=RouterConfig)
as1r1.addDaemon(BGP)
as1r2 = self.addRouter("as1r2", config=RouterConfig)
as1r2.addDaemon(BGP)
as1r3 = self.addRouter("as1r3", config=RouterConfig)
as1r3.addDaemon(BGP)
self.addLink(as1r1, as1r2)
self.addLink(as1r1, as1r3)
self.addLink(as1r2, as1r3)
# AS2 routers
as2r1 = self.addRouter("as2r1", config=RouterConfig)
as2r1.addDaemon(BGP)
as2r2 = self.addRouter("as2r2", config=RouterConfig)
as2r2.addDaemon(BGP)
as2r3 = self.addRouter("as2r3", config=RouterConfig)
as2r3.addDaemon(BGP)
self.addLink(as2r1, as2r2)
self.addLink(as2r1, as2r3)
self.addLink(as2r2, as2r3)
# AS3 routers
as3r1 = self.addRouter("as3r1", config=RouterConfig)
as3r1.addDaemon(BGP)
as3r2 = self.addRouter("as3r2", config=RouterConfig)
as3r2.addDaemon(BGP)
as3r3 = self.addRouter("as3r3", config=RouterConfig)
as3r3.addDaemon(BGP)
self.addLink(as3r1, as3r2)
self.addLink(as3r1, as3r3)
self.addLink(as3r2, as3r3)
# Inter-AS links
self.addLink(as1r1, as2r1)
self.addLink(as2r3, as3r1)
# AS1 is composed of 3 routers that have a full-mesh set of iBGP peering between them
self.addiBGPFullMesh(1, routers=[as1r1, as1r2, as1r3])
# AS2 only has one iBGP session between its routers
self.addAS(2, routers=[as2r1, as2r2, as2r3])
bgp_peering(self, as2r1, as2r3)
# AS3 is also composed of 3 routers that have a full-mesh set of iBGP peering between them
self.addAS(3, routers=[as3r1, as3r2, as3r3])
bgp_fullmesh(self, [as3r1, as3r2, as3r3])
# Establish eBGP sessions between ASes
ebgp_session(self, as1r1, as2r1)
ebgp_session(self, as2r3, as3r1)
super(MyTopology, self).build(*args, **kwargs)
IPTables¶
This is currently mainly a proxy class to generate a list of static rules to pass to iptables. As such, see man iptables and man iptables-extensions to see the various table names, commands, pre-existing chains, …
It takes one parameter:
-
IPTables.
set_defaults
(defaults) Parameters: rules – The (ordered) list of iptables rules that should be executed. If a rule is an iterable of strings, these will be joined using a space.
IP6Tables¶
This class is the IPv6 equivalent to IPTables.
It also takes one parameter:
-
IP6Tables.
set_defaults
(defaults) Parameters: rules – The (ordered) list of iptables rules that should be executed. If a rule is an iterable of strings, these will be joined using a space.
OpenR¶
The OpenR daemon can be tuned by adding keyword arguments to router.addDaemon(OpenR, **kargs)
.
Here is a list of the parameters:
-
OpenrDaemon.
_defaults
(**kwargs) Default parameters of the OpenR daemon. The template file openr.mako sets the default parameters listed here. See: https://github.com/facebook/openr/blob/master/openr/docs/Runbook.md.
Parameters: - alloc_prefix_len – Block size of allocated prefix in terms of it’s prefix length. In this case ‘/80’ prefix will be elected for a node. e.g. ‘face:b00c:0:0:1234::/80’. Default: 128.
- assume_drained – Default: False.
- config_store_filepath – Default: /tmp/aq_persistent_config_store.bin
- decision_debounce_max_ms – Knobs to control how often to run Decision. On receipt of first even debounce is created with MIN time which grows exponentially up to max if there are more events before debounce is executed. This helps us to react to single network failures quickly enough (with min duration) while avoid high CPU utilization under heavy network churn. Default: 250.
- decision_debounce_min_ms – Knobs to control how often to run Decision. On receipt of first even debounce is created with MIN time which grows exponentially up to max if there are more events before debounce is executed. This helps us to react to single network failures quickly enough (with min duration) while avoid high CPU utilization under heavy network churn. Default: 10.
- decision_rep_port – Default: 60004.
- domain – Name of domain this node is part of. OpenR will ‘only’ form adjacencies to OpenR instances within it’s own domain. This option becomes very useful if you want to run OpenR on two nodes adjacent to each other but belonging to different domains, e.g. Data Center and Wide Area Network. Usually it should depict the Network. Default: openr.
- dryrun – OpenR will not try to program routes in it’s default configuration. You should explicitly set this option to false to proceed with route programming. Default: False.
- enable_subnet_validation – OpenR supports subnet validation to avoid mis-cabling of v4 addresses on different subnets on each end of the link. Need to enable v4 and this flag at the same time to turn on validation. Default: True.
- enable_fib_sync – Default: False.
- enable_health_checker – OpenR can measure network health internally by pinging other nodes in the network and exports this information as counters or via breeze APIs. By default health checker is disabled. The expectation is that each node must have at least one v6 loopback addressed announced into the network for the reachability check. Default: False.
- enable_legacy_flooding – Default: True.
- enable_lfa – With this option, additional Loop-Free Alternate (LFA) routes can be computed, per RFC 5286, for fast failure recovery. Under the failure of all primary nexthops for a prefix, because of link failure, next best precomputed LFA will be used without need of an SPF run. Default: False.
- enable_netlink_fib_handler – Knob to enable/disable default implementation of ‘FibService’ that comes along with OpenR for Linux platform. If you want to run your own FIB service then disable this option. Default: True.
- enable_netlink_system_handler – Knob to enable/disable default implementation of ‘SystemService’ and ‘PlatformPublisher’ that comes along with OpenR for Linux platform. If you want to run your own SystemService then disable this option. Default: True.
- enable_perf_measurement – Experimental feature to measure convergence performance. Performance information can be viewed via breeze API ‘breeze perf fib’. Default: True.
- enable_prefix_alloc – Enable prefix allocator to elect and assign a unique prefix for the node. You will need to specify other configuration parameters below. Default: False.
- enable_rtt_metric – Default mechanism for cost of a link is ‘1’ and hence cost of path is hop count. With this option you can ask OpenR to compute and use RTT of a link as a metric value. You should only use this for networks where links have significant delay, on the order of a couple of milliseconds. Using this for point-to-point links will cause lot of churn in metric updates as measured RTT will fluctuate a lot because of packet processing overhead. RTT is measured at application level and hence the fluctuation for point-to-point links. Default: True.
- enable_secure_thrift_server – Flag to enable TLS for our thrift server. Disable this for plaintext thrift. Default: False.
- enable_segment_routing – Experinmental and partially implemented segment routing feature. As of now it only elects node/adjacency labels. In future we will extend it to compute and program FIB routes. Default: False.
- enable_spark – Default: True.
- enable_v4 – OpenR supports v4 as well but it needs to be turned on explicitly. It is expected that each interface will have v4 address configured for link local transport and v4/v6 topologies are congruent. Default: False.
- enable_watchdog – Default: True.
- fib_handler_port – TCP port on which ‘FibService’ will be listening. Default: 60100.
- fib_rep_port – Default: 60009.
- health_checker_ping_interval_s – Configure ping interval of the health checker. The below option configures it to ping all other nodes every 3 seconds. Default: 3.
- health_checker_rep_port – Default: 60012.
- ifname_prefix – Interface prefixes to perform neighbor discovery on. All interfaces whose names start with these are used for neighbor discovery. Default: “”
- iface_regex_exclude – Default:”“.
- iface_regex_include – Default: “”.
- ip_tos – Set type of service (TOS) value with which every control plane packet from Open/R will be marked with. This marking can be used to prioritize control plane traffic (as compared to data plane) so that congestion in network doesn’t affect operations of Open/R. Default: 192
- key_prefix_filters – This comma separated string is used to set the key prefixes when key prefix filter is enabled (See SET_LEAF_NODE). It is also set when requesting KEY_DUMP from peer to request keys that match one of these prefixes. Default: “”.
- kvstore_flood_msg_per_sec – Default: 0.
- kvstore_flood_msg_burst_size – Default: 0.
- kvstore_flood_msg_per_sec – Default: 0.
- kvstore_ttl_decrement_ms – Default: 1.
- kvstore_zmq_hwm – Set buffering size for KvStore socket communication. Updates to neighbor node during flooding can be buffered upto this number. For larger networks where burst of updates can be high having high value makes sense. For smaller networks where burst of updates are low, having low value makes more sense. Default: 65536.
- link_flap_initial_backoff_ms – Default: 1000.
- link_flap_max_backoff_ms – Default: 60000.
- link_monitor_cmd_port – Default: 60006.
- loopback_iface – Indicates loopback address to which auto elected prefix will be assigned if enabled. Default: “lo”.
- memory_limit_mb – Enforce upper limit on amount of memory in mega-bytes that open/r process can use. Above this limit watchdog thread will trigger crash. Service can be auto-restarted via system or some kind of service manager. This is very useful to guarantee protocol doesn’t cause trouble to other services on device where it runs and takes care of slow memory leak kind of issues. Default: 300.
- minloglevel – Log messages at or above this level. Again, the numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. Default: 0.
- node_name – Name of the OpenR node. Cruical setting if you run multiple nodes. Default: “”.
- override_loopback_addr – Whenever new address is elected for a node, before assigning it to interface all previously allocated prefixes or other global prefixes will be overridden with the new one. Use it with care! Default: False.
- prefix_manager_cmd_port – Default: 60011.
- prefixes – Static list of comma separate prefixes to announce from the current node. Can’t be changed while running. Default: “”.
- redistribute_ifaces – Comma separated list of interface names whose ‘/32’ (for v4) and ‘/128’ (for v6) should be announced. OpenR will monitor address add/remove activity on this interface and announce it to rest of the network. Default: “lo1”.
- seed_prefix – In order to elect a prefix for the node a super prefix to elect from is required. This is only applicable when ‘ENABLE_PREFIX_ALLOC’ is set to true. Default: “”.
- set_leaf_node – Sometimes a node maybe a leaf node and have only one path in to network. This node does not require to keep track of the entire topology. In this case, it may be useful to optimize memory by reducing the amount of key/vals tracked by the node. Setting this flag enables key prefix filters defined by KEY_PREFIX_FILTERS. A node only tracks keys in kvstore that matches one of the prefixes in KEY_PREFIX_FILTERS. Default: False.
- set_loopback_address – If set to true along with ‘ENABLE_PREFIX_ALLOC’ then second valid IP address of the block will be assigned onto ‘LOOPBACK_IFACE’ interface. e.g. in this case ‘face:b00c:0:0:1234::1/80’ will be assigned on ‘lo’ interface. Default: False.
- spark_fastinit_keepalive_time_ms – When interface is detected UP, OpenR can perform fast initial neighbor discovery as opposed to slower keep alive packets. Default value is 100 which means neighbor will be discovered within 200ms on a link. Default: 100.
- spark_hold_time_s – Hold time indicating time in seconds from it’s last hello after which neighbor will be declared as down. Default: 30.
- spark_keepalive_time_s – How often to send spark hello messages to neighbors. Default: 3.
- static_prefix_alloc – Default: False.
- tls_acceptable_peers – A comma separated list of strings. Strings are x509 common names to accept SSL connections from. Default: “”
- tls_ecc_curve_name – If we are running an SSL thrift server, this option specifies the eccCurveName for the associated wangle::SSLContextConfig. Default: “prime256v1”.
- tls_ticket_seed_path – If we are running an SSL thrift server, this option specifies the TLS ticket seed file path to use for client session resumption. Default: “”.
- x509_ca_path – If we are running an SSL thrift server, this option specifies the certificate authority path for verifying peers. Default: “”.
- x509_cert_path – If we are running an SSL thrift server, this option specifies the certificate path for the associated wangle::SSLContextConfig. Default: “”.
- x509_key_path – If we are running an SSL thrift server, this option specifies the key path for the associated wangle::SSLContextConfig. Default: “”.
- logbufsecs – Default: 0
- log_dir – Directory to store log files at. The folder must exist. Default: /var/log.
- max_log_size – Default: 1.
- v – Show all verbose ‘VLOG(m)’ messages for m less or equal the value of this flag. Use higher value for more verbose logging. Default: 1.
OSPF¶
You can add keyword arguments to router.addDaemon(OSPF, **kargs)
to change the following parameters:
-
OSPF.
set_defaults
(defaults) Parameters: - debug – the set of debug events that should be logged
- dead_int – Dead interval timer
- hello_int – Hello interval timer
- priority – priority for the interface, used for DR election
- redistribute – set of OSPFRedistributedRoute sources
This daemon also uses the following interface parameters:
- igp_passive: Whether the interface is passive (default value: False)
- ospf_dead_int: Dead interval timer specific to this interface (default value:
dead_int
parameter) - ospf_hello_int: Hello interval timer specific to this interface (default value:
hello_int
parameter) - ospf_priority: Priority for this specific to this interface (default value:
priority
parameter)
OSPF uses two link parameters:
- igp_cost: The IGP cost of the link (default value: 1)
- igp_area: The OSPF area of the link (default value: ‘0.0.0.0’)
We can pass parameters to links and interfaces when calling addLink()
:
from ipmininet.iptopo import IPTopo
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
# Add routers (OSPF daemon is added by default with the default config)
router1 = self.addRouter("router1")
router2 = self.addRouter("router2")
# Add link
l = self.addLink(router1, router2,
igp_cost=5, igp_area="0.0.0.1") # Link parameters
l[router1].addParams(ospf_dead_int=1) # Router1 interface parameters
l[router2].addParams(ospf_priority=1) # Router2 interface parameters
super(MyTopology, self).build(*args, **kwargs)
OSPF can use an overlay to declare with routers or links are completely in a given OSPF area. The following code adds all the interfaces of router r1 to ‘0.0.0.1’ while the link between r2 and r3 is in area ‘0.0.0.5’:
from ipmininet.iptopo import IPTopo
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
# Add routers (OSPF daemon is added by default with the default config)
r1 = self.addRouter("r1")
r2 = self.addRouter("r2")
r3 = self.addRouter("r3")
# Add links
self.addLink(r1, r2)
self.addLink(r1, r3)
self.addLink(r2, r3)
# Define OSPF areas
self.addOSPFArea('0.0.0.1', routers=[r1], links=[])
self.addOSPFArea('0.0.0.5', routers=[], links=[(r2, r3)])
super(MyTopology, self).build(*args, **kwargs)
OSPF6¶
OSPF6 supports the same parameters as OSPF. It supports the following parameter:
-
OSPF6.
set_defaults
(defaults) Parameters: - debug – the set of debug events that should be logged
- dead_int – Dead interval timer
- hello_int – Hello interval timer
- priority – priority for the interface, used for DR election
- redistribute – set of OSPFRedistributedRoute sources
- instance_id – the number of the attached OSPF instance
OSPF6 uses one link parameter:
- igp_cost: The IGP cost of the link (default value: 1)
It uses the following interface parameters:
- igp_passive: Whether the interface is passive (default value: False)
- instance_id: The number of the attached OSPF6 instance (default value: 0)
- ospf6_dead_int: Dead interval timer specific to this interface (default value:
ospf_dead_int
parameter) - ospf6_hello_int: Hello interval timer specific to this interface (default value:
ospf_hello_int
parameter) - ospf6_priority: Priority for this specific to this interface (default value:
ospf_priority
parameter)
from ipmininet.iptopo import IPTopo
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
# Add routers (OSPF daemon is added by default with the default config)
router1 = self.addRouter("router1")
router2 = self.addRouter("router2")
# Add link
l = self.addLink(router1, router2,
igp_cost=5) # Link parameters
l[router1].addParams(ospf6_dead_int=1) # Router1 interface parameters
l[router2].addParams(ospf6_priority=1) # Router2 interface parameters
super(MyTopology, self).build(*args, **kwargs)
PIMD¶
When adding PIMD to a router with router.addDaemon(PIMD, **kargs)
, we can give the following parameters:
-
PIMD.
set_defaults
(defaults) Parameters: - debug – the set of debug events that should be logged
- multicast_ssm – Enable pim ssm mode by default or not
- multicast_igmp – Enable igmp by default or not
RADVD¶
When adding RADVD to a router with router.addDaemon(RADVD, **kargs)
, we can give the following parameters:
-
RADVD.
set_defaults
(defaults) Parameters: debuglevel – Turn on debugging information. Takes an integer between 0 and 5, where 0 completely turns off debugging, and 5 is extremely verbose. (see radvd(8) for more details)
This daemon also uses the following interface parameters:
- ra: A list of AdvPrefix objects that describes the prefixes to advertise
- rdnss: A list of AdvRDNSS objects that describes the DNS servers to advertise
from ipmininet.iptopo import IPTopo
from ipmininet.router.config import RADVD, AdvPrefix, AdvRDNSS
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
r = self.addRouter('r')
r.addDaemon(RADVD, debug=0)
h = self.addHost('h')
dns = self.addHost('dns')
lrh = self.addLink(r, h)
lrh[r].addParams(ip=("2001:1341::1/64", "2001:2141::1/64"),
ra=[AdvPrefix("2001:1341::/64", valid_lifetime=86400, preferred_lifetime=14400),
AdvPrefix("2001:2141::/64")],
rdnss=[AdvRDNSS("2001:89ab::d", max_lifetime=25),
AdvRDNSS("2001:cdef::d", max_lifetime=25)])
lrdns = self.addLink(r, dns)
lrdns[r].addParams(ip=("2001:89ab::1/64", "2001:cdef::1/64")) # Static IP addresses
lrdns[dns].addParams(ip=("2001:89ab::d/64", "2001:cdef::d/64")) # Static IP addresses
super(MyTopology, self).build(*args, **kwargs)
Instead of giving all addresses explicitly, you can use AdvConnectedPrefix() to advertise all the prefixes of the interface. You can also give the name of the DNS server (instead of an IP address) in the AdvRDNSS constructor.
from ipmininet.iptopo import IPTopo
from ipmininet.router.config import RouterConfig, RADVD, AdvConnectedPrefix, AdvRDNSS
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
r = self.addRouter('r')
r.addDaemon(RADVD, debug=0)
h = self.addHost('h')
dns = self.addHost('dns')
lrh = self.addLink(r, h)
lrh[r].addParams(ip=("2001:1341::1/64", "2001:2141::1/64"),
ra=[AdvConnectedPrefix(valid_lifetime=86400, preferred_lifetime=14400)],
rdnss=[AdvRDNSS(dns, max_lifetime=25)])
lrdns = self.addLink(r, dns)
lrdns[r].addParams(ip=("2001:89ab::1/64", "2001:cdef::1/64")) # Static IP addresses
lrdns[dns].addParams(ip=("2001:89ab::d/64", "2001:cdef::d/64")) # Static IP addresses
super(MyTopology, self).build(*args, **kwargs)
SSHd¶
The SSHd daemon does not take any parameter. The SSH private and public keys are randomly generated but you can retrieve their paths with the following line:
from ipmininet.router.config.sshd import KEYFILE, PUBKEY
Zebra¶
FRRouting daemons (i.e., OSPF, OSPF6, BGP and PIMD) require this daemon and automatically trigger it.
So we only need to explicitly add it through router.addDaemon(Zebra, **kargs)
if we want to change one of its parameters:
-
Zebra.
set_defaults
(defaults) Parameters: - debug – the set of debug events that should be logged
- access_lists – The set of AccessList to create, independently from the ones already included by route_maps
- route_maps – The set of RouteMap to create
Configuring IPv4 and IPv6 networks¶
In Mininet, we can only use IPv4 in the emulated network. IPMininet enables the emulation of either IPv6-only or dual-stacked networks.
Dual-stacked networks¶
By default, your network is dual-stacked. It has both IPv4 and IPv6 addresses dynamically assigned by the library. Moreover, both OSPF and OSPF6 daemons are running on each router to ensure basic routing.
from ipmininet.iptopo import IPTopo
from ipmininet.ipnet import IPNet
from ipmininet.cli import IPCLI
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
r1 = self.addRouter("r1")
r2 = self.addRouter("r2")
h1 = self.addHost("h1")
h2 = self.addHost("h2")
self.addLink(h1, r1)
self.addLink(r1, r2)
self.addLink(r2, h2)
super(MyTopology, self).build(*args, **kwargs)
net = IPNet(topo=MyTopology())
try:
net.start()
IPCLI(net)
finally:
net.stop()
If you wait for the network to converge and execute pingall in the IPMininet CLI, you will see that hosts can ping each other in both IPv4 and IPv6. You can also check the routes on the nodes with <nodename> ip [-6|-4] route.
Single-stacked networks¶
You can choose to make a whole network only in IPv4 or in IPv6 by using one parameter in the IPNet constructor. The two following examples show respectively an IPv4-only and IPv6-only network. In single stacked networks, only one of the routing daemons (either OSPF or OSPF6) is launched.
from ipmininet.iptopo import IPTopo
from ipmininet.ipnet import IPNet
from ipmininet.cli import IPCLI
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
r1 = self.addRouter("r1")
r2 = self.addRouter("r2")
h1 = self.addHost("h1")
h2 = self.addHost("h2")
self.addLink(h1, r1)
self.addLink(r1, r2)
self.addLink(r2, h2)
super(MyTopology, self).build(*args, **kwargs)
net = IPNet(topo=MyTopology(), use_v6=False) # This disables IPv6
try:
net.start()
IPCLI(net)
finally:
net.stop()
from ipmininet.iptopo import IPTopo
from ipmininet.ipnet import IPNet
from ipmininet.cli import IPCLI
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
r1 = self.addRouter("r1")
r2 = self.addRouter("r2")
h1 = self.addHost("h1")
h2 = self.addHost("h2")
self.addLink(h1, r1)
self.addLink(r1, r2)
self.addLink(r2, h2)
super(MyTopology, self).build(*args, **kwargs)
net = IPNet(topo=MyTopology(), use_v4=False) # This disables IPv4
try:
net.start()
IPCLI(net)
finally:
net.stop()
Hybrids networks¶
In some cases, it is interesting to have only some parts of the network with IPv6 and/or IPv4. The hosts will have IPv4 (resp. IPv6) routes only if its access router has IPv4 (resp. IPv6) addresses. IPv4-only (resp. IPv6-only) routers won’t have an OSPF (resp. OSPF6) daemon.
from ipmininet.iptopo import IPTopo
from ipmininet.ipnet import IPNet
from ipmininet.cli import IPCLI
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
r1 = self.addRouter("r1")
r2 = self.addRouter("r2", use_v4=False) # This disables IPv4 on the router
r3 = self.addRouter("r3", use_v6=False) # This disables IPv6 on the router
h1 = self.addHost("h1")
h2 = self.addHost("h2")
h3 = self.addHost("h3")
self.addLink(r1, r2)
self.addLink(r1, r3)
self.addLink(r2, r3)
self.addLink(r1, h1)
self.addLink(r2, h2)
self.addLink(r3, h3)
super(MyTopology, self).build(*args, **kwargs)
net = IPNet(topo=MyTopology())
try:
net.start()
IPCLI(net)
finally:
net.stop()
Static addressing¶
Addresses are allocated dynamically by default but you can set your own addresses if you disable auto-allocation when creating the IPNet object.
from ipmininet.iptopo import IPTopo
from ipmininet.ipnet import IPNet
from ipmininet.cli import IPCLI
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
r1 = self.addRouter("r1")
r2 = self.addRouter("r2")
h1 = self.addHost("h1")
h2 = self.addHost("h2")
lr1r2 = self.addLink(r1, r2)
lr1r2[r1].addParams(ip=("2042:12::1/64", "10.12.0.1/24"))
lr1r2[r2].addParams(ip=("2042:12::2/64", "10.12.0.2/24"))
lr1h1 = self.addLink(r1, h1)
lr1h1[r1].addParams(ip=("2042:1a::1/64", "10.51.0.1/24"))
lr1h1[h1].addParams(ip=("2042:1a::a/64", "10.51.0.5/24"))
lr2h2 = self.addLink(r2, h2)
lr2h2[r2].addParams(ip=("2042:2b::2/64", "10.62.0.2/24"))
lr2h2[r2].addParams(ip=("2042:2b::b/64", "10.62.0.6/24"))
super(MyTopology, self).build(*args, **kwargs)
net = IPNet(topo=MyTopology(), allocate_IPs=False) # Disable IP auto-allocation
try:
net.start()
IPCLI(net)
finally:
net.stop()
You can also declare your subnets by declaring a Subnet overlay.
from ipmininet.iptopo import IPTopo
from ipmininet.ipnet import IPNet
from ipmininet.cli import IPCLI
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
r1 = self.addRouter("r1")
r2 = self.addRouter("r2")
h1 = self.addHost("h1")
h2 = self.addHost("h2")
lr1r2 = self.addLink(r1, r2)
self.addLink(r1, h1)
self.addLink(r2, h2)
# The interfaces of the nodes and links on their common LAN
# will get an address for each subnet.
self.addSubnet(nodes=[r1, r2], subnets=["2042:12::/64", "10.12.0.0/24"])
self.addSubnet(nodes=[r1, h1], subnets=["2042:1a::/64", "10.51.0.0/24"])
self.addSubnet(links=[lr1r2], subnets=["2042:2b::/64", "10.62.0.0/24"])
super(MyTopology, self).build(*args, **kwargs)
net = IPNet(topo=MyTopology(), allocate_IPs=False) # Disable IP auto-allocation
try:
net.start()
IPCLI(net)
finally:
net.stop()
Static routing¶
By default, OSPF and OSPF6 are launched on each router. If you want to prevent that, you have to change the router configuration class. You can change it when adding a new router to your topology.
from ipmininet.iptopo import IPTopo
from ipmininet.router.config import RouterConfig, STATIC, StaticRoute
from ipmininet.ipnet import IPNet
from ipmininet.cli import IPCLI
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
# Change the config object for RouterConfig
# because it does not add by default OSPF or OSPF6
r1 = self.addRouter("r1", config=RouterConfig)
r2 = self.addRouter("r2", config=RouterConfig)
h1 = self.addHost("h1")
h2 = self.addHost("h2")
lr1r2 = self.addLink(r1, r2)
lr1r2[r1].addParams(ip=("2042:12::1/64", "10.12.0.1/24"))
lr1r2[r2].addParams(ip=("2042:12::2/64", "10.12.0.2/24"))
lr1h1 = self.addLink(r1, h1)
lr1h1[r1].addParams(ip=("2042:1a::1/64", "10.51.0.1/24"))
lr1h1[h1].addParams(ip=("2042:1a::a/64", "10.51.0.5/24"))
lr2h2 = self.addLink(r2, h2)
lr2h2[r2].addParams(ip=("2042:2b::2/64", "10.62.0.2/24"))
lr2h2[r2].addParams(ip=("2042:2b::b/64", "10.62.0.6/24"))
# Add static routes
r1.addDaemon(STATIC, static_routes=[StaticRoute("2042:2b::/64", "2042:12::2"),
StaticRoute("10.62.0.0/24", "10.12.0.2")])
r2.addDaemon(STATIC, static_routes=[StaticRoute("2042:1a::/64", "2042:12::1"),
StaticRoute("10.51.0.0/24", "10.12.0.1")])
super(MyTopology, self).build(*args, **kwargs)
net = IPNet(topo=MyTopology(), allocate_IPs=False) # Disable IP auto-allocation
try:
net.start()
IPCLI(net)
finally:
net.stop()
You can also add routes manually when the network has started since you can run any command (like in Mininet).
net = IPNet(topo=MyTopology(), allocate_IPs=False) # Disable IP auto-allocation
try:
net.start()
# Static routes
net["r1"].cmd("ip -6 route add 2042:2b::/64 via 2042:12::2")
net["r1"].cmd("ip -4 route add 10.62.0.0/24 via 10.12.0.2")
net["r2"].cmd("ip -6 route add 2042:1a::/64 via 2042:12::1")
net["r2"].cmd("ip -4 route add 10.51.0.0/24 via 10.12.0.1")
IPCLI(net)
finally:
net.stop()
IPMininet API¶
ipmininet package¶
This is a python library, extending [Mininet](http://mininet.org), in order to support emulation of (complex) IP networks. As such it provides new classes, such as Routers, auto-configures all properties not set by the user, such as IP addresses or router configuration files, …
Subpackages¶
ipmininet.install package¶
Submodules¶
-
class
ipmininet.install.utils.
Debian
¶ Bases:
ipmininet.install.utils.Distribution
-
INSTALL_CMD
= 'apt-get -y -q install'¶
-
NAME
= 'Debian'¶
-
PIP2_CMD
= 'pip2'¶
-
PIP3_CMD
= 'pip3'¶
-
UPDATE_CMD
= 'apt-get update'¶
-
-
class
ipmininet.install.utils.
Distribution
¶ Bases:
object
-
INSTALL_CMD
= None¶
-
NAME
= None¶
-
PIP2_CMD
= None¶
-
PIP3_CMD
= None¶
-
SpinPipVersion
= '18.1'¶
-
UPDATE_CMD
= None¶
-
check_pip_version
(pip)¶
-
install
(*packages)¶
-
pip_install
(version, *packages, **kwargs)¶
-
require_pip
(version)¶
-
update
()¶
-
-
class
ipmininet.install.utils.
Fedora
¶ Bases:
ipmininet.install.utils.Distribution
-
INSTALL_CMD
= 'yum -y install'¶
-
NAME
= 'Fedora'¶
-
PIP2_CMD
= 'pip2'¶
-
PIP3_CMD
= 'pip'¶
-
UPDATE_CMD
= 'true'¶
-
-
class
ipmininet.install.utils.
Ubuntu
¶ Bases:
ipmininet.install.utils.Distribution
-
INSTALL_CMD
= 'apt-get -y -q install'¶
-
NAME
= 'Ubuntu'¶
-
PIP2_CMD
= 'pip2'¶
-
PIP3_CMD
= 'pip3'¶
-
UPDATE_CMD
= 'apt-get update'¶
-
-
ipmininet.install.utils.
identify_distribution
()¶
-
ipmininet.install.utils.
sh
(*cmds, **kwargs)¶
-
ipmininet.install.utils.
supported_distributions
()¶
ipmininet.router package¶
This module defines a modular router that is able to support multiple routing daemons
-
class
ipmininet.router.
Router
(name, config=<class 'ipmininet.router.config.base.BasicRouterConfig'>, cwd='/tmp', process_manager=<class 'ipmininet.router.__router.ProcessHelper'>, use_v4=True, use_v6=True, password='zebra', *args, **kwargs)¶ Bases:
mininet.node.Node
,ipmininet.utils.L3Router
The actualy router, which manages a set of daemons
Most of the heavy lifting for this router should happen in the associated config object.
Parameters: - config – The configuration generator for this router. Either a class or a tuple (class, kwargs)
- cwd – The base directory for temporary files such as configs
- process_manager – The class that will manage all the associated processes for this router
- use_v4 – Wether this router has IPv4
- use_v6 – Wether this router has IPv6
- password – The password for the routing daemons vtysh access
-
asn
¶
-
get
(key, val=None)¶ Check for a given key in the router parameters
-
start
()¶ Start the router: Configure the daemons, set the relevant sysctls, and fire up all needed processes
-
terminate
()¶ Stops this router and sets back all sysctls to their old values
-
class
ipmininet.router.
ProcessHelper
(node, *args, **kwargs)¶ Bases:
object
This class holds processes that are part of a given family, e.g. routing daemons. This also provides the abstraction to execute a new process, currently in a mininet namespace, but could be extended to execute in a different environment.
Parameters: node – The object to use to create subprocesses. -
call
(*args, **kwargs)¶ Call a command, wait for it to end and return its ouput.
Parameters: - args – the command + arguments
- kwargs – key-val arguments, as used in subprocess.Popen
-
get_process
(pid)¶ Return a given process handle in this family
Parameters: pid – a process index, as return by popen
-
pexec
(*args, **kw)¶ Call a command, wait for it to terminate and save stdout, stderr and its return code
-
popen
(*args, **kwargs)¶ Call a command and return a Popen handle to it.
Parameters: - args – the command + arguments
- kwargs – key-val arguments, as used in subprocess.Popen
Returns: a process index in this family
-
terminate
()¶ Terminate all processes in this family
-
Subpackages¶
This module holds the configuration generators for routing daemons that can be used in a router.
-
class
ipmininet.router.config.
BasicRouterConfig
(node, daemons=(), additional_daemons=(), *args, **kwargs)¶ Bases:
ipmininet.router.config.base.RouterConfig
A basic router that will run an OSPF daemon
A simple router made of at least an OSPF daemon
Parameters: additional_daemons – Other daemons that should be used
-
class
ipmininet.router.config.
Zebra
(*args, **kwargs)¶ Bases:
ipmininet.router.config.zebra.QuaggaDaemon
-
KILL_PATTERNS
= ('zebra',)¶
-
NAME
= 'zebra'¶
-
PRIO
= 0¶
-
STARTUP_LINE_EXTRA
= '-k'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
has_started
()¶ Return whether this daemon has started or not
-
listening
()¶
-
set_defaults
(defaults)¶ Parameters: - debug – the set of debug events that should be logged
- access_lists – The set of AccessList to create, independently from the ones already included by route_maps
- route_maps – The set of RouteMap to create
-
-
class
ipmininet.router.config.
OSPF
(node, *args, **kwargs)¶ Bases:
ipmininet.router.config.zebra.QuaggaDaemon
This class provides a simple configuration for an OSPF daemon. It advertizes one network per interface (the primary one), and set interfaces not facing another L3Router to passive
-
DEPENDS
= (<class 'ipmininet.router.config.zebra.Zebra'>,)¶
-
KILL_PATTERNS
= ('ospfd',)¶
-
NAME
= 'ospfd'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
is_active_interface
(itf)¶ Return whether an interface is active or not for the OSPF daemon
-
set_defaults
(defaults)¶ Parameters: - debug – the set of debug events that should be logged
- dead_int – Dead interval timer
- hello_int – Hello interval timer
- priority – priority for the interface, used for DR election
- redistribute – set of OSPFRedistributedRoute sources
-
-
class
ipmininet.router.config.
OSPF6
(node, *args, **kwargs)¶ Bases:
ipmininet.router.config.ospf.OSPF
This class provides a simple configuration for an OSPF6 daemon. It advertizes one network per interface (the primary one), and set interfaces not facing another L3Router to passive
-
DEAD_INT
= 3¶
-
KILL_PATTERNS
= ('ospf6d',)¶
-
NAME
= 'ospf6d'¶
-
set_defaults
(defaults)¶ Parameters: - debug – the set of debug events that should be logged
- dead_int – Dead interval timer
- hello_int – Hello interval timer
- priority – priority for the interface, used for DR election
- redistribute – set of OSPFRedistributedRoute sources
- instance_id – the number of the attached OSPF instance
-
-
class
ipmininet.router.config.
OSPFArea
(area, routers=(), links=(), **props)¶ Bases:
ipmininet.overlay.Overlay
An overlay to group OSPF links and routers by area
Parameters: - area – the area for this overlay
- routers – the set of routers for which all their interfaces belong to that area
- links – individual links belonging to this area
-
apply
(topo)¶ Apply the Overlay properties to the given topology
-
area
¶
-
class
ipmininet.router.config.
BGP
(node, port=179, *args, **kwargs)¶ Bases:
ipmininet.router.config.zebra.QuaggaDaemon
This class provides the configuration skeletons for BGP routers.
-
DEPENDS
= (<class 'ipmininet.router.config.zebra.Zebra'>,)¶
-
KILL_PATTERNS
= ('bgpd',)¶
-
NAME
= 'bgpd'¶
-
STARTUP_LINE_EXTRA
¶ We add the port to the standard startup line
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
set_defaults
(defaults)¶ Parameters: - debug – the set of debug events that should be logged
- address_families – The set of AddressFamily to use
-
-
class
ipmininet.router.config.
AS
(asn, routers=(), **props)¶ Bases:
ipmininet.overlay.Overlay
An overlay class that groups routers by AS number
Parameters: - asn – The number for this AS
- routers – an initial set of routers to add to this AS
- props – key-vals to set on all routers of this AS
-
asn
¶
-
class
ipmininet.router.config.
iBGPFullMesh
(asn, routers=(), **props)¶ Bases:
ipmininet.router.config.bgp.AS
An overlay class to establish iBGP sessions in full mesh between BGP routers.
Parameters: - asn – The number for this AS
- routers – an initial set of routers to add to this AS
- props – key-vals to set on all routers of this AS
-
apply
(topo)¶ Apply the Overlay properties to the given topology
-
ipmininet.router.config.
bgp_peering
(topo, a, b)¶ Register a BGP peering between two nodes
-
class
ipmininet.router.config.
RouterConfig
(node, daemons=(), sysctl=None, *args, **kwargs)¶ Bases:
object
This class manages a set of daemons, and generates the global configuration for a router
Initialize our config builder
Parameters: - node – The node for which this object will build configurations
- daemons – an iterable of active routing daemons for this node
- sysctl – A dictionnary of sysctl to set for this node. By default, it enables IPv4/IPv6 forwarding on all interfaces.
-
build
()¶ Build the configuration for each daemon, then write the configuration files
-
cleanup
()¶ Cleanup all temporary files for the daemons
-
compute_routerid
()¶ Computes the default router id for all daemons. If a router ids were explicitly set for some of its daemons, the router id set to the daemon with the highest priority is chosen as the global router id. Otherwise if it has IPv4 addresses, it returns the most-visible one among its router interfaces. If both conditions are wrong, it generates a unique router id.
-
daemon
(key)¶ Return the Daemon object in this config for the given key
Parameters: key – the daemon name or a daemon class or instance Returns: the Daemon object Raises: KeyError – if not found
-
daemons
¶
-
static
incr_last_routerid
()¶
-
register_daemon
(cls, **daemon_opts)¶ Add a new daemon to this configuration
Parameters: - cls – Daemon class or object, or a 2-tuple (Daemon, dict)
- daemon_opts – Options to set on the daemons
-
sysctl
¶ Return an list of all sysctl to set on this node
-
ipmininet.router.config.
bgp_fullmesh
(topo, routers)¶ Establish a full-mesh set of BGP peerings between routers
Parameters: routers – The set of routers peering within each other
-
ipmininet.router.config.
ebgp_session
(topo, a, b)¶ Register an eBGP peering between two nodes, and disable IGP adjacencies between them.
-
class
ipmininet.router.config.
IPTables
(node, **kwargs)¶ Bases:
ipmininet.router.config.base.Daemon
iptables: the default Linux firewall/ACL engine for IPv4. This is currently mainly a proxy class to generate a list of static rules to pass to iptables.
As such, see man iptables and man iptables-extensions to see the various table names, commands, pre-existing chains, …
Parameters: - node – The node for which we build the config
- kwargs – Pre-set options for the daemon, see defaults()
-
NAME
= 'iptables'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
dry_run
¶ The startup line to use to check that the daemon is well-configured
-
set_defaults
(defaults)¶ Parameters: rules – The (ordered) list of iptables rules that should be executed. If a rule is an iterable of strings, these will be joined using a space.
-
startup_line
¶ Return the corresponding startup_line for this daemon
-
class
ipmininet.router.config.
IP6Tables
(node, **kwargs)¶ Bases:
ipmininet.router.config.iptables.IPTables
The IPv6 counterpart to iptables …
Parameters: - node – The node for which we build the config
- kwargs – Pre-set options for the daemon, see defaults()
-
NAME
= 'ip6tables'¶
-
class
ipmininet.router.config.
SSHd
(node, **kwargs)¶ Bases:
ipmininet.router.config.base.Daemon
Parameters: - node – The node for which we build the config
- kwargs – Pre-set options for the daemon, see defaults()
-
KILL_PATTERNS
= ('None -D -u0',)¶
-
NAME
= 'sshd'¶
-
STARTUP_LINE_BASE
= 'None -D -u0'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
dry_run
¶ The startup line to use to check that the daemon is well-configured
-
set_defaults
(defaults)¶ Update defaults to contain the defaults specific to this daemon
-
startup_line
¶ Return the corresponding startup_line for this daemon
-
class
ipmininet.router.config.
RADVD
(node, **kwargs)¶ Bases:
ipmininet.router.config.base.Daemon
The class representing the radvd daemon, used for router advertisements
Parameters: - node – The node for which we build the config
- kwargs – Pre-set options for the daemon, see defaults()
-
KILL_PATTERNS
= ('radvd',)¶
-
NAME
= 'radvd'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
cleanup
()¶ Cleanup the files belonging to this daemon
-
dry_run
¶ The startup line to use to check that the daemon is well-configured
-
set_defaults
(defaults)¶ Parameters: debuglevel – Turn on debugging information. Takes an integer between 0 and 5, where 0 completely turns off debugging, and 5 is extremely verbose. (see radvd(8) for more details)
-
startup_line
¶ Return the corresponding startup_line for this daemon
-
class
ipmininet.router.config.
AdvPrefix
(prefix=(), valid_lifetime=86400, preferred_lifetime=14400)¶ Bases:
ipmininet.router.config.utils.ConfigDict
The class representing advertised prefixes in a Router Advertisement
Parameters: - prefix – the list of IPv6 prefixes to advertise
- valid_lifetime – corresponds to the AdvValidLifetime in radvd.conf(5) for this prefix
- preferred_lifetime – corresponds to the AdvPreferredLifetime in radvd.conf(5) for this prefix
-
class
ipmininet.router.config.
AdvConnectedPrefix
(valid_lifetime=86400, preferred_lifetime=14400)¶ Bases:
ipmininet.router.config.radvd.AdvPrefix
This class forces the advertisement of all prefixes on the interface
Parameters: - valid_lifetime – corresponds to the AdvValidLifetime in radvd.conf(5) for this prefix
- preferred_lifetime – corresponds to the AdvPreferredLifetime in radvd.conf(5) for this prefix
-
class
ipmininet.router.config.
AdvRDNSS
(node, max_lifetime=25)¶ Bases:
ipmininet.router.config.utils.ConfigDict
The class representing an advertised DNS server in a Router Advertisement
Parameters: - node – Either the IPv6 address of the DNS server or the node name
- max_lifetime – corresponds to the AdvValidLifetime in radvd.conf(5) for this dns server address
-
class
ipmininet.router.config.
PIMD
(node, *args, **kwargs)¶ Bases:
ipmininet.router.config.zebra.QuaggaDaemon
This class configures a PIM daemon to responds to IGMP queries in order to setup multicast routing in the network.
-
DEPENDS
= (<class 'ipmininet.router.config.zebra.Zebra'>,)¶
-
KILL_PATTERNS
= ('pimd',)¶
-
NAME
= 'pimd'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
set_defaults
(defaults)¶ Parameters: - debug – the set of debug events that should be logged
- multicast_ssm – Enable pim ssm mode by default or not
- multicast_igmp – Enable igmp by default or not
-
-
class
ipmininet.router.config.
STATIC
(node, **kwargs)¶ Bases:
ipmininet.router.config.zebra.QuaggaDaemon
Parameters: - node – The node for which we build the config
- kwargs – Pre-set options for the daemon, see defaults()
-
DEPENDS
= (<class 'ipmininet.router.config.zebra.Zebra'>,)¶
-
KILL_PATTERNS
= ('staticd',)¶
-
NAME
= 'staticd'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
set_defaults
(defaults)¶ Parameters: - debug – the set of debug events that should be logged
- static_routes – The set of StaticRoute to create
-
class
ipmininet.router.config.
StaticRoute
(prefix, nexthop, distance=10)¶ Bases:
object
A class representing a static route
Parameters: - prefix – The prefix for this static route
- nexthop – The nexthop for this prefix, one of: <IP address, interface name, null0, blackhole, reject>
- distance – The distance metric of the route
-
class
ipmininet.router.config.
OpenrDaemon
(node, **kwargs)¶ Bases:
ipmininet.router.config.base.Daemon
The base class for the OpenR daemon
Parameters: - node – The node for which we build the config
- kwargs – Pre-set options for the daemon, see defaults()
-
NAME
= 'openr'¶
-
STARTUP_LINE_EXTRA
¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
dry_run
¶ The OpenR dryrun runs the daemon and does not shutdown the daemon. As a workaround we only show the version of the openr daemon
-
set_defaults
(defaults)¶ Update defaults to contain the defaults specific to this daemon
-
startup_line
¶ Return the corresponding startup_line for this daemon
-
class
ipmininet.router.config.
Openr
(node, *args, **kwargs)¶ Bases:
ipmininet.router.config.openrd.OpenrDaemon
This class provides a simple configuration for an OpenR daemon.
-
DEPENDS
= (<class 'ipmininet.router.config.openrd.OpenrDaemon'>,)¶
-
KILL_PATTERNS
= ('openr',)¶
-
NAME
= 'openr'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
is_active_interface
(itf)¶ Return whether an interface is active or not for the OpenR daemon
-
set_defaults
(defaults)¶ Updates some options of the OpenR daemon to run a network of routers in mininet. For a full list of parameters see OpenrDaemon:_defaults in openrd.py
-
-
class
ipmininet.router.config.
OpenrDomain
(domain, routers=(), links=(), **props)¶ Bases:
ipmininet.overlay.Overlay
An overlay to group OpenR links and routers by domain
Parameters: - domain – the domain for this overlay
- routers – the set of routers for which all their interfaces belong to that area
- links – individual links belonging to this area
-
apply
(topo)¶ Apply the Overlay properties to the given topology
-
domain
¶
This modules provides a config object for a router, that is able to provide configurations for a set of routing daemons. It also defines the base class for a routing daemon, as well as a minimalistic configuration for a router.
-
class
ipmininet.router.config.base.
BasicRouterConfig
(node, daemons=(), additional_daemons=(), *args, **kwargs)¶ Bases:
ipmininet.router.config.base.RouterConfig
A basic router that will run an OSPF daemon
A simple router made of at least an OSPF daemon
Parameters: additional_daemons – Other daemons that should be used
-
class
ipmininet.router.config.base.
Daemon
(node, **kwargs)¶ Bases:
object
This class serves as base for routing daemons
Parameters: - node – The node for which we build the config
- kwargs – Pre-set options for the daemon, see defaults()
-
DEPENDS
= ()¶
-
KILL_PATTERNS
= ()¶
-
NAME
= None¶
-
PRIO
= 10¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
cfg_filename
¶ Return the filename in which this daemon config should be stored
-
cleanup
()¶ Cleanup the files belonging to this daemon
-
dry_run
¶ The startup line to use to check that the daemon is well-configured
-
has_started
()¶ Return whether this daemon has started or not
-
options
¶ Get the options ConfigDict for this daemon
-
render
(cfg, **kwargs)¶ Render the configuration file for this daemon
Parameters: - cfg – The global config for the node
- kwargs – Additional keywords args. will be passed directly to the template
-
set_defaults
(defaults)¶ Update defaults to contain the defaults specific to this daemon
-
startup_line
¶ Return the corresponding startup_line for this daemon
-
template_filename
¶
-
write
(cfg)¶ Write down the configuration for this daemon
Parameters: cfg – The configuration string
-
class
ipmininet.router.config.base.
RouterConfig
(node, daemons=(), sysctl=None, *args, **kwargs)¶ Bases:
object
This class manages a set of daemons, and generates the global configuration for a router
Initialize our config builder
Parameters: - node – The node for which this object will build configurations
- daemons – an iterable of active routing daemons for this node
- sysctl – A dictionnary of sysctl to set for this node. By default, it enables IPv4/IPv6 forwarding on all interfaces.
-
build
()¶ Build the configuration for each daemon, then write the configuration files
-
cleanup
()¶ Cleanup all temporary files for the daemons
-
compute_routerid
()¶ Computes the default router id for all daemons. If a router ids were explicitly set for some of its daemons, the router id set to the daemon with the highest priority is chosen as the global router id. Otherwise if it has IPv4 addresses, it returns the most-visible one among its router interfaces. If both conditions are wrong, it generates a unique router id.
-
daemon
(key)¶ Return the Daemon object in this config for the given key
Parameters: key – the daemon name or a daemon class or instance Returns: the Daemon object Raises: KeyError – if not found
-
daemons
¶
-
static
incr_last_routerid
()¶
-
register_daemon
(cls, **daemon_opts)¶ Add a new daemon to this configuration
Parameters: - cls – Daemon class or object, or a 2-tuple (Daemon, dict)
- daemon_opts – Options to set on the daemons
-
sysctl
¶ Return an list of all sysctl to set on this node
Base classes to configure a BGP daemon
-
ipmininet.router.config.bgp.
AF_INET
(*args, **kwargs)¶ The ipv4 (unicast) address family
-
ipmininet.router.config.bgp.
AF_INET6
(*args, **kwargs)¶ The ipv6 (unicast) address family
-
class
ipmininet.router.config.bgp.
AS
(asn, routers=(), **props)¶ Bases:
ipmininet.overlay.Overlay
An overlay class that groups routers by AS number
Parameters: - asn – The number for this AS
- routers – an initial set of routers to add to this AS
- props – key-vals to set on all routers of this AS
-
asn
¶
-
class
ipmininet.router.config.bgp.
AddressFamily
(af_name, redistribute=(), networks=(), *args, **kwargs)¶ Bases:
object
An address family that is exchanged through BGP
-
class
ipmininet.router.config.bgp.
BGP
(node, port=179, *args, **kwargs)¶ Bases:
ipmininet.router.config.zebra.QuaggaDaemon
This class provides the configuration skeletons for BGP routers.
-
DEPENDS
= (<class 'ipmininet.router.config.zebra.Zebra'>,)¶
-
KILL_PATTERNS
= ('bgpd',)¶
-
NAME
= 'bgpd'¶
-
STARTUP_LINE_EXTRA
¶ We add the port to the standard startup line
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
set_defaults
(defaults)¶ Parameters: - debug – the set of debug events that should be logged
- address_families – The set of AddressFamily to use
-
-
class
ipmininet.router.config.bgp.
Peer
(base, node, v6=False)¶ Bases:
object
A BGP peer
Parameters: - base – The base router that has this peer
- node – The actual peer
-
ipmininet.router.config.bgp.
bgp_fullmesh
(topo, routers)¶ Establish a full-mesh set of BGP peerings between routers
Parameters: routers – The set of routers peering within each other
-
ipmininet.router.config.bgp.
bgp_peering
(topo, a, b)¶ Register a BGP peering between two nodes
-
ipmininet.router.config.bgp.
ebgp_session
(topo, a, b)¶ Register an eBGP peering between two nodes, and disable IGP adjacencies between them.
-
class
ipmininet.router.config.bgp.
iBGPFullMesh
(asn, routers=(), **props)¶ Bases:
ipmininet.router.config.bgp.AS
An overlay class to establish iBGP sessions in full mesh between BGP routers.
Parameters: - asn – The number for this AS
- routers – an initial set of routers to add to this AS
- props – key-vals to set on all routers of this AS
-
apply
(topo)¶ Apply the Overlay properties to the given topology
This module defines IP(6)Table configuration. Due to the current (sad) state of affairs of IPv6, one is required to explicitely make two different daemon instances, one to manage iptables, one to manage ip6tables …
-
class
ipmininet.router.config.iptables.
IP6Tables
(node, **kwargs)¶ Bases:
ipmininet.router.config.iptables.IPTables
The IPv6 counterpart to iptables …
Parameters: - node – The node for which we build the config
- kwargs – Pre-set options for the daemon, see defaults()
-
NAME
= 'ip6tables'¶
-
class
ipmininet.router.config.iptables.
IPTables
(node, **kwargs)¶ Bases:
ipmininet.router.config.base.Daemon
iptables: the default Linux firewall/ACL engine for IPv4. This is currently mainly a proxy class to generate a list of static rules to pass to iptables.
As such, see man iptables and man iptables-extensions to see the various table names, commands, pre-existing chains, …
Parameters: - node – The node for which we build the config
- kwargs – Pre-set options for the daemon, see defaults()
-
NAME
= 'iptables'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
dry_run
¶ The startup line to use to check that the daemon is well-configured
-
set_defaults
(defaults)¶ Parameters: rules – The (ordered) list of iptables rules that should be executed. If a rule is an iterable of strings, these will be joined using a space.
-
startup_line
¶ Return the corresponding startup_line for this daemon
-
class
ipmininet.router.config.iptables.
Rule
(*args, **kw)¶ Bases:
object
A wrapper to represent an IPTable rule
Parameters: - args – the rule members, which will joined by a whitespace
- table – Specify the table in which the rule should be installed. Defaults to filter.
Base classes to configure an OpenR daemon
-
class
ipmininet.router.config.openr.
Openr
(node, *args, **kwargs)¶ Bases:
ipmininet.router.config.openrd.OpenrDaemon
This class provides a simple configuration for an OpenR daemon.
-
DEPENDS
= (<class 'ipmininet.router.config.openrd.OpenrDaemon'>,)¶
-
KILL_PATTERNS
= ('openr',)¶
-
NAME
= 'openr'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
is_active_interface
(itf)¶ Return whether an interface is active or not for the OpenR daemon
-
set_defaults
(defaults)¶ Updates some options of the OpenR daemon to run a network of routers in mininet. For a full list of parameters see OpenrDaemon:_defaults in openrd.py
-
-
class
ipmininet.router.config.openr.
OpenrDomain
(domain, routers=(), links=(), **props)¶ Bases:
ipmininet.overlay.Overlay
An overlay to group OpenR links and routers by domain
Parameters: - domain – the domain for this overlay
- routers – the set of routers for which all their interfaces belong to that area
- links – individual links belonging to this area
-
apply
(topo)¶ Apply the Overlay properties to the given topology
-
domain
¶
-
class
ipmininet.router.config.openr.
OpenrNetwork
(domain)¶ Bases:
object
A class holding an OpenR network properties
-
class
ipmininet.router.config.openr.
OpenrPrefixes
(prefixes)¶ Bases:
object
A class representing a prefix type in OpenR
-
class
ipmininet.router.config.openrd.
OpenrDaemon
(node, **kwargs)¶ Bases:
ipmininet.router.config.base.Daemon
The base class for the OpenR daemon
Parameters: - node – The node for which we build the config
- kwargs – Pre-set options for the daemon, see defaults()
-
NAME
= 'openr'¶
-
STARTUP_LINE_EXTRA
¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
dry_run
¶ The OpenR dryrun runs the daemon and does not shutdown the daemon. As a workaround we only show the version of the openr daemon
-
set_defaults
(defaults)¶ Update defaults to contain the defaults specific to this daemon
-
startup_line
¶ Return the corresponding startup_line for this daemon
Base classes to configure an OSPF daemon
-
class
ipmininet.router.config.ospf.
OSPF
(node, *args, **kwargs)¶ Bases:
ipmininet.router.config.zebra.QuaggaDaemon
This class provides a simple configuration for an OSPF daemon. It advertizes one network per interface (the primary one), and set interfaces not facing another L3Router to passive
-
DEPENDS
= (<class 'ipmininet.router.config.zebra.Zebra'>,)¶
-
KILL_PATTERNS
= ('ospfd',)¶
-
NAME
= 'ospfd'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
is_active_interface
(itf)¶ Return whether an interface is active or not for the OSPF daemon
-
set_defaults
(defaults)¶ Parameters: - debug – the set of debug events that should be logged
- dead_int – Dead interval timer
- hello_int – Hello interval timer
- priority – priority for the interface, used for DR election
- redistribute – set of OSPFRedistributedRoute sources
-
-
class
ipmininet.router.config.ospf.
OSPFArea
(area, routers=(), links=(), **props)¶ Bases:
ipmininet.overlay.Overlay
An overlay to group OSPF links and routers by area
Parameters: - area – the area for this overlay
- routers – the set of routers for which all their interfaces belong to that area
- links – individual links belonging to this area
-
apply
(topo)¶ Apply the Overlay properties to the given topology
-
area
¶
-
class
ipmininet.router.config.ospf.
OSPFNetwork
(domain, area)¶ Bases:
object
A class holding an OSPF network properties
-
class
ipmininet.router.config.ospf.
OSPFRedistributedRoute
(subtype, metric_type=1, metric=1000)¶ Bases:
object
A class representing a redistributed route type in OSPF
Base classes to configure an OSPF6 daemon
-
class
ipmininet.router.config.ospf6.
OSPF6
(node, *args, **kwargs)¶ Bases:
ipmininet.router.config.ospf.OSPF
This class provides a simple configuration for an OSPF6 daemon. It advertizes one network per interface (the primary one), and set interfaces not facing another L3Router to passive
-
DEAD_INT
= 3¶
-
KILL_PATTERNS
= ('ospf6d',)¶
-
NAME
= 'ospf6d'¶
-
set_defaults
(defaults)¶ Parameters: - debug – the set of debug events that should be logged
- dead_int – Dead interval timer
- hello_int – Hello interval timer
- priority – priority for the interface, used for DR election
- redistribute – set of OSPFRedistributedRoute sources
- instance_id – the number of the attached OSPF instance
-
-
class
ipmininet.router.config.ospf6.
OSPF6RedistributedRoute
(subtype, metric_type=1, metric=1000)¶ Bases:
ipmininet.router.config.ospf.OSPFRedistributedRoute
A class representing a redistributed route type in OSPF6
-
class
ipmininet.router.config.pimd.
PIMD
(node, *args, **kwargs)¶ Bases:
ipmininet.router.config.zebra.QuaggaDaemon
This class configures a PIM daemon to responds to IGMP queries in order to setup multicast routing in the network.
-
DEPENDS
= (<class 'ipmininet.router.config.zebra.Zebra'>,)¶
-
KILL_PATTERNS
= ('pimd',)¶
-
NAME
= 'pimd'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
set_defaults
(defaults)¶ Parameters: - debug – the set of debug events that should be logged
- multicast_ssm – Enable pim ssm mode by default or not
- multicast_igmp – Enable igmp by default or not
-
-
class
ipmininet.router.config.radvd.
AdvConnectedPrefix
(valid_lifetime=86400, preferred_lifetime=14400)¶ Bases:
ipmininet.router.config.radvd.AdvPrefix
This class forces the advertisement of all prefixes on the interface
Parameters: - valid_lifetime – corresponds to the AdvValidLifetime in radvd.conf(5) for this prefix
- preferred_lifetime – corresponds to the AdvPreferredLifetime in radvd.conf(5) for this prefix
-
class
ipmininet.router.config.radvd.
AdvPrefix
(prefix=(), valid_lifetime=86400, preferred_lifetime=14400)¶ Bases:
ipmininet.router.config.utils.ConfigDict
The class representing advertised prefixes in a Router Advertisement
Parameters: - prefix – the list of IPv6 prefixes to advertise
- valid_lifetime – corresponds to the AdvValidLifetime in radvd.conf(5) for this prefix
- preferred_lifetime – corresponds to the AdvPreferredLifetime in radvd.conf(5) for this prefix
-
class
ipmininet.router.config.radvd.
AdvRDNSS
(node, max_lifetime=25)¶ Bases:
ipmininet.router.config.utils.ConfigDict
The class representing an advertised DNS server in a Router Advertisement
Parameters: - node – Either the IPv6 address of the DNS server or the node name
- max_lifetime – corresponds to the AdvValidLifetime in radvd.conf(5) for this dns server address
-
class
ipmininet.router.config.radvd.
RADVD
(node, **kwargs)¶ Bases:
ipmininet.router.config.base.Daemon
The class representing the radvd daemon, used for router advertisements
Parameters: - node – The node for which we build the config
- kwargs – Pre-set options for the daemon, see defaults()
-
KILL_PATTERNS
= ('radvd',)¶
-
NAME
= 'radvd'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
cleanup
()¶ Cleanup the files belonging to this daemon
-
dry_run
¶ The startup line to use to check that the daemon is well-configured
-
set_defaults
(defaults)¶ Parameters: debuglevel – Turn on debugging information. Takes an integer between 0 and 5, where 0 completely turns off debugging, and 5 is extremely verbose. (see radvd(8) for more details)
-
startup_line
¶ Return the corresponding startup_line for this daemon
This module defines an sshd configuration.
-
class
ipmininet.router.config.sshd.
SSHd
(node, **kwargs)¶ Bases:
ipmininet.router.config.base.Daemon
Parameters: - node – The node for which we build the config
- kwargs – Pre-set options for the daemon, see defaults()
-
KILL_PATTERNS
= ('None -D -u0',)¶
-
NAME
= 'sshd'¶
-
STARTUP_LINE_BASE
= 'None -D -u0'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
dry_run
¶ The startup line to use to check that the daemon is well-configured
-
set_defaults
(defaults)¶ Update defaults to contain the defaults specific to this daemon
-
startup_line
¶ Return the corresponding startup_line for this daemon
-
class
ipmininet.router.config.staticd.
STATIC
(node, **kwargs)¶ Bases:
ipmininet.router.config.zebra.QuaggaDaemon
Parameters: - node – The node for which we build the config
- kwargs – Pre-set options for the daemon, see defaults()
-
DEPENDS
= (<class 'ipmininet.router.config.zebra.Zebra'>,)¶
-
KILL_PATTERNS
= ('staticd',)¶
-
NAME
= 'staticd'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
set_defaults
(defaults)¶ Parameters: - debug – the set of debug events that should be logged
- static_routes – The set of StaticRoute to create
-
class
ipmininet.router.config.staticd.
StaticRoute
(prefix, nexthop, distance=10)¶ Bases:
object
A class representing a static route
Parameters: - prefix – The prefix for this static route
- nexthop – The nexthop for this prefix, one of: <IP address, interface name, null0, blackhole, reject>
- distance – The distance metric of the route
This modules contains various utilies to streamline config generation
-
class
ipmininet.router.config.utils.
ConfigDict
(**kwargs)¶ Bases:
dict
A dictionary whose attributes are its keys. Be careful if subclassing, as attributes defined by doing assignments such as self.xx = yy in __init__ will be shadowed!
-
ipmininet.router.config.utils.
ip_statement
(ip)¶ Return the zebra ip statement for a given ip prefix
-
class
ipmininet.router.config.zebra.
AccessList
(name=None, entries=())¶ Bases:
object
A zebra access-list class. It contains a set of AccessListEntry, which describes all prefix belonging or not to this ACL
Setup a new access-list
Parameters: - name – The name of the acl, which will default to acl## where ## is the instance number
- entries – A sequence of AccessListEntry instance, or of ip_interface which describes which prefixes are composing the ACL
-
acl_type
¶ Return the zebra string describing this ACL (access-list, prefix-list, …)
-
count
= 0¶
-
class
ipmininet.router.config.zebra.
AccessListEntry
(prefix, action='permit')¶ Bases:
object
A zebra access-list entry
Parameters: - prefix – The ip_interface prefix for that ACL entry
- action – Wether that prefix belongs to the ACL (PERMIT) or not (DENY)
-
class
ipmininet.router.config.zebra.
QuaggaDaemon
(node, **kwargs)¶ Bases:
ipmininet.router.config.base.Daemon
The base class for all Quagga-derived daemons
Parameters: - node – The node for which we build the config
- kwargs – Pre-set options for the daemon, see defaults()
-
STARTUP_LINE_EXTRA
= ''¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
dry_run
¶ The startup line to use to check that the daemon is well-configured
-
set_defaults
(defaults)¶ Parameters: debug – the set of debug events that should be logged
-
startup_line
¶ Return the corresponding startup_line for this daemon
-
zebra_socket
¶ Return the path towards the zebra API socket for the given node
-
class
ipmininet.router.config.zebra.
RouteMap
(name=None, maps=(), proto=())¶ Bases:
object
A class representing a set of route maps applied to a given protocol
Parameters: - name – The name of the route-map, defaulting to rm##
- maps – A set of RouteMapEntry, or of (action, [acl, acl, …]) tuples that will compose the route map
- proto – The set of protocols to which this route-map applies
-
count
= 0¶
-
describe
¶ Return the zebra description of this route map and apply it to the relevant protocols
-
class
ipmininet.router.config.zebra.
RouteMapEntry
(action='deny', match=(), prio=10)¶ Bases:
object
A class representing a set of match clauses in a route map with an action applied to it
Parameters: - action – Wether routes matching this route map entry will be accepted or not
- match – The set of ACL that will match in this route map entry
- prio – The priority of this route map entry wrt. other in the route map
-
class
ipmininet.router.config.zebra.
Zebra
(*args, **kwargs)¶ Bases:
ipmininet.router.config.zebra.QuaggaDaemon
-
KILL_PATTERNS
= ('zebra',)¶
-
NAME
= 'zebra'¶
-
PRIO
= 0¶
-
STARTUP_LINE_EXTRA
= '-k'¶
-
build
()¶ Build the configuration tree for this daemon
Returns: ConfigDict-like object describing this configuration
-
has_started
()¶ Return whether this daemon has started or not
-
listening
()¶
-
set_defaults
(defaults)¶ Parameters: - debug – the set of debug events that should be logged
- access_lists – The set of AccessList to create, independently from the ones already included by route_maps
- route_maps – The set of RouteMap to create
-
Submodules¶
ipmininet.clean module¶
-
ipmininet.clean.
cleanup
()¶ Cleanup all possible junk that we may have started.
ipmininet.cli module¶
An enhanced CLI providing IP-related commands
-
class
ipmininet.cli.
IPCLI
(mininet, stdin=<_io.TextIOWrapper name='<stdin>' mode='r' encoding='UTF-8'>, script=None)¶ Bases:
mininet.cli.CLI
Start and run interactive or batch mode CLI mininet: Mininet network object stdin: standard input for CLI script: script to run in batch mode
-
default
(line)¶ Called on an input line when the command prefix is not recognized. Overridden to run shell commands when a node is the first CLI argument. Past the first CLI argument, node names are automatically replaced with corresponding addresses if possible. We select only one IP version for these automatic replacements. The chosen IP version chosen is first restricted by the addresses available on the first node. Then, we choose the IP version that enables every replacement. We use IPv4 as a tie-break.
-
do_ip
(line)¶ ip IP1 IP2 …: return the node associated to the given IP
-
do_ips
(line)¶ ips n1 n2 …: return the ips associated to the given node name
-
do_ping4all
(line)¶ Ping (IPv4-only) between all hosts.
-
do_ping4pair
(_line)¶ Ping (IPv4-only) between first two hosts, useful for testing.
-
do_ping6all
(line)¶ Ping (IPv4-only) between all hosts.
-
do_ping6pair
(_line)¶ Ping (IPv6-only) between first two hosts, useful for testing.
-
do_route
(line='')¶ route destination: Print all the routes towards that destination for every router in the network
-
ipmininet.ipnet module¶
IPNet: The Mininet that plays nice with IP networks. This modules will auto-generate all needed configuration properties if unspecified by the user
-
class
ipmininet.ipnet.
BroadcastDomain
(interfaces=None, *args, **kwargs)¶ Bases:
object
An IP broadcast domain in the network. This class stores the set of interfaces belonging to the same broadcast domain, as well as the associated IP prefix if any
Initialize the broadcast domain and optionally explore a set of interfaces
Parameters: interfaces – one Intf or a list of Intf -
BOUNDARIES
= (<class 'mininet.node.Host'>, <class 'ipmininet.router.__router.Router'>)¶
-
explore
(itfs)¶ Explore a new list of interfaces and add them and their neightbors to this broadcast domain
Parameters: itf – a list of Intf
-
static
is_domain_boundary
(node)¶ Check whether the node is a L3 broadcast domain boundary
Parameters: node – a Node instance
-
len_v4
()¶ The number of IPv4 addresses in this broadcast domain
-
len_v6
()¶ The number of IPv6 addresses in this broadcast domain
-
max_v4prefixlen
¶ Return the maximal IPv4 prefix suitable for this domain
-
max_v6prefixlen
¶ Return the maximal IPv6 prefix suitable for this domain
-
next_ipv4
()¶ Allocate and return the next available IPv4 address in this domain
Return ip_interface:
-
next_ipv6
()¶ Allocate and return the next available IPv6 address in this domain
Return ip_interface:
-
routers
¶ List all interfaces in this domain belonging to a L3 router
-
use_ip_version
(ip_version)¶ Checks whether it makes sense to allocate a subnet of an IP version to this domain. If there is no other node allowing it, there is no point in allocating an address to a single host.
Parameters: ip_version – either 4 or 6 Returns: True iif there is more than one interface on the domain enabling this IP version
-
-
class
ipmininet.ipnet.
IPNet
(router=<class 'ipmininet.router.__router.Router'>, config=<class 'ipmininet.router.config.base.BasicRouterConfig'>, use_v4=True, ipBase='192.168.0.0/16', max_v4_prefixlen=24, use_v6=True, ip6Base='fc00::/7', allocate_IPs=True, max_v6_prefixlen=48, igp_metric=1, igp_area='0.0.0.0', link=<class 'ipmininet.link.IPLink'>, intf=<class 'ipmininet.link.IPIntf'>, switch=<class 'mininet.nodelib.LinuxBridge'>, controller=None, *args, **kwargs)¶ Bases:
mininet.net.Mininet
IPNet: An IP-aware Mininet
Extends Mininet by adding IP-related ivars/functions and configuration knobs.
Parameters: - router – The class to use to build routers
- config – The default configuration for the routers
- use_v4 – Enable IPv4
- max_v4_prefixlen – The maximal IPv4 prefix for the auto-allocated broadcast domains
- use_v6 – Enable IPv6
- ip6Base – Base prefix to use for IPv6 allocations
- max_v6_prefixlen – Maximal IPv6 prefixlen to auto-allocate
- allocate_IPs – wether to auto-allocate subnets in the network
- igp_metric – The default IGP metric for the links
- igp_area – The default IGP area for the links
-
addHost
(name, **params)¶ Prevent Mininet from forcing the allocation of IPv4 addresses on hosts. We delegate it to the address auto-allocation of IPNet.
-
addLink
(node1, node2, igp_metric=None, igp_area=None, igp_passive=False, v4_width=1, v6_width=1, *args, **params)¶ Register a link with additional properties
Parameters: - igp_metric – the associated igp metric for this link
- igp_area – the associated igp area for this link
- igp_passive – whether IGP should create adjacencies over this link or not
- v4_width – the number of IPv4 addresses to allocate on the interfaces
- v6_width – the number of IPv6 addresses to allocate on the interfaces
- ra – list of AdvPrefix objects, each one representing an advertised prefix
- rdnss – list of AdvRDNSS objects, each one representing an advertised DNS server
-
addRouter
(name, cls=None, **params)¶ Add a router to the network
Parameters: - name – the node name
- cls – the class to use to instantiate it
-
build
()¶ Build mininet.
-
buildFromTopo
(topo)¶ Build mininet from a topology object At the end of this function, everything should be connected and up.
-
node_for_ip
(ip)¶ Return the node owning a given IP address
Parameters: ip – an IP address Returns: a node name
-
ping
(hosts=None, timeout=None, use_v4=True, use_v6=True)¶ Ping between all specified hosts. If use_v4 is true, pings over IPv4 are used between any pair of hosts having at least one IPv4 address on one of their interfaces (loopback excluded). If use_v6 is true, pings over IPv6 are used between any pair of hosts having at least one non-link-local IPv6 address on one of their interfaces (loopback excluded).
Parameters: - hosts – list of hosts or None if all must be pinged
- timeout – time to wait for a response, as string
- use_v4 – whether IPv4 addresses can be used
- use_v6 – whether IPv6 addresses can be used
Returns: the packet loss percentage of IPv4 connectivity if self.use_v4 is set the loss percentage of IPv6 connectivity otherwise
-
ping4All
(timeout=None)¶ Ping (IPv4-only) between all hosts. return: ploss packet loss percentage
-
ping4Pair
()¶ Ping (IPv4-only) between first two hosts, useful for testing. return: ploss packet loss percentage
-
ping6All
(timeout=None)¶ Ping (IPv6-only) between all hosts. return: ploss packet loss percentage
-
ping6Pair
()¶ Ping (IPv6-only) between first two hosts, useful for testing. return: ploss packet loss percentage
-
pingAll
(timeout=None, use_v4=True, use_v6=True)¶ Ping between all hosts. return: ploss packet loss percentage
-
pingPair
(use_v4=True, use_v6=True)¶ Ping between first two hosts, useful for testing. return: ploss packet loss percentage
-
start
()¶ Start controller and switches.
-
stop
()¶ Stop the controller(s), switches and hosts
ipmininet.iptopo module¶
This module defines topology class that supports adding L3 routers
-
class
ipmininet.iptopo.
IPTopo
(*args, **kwargs)¶ Bases:
mininet.topo.Topo
A topology that supports L3 routers
-
OVERLAYS
= {'AS': <class 'ipmininet.router.config.bgp.AS'>, 'OSPFArea': <class 'ipmininet.router.config.ospf.OSPFArea'>, 'OpenrDomain': <class 'ipmininet.router.config.openr.OpenrDomain'>, 'Subnet': <class 'ipmininet.overlay.Subnet'>, 'iBGPFullMesh': <class 'ipmininet.router.config.bgp.iBGPFullMesh'>}¶
-
addDaemon
(router, daemon, default_cfg_class=<class 'ipmininet.router.config.base.BasicRouterConfig'>, cfg_daemon_list='daemons', **daemon_params)¶ Add the daemon to the list of daemons to start on the router.
Parameters: - router – router name
- daemon – daemon class
- default_cfg_class – config class to use if there is no configuration class defined for the router yet.
- cfg_daemon_list – name of the parameter containing the list of daemons in your config class constructor. For instance, RouterConfig uses ‘daemons’ but BasicRouterConfig uses ‘additional_daemons’.
- daemon_params – all the parameters to give when instantiating the daemon class.
-
addLink
(node1, node2, port1=None, port2=None, key=None, **opts)¶ Parameters: - node1 – first node to link
- node2 – second node to link
- port1 – port of the first node (optional)
- port2 – port of the second node (optional)
- key – a key to identify the link (optional)
- opts – link options (optional)
Returns: link info key
-
addOverlay
(overlay)¶ Add a new overlay on this topology
-
addRouter
(name, **kwargs)¶ Add a router to the topology
Parameters: name – the name of the node
-
build
(*args, **kwargs)¶ Override this method to build your topology.
-
capture_physical_interface
(intfname, node)¶ Adds a pre-existing physical interface to the given node.
-
getLinkInfo
(l, key, default)¶ Attempt to retrieve the information for the given link/key combination. If not found, set to an instance of default and return it
-
getNodeInfo
(n, key, default)¶ Attempt to retrieve the information for the given node/key combination. If not found, set to an instance of default and return it
-
hosts
(sort=True)¶ Return hosts. sort: sort hosts alphabetically returns: list of hosts
-
isNodeType
(n, x)¶ Return wether node n has a key x set to True
Parameters: - n – node name
- x – the key to check
-
isRouter
(n)¶ Check whether the given node is a router
Parameters: n – node name
-
post_build
(net)¶ A method that will be invoced once the topology has been fully built and before it is started.
Parameters: net – The freshly built (Mininet) network
-
routers
(sort=True)¶ Return a list of router node names
-
-
class
ipmininet.iptopo.
IntfDescription
(o, topo, link, intf_attrs)¶ Bases:
ipmininet.iptopo.RouterDescription
-
addParams
(**kwargs)¶
-
-
class
ipmininet.iptopo.
LinkDescription
(topo, src, dst, key, link_attrs)¶ Bases:
object
-
class
ipmininet.iptopo.
OverlayWrapper
(topo, overlay)¶ Bases:
object
-
class
ipmininet.iptopo.
RouterDescription
(o, topo)¶ Bases:
str
-
addDaemon
(daemon, default_cfg_class=<class 'ipmininet.router.config.base.BasicRouterConfig'>, cfg_daemon_list='daemons', **daemon_params)¶ Add the daemon to the list of daemons to start on the router.
Parameters: - daemon – daemon class
- default_cfg_class – config class to use if there is no configuration class defined for the router yet.
- cfg_daemon_list – name of the parameter containing the list of daemons in your config class constructor. For instance, RouterConfig uses ‘daemons’ but BasicRouterConfig uses ‘additional_daemons’.
- daemon_params – all the parameters to give when instantiating the daemon class.
-
ipmininet.link module¶
Classes for interfaces and links that are IP-agnostic. This basically enhance the Intf class from Mininet, and then define sane defaults for the link classes and a new TCIntf base.
-
class
ipmininet.link.
GRETunnel
(if1, if2, if1address, if2address=None, bidirectional=True)¶ Bases:
object
The GRETunnel class, which enables to create a GRE Tunnel in a network linking two existing interfaces.
Currently, these tunnels only define stretched IP subnets.
The instantiation of these tunnels should happen after the network has been built and before the network has been started. You can leverage the IPTopo.post_build method to do it.
Parameters: - if1 – The first interface of the tunnel
- if2 – The second interface of the tunnel
- if1address – The ip_interface address for if1
- if2address – The ip_interface address for if2
- bidirectional – Whether both end of the tunnel should be established or not. GRE is stateless so there is no handshake per-say, however if one end of the tunnel is not established, the kernel will drop by defualt the encapsualted packets.
-
cleanup
()¶
-
setup_tunnel
()¶
-
class
ipmininet.link.
IPIntf
(*args, **kwargs)¶ Bases:
mininet.link.Intf
This class represents a node interface. It is IP-agnostic, as in its addresses attribute is a dictionnary keyed by IP version, containing the list of all addresses for a given version
-
describe
¶ Return a string describing the interface facing this one
-
get
(key, val)¶ Check for a given key in the interface parameters
-
igp_area
¶ Return the igp area associated to this interface
-
igp_metric
¶ Return the igp metric associated to this interface
-
interface_width
¶ Return the number of addresses that should be allocated to this interface, per address family
-
ip
¶
-
ip6
¶ Return the default IPv6 for this interface
-
ip6s
(exclude_lls=False)¶ Return a generator over all IPv6 assigned to this interface
Parameters: exclude_lls – Whether Link-locals should be included or not
-
ips
()¶ Return a generator over all IPv4 assigned to this interface
-
prefixLen
¶
-
prefixLen6
¶ Return the prefix length for the default IPv6 for this interface
-
setIP
(ip, prefixLen=None)¶ Set one or more IP addresses, possibly from different families. This will remove previously set addresses of the affected families.
Parameters: - ip – either an IP string (mininet-like behavior), or an ip_interface like, or a sequence of both
- prefixLen – the prefix length to use for all cases where the addresses is given as a string without a given prefix.
-
setIP6
(ip, prefixLen=None)¶ Set one or more IP addresses, possibly from different families. This will remove previously set addresses of the affected families.
Parameters: - ip – either an IP string (mininet-like behavior), or an ip_interface like, or a sequence of both
- prefixLen – the prefix length to use for all cases where the addresses is given as a string without a given prefix.
-
updateAddr
()¶ Return IP address and MAC address based on ifconfig.
-
updateIP
()¶ Return updated IP address based on ifconfig
-
updateIP6
()¶
-
updateMAC
()¶ Return updated MAC address based on ifconfig
-
-
class
ipmininet.link.
IPLink
(node1, node2, intf=<class 'ipmininet.link.IPIntf'>, *args, **kwargs)¶ Bases:
mininet.link.Link
A Link class that defaults to IPIntf
We override Link intf default to use IPIntf
-
class
ipmininet.link.
OrderedAddress
(addr)¶ Bases:
object
-
class
ipmininet.link.
PhysicalInterface
(name, *args, **kw)¶ Bases:
ipmininet.link.IPIntf
An interface that will wrap around an existing (physical) interface, and try to preserve its addresses. The interface must be present in the root namespace.
-
ipmininet.link.
address_comparator
(a, b)¶ Return -1, 0, 1 if a is less, equally, more visible than b. We define visibility according to IP version, address scope, address class, and address value
ipmininet.overlay module¶
-
class
ipmininet.overlay.
Overlay
(nodes=(), links=(), nprops=None, lprops=None)¶ Bases:
object
This overlay simply defines groups of nodes and links, and properties that are common to all of them. It then registers these properties to the element when apply() is called.
Elements are referenced in the same way than for the IPTopo: node -> node name link -> (node1 name, node2 name).
Parameters: - nodes – The nodes in this overlay
- links – the links in this overlay
- nprops – the properties shared by all nodes in this overlay
- lprops – the properties shared by all links in this overlay
-
add_link
(*link)¶ Add one or more link to this overlay
-
add_node
(*node)¶ Add one or more nodes to this overlay
-
apply
(topo)¶ Apply the Overlay properties to the given topology
-
check_consistency
(topo)¶ Check that this overlay is consistent
-
link_property
(l)¶ Return the properties for the given link
-
node_property
(n)¶ Return the properties for the given node
-
set_link_property
(n, key, val)¶ Set the property of a given link
-
set_node_property
(n, key, val)¶ Set the property of a given node
-
class
ipmininet.overlay.
Subnet
(nodes=(), links=(), subnets=())¶ Bases:
ipmininet.overlay.Overlay
This overlay simply defines groups of routers and hosts that share a common set of subnets. These routers and hosts have to be on the same LAN.
Parameters: - nodes – The routers and hosts that needs an address on their common LAN
- links – The links that has to be in the LAN. This parameter is useful to identify LANs if there is more than one common LAN between the nodes. Routers and Hosts of the links will have an address assigned.
- subnets – For each subnet, an address will be added to the interface of the nodes in their common LAN
-
apply
(topo)¶ Apply the Overlay properties to the given topology
-
check_consistency
(topo)¶ Check that this overlay is consistent
ipmininet.topologydb module¶
This module defines a data-store to help dealing with all (possibly) auto-allocated properties of a topology: ip addresses, router ids, …
-
class
ipmininet.topologydb.
TopologyDB
(db=None, net=None, *args, **kwargs)¶ Bases:
object
A convenience store for auto-allocated mininet properties. This is NOT to be used as IGP graph as it does not reflect the actual availability of a node in the network (as-in it is a static view of the network).
Either extract properties from a network or load a save file
Parameters: - db – a path towards a saved version of this class which will be loaded
- net – an IPNet instance which will be parsed in order to extract useful properties
-
add_host
(n)¶ Register an host
Parameters: n – Host instance
-
add_router
(n)¶ Register an router
Parameters: n – Router instance
-
add_switch
(n)¶ Register an switch
Parameters: n – Switch instance
-
interface
(x, y)¶ Return the ip address of the interface of x facing y
Parameters: - x – the node from which we want an IP address
- y – the node on the other side of the link
Returns: ip_interface-like object
-
interface_bandwidth
(x, y)¶ Return the bandwidth capacity of the interface on node x facing node y.
Parameters: - x – node name
- y – node name
Returns: The bandwidth of link x-y, -1 if unlimited
-
interfaces
(x)¶ Return the list of interface names of node x
-
load
(fpath)¶ Load a topology database
Parameters: fpath – path towards the file to load
-
node
(x)¶
-
parse_net
(net)¶ Stores the content of the given network
Parameters: net – IPNet instance
-
routerid
(x)¶ Return the router id of a node
Parameters: x – router name Returns: the routerid
-
save
(fpath)¶ Save the topology database
Parameters: fpath – the save file name
-
subnet
(x, y)¶ Return the subnet linking node x and y
Parameters: - x – node name
- y – node name
Returns: ip_network-like object
ipmininet.utils module¶
utils: utility functions to manipulate host, interfaces, …
-
class
ipmininet.utils.
L3Router
¶ Bases:
object
Placeholder class to identify L3 routing devices (primarely routers, but this could also be used for a device needing to participate to some routing protocol e.g. for TE purposes)
-
static
is_l3router_intf
(itf)¶ Returns whether an interface belongs to an L3Router (in the Mininet meaning: an intf with an associated node)
-
static
-
ipmininet.utils.
address_pair
(n, use_v4=True, use_v6=True)¶ Returns a tuple (ip, ip6) with ip/ip6 being one of the IPv4/IPv6 addresses of the node n
-
ipmininet.utils.
find_node
(start, node_name)¶ Parameters: - start – The starting node of the search
- node_name – The name of the node to find
Returns: The interface of the node connected to start with node_name as name
-
ipmininet.utils.
get_set
(d, key, default)¶ Attempt to return the value for the given key, otherwise intialize it
Parameters: - d – dict
- default – constructor
-
ipmininet.utils.
has_cmd
(cmd)¶ Return whether the given executable is available on the system or not
-
ipmininet.utils.
is_container
(x)¶ Return whether x is a container (=iterable but not a string)
-
ipmininet.utils.
otherIntf
(intf)¶ “Get the interface on the other side of a link
-
ipmininet.utils.
prefix_for_netmask
(mask)¶ Return the prefix length associated to a given netmask. Will return garbage if the netmask is unproperly formatted!
-
ipmininet.utils.
realIntfList
(n)¶ Return the list of interfaces of node n excluding loopback
-
ipmininet.utils.
require_cmd
(cmd, help_str=None)¶ Ensures that a command is available in $PATH
Parameters: - cmd – the command to test
- help_str – an optional help string to display if cmd is not found