<OpenFlow Load Balancer ASSIGNMENT>

Hello GENI index Hello GENI index Hello GENI index


Debugging an OpenFlow Controller

You will find it helpful to know what is going on inside your OpenFlow controller and its associated switch when implementing these exercises. This section contains a few tips that may help you out if you are using the Open vSwitch implementation provided with this tutorial. If you are using a hardware OpenFlow switch, your instructor can help you find equivalent commands.
The Open vSwitch installation provided by the RSpec included in this tutorial is located in /opt/openvswitch-1.6.1-F15. You will find Open vSwitch commands in /opt/openvswitch-1.6.1-F15/bin and /opt/openvswitch-1.6.1-F15/sbin. Some of these commands may be helpful to you. If you add these paths to your shell’s $PATH, you will be able to access their manual pages with man. Note that $PATH will not affect sudo, so you will still have to provide the absolute path to sudo; the absolute path is omitted from the following examples for clarity and formatting.

  • 2.1 ovs-vsctl
    Open vSwitch switches are primarily configured using the ovs-vsctl command. For exploring, you may find the ovs-vsctl show command useful, as it dumps the status of all virtual switches on the local Open vSwitch instance. Once you have some information on the local switch configurations, ovs-vsctl provides a broad range of capabilities that you will likely find useful for expanding your network setup to more complex configurations for testing and verification. In particular, the subcommands add-br, add-port, and set-controller may be of interest.
  • 2.2 ovs-ofctl
    The switch host configured by the given rspec listens for incoming OpenFlow connections on localhost port 6634. You can use this to query the switch state using the ovs-ofctl command. In particular, you may find the dump-tables and dump-flows subcommands useful. For example, sudo ovs-ofctl dump-flows tcp: will output lines that look like this:
    cookie=0x4, duration=6112.717s, table=0, n packets=1, n bytes=74, idle age=78,priority=5,tcp,
    nw src= actions=CONTROLLER:65535
    This indicates that any TCP segment with source IP in the subnet should be sent to the OpenFlow controller for processing, that it has been 78 seconds since such a segment was last seen, that one such segment has been seen so far, and the total number of bytes in packets matching this rule is 74. The other fields are perhaps interesting, but you will probably not need them for debugging. (Unless, of course, you choose to use multiple tables — an exercise in OpenFlow 1.1 functionality left to the reader.)
  • 2.3 Unix utilities
    You will want to use a variety of Unix utilities, in addition to the tools listed in ExerciseLayout, to test your controllers. The standard ping and /usr/sbin/arping tools are useful for debugging connectivity (but make sure your controller passes ICMP ECHO REQUEST and REPLY packets and ARP traffic, respectively!), and the command netstat -an will show all active network connections on a Unix host; the TCP connections of interest in this exercise will be at the top of the listing. The format of netstat output is out of the scope of this tutorial, but information is available online and in the manual pages.


  • 3.3 Load Balancing -- Files to download: load-balancer.rb,
    Load balancing in computer networking is the division of network traffic between two or more network devices or paths, typically for the purpose of achieving higher total throughput than either one path, ensuring a specific maximum latency or minimum bandwidth to some or all flows, or similar purposes. For this exercise, you will design a load-balancing OpenFlow controller capable of collecting external data and using it to divide traffic between dissimilar network paths so as to achieve full bandwidth utilization with minimal queuing delays.
    An interesting property of removing the controller from an OpenFlow device and placing it in an external system of arbitrary computing power and storage capability is that decision-making for network flows based on external state becomes reasonable. Traditional routing and switching devices make flow decisions based largely on local data (or perhaps data from adjacent network devices), but an OpenFlow controller can collect data from servers, network devices, or any other convenient source, and use this data to direct incoming flows.
    For the purpose of this exercise, data collection will be limited to the bandwidth and queue occupancy of two emulated network links.

Experimental Setup

Follow instructions in the DesignSetup step to build a load balancing experiment topology. Your GENI resources will be configured in a manner similar to the above figure. The various parts of the diagram are as follows:

    • Inside and Outside Nodes: These nodes can be any exclusive ProtoGENI PCs.
    • Switch: The role of the Open vSwitch node may be played either by a software Open vSwitch installation on a ProtoGENI node, or by the OpenFlow switches available in GENI — consult your instructor.
    • Traffic Shaping Nodes (Left and Right): These are Linux hosts with two network interfaces. You can configure netem on the two traffic shaping nodes to have differing characteristics; the specific values don’t matter, as long as they are reasonable. (No slower than a few hundred kbps, no faster than a few tens of Mbps with 0-100 ms of delay would be a good guideline.) Use several different bandwidth combinations as you test your load balancer.
    • Aggregator: This node is a Linux host running Open vSwitch with a switch controller that will cause TCP connections to “follow” the decisions made by your OpenFlow controller on the Switch node.

Linux netem
Use the tc command to enable and configure delay and bandwidth constraints on the outgoing interfaces for traffic traveling from the OpenFlow switch to the Aggregator node. To configure a path with 20 Mbps bandwidth and a 20 ms delay on eth2, you would issue the command:

