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