Getting Started OpenFlow OpenvSwitch Tutorial Lab : Setup

Getting Started OpenFlow OpenvSwitch Tutorial Lab : Setup

Open Vswitch Lab

Getting Started OpenFlow OpenvSwitch Tutorial Lab : Setup
For a more up to date tutorial as anything more then 6 months old is outdated in the world of SDN Please see:
OpenDaylight OpenStack Integration with DevStack on Fedora 20

I wrote a Python OpenFlow installation app to automate an OpenFlow KVM and Open vSwitch setup found at:
OpenFlow, OpenvSwitch and KVM SDN Lab Installation App →


Getting Started OpenFlow OpenvSwitch Tutorial Lab – Setup:

Getting Started OpenFlow OpenvSwitch Tutorial Lab : This is an OpenFlow Tutorial using OpenvSwitch and Floodlight controller but any other controller or switch can be used. I have had some requests on some scenarios so I put this together. Adding a few more flexible components. Getting to know all of these packages like KVM, OpenvSwitch are going to be pretty big in the future ecosystem orchestrations.

The video doesn’t have any sound, I am tight on time, sorry. I think it should be pretty straightforward and the video may help if you get stuck. Probably a couple typos here and there I will try and catch over the weekend. We are lacking good lab material on these topics right now so maybe this will save a couple folks some time.


Prerequisites

The KVM requires an x86 machine with either Intel VT or AMD w/AMD-V support. Anything fairly new will have that support in the processor. There are a few older HW builds that support hardware assisted virtualization by enabling it in the bios. Pretty much Googling your machine for hardware virtualization will let you know. Qemu can be run on non VT HW but the machines will probably get brutalized by a few host VMs. When you are setting up the vSwitch either have an out of band or be on it physically. Be careful when you are adding multiple interfaces to bridges since you can spin up a bridging loop pretty quickly unless you have STP on. I recommend a test/dev network or mom’s basement network. If not BPDUguard is your friend 🙂 This is done on a fresh install of 64-bit Ubuntu 12.04 (Precise).

Quick screencast. I highly recommend considering using a small Linux Kernel named linux-0.2.img.bz2 from Qemu if using a laptop or nested hypervisor.



Install OpenvSwitch


Add your bridge, think of this as a subnet if you aren’t familiar with the term.

Add a physical interface to your virtual bridge for connectivity off box. If you don’t script this part you will probably clip your connection as you zero out eth0 and apply it to br-int. You can pop the commands into a text file and make it executable with
chmod +x script.sh


Install FloodLight OpenFlow Controller and Attach OpenvSwitch

Install dependencies, apt-get for UB and yum for RH:

Clone the Github project and build the jar and start the controller:


Attach OpenvSwitch to the Controller


In the FloodLight console you will see something like this:

 


The output of OVS ‘ovs-vsctl show’ looks something like this:



Install KVM and Integrate into OVS

These two scripts bring up the KVM Tap interfaces into your bridge from the CLI. If you copy and paste below make sure the (‘) does not get formatted improperly. It should be yellow in nano. “switch=br-int” br-int is the name of your bridge in OVS.
$nano /etc/ovs-ifup  (open and paste what is below)

$nano /etc/ovs-ifdown (open and paste what is below)

Make both files executable
chmod +x /etc/ovs-ifup /etc/ovs-ifdown


Boot the Guest Virtual Machines

  • Host1

  • Host2

  • Host3

Each one of those will begin loading from the ISO. I just click “Try Ubuntu” when they are booting and just run them from disk since really all we need are nodes that can test connectivity as we push static flows. If it is a more permanent test lab it would make since to install them to disk.

While those are spinning up let’s install curl.


Figure 1. OVS Taps


One they are up assign IP addresses to them by clicking in the top left of the Ubuntu window and type in ‘terminal’ no parentheses. Then give them IPs if you want to statically assign them with ifconfig.


Check out the rest of the tutorials in this series:


