blob: 0c8ba3d0f1f721234c1b40a287f3bec43dad678d [file] [log] [blame]
Dan Talaycof7dae842010-02-19 11:50:02 -08001OpenFlow Testing Framework
Dan Talayco10ffe262010-07-20 21:55:53 -07002July, 2010
Dan Talayco78cb7cc2012-03-23 14:25:50 -07003Last updated March 2012
Dan Talaycof7dae842010-02-19 11:50:02 -08004
Dan Talaycof3171872010-05-07 09:29:57 -07005Copyright (c) 2010 The Board of Trustees of The Leland Stanford
6Junior University
7
Dan Talaycof7dae842010-02-19 11:50:02 -08008Warning
9+++++++
10
Dan Talayco10ffe262010-07-20 21:55:53 -070011 This is still experimental and it requires root privilege to
12 control the dataplane ports. As a consequence, there may be
13 risks to the machine on which this is running. Use caution.
Dan Talayco94696932010-07-09 09:42:24 -070014
Dan Talayco10ffe262010-07-20 21:55:53 -070015 Please see Helpful Notes below.
Dan Talayco551befa2010-07-15 17:05:32 -070016
Dan Talayco10275aa2010-07-20 14:12:31 -070017License
18+++++++
Dan Talayco551befa2010-07-15 17:05:32 -070019
Dan Talayco10ffe262010-07-20 21:55:53 -070020 The software included with this distribution is subject to the
21 OpenFlow Switching License as given in the included file LICENSE.
22 Details are also available at:
Dan Talayco551befa2010-07-15 17:05:32 -070023
Dan Talayco10275aa2010-07-20 14:12:31 -070024 http://www.openflow.org/wp/legal
Dan Talayco551befa2010-07-15 17:05:32 -070025
Dan Talayco10ffe262010-07-20 21:55:53 -070026 Other software referenced in this distribution is subject to its
27 respective license.
28
29Getting OFTest
30++++++++++++++
31
32 You can check out OFTest with git with the following command:
33
Dan Talayco78cb7cc2012-03-23 14:25:50 -070034 git clone git://github.com/floodlight/oftest
Dan Talayco551befa2010-07-15 17:05:32 -070035
Dan Talayco80857c52010-05-05 10:14:05 -070036Introduction
37++++++++++++
38
39 This test framework is meant to exercise a candidate OpenFlow
40 switch (the device/switch under test, DUT or SUT). It provides a
41 connection like a controller to which the switch connects and it
42 controls data plane ports, sending and receiving packets, which
43 should be connected to the switch.
44
45 There are two parts to running the test framework:
46
47 * Building the python libraries that support the OF protocol
48 * Running oft, the main entry point of the test framework
49
50 Normally log output from oft is sent to the file oft.log, but
51 can be redirected to the console by specifying --log-file="".
52
Dan Talaycof7dae842010-02-19 11:50:02 -080053Quick Start
54+++++++++++
Dan Talaycoa85e5662010-04-16 09:35:30 -070055
Rich Lane2a3bbb42012-10-04 15:45:32 -070056 You need to have Python and Scapy installed on your system.
57 See 'Pre-requisites' below.
Dan Talayco94696932010-07-09 09:42:24 -070058
Dan Talaycoa85e5662010-04-16 09:35:30 -070059 Make sure your switch is running and trying to connect to a
60 controller on the machine where you're running oft (normally port
Dan Talayco80857c52010-05-05 10:14:05 -070061 6633). See below regarding run_switch.py for a script that starts
62 up a software switch on the test host.
Dan Talaycoa85e5662010-04-16 09:35:30 -070063
64 Currently, switches must be running version 1.0 of OpenFlow.
65
Dan Talayco78cb7cc2012-03-23 14:25:50 -070066 # git clone git://github.com/floodlight/oftest
Rich Laneac2da802012-10-03 10:12:10 -070067 # cd oftest
Rich Lane2a3bbb42012-10-04 15:45:32 -070068 # make -C tools/munger
Dan Talayco94696932010-07-09 09:42:24 -070069 Make sure the switch you want to test is running --
70 see (4) below for the reference switch example.
Dan Talayco80857c52010-05-05 10:14:05 -070071 # ./oft --list
Dan Talayco78cb7cc2012-03-23 14:25:50 -070072 # sudo ./oft --test-spec=Echo
73 # sudo ./oft --verbose --log-file=""
Dan Talayco80857c52010-05-05 10:14:05 -070074 # sudo ./oft --test-spec=<mod> --platform=remote --host=...
Dan Talayco1ddefbf2010-03-07 21:56:47 -080075
76Longer Start
77++++++++++++
Dan Talaycof7dae842010-02-19 11:50:02 -080078
79 1. Pre-requisites:
Dan Talaycoa85e5662010-04-16 09:35:30 -070080 * An OF switch instance to test (see 4 below)
Dan Talayco80857c52010-05-05 10:14:05 -070081 * Root privilege on host running oft
82 * Switch running OpenFlow 1.0 and attempting to connect
83 to a controller on the machine running oft.
Dan Talayco78cb7cc2012-03-23 14:25:50 -070084 * Python 2.5 or 2.6. You can run platforms using eth interfaces
85 with Python 2.4. Python 2.7 may work.
Dan Talayco80857c52010-05-05 10:14:05 -070086 * oftest checked out (called <oftest> here)
Dan Talaycof7dae842010-02-19 11:50:02 -080087 * scapy installed: http://www.secdev.org/projects/scapy/
Dan Talayco80857c52010-05-05 10:14:05 -070088 'sudo apt-get install scapy' should work on Debian.
Dan Talaycoa85e5662010-04-16 09:35:30 -070089 * tcpdump installed (optional, but scapy will complain if it's
90 not there)
Dan Talaycof7dae842010-02-19 11:50:02 -080091 * Doxygen and doxypy for document generation (optional)
92 * lint for source checking (optional)
93
94 2. Build the OpenFlow Python message classes
Dan Talaycoc4747962010-02-19 12:29:17 -080095
96 Important: The OF version used by the controller is based on
97 the file in <oftest>/tools/pylibopenflow/include/openflow.h
98 This is currently the 1.0 release file.
99
Rich Lane2a3bbb42012-10-04 15:45:32 -0700100 make -C <oftest>/tools/munger
Dan Talayco80857c52010-05-05 10:14:05 -0700101
Rich Lane2a3bbb42012-10-04 15:45:32 -0700102 This places files in <oftest>/src/python/oftest/src.
Dan Talaycof7dae842010-02-19 11:50:02 -0800103
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800104 3. Edit configuration if necessary
105 Local platforms work with veth interface pairs and default to
106 four ports. You can adjust this a bit with the command line
107 parameters port_count, base_of_port and base_if_index.
Dan Talayco80857c52010-05-05 10:14:05 -0700108
Dan Talayco673e0852010-03-06 23:09:23 -0800109 Starting from remote.py as a simple example, you can add your
110 own <platform>.py file and then have it imported with
Dan Talayco80857c52010-05-05 10:14:05 -0700111 --platform=<platform> on the command line. This is meant to
112 allow you to test remote switches attempting to connect to a
113 controller on a network accessible to the test host.
Dan Talaycof7dae842010-02-19 11:50:02 -0800114
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800115 4. Start the switch to test
Dan Talaycof7dae842010-02-19 11:50:02 -0800116 The switch must be running and actively attempting to
Dan Talayco80857c52010-05-05 10:14:05 -0700117 connect to a controller on the test host at the port number
118 used by oft (6633 by default, or specified as --port=<n> as
119 an argument to oft).
Dan Talaycof7dae842010-02-19 11:50:02 -0800120
Dan Talaycoa85e5662010-04-16 09:35:30 -0700121 If you're new to the test environment and want to check its
122 sanity, you can do the following. This requires that
123 your host kernel supports virtual ethernet interfaces. This
124 is best done in a window separate from where you will run oft.
Dan Talayco80857c52010-05-05 10:14:05 -0700125
Dan Talaycoa85e5662010-04-16 09:35:30 -0700126 4A. Check out openflow (preferably at the same level as oftest):
127 git clone git://openflowswitch.org/openflow.git
128 4B. cd openflow; ./boot.sh; ./configure; make
129 4C. cd ../oftest/tests
130 4D. Run the switch startup script:
131 sudo ./run_switch.py; Now you can run oft (see below).
Dan Talayco80857c52010-05-05 10:14:05 -0700132 4F. Use --help to see command line switches. If you use a port
133 number other than the default, make sure you use the same
134 one for the switch as for oft.
Dan Talaycoa85e5662010-04-16 09:35:30 -0700135 4E. Use control-C to terminate the switch daemons.
136 4F. To clean up the virtual ethernet interfaces, use
137 sudo rmmod veth
138
Dan Talayco78cb7cc2012-03-23 14:25:50 -0700139 New tools allow you to run an OVS instance as well. See
140 oftest/tools/ovs-ctl. You will need to install a version of
141 openvswitch. See http://openvswitch.org/.
142
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800143 5. Run oft
Dan Talayco673e0852010-03-06 23:09:23 -0800144 See Warning above; requires sudo to control the dataplane
Rich Laneac2da802012-10-03 10:12:10 -0700145 cd <oftest>
Dan Talaycoa85e5662010-04-16 09:35:30 -0700146 sudo ./oft --help
147
Dan Talayco10275aa2010-07-20 14:12:31 -0700148Helpful Note: Recovering From Crash
149+++++++++++++++++++++++++++++++++++
150
Dan Talayco10ffe262010-07-20 21:55:53 -0700151 If the test script, oft, becomes unresponsive, you may find that
152 ^C does not break out of the script. In this case you have two
153 options:
Dan Talayco10275aa2010-07-20 14:12:31 -0700154
Dan Talayco10ffe262010-07-20 21:55:53 -0700155 * Use ^Z to interrupt the script and return to the shell prompt.
156 * Start another terminal window to the same machine.
Dan Talayco10275aa2010-07-20 14:12:31 -0700157
Dan Talayco10ffe262010-07-20 21:55:53 -0700158 In either case, you then need to kill the process that is hung.
159 Use the following commands:
Dan Talayco10275aa2010-07-20 14:12:31 -0700160
Dan Talayco10ffe262010-07-20 21:55:53 -0700161 me@host> ps aux | grep oft
162 root 4 0.0 S< Jul07 0:00 [ksoftirqd/0]
163 ...
164 root 14066 3.2 Tl 09:27 0:00 python ./oft ...
165 me 14074 0.0 R+ 09:28 0:00 grep oft
Dan Talayco10275aa2010-07-20 14:12:31 -0700166
Dan Talayco10ffe262010-07-20 21:55:53 -0700167 me@host> sudo kill -9 14066
Dan Talayco10275aa2010-07-20 14:12:31 -0700168
Dan Talayco10ffe262010-07-20 21:55:53 -0700169 where 14066 is the process ID of the hung process. (Replace it
170 with the PID for your process.)
171
172 This is still preliminary work and there are bugs in the framework
173 that need to be ironed out. Please report any issues to
174 dtalayco@stanford.edu.
Dan Talayco10275aa2010-07-20 14:12:31 -0700175
176
Dan Talaycoa85e5662010-04-16 09:35:30 -0700177OFT Command Line Options
178++++++++++++++++++++++++
179
180 Here is a summary of the oft command line options. Use --help to see
181 the long and short command option names.
182
183 platform : String identifying the target platform
184 controller_host : Host on which test controller is running (for sockets)
185 controller_port : Port on which test controller listens for switch cxn
186 port_count : Number of ports in dataplane
187 base_of_port : Base OpenFlow port number in dataplane
188 base_if_index : Base OS network interface for dataplane
189 test_dir : Directory to search for test files (default .)
190 test_spec : Specification of test(s) to run
191 log_file : Filename for test logging
192 list : Boolean: List all tests and exit
193 debug : String giving debug level (info, warning, error...)
194 verbose : Same as debug=verbose
Dan Talaycof7dae842010-02-19 11:50:02 -0800195
196Overview
197++++++++
198
199 The directory structure is currently:
200
201 <oftest>
202 `
Rich Laneac2da802012-10-03 10:12:10 -0700203 |-- oft
Dan Talaycof7dae842010-02-19 11:50:02 -0800204 |-- doc
205 |-- src
206 | `-- python
207 | `-- oftest
208 |-- tests
Rich Laneac2da802012-10-03 10:12:10 -0700209 | `-- test cases
Dan Talaycof7dae842010-02-19 11:50:02 -0800210 `-- tools
211 |-- munger
212 `-- pylibopenflow
213
214 The tools directory is what processes the OpenFlow header
215 files to produce Python classes representing OpenFlow messages.
216 The results are placed in src/python/oftest and currently
217 include:
218
219 message.py: The main API providing OF message classes
220 error.py: Subclasses for error messages
221 action.py: Subclasses for action specification
222 cstruct.py: Direct representation of C structures in Python
223 class_maps.py: Addition info about C structures
224
225 In addition, the following Python files are present in
226 src/python/oftest:
227
Dan Talaycof7dae842010-02-19 11:50:02 -0800228 controller.py: The controller representation
229 dataplane.py: The dataplane representation
230 action_list.py: Action list class
231 netutils.py: e.g., set promisc on sockets
232 ofutils.py: Utilities related to OpenFlow messages
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800233 oft_assert.py: Test framework level assertion
Rich Laneac2da802012-10-03 10:12:10 -0700234 testutils.py: Test utilities
Dan Talaycof7dae842010-02-19 11:50:02 -0800235
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800236 Tests are run from the tests directory. The file oft is the
237 top level entry point for tests. Try ./oft --help for some more.
Dan Talaycof7dae842010-02-19 11:50:02 -0800238
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800239Important Notes
240+++++++++++++++
241
Rich Lane2a3bbb42012-10-04 15:45:32 -0700242 1. If you change any of the code generation scripts in
243 tools/munger/scripts you must re-run make -C tools/munger to
244 regenerate the OpenFlow message classes.
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800245
246 2. If your running into issues with transactions, and it appears that
247 OpenFlow messages aren't quite right, start by looking at any length
248 fields in the packets. With the local platform, you can use wireshark
249 on the loopback interface as well as the dataplane veth interfaces.
250
251Adding Your Own Test Cases
252++++++++++++++++++++++++++
253
Dan Talayco6213e3c2010-07-21 21:49:00 -0700254 Check the online tutorial:
255 http://openflow.org/wk/index.php/OFTestTutorial
256
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800257 You can:
258
259 * Add cases to an existing file
260 * Add a new file
261
262 If you add cases to an existing file, each case should be its own
263 class. It must inherit from unittest.TestCase or one of its
264 derivatives and define runTest (that's how test cases are discovered).
265
266 If you add a new file, it must implement a top level function called
267 test_set_init which takes a configuration dictionary. See basic.py
268 for an example. The main point of this is to pass the port map
269 object to the test cases. But you can access any configuration
270 parameters this way. Each test case in the new file must derive
271 from unittest.TestCase.
Dan Talaycof7dae842010-02-19 11:50:02 -0800272
Dan Talayco79f36082010-03-11 16:53:53 -0800273 CONVENTIONS:
274
275 The first line of the doc string for a file and for a test class is
276 displayed in the list command. Please keep it clear and under 50
277 characters.
278
Dan Talaycod2ca1032010-03-10 14:40:26 -0800279
280Using CentOS/RHEL
281+++++++++++++++++
282
283 CentOS/RHEL have two challenges: they are very tied to Python 2.4
284 (and Scapy requires Python 2.5 for its latest version) and they
285 require a kernel upgrade to use veth pairs for local platform
286 testing.
287
288 If you only need to control eth interfaces for a remote platform,
Dan Talaycofa16d592010-03-12 10:01:43 -0800289 you can use CentOS/RHEL without major disruption. The key is to
290 download scapy-1.2 from the following link:
Dan Talaycod2ca1032010-03-10 14:40:26 -0800291
292 wget http://hg.secdev.org/scapy/raw-file/v1.2.0.2/scapy.py
293
294 See: http://www.dirk-loss.de/scapy-doc/installation.html#installing-scapy-v1-2
295 for more info.
296
297 Copy scapy.py to /usr/lib/python2.4/site-packages
298
299 If you hit an error related to importing scapy.all, you just need
300 to change the import to refer to scapy (not scapy.all). See
301 examples in parse.py for example.
302
303
Dan Talaycof7dae842010-02-19 11:50:02 -0800304Other Info
305++++++++++
306
307 * Build doc with
308 + cd <oftest>/tools/munger
309 + make doc
310 Places the results in <oftest>/doc/html
Dan Talayco10ffe262010-07-20 21:55:53 -0700311 If you have problems, check the install location doxypy.py and
312 that it is set correctly in <oftest>/doc/Doxyfile
Dan Talaycof7dae842010-02-19 11:50:02 -0800313
314 * Run lint on sources
315 + cd <oftest>/tools/munger
316 + make lint
317 Places results in <oftest>/lint/*.log
318 The file controller.log currently has some errors indicated
319
320
321To Do
322+++++
323
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800324 * Need to have an overview of the components of the test, how they
325 connect and how they are managed by the test framework.
Dan Talaycof7dae842010-02-19 11:50:02 -0800326 * See the Regression Test component on trac:
327 http://www.openflowswitch.org/bugs/openflow
328 http://www.openflowswitch.org/bugs/openflow/query?component=Regression+test+suite
329
Dan Talaycoc4747962010-02-19 12:29:17 -0800330 * Make the framework work with OF versions other than 1.0?
331