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 and hosts as well.
from ipmininet.iptopo import IPTopo
from ipmininet.router.config import SSHd
from ipmininet.host.config import Named
class MyTopology(IPTopo):
def build(self, *args, **kwargs):
r1 = self.addRouter("r1")
r1.addDaemon(SSHd)
h1 = self.addHost("h1")
h1.addDaemon(Named)
# [...]
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()
IPMininet network cleaning¶
If you forget to clean your network with net.stop()
in your script,
your machine can will have ghost daemon process and uncleaned network namespaces.
This can also happen if IPMininet crashes.
In both cases, you have to clean it up with the following command:
sudo python -m ipmininet.clean
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.