blob: 596d91a4cedcfe3cb4eacd5605b7d7283a4faf82 [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 Talayco94696932010-07-09 09:42:24 -07007
8
9=Warning=
10
11==Risks==
12This is still '''experimental''' and it requires root privilege to
13control the dataplane ports. As a consequence, there may be
14'''risks''' to the machine on which this is running.
15Use caution.
16
17==Recovering From Problems==
18
19If the test script, oft, becomes unresponsive, you may find that ^C does not
20break out of the script. In this case you have two options:
21
22* Use ^Z to interrupt the script and return to the shell prompt.
23* Start another terminal window to the same machine.
24
25In either case, you then need to kill the process that is hung. Use the
26following commands:
27
28 me@host> ps aux | grep oft
29 root 4 0.0 0.0 0 0 ? S< Jul07 0:00 [ksoftirqd/0]
30 ...
31 root 14066 3.2 0.6 149888 25344 pts/4 Tl 09:27 0:00 python ./oft ...
32 me 14074 0.0 0.0 7452 876 pts/4 R+ 09:28 0:00 grep oft
33
34 me@host> sudo kill -9 14066
35
36where 14066 is the process ID of the hung process. (Replace it with the PID for your process.)
37
38==Preliminary Work==
39
40This is still preliminary work and there are bugs in the
41framework that need to be ironed out. Please report any issues
42to dtalayco@stanford.edu.
43
Dan Talaycof7dae842010-02-19 11:50:02 -080044Warning
45+++++++
46
47This is still experimental and it requires root privilege to
Dan Talayco94696932010-07-09 09:42:24 -070048control the dataplane ports. As a consequence, there may be
49risks to the machine on which this is running. Use caution.
50
51Recovering From Problems
52++++++++++++++++++++++++
53
54If the test script, oft, becomes unresponsive, you may find that ^C
55does not break out of the script. In this case you have two options:
56
57* Use ^Z to interrupt the script and return to the shell prompt.
58* Start another terminal window to the same machine.
59
60In either case, you then need to kill the process that is hung. Use
61the following commands:
62
63 me@host> ps aux | grep oft
64 root 4 0.0 S< Jul07 0:00 [ksoftirqd/0]
65 ...
66 root 14066 3.2 Tl 09:27 0:00 python ./oft ...
67 me 14074 0.0 R+ 09:28 0:00 grep oft
68
69 me@host> sudo kill -9 14066
70
71where 14066 is the process ID of the hung process. (Replace it with
72the PID for your process.)
Dan Talaycof7dae842010-02-19 11:50:02 -080073
Dan Talayco1ddefbf2010-03-07 21:56:47 -080074This is still preliminary work and there are bugs in the
75framework that need to be ironed out. Please report any issues
76to dtalayco@stanford.edu.
77
Dan Talayco80857c52010-05-05 10:14:05 -070078Introduction
79++++++++++++
80
81 This test framework is meant to exercise a candidate OpenFlow
82 switch (the device/switch under test, DUT or SUT). It provides a
83 connection like a controller to which the switch connects and it
84 controls data plane ports, sending and receiving packets, which
85 should be connected to the switch.
86
87 There are two parts to running the test framework:
88
89 * Building the python libraries that support the OF protocol
90 * Running oft, the main entry point of the test framework
91
92 Normally log output from oft is sent to the file oft.log, but
93 can be redirected to the console by specifying --log-file="".
94
Dan Talaycof7dae842010-02-19 11:50:02 -080095Quick Start
96+++++++++++
Dan Talaycoa85e5662010-04-16 09:35:30 -070097
Dan Talayco94696932010-07-09 09:42:24 -070098 You need to have Python setup tools and Scapy installed on your
99 system. See 'Pre-requisites' below.
100
Dan Talaycoa85e5662010-04-16 09:35:30 -0700101 Make sure your switch is running and trying to connect to a
102 controller on the machine where you're running oft (normally port
Dan Talayco80857c52010-05-05 10:14:05 -0700103 6633). See below regarding run_switch.py for a script that starts
104 up a software switch on the test host.
Dan Talaycoa85e5662010-04-16 09:35:30 -0700105
106 Currently, switches must be running version 1.0 of OpenFlow.
107
Dan Talayco80857c52010-05-05 10:14:05 -0700108 # git clone yuba:/usr/local/git/openflow-projects/oftest
109 # cd oftest/tools/munger
110 # make install
111 # cd ../../tests
Dan Talayco94696932010-07-09 09:42:24 -0700112 Make sure the switch you want to test is running --
113 see (4) below for the reference switch example.
Dan Talayco80857c52010-05-05 10:14:05 -0700114 # ./oft --list
115 # sudo ./oft
116 # sudo ./oft --verbose --log-file=""
117 # sudo ./oft --test-spec=<mod> --platform=remote --host=...
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800118
119Longer Start
120++++++++++++
Dan Talaycof7dae842010-02-19 11:50:02 -0800121
122 1. Pre-requisites:
Dan Talaycoa85e5662010-04-16 09:35:30 -0700123 * An OF switch instance to test (see 4 below)
Dan Talayco80857c52010-05-05 10:14:05 -0700124 * Root privilege on host running oft
125 * Switch running OpenFlow 1.0 and attempting to connect
126 to a controller on the machine running oft.
127 * Python 2.5. You can run platforms using eth interfaces
128 with Python 2.4.
129 * Python setup tools (e.g.: sudo apt-get install python-setuptools)
130 * oftest checked out (called <oftest> here)
Dan Talaycof7dae842010-02-19 11:50:02 -0800131 * scapy installed: http://www.secdev.org/projects/scapy/
Dan Talayco80857c52010-05-05 10:14:05 -0700132 'sudo apt-get install scapy' should work on Debian.
Dan Talaycoa85e5662010-04-16 09:35:30 -0700133 * tcpdump installed (optional, but scapy will complain if it's
134 not there)
Dan Talaycof7dae842010-02-19 11:50:02 -0800135 * Doxygen and doxypy for document generation (optional)
136 * lint for source checking (optional)
137
138 2. Build the OpenFlow Python message classes
Dan Talaycoc4747962010-02-19 12:29:17 -0800139
140 Important: The OF version used by the controller is based on
141 the file in <oftest>/tools/pylibopenflow/include/openflow.h
142 This is currently the 1.0 release file.
143
Dan Talaycoa85e5662010-04-16 09:35:30 -0700144 cd <oftest>/tools/munger
145 make install
Dan Talayco80857c52010-05-05 10:14:05 -0700146
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800147 This places files in <oftest>/src/python/oftest/src and then
148 calls setuptools to install on the local host
Dan Talaycof7dae842010-02-19 11:50:02 -0800149
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800150 3. Edit configuration if necessary
151 Local platforms work with veth interface pairs and default to
152 four ports. You can adjust this a bit with the command line
153 parameters port_count, base_of_port and base_if_index.
Dan Talayco80857c52010-05-05 10:14:05 -0700154
Dan Talayco673e0852010-03-06 23:09:23 -0800155 Starting from remote.py as a simple example, you can add your
156 own <platform>.py file and then have it imported with
Dan Talayco80857c52010-05-05 10:14:05 -0700157 --platform=<platform> on the command line. This is meant to
158 allow you to test remote switches attempting to connect to a
159 controller on a network accessible to the test host.
Dan Talaycof7dae842010-02-19 11:50:02 -0800160
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800161 4. Start the switch to test
Dan Talaycof7dae842010-02-19 11:50:02 -0800162 The switch must be running and actively attempting to
Dan Talayco80857c52010-05-05 10:14:05 -0700163 connect to a controller on the test host at the port number
164 used by oft (6633 by default, or specified as --port=<n> as
165 an argument to oft).
Dan Talaycof7dae842010-02-19 11:50:02 -0800166
Dan Talaycoa85e5662010-04-16 09:35:30 -0700167 If you're new to the test environment and want to check its
168 sanity, you can do the following. This requires that
169 your host kernel supports virtual ethernet interfaces. This
170 is best done in a window separate from where you will run oft.
Dan Talayco80857c52010-05-05 10:14:05 -0700171
Dan Talaycoa85e5662010-04-16 09:35:30 -0700172 4A. Check out openflow (preferably at the same level as oftest):
173 git clone git://openflowswitch.org/openflow.git
174 4B. cd openflow; ./boot.sh; ./configure; make
175 4C. cd ../oftest/tests
176 4D. Run the switch startup script:
177 sudo ./run_switch.py; Now you can run oft (see below).
Dan Talayco80857c52010-05-05 10:14:05 -0700178 4F. Use --help to see command line switches. If you use a port
179 number other than the default, make sure you use the same
180 one for the switch as for oft.
Dan Talaycoa85e5662010-04-16 09:35:30 -0700181 4E. Use control-C to terminate the switch daemons.
182 4F. To clean up the virtual ethernet interfaces, use
183 sudo rmmod veth
184
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800185 5. Run oft
Dan Talayco673e0852010-03-06 23:09:23 -0800186 See Warning above; requires sudo to control the dataplane
Dan Talaycoa85e5662010-04-16 09:35:30 -0700187 cd <oftest>/tests
188 sudo ./oft --help
189
190OFT Command Line Options
191++++++++++++++++++++++++
192
193 Here is a summary of the oft command line options. Use --help to see
194 the long and short command option names.
195
196 platform : String identifying the target platform
197 controller_host : Host on which test controller is running (for sockets)
198 controller_port : Port on which test controller listens for switch cxn
199 port_count : Number of ports in dataplane
200 base_of_port : Base OpenFlow port number in dataplane
201 base_if_index : Base OS network interface for dataplane
202 test_dir : Directory to search for test files (default .)
203 test_spec : Specification of test(s) to run
204 log_file : Filename for test logging
205 list : Boolean: List all tests and exit
206 debug : String giving debug level (info, warning, error...)
207 verbose : Same as debug=verbose
Dan Talaycof7dae842010-02-19 11:50:02 -0800208
209Overview
210++++++++
211
212 The directory structure is currently:
213
214 <oftest>
215 `
216 |-- doc
217 |-- src
218 | `-- python
219 | `-- oftest
220 |-- tests
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800221 | `-- oft and files with test cases
Dan Talaycof7dae842010-02-19 11:50:02 -0800222 `-- tools
223 |-- munger
224 `-- pylibopenflow
225
226 The tools directory is what processes the OpenFlow header
227 files to produce Python classes representing OpenFlow messages.
228 The results are placed in src/python/oftest and currently
229 include:
230
231 message.py: The main API providing OF message classes
232 error.py: Subclasses for error messages
233 action.py: Subclasses for action specification
234 cstruct.py: Direct representation of C structures in Python
235 class_maps.py: Addition info about C structures
236
237 In addition, the following Python files are present in
238 src/python/oftest:
239
Dan Talaycof7dae842010-02-19 11:50:02 -0800240 controller.py: The controller representation
241 dataplane.py: The dataplane representation
242 action_list.py: Action list class
243 netutils.py: e.g., set promisc on sockets
244 ofutils.py: Utilities related to OpenFlow messages
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800245 oft_assert.py: Test framework level assertion
Dan Talaycof7dae842010-02-19 11:50:02 -0800246
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800247 Tests are run from the tests directory. The file oft is the
248 top level entry point for tests. Try ./oft --help for some more.
Dan Talaycof7dae842010-02-19 11:50:02 -0800249
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800250Important Notes
251+++++++++++++++
252
253 1. If you edit any of the files in src/python/oftest or any of the
254 scripts in tools/munger/scripts, you MUST re-run make install. This
255 is easy to forget.
256
257 2. If your running into issues with transactions, and it appears that
258 OpenFlow messages aren't quite right, start by looking at any length
259 fields in the packets. With the local platform, you can use wireshark
260 on the loopback interface as well as the dataplane veth interfaces.
261
262Adding Your Own Test Cases
263++++++++++++++++++++++++++
264
265 You can:
266
267 * Add cases to an existing file
268 * Add a new file
269
270 If you add cases to an existing file, each case should be its own
271 class. It must inherit from unittest.TestCase or one of its
272 derivatives and define runTest (that's how test cases are discovered).
273
274 If you add a new file, it must implement a top level function called
275 test_set_init which takes a configuration dictionary. See basic.py
276 for an example. The main point of this is to pass the port map
277 object to the test cases. But you can access any configuration
278 parameters this way. Each test case in the new file must derive
279 from unittest.TestCase.
Dan Talaycof7dae842010-02-19 11:50:02 -0800280
Dan Talayco79f36082010-03-11 16:53:53 -0800281 CONVENTIONS:
282
283 The first line of the doc string for a file and for a test class is
284 displayed in the list command. Please keep it clear and under 50
285 characters.
286
Dan Talaycod2ca1032010-03-10 14:40:26 -0800287
288Using CentOS/RHEL
289+++++++++++++++++
290
291 CentOS/RHEL have two challenges: they are very tied to Python 2.4
292 (and Scapy requires Python 2.5 for its latest version) and they
293 require a kernel upgrade to use veth pairs for local platform
294 testing.
295
296 If you only need to control eth interfaces for a remote platform,
Dan Talaycofa16d592010-03-12 10:01:43 -0800297 you can use CentOS/RHEL without major disruption. The key is to
298 download scapy-1.2 from the following link:
Dan Talaycod2ca1032010-03-10 14:40:26 -0800299
300 wget http://hg.secdev.org/scapy/raw-file/v1.2.0.2/scapy.py
301
302 See: http://www.dirk-loss.de/scapy-doc/installation.html#installing-scapy-v1-2
303 for more info.
304
305 Copy scapy.py to /usr/lib/python2.4/site-packages
306
307 If you hit an error related to importing scapy.all, you just need
308 to change the import to refer to scapy (not scapy.all). See
309 examples in parse.py for example.
310
311
Dan Talaycof7dae842010-02-19 11:50:02 -0800312Other Info
313++++++++++
314
315 * Build doc with
316 + cd <oftest>/tools/munger
317 + make doc
318 Places the results in <oftest>/doc/html
319
320 * Run lint on sources
321 + cd <oftest>/tools/munger
322 + make lint
323 Places results in <oftest>/lint/*.log
324 The file controller.log currently has some errors indicated
325
326
327To Do
328+++++
329
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800330 * Need to have an overview of the components of the test, how they
331 connect and how they are managed by the test framework.
Dan Talaycof7dae842010-02-19 11:50:02 -0800332 * See the Regression Test component on trac:
333 http://www.openflowswitch.org/bugs/openflow
334 http://www.openflowswitch.org/bugs/openflow/query?component=Regression+test+suite
335
Dan Talaycoc4747962010-02-19 12:29:17 -0800336 * Make the framework work with OF versions other than 1.0?
337