wiki:GENIExperimenter/Tutorials/NSDI13/OpenFlowTutorial/Execute

Version 6 (modified by nriga@bbn.com, 11 years ago) (diff)

--

OpenFlow Tutorial using GENI

Hello GENI index Hello GENI index Hello GENI index

Configure and Initialize Services: Configure your OpenFlow switch

Although OVS is installed and initialized on the host that is meant to act as a software switch, it has not been configured yet. There are two main things that need to be configured : create your software switch with the interfaces as ports and point the switch to an OpenFlow controller.

In order to configure our switch, we first need to login to the host that will be used as an OpenFlow switch.

Login to OVS host

Login information for a VM
  1. Return to the Slice page. Press the Details button in the row of the slice table for Utah ProtoGENI.
  2. Click on the ssh link. If you have installed FireSSH a new tab will open up.
  3. In the window that will pop up :
    • in the password field type in your passphrase
    • in the private key, browse to the file that has your private key
    • Press OK
  4. If you don't have FireSSH installed, open a new terminal window. Copy the command to the right of Login into that terminal window.
  5. You are now logged in to the OVS host.

1. Create the Software Switch

Now that you are logged in, we need first to initialize OVS:

  • Start the OVS database:
    sudo ovsdb-server --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
    
  • Initialize OVS:
    sudo ovs-vsctl --no-wait init
    
    sudo ovs-vswitchd --pidfile --detach
    

