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

Friday, September 13, 2013

Start and stop POX controller

1) To start POX, go inside the POX folder

$sudo python ./pox.py py

         or

$sudo python ./pox.py py openflow.discovery forwarding.l2_learning

2) If it says address already in use

Find what application/process is using the pro, type:

$sudo netstat -lpn |grep :6633

You will get an output similar to this one

tcp6       0      0 :::6633                 :::*                    LISTEN      6782/java

I have got the process Id, which is 6782, now this is the process that is using port 6633. To Kill the process, type

$sudo kill 6782

3) Stop POX

POX > exit ()

If you forget it, then next time

$sudo killall controller



Wednesday, September 11, 2013

Install POX controller

POX is a platform for the rapid development and prototyping of network control software using Python.  It’s one of a growing number of frameworks (including NOX, Floodlight, Trema, etc.,) for helping to write an OpenFlow controller.

POX as well as being a framework for interacting with OpenFlow switches, it can be used as the basis for some of our ongoing work to help build the emerging discipline of Software Defined Networking.  It can be used to explore and prototype distribution, SDN debugging, network virtualization, controller design, and programming models.

Installing POX

$ git clone http://github.com/noxrepo/pox

$ cd pox