Upload
nshivegowda
View
226
Download
0
Embed Size (px)
Citation preview
8/8/2019 Tp Mininet
http://slidepdf.com/reader/full/tp-mininet 1/6
Green Networks
Introduction to Mininet
Dino López
This lab session aims at introducing the Mininet platform, that will be used in this module inorder to deploy Software Defined Network (SDN applications). Mininet is a solution thatprovides the needed tools and libraries in order to deploy virtual networks in a single (orseveral) physical machine, by mean of a few commands (or a few lines of code). A virtualMininet network is composed by Virtual Machines (VMs) or real machines (able to executenative software), by virtual or real switches or any other forwarding device.
For its aim, Mininet employs very advanced technologies, like Linux Containers and SDNswitches.
Setting up the Mininet platform1. First of all, uncompress the mininet-x86_64.vmdk.gz file with the gunzip command. The
length of the compressed file is around 1.6GB, but once such a file is uncompressed, it willtake around 4.2GB in your file system.
2. Create a new VirtualBox VM, that you can label “mininet” for instance. Select “Linux” inthe OS type and Ubuntu (64 bits) for the Linux version. Regarding the RAM, you can choose1024MB if your physical machine has more than 2GB. Finally, regarding the HD, choose theone that you have uncompressed in step number 1.
3. The created mininet VM, will not have a Windows Manager. However, graphical applications
have been installed inside (e.g. wireshark) that you will probably use in other labs fromthis course itself. So how are you going to proceed in order to correctly use such graphicalsoftwares? The solution that I prefer is configure the network of the VM in the “Host-onlyAdapter” mode and then access it by ssh. In order to do that, in the main window of
VirtualBox click on “File ! Preferences ! Network”, then in the “Host-only Networks”
tab, verify that a module has been already created (e.g. vboxnet0). If the module does notexist, then add a new module. Usually, when a very first module is created, it will beautomatically configured with the right values. However, it is always a goof idea to verifythat the IPv4 addresses and DHCP server parameters are well configured. Once the Host-only adapter has been created, configure the network interface of the VM: right click on
your VM, then click on “settings ! network”. Select Host-only Adapter mode and select
also the host-only module (that you maybe just created). The instructions given in thisdocument are not clear enough? Then, you want to have a look at this website http://christophermaier.name/blog/2010/09/01/host-only-networking-with-virtualbox or this onehttp://technology.amis.nl/2014/01/27/a-short-guide-to-networking-in-virtual-box-with-oracle-linux-inside/
8/8/2019 Tp Mininet
http://slidepdf.com/reader/full/tp-mininet 2/6
4. Once the network of the VM is configured, turn on your VM, wait for the OS to load, andthen log in. The user/password for your mininet guest will be mininet/mininet. Now, opena 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, thenplease proceed with the following exercises.
Your first contact with MininetThe following exercises proposed in this document have been taken from the tutorialavailable in the Mininet official website http://mininet.org/walkthrough/
Note: keep in mind that in order to execute the Mininet platform, you will need root rights(i.e. use sudo). So start by executing mininet
$ sudo mn
If everything went OK, at the end you must see the Mininet CLI “mininet>”, and a virtualnetwork should be deployed. The default deployed topology is called “minimal”. All thecommand available through the CLI can be listed with the “help” command.
mininet> help
The nodes created within our virtual networks can be listed with the “nodes” command
mininet> nodes
In Mininet, clients will be named h1, h2, … hX. The switches will be named s1, s2, … sX, andthe controllers (don't take care for now about such controllers) are named c0, c1, … cX.
How many switches and clients are available in the deployed network?
The informations related to each node can be displayed with the “dump” command.
Explain what you have obtained with the “dump” command.
The links of our topology can be listed with the “net” command
Draw the topology of the deployed virtual network
Since the clients deployed by Mininet are images of the host PC (i.e. the PC where Mininet hasbeen installed), the mininet clients can access the user-space part and file system of thehost. Therefore, it is possible for a Mininet client to execute “inside” such clients thecommands and applications available in the host. In order to do that, you must first indicatethe name of the client to execute a command, followed by the command to be executed (asyou'd do in the real PC). For instance, in order to display the configuration of the NIC at theh1 client, you must issue
mininet> h1 ifconfig –a
8/8/2019 Tp Mininet
http://slidepdf.com/reader/full/tp-mininet 3/6
Add to the topology drawn earlier, the NIC label, IP address and network mask associated toeach client.
Can the h1 client be reached by h2? Verify it thank to the ping command. Give the commandthat you must issue through the CLI.
To leave from Mininet, you must exécute the “exit” command. Important: if during thedeployment process of the virtual network some errors occur, or if you leave Mininet due toan 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 aterminal, the you can
I. Execute Mininet with “-x” option, that will open an xterm terminal for each deployednode. 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 toactivate the X11 forwarding, and hence, be able to correctly deploy the xterm terminalemulator (for instance, ssh –X [email protected]).
Other network topologiesMininet features different templates able to create different network topologies, by providingthe “--topo” parameter at the Mininet startup. As written earlier, the default deployedtopology is the “minimal” one. However, you can use either the “single”, “linear” or “tree”topology. The following command deploys the “single” topology:
$ sudo mn --topo single
the above command will deploy the “minimal” topology actually. However, with “single”, onecan deploy as many clients as required. For instance, issuing the following command “$ sudomn –topo single,3” will deploy 3 clients.
Execute the following commands and draw the created network topology:
1. $ sudo mn --topo linear
2. $ sudo mn --topo linear,3
3. $ sudo mn --topo tree
4. $sudo mn --topo tree,2
5. $sudo mn --topo tree,2,fanout=3. What are the objectives of the arguments “2” and“fanout=3” ? Explain it.
8/8/2019 Tp Mininet
http://slidepdf.com/reader/full/tp-mininet 4/6
Custom topologiesWhat if someone would like to work with a network topology that is not provided by Mininettemplates? In that case, one can easily create the required network topology thanks to thePython libraries and APIs provided by Mininet. Suppose for instance that we need to create aclient 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 hosts and switches
h1 = self.addNode('h1')
h2 = self.addNode('h2')
s1 = self.addSwitch('s1')
# 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
8/8/2019 Tp Mininet
http://slidepdf.com/reader/full/tp-mininet 5/6
If the network is successfully created, then you must end in the CLI environment. Open anxterm for each client (h1 and h2) and explore their NIC configuration. How many interfacesare attached to h1 and h2? What are the assigned IP addresses? Configure through the CLI theh1 NIC, as well as the h2 NIC connected to h1 and assign them the IP addresses192.168.0.1/24 and 192.168.0.2/24 respectively. How can you do to configure the NIC throughthe 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
Almost the endTo be able to create a custom topology is very useful. However, it would be still better if,
instead of providing at each deployment the needed command to obtain a networkconfiguration, the configuration was done automatically by our Python script. Well, this is thefinal exercise to be done in this lab.
Please, read and understand the following code, where we assign and IP address to the h2-eth1 interface from h2. Then h1 executes a ping towards h2. As you can guess, to execute acommand from a given client, we use the cmd() method, by providing as argument thecommand itself.
from mininet.net import Mininet
from mininet.topo import Topo
from mininet.node import Node
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.log import setLogLevel
class Test_Topo(Topo):
…
topos = {
'toptest': (lambda: Test_Topo())
}
8/8/2019 Tp Mininet
http://slidepdf.com/reader/full/tp-mininet 6/6
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 reachh2? If h2 is unreachable, provide through the CLI the needed configurations to provide fullconnectivity between h1 and h2. Once you have found the way to enable the connectivitybetween h1 and h2, modify your Python code in order to execute all those commandsautomatically from your script.