Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 1 | OpenFlow Testing Framework |
Dan Talayco | 10ffe26 | 2010-07-20 21:55:53 -0700 | [diff] [blame] | 2 | July, 2010 |
Rich Lane | ea5060d | 2013-01-06 13:59:00 -0800 | [diff] [blame^] | 3 | Last updated January 2013 |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 4 | |
Dan Talayco | f317187 | 2010-05-07 09:29:57 -0700 | [diff] [blame] | 5 | Copyright (c) 2010 The Board of Trustees of The Leland Stanford |
| 6 | Junior University |
| 7 | |
Dan Talayco | 10275aa | 2010-07-20 14:12:31 -0700 | [diff] [blame] | 8 | License |
| 9 | +++++++ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 10 | |
Dan Talayco | 10ffe26 | 2010-07-20 21:55:53 -0700 | [diff] [blame] | 11 | The software included with this distribution is subject to the |
| 12 | OpenFlow Switching License as given in the included file LICENSE. |
| 13 | Details are also available at: |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 14 | |
Dan Talayco | 10275aa | 2010-07-20 14:12:31 -0700 | [diff] [blame] | 15 | http://www.openflow.org/wp/legal |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 16 | |
Dan Talayco | 10ffe26 | 2010-07-20 21:55:53 -0700 | [diff] [blame] | 17 | Other software referenced in this distribution is subject to its |
| 18 | respective license. |
| 19 | |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 20 | Introduction |
| 21 | ++++++++++++ |
| 22 | |
| 23 | This test framework is meant to exercise a candidate OpenFlow |
| 24 | switch (the device/switch under test, DUT or SUT). It provides a |
| 25 | connection like a controller to which the switch connects and it |
| 26 | controls data plane ports, sending and receiving packets, which |
| 27 | should be connected to the switch. |
| 28 | |
| 29 | There are two parts to running the test framework: |
| 30 | |
| 31 | * Building the python libraries that support the OF protocol |
| 32 | * Running oft, the main entry point of the test framework |
| 33 | |
| 34 | Normally log output from oft is sent to the file oft.log, but |
| 35 | can be redirected to the console by specifying --log-file="". |
Rich Lane | ea5060d | 2013-01-06 13:59:00 -0800 | [diff] [blame^] | 36 | |
| 37 | For information on writing new tests or making improvements to |
| 38 | the test framework see the file DEVELOPING. |
| 39 | |
| 40 | Getting OFTest |
| 41 | ++++++++++++++ |
| 42 | |
| 43 | You can check out OFTest with git with the following command: |
| 44 | |
| 45 | git clone git://github.com/floodlight/oftest |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 46 | |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 47 | Quick Start |
| 48 | +++++++++++ |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 49 | |
Rich Lane | 2a3bbb4 | 2012-10-04 15:45:32 -0700 | [diff] [blame] | 50 | You need to have Python and Scapy installed on your system. |
| 51 | See 'Pre-requisites' below. |
Dan Talayco | 9469693 | 2010-07-09 09:42:24 -0700 | [diff] [blame] | 52 | |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 53 | Make sure your switch is running and trying to connect to a |
| 54 | controller on the machine where you're running oft (normally port |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 55 | 6633). See below regarding run_switch.py for a script that starts |
| 56 | up a software switch on the test host. |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 57 | |
| 58 | Currently, switches must be running version 1.0 of OpenFlow. |
| 59 | |
Dan Talayco | 78cb7cc | 2012-03-23 14:25:50 -0700 | [diff] [blame] | 60 | # git clone git://github.com/floodlight/oftest |
Rich Lane | ac2da80 | 2012-10-03 10:12:10 -0700 | [diff] [blame] | 61 | # cd oftest |
Rich Lane | 2a3bbb4 | 2012-10-04 15:45:32 -0700 | [diff] [blame] | 62 | # make -C tools/munger |
Dan Talayco | 9469693 | 2010-07-09 09:42:24 -0700 | [diff] [blame] | 63 | Make sure the switch you want to test is running -- |
| 64 | see (4) below for the reference switch example. |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 65 | # ./oft --list |
Rich Lane | ea5060d | 2013-01-06 13:59:00 -0800 | [diff] [blame^] | 66 | # sudo ./oft basic.Echo |
Dan Talayco | 78cb7cc | 2012-03-23 14:25:50 -0700 | [diff] [blame] | 67 | # sudo ./oft --verbose --log-file="" |
Rich Lane | ea5060d | 2013-01-06 13:59:00 -0800 | [diff] [blame^] | 68 | # sudo ./oft basic --platform=remote --host=... |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 69 | |
| 70 | Longer Start |
| 71 | ++++++++++++ |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 72 | |
| 73 | 1. Pre-requisites: |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 74 | * An OF switch instance to test (see 4 below) |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 75 | * Root privilege on host running oft |
| 76 | * Switch running OpenFlow 1.0 and attempting to connect |
| 77 | to a controller on the machine running oft. |
Dan Talayco | 78cb7cc | 2012-03-23 14:25:50 -0700 | [diff] [blame] | 78 | * Python 2.5 or 2.6. You can run platforms using eth interfaces |
| 79 | with Python 2.4. Python 2.7 may work. |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 80 | * oftest checked out (called <oftest> here) |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 81 | * scapy installed: http://www.secdev.org/projects/scapy/ |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 82 | 'sudo apt-get install scapy' should work on Debian. |
Rich Lane | b42a31c | 2012-10-05 17:54:17 -0700 | [diff] [blame] | 83 | * pypcap installed: http://code.google.com/p/pypcap/ (optional) |
| 84 | 'sudo apt-get install python-pypcap' should work on Debian. |
| 85 | Tests using VLAN tags may fail without pypcap. |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 86 | * tcpdump installed (optional, but scapy will complain if it's |
| 87 | not there) |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 88 | * Doxygen and doxypy for document generation (optional) |
| 89 | * lint for source checking (optional) |
| 90 | |
| 91 | 2. Build the OpenFlow Python message classes |
Dan Talayco | c474796 | 2010-02-19 12:29:17 -0800 | [diff] [blame] | 92 | |
| 93 | Important: The OF version used by the controller is based on |
| 94 | the file in <oftest>/tools/pylibopenflow/include/openflow.h |
| 95 | This is currently the 1.0 release file. |
| 96 | |
Rich Lane | 2a3bbb4 | 2012-10-04 15:45:32 -0700 | [diff] [blame] | 97 | make -C <oftest>/tools/munger |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 98 | |
Rich Lane | 2a3bbb4 | 2012-10-04 15:45:32 -0700 | [diff] [blame] | 99 | This places files in <oftest>/src/python/oftest/src. |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 100 | |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 101 | 3. Edit configuration if necessary |
Rich Lane | ea5060d | 2013-01-06 13:59:00 -0800 | [diff] [blame^] | 102 | The default (local) platform uses 4 veth interface pairs and |
| 103 | is only suitable for testing local software switches. To test |
| 104 | hardware switches you will need to create an appropriate |
| 105 | platform file. See the "Platforms" section below. |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 106 | |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 107 | 4. Start the switch to test |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 108 | The switch must be running and actively attempting to |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 109 | connect to a controller on the test host at the port number |
| 110 | used by oft (6633 by default, or specified as --port=<n> as |
| 111 | an argument to oft). |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 112 | |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 113 | If you're new to the test environment and want to check its |
| 114 | sanity, you can do the following. This requires that |
| 115 | your host kernel supports virtual ethernet interfaces. This |
| 116 | is best done in a window separate from where you will run oft. |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 117 | |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 118 | 4A. Check out openflow (preferably at the same level as oftest): |
| 119 | git clone git://openflowswitch.org/openflow.git |
| 120 | 4B. cd openflow; ./boot.sh; ./configure; make |
Rich Lane | 7bfaeb4 | 2012-10-04 18:18:44 -0700 | [diff] [blame] | 121 | 4C. cd ../oftest |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 122 | 4D. Run the switch startup script: |
| 123 | sudo ./run_switch.py; Now you can run oft (see below). |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 124 | 4F. Use --help to see command line switches. If you use a port |
| 125 | number other than the default, make sure you use the same |
| 126 | one for the switch as for oft. |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 127 | 4E. Use control-C to terminate the switch daemons. |
| 128 | 4F. To clean up the virtual ethernet interfaces, use |
| 129 | sudo rmmod veth |
| 130 | |
Dan Talayco | 78cb7cc | 2012-03-23 14:25:50 -0700 | [diff] [blame] | 131 | New tools allow you to run an OVS instance as well. See |
| 132 | oftest/tools/ovs-ctl. You will need to install a version of |
| 133 | openvswitch. See http://openvswitch.org/. |
| 134 | |
Rich Lane | ea5060d | 2013-01-06 13:59:00 -0800 | [diff] [blame^] | 135 | 5. Run oft (requires sudo to control the dataplane) |
Rich Lane | ac2da80 | 2012-10-03 10:12:10 -0700 | [diff] [blame] | 136 | cd <oftest> |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 137 | sudo ./oft --help |
| 138 | |
Rich Lane | ea5060d | 2013-01-06 13:59:00 -0800 | [diff] [blame^] | 139 | Important Notes |
| 140 | +++++++++++++++ |
| 141 | |
| 142 | 1. If you're running into issues with transactions, and it appears that |
| 143 | OpenFlow messages aren't quite right, start by looking at any length |
| 144 | fields in the packets. With the local platform, you can use wireshark |
| 145 | on the loopback interface as well as the dataplane veth interfaces. |
| 146 | |
| 147 | 2. If tests dealing with VLANs fail unexpectedly then try installing |
| 148 | pypcap (see Longer Start above). |
| 149 | |
| 150 | Platforms |
| 151 | +++++++++ |
| 152 | |
| 153 | The "platform" is a configuration file (written in Python) that |
| 154 | tells OFTest how to send packets to and receive packets from the |
| 155 | dataplane of the switch. The default platform uses Linux virtual |
| 156 | ethernet interfaces and is suitable only for local software switches. |
| 157 | |
| 158 | You can add your own platform, say gp104, by adding a file gp104.py to the |
| 159 | platforms directory that defines the function platform_config_update and then |
| 160 | use the parameter --platform=gp104 on the command line. You can also use the |
| 161 | --platform-dir option to change which directory is searched. |
| 162 | |
| 163 | IMPORTANT: That file should define a function platform_config_update which |
| 164 | takes a configuration dictionary as an argument and updates it for the |
| 165 | current run. In particular, it should set up config["port_map"] with |
| 166 | the proper map from OF port numbers to OF interface names. |
| 167 | |
Dan Talayco | 10275aa | 2010-07-20 14:12:31 -0700 | [diff] [blame] | 168 | Helpful Note: Recovering From Crash |
| 169 | +++++++++++++++++++++++++++++++++++ |
| 170 | |
Dan Talayco | 10ffe26 | 2010-07-20 21:55:53 -0700 | [diff] [blame] | 171 | If the test script, oft, becomes unresponsive, you may find that |
| 172 | ^C does not break out of the script. In this case you have two |
| 173 | options: |
Dan Talayco | 10275aa | 2010-07-20 14:12:31 -0700 | [diff] [blame] | 174 | |
Dan Talayco | 10ffe26 | 2010-07-20 21:55:53 -0700 | [diff] [blame] | 175 | * Use ^Z to interrupt the script and return to the shell prompt. |
| 176 | * Start another terminal window to the same machine. |
Dan Talayco | 10275aa | 2010-07-20 14:12:31 -0700 | [diff] [blame] | 177 | |
Dan Talayco | 10ffe26 | 2010-07-20 21:55:53 -0700 | [diff] [blame] | 178 | In either case, you then need to kill the process that is hung. |
| 179 | Use the following commands: |
Dan Talayco | 10275aa | 2010-07-20 14:12:31 -0700 | [diff] [blame] | 180 | |
Dan Talayco | 10ffe26 | 2010-07-20 21:55:53 -0700 | [diff] [blame] | 181 | me@host> ps aux | grep oft |
| 182 | root 4 0.0 S< Jul07 0:00 [ksoftirqd/0] |
| 183 | ... |
| 184 | root 14066 3.2 Tl 09:27 0:00 python ./oft ... |
| 185 | me 14074 0.0 R+ 09:28 0:00 grep oft |
Dan Talayco | 10275aa | 2010-07-20 14:12:31 -0700 | [diff] [blame] | 186 | |
Dan Talayco | 10ffe26 | 2010-07-20 21:55:53 -0700 | [diff] [blame] | 187 | me@host> sudo kill -9 14066 |
Dan Talayco | 10275aa | 2010-07-20 14:12:31 -0700 | [diff] [blame] | 188 | |
Dan Talayco | 10ffe26 | 2010-07-20 21:55:53 -0700 | [diff] [blame] | 189 | where 14066 is the process ID of the hung process. (Replace it |
| 190 | with the PID for your process.) |
| 191 | |
| 192 | This is still preliminary work and there are bugs in the framework |
| 193 | that need to be ironed out. Please report any issues to |
| 194 | dtalayco@stanford.edu. |
Dan Talayco | 10275aa | 2010-07-20 14:12:31 -0700 | [diff] [blame] | 195 | |
Dan Talayco | d2ca103 | 2010-03-10 14:40:26 -0800 | [diff] [blame] | 196 | Using CentOS/RHEL |
| 197 | +++++++++++++++++ |
| 198 | |
| 199 | CentOS/RHEL have two challenges: they are very tied to Python 2.4 |
| 200 | (and Scapy requires Python 2.5 for its latest version) and they |
| 201 | require a kernel upgrade to use veth pairs for local platform |
| 202 | testing. |
| 203 | |
| 204 | If you only need to control eth interfaces for a remote platform, |
Dan Talayco | fa16d59 | 2010-03-12 10:01:43 -0800 | [diff] [blame] | 205 | you can use CentOS/RHEL without major disruption. The key is to |
| 206 | download scapy-1.2 from the following link: |
Dan Talayco | d2ca103 | 2010-03-10 14:40:26 -0800 | [diff] [blame] | 207 | |
| 208 | wget http://hg.secdev.org/scapy/raw-file/v1.2.0.2/scapy.py |
| 209 | |
| 210 | See: http://www.dirk-loss.de/scapy-doc/installation.html#installing-scapy-v1-2 |
| 211 | for more info. |
| 212 | |
| 213 | Copy scapy.py to /usr/lib/python2.4/site-packages |
| 214 | |
| 215 | If you hit an error related to importing scapy.all, you just need |
| 216 | to change the import to refer to scapy (not scapy.all). See |
| 217 | examples in parse.py for example. |