sudo tc qdisc add dev eth2 root handle 1:0 netem delay 20ms
sudo tc qdisc add dev eth2 parent 1:0 tbf rate 20mbit buffer 20000 limit 16000

See the tc and tc-tbf manual pages for more information on configuring tc token bucket filters as in the second command line. Use the tc qdisc change command to reconfigure existing links,instead of tc qdisc add.
The outgoing links in the provided lb.rspec are numbered and for left and right, respectively.

Balancing the Load
An example openflow controller that arbitrarily assigns incoming TCP connections to alternating paths can be found at load-balancer.rb (If you have already downloaded it, ignore this).
The goal of your OpenFlow controller will be to achieve full bandwidth utilization with minimal queuing delays of the two links between the OpenFlow switch and the Aggregator host. In order to accomplish this, your OpenFlow switch will intelligently divide TCP flows between the two paths. The intelligence for this decision will come from bandwidth and queuing status reports from the two traffic shaping nodes representing the alternate paths.
When the network is lightly loaded, flows may be directed toward either path, as neither path exhibits queuing delays and both paths are largely unloaded. As network load increases, however, your controller should direct flows toward the least loaded fork in the path, as defined by occupied bandwidth for links that are not yet near capacity and queue depth for links that are near capacity.
Because TCP traffic is bursty and unpredictable, your controller will not be able to perfectly balance the flows between these links. However, as more TCP flows are combined on the links, their combined congestion control behaviors will allow you to utilize the links to near capacity, with queuing delays that are roughly balanced. Your controller need not re-balance flows that have previously been assigned, but you may do so if you like.
The binding of OpenFlow port numbers to logical topology links can be found in the file /tmp/portmap on the switch node when the provided RSpec boots. It consists of three lines, each containing one logical link name (left, right, and outside) and an integer indicating the port on which the corresponding link is connected. You may use this information in your controller configuration if it is helpful.
You will find an example OpenFlow controller that arbitrarily assigns incoming TCP connections to alternating paths in the file load-balancer.rb. This simple controller can be used as a starting point for your controller if you desire. Examining its behavior may also prove instructive; you should see that its effectiveness at achieving the assignment goals falls off as the imbalance between balanced link capacities or delays grows.

Gathering Information
The information you will use to inform your OpenFlow controller about the state of the two load-balanced paths will be gathered from the traffic shaping hosts. This information can be parsed out of the file /proc/net/dev, which contains a line for each interface on the machine, as well as the tc -p qdisc show command, which displays the number of packets in the token bucket queue. As TCP connections take some time to converge on a stable bandwidth utilization, you may want to collect these statistics once every few seconds, and smooth the values you receive over the intervening time periods.
You may find the file /tmp/ifmap on the traffic shaping nodes useful. It is created at system startup, and identifies the inside- and outside-facing interfaces with lines such as:

inside eth2
outside eth1

The first word on the line is the “direction” of the interface — toward the inside or outside of the network diagram. The second is the interface name as found in /proc/net/dev.
You are free to communicate these network statistics from the traffic shaping nodes to your OpenFlow controller in any fashion you like. You may want to use a web service, or transfer the data via an external daemon and query a statistics file from the controller. Keep in mind that flow creation decisions need to be made rather quickly, to prevent retransmissions on the connecting host.

To help user to fetch the information about the amount of traffic as well as the queue depth (measured in number of packets) on both left and right node, we provide a script that the user can download and run on both left and right node
You can download the script from (If you have already downloaded it, ignore this). Then do the following to start monitoring network usage:

    • 1. install Twisted Web package for Python on both left and right node:
      sudo yum install python-twisted-web
    • 2. upload onto left and right node, then change the listening IP address in to the public IP address of left and right node respectively. i.e., replacing the following in your file to the public IP address of the left/right node.
      reactor.listenTCP(8000, factory, interface = '')
    • 3. apply qdisc on interface eth1 of both left and right node by executing (you may further change the parameters by using tc qdisc change):
      sudo /sbin/tc qdisc add dev eth1 root handle 1:0 netem delay 20ms
      sudo /sbin/tc qdisc add dev eth1 parent 1:0 tbf rate 20mbit buffer 20000 limit 16000
    • 4. run the script by:
    • 5. verify it is working by opening a web browser and typing the following URL (replacing with your left or right node's public IP address):
      For more information about, please look at the comments in the file.

To help you get started, the following is the ruby class that helps collecting the monitoring results:

class DataCollector
    @@Weight = 0.2

    attr_reader :port

    def initialize(host, port)
        @host = host
        @uri = 'http://' + host + ':8000/qinfo/'
        @last = 0
        @ewmabytes = 0
        @ewmapkts = 0
        @lock =
        @port = port

    def run
        starttime =
        while true
            data = Net::HTTP.get(URI(@uri + @last.to_s))
            data.each do |line|
                ts, bytes, qlen = line.chomp.split(' ').map { |x| x.to_i }
                @lock.synchronize do
                    if ts <= @last
                    elsif @last == 0
                        @ewmabytes = bytes
                        @ewmapkts = qlen
                        # Just assume we haven't missed too many entries
                        @ewmabytes = bytes * @@Weight + @ewmabytes * (1 - @@Weight)
                        @ewmapkts = qlen * @@Weight + @ewmapkts * (1 - @@Weight)
                    @last = ts
            sleep 5

    def averages
        a = nil
        @lock.synchronize do
            a = [@ewmabytes, @ewmapkts]
        return a

In the above code, function averages will return the weighted average number of bytes seen in the corresponding node, as well as the weighted average queue depth in terms of number of packets seen in the corresponding node.
Here is some example code that makes use of this class:

        @collectors = [$leftip, @leftport),
             $rightip, @rightport)]
        @collectors.each do |collector|
   do |c|

        left_monitor_value = @collectors[0].averages
        right_monitor_value = @collectors[1].averages
        #left_monitor_value[0] shows the average number of bytes seen on the left node
        #left_monitor_value[1] shows the average number of queued packets on the left node

