Monday, October 28, 2013

Install Floodlight controller on ubuntu 12.04 +

Prerequisites

Ubuntu 10.04 (Natty) or higher.
Install JDK and Ant by running “sudo apt-get install build-essential default-jdk ant python-dev eclipse”

Download and build

$ git clone git://github.com/floodlight/floodlight.git
$ cd floodlight
$ git checkout stable
$ ant;


Running Floodlight

Assuming java is in your path, directly run the floodlight.jar file produced by ant.

 $ java -jar target/floodlight.jar

Additionl stuff on how to set Java path

$sudo su
$vim .bashrc


Include following lines at the end of the file

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_25
export JAVA_HOME
PATH=$PATH:$JAVA_HOME
export PATH


Then go to /etc/environment
add this line:

JAVA_HOME=/usr/lib/jvm/jdk1.7.0_25

Then go to /etc/profile.d/java.sh (create it if necessary)

export JDK_HOME=/usr/lib/jvm/jdk1.7.0_25
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_25


Then in a terminal run:

sudo chmod +x /etc/profile.d/java.sh
source /etc/profile.d/java.sh


Check the path

echo $JAVA_HOME


Prerequisites

Linux

  • Ubuntu 10.04 (Natty) or higher.  (Has been run with Ubuntu 10.04 with Ant versions 1.8.1 or lower).
  • Install JDK and Ant by running “sudo apt-get install build-essential default-jdk ant python-dev eclipse”
- See more at: http://www.projectfloodlight.org/getting-started/#sthash.vgwXGTWY.dpuf

Prerequisites

Linux

  • Ubuntu 10.04 (Natty) or higher.  (Has been run with Ubuntu 10.04 with Ant versions 1.8.1 or lower).
  • Install JDK and Ant by running “sudo apt-get install build-essential default-jdk ant python-dev eclipse”
- See more at: http://www.projectfloodlight.org/getting-started/#sthash.vgwXGTWY.dpuf

Friday, October 25, 2013

Change the role of the POX controller (Master / Slave)

Use the openflow.nicira

Go inside the POX folder
$sudo python ./pox.py py openflow.nicira forwarding.l2_learning


POX> import pox.openflow.nicira as nx
POX> for connection in core.openflow.connections:
 ...            connection.send(nx.nx_role_request(master="true"))

Example 

Two controllers are running in PC1 and PC2
PC1 controller requesting the Master role






Mininet script for multiple controllers

Controller 1 is running on 192.168.200.22
Controller 2 is running on the same machine that mininet is running

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

#!/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="192.168.200.22", port=6633)
    c2 = net.addController('c2', 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 )
    s1.linkTo( s2 )
    s2.linkTo( h3 )
    s2.linkTo( h4 )

    net.build()
    c1.start()
    c2.start()
    s1.start([c1,c2])
    s2.start([c1,c2])

    net.start()
    net.staticArp()
    CLI( net )
    net.stop()

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

In band controller


SDN Can be deployed in two ways..

Out Band Control : All the switches are directly connected to controller. So controller traffic go via the directly connected links.

s1 ---  s2 --- s3
 l         l       l
 l ----- c1----- l

In Band Control : A switch is connected to the controller via another switch

s1 --- s2
 l
c1


#!/usr/bin/python

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

class InbandController( RemoteController ):

    def checkListening( self ):
        "Overridden to do nothing."
        return

def emptyNet():

    "Create an empty network and add nodes to it."

    net = Mininet( topo=None, build=False)

    net.addController('c0', controller=InbandController, ip='10.0.0.1')

    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' )

    s1 = net.addSwitch( 's1', cls=OVSSwitch )

    net.addLink( h1, s1 )
    net.addLink( h2, s1 )
    net.addLink( h3, s1 )

    net.start()
    s1.cmd('ifconfig s1 10.0.0.10')

    CLI( net )
    net.stop()

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


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

We start the controller in h1..

So start the controller.  First open an xterm to h1, which is where we said the controller would be.

mininet> xterm h1

When the xterm opens, start the controller. For this quick test, we will just start the OpenFlow Reference controller.

root@mininet-vm:~# controller -v ptcp:6633

This means that the controller and switch are successfully talking to each other.  And if you do a pingall now.

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

Switch / Link go down and come up on the fly

It is detected by openflow.discovery

s1 goes down and comes up

mininet > py s1.stop

mininet > py s1.start([c1,c2])





Add components to mininet on fly

Add a new controller, switch, two hosts

mininet> py net.addController('c2', IP="127.0.0.2", port=6633)

mininet> py net.addSwitch('s2')
mininet> py s2.start([c2])

mininet> py net.addHost('h4')
mininet> py net.addLink(s2, net.get('h4'))
mininet> py s2.attach('s2-eth1')
mininet> py net.get('h4').cmd('ifconfig h4-eth0 10.4')

mininet> py net.addHost('h5')
mininet> py net.addLink(s2, net.get('h5'))
mininet> py s2.attach('s2-eth2')
mininet> py net.get('h5').cmd('ifconfig h5-eth0 10.5')

Thursday, October 3, 2013

Multiple controllers and Mininet on the same VM

1) Mininet Script

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

2) Start POX controllers

./pox.py --port=6633 MyScript.py
./pox.py --port=6634 MyScript.py

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

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

Tuesday, September 10, 2013

Start and stop mininet scripts

Start mininet

#Go inside mininet folder

$sudo python ./test.py

Stop mininet and clean

mininet > exit ()

$ sudo mn -c


Install Mininet on ubuntu 12.04 +

Mininet [Bob Lantz and McKeown 2010] is an emulation environment which creates a complete network of hosts, links, and switches on a single machine. It creates virtual networks using process based virtualization and network namespaces (features available in Linux kernels). 

In Mininet, hosts are emulated as bash processes running in a network namespace. So any code that would run on a Linux server can be run within
a Mininet “Host”. The Mininet “Host” has its own private network interface and can only see its own processes. Switches in Mininet are software-based OpenFlow switches. Links are virtual ethernet pairs, which resides in the Linux kernel and connect emulated switches to emulated hosts. 

Mininet is useful for SDN interactive development, testing and demonstrations. SDN prototypes in Mininet can be transferred to hardware with minimal changes for real time execution.

Installation from Packages

#remove any traces of earlier versions of Mininet and Open vSwitch from /usr/local/

$sudo rm -rf /usr/local/bin/mn /usr/local/bin/mnexec \
    /usr/local/lib/python*/*/*mininet* \
    /usr/local/bin/ovs-* /usr/local/sbin/ovs-*


#to confirm which OS version you are running
$lsb_release -a

#install the base Mininet package corresponding to the distribution you are running
Mininet 2.1.0 on Ubuntu 13.10: sudo apt-get install mininet
Mininet 2.0.0 on Ubuntu 13.04: sudo apt-get install mininet
Mininet 2.0.0 on Ubuntu 12.10: sudo apt-get install mininet/quantal-backports
Mininet 2.0.0 on Ubuntu 12.04: sudo apt-get install mininet/precise-backports


#deactivate openvswitch-controller if it is running

$sudo service openvswitch-controller stop
$sudo update-rc.d openvswitch-controller disable


#test Mininet
$sudo mn --test pingall

#If Mininet complains that Open vSwitch isn’t working, you may need to rebuild its kernel module:
$sudo dpkg-reconfigure openvswitch-datapath-dkms
$sudo service openflow-switch restart


#install additional software

$git clone git://github.com/mininet/mininet
$mininet/util/install.sh -fw