just referred to http://mininet.github.com/walkthrough/
I am using Mininet VM provided by Mininet github which is running within KVM.
[ sample operations ]
log onto the Mininet VM and become root user.
openflow@mininet-vm:~$ sudo su - root@mininet-vm:~# |
run mininet ( mn )
mn is python script.
root@mininet-vm:~# which mn /usr/local/bin/mn root@mininet-vm:~# cat /usr/local/bin/mn #!/usr/bin/python # EASY-INSTALL-SCRIPT: 'mininet==0.0.0','mn' __requires__ = 'mininet==0.0.0' import pkg_resources pkg_resources.run_script('mininet==0.0.0', 'mn') |
rum mn
root@mininet-vm:~# mn *** Loading openvswitch_mod *** Adding controller *** Creating network *** Adding hosts: h2 h3 *** Adding switches: s1 *** Adding links: (s1, h2) (s1, h3) *** Configuring hosts h2 h3 *** Starting controller *** Starting 1 switches s1 *** Starting CLI: mininet> |
get info about nodes , links and all nodes
mininet> nodes available nodes are: c0 h3 h2 s1 mininet> net s1 <-> h2-eth0 h3-eth0 mininet> dump c0: IP=127.0.0.1 intfs= pid=1218 s1: IP=None intfs=s1-eth1,s1-eth2 pid=1221 h2: IP=10.0.0.2 intfs=h2-eth0 pid=1219 h3: IP=10.0.0.3 intfs=h3-eth0 pid=1220 mininet> |
There are two hosts , “h2 and h3” and one switch “s1” and one controller “c0”
an output of ifconfig on “h2” host.
mininet> h2 ifconfig h2-eth0 Link encap:Ethernet HWaddr 8e:6b:ff:e6:5c:91 inet addr:10.0.0.2 Bcast:10.255.255.255 Mask:255.0.0.0 |
ininet> h3 ifconfig h3-eth0 Link encap:Ethernet HWaddr 6e:ce:21:9e:a7:de inet addr:10.0.0.3 Bcast:10.255.255.255 Mask:255.0.0.0 |
s1
mininet> s1 ifconfig eth0 Link encap:Ethernet HWaddr 52:54:00:fa:e0:d1 inet addr:192.168.10.253 Bcast:192.168.10.255 Mask:255.255.255.0 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 s1-eth1 Link encap:Ethernet HWaddr a2:92:fb:c4:fc:52 inet6 addr: fe80::a092:fbff:fec4:fc52/64 Scope:Link s1-eth2 Link encap:Ethernet HWaddr 06:93:f8:db:73:ad inet6 addr: fe80::493:f8ff:fedb:73ad/64 Scope:Link |
send ping to h3 from h2
mininet> h2 ping -c 1 h3 PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data. 64 bytes from 10.0.0.3: icmp_req=1 ttl=64 time=4.75 ms --- 10.0.0.3 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 4.753/4.753/4.753/0.000 ms |
send ping to all nodes
mininet> pingall *** Ping: testing ping reachability h2 -> h3 h3 -> h2 *** Results: 0% dropped (0/2 lost) |
run web server on h2
mininet> h2 python -m SimpleHTTPServer 80 & |
get an web content from h3
In my environment , it took around 15 seconds to get the content.
mininet> h3 wget -O - h2 --2012-12-20 18:15:48-- http://10.0.0.2/ Connecting to 10.0.0.2:80... connected. HTTP request sent, awaiting response... 200 OK Length: 370 [text/html] Saving to: `STDOUT' <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html> <title>Directory listing for /</title> <body> <h2>Directory listing for /</h2> <hr> <ul> <li><a href=".aptitude/">.aptitude/</a> <li><a href=".bash_history">.bash_history</a> <li><a href=".bashrc">.bashrc</a> <li><a href=".profile">.profile</a> <li><a href=".viminfo">.viminfo</a> </ul> <hr> </body> </html> 0K 100% 42.5M=0s 2012-12-20 18:16:08 (42.5 MB/s) - written to stdout [370/370] mininet> |
stop web server on h2
check PID
mininet> h2 ps aux | grep python | grep -v grep root 944 0.0 1.9 16536 9772 ttyS0 R+ 17:47 0:00 /usr/bin/python /usr/local/bin/mn root 1030 0.0 1.1 11940 5764 ? SN 18:14 0:00 python -m SimpleHTTPServer 80 mininet> h2 kill 1030 |
kill process
mininet> h2 kill 1030 |
run regression tests which Mininet has
ping
mininet> dump c0: IP=127.0.0.1 intfs= pid=956 s1: IP=None intfs=s1-eth1,s1-eth2 pid=959 h2: IP=10.0.0.2 intfs=h2-eth0 pid=957 h3: IP=10.0.0.3 intfs=h3-eth0 pid=958 mininet> pingpair h2 -> h3 h3 -> h2 *** Results: 0% dropped (0/2 lost) |
iperf
mininet> iperf *** Iperf: testing TCP bandwidth between h2 and h3 *** Results: ['3.88 Gbits/sec', '3.88 Gbits/sec'] |
exit
mininet> exit *** Stopping 2 hosts h2 h3 *** Stopping 1 switches s1.. *** Stopping 1 controllers *** Done completed in 7.443 seconds root@mininet-vm:~# |
run mn with debug mode
root@mininet-vm:~# mn -v debug *** openvswitch_mod already loaded *** Adding controller *** Creating network *** Adding hosts: h2 h3 *** Adding switches: s1 *** Adding links: *** h2 : ('ip link show',) 17: lo: <LOOPBACK> mtu 16436 qdisc noop state DOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 19: h2-eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000 link/ether 9a:e3:c2:9e:af:fd brd ff:ff:ff:ff:ff:ff (s1, h2) *** h3 : ('ip link show',) 18: lo: <LOOPBACK> mtu 16436 qdisc noop state DOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 21: h3-eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000 link/ether 82:84:4d:91:6a:c9 brd ff:ff:ff:ff:ff:ff (s1, h3) *** Configuring hosts *** h2 : ('ifconfig', 'h2-eth0', '10.0.0.2/8', 'up') *** h2 : ('ip route flush root 0/0',) *** h2 : ('route add default h2-eth0',) h2 *** h3 : ('ifconfig', 'h3-eth0', '10.0.0.3/8', 'up') *** h3 : ('ip route flush root 0/0',) *** h3 : ('route add default h3-eth0',) h3 *** Starting controller *** c0 : ('controller -v ptcp:6633 1>/tmp/c0.log 2>/tmp/c0.log&',) *** Starting 1 switches s1 *** s1 : ('ovs-dpctl add-dp dp0',) *** s1 : ('ovs-dpctl', 'add-if', 'dp0', 's1-eth1 s1-eth2') *** s1 : ('ovs-openflowd dp0 tcp:127.0.0.1:6633 --fail=secure --listen=ptcp:6634 --datapath-id=0000000000000001 1>/tmp/s1-ofp.log 2>/tmp/s1-ofp.log&',) *** Starting CLI: mininet> dump c0: IP=127.0.0.1 intfs= pid=1223 *** s1 : ('ifconfig s1-eth2',) s1-eth2 Link encap:Ethernet HWaddr b6:87:52:62:69:f8 inet6 addr: fe80::b487:52ff:fe62:69f8/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5 errors:0 dropped:0 overruns:0 frame:0 TX packets:10 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:398 (398.0 B) TX bytes:796 (796.0 B) s1: IP=None intfs=s1-eth1,s1-eth2 pid=1226 *** h2 : ('ifconfig h2-eth0',) h2-eth0 Link encap:Ethernet HWaddr 9a:e3:c2:9e:af:fd inet addr:10.0.0.2 Bcast:10.255.255.255 Mask:255.0.0.0 inet6 addr: fe80::98e3:c2ff:fe9e:affd/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:10 errors:0 dropped:0 overruns:0 frame:0 TX packets:5 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:796 (796.0 B) TX bytes:398 (398.0 B) h2: IP=10.0.0.2 intfs=h2-eth0 pid=1224 *** h3 : ('ifconfig h3-eth0',) h3-eth0 Link encap:Ethernet HWaddr 82:84:4d:91:6a:c9 inet addr:10.0.0.3 Bcast:10.255.255.255 Mask:255.0.0.0 inet6 addr: fe80::8084:4dff:fe91:6ac9/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:10 errors:0 dropped:0 overruns:0 frame:0 TX packets:5 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:796 (796.0 B) TX bytes:398 (398.0 B) h3: IP=10.0.0.3 intfs=h3-eth0 pid=1225 mininet> mininet> iperf *** Iperf: testing TCP bandwidth between h2 and h3 *** h3 : ('killall -9 iperf',) iperf: no process found *** h2 : ('sh -c "echo A | telnet -e A 10.0.0.3 5001"',) Telnet escape character is 'A'. Trying 10.0.0.3... Connected to 10.0.0.3. Escape character is 'A'. telnet> Connection closed. *** h2 : ('iperf -t 5 -c 10.0.0.3 ',) ------------------------------------------------------------ Client connecting to 10.0.0.3, TCP port 5001 TCP window size: 16.0 KByte (default) ------------------------------------------------------------ [ 3] local 10.0.0.2 port 52003 connected with 10.0.0.3 port 5001 [ ID] Interval Transfer Bandwidth [ 3] 0.0- 5.0 sec 2.15 GBytes 3.69 Gbits/sec Client output: ------------------------------------------------------------ Client connecting to 10.0.0.3, TCP port 5001 TCP window size: 16.0 KByte (default) ------------------------------------------------------------ [ 3] local 10.0.0.2 port 52003 connected with 10.0.0.3 port 5001 [ ID] Interval Transfer Bandwidth [ 3] 0.0- 5.0 sec 2.15 GBytes 3.69 Gbits/sec ------------------------------------------------------------ Server listening on TCP port 5001 TCP window size: 85.3 KByte (default) ------------------------------------------------------------ [ 4] local 10.0.0.3 port 5001 connected with 10.0.0.2 port 52002 [ ID] Interval Transfer Bandwidth [ 4] 0.0- 0.0 sec 0.00 Bytes 0.00 bits/sec [ 5] local 10.0.0.3 port 5001 connected with 10.0.0.2 port 52003 [ 5] 0.0- 5.0 sec 2.15 GBytes 3.69 Gbits/sec Server output: ------------------------------------------------------------ Server listening on TCP port 5001 TCP window size: 85.3 KByte (default) ------------------------------------------------------------ [ 4] local 10.0.0.3 port 5001 connected with 10.0.0.2 port 52002 [ ID] Interval Transfer Bandwidth [ 4] 0.0- 0.0 sec 0.00 Bytes 0.00 bits/sec [ 5] local 10.0.0.3 port 5001 connected with 10.0.0.2 port 52003 [ 5] 0.0- 5.0 sec 2.15 GBytes 3.69 Gbits/sec *** Results: ['3.69 Gbits/sec', '3.69 Gbits/sec'] mininet> mininet> exit |
- customize topologies
there’s a sample python script “topo-2sw-2host.py” under /home/openflow/mininet/custom
directory.
two hosts ( h1 and h2 )
two switches ( s3 and s4 )
root@mininet-vm:~# cat -n /home/openflow/mininet/custom/topo-2sw-2host.py 1 """Custom topology example 2 3 author: Brandon Heller (brandonh@stanford.edu) 4 5 Two directly connected switches plus a host for each switch: 6 7 host --- switch --- switch --- host 8 9 Adding the 'topos' dict with a key/value pair to generate our newly defined 10 topology enables one to pass in '--topo=mytopo' from the command line. 11 """ 12 13 from mininet.topo import Topo, Node 14 15 class MyTopo( Topo ): 16 "Simple topology example." 17 18 def __init__( self, enable_all = True ): 19 "Create custom topo." 20 21 # Add default members to class. 22 super( MyTopo, self ).__init__() 23 24 # Set Node IDs for hosts and switches 25 leftHost = 1 26 leftSwitch = 2 27 rightSwitch = 3 28 rightHost = 4 29 30 # Add nodes 31 self.add_node( leftSwitch, Node( is_switch=True ) ) 32 self.add_node( rightSwitch, Node( is_switch=True ) ) 33 self.add_node( leftHost, Node( is_switch=False ) ) 34 self.add_node( rightHost, Node( is_switch=False ) ) 35 36 # Add edges 37 self.add_edge( leftHost, leftSwitch ) 38 self.add_edge( leftSwitch, rightSwitch ) 39 self.add_edge( rightSwitch, rightHost ) 40 41 # Consider all switches and hosts 'on' 42 self.enable_all() 43 44 45 topos = { 'mytopo': ( lambda: MyTopo() ) } root@mininet-vm:~# |
run mn with topo-2sw-2host.py
root@mininet-vm:~# mn --custom /home/openflow/mininet/custom/topo-2sw-2host.py --test iperf -v debug --topo mytopo custom in sys.argv *** openvswitch_mod already loaded *** Adding controller *** Creating network *** Adding hosts: h1 h4 *** Adding switches: s2 s3 *** Adding links: *** h1 : ('ip link show',) 38: lo: <LOOPBACK> mtu 16436 qdisc noop state DOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 41: h1-eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000 link/ether fe:2d:67:92:55:26 brd ff:ff:ff:ff:ff:ff (h1, s2) (s2, s3) *** h4 : ('ip link show',) 39: lo: <LOOPBACK> mtu 16436 qdisc noop state DOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 44: h4-eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000 link/ether ca:11:19:56:86:e0 brd ff:ff:ff:ff:ff:ff (s3, h4) *** Configuring hosts *** h1 : ('ifconfig', 'h1-eth0', '10.0.0.1/8', 'up') *** h1 : ('ip route flush root 0/0',) *** h1 : ('route add default h1-eth0',) h1 *** h4 : ('ifconfig', 'h4-eth0', '10.0.0.4/8', 'up') *** h4 : ('ip route flush root 0/0',) *** h4 : ('route add default h4-eth0',) h4 *** Starting controller *** c0 : ('controller -v ptcp:6633 1>/tmp/c0.log 2>/tmp/c0.log&',) *** Starting 2 switches s2 *** s2 : ('ovs-dpctl add-dp dp0',) *** s2 : ('ovs-dpctl', 'add-if', 'dp0', 's2-eth1 s2-eth2') *** s2 : ('ovs-openflowd dp0 tcp:127.0.0.1:6633 --fail=secure --listen=ptcp:6634 --datapath-id=0000000000000002 1>/tmp/s2-ofp.log 2>/tmp/s2-ofp.log&',) s3 *** s3 : ('ovs-dpctl add-dp dp1',) *** s3 : ('ovs-dpctl', 'add-if', 'dp1', 's3-eth1 s3-eth2') *** s3 : ('ovs-openflowd dp1 tcp:127.0.0.1:6633 --fail=secure --listen=ptcp:6635 --datapath-id=0000000000000003 1>/tmp/s3-ofp.log 2>/tmp/s3-ofp.log&',) *** Iperf: testing TCP bandwidth between h1 and h4 *** h4 : ('killall -9 iperf',) iperf: no process found *** h1 : ('sh -c "echo A | telnet -e A 10.0.0.4 5001"',) Telnet escape character is 'A'. Trying 10.0.0.4... Connected to 10.0.0.4. Escape character is 'A'. telnet> Connection closed. *** h1 : ('iperf -t 5 -c 10.0.0.4 ',) ------------------------------------------------------------ Client connecting to 10.0.0.4, TCP port 5001 TCP window size: 69.3 KByte (default) ------------------------------------------------------------ [ 3] local 10.0.0.1 port 59865 connected with 10.0.0.4 port 5001 [ ID] Interval Transfer Bandwidth [ 3] 0.0- 5.0 sec 1.28 GBytes 2.21 Gbits/sec Client output: ------------------------------------------------------------ Client connecting to 10.0.0.4, TCP port 5001 TCP window size: 69.3 KByte (default) ------------------------------------------------------------ [ 3] local 10.0.0.1 port 59865 connected with 10.0.0.4 port 5001 [ ID] Interval Transfer Bandwidth [ 3] 0.0- 5.0 sec 1.28 GBytes 2.21 Gbits/sec [ 4] local 10.0.0.4 port 5001 connected with 10.0.0.1 port 59864 [ ID] Interval Transfer Bandwidth [ 4] 0.0- 0.0 sec 0.00 Bytes 0.00 bits/sec [ 5] local 10.0.0.4 port 5001 connected with 10.0.0.1 port 59865 [ 5] 0.0- 5.0 sec 1.28 GBytes 2.20 Gbits/sec Server output: ------------------------------------------------------------ Server listening on TCP port 5001 TCP window size: 85.3 KByte (default) ------------------------------------------------------------ [ 4] local 10.0.0.4 port 5001 connected with 10.0.0.1 port 59864 [ ID] Interval Transfer Bandwidth [ 4] 0.0- 0.0 sec 0.00 Bytes 0.00 bits/sec [ 5] local 10.0.0.4 port 5001 connected with 10.0.0.1 port 59865 [ 5] 0.0- 5.0 sec 1.28 GBytes 2.20 Gbits/sec *** Results: ['2.20 Gbits/sec', '2.21 Gbits/sec'] *** Stopping 2 hosts h1 h4 *** Stopping 2 switches s2*** s2 : ('kill %ovs-openflowd',) ..s3*** s3 : ('kill %ovs-openflowd',) .. *** Stopping 1 controllers *** c0 : ('kill %controller',) *** Done completed in 5.459 seconds root@mininet-vm:~# |
get h2 host info
root@mininet-vm:~# mn mininet> py dir(h2) ['IP', 'MAC', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_ipMatchRegex', '_macMatchRegex', 'addIntf', 'args', 'cleanup', 'cmd', 'cmdPrint', 'connection', 'connectionsTo', 'defaultIP', 'defaultIntf', 'defaultMAC', 'deleteIntfs', 'execed', 'fdToNode', 'inNamespace', 'inToNode', 'intfIsUp', 'intfName', 'intfs', 'ips', 'lastCmd', 'lastPid', 'linkTo', 'macs', 'monitor', 'name', 'newPort', 'outToNode', 'pid', 'pollOut', 'portBase', 'ports', 'read', 'readbuf', 'readline', 'registerIntf', 'sendCmd', 'sendInt', 'setARP', 'setDefaultRoute', 'setHostRoute', 'setIP', 'setMAC', 'shell', 'stdin', 'stdout', 'stop', 'terminate', 'updateIP', 'updateMAC', 'waitOutput', 'waitReadable', 'waiting', 'write'] mininet> py h2.IP(),h2.MAC() ('10.0.0.2', 'f6:b3:d5:d4:6f:66') |
down/up links
mininet> link s1 h2 down mininet> pingall *** Ping: testing ping reachability h2 -> X h3 -> X *** Results: 100% dropped (2/2 lost) mininet> mininet> link s1 h2 up mininet> pingall *** Ping: testing ping reachability h2 -> h3 h3 -> h2 *** Results: 0% dropped (0/2 lost) |
run four hosts and access to the hosts over SSH
run sample script
root@mininet-vm:~# /home/openflow/mininet/examples/sshd.py *** Adding controller *** Creating network *** Adding hosts: h1 h2 h3 h4 *** Adding switches: s5 *** Adding links: (h1, s5) (h2, s5) (h3, s5) (h4, s5) *** Configuring hosts h1 h2 h3 h4 *** Starting controller *** Starting 1 switches s5 *** Hosts are running sshd at the following addresses: h1 10.0.0.1 h2 10.0.0.2 h3 10.0.0.3 h4 10.0.0.4 |
access to the h1 over SSH
open another terminal and access to the h1
root@mininet-vm:~# ssh 10.0.0.1 -l openflow openflow@10.0.0.1's password: Welcome to Ubuntu 11.10 (GNU/Linux 3.0.0-12-generic i686) * Documentation: https://help.ubuntu.com/ New release '12.04 LTS' available. Run 'do-release-upgrade' to upgrade to it. Last login: Thu Dec 20 20:00:13 2012 from 10.123.123.1 openflow@mininet-vm:~$ ping 10.0.0.2 -c 1 PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data. 64 bytes from 10.0.0.2: icmp_req=1 ttl=64 time=4.90 ms --- 10.0.0.2 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 4.901/4.901/4.901/0.000 ms openflow@mininet-vm:~$ exit logout Connection to 10.0.0.1 closed. root@mininet-vm:~# |
Hello,
ReplyDeleteI found your detailed description of MININET wonderful...
I have one query, How to drop packets from any particular host?
plz let me know...
my email is:
varunmoruse@rediffmail.com
hey, great tutorial!
ReplyDeletecould you also explain how to change host IPs, i mean in order to run two different subnets?