blob: 371bbd655a4e8fefbff4e1be3cb33207634df31c [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 Talayco551befa2010-07-15 17:05:32 -070014Rebuilding
15++++++++++
16
17If you ever make a change to the code in src/oftest/python...
18you must rebuild and reinstall the source code. See Step (2)
19in the Longer Start below.
20
21If you see
22
23 WARNING:..:Could not import file ...
24
25There is likely a Python error in the file. Try invoking the
26Python cli and importing the file directly to get more information.
27
28Recovering From Crash
29+++++++++++++++++++++
Dan Talayco94696932010-07-09 09:42:24 -070030
31If the test script, oft, becomes unresponsive, you may find that ^C
32does not break out of the script. In this case you have two options:
33
34* Use ^Z to interrupt the script and return to the shell prompt.
35* Start another terminal window to the same machine.
36
37In either case, you then need to kill the process that is hung. Use
38the following commands:
39
40 me@host> ps aux | grep oft
41 root 4 0.0 S< Jul07 0:00 [ksoftirqd/0]
42 ...
43 root 14066 3.2 Tl 09:27 0:00 python ./oft ...
44 me 14074 0.0 R+ 09:28 0:00 grep oft
45
46 me@host> sudo kill -9 14066
47
48where 14066 is the process ID of the hung process. (Replace it with
49the PID for your process.)
Dan Talaycof7dae842010-02-19 11:50:02 -080050
Dan Talayco1ddefbf2010-03-07 21:56:47 -080051This is still preliminary work and there are bugs in the
52framework that need to be ironed out. Please report any issues
53to dtalayco@stanford.edu.
54
Dan Talayco551befa2010-07-15 17:05:32 -070055
Dan Talayco80857c52010-05-05 10:14:05 -070056Introduction
57++++++++++++
58
59 This test framework is meant to exercise a candidate OpenFlow
60 switch (the device/switch under test, DUT or SUT). It provides a
61 connection like a controller to which the switch connects and it
62 controls data plane ports, sending and receiving packets, which
63 should be connected to the switch.
64
65 There are two parts to running the test framework:
66
67 * Building the python libraries that support the OF protocol
68 * Running oft, the main entry point of the test framework
69
70 Normally log output from oft is sent to the file oft.log, but
71 can be redirected to the console by specifying --log-file="".
72
Dan Talaycof7dae842010-02-19 11:50:02 -080073Quick Start
74+++++++++++
Dan Talaycoa85e5662010-04-16 09:35:30 -070075
Dan Talayco94696932010-07-09 09:42:24 -070076 You need to have Python setup tools and Scapy installed on your
77 system. See 'Pre-requisites' below.
78
Dan Talaycoa85e5662010-04-16 09:35:30 -070079 Make sure your switch is running and trying to connect to a
80 controller on the machine where you're running oft (normally port
Dan Talayco80857c52010-05-05 10:14:05 -070081 6633). See below regarding run_switch.py for a script that starts
82 up a software switch on the test host.
Dan Talaycoa85e5662010-04-16 09:35:30 -070083
84 Currently, switches must be running version 1.0 of OpenFlow.
85
Dan Talayco80857c52010-05-05 10:14:05 -070086 # git clone yuba:/usr/local/git/openflow-projects/oftest
87 # cd oftest/tools/munger
88 # make install
89 # cd ../../tests
Dan Talayco94696932010-07-09 09:42:24 -070090 Make sure the switch you want to test is running --
91 see (4) below for the reference switch example.
Dan Talayco80857c52010-05-05 10:14:05 -070092 # ./oft --list
93 # sudo ./oft
94 # sudo ./oft --verbose --log-file=""
95 # sudo ./oft --test-spec=<mod> --platform=remote --host=...
Dan Talayco1ddefbf2010-03-07 21:56:47 -080096
97Longer Start
98++++++++++++
Dan Talaycof7dae842010-02-19 11:50:02 -080099
100 1. Pre-requisites:
Dan Talaycoa85e5662010-04-16 09:35:30 -0700101 * An OF switch instance to test (see 4 below)
Dan Talayco80857c52010-05-05 10:14:05 -0700102 * Root privilege on host running oft
103 * Switch running OpenFlow 1.0 and attempting to connect
104 to a controller on the machine running oft.
105 * Python 2.5. You can run platforms using eth interfaces
106 with Python 2.4.
107 * Python setup tools (e.g.: sudo apt-get install python-setuptools)
108 * oftest checked out (called <oftest> here)
Dan Talaycof7dae842010-02-19 11:50:02 -0800109 * scapy installed: http://www.secdev.org/projects/scapy/
Dan Talayco80857c52010-05-05 10:14:05 -0700110 'sudo apt-get install scapy' should work on Debian.
Dan Talaycoa85e5662010-04-16 09:35:30 -0700111 * tcpdump installed (optional, but scapy will complain if it's
112 not there)
Dan Talaycof7dae842010-02-19 11:50:02 -0800113 * Doxygen and doxypy for document generation (optional)
114 * lint for source checking (optional)
115
116 2. Build the OpenFlow Python message classes
Dan Talaycoc4747962010-02-19 12:29:17 -0800117
118 Important: The OF version used by the controller is based on
119 the file in <oftest>/tools/pylibopenflow/include/openflow.h
120 This is currently the 1.0 release file.
121
Dan Talaycoa85e5662010-04-16 09:35:30 -0700122 cd <oftest>/tools/munger
123 make install
Dan Talayco80857c52010-05-05 10:14:05 -0700124
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800125 This places files in <oftest>/src/python/oftest/src and then
126 calls setuptools to install on the local host
Dan Talaycof7dae842010-02-19 11:50:02 -0800127
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800128 3. Edit configuration if necessary
129 Local platforms work with veth interface pairs and default to
130 four ports. You can adjust this a bit with the command line
131 parameters port_count, base_of_port and base_if_index.
Dan Talayco80857c52010-05-05 10:14:05 -0700132
Dan Talayco673e0852010-03-06 23:09:23 -0800133 Starting from remote.py as a simple example, you can add your
134 own <platform>.py file and then have it imported with
Dan Talayco80857c52010-05-05 10:14:05 -0700135 --platform=<platform> on the command line. This is meant to
136 allow you to test remote switches attempting to connect to a
137 controller on a network accessible to the test host.
Dan Talaycof7dae842010-02-19 11:50:02 -0800138
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800139 4. Start the switch to test
Dan Talaycof7dae842010-02-19 11:50:02 -0800140 The switch must be running and actively attempting to
Dan Talayco80857c52010-05-05 10:14:05 -0700141 connect to a controller on the test host at the port number
142 used by oft (6633 by default, or specified as --port=<n> as
143 an argument to oft).
Dan Talaycof7dae842010-02-19 11:50:02 -0800144
Dan Talaycoa85e5662010-04-16 09:35:30 -0700145 If you're new to the test environment and want to check its
146 sanity, you can do the following. This requires that
147 your host kernel supports virtual ethernet interfaces. This
148 is best done in a window separate from where you will run oft.
Dan Talayco80857c52010-05-05 10:14:05 -0700149
Dan Talaycoa85e5662010-04-16 09:35:30 -0700150 4A. Check out openflow (preferably at the same level as oftest):
151 git clone git://openflowswitch.org/openflow.git
152 4B. cd openflow; ./boot.sh; ./configure; make
153 4C. cd ../oftest/tests
154 4D. Run the switch startup script:
155 sudo ./run_switch.py; Now you can run oft (see below).
Dan Talayco80857c52010-05-05 10:14:05 -0700156 4F. Use --help to see command line switches. If you use a port
157 number other than the default, make sure you use the same
158 one for the switch as for oft.
Dan Talaycoa85e5662010-04-16 09:35:30 -0700159 4E. Use control-C to terminate the switch daemons.
160 4F. To clean up the virtual ethernet interfaces, use
161 sudo rmmod veth
162
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800163 5. Run oft
Dan Talayco673e0852010-03-06 23:09:23 -0800164 See Warning above; requires sudo to control the dataplane
Dan Talaycoa85e5662010-04-16 09:35:30 -0700165 cd <oftest>/tests
166 sudo ./oft --help
167
168OFT Command Line Options
169++++++++++++++++++++++++
170
171 Here is a summary of the oft command line options. Use --help to see
172 the long and short command option names.
173
174 platform : String identifying the target platform
175 controller_host : Host on which test controller is running (for sockets)
176 controller_port : Port on which test controller listens for switch cxn
177 port_count : Number of ports in dataplane
178 base_of_port : Base OpenFlow port number in dataplane
179 base_if_index : Base OS network interface for dataplane
180 test_dir : Directory to search for test files (default .)
181 test_spec : Specification of test(s) to run
182 log_file : Filename for test logging
183 list : Boolean: List all tests and exit
184 debug : String giving debug level (info, warning, error...)
185 verbose : Same as debug=verbose
Dan Talaycof7dae842010-02-19 11:50:02 -0800186
187Overview
188++++++++
189
190 The directory structure is currently:
191
192 <oftest>
193 `
194 |-- doc
195 |-- src
196 | `-- python
197 | `-- oftest
198 |-- tests
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800199 | `-- oft and files with test cases
Dan Talaycof7dae842010-02-19 11:50:02 -0800200 `-- tools
201 |-- munger
202 `-- pylibopenflow
203
204 The tools directory is what processes the OpenFlow header
205 files to produce Python classes representing OpenFlow messages.
206 The results are placed in src/python/oftest and currently
207 include:
208
209 message.py: The main API providing OF message classes
210 error.py: Subclasses for error messages
211 action.py: Subclasses for action specification
212 cstruct.py: Direct representation of C structures in Python
213 class_maps.py: Addition info about C structures
214
215 In addition, the following Python files are present in
216 src/python/oftest:
217
Dan Talaycof7dae842010-02-19 11:50:02 -0800218 controller.py: The controller representation
219 dataplane.py: The dataplane representation
220 action_list.py: Action list class
221 netutils.py: e.g., set promisc on sockets
222 ofutils.py: Utilities related to OpenFlow messages
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800223 oft_assert.py: Test framework level assertion
Dan Talaycof7dae842010-02-19 11:50:02 -0800224
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800225 Tests are run from the tests directory. The file oft is the
226 top level entry point for tests. Try ./oft --help for some more.
Dan Talaycof7dae842010-02-19 11:50:02 -0800227
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800228Important Notes
229+++++++++++++++
230
231 1. If you edit any of the files in src/python/oftest or any of the
232 scripts in tools/munger/scripts, you MUST re-run make install. This
233 is easy to forget.
234
235 2. If your running into issues with transactions, and it appears that
236 OpenFlow messages aren't quite right, start by looking at any length
237 fields in the packets. With the local platform, you can use wireshark
238 on the loopback interface as well as the dataplane veth interfaces.
239
240Adding Your Own Test Cases
241++++++++++++++++++++++++++
242
243 You can:
244
245 * Add cases to an existing file
246 * Add a new file
247
248 If you add cases to an existing file, each case should be its own
249 class. It must inherit from unittest.TestCase or one of its
250 derivatives and define runTest (that's how test cases are discovered).
251
252 If you add a new file, it must implement a top level function called
253 test_set_init which takes a configuration dictionary. See basic.py
254 for an example. The main point of this is to pass the port map
255 object to the test cases. But you can access any configuration
256 parameters this way. Each test case in the new file must derive
257 from unittest.TestCase.
Dan Talaycof7dae842010-02-19 11:50:02 -0800258
Dan Talayco79f36082010-03-11 16:53:53 -0800259 CONVENTIONS:
260
261 The first line of the doc string for a file and for a test class is
262 displayed in the list command. Please keep it clear and under 50
263 characters.
264
Dan Talaycod2ca1032010-03-10 14:40:26 -0800265
266Using CentOS/RHEL
267+++++++++++++++++
268
269 CentOS/RHEL have two challenges: they are very tied to Python 2.4
270 (and Scapy requires Python 2.5 for its latest version) and they
271 require a kernel upgrade to use veth pairs for local platform
272 testing.
273
274 If you only need to control eth interfaces for a remote platform,
Dan Talaycofa16d592010-03-12 10:01:43 -0800275 you can use CentOS/RHEL without major disruption. The key is to
276 download scapy-1.2 from the following link:
Dan Talaycod2ca1032010-03-10 14:40:26 -0800277
278 wget http://hg.secdev.org/scapy/raw-file/v1.2.0.2/scapy.py
279
280 See: http://www.dirk-loss.de/scapy-doc/installation.html#installing-scapy-v1-2
281 for more info.
282
283 Copy scapy.py to /usr/lib/python2.4/site-packages
284
285 If you hit an error related to importing scapy.all, you just need
286 to change the import to refer to scapy (not scapy.all). See
287 examples in parse.py for example.
288
289
Dan Talaycof7dae842010-02-19 11:50:02 -0800290Other Info
291++++++++++
292
293 * Build doc with
294 + cd <oftest>/tools/munger
295 + make doc
296 Places the results in <oftest>/doc/html
297
298 * Run lint on sources
299 + cd <oftest>/tools/munger
300 + make lint
301 Places results in <oftest>/lint/*.log
302 The file controller.log currently has some errors indicated
303
304
305To Do
306+++++
307
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800308 * Need to have an overview of the components of the test, how they
309 connect and how they are managed by the test framework.
Dan Talaycof7dae842010-02-19 11:50:02 -0800310 * See the Regression Test component on trac:
311 http://www.openflowswitch.org/bugs/openflow
312 http://www.openflowswitch.org/bugs/openflow/query?component=Regression+test+suite
313
Dan Talaycoc4747962010-02-19 12:29:17 -0800314 * Make the framework work with OF versions other than 1.0?
315