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