Version 13 (modified by 10 years ago) (diff) | ,
---|
OpenFlow Load Balancer Tutorial
Appendix: Hints and Explanations
A. LabWiki Script for the LoadBalancer
defProperty('slice', 'testloadbal3', "slice name") defProperty('intervalcol',"1", "Interval to Tail") defProperty('theSender', "outside", "ID of sender node") defProperty('theReceiver', "inside", "ID of receiver node") defProperty('theSwitch',"switch", "ID of switch node") defProperty('pathfile', "/tmp/flowstats.out", "Path to file") theSender = property.theSender.to_s.split(',').map { |x| "#{x}-#{property.slice}" } theReceiver = property.theReceiver.to_s.split(',').map { |x| "#{x}-#{property.slice}" } theSwitch = property.theSwitch.value.to_s.split(',').map { |x| "#{x}-#{property.slice}" } iperfNodes = theSender + theReceiver defApplication('clean_iperf') do |app| app.description = 'Some commands to ensure that we start with a clean slate' app.binary_path = '/usr/bin/killall -s9 iperf; ' app.quiet = true end defApplication('iperfserv') do |app| app.description = "manually run Iperf server" app.binary_path = "/usr/bin/iperf -s" end defApplication('iperfclient') do |app| app.description = "manually run Iperf client" app.binary_path = "/usr/bin/iperf -c 10.10.10.2 -t 800 -P 5" end defApplication('ofstats') do |app| app.description = 'Simple Definition for the of-collect application' # Define the path to the binary executable for this application app.binary_path = '/usr/local/bin/ofcollect.rb' app.defProperty('target', 'Address to output file', '-f', {:type => :string}) app.defProperty("interval","Interval",'-i', {:type => :string}) app.defMeasurement('wrapper_ofthroughput') do |m| m.defMetric('pathtype', :string) m.defMetric('throughput',:int64) m.defMetric('avgperflow',:int64) end end defGroup('iperf_nodes', *iperfNodes) do |g| g.addApplication("clean_iperf") do |app| end end defGroup('Source1', *theSwitch) do |node| node.addApplication("ofstats") do |app| app.setProperty('target', property.pathfile) app.setProperty('interval', property.intervalcol) app.measure('wrapper_ofthroughput', :samples => 1) end end defGroup('Sender1', *theSender) do |node| node.addApplication("iperfclient") do |app| end end defGroup('Sender2', *theSender) do |node| node.addApplication("iperfclient") do |app| end end defGroup('Sender3', *theSender) do |node| node.addApplication("iperfclient") do |app| end end defGroup('Receiver', *theReceiver) do |node| node.addApplication("iperfserv") do |app| end end onEvent(:ALL_UP_AND_INSTALLED) do |event| info "Starting the collect" group('iperf_nodes').startApplications after 2 do group('Receiver').startApplications end after 15 do group('Sender1').startApplications group('Source1').startApplications end after 40 do group('Sender2').startApplications end after 80 do group('Sender3').startApplications end after 200 do info "Stopping the collect" allGroups.stopApplications Experiment.done end end defGraph 'Throughput' do |g| g.ms('wrapper_ofthroughput').select(:oml_ts_client, :throughput, :pathtype) g.caption "Throughput of Flows" g.type 'line_chart3' g.mapping :x_axis => :oml_ts_client, :y_axis => :throughput, :group_by => :pathtype g.xaxis :legend => 'Time[s]' g.yaxis :legend => 'Throughput [bps]', :ticks => {:format => 's'} end defGraph 'ThroughputperFlow' do |g| g.ms('wrapper_ofthroughput').select(:oml_ts_client, :avgperflow, :pathtype) g.caption "Average Throughput of Flows" g.type 'line_chart3' g.mapping :x_axis => :oml_ts_client, :y_axis => :avgperflow, :group_by => :pathtype g.xaxis :legend => 'Time [s]' g.yaxis :legend => 'Average per Flow [bps]', :ticks => {:format => 's'} end
B. About the OpenFlow controller load-balancer.rb
- Trema web site: http://trema.github.io/trema/
- Treme ruby API document: http://rubydoc.info/github/trema/trema/master/frames
- Functions used in our tutorial:
- start(): is the function that will be called when the OpenFlow Controller is started. Here in our case, we read the file /tmp/portmap and figures out which OpenFlow port points to which path
- switch_ready(): is the function that will be called each time a switch connects to the OpenFlow Controller. Here in our case, we allow all non-TCP flows to pass (including ARP and ICMP packets) and ask new inbound TCP flow to go to the controller. We also starts a "timer" function that calls "query_stats()" once every 2 seconds.
- query_stats(): is the function that sends out a flow_stats_request to get the current statistics about each flow.
- packet_in(): is the function that will be called each time a packet arrives at the controller. Here in our case, we call "decide_path()" to get path decisions, then send flow entry back to the OpenFlow Switch to instruct the switch which path to take for this new TCP flow.
- stats_reply(): is the function that will be called when the OpenFlow Controller receives a flow_stats_reply message from the OpenFlow Switch. Here in our case, we update the flow statistics so that "decide_path()" can make the right decision.
- send_flow_mod_add(): is the function that you should use to add a flow entry into an OpenFlow Switch.
- decide_path(): is the function that makes path decisions. It returns the path choices based on flow statistics.
- The Whole Process:
- When the OpenFlow switch is ready, our controller starts a function that asks for flow stats once every 2 seconds.
- 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".
- As a result, our controller updates its knowledge about both left and right path once every 2 seconds.
- Upon the arrival of a new TCP flow, the OpenFlow controller decides which path to send the new flow to, based on the updated flow statistics.
The FlowStatsReply message is in the following format:
FlowStatsReply.new( :length => 96, :table_id => 0, :match => Match.new :duration_sec => 10, :duration_nsec => 106000000, :priority => 0, :idle_timeout => 0, :hard_timeout => 0, :cookie => 0xabcd, :packet_count => 1, :byte_count => 1, :actions => [ ActionOutput.new ] )
C. About The Rspec file OpenFlowLBExo.rspec
- The Rspec file describes a topology we showed earlier--each node is assigned with certain number of interfaces with pre-defined IP addresses
- Some of the nodes are loaded with softwares and post-scripts. We will take node "Switch" as an example since it is the most complicated one.
- The following section in the Rspec file for node "Switch":
<install url="http://emmy9.casa.umass.edu/GEC-19/of-switch-exo.tar.gz" install_path="/tmp"/>
means it is going to download that tar ball from the specified URL and extract to directory "/tmp" - The following section in the Rspec file for node "Switch":
<execute shell="bash" command=" sudo cp /tmp/of-topo-setup/gimibot/postboot_script_exo.sh / ; sh /postboot_script_exo.sh $self.Name() $sliceName; sh /tmp/of-topo-setup/lb-setup $switch.IP("outside-switch") $switch.IP("switch-left") $switch.IP("switch-right")"/>
names the post-boot script that ExoGENI is going to run for you after the nodes are booted.
- The following section in the Rspec file for node "Switch":
- More information about "/tmp/postboot_script_exo.sh": It is a "hook" to the LabWiki interface. Experimenter run this so that LabWiki knows the name of the slice and the hostname of the particular node that OML/OMF toolkits are running on.
- Take a look at the script for setting up the switch node, it is located at the node at "/tmp/of-topo-setup/lb-setup".
D. Tips: 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.
- 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. - 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:127.0.0.1:6634 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=10.10.10.0/24 actions=CONTROLLER:65535
This indicates that any TCP segment with source IP in the 10.10.10.0/24 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.) - 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. - Linux netem
Use the tc command to enable and configure delay and lossrate constraints on the outgoing interfaces for traffic traveling from the OpenFlow switch to the Aggregator node. To configure a path with a 20 ms delay and 10% lossrate on eth2, you would issue the command:sudo tc qdisc add dev eth2 root handle 1:0 netem delay 20ms loss 2%
Use the "tc qdisc change" command to reconfigure existing links,instead of "tc qdisc add".