blob: 5d1b5c5886af1dd9ebe68db913797b91d5c23acd [file] [log] [blame]
Dan Talaycof7dae842010-02-19 11:50:02 -08001OpenFlow Testing Framework
Dan Talayco10ffe262010-07-20 21:55:53 -07002July, 2010
Dan Talaycof7dae842010-02-19 11:50:02 -08003
Dan Talaycof3171872010-05-07 09:29:57 -07004Copyright (c) 2010 The Board of Trustees of The Leland Stanford
5Junior University
6
Dan Talaycof7dae842010-02-19 11:50:02 -08007Warning
8+++++++
9
Dan Talayco10ffe262010-07-20 21:55:53 -070010 This is still experimental and it requires root privilege to
11 control the dataplane ports. As a consequence, there may be
12 risks to the machine on which this is running. Use caution.
Dan Talayco94696932010-07-09 09:42:24 -070013
Dan Talayco10ffe262010-07-20 21:55:53 -070014 Please see Helpful Notes below.
Dan Talayco551befa2010-07-15 17:05:32 -070015
Dan Talayco10275aa2010-07-20 14:12:31 -070016License
17+++++++
Dan Talayco551befa2010-07-15 17:05:32 -070018
Dan Talayco10ffe262010-07-20 21:55:53 -070019 The software included with this distribution is subject to the
20 OpenFlow Switching License as given in the included file LICENSE.
21 Details are also available at:
Dan Talayco551befa2010-07-15 17:05:32 -070022
Dan Talayco10275aa2010-07-20 14:12:31 -070023 http://www.openflow.org/wp/legal
Dan Talayco551befa2010-07-15 17:05:32 -070024
Dan Talayco10ffe262010-07-20 21:55:53 -070025 Other software referenced in this distribution is subject to its
26 respective license.
27
28Getting OFTest
29++++++++++++++
30
31 You can check out OFTest with git with the following command:
32
33 git clone git://openflow.org/oftest
Dan Talayco551befa2010-07-15 17:05:32 -070034
Dan Talayco80857c52010-05-05 10:14:05 -070035Introduction
36++++++++++++
37
38 This test framework is meant to exercise a candidate OpenFlow
39 switch (the device/switch under test, DUT or SUT). It provides a
40 connection like a controller to which the switch connects and it
41 controls data plane ports, sending and receiving packets, which
42 should be connected to the switch.
43
44 There are two parts to running the test framework:
45
46 * Building the python libraries that support the OF protocol
47 * Running oft, the main entry point of the test framework
48
49 Normally log output from oft is sent to the file oft.log, but
50 can be redirected to the console by specifying --log-file="".
51
Dan Talaycof7dae842010-02-19 11:50:02 -080052Quick Start
53+++++++++++
Dan Talaycoa85e5662010-04-16 09:35:30 -070054
Dan Talayco94696932010-07-09 09:42:24 -070055 You need to have Python setup tools and Scapy installed on your
56 system. See 'Pre-requisites' below.
57
Dan Talaycoa85e5662010-04-16 09:35:30 -070058 Make sure your switch is running and trying to connect to a
59 controller on the machine where you're running oft (normally port
Dan Talayco80857c52010-05-05 10:14:05 -070060 6633). See below regarding run_switch.py for a script that starts
61 up a software switch on the test host.
Dan Talaycoa85e5662010-04-16 09:35:30 -070062
63 Currently, switches must be running version 1.0 of OpenFlow.
64
Dan Talayco80857c52010-05-05 10:14:05 -070065 # git clone yuba:/usr/local/git/openflow-projects/oftest
66 # cd oftest/tools/munger
67 # make install
68 # cd ../../tests
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
72 # sudo ./oft
73 # sudo ./oft --verbose --log-file=""
74 # 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.
84 * Python 2.5. You can run platforms using eth interfaces
85 with Python 2.4.
86 * Python setup tools (e.g.: sudo apt-get install python-setuptools)
87 * oftest checked out (called <oftest> here)
Dan Talaycof7dae842010-02-19 11:50:02 -080088 * scapy installed: http://www.secdev.org/projects/scapy/
Dan Talayco80857c52010-05-05 10:14:05 -070089 'sudo apt-get install scapy' should work on Debian.
Dan Talaycoa85e5662010-04-16 09:35:30 -070090 * tcpdump installed (optional, but scapy will complain if it's
91 not there)
Dan Talaycof7dae842010-02-19 11:50:02 -080092 * Doxygen and doxypy for document generation (optional)
93 * lint for source checking (optional)
94
95 2. Build the OpenFlow Python message classes
Dan Talaycoc4747962010-02-19 12:29:17 -080096
97 Important: The OF version used by the controller is based on
98 the file in <oftest>/tools/pylibopenflow/include/openflow.h
99 This is currently the 1.0 release file.
100
Dan Talaycoa85e5662010-04-16 09:35:30 -0700101 cd <oftest>/tools/munger
102 make install
Dan Talayco80857c52010-05-05 10:14:05 -0700103
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800104 This places files in <oftest>/src/python/oftest/src and then
105 calls setuptools to install on the local host
Dan Talaycof7dae842010-02-19 11:50:02 -0800106
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800107 3. Edit configuration if necessary
108 Local platforms work with veth interface pairs and default to
109 four ports. You can adjust this a bit with the command line
110 parameters port_count, base_of_port and base_if_index.
Dan Talayco80857c52010-05-05 10:14:05 -0700111
Dan Talayco673e0852010-03-06 23:09:23 -0800112 Starting from remote.py as a simple example, you can add your
113 own <platform>.py file and then have it imported with
Dan Talayco80857c52010-05-05 10:14:05 -0700114 --platform=<platform> on the command line. This is meant to
115 allow you to test remote switches attempting to connect to a
116 controller on a network accessible to the test host.
Dan Talaycof7dae842010-02-19 11:50:02 -0800117
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800118 4. Start the switch to test
Dan Talaycof7dae842010-02-19 11:50:02 -0800119 The switch must be running and actively attempting to
Dan Talayco80857c52010-05-05 10:14:05 -0700120 connect to a controller on the test host at the port number
121 used by oft (6633 by default, or specified as --port=<n> as
122 an argument to oft).
Dan Talaycof7dae842010-02-19 11:50:02 -0800123
Dan Talaycoa85e5662010-04-16 09:35:30 -0700124 If you're new to the test environment and want to check its
125 sanity, you can do the following. This requires that
126 your host kernel supports virtual ethernet interfaces. This
127 is best done in a window separate from where you will run oft.
Dan Talayco80857c52010-05-05 10:14:05 -0700128
Dan Talaycoa85e5662010-04-16 09:35:30 -0700129 4A. Check out openflow (preferably at the same level as oftest):
130 git clone git://openflowswitch.org/openflow.git
131 4B. cd openflow; ./boot.sh; ./configure; make
132 4C. cd ../oftest/tests
133 4D. Run the switch startup script:
134 sudo ./run_switch.py; Now you can run oft (see below).
Dan Talayco80857c52010-05-05 10:14:05 -0700135 4F. Use --help to see command line switches. If you use a port
136 number other than the default, make sure you use the same
137 one for the switch as for oft.
Dan Talaycoa85e5662010-04-16 09:35:30 -0700138 4E. Use control-C to terminate the switch daemons.
139 4F. To clean up the virtual ethernet interfaces, use
140 sudo rmmod veth
141
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800142 5. Run oft
Dan Talayco673e0852010-03-06 23:09:23 -0800143 See Warning above; requires sudo to control the dataplane
Dan Talaycoa85e5662010-04-16 09:35:30 -0700144 cd <oftest>/tests
145 sudo ./oft --help
146
Dan Talayco10275aa2010-07-20 14:12:31 -0700147Helpful Note: Rebuilding
148++++++++++++++++++++++++
149
Dan Talayco10ffe262010-07-20 21:55:53 -0700150 If you ever make a change to the code in src/oftest/python...
151 you must rebuild and reinstall the source code. See Step (2)
152 in the Longer Start above.
Dan Talayco10275aa2010-07-20 14:12:31 -0700153
Dan Talayco10ffe262010-07-20 21:55:53 -0700154 If you see
Dan Talayco10275aa2010-07-20 14:12:31 -0700155
Dan Talayco10ffe262010-07-20 21:55:53 -0700156 WARNING:..:Could not import file ...
Dan Talayco10275aa2010-07-20 14:12:31 -0700157
Dan Talayco10ffe262010-07-20 21:55:53 -0700158 There is likely a Python error in the file. Try invoking the
159 Python cli directly and importing the file to get more
160 information.
Dan Talayco10275aa2010-07-20 14:12:31 -0700161
162Helpful Note: Recovering From Crash
163+++++++++++++++++++++++++++++++++++
164
Dan Talayco10ffe262010-07-20 21:55:53 -0700165 If the test script, oft, becomes unresponsive, you may find that
166 ^C does not break out of the script. In this case you have two
167 options:
Dan Talayco10275aa2010-07-20 14:12:31 -0700168
Dan Talayco10ffe262010-07-20 21:55:53 -0700169 * Use ^Z to interrupt the script and return to the shell prompt.
170 * Start another terminal window to the same machine.
Dan Talayco10275aa2010-07-20 14:12:31 -0700171
Dan Talayco10ffe262010-07-20 21:55:53 -0700172 In either case, you then need to kill the process that is hung.
173 Use the following commands:
Dan Talayco10275aa2010-07-20 14:12:31 -0700174
Dan Talayco10ffe262010-07-20 21:55:53 -0700175 me@host> ps aux | grep oft
176 root 4 0.0 S< Jul07 0:00 [ksoftirqd/0]
177 ...
178 root 14066 3.2 Tl 09:27 0:00 python ./oft ...
179 me 14074 0.0 R+ 09:28 0:00 grep oft
Dan Talayco10275aa2010-07-20 14:12:31 -0700180
Dan Talayco10ffe262010-07-20 21:55:53 -0700181 me@host> sudo kill -9 14066
Dan Talayco10275aa2010-07-20 14:12:31 -0700182
Dan Talayco10ffe262010-07-20 21:55:53 -0700183 where 14066 is the process ID of the hung process. (Replace it
184 with the PID for your process.)
185
186 This is still preliminary work and there are bugs in the framework
187 that need to be ironed out. Please report any issues to
188 dtalayco@stanford.edu.
Dan Talayco10275aa2010-07-20 14:12:31 -0700189
190
Dan Talaycoa85e5662010-04-16 09:35:30 -0700191OFT Command Line Options
192++++++++++++++++++++++++
193
194 Here is a summary of the oft command line options. Use --help to see
195 the long and short command option names.
196
197 platform : String identifying the target platform
198 controller_host : Host on which test controller is running (for sockets)
199 controller_port : Port on which test controller listens for switch cxn
200 port_count : Number of ports in dataplane
201 base_of_port : Base OpenFlow port number in dataplane
202 base_if_index : Base OS network interface for dataplane
203 test_dir : Directory to search for test files (default .)
204 test_spec : Specification of test(s) to run
205 log_file : Filename for test logging
206 list : Boolean: List all tests and exit
207 debug : String giving debug level (info, warning, error...)
208 verbose : Same as debug=verbose
Dan Talaycof7dae842010-02-19 11:50:02 -0800209
210Overview
211++++++++
212
213 The directory structure is currently:
214
215 <oftest>
216 `
217 |-- doc
218 |-- src
219 | `-- python
220 | `-- oftest
221 |-- tests
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800222 | `-- oft and files with test cases
Dan Talaycof7dae842010-02-19 11:50:02 -0800223 `-- tools
224 |-- munger
225 `-- pylibopenflow
226
227 The tools directory is what processes the OpenFlow header
228 files to produce Python classes representing OpenFlow messages.
229 The results are placed in src/python/oftest and currently
230 include:
231
232 message.py: The main API providing OF message classes
233 error.py: Subclasses for error messages
234 action.py: Subclasses for action specification
235 cstruct.py: Direct representation of C structures in Python
236 class_maps.py: Addition info about C structures
237
238 In addition, the following Python files are present in
239 src/python/oftest:
240
Dan Talaycof7dae842010-02-19 11:50:02 -0800241 controller.py: The controller representation
242 dataplane.py: The dataplane representation
243 action_list.py: Action list class
244 netutils.py: e.g., set promisc on sockets
245 ofutils.py: Utilities related to OpenFlow messages
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800246 oft_assert.py: Test framework level assertion
Dan Talaycof7dae842010-02-19 11:50:02 -0800247
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800248 Tests are run from the tests directory. The file oft is the
249 top level entry point for tests. Try ./oft --help for some more.
Dan Talaycof7dae842010-02-19 11:50:02 -0800250
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800251Important Notes
252+++++++++++++++
253
254 1. If you edit any of the files in src/python/oftest or any of the
255 scripts in tools/munger/scripts, you MUST re-run make install. This
256 is easy to forget.
257
258 2. If your running into issues with transactions, and it appears that
259 OpenFlow messages aren't quite right, start by looking at any length
260 fields in the packets. With the local platform, you can use wireshark
261 on the loopback interface as well as the dataplane veth interfaces.
262
263Adding Your Own Test Cases
264++++++++++++++++++++++++++
265
Dan Talayco6213e3c2010-07-21 21:49:00 -0700266 Check the online tutorial:
267 http://openflow.org/wk/index.php/OFTestTutorial
268
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800269 You can:
270
271 * Add cases to an existing file
272 * Add a new file
273
274 If you add cases to an existing file, each case should be its own
275 class. It must inherit from unittest.TestCase or one of its
276 derivatives and define runTest (that's how test cases are discovered).
277
278 If you add a new file, it must implement a top level function called
279 test_set_init which takes a configuration dictionary. See basic.py
280 for an example. The main point of this is to pass the port map
281 object to the test cases. But you can access any configuration
282 parameters this way. Each test case in the new file must derive
283 from unittest.TestCase.
Dan Talaycof7dae842010-02-19 11:50:02 -0800284
Dan Talayco79f36082010-03-11 16:53:53 -0800285 CONVENTIONS:
286
287 The first line of the doc string for a file and for a test class is
288 displayed in the list command. Please keep it clear and under 50
289 characters.
290
Dan Talaycod2ca1032010-03-10 14:40:26 -0800291
292Using CentOS/RHEL
293+++++++++++++++++
294
295 CentOS/RHEL have two challenges: they are very tied to Python 2.4
296 (and Scapy requires Python 2.5 for its latest version) and they
297 require a kernel upgrade to use veth pairs for local platform
298 testing.
299
300 If you only need to control eth interfaces for a remote platform,
Dan Talaycofa16d592010-03-12 10:01:43 -0800301 you can use CentOS/RHEL without major disruption. The key is to
302 download scapy-1.2 from the following link:
Dan Talaycod2ca1032010-03-10 14:40:26 -0800303
304 wget http://hg.secdev.org/scapy/raw-file/v1.2.0.2/scapy.py
305
306 See: http://www.dirk-loss.de/scapy-doc/installation.html#installing-scapy-v1-2
307 for more info.
308
309 Copy scapy.py to /usr/lib/python2.4/site-packages
310
311 If you hit an error related to importing scapy.all, you just need
312 to change the import to refer to scapy (not scapy.all). See
313 examples in parse.py for example.
314
315
Dan Talaycof7dae842010-02-19 11:50:02 -0800316Other Info
317++++++++++
318
319 * Build doc with
320 + cd <oftest>/tools/munger
321 + make doc
322 Places the results in <oftest>/doc/html
Dan Talayco10ffe262010-07-20 21:55:53 -0700323 If you have problems, check the install location doxypy.py and
324 that it is set correctly in <oftest>/doc/Doxyfile
Dan Talaycof7dae842010-02-19 11:50:02 -0800325
326 * Run lint on sources
327 + cd <oftest>/tools/munger
328 + make lint
329 Places results in <oftest>/lint/*.log
330 The file controller.log currently has some errors indicated
331
332
333To Do
334+++++
335
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800336 * Need to have an overview of the components of the test, how they
337 connect and how they are managed by the test framework.
Dan Talaycof7dae842010-02-19 11:50:02 -0800338 * See the Regression Test component on trac:
339 http://www.openflowswitch.org/bugs/openflow
340 http://www.openflowswitch.org/bugs/openflow/query?component=Regression+test+suite
341
Dan Talaycoc4747962010-02-19 12:29:17 -0800342 * Make the framework work with OF versions other than 1.0?
343