blob: 3cb9ac9910ddced38cae51c4f6782bbb3ea8f956 [file] [log] [blame]
Dan Talaycof7dae842010-02-19 11:50:02 -08001OpenFlow Testing Framework
Dan Talayco79f36082010-03-11 16:53:53 -08002March, 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
10This is still experimental and it requires root privilege to
Dan Talayco94696932010-07-09 09:42:24 -070011control the dataplane ports. As a consequence, there may be
12risks to the machine on which this is running. Use caution.
13
Dan Talayco10275aa2010-07-20 14:12:31 -070014Please 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 Talayco10275aa2010-07-20 14:12:31 -070019The software included with this distribution is subject to the
20OpenFlow Switching License as given in the included file LICENSE.
21Details 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 Talayco10275aa2010-07-20 14:12:31 -070025Other software referenced in this distribution is subject to its
26respective license.
Dan Talayco551befa2010-07-15 17:05:32 -070027
Dan Talayco80857c52010-05-05 10:14:05 -070028Introduction
29++++++++++++
30
31 This test framework is meant to exercise a candidate OpenFlow
32 switch (the device/switch under test, DUT or SUT). It provides a
33 connection like a controller to which the switch connects and it
34 controls data plane ports, sending and receiving packets, which
35 should be connected to the switch.
36
37 There are two parts to running the test framework:
38
39 * Building the python libraries that support the OF protocol
40 * Running oft, the main entry point of the test framework
41
42 Normally log output from oft is sent to the file oft.log, but
43 can be redirected to the console by specifying --log-file="".
44
Dan Talaycof7dae842010-02-19 11:50:02 -080045Quick Start
46+++++++++++
Dan Talaycoa85e5662010-04-16 09:35:30 -070047
Dan Talayco94696932010-07-09 09:42:24 -070048 You need to have Python setup tools and Scapy installed on your
49 system. See 'Pre-requisites' below.
50
Dan Talaycoa85e5662010-04-16 09:35:30 -070051 Make sure your switch is running and trying to connect to a
52 controller on the machine where you're running oft (normally port
Dan Talayco80857c52010-05-05 10:14:05 -070053 6633). See below regarding run_switch.py for a script that starts
54 up a software switch on the test host.
Dan Talaycoa85e5662010-04-16 09:35:30 -070055
56 Currently, switches must be running version 1.0 of OpenFlow.
57
Dan Talayco80857c52010-05-05 10:14:05 -070058 # git clone yuba:/usr/local/git/openflow-projects/oftest
59 # cd oftest/tools/munger
60 # make install
61 # cd ../../tests
Dan Talayco94696932010-07-09 09:42:24 -070062 Make sure the switch you want to test is running --
63 see (4) below for the reference switch example.
Dan Talayco80857c52010-05-05 10:14:05 -070064 # ./oft --list
65 # sudo ./oft
66 # sudo ./oft --verbose --log-file=""
67 # sudo ./oft --test-spec=<mod> --platform=remote --host=...
Dan Talayco1ddefbf2010-03-07 21:56:47 -080068
69Longer Start
70++++++++++++
Dan Talaycof7dae842010-02-19 11:50:02 -080071
72 1. Pre-requisites:
Dan Talaycoa85e5662010-04-16 09:35:30 -070073 * An OF switch instance to test (see 4 below)
Dan Talayco80857c52010-05-05 10:14:05 -070074 * Root privilege on host running oft
75 * Switch running OpenFlow 1.0 and attempting to connect
76 to a controller on the machine running oft.
77 * Python 2.5. You can run platforms using eth interfaces
78 with Python 2.4.
79 * Python setup tools (e.g.: sudo apt-get install python-setuptools)
80 * oftest checked out (called <oftest> here)
Dan Talaycof7dae842010-02-19 11:50:02 -080081 * scapy installed: http://www.secdev.org/projects/scapy/
Dan Talayco80857c52010-05-05 10:14:05 -070082 'sudo apt-get install scapy' should work on Debian.
Dan Talaycoa85e5662010-04-16 09:35:30 -070083 * tcpdump installed (optional, but scapy will complain if it's
84 not there)
Dan Talaycof7dae842010-02-19 11:50:02 -080085 * Doxygen and doxypy for document generation (optional)
86 * lint for source checking (optional)
87
88 2. Build the OpenFlow Python message classes
Dan Talaycoc4747962010-02-19 12:29:17 -080089
90 Important: The OF version used by the controller is based on
91 the file in <oftest>/tools/pylibopenflow/include/openflow.h
92 This is currently the 1.0 release file.
93
Dan Talaycoa85e5662010-04-16 09:35:30 -070094 cd <oftest>/tools/munger
95 make install
Dan Talayco80857c52010-05-05 10:14:05 -070096
Dan Talayco1ddefbf2010-03-07 21:56:47 -080097 This places files in <oftest>/src/python/oftest/src and then
98 calls setuptools to install on the local host
Dan Talaycof7dae842010-02-19 11:50:02 -080099
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800100 3. Edit configuration if necessary
101 Local platforms work with veth interface pairs and default to
102 four ports. You can adjust this a bit with the command line
103 parameters port_count, base_of_port and base_if_index.
Dan Talayco80857c52010-05-05 10:14:05 -0700104
Dan Talayco673e0852010-03-06 23:09:23 -0800105 Starting from remote.py as a simple example, you can add your
106 own <platform>.py file and then have it imported with
Dan Talayco80857c52010-05-05 10:14:05 -0700107 --platform=<platform> on the command line. This is meant to
108 allow you to test remote switches attempting to connect to a
109 controller on a network accessible to the test host.
Dan Talaycof7dae842010-02-19 11:50:02 -0800110
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800111 4. Start the switch to test
Dan Talaycof7dae842010-02-19 11:50:02 -0800112 The switch must be running and actively attempting to
Dan Talayco80857c52010-05-05 10:14:05 -0700113 connect to a controller on the test host at the port number
114 used by oft (6633 by default, or specified as --port=<n> as
115 an argument to oft).
Dan Talaycof7dae842010-02-19 11:50:02 -0800116
Dan Talaycoa85e5662010-04-16 09:35:30 -0700117 If you're new to the test environment and want to check its
118 sanity, you can do the following. This requires that
119 your host kernel supports virtual ethernet interfaces. This
120 is best done in a window separate from where you will run oft.
Dan Talayco80857c52010-05-05 10:14:05 -0700121
Dan Talaycoa85e5662010-04-16 09:35:30 -0700122 4A. Check out openflow (preferably at the same level as oftest):
123 git clone git://openflowswitch.org/openflow.git
124 4B. cd openflow; ./boot.sh; ./configure; make
125 4C. cd ../oftest/tests
126 4D. Run the switch startup script:
127 sudo ./run_switch.py; Now you can run oft (see below).
Dan Talayco80857c52010-05-05 10:14:05 -0700128 4F. Use --help to see command line switches. If you use a port
129 number other than the default, make sure you use the same
130 one for the switch as for oft.
Dan Talaycoa85e5662010-04-16 09:35:30 -0700131 4E. Use control-C to terminate the switch daemons.
132 4F. To clean up the virtual ethernet interfaces, use
133 sudo rmmod veth
134
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800135 5. Run oft
Dan Talayco673e0852010-03-06 23:09:23 -0800136 See Warning above; requires sudo to control the dataplane
Dan Talaycoa85e5662010-04-16 09:35:30 -0700137 cd <oftest>/tests
138 sudo ./oft --help
139
Dan Talayco10275aa2010-07-20 14:12:31 -0700140Helpful Note: Rebuilding
141++++++++++++++++++++++++
142
143If you ever make a change to the code in src/oftest/python...
144you must rebuild and reinstall the source code. See Step (2)
145in the Longer Start above.
146
147If you see
148
149 WARNING:..:Could not import file ...
150
151There is likely a Python error in the file. Try invoking the
152Python cli directly and importing the file to get more information.
153
154Helpful Note: Recovering From Crash
155+++++++++++++++++++++++++++++++++++
156
157If the test script, oft, becomes unresponsive, you may find that ^C
158does not break out of the script. In this case you have two options:
159
160* Use ^Z to interrupt the script and return to the shell prompt.
161* Start another terminal window to the same machine.
162
163In either case, you then need to kill the process that is hung. Use
164the following commands:
165
166 me@host> ps aux | grep oft
167 root 4 0.0 S< Jul07 0:00 [ksoftirqd/0]
168 ...
169 root 14066 3.2 Tl 09:27 0:00 python ./oft ...
170 me 14074 0.0 R+ 09:28 0:00 grep oft
171
172 me@host> sudo kill -9 14066
173
174where 14066 is the process ID of the hung process. (Replace it with
175the PID for your process.)
176
177This is still preliminary work and there are bugs in the
178framework that need to be ironed out. Please report any issues
179to dtalayco@stanford.edu.
180
181
Dan Talaycoa85e5662010-04-16 09:35:30 -0700182OFT Command Line Options
183++++++++++++++++++++++++
184
185 Here is a summary of the oft command line options. Use --help to see
186 the long and short command option names.
187
188 platform : String identifying the target platform
189 controller_host : Host on which test controller is running (for sockets)
190 controller_port : Port on which test controller listens for switch cxn
191 port_count : Number of ports in dataplane
192 base_of_port : Base OpenFlow port number in dataplane
193 base_if_index : Base OS network interface for dataplane
194 test_dir : Directory to search for test files (default .)
195 test_spec : Specification of test(s) to run
196 log_file : Filename for test logging
197 list : Boolean: List all tests and exit
198 debug : String giving debug level (info, warning, error...)
199 verbose : Same as debug=verbose
Dan Talaycof7dae842010-02-19 11:50:02 -0800200
201Overview
202++++++++
203
204 The directory structure is currently:
205
206 <oftest>
207 `
208 |-- doc
209 |-- src
210 | `-- python
211 | `-- oftest
212 |-- tests
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800213 | `-- oft and files with test cases
Dan Talaycof7dae842010-02-19 11:50:02 -0800214 `-- tools
215 |-- munger
216 `-- pylibopenflow
217
218 The tools directory is what processes the OpenFlow header
219 files to produce Python classes representing OpenFlow messages.
220 The results are placed in src/python/oftest and currently
221 include:
222
223 message.py: The main API providing OF message classes
224 error.py: Subclasses for error messages
225 action.py: Subclasses for action specification
226 cstruct.py: Direct representation of C structures in Python
227 class_maps.py: Addition info about C structures
228
229 In addition, the following Python files are present in
230 src/python/oftest:
231
Dan Talaycof7dae842010-02-19 11:50:02 -0800232 controller.py: The controller representation
233 dataplane.py: The dataplane representation
234 action_list.py: Action list class
235 netutils.py: e.g., set promisc on sockets
236 ofutils.py: Utilities related to OpenFlow messages
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800237 oft_assert.py: Test framework level assertion
Dan Talaycof7dae842010-02-19 11:50:02 -0800238
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800239 Tests are run from the tests directory. The file oft is the
240 top level entry point for tests. Try ./oft --help for some more.
Dan Talaycof7dae842010-02-19 11:50:02 -0800241
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800242Important Notes
243+++++++++++++++
244
245 1. If you edit any of the files in src/python/oftest or any of the
246 scripts in tools/munger/scripts, you MUST re-run make install. This
247 is easy to forget.
248
249 2. If your running into issues with transactions, and it appears that
250 OpenFlow messages aren't quite right, start by looking at any length
251 fields in the packets. With the local platform, you can use wireshark
252 on the loopback interface as well as the dataplane veth interfaces.
253
254Adding Your Own Test Cases
255++++++++++++++++++++++++++
256
257 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
311
312 * Run lint on sources
313 + cd <oftest>/tools/munger
314 + make lint
315 Places results in <oftest>/lint/*.log
316 The file controller.log currently has some errors indicated
317
318
319To Do
320+++++
321
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800322 * Need to have an overview of the components of the test, how they
323 connect and how they are managed by the test framework.
Dan Talaycof7dae842010-02-19 11:50:02 -0800324 * See the Regression Test component on trac:
325 http://www.openflowswitch.org/bugs/openflow
326 http://www.openflowswitch.org/bugs/openflow/query?component=Regression+test+suite
327
Dan Talaycoc4747962010-02-19 12:29:17 -0800328 * Make the framework work with OF versions other than 1.0?
329