Question: Implement your load-balancer.rb, run it on switch, and display the number of bytes and queue length on both left and right node when a new TCP flow comes and path decision is made
A sample output should be as follows:

left:  5302.5338056252 bytes, Q Depth: 20.5240502532964 packets
right: 14193.5212452065 bytes, Q Depth: 27.3912943665466 packets
so this new flow goes left. Total number of flows on left: 1

You can use iperf to generate TCP flows from outside node to inside node:

    • On inside, run:
      /usr/local/etc/emulab/emulab-iperf -s
    • On outside run the following multiple times, with about 6 seconds interval between each run:
      /usr/local/etc/emulab/emulab-iperf -c -t 100 &
      This will give the enough time to collect network usage statistics from both left and right node so that the load-balancer can make the right decision.

If you really do not know where to start, you can find a semi-complete load-balancer.rb HERE, you only need to complete the next_path function that prints out the statistics of each path and returns the path choice
Hints: Want to get the complete load-balancer.rb? ask your instructor or visit here (you need a password to get it), or send an email (the solution code may be full of bugs, feel free to tweak it and report bugs/ask questions)

    • Remember that the TCP control loop is rathers low — on the order of several round trip times for the TCP connection. This means your load balancing control loop should be slow.
    • You may wish to review control theory, as well as TCP congestion control and avoidance principles.
    • Without rebalancing, “correcting” a severe imbalance may be difficult or impossible. For testing purposes, add flows to the path slowly and wait for things to stabilize.
    • Some thoughts on reducing the flow count when load balancing via Open- Flow can be found in Wang et al. You are not required to implement these techniques, but may find them helpful.
    • Remember that the default OpenFlow policy for your switch or Open vSwitch instance will likely be to send any packets that do not match a flow spec to the controller, so you will have to handle or discard these packets.
    • You will want your load balancer to communicate with the traffic shaping nodes via their administrative IP address, available in the slice manifest.
    • If packet processing on the OpenFlow controller blocks for communication with the traffic shaping nodes, TCP performance may suffer. Use require ’threads’, Thread, and Mutex to fetch load information in a separate thread.
    • The OpenFlow debugging hints from Section 3.1 remain relevant for this exercise.
  • Simplified Load Balancer:
    The above question requires the user to implement a web server on both left node and right node to report the querying results about token bucket buffer statistics. At the same time, the openflow controller that the experimenter implemented should pull the web page, parse the content to get those statistics, which seems to be too complicated.

An alternative way to accomplish this is by querying Flow statistics directly from the OpenFlow switch.

Process: Upon the arrival of a new TCP flow, the OpenFlow controller should send out a FlowStatsRequest message to the OpenFlow switch. The OpenFlow switch will reply with statistics information about all flows in its flow table. This flow statistics message will be fetched by the stats_reply function in the openflow controller implemented by the user on node switch. Based on the statistics, experimenters can apply their own policy on which path to choose in different situations. The FlowStatsReply message is in the following format:
  :length => 96,
  :table_id => 0,
  :match =>
  :duration_sec => 10,
  :duration_nsec => 106000000,
  :priority => 0,
  :idle_timeout => 0,
  :hard_timeout => 0,
  :cookie => 0xabcd,
  :packet_count => 1,
  :byte_count => 1,
  :actions => [ ]

For more information about FlowStatsRequest and FlowStatsReply, please refer to and
The difference between this Load Balancer and the Load Balancer introduced in the previous section is, this Load Balancer only reports the cumulated statistics of each flow over-time while the previous Load Balancer fetches the real-time network traffic information from both paths.

We have already implemented a sample Load Balancer that decides path based on the accumulated number of bytes sent through left and right path (such that the new flow will go to the one path with less number of bytes sent).
Experimenter can download the sample Load Balancer HERE.

Question: Try modify the downloaded load balancer so that it decides path based on the average per-flow throughput observed on each path

Note: since Trema does not yet support multi-thread mode, this simple implementation runs in one thread. As a result, users will experience some delay in fetching the flow statistics (i.e., stats_reply will not be called right after a FlowStatsRequest message has been sent in packet_in handler).

Next: Teardown Experiment

Last modified 9 years ago Last modified on 05/31/13 10:11:56

Attachments (1)

Download all attachments as: .zip