Thursday, October 3, 2013

Configure openVswitch with POX controller

Configure openVswitch in openVswitch in PC1

PC1 eth0.10 interface IP is 192.168.10.100

#We attach  PC1 eth0.10 interface to the bridge connection between openVswitch in PC1 and controller

$sudo ovs-vsctl add-br br0
$sudo ovs-vsctl add-port br0 eth0.10
$sudo ifconfig br0 192.168.10.100 netmask 255.255.255.0

#Attach OpenvSwitch to the Controller which is in 192.168.100.30

$ovs-vsctl set-controller br0 tcp:192.168.100.30:6633

To remove openVswitch bridge connection

$sudo ovs-vsctl del-br br-0
$sudo ovs-vsctl del-port br-0 eth0.10

To remove the Controller

$sudo ovs-vsctl del-controller br-0


Installing and Configuring OpenVSwitch on Ubuntu 12.10


System Preperation

Install dependencies

$apt-get update 
$apt-get install python-simplejson automake autoconf gcc uml-utilities libtool build-essential git pkg-config

Download the OVS tarball Note: you can also pull from the git repository 

$wget http://openvswitch.org/releases/openvswitch-1.10.0.tar.gz

$tar zxvf openvswitch-1.10.0.tar.gz

$cd openvswitch-1.10.0

Compiling Open vSwitch From Source 

$./boot.sh   
$./configure --with-linux=/lib/modules/`uname -r`/build 
$make 
$make install

#Load the OVS Kernel Module
$insmod datapath/linux/openvswitch.ko

#Pull down the headers for your kernel
$sudo apt-get install linux-headers-`uname -r`

Open vSwitch Configuration 
$touch /usr/local/etc/ovs-vswitchd.conf 
$mkdir -p /usr/local/etc/openvswitch 
$ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema

#Start ovsdb-server, this stores the config into a file that is persistent even after restarts.

$ovsdb-server /usr/local/etc/openvswitch/conf.db \
--remote=punix:/usr/local/var/run/openvswitch/db.sock \
--remote=db:Open_vSwitch,manager_options \
--private-key=db:SSL,private_key \
--certificate=db:SSL,certificate \
--bootstrap-ca-cert=db:SSL,ca_cert --pidfile --detach --log-file

#Only need to run this the first time. 
$ovs-vsctl --no-wait init

#Start vswitch  
$ovs-vswitchd --pidfile --detach


#Verify the kernel module(s) in case you didn't earlier and get errors. 
$lsmod | grep br 
brcompat               13512  0
openvswitch            98196  1 brcompat

#If they are not there try loading again and check your path to the kernel module. 
$insmod datapath/linux/openvswitch.ko

#At this point you have a fucntioning vanilla OVS install. Output should look something like this. 
$ovs-vsctl show
b6d574d7-5582-4cc0-93e5-a90cf0eb0a38
root@demo-139:/home/ubuntu/ovs-vxlan# ovs-vsctl --version
ovs-vsctl (Open vSwitch) 1.8.90
Compiled October 03 2013 06:23:36

Monday, September 16, 2013

Add and delete flow paths from POX controller

POX>from pox.core import core
POX>import pox.openflow.libopenflow_01 as of
POX>from pox.lib.addresses import IPAddr

Add flows

POX>for connection in core.openflow.connections:
                connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=2),priority=32,
 match=of.ofp_match(dl_type=0x800,nw_src="10.0.0.1",nw_dst="10.0.0.2")))

Delete flows

POX>for connection in core.openflow.connections:    
                connection.send(of.ofp_flow_mod(command=of.OFPFC_DELETE_STRICT,
 action=of.ofp_action_output(port=3),priority=32,
 match=of.ofp_match(dl_type=0x800,nw_src="10.0.0.1",nw_dst="10.0.0.3")))

Dont forget to add
net.staticArp() after net.build() in mininet code

*make sure in for loops, intendent is there
     For connection....
              connection.send......

Sunday, September 15, 2013

Add and check flow paths from shell command prompt and mininet prompt

To check the flow paths

#from the shell prompt
$ sudo ovs-ofctl dump-flows s1

#from the Mininet prompt is 
mininet> dpctl dump-flows s1
or
mininet> s1 ovs-ofctl dump-flows s1
or
mininet> sh ovs-ofctl dump-flows s1

To Add flows paths (From shell prompt)

Check the destination and add the flow
$ sudo ovs-ofctl add-flow s1 ip,nw_dst=10.0.0.1,actions=output:1 
or
$ sudo ovs-ofctl add-flow s1 eth_type=0x800,nw_dst=10.0.0.1,actions=output:1 


To Remove flows paths (From shell prompt)