Ignore the warnings you are going to see. Now that OVS is running it is time to create our software switch. The software switch will be a bridge, in which we are going to add all the interfaces we want to be part of the switch.

  1. Create the ethernet bridge
    • sudo ovs-vsctl add-br br0
    • sudo ovs-vsctl set bridge br0 datapath_type=netdev

  2. List all the interfaces of the node
    • ifconfig

  • Be careful not to bring down eth0. This is your control interface, if you bring that interface down you won't be able to login to your host!. For all interfaces other than eth0 and l0, remove the IP from the interfaces:
    • sudo ifconfig ethX 0

  • Add all the interfaces you just brought down to your switch (bridge):
    • sudo ovs-vsctl add-port br0 ethX
  • Login information for a VM

    Congratulations! You have configured your software switch, which three ports, let's see them. Run:

    sudo ovs-vsctl list-ports br0
    

    2. Point your switch to a controller

    An OpenFlow switch will not forward any packet, unless instructed by a controller. Basically the forwarding table is empty, until an external controller inserts forwarding rules. The OpenFlow controller communicates with the switch over the control network and it can be anywhere in the Internet as long as it is reachable by the OVS host. For the purpose of this tutorial and in order to minimize the resources we have reserved we are going to run OpenFlow controller at the same host as the OVS switch. This is merely for convenience reasons, the controller could have been anywhere on the Internet.

    In order to point our software OpenFlow switch to the controller run:

    sudo ovs-vsctl set-controller br0 tcp:127.0.0.1:6633
    

    standalone vs secure mode

    The OpenFlow controller is responsible for setting up all flows on the switch, which means that when the controller is not running there should be no packet switching at all. Depending on the setup of your network, such a behavior might not be desired. It might be best that when the controller is down, the switch should default back in being a learning layer 2 switch. In other circumstances however this might be undesirable. In OVS this is a tunable parameter, called fail-safe-mode which can be set to the following parameters:

    • standalone [default] : in which case OVS will take responsibility for forwarding the packets if the controller fails
    • secure : in which case only the controller is responsible for forwarding packets, and if the controller is down all packets are going to be dropped.

    In OVS when the parameter is not set it falls back to the standalone mode. For the purpose of this tutorial we will set the fail-safe-mode to secure, since we want to be the ones controlling the forwarding. Run:

    sudo ovs-vsctl set-fail-mode br0 secure
    

    Execute Experiment

    Now that our switch is up and running we are ready to start working on our controller. For this tutorial we are going to use the PoX controller.

    Login to your hosts

    Login information for a VM
    1. Return to the Portal browser tab.
    2. Click on the ssh link for each of your hosts. If you have installed FireSSH a new tab will open up.
    3. In the window that will pop up :
      • in the password field type in your passphrase
      • in the private key, browse to the file that has your private key
      • Press OK
    4. If you don't have FireSSH installed, open a new terminal window. Copy the command to the right of Login for each of your hosts into that terminal window.
    5. You are now logged in to the all your hosts.

    All of the hosts are in the 10.10.1.0/24 subnet. From host1 try pinging host2:

    ping 10.10.1.2
    

    This ping should timeout, since there is no controller running.

    Use a Learning Switch Controller

    We have installed the PoX controller under /tmp/pox. On the terminal of the OVS host run:

    cd /tmp/pox
    

    PoX comes with a set of example modules that you can use out of the box. One of the modules is a learning switch. Let's start the controller:

    ./pox.py --verbose samples.pretty_log forwarding.l2_learning
    

    Go back to the terminal of host1 and try to ping host2 again:

    ping 10.10.1.2
    

    Now the ping should work.

    Go back to your OVS host and take a look at the print outs. You should see that your controller installed flows based on the mac addresses of your packets. Kill your controller by pressing Ctrl-C. Notice what will happen to your ping.

    Soft vs Hard Timeouts

    All rules on the switch have two different timeouts:

    • Soft Timeout: This determines for how long the flow will remain at the forwarding table of the switch, if there no packets received that match the specific flow. As long as packets from that flow are received the flow remains on the flow table.
    • Hard Timeout: This determines the total time that a flow will remain at the forwarding table, independent of whether packets that match the flow are received; i.e. the flow will be removed after the hard timeout expires.

    Can you tell now why there were packets flowing even after you killed your controller?

    Run a port deflection Controller

    In the above example we ran a very simple controller. The power of OpenFlow comes from the fact that you can decide to forward the packet anyway you want based on the supported OpenFlow actions.

    As a first exercise we are going to take advantage of OpenFlow's ability to rewrite the src or destination port, and we are going to have two servers on the same host listening on different ports and dynamically diverge the packets to a server by rewriting the destination TCP port. In order to do that do the following:

    1. Open a second terminal on host2
    2. On each terminal of host2 run a netcat server on a different port:
      nc -l 5000
      
      nc -l 6000
      
    3. On your OVS host:
      cd /tmp/pox/ext
      
    4. Open the port_deflection.py file, and edit it to implement a controller that will change the port on the packets and deflect traffic to host2 port 5000 to host2 port 6000. If you want to see the solution, its in file port_deflection_sol.py file.
    5. Once you are done coding test your controller:
      cd /tmp/pox
      
      pox.py port_deflection
      
    6. Go back to the terminal of host1 and try to connect to host2 port 5000
      nc 10.10.1.2 5000
      
      If your controller works correctly you should see your text showing up on the terminal of host2 port 6000.

    Congratulations, you wrote an OpenFlow controller!

    Run a server deflection Controller

    As a second exercise, instead of diverging the traffic to a different server running on the same host, we will diverge the traffic to a server running on a different host.

    1. Open a second terminal on host3
    2. On the terminal of host3 run a netcat server:
      nc -l 5000
      
    3. On your OVS host open the server_deflection.py file, and edit it to implement a controller that will diverge traffic destined for host2 to host3. Before you start implementing think about what are the side effects of diverging traffic to a different host.
      • Is it enough to just change the IP address?
      • Is it enough to just modify the TCP packets?
      If you want to see the solution, its in file server_deflection_sol.py file.
    4. Once you are done coding test your controller:
      cd /tmp/pox
      
      pox.py server_deflection
      
    5. Go back to the terminal of host1 and try to connect to host2 port 5000
      nc 10.10.1.2 5000
      
      If your controller works correctly you should see your text showing up on the terminal of host3.

    Next : Finish the experiment