Green Networks: Introduction To Mininet
Green Networks: Introduction To Mininet
Green Networks: Introduction To Mininet
Introduction to Mininet
Dino Lpez
This lab session aims at introducing the Mininet platform, that will be used in this module in
order to deploy Software Defined Network (SDN applications). Mininet is a solution that
provides the needed tools and libraries in order to deploy virtual networks in a single (or
several) physical machine, by mean of a few commands (or a few lines of code). A virtual
Mininet network is composed by Virtual Machines (VMs) or real machines (able to execute
native software), by virtual or real switches or any other forwarding device.
For its aim, Mininet employs very advanced technologies, like Linux Containers and SDN
switches.
4. Once the network of the VM is configured, turn on your VM, wait for the OS to load, and
then log in. The user/password for your mininet guest will be mininet/mininet. Now, open
a terminal in the host PC and connect to mininet by SSH
If everything is working well and you're already connected by SSH to you mininet guest, then
please proceed with the following exercises.
Add to the topology drawn earlier, the NIC label, IP address and network mask associated to
each client.
Can the h1 client be reached by h2? Verify it thank to the ping command. Give the command
that you must issue through the CLI.
To leave from Mininet, you must excute the exit command. Important: if during the
deployment process of the virtual network some errors occur, or if you leave Mininet due to
an error message, the you must clean Mininet with the following command
$ sudo mn c
If you prefer to interact with a Mininet client like you do with a normal computer through a
terminal, the you can
I. Execute Mininet with -x option, that will open an xterm terminal for each deployed
node. E.g. $ sudo mn x
II. Individually open an xterm terminal emulator from the CLI. For instance
mininet> xterm h1 will open xterm for h1
Important! If you're working with the mininet VM by SSH, you must use X option in order to
activate the X11 forwarding, and hence, be able to correctly deploy the xterm terminal
emulator (for instance, ssh X [email protected]).
Custom topologies
What if someone would like to work with a network topology that is not provided by Mininet
templates? In that case, one can easily create the required network topology thanks to the
Python libraries and APIs provided by Mininet. Suppose for instance that we need to create a
client h1 directly connected to a second client named h2, and this last one to a switch s1.
Well, here is the Python code that will solve our problems
from mininet.topo import Topo
class Test_Topo(Topo):
def __init__(self):
"Create custom topology"
# Initialize topology
Topo.__init__(self)
# Add links
self.addLink(h2, s1)
self.addLink(h1, h2)
topos = {
'toptest': (lambda: Test_Topo())
}
Like exercise, write the above code in a toptest.py file and save it in the /home/mininet/
mytopos/ directory (or any one that you prefer). After that, execute the following command
$ sudo mn --custom /home/mininet/mytopos/toptest.py --topo toptest
If the network is successfully created, then you must end in the CLI environment. Open an
xterm for each client (h1 and h2) and explore their NIC configuration. How many interfaces
are attached to h1 and h2? What are the assigned IP addresses? Configure through the CLI the
h1 NIC, as well as the h2 NIC connected to h1 and assign them the IP addresses
192.168.0.1/24 and 192.168.0.2/24 respectively. How can you do to configure the NIC through
the CLI? One option is to use the ifconfig command (please refer to http://
www.tecmint.com/ifconfig-command-examples/ for an example).
Verify the connectivity between h1 and h2. Which command have you used?
Optional exercise: Create a Python script to create the following topology
h1 -------- s1 -------- s2 -------- s3 -------- h2
class Test_Topo(Topo):
topos = {
'toptest': (lambda: Test_Topo())
}
def topTest():
topo = Test_Topo()
net = Mininet(topo=topo, link=TCLink)
net.start()
h1 = net.get('h1')
h2 = net.get('h2')
h2int1 = h2.intf('h2-eth1')
h2.setIP('11.0.0.3', 8, h2int1)
print h1.cmd('ping -c 3 %s' % h2.IP(h2int1))
CLI(net); # this line allows to land into the CLI
net.stop(); # we need to clean up everything before leaving
if __name__ == '__main__':
setLogLevel('info')
topTest()
Please note that this time, we execute our code by directly calling the Python interpreter
$ sudo python /home/mininet/mytopos/toptest.py
As exercises, add the code shown above in your toptest.py file and execute it. Can h1 reach
h2? If h2 is unreachable, provide through the CLI the needed configurations to provide full
connectivity between h1 and h2. Once you have found the way to enable the connectivity
between h1 and h2, modify your Python code in order to execute all those commands
automatically from your script.