Learning OVS (open vswitch) using mininet — Part 1

In this post  I am going to show you the usage information about the mininet. mininet is wonderful tool for network emulation, we can create switches, host and connection between them for testing purpose.

I have downloaded the mininet from http://mininet.org/download/ and import it as a VM inside the Oracle Virtual box. It’s pretty much easy to do that within few minutes your machine will be ready.

Step 1 : I powered on the VM, and login using mininet username and password. Initially it was having only one interface (eth0).

root@mininet-vm:~# ifconfig -s
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500 0       458      0      0 0           190      0      0      0 BMRU
lo        65536 0      3449      0      0 0          3449      0      0      0 LRU

Step 2 : I switched to root using “sudo su -” command and issued below command to create a topology. By default it will create a linear topology with two hosts and one switch.

root@mininet-vm:~# mn
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2
*** Adding switches:
s1
*** Adding links:
(h1, s1) (h2, s1)
*** Configuring hosts
h1 h2
*** Starting controller
c0
*** Starting 1 switches
s1 …
*** Starting CLI:

Step 3 : Now I am at new prompt if I want to issue any OS command instead of coming out of this prompt, we can append the sh to any command, it will show the results from original shell.

mininet> sh ifconfig -s
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500 0       501      0      0 0           245      0      0      0 BMRU
lo        65536 0      3470      0      0 0          3470      0      0      0 LRU
s1         1500 0         0      0      0 0             0      0      0      0 BRU
s1-eth1    1500 0         0      0      0 0             0      0      0      0 BMRU
s1-eth2    1500 0         0      0      0 0             0      0      0      0 BMRU

Step 4 : Checking the OVS-bridge configuration after configuration of two hosts and one switch.

mininet> sh ovs-vsctl show
0b8ed0aa-67ac-4405-af13-70249a7e8a96
Bridge “s1”
Controller “tcp:127.0.0.1:6633”
is_connected: true
Controller “ptcp:6634”
fail_mode: secure
Port “s1”
Interface “s1”
type: internal
Port “s1-eth2”
Interface “s1-eth2”
Port “s1-eth1”
Interface “s1-eth1”
ovs_version: “2.0.2”

Step 5 : Commands in step 3 and 4 are issued on root shell instead of in mn environment. I am issuing below commands at mn prompt to see the current topology settings.

a) nodes command showing the us all the components present in topology.

mininet> nodes
available nodes are:
c0 h1 h2 s1

b) dump command can give us the more detailed information of every component.
mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=1870>
<Host h2: h2-eth0:10.0.0.2 pid=1873>
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None pid=1878>
<Controller c0: 127.0.0.1:6633 pid=1863>
mininet> net
h1 h1-eth0:s1-eth1

c) net command to see the networking connection between the components.

mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
s1 lo:  s1-eth1:h1-eth0 s1-eth2:h2-eth0
c0

d) We can ping the h2 host from h1 using below command.

mininet> h1 ping h2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=1.44 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.817 ms
^C
— 10.0.0.2 ping statistics —
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.817/1.130/1.443/0.313 ms

e) If I want to issue any command inside the virtual host h1 we can use the SYNTAX like below. It’s showing the interface information from the h1 host.

mininet> h1 ifconfig
h1-eth0   Link encap:Ethernet  HWaddr 1a:3f:3b:a5:4e:dc
inet addr:10.0.0.1  Bcast:10.255.255.255  Mask:255.0.0.0
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:280 (280.0 B)  TX bytes:280 (280.0 B)

lo        Link encap:Local Loopback
inet addr:127.0.0.1  Mask:255.0.0.0
UP LOOPBACK RUNNING  MTU:65536  Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

f) pingall is wonderful command to test the connectivity of all hosts present in topology.

mininet> pingall
*** Ping: testing ping reachability
h1 -> h2
h2 -> h1
*** Results: 0% dropped (2/2 received)

g) exit command will terminate the existing topology.

mininet> exit
*** Stopping 1 controllers
c0
*** Stopping 2 links
..
*** Stopping 1 switches
s1
*** Stopping 2 hosts
h1 h2
*** Done
completed in 488.486 seconds

h) It’s advisable to run the below command to clear any zombie process once you are back at shell.

root@mininet-vm:~# sudo mn -c
*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes
killall controller ofprotocol ofdatapath ping nox_core lt-nox_core ovs-openflowd ovs-controller udpbwtest mnexec ivs 2> /dev/null
killall -9 controller ofprotocol ofdatapath ping nox_core lt-nox_core ovs-openflowd ovs-controller udpbwtest mnexec ivs 2> /dev/null
pkill -9 -f “sudo mnexec”
*** Removing junk from /tmp
rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log
*** Removing old X11 tunnels
*** Removing excess kernel datapaths
ps ax | egrep -o ‘dp[0-9]+’ | sed ‘s/dp/nl:/’
***  Removing OVS datapaths
ovs-vsctl –timeout=1 list-br
ovs-vsctl –timeout=1 list-br
*** Removing all links of the pattern foo-ethX
ip link show | egrep -o ‘([-_.[:alnum:]]+-eth[[:digit:]]+)’
ip link show
*** Killing stale mininet node processes
pkill -9 -f mininet:
*** Shutting down stale tunnels
pkill -9 -f Tunnel=Ethernet
pkill -9 -f .ssh/mn
rm -f ~/.ssh/mn/*
*** Cleanup complete.

In the next article I will show how to create other topologies instead of the default one.

Advertisements

2 thoughts on “Learning OVS (open vswitch) using mininet — Part 1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s