Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 1 | OpenFlow Testing Framework |
Dan Talayco | 79f3608 | 2010-03-11 16:53:53 -0800 | [diff] [blame] | 2 | March, 2010 |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 3 | |
Dan Talayco | f317187 | 2010-05-07 09:29:57 -0700 | [diff] [blame^] | 4 | Copyright (c) 2010 The Board of Trustees of The Leland Stanford |
| 5 | Junior University |
| 6 | |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 7 | Warning |
| 8 | +++++++ |
| 9 | |
| 10 | This is still experimental and it requires root privilege to |
| 11 | control the dataplane ports. As a consequence, there are |
| 12 | some serious risks to the machine on which this is running. |
| 13 | Use caution. |
| 14 | |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 15 | This is still preliminary work and there are bugs in the |
| 16 | framework that need to be ironed out. Please report any issues |
| 17 | to dtalayco@stanford.edu. |
| 18 | |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 19 | Introduction |
| 20 | ++++++++++++ |
| 21 | |
| 22 | This test framework is meant to exercise a candidate OpenFlow |
| 23 | switch (the device/switch under test, DUT or SUT). It provides a |
| 24 | connection like a controller to which the switch connects and it |
| 25 | controls data plane ports, sending and receiving packets, which |
| 26 | should be connected to the switch. |
| 27 | |
| 28 | There are two parts to running the test framework: |
| 29 | |
| 30 | * Building the python libraries that support the OF protocol |
| 31 | * Running oft, the main entry point of the test framework |
| 32 | |
| 33 | Normally log output from oft is sent to the file oft.log, but |
| 34 | can be redirected to the console by specifying --log-file="". |
| 35 | |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 36 | Quick Start |
| 37 | +++++++++++ |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 38 | |
| 39 | Make sure your switch is running and trying to connect to a |
| 40 | controller on the machine where you're running oft (normally port |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 41 | 6633). See below regarding run_switch.py for a script that starts |
| 42 | up a software switch on the test host. |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 43 | |
| 44 | Currently, switches must be running version 1.0 of OpenFlow. |
| 45 | |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 46 | # git clone yuba:/usr/local/git/openflow-projects/oftest |
| 47 | # cd oftest/tools/munger |
| 48 | # make install |
| 49 | # cd ../../tests |
| 50 | Make sure the switch you want to test is running |
| 51 | # ./oft --list |
| 52 | # sudo ./oft |
| 53 | # sudo ./oft --verbose --log-file="" |
| 54 | # sudo ./oft --test-spec=<mod> --platform=remote --host=... |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 55 | |
| 56 | Longer Start |
| 57 | ++++++++++++ |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 58 | |
| 59 | 1. Pre-requisites: |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 60 | * An OF switch instance to test (see 4 below) |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 61 | * Root privilege on host running oft |
| 62 | * Switch running OpenFlow 1.0 and attempting to connect |
| 63 | to a controller on the machine running oft. |
| 64 | * Python 2.5. You can run platforms using eth interfaces |
| 65 | with Python 2.4. |
| 66 | * Python setup tools (e.g.: sudo apt-get install python-setuptools) |
| 67 | * oftest checked out (called <oftest> here) |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 68 | * scapy installed: http://www.secdev.org/projects/scapy/ |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 69 | 'sudo apt-get install scapy' should work on Debian. |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 70 | * tcpdump installed (optional, but scapy will complain if it's |
| 71 | not there) |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 72 | * Doxygen and doxypy for document generation (optional) |
| 73 | * lint for source checking (optional) |
| 74 | |
| 75 | 2. Build the OpenFlow Python message classes |
Dan Talayco | c474796 | 2010-02-19 12:29:17 -0800 | [diff] [blame] | 76 | |
| 77 | Important: The OF version used by the controller is based on |
| 78 | the file in <oftest>/tools/pylibopenflow/include/openflow.h |
| 79 | This is currently the 1.0 release file. |
| 80 | |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 81 | cd <oftest>/tools/munger |
| 82 | make install |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 83 | |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 84 | This places files in <oftest>/src/python/oftest/src and then |
| 85 | calls setuptools to install on the local host |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 86 | |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 87 | 3. Edit configuration if necessary |
| 88 | Local platforms work with veth interface pairs and default to |
| 89 | four ports. You can adjust this a bit with the command line |
| 90 | parameters port_count, base_of_port and base_if_index. |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 91 | |
Dan Talayco | 673e085 | 2010-03-06 23:09:23 -0800 | [diff] [blame] | 92 | Starting from remote.py as a simple example, you can add your |
| 93 | own <platform>.py file and then have it imported with |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 94 | --platform=<platform> on the command line. This is meant to |
| 95 | allow you to test remote switches attempting to connect to a |
| 96 | controller on a network accessible to the test host. |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 97 | |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 98 | 4. Start the switch to test |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 99 | The switch must be running and actively attempting to |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 100 | connect to a controller on the test host at the port number |
| 101 | used by oft (6633 by default, or specified as --port=<n> as |
| 102 | an argument to oft). |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 103 | |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 104 | If you're new to the test environment and want to check its |
| 105 | sanity, you can do the following. This requires that |
| 106 | your host kernel supports virtual ethernet interfaces. This |
| 107 | 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] | 108 | |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 109 | 4A. Check out openflow (preferably at the same level as oftest): |
| 110 | git clone git://openflowswitch.org/openflow.git |
| 111 | 4B. cd openflow; ./boot.sh; ./configure; make |
| 112 | 4C. cd ../oftest/tests |
| 113 | 4D. Run the switch startup script: |
| 114 | sudo ./run_switch.py; Now you can run oft (see below). |
Dan Talayco | 80857c5 | 2010-05-05 10:14:05 -0700 | [diff] [blame] | 115 | 4F. Use --help to see command line switches. If you use a port |
| 116 | number other than the default, make sure you use the same |
| 117 | one for the switch as for oft. |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 118 | 4E. Use control-C to terminate the switch daemons. |
| 119 | 4F. To clean up the virtual ethernet interfaces, use |
| 120 | sudo rmmod veth |
| 121 | |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 122 | 5. Run oft |
Dan Talayco | 673e085 | 2010-03-06 23:09:23 -0800 | [diff] [blame] | 123 | See Warning above; requires sudo to control the dataplane |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame] | 124 | cd <oftest>/tests |
| 125 | sudo ./oft --help |
| 126 | |
| 127 | OFT Command Line Options |
| 128 | ++++++++++++++++++++++++ |
| 129 | |
| 130 | Here is a summary of the oft command line options. Use --help to see |
| 131 | the long and short command option names. |
| 132 | |
| 133 | platform : String identifying the target platform |
| 134 | controller_host : Host on which test controller is running (for sockets) |
| 135 | controller_port : Port on which test controller listens for switch cxn |
| 136 | port_count : Number of ports in dataplane |
| 137 | base_of_port : Base OpenFlow port number in dataplane |
| 138 | base_if_index : Base OS network interface for dataplane |
| 139 | test_dir : Directory to search for test files (default .) |
| 140 | test_spec : Specification of test(s) to run |
| 141 | log_file : Filename for test logging |
| 142 | list : Boolean: List all tests and exit |
| 143 | debug : String giving debug level (info, warning, error...) |
| 144 | verbose : Same as debug=verbose |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 145 | |
| 146 | Overview |
| 147 | ++++++++ |
| 148 | |
| 149 | The directory structure is currently: |
| 150 | |
| 151 | <oftest> |
| 152 | ` |
| 153 | |-- doc |
| 154 | |-- src |
| 155 | | `-- python |
| 156 | | `-- oftest |
| 157 | |-- tests |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 158 | | `-- oft and files with test cases |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 159 | `-- tools |
| 160 | |-- munger |
| 161 | `-- pylibopenflow |
| 162 | |
| 163 | The tools directory is what processes the OpenFlow header |
| 164 | files to produce Python classes representing OpenFlow messages. |
| 165 | The results are placed in src/python/oftest and currently |
| 166 | include: |
| 167 | |
| 168 | message.py: The main API providing OF message classes |
| 169 | error.py: Subclasses for error messages |
| 170 | action.py: Subclasses for action specification |
| 171 | cstruct.py: Direct representation of C structures in Python |
| 172 | class_maps.py: Addition info about C structures |
| 173 | |
| 174 | In addition, the following Python files are present in |
| 175 | src/python/oftest: |
| 176 | |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 177 | controller.py: The controller representation |
| 178 | dataplane.py: The dataplane representation |
| 179 | action_list.py: Action list class |
| 180 | netutils.py: e.g., set promisc on sockets |
| 181 | ofutils.py: Utilities related to OpenFlow messages |
Dan Talayco | 60a8d7a | 2010-03-03 15:20:59 -0800 | [diff] [blame] | 182 | oft_assert.py: Test framework level assertion |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 183 | |
Dan Talayco | 60a8d7a | 2010-03-03 15:20:59 -0800 | [diff] [blame] | 184 | Tests are run from the tests directory. The file oft is the |
| 185 | top level entry point for tests. Try ./oft --help for some more. |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 186 | |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 187 | Important Notes |
| 188 | +++++++++++++++ |
| 189 | |
| 190 | 1. If you edit any of the files in src/python/oftest or any of the |
| 191 | scripts in tools/munger/scripts, you MUST re-run make install. This |
| 192 | is easy to forget. |
| 193 | |
| 194 | 2. If your running into issues with transactions, and it appears that |
| 195 | OpenFlow messages aren't quite right, start by looking at any length |
| 196 | fields in the packets. With the local platform, you can use wireshark |
| 197 | on the loopback interface as well as the dataplane veth interfaces. |
| 198 | |
| 199 | Adding Your Own Test Cases |
| 200 | ++++++++++++++++++++++++++ |
| 201 | |
| 202 | You can: |
| 203 | |
| 204 | * Add cases to an existing file |
| 205 | * Add a new file |
| 206 | |
| 207 | If you add cases to an existing file, each case should be its own |
| 208 | class. It must inherit from unittest.TestCase or one of its |
| 209 | derivatives and define runTest (that's how test cases are discovered). |
| 210 | |
| 211 | If you add a new file, it must implement a top level function called |
| 212 | test_set_init which takes a configuration dictionary. See basic.py |
| 213 | for an example. The main point of this is to pass the port map |
| 214 | object to the test cases. But you can access any configuration |
| 215 | parameters this way. Each test case in the new file must derive |
| 216 | from unittest.TestCase. |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 217 | |
Dan Talayco | 79f3608 | 2010-03-11 16:53:53 -0800 | [diff] [blame] | 218 | CONVENTIONS: |
| 219 | |
| 220 | The first line of the doc string for a file and for a test class is |
| 221 | displayed in the list command. Please keep it clear and under 50 |
| 222 | characters. |
| 223 | |
Dan Talayco | d2ca103 | 2010-03-10 14:40:26 -0800 | [diff] [blame] | 224 | |
| 225 | Using CentOS/RHEL |
| 226 | +++++++++++++++++ |
| 227 | |
| 228 | CentOS/RHEL have two challenges: they are very tied to Python 2.4 |
| 229 | (and Scapy requires Python 2.5 for its latest version) and they |
| 230 | require a kernel upgrade to use veth pairs for local platform |
| 231 | testing. |
| 232 | |
| 233 | If you only need to control eth interfaces for a remote platform, |
Dan Talayco | fa16d59 | 2010-03-12 10:01:43 -0800 | [diff] [blame] | 234 | you can use CentOS/RHEL without major disruption. The key is to |
| 235 | download scapy-1.2 from the following link: |
Dan Talayco | d2ca103 | 2010-03-10 14:40:26 -0800 | [diff] [blame] | 236 | |
| 237 | wget http://hg.secdev.org/scapy/raw-file/v1.2.0.2/scapy.py |
| 238 | |
| 239 | See: http://www.dirk-loss.de/scapy-doc/installation.html#installing-scapy-v1-2 |
| 240 | for more info. |
| 241 | |
| 242 | Copy scapy.py to /usr/lib/python2.4/site-packages |
| 243 | |
| 244 | If you hit an error related to importing scapy.all, you just need |
| 245 | to change the import to refer to scapy (not scapy.all). See |
| 246 | examples in parse.py for example. |
| 247 | |
| 248 | |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 249 | Other Info |
| 250 | ++++++++++ |
| 251 | |
| 252 | * Build doc with |
| 253 | + cd <oftest>/tools/munger |
| 254 | + make doc |
| 255 | Places the results in <oftest>/doc/html |
| 256 | |
| 257 | * Run lint on sources |
| 258 | + cd <oftest>/tools/munger |
| 259 | + make lint |
| 260 | Places results in <oftest>/lint/*.log |
| 261 | The file controller.log currently has some errors indicated |
| 262 | |
| 263 | |
| 264 | To Do |
| 265 | +++++ |
| 266 | |
Dan Talayco | 60a8d7a | 2010-03-03 15:20:59 -0800 | [diff] [blame] | 267 | * Need to have an overview of the components of the test, how they |
| 268 | connect and how they are managed by the test framework. |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 269 | * See the Regression Test component on trac: |
| 270 | http://www.openflowswitch.org/bugs/openflow |
| 271 | http://www.openflowswitch.org/bugs/openflow/query?component=Regression+test+suite |
| 272 | |
Dan Talayco | c474796 | 2010-02-19 12:29:17 -0800 | [diff] [blame] | 273 | * Make the framework work with OF versions other than 1.0? |
| 274 | |