Check the source and remove the flow
$ sudo ovs-ofctl del-flows s1 ip,nw_src=10.0.0.1,actions=output:1

If you are trying to communicate using IP addresses, make sure to handle ARPs

$ sudo ovs-ofctl add-flow s1 eth_type=0x806,actions=output:ALL




Mininet script with two switches, different subnets

Multiple subnets : 10.0.0.0 and 11.0.0.0
So use POX l3_learning module

           s1 --------- s2
         l     l        l     l
        h1   h2    h3    h4

==========================================

#!/usr/bin/python

from mininet.net import Mininet
from mininet.node import Controller, OVSKernelSwitch, RemoteController
from mininet.cli import CLI
from mininet.log import setLogLevel, info

def emptyNet():

    net = Mininet(controller=RemoteController, switch=OVSKernelSwitch)

    c1 = net.addController('c1', controller=RemoteController, ip="127.0.0.1", port=6633)

    h1 = net.addHost( 'h1', ip='10.0.0.1' )
    h2 = net.addHost( 'h2', ip='10.0.0.2' )
    h3 = net.addHost( 'h3', ip='10.0.0.3' )
    h4 = net.addHost( 'h4', ip='10.0.0.4' )

    s1 = net.addSwitch( 's1' )
    s2 = net.addSwitch( 's2' )

    s1.linkTo( h1 )
    s1.linkTo( h2 )
    s2.linkTo( h3 )
    s2.linkTo( h4 )
    s1.linkTo( s2 )

    net.build()
    c1.start()
    s1.start([c1])
    s2.start([c1])
  
    CLI( net )
    net.stop()

if __name__ == '__main__':
    setLogLevel( 'info' )
    emptyNet()

==============================================

When mininet is running add default routing


mininet > h1 route add -net default h1-eth0
mininet > h2 route add -net default h2-eth0
mininet > h3 route add -net default h3-eth0
mininet > h4 route add -net default h4-eth0



Mininet script with two switches, single subnet

Single subnet : 10.0.0.0, So use POX l2_learning module

           s1 --------- s2
         l     l        l     l
        h1   h2    h3    h4

==========================================

#!/usr/bin/python

from mininet.net import Mininet
from mininet.node import Controller, OVSKernelSwitch, RemoteController
from mininet.cli import CLI
from mininet.log import setLogLevel, info

def emptyNet():

    net = Mininet(controller=RemoteController, switch=OVSKernelSwitch)

    c1 = net.addController('c1', controller=RemoteController, ip="127.0.0.1", port=6633)

    h1 = net.addHost( 'h1', ip='10.0.0.1' )
    h2 = net.addHost( 'h2', ip='10.0.0.2' )
    h3 = net.addHost( 'h3', ip='10.0.0.3' )
    h4 = net.addHost( 'h4', ip='10.0.0.4' )

    s1 = net.addSwitch( 's1' )
    s2 = net.addSwitch( 's2' )

    s1.linkTo( h1 )
    s1.linkTo( h2 )
    s2.linkTo( h3 )
    s2.linkTo( h4 )
    s1.linkTo( s2 )

    net.build()
    c1.start()
    s1.start([c1])
    s2.start([c1])
  
    CLI( net )
    net.stop()

if __name__ == '__main__':
    setLogLevel( 'info' )
    emptyNet()




Saturday, September 14, 2013

Mininet XTerm, TCP dump and iperf

Verify Hub Behavior with tcpdump

To verify that hosts can ping each other, and that all hosts see the exact same traffic - the behavior of a hub. To do this, we'll create xterms for each host, and view the traffic in each. In the Mininet console, start up three xterms:

mininet> xterm h2 h3 h4

In the xterms for h3 and h4, run tcpdump, a utility to print the packets seen by a host:

$ sudo tcpdump -XX -n -i h3-eth0

and respectively:

$ sudo tcpdump -XX -n -i h4-eth0

In the xterm for h2, send a ping:

$ ping -c1 10.0.0.3

The ping packets are now going up to the controller, which then floods them out all interfaces except the sending one. You should see identical ARP and ICMP packets corresponding to the ping in both xterms running tcpdump.

Now, see what happens when a non-existent host doesn't reply. From h2 xterm:

$ ping -c1 10.0.0.5

You should see three unanswered ARP requests in the tcpdump xterms. If your code is off later, three unanswered ARP requests is a signal that you might be accidentally dropping packets.

You can close the xterms now.

Benchmark Hub Controller with iperf

Here, you'll benchmark the provided hub.

First, verify reachability. Mininet should be running, along with the POX in a second window. In the Mininet console, run:

mininet> pingall

This is just a sanity check for connectivity. Now, in the Mininet console, run:

mininet> iperf