blob: 9e873994a16d15d1fe15224f653fbfc9b2137194 [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
11control the dataplane ports. As a consequence, there are
12some serious risks to the machine on which this is running.
13Use caution.
14
Dan Talayco1ddefbf2010-03-07 21:56:47 -080015This is still preliminary work and there are bugs in the
16framework that need to be ironed out. Please report any issues
17to dtalayco@stanford.edu.
18
Dan Talayco80857c52010-05-05 10:14:05 -070019Introduction
20++++++++++++
21
22 This test framework is meant to exercise a candidate OpenFlow
23 switch (the device/switch under test, DUT or SUT). It provides a
24 connection like a controller to which the switch connects and it
25 controls data plane ports, sending and receiving packets, which
26 should be connected to the switch.
27
28 There are two parts to running the test framework:
29
30 * Building the python libraries that support the OF protocol
31 * Running oft, the main entry point of the test framework
32
33 Normally log output from oft is sent to the file oft.log, but
34 can be redirected to the console by specifying --log-file="".
35
Dan Talaycof7dae842010-02-19 11:50:02 -080036Quick Start
37+++++++++++
Dan Talaycoa85e5662010-04-16 09:35:30 -070038
39 Make sure your switch is running and trying to connect to a
40 controller on the machine where you're running oft (normally port
Dan Talayco80857c52010-05-05 10:14:05 -070041 6633). See below regarding run_switch.py for a script that starts
42 up a software switch on the test host.
Dan Talaycoa85e5662010-04-16 09:35:30 -070043
44 Currently, switches must be running version 1.0 of OpenFlow.
45
Dan Talayco80857c52010-05-05 10:14:05 -070046 # git clone yuba:/usr/local/git/openflow-projects/oftest
47 # cd oftest/tools/munger
48 # make install
49 # cd ../../tests
50 Make sure the switch you want to test is running
51 # ./oft --list
52 # sudo ./oft
53 # sudo ./oft --verbose --log-file=""
54 # sudo ./oft --test-spec=<mod> --platform=remote --host=...
Dan Talayco1ddefbf2010-03-07 21:56:47 -080055
56Longer Start
57++++++++++++
Dan Talaycof7dae842010-02-19 11:50:02 -080058
59 1. Pre-requisites:
Dan Talaycoa85e5662010-04-16 09:35:30 -070060 * An OF switch instance to test (see 4 below)
Dan Talayco80857c52010-05-05 10:14:05 -070061 * Root privilege on host running oft
62 * Switch running OpenFlow 1.0 and attempting to connect
63 to a controller on the machine running oft.
64 * Python 2.5. You can run platforms using eth interfaces
65 with Python 2.4.
66 * Python setup tools (e.g.: sudo apt-get install python-setuptools)
67 * oftest checked out (called <oftest> here)
Dan Talaycof7dae842010-02-19 11:50:02 -080068 * scapy installed: http://www.secdev.org/projects/scapy/
Dan Talayco80857c52010-05-05 10:14:05 -070069 'sudo apt-get install scapy' should work on Debian.
Dan Talaycoa85e5662010-04-16 09:35:30 -070070 * tcpdump installed (optional, but scapy will complain if it's
71 not there)
Dan Talaycof7dae842010-02-19 11:50:02 -080072 * Doxygen and doxypy for document generation (optional)
73 * lint for source checking (optional)
74
75 2. Build the OpenFlow Python message classes
Dan Talaycoc4747962010-02-19 12:29:17 -080076
77 Important: The OF version used by the controller is based on
78 the file in <oftest>/tools/pylibopenflow/include/openflow.h
79 This is currently the 1.0 release file.
80
Dan Talaycoa85e5662010-04-16 09:35:30 -070081 cd <oftest>/tools/munger
82 make install
Dan Talayco80857c52010-05-05 10:14:05 -070083
Dan Talayco1ddefbf2010-03-07 21:56:47 -080084 This places files in <oftest>/src/python/oftest/src and then
85 calls setuptools to install on the local host
Dan Talaycof7dae842010-02-19 11:50:02 -080086
Dan Talayco1ddefbf2010-03-07 21:56:47 -080087 3. Edit configuration if necessary
88 Local platforms work with veth interface pairs and default to
89 four ports. You can adjust this a bit with the command line
90 parameters port_count, base_of_port and base_if_index.
Dan Talayco80857c52010-05-05 10:14:05 -070091
Dan Talayco673e0852010-03-06 23:09:23 -080092 Starting from remote.py as a simple example, you can add your
93 own <platform>.py file and then have it imported with
Dan Talayco80857c52010-05-05 10:14:05 -070094 --platform=<platform> on the command line. This is meant to
95 allow you to test remote switches attempting to connect to a
96 controller on a network accessible to the test host.
Dan Talaycof7dae842010-02-19 11:50:02 -080097
Dan Talayco1ddefbf2010-03-07 21:56:47 -080098 4. Start the switch to test
Dan Talaycof7dae842010-02-19 11:50:02 -080099 The switch must be running and actively attempting to
Dan Talayco80857c52010-05-05 10:14:05 -0700100 connect to a controller on the test host at the port number
101 used by oft (6633 by default, or specified as --port=<n> as
102 an argument to oft).
Dan Talaycof7dae842010-02-19 11:50:02 -0800103
Dan Talaycoa85e5662010-04-16 09:35:30 -0700104 If you're new to the test environment and want to check its
105 sanity, you can do the following. This requires that
106 your host kernel supports virtual ethernet interfaces. This
107 is best done in a window separate from where you will run oft.
Dan Talayco80857c52010-05-05 10:14:05 -0700108
Dan Talaycoa85e5662010-04-16 09:35:30 -0700109 4A. Check out openflow (preferably at the same level as oftest):
110 git clone git://openflowswitch.org/openflow.git
111 4B. cd openflow; ./boot.sh; ./configure; make
112 4C. cd ../oftest/tests
113 4D. Run the switch startup script:
114 sudo ./run_switch.py; Now you can run oft (see below).
Dan Talayco80857c52010-05-05 10:14:05 -0700115 4F. Use --help to see command line switches. If you use a port
116 number other than the default, make sure you use the same
117 one for the switch as for oft.
Dan Talaycoa85e5662010-04-16 09:35:30 -0700118 4E. Use control-C to terminate the switch daemons.
119 4F. To clean up the virtual ethernet interfaces, use
120 sudo rmmod veth
121
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800122 5. Run oft
Dan Talayco673e0852010-03-06 23:09:23 -0800123 See Warning above; requires sudo to control the dataplane
Dan Talaycoa85e5662010-04-16 09:35:30 -0700124 cd <oftest>/tests
125 sudo ./oft --help
126
127OFT Command Line Options
128++++++++++++++++++++++++
129
130 Here is a summary of the oft command line options. Use --help to see
131 the long and short command option names.
132
133 platform : String identifying the target platform
134 controller_host : Host on which test controller is running (for sockets)
135 controller_port : Port on which test controller listens for switch cxn
136 port_count : Number of ports in dataplane
137 base_of_port : Base OpenFlow port number in dataplane
138 base_if_index : Base OS network interface for dataplane
139 test_dir : Directory to search for test files (default .)
140 test_spec : Specification of test(s) to run
141 log_file : Filename for test logging
142 list : Boolean: List all tests and exit
143 debug : String giving debug level (info, warning, error...)
144 verbose : Same as debug=verbose
Dan Talaycof7dae842010-02-19 11:50:02 -0800145
146Overview
147++++++++
148
149 The directory structure is currently:
150
151 <oftest>
152 `
153 |-- doc
154 |-- src
155 | `-- python
156 | `-- oftest
157 |-- tests
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800158 | `-- oft and files with test cases
Dan Talaycof7dae842010-02-19 11:50:02 -0800159 `-- tools
160 |-- munger
161 `-- pylibopenflow
162
163 The tools directory is what processes the OpenFlow header
164 files to produce Python classes representing OpenFlow messages.
165 The results are placed in src/python/oftest and currently
166 include:
167
168 message.py: The main API providing OF message classes
169 error.py: Subclasses for error messages
170 action.py: Subclasses for action specification
171 cstruct.py: Direct representation of C structures in Python
172 class_maps.py: Addition info about C structures
173
174 In addition, the following Python files are present in
175 src/python/oftest:
176
Dan Talaycof7dae842010-02-19 11:50:02 -0800177 controller.py: The controller representation
178 dataplane.py: The dataplane representation
179 action_list.py: Action list class
180 netutils.py: e.g., set promisc on sockets
181 ofutils.py: Utilities related to OpenFlow messages
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800182 oft_assert.py: Test framework level assertion
Dan Talaycof7dae842010-02-19 11:50:02 -0800183
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800184 Tests are run from the tests directory. The file oft is the
185 top level entry point for tests. Try ./oft --help for some more.
Dan Talaycof7dae842010-02-19 11:50:02 -0800186
Dan Talayco1ddefbf2010-03-07 21:56:47 -0800187Important Notes
188+++++++++++++++
189
190 1. If you edit any of the files in src/python/oftest or any of the
191 scripts in tools/munger/scripts, you MUST re-run make install. This
192 is easy to forget.
193
194 2. If your running into issues with transactions, and it appears that
195 OpenFlow messages aren't quite right, start by looking at any length
196 fields in the packets. With the local platform, you can use wireshark
197 on the loopback interface as well as the dataplane veth interfaces.
198
199Adding Your Own Test Cases
200++++++++++++++++++++++++++
201
202 You can:
203
204 * Add cases to an existing file
205 * Add a new file
206
207 If you add cases to an existing file, each case should be its own
208 class. It must inherit from unittest.TestCase or one of its
209 derivatives and define runTest (that's how test cases are discovered).
210
211 If you add a new file, it must implement a top level function called
212 test_set_init which takes a configuration dictionary. See basic.py
213 for an example. The main point of this is to pass the port map
214 object to the test cases. But you can access any configuration
215 parameters this way. Each test case in the new file must derive
216 from unittest.TestCase.
Dan Talaycof7dae842010-02-19 11:50:02 -0800217
Dan Talayco79f36082010-03-11 16:53:53 -0800218 CONVENTIONS:
219
220 The first line of the doc string for a file and for a test class is
221 displayed in the list command. Please keep it clear and under 50
222 characters.
223
Dan Talaycod2ca1032010-03-10 14:40:26 -0800224
225Using CentOS/RHEL
226+++++++++++++++++
227
228 CentOS/RHEL have two challenges: they are very tied to Python 2.4
229 (and Scapy requires Python 2.5 for its latest version) and they
230 require a kernel upgrade to use veth pairs for local platform
231 testing.
232
233 If you only need to control eth interfaces for a remote platform,
Dan Talaycofa16d592010-03-12 10:01:43 -0800234 you can use CentOS/RHEL without major disruption. The key is to
235 download scapy-1.2 from the following link:
Dan Talaycod2ca1032010-03-10 14:40:26 -0800236
237 wget http://hg.secdev.org/scapy/raw-file/v1.2.0.2/scapy.py
238
239 See: http://www.dirk-loss.de/scapy-doc/installation.html#installing-scapy-v1-2
240 for more info.
241
242 Copy scapy.py to /usr/lib/python2.4/site-packages
243
244 If you hit an error related to importing scapy.all, you just need
245 to change the import to refer to scapy (not scapy.all). See
246 examples in parse.py for example.
247
248
Dan Talaycof7dae842010-02-19 11:50:02 -0800249Other Info
250++++++++++
251
252 * Build doc with
253 + cd <oftest>/tools/munger
254 + make doc
255 Places the results in <oftest>/doc/html
256
257 * Run lint on sources
258 + cd <oftest>/tools/munger
259 + make lint
260 Places results in <oftest>/lint/*.log
261 The file controller.log currently has some errors indicated
262
263
264To Do
265+++++
266
Dan Talayco60a8d7a2010-03-03 15:20:59 -0800267 * Need to have an overview of the components of the test, how they
268 connect and how they are managed by the test framework.
Dan Talaycof7dae842010-02-19 11:50:02 -0800269 * See the Regression Test component on trac:
270 http://www.openflowswitch.org/bugs/openflow
271 http://www.openflowswitch.org/bugs/openflow/query?component=Regression+test+suite
272
Dan Talaycoc4747962010-02-19 12:29:17 -0800273 * Make the framework work with OF versions other than 1.0?
274