Thanks for stopping by.

About the Author

Brent SalisburyI have over 20 years of experience wearing various hats from, network engineer, architect, ops and software engineer. More at Brent's LinkedInView all posts by Brent Salisbury →

  1. RolandRoland06-27-2012


    Wow..great tutorial setup. I started on senior project about OF and OVS and always stuck about how set it up. You save my day. Thank you very much. Can I adopt this for senior project?

    • RolandRoland06-27-2012


      I mean to adopt the setting. It will be helpful if you can give me some idea. Thanks again! Really helpful articles in this site.

      • Brent SalisburyBrent Salisbury06-27-2012


        Hi roland, Please do take whatever is helpful. It’s all just piecing other peoples work together. Sharing what you do with it would be just as, or even more interesting!
        Thanks,
        -Brent

        • varunvarun07-20-2012


          Hi Brent,
          The question I want to ask is whether we can implement the shortest path scheme for ARP demo given for Openflow controller or is it given in any of the scripts?????

  2. Phil HattwickPhil Hattwick07-08-2012


    Hi Brent, Your posts are a great source of sanity when debugging ovs issues. I think had an issue with one of your steps:

    $ ovs-vsctl add-br br0
    $ ovs-vsctl add-port br-int eth0

    If course, I could be wrong, but I had to add-br br-int instead of add-br br0, so that the second command would work. I checked your video, and you made this correction in the video.

    Hope this is helpful.

    Special Agent

    • Phil HattwickPhil Hattwick07-09-2012


      Also I experimented with not adding a tap. Instead, I edited /etc/vmbuilder/libvirt and added:

      Doing this, I no longer added taps. When I launch a new guest, vnet0 was automatically added to ovs bridge br-int.

      • Brent SalisburyBrent Salisbury07-09-2012


        Thanks a bunch Phil, good grief I had about 5 randoms mixes there. doh. Thats slick on the vmbuilder tweak. If you get a chance would you paste that conf? Thanks!!

  3. varunvarun07-20-2012


    one more thing what more can we do with openflow? does it need to write a script in python for that?

    • Brent SalisburyBrent Salisbury07-27-2012


      Hi Varum, Apologies for the delay on the comment. I need to get a plugin to better manage comments, I totally missed it. I would say scripting is going to be pretty handy for us in the early days or even like it is today for sysadmins and some of the more homegrown network management stuff since what we have today as far as tools is so weak most need to do something do it yourself for anything niche.

      In the Floodlight directory under examples there is a Python script called cli.py that can do some things also. Murphy with the POX controller is putting some cool stuff together on this front also. I strongly feel it will help folks better understand what the concepts are as the basic tools start being available. I am working on a couple things that is midway on the list I hope to get out in the next couple of weeks that will be just basic python tools to make it a bit easier to do some learning labs. Let me know if there was anything more specific you were looking for.
      regards,
      -Brent

  4. nehaneha08-23-2012


    Hey there
    I am trying to set up the lab following your tutorial. I have successfully done the 1st part of the lab but when I start with the second part of installing the kvm and running virtual host i get the following error :

    “Could not access KVM kernel module: No such file or directory
    failed to initialize KVM: No such file or directory”
    I get this this error when I try spin up the host . please guide me through the same.

    regards.

    • Brent SalisburyBrent Salisbury08-24-2012


      Hi Neha, Sounds the KVM kernel module is not loaded. You will need to get that up and running. Try ‘modprobe kvm-intel’ or ‘modprobe kvm-amd’ depending on your arch type (amd or intel).

      If it is not found that way, you can try searching for it and loading it with insmod.
      (as root)
      $ updatedb &
      $ locate kvm | grep ko
      $ insmod /path/to/kvm-intel.ko

      Here is an example:

      openstack3:~# locate kvm | grep ko
      /lib/modules/3.2.0-23-generic/kernel/arch/x86/kvm/kvm-amd.ko
      /lib/modules/3.2.0-23-generic/kernel/arch/x86/kvm/kvm-intel.ko
      /lib/modules/3.2.0-23-generic/kernel/arch/x86/kvm/kvm.ko
      /lib/modules/3.2.0-25-generic/kernel/arch/x86/kvm/kvm-amd.ko
      /lib/modules/3.2.0-25-generic/kernel/arch/x86/kvm/kvm-intel.ko
      /lib/modules/3.2.0-25-generic/kernel/arch/x86/kvm/kvm.ko

      insmod /lib/modules/3.2.0-23-generic/kernel/arch/x86/kvm/kvm-intel.ko

      Output after that if accepted should be something like this:
      openstack3:~# lsmod | grep kvm
      kvm_intel 137721 0
      kvm 415549 1 kvm_intel

      I am a little worried you may be on older hardware that doesnt have hardware virtualization. If so the QEMU command will be what you will use.

      Output as a ‘Y’ from this command may help.

      cat /sys/module/kvm_intel/parameters/nested
      or run
      grep –color vmx /proc/cpuinfo

      and the output should have VMX support highlighted.

      Thanks,
      -Brent

  5. Valentin BudValentin Bud09-10-2012


    I have read a few post of yours regarding openvswitch. I must say I like your writing style. Thanks for sharing.
    I am curios what other openflow controllers are out there that worth investing time in playing with?
    I am new to openflow, I admit I don’t really grasp the concept but I think it could be used in virtualization environments side by side with KVM and OpenNebula to provide better security and to direct traffic from certain VMs to only a subset of VMs. Am I right?
    Thanks

    • Brent SalisburyBrent Salisbury09-13-2012


      Hi Vanlentin, You are absolutely right. I think the big picture promise would be that we have this giant flat network and all tenancies are maintained by flow instantiation that determines programmatically who can and cant talk to each other via policy. I dont think it is too crazy, pretty sure thats the guys of the Nicira NVP product and upcoming ones from IBM/BigSwitch etc. Sorry for the slow reply been traveling a bit.
      Thanks!

  6. patriciopatricio10-20-2012


    hi,
    thank you very much for your tutorial. I’m new on openflow and linux.
    every time i execute the comands of the tutorial my internet stops workiing, do you knnow why?
    please help me.

  7. Brent SalisburyBrent Salisbury10-20-2012


    Hi Patricio, When you add eth0 to the br-int interface you will drop your connection until you change your default route.
    $route -n should point to br-int and your gateway instead of eth0 since you zeroed out your ip and moved it to br-int.

    If you put this in a file and give it +x permissions and execute it it will prolly work for you.

    chmod +x
    ./
    ==================================
    ovs-vsctl add-br br-int
    ovs-vsctl add-port br-int eth0
    ifconfig eth0 0
    ifconfig br-int netmask 255.255.255.0 < ------- Insert your ip address route add default gw br-int < ------your default gateway ie. 192.168.1.1 =================================== From the post: $ ovs-vsctl add-br br-int Add a physical interface to your virtual bridge for connectivity off box. If you don’t script this part you will probably clip your connection as you zero out eth0 and apply it to br-int. You can pop the commands into a text file and make it executable with chmod +x ,

    $ ovs-vsctl add-port br-int eth0
    $ ifconfig eth0 0

    Zero out your eth0 interface and slap it on the bridge interface
    (warning will clip you unless you script it)

    $ifconfig br-int 192.168.1.208 netmask 255.255.255.0
    Change your default route
    $route add default gw 192.168.1.1 br-int

    Thanks,
    -Brent

  8. RolandRoland10-20-2012


    Hi,

    This command only bring up the Ubuntu guest VM from .iso file.
    kvm -m 512 -net nic,macaddr=00:00:00:00:cc:10 -net tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown -cdrom ubuntu-12.04-desktop-amd64.iso

    How to modify this command to start a VM from an existing image file (.img, .qcow2, .vmdk)?
    I tried,

    kvm -m 512 -net nic,macaddr=00:00:00:00:cc:10 -net tap,script=/etc/ovs-ifup,downscript=/etc/ovs-ifdown vm1.qcow2

    but it does not work. Please help. Thank you

  9. HemantHemant11-06-2012


    Hi,

    Thank you for the tutorial..It really helped a lot..But I am facing a problem while adding route using the command route add default gw 192.168.1.1 br-int, I get the SIOCADDRT: Invalid Argument error..And when I delete the route using the command route del default gw 192.168.1.1 eth0, I get SIOCADDRT: No Such Process error..Can you please help me..I am working on an academic Openflow project.

    Thanks,
    Hemant

  10. vamsivamsi11-15-2012


    Brent, can you provide the link to the next section ? This blog is the most helpful on SDN networking and appreciate your efforts.

    I am trying to build a simple topology using openvswitches, and can see the flows on the floodlight controllers, but how do we manipulate these flows ? Is there a separate componant like flow visor which needs to be installed for manipulating flows ? Please suggest how to proceed.

  11. WayneWayne11-16-2012


    It a good guide to let us try to use Open vSwitch, thank you very much!!
    And I’m expecting the next section now!!

  12. Brent SalisburyBrent Salisbury11-18-2012


    Hey guys, I need to fix some links. Here are 3 labs. I probably need to revisit them so apologies if a typo or two.

    http://networkstatic.net/openflow-starter-tutorial-lab-1/
    http://networkstatic.net/openflow-tutorial-lab-2/
    http://networkstatic.net/openflow-tutorial-lab-3/
    http://networkstatic.net/tutorial-to-build-a-floodlight-sdn-openflow-controller-module/

    Once nice thing I have run across is a small Linux Kernel w/ a network stack image that is much better than using a full blown Linux Distro. Can be DLed at
    http://wiki.qemu.org/download/linux-0.2.img.bz2

    Thanks!
    -Brent

  13. EzdenEzden11-22-2012


    Hello
    I am new to Linux but I am trying to build OpenVswitch to work as a physical L2 switch, I add the eth0 and wlan0 to the bridge , and I deleted their ip addresses. I connect those interfaces to two computers.

    Now those two computers can detect each other through the middle openvswitch computer , i can see their macs in each other arp table, but I couldnt make them ping each other.

    any suggestion please?

  14. JohnJohn01-10-2013


    Hi Brent,

    This is a fantastic post and got me started on the technology from very little foundations. I have two queries though if you don’t mind:

    1 – When I build the jar and start the controller i.e. $java -jar target/floodlight.jar I get a whole host of commands that seem to be never ending. Perhaps this is binding to all the ports but if I am to continue the tutorial I need to open a new terminal. This has run in the past for hours upon end. I am guessing this is incorrect?

    2 – When I run the KVM creation command I can’t seem to intall Ubuntu as it says I’m not connected to the Internet and I don’t have enough free space (though I have lots of free space). When I manually try and created these VMs through Virtualbox, I can do so if I choose eth0 as the Bridged adapter, but the second I choose br-int as the bridged adapter the whole host hangs.

    Anyone got any ideas?

  15. NitinNitin01-19-2013


    Dear Sir,

    I have problem in using git clone git://github.com/floodlight/floodlight.git command for installation of floodlight.
    When i run it, my terminal shows error like:
    Cloning into floodlight…
    github.com[0: 207.97.227.239]: errno=Connection refused
    fatal: unable to connect a socket (Connection refused)

    Thanking You

  16. RizwanRizwan02-14-2013


    Hi Brent,

    A question, i have setup up NAT (masquerade) at linux ethernet interface. Now using openvswitch if i add this port to openflow bridge, tutorial says i’d have to remove the IP Address. Im wondering is there any possibility to let the routing/natting being done by linux iptables itself while just do the switching decision using openflow??

    What would happen if i do not remove the IP Address and in openflow controller, just add flowmod to redirect packet to particular port and don’t change the headers etc.

    Would this work, or i have to implement the whole NAT scenario in OFController???

  17. Florence-amaddineFlorence-amaddine04-11-2013


    Hello!
    I’m working on a project to make a stress test on OpenFlow controller, can you help me with your knowledge.!!!!
    My problem I do not know how to define the flow rules in the nox controller.
    and how to put two nox controllers in a same network (to have a master and slave?)!!!! thank’s

  18. EtienneEtienne04-28-2013


    Hi! ,

    First of all I would like to thank you for these guides and for the time which you are spending in writing them. Just wondering if you have a simple guide how to install OpenVswitch on an ubuntu machine without KVM. Basically i am not very keen on Linux and i have a Pc with 4 NIc cards and want to convert it into a simple 1 switch, however i couldnt find any source to this, all posts relate to using KVM.

    Many thanks for this
    Etienne

  19. Brent SalisburyBrent Salisbury04-28-2013


    Heya Etienne, thanks and I do have an older post with that.

    Take a look at Installing Open vSwitch with KVM :
    http://networkstatic.net/installing-open-vswitch-with-kvm/

    I just took a quick look and it still looks to be valid. Let me know if you have issues with it and I will try and get back fairly quickly.

    Cheers,
    -Brent

    • etienneetienne04-29-2013


      Hi Brent! Thanks for your reply. Still have a question :/ That post shows how to install Open vSwitch using KVM (sorry i am no expert on Linux) right ? I would like to install the switch on a bare PC (without KVM thing) having 4 nic cards basically eth0 will be the uplink to the controller while eth1,eth2,eth3 will be the physical switch ports . Is this the manual which I must look into http://networkstatic.net/openvswitch-configure-from-packages-and-attaching-to-a-floodlight-openflow-controller/ ? There you explained how to install Open VSwitch using packages.

      Sorry about this but i’m still a bit confused.

      Thanks
      Etienne

      • Brent SalisburyBrent Salisbury04-29-2013


        Ahh I got you. Yeah Open vSwitch is built to be compiled on Linux. I haven’t heard of a Windows port. That said, now is as good a time as any to learn Linux 🙂

        I really do recommend everyone that deals with infrastructure understand basic Linux commands and architectures.

        If you feel like giving it a shot this will get you started building a VM on your windows machine w/ VirtualBox
        http://networkstatic.net/openvswitch-and-openflow-lab-preparation/

        Cheers,
        -Brent

        • EtienneEtienne04-30-2013


          Hi Brent, Many thanks for this ! and by the way.. nice blog 🙂 really informative and helpful for a newbie like I am !

          Thanks again…
          Etienne

  20. Brent SalisburyBrent Salisbury04-30-2013


    Certainly, glad to help Etienne. Drop by and let me know how the learning is going. Keep it up.
    Regards,
    -Brent

  21. RameshRamesh06-29-2013


    Sir how do i open the VM .

    • Brent SalisburyBrent Salisbury07-03-2013


      Hey Ramesh, It should pop open for you. In the script it will call the VM instances. I think I was compiling Open vSwitch from source so it could be you are running the latest stable kernel 3.9.8 which OVS isnt compiling on quite yet.

      Run: ovs-vsctl show

      Make sure that shows up. Go through the script and find where the KVM/Qemu instance is called and try that from the CLI.

      Cheers,

      Brent

  22. kevinkevin07-03-2013


    Hi Brent,
    After setting ip static. Why my internet stop working?
    Can you help me? please!

  23. Anu MAnu M10-15-2013


    Hi Brent,

    Great article. I have Ubuntu 12.04.3 spun up on my KVM virtual machine and I am doing the procedure you mention here to install kvm and ovs in the virtual machine. When I purge network-manager, I am unable to continue installing openvswitch as my network connection is lost. Can you help me with this?

    PS: I have a wireless connection for my host.

    Thank you,
    Anu

  24. Brent SalisburyBrent Salisbury10-16-2013


    Hi Anu, I really need to pull the remove network-manager out. It isnt a requirement. I just used to get annoyed with network-manager and brcompat pre-OVS kernel module being upstreamed. Sorry about that, just leave it in place and it shouldnt affect anything. Wireless is tough without it.

    For just regular wired connections /etc/network/interfaces holds the persistent IP information (which im sure you know but for others).

    Let me know how it goes, I need to update the lab with Daylight modules. By the way I posted a couple of quick videos on setting up edge switches as firewalls. It might be interesting for you. I have a bunch more I need to get posted. Check the bottom of this post if interested.

    http://networkstatic.net/the-openflow-overlay/

    Cheers!
    -Brent

    • Anu MAnu M10-22-2013


      Thank you very much, Brent. Great help!

  25. spencerspencer10-16-2013


    Hello Brent. First of all, thank you very much for the article.

    Here is the situation. The topology is as follows.
    Laptop (PC A) is the openvswitch. On PC A, 2 virtual machines(clients) are running. (Followed all the steps on this page.) Desktop (PC B) is the controller. They are connected by an ethernet cable plugged in directly. *PC A has br-int connected to tap0, tap1, eth0 ports connected.

    The final goal is to track and manage flows on PC A from PC B (floodlight).

    The problem comes when i try to connect br-int to controller on PC B. When the connection to the controller is established, all the pinging and routing stops. Even from vm1 to vm2. I could see the switch and hosts on the floodlight UI but can’t seem to see the flow on it. If i detach the controller off PC B, pinging from vm1 to vm2 works. Same as from PC A(host) to vm1 (client).

    Am I doing something wrong or misunderstanding something?
    Could you help me with this issue?

    Thank you again,
    Spencer.

  26. CharanCharan10-18-2013


    Hi Brent,
    Thank you for all your posts. I have few doubts regarding one of my projects on SDN.
    Could you help me about how to write flows on an OVS switch. Is it possible to write code in Shell Scripting ?
    I have OVS switch and floodlight controller installed in one VM. Other two Host (VMs) connected to OVS, I want to push flows so that the traffic on OVS port eth0 (Host1) should get routed to port eth1 (Host2).

    Thanks in advance
    Charan


  27. It’s not my first time to pay a quick visit this site, i am visiting this web page dailly and get nice data from here everyday.


  28. Howdy! This is kind of off topic but I need some guidance from an established blog.

    Is it difficult to set up your own blog? I’m not very techincal
    but I can figure things out pretty fast.
    I’m thinking about making my own but I’m not sure where to begin.
    Do you have any ideas or suggestions? Many thanks

  29. Han HsuHan Hsu01-07-2014


    Hi!
    I created a network with two openvswitch(A and B) and a controller:
    B(eth0) ——– (eth0)A(eth1) —— controller
    using this command:
    A:> ovs-vsctl add-br br0
    > ovs-vsctl add-port br0 eth0
    B: > ovs-vsctl add-br br0
    > ovs-vsctl add-port bro eth0
    The controller’s IP is 192.168.2.200
    Can you tell me how to use commands to connect A,B to controller?


  30. Very good post. I am experiencing a few of these issues as well..

  31. ElenaElena03-16-2014


    Good post. I learn something totally new and challenging on sites I stumbleupon everyday.

    It’s always exciting to read content from other authors and practice a little something from their web sites.

  32. sakshisakshi04-09-2014


    In real scenario is it possible to connect controller using one IP Address to many switches?


  33. Simply want to say your article is as astonishing.
    The clarity in your post is simply spectacular and i
    could assume you’re an expert on this subject.
    Fine with your permission allow me to grab your feed to keep up to date with
    forthcoming post. Thanks a million and please carry on the gratifying work.