Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 1 | OpenFlow Testing Framework |
Dan Talayco | 79f3608 | 2010-03-11 16:53:53 -0800 | [diff] [blame] | 2 | March, 2010 |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 3 | |
| 4 | Warning |
| 5 | +++++++ |
| 6 | |
| 7 | This is still experimental and it requires root privilege to |
| 8 | control the dataplane ports. As a consequence, there are |
| 9 | some serious risks to the machine on which this is running. |
| 10 | Use caution. |
| 11 | |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 12 | This is still preliminary work and there are bugs in the |
| 13 | framework that need to be ironed out. Please report any issues |
| 14 | to dtalayco@stanford.edu. |
| 15 | |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 16 | Quick Start |
| 17 | +++++++++++ |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame^] | 18 | |
| 19 | Make sure your switch is running and trying to connect to a |
| 20 | controller on the machine where you're running oft (normally port |
| 21 | 6633). (We plan to add a script for the simple case of the SW |
| 22 | switch running on the same host.) |
| 23 | |
| 24 | Currently, switches must be running version 1.0 of OpenFlow. |
| 25 | |
| 26 | git clone yuba:/usr/local/git/openflow-projects/oftest |
| 27 | cd <oftest>/tools/munger |
| 28 | make install |
| 29 | cd ../../tests |
| 30 | <start your OF switch to test> |
| 31 | ./oft --list |
| 32 | sudo ./oft --verbose --log-file="" |
| 33 | sudo ./oft --test-spec=<mod> --debug=info --platform=remote --host=... |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 34 | |
| 35 | Longer Start |
| 36 | ++++++++++++ |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 37 | |
| 38 | 1. Pre-requisites: |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame^] | 39 | * An OF switch instance to test (see 4 below) |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 40 | * Root privilege on host |
Dan Talayco | d2ca103 | 2010-03-10 14:40:26 -0800 | [diff] [blame] | 41 | * Python 2.5. You can run platforms using eth interfaces with |
| 42 | Python 2.4. |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame^] | 43 | * oftest checked out (to a directory called <oftest> here) |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 44 | * scapy installed: http://www.secdev.org/projects/scapy/ |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame^] | 45 | * tcpdump installed (optional, but scapy will complain if it's |
| 46 | not there) |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 47 | * Doxygen and doxypy for document generation (optional) |
| 48 | * lint for source checking (optional) |
| 49 | |
| 50 | 2. Build the OpenFlow Python message classes |
Dan Talayco | c474796 | 2010-02-19 12:29:17 -0800 | [diff] [blame] | 51 | |
| 52 | Important: The OF version used by the controller is based on |
| 53 | the file in <oftest>/tools/pylibopenflow/include/openflow.h |
| 54 | This is currently the 1.0 release file. |
| 55 | |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame^] | 56 | cd <oftest>/tools/munger |
| 57 | make install |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 58 | This places files in <oftest>/src/python/oftest/src and then |
| 59 | calls setuptools to install on the local host |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 60 | |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 61 | 3. Edit configuration if necessary |
| 62 | Local platforms work with veth interface pairs and default to |
| 63 | four ports. You can adjust this a bit with the command line |
| 64 | parameters port_count, base_of_port and base_if_index. |
| 65 | |
Dan Talayco | 673e085 | 2010-03-06 23:09:23 -0800 | [diff] [blame] | 66 | Starting from remote.py as a simple example, you can add your |
| 67 | own <platform>.py file and then have it imported with |
| 68 | --platform=<platform> on the command line. |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 69 | |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 70 | 4. Start the switch to test |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 71 | The switch must be running and actively attempting to |
| 72 | connect to the controller at the host/port specified above. |
| 73 | |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame^] | 74 | If you're new to the test environment and want to check its |
| 75 | sanity, you can do the following. This requires that |
| 76 | your host kernel supports virtual ethernet interfaces. This |
| 77 | is best done in a window separate from where you will run oft. |
| 78 | |
| 79 | 4A. Check out openflow (preferably at the same level as oftest): |
| 80 | git clone git://openflowswitch.org/openflow.git |
| 81 | 4B. cd openflow; ./boot.sh; ./configure; make |
| 82 | 4C. cd ../oftest/tests |
| 83 | 4D. Run the switch startup script: |
| 84 | sudo ./run_switch.py; Now you can run oft (see below). |
| 85 | 4F. Use --help to see command line switches. Make sure you |
| 86 | use the same port for the switch as for oft. |
| 87 | 4E. Use control-C to terminate the switch daemons. |
| 88 | 4F. To clean up the virtual ethernet interfaces, use |
| 89 | sudo rmmod veth |
| 90 | |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 91 | 5. Run oft |
Dan Talayco | 673e085 | 2010-03-06 23:09:23 -0800 | [diff] [blame] | 92 | See Warning above; requires sudo to control the dataplane |
Dan Talayco | a85e566 | 2010-04-16 09:35:30 -0700 | [diff] [blame^] | 93 | cd <oftest>/tests |
| 94 | sudo ./oft --help |
| 95 | |
| 96 | OFT Command Line Options |
| 97 | ++++++++++++++++++++++++ |
| 98 | |
| 99 | Here is a summary of the oft command line options. Use --help to see |
| 100 | the long and short command option names. |
| 101 | |
| 102 | platform : String identifying the target platform |
| 103 | controller_host : Host on which test controller is running (for sockets) |
| 104 | controller_port : Port on which test controller listens for switch cxn |
| 105 | port_count : Number of ports in dataplane |
| 106 | base_of_port : Base OpenFlow port number in dataplane |
| 107 | base_if_index : Base OS network interface for dataplane |
| 108 | test_dir : Directory to search for test files (default .) |
| 109 | test_spec : Specification of test(s) to run |
| 110 | log_file : Filename for test logging |
| 111 | list : Boolean: List all tests and exit |
| 112 | debug : String giving debug level (info, warning, error...) |
| 113 | verbose : Same as debug=verbose |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 114 | |
| 115 | Overview |
| 116 | ++++++++ |
| 117 | |
| 118 | The directory structure is currently: |
| 119 | |
| 120 | <oftest> |
| 121 | ` |
| 122 | |-- doc |
| 123 | |-- src |
| 124 | | `-- python |
| 125 | | `-- oftest |
| 126 | |-- tests |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 127 | | `-- oft and files with test cases |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 128 | `-- tools |
| 129 | |-- munger |
| 130 | `-- pylibopenflow |
| 131 | |
| 132 | The tools directory is what processes the OpenFlow header |
| 133 | files to produce Python classes representing OpenFlow messages. |
| 134 | The results are placed in src/python/oftest and currently |
| 135 | include: |
| 136 | |
| 137 | message.py: The main API providing OF message classes |
| 138 | error.py: Subclasses for error messages |
| 139 | action.py: Subclasses for action specification |
| 140 | cstruct.py: Direct representation of C structures in Python |
| 141 | class_maps.py: Addition info about C structures |
| 142 | |
| 143 | In addition, the following Python files are present in |
| 144 | src/python/oftest: |
| 145 | |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 146 | controller.py: The controller representation |
| 147 | dataplane.py: The dataplane representation |
| 148 | action_list.py: Action list class |
| 149 | netutils.py: e.g., set promisc on sockets |
| 150 | ofutils.py: Utilities related to OpenFlow messages |
Dan Talayco | 60a8d7a | 2010-03-03 15:20:59 -0800 | [diff] [blame] | 151 | oft_assert.py: Test framework level assertion |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 152 | |
Dan Talayco | 60a8d7a | 2010-03-03 15:20:59 -0800 | [diff] [blame] | 153 | Tests are run from the tests directory. The file oft is the |
| 154 | top level entry point for tests. Try ./oft --help for some more. |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 155 | |
Dan Talayco | 1ddefbf | 2010-03-07 21:56:47 -0800 | [diff] [blame] | 156 | Important Notes |
| 157 | +++++++++++++++ |
| 158 | |
| 159 | 1. If you edit any of the files in src/python/oftest or any of the |
| 160 | scripts in tools/munger/scripts, you MUST re-run make install. This |
| 161 | is easy to forget. |
| 162 | |
| 163 | 2. If your running into issues with transactions, and it appears that |
| 164 | OpenFlow messages aren't quite right, start by looking at any length |
| 165 | fields in the packets. With the local platform, you can use wireshark |
| 166 | on the loopback interface as well as the dataplane veth interfaces. |
| 167 | |
| 168 | Adding Your Own Test Cases |
| 169 | ++++++++++++++++++++++++++ |
| 170 | |
| 171 | You can: |
| 172 | |
| 173 | * Add cases to an existing file |
| 174 | * Add a new file |
| 175 | |
| 176 | If you add cases to an existing file, each case should be its own |
| 177 | class. It must inherit from unittest.TestCase or one of its |
| 178 | derivatives and define runTest (that's how test cases are discovered). |
| 179 | |
| 180 | If you add a new file, it must implement a top level function called |
| 181 | test_set_init which takes a configuration dictionary. See basic.py |
| 182 | for an example. The main point of this is to pass the port map |
| 183 | object to the test cases. But you can access any configuration |
| 184 | parameters this way. Each test case in the new file must derive |
| 185 | from unittest.TestCase. |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 186 | |
Dan Talayco | 79f3608 | 2010-03-11 16:53:53 -0800 | [diff] [blame] | 187 | CONVENTIONS: |
| 188 | |
| 189 | The first line of the doc string for a file and for a test class is |
| 190 | displayed in the list command. Please keep it clear and under 50 |
| 191 | characters. |
| 192 | |
Dan Talayco | d2ca103 | 2010-03-10 14:40:26 -0800 | [diff] [blame] | 193 | |
| 194 | Using CentOS/RHEL |
| 195 | +++++++++++++++++ |
| 196 | |
| 197 | CentOS/RHEL have two challenges: they are very tied to Python 2.4 |
| 198 | (and Scapy requires Python 2.5 for its latest version) and they |
| 199 | require a kernel upgrade to use veth pairs for local platform |
| 200 | testing. |
| 201 | |
| 202 | If you only need to control eth interfaces for a remote platform, |
Dan Talayco | fa16d59 | 2010-03-12 10:01:43 -0800 | [diff] [blame] | 203 | you can use CentOS/RHEL without major disruption. The key is to |
| 204 | download scapy-1.2 from the following link: |
Dan Talayco | d2ca103 | 2010-03-10 14:40:26 -0800 | [diff] [blame] | 205 | |
| 206 | wget http://hg.secdev.org/scapy/raw-file/v1.2.0.2/scapy.py |
| 207 | |
| 208 | See: http://www.dirk-loss.de/scapy-doc/installation.html#installing-scapy-v1-2 |
| 209 | for more info. |
| 210 | |
| 211 | Copy scapy.py to /usr/lib/python2.4/site-packages |
| 212 | |
| 213 | If you hit an error related to importing scapy.all, you just need |
| 214 | to change the import to refer to scapy (not scapy.all). See |
| 215 | examples in parse.py for example. |
| 216 | |
| 217 | |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 218 | Other Info |
| 219 | ++++++++++ |
| 220 | |
| 221 | * Build doc with |
| 222 | + cd <oftest>/tools/munger |
| 223 | + make doc |
| 224 | Places the results in <oftest>/doc/html |
| 225 | |
| 226 | * Run lint on sources |
| 227 | + cd <oftest>/tools/munger |
| 228 | + make lint |
| 229 | Places results in <oftest>/lint/*.log |
| 230 | The file controller.log currently has some errors indicated |
| 231 | |
| 232 | |
| 233 | To Do |
| 234 | +++++ |
| 235 | |
Dan Talayco | 60a8d7a | 2010-03-03 15:20:59 -0800 | [diff] [blame] | 236 | * Need to have an overview of the components of the test, how they |
| 237 | connect and how they are managed by the test framework. |
Dan Talayco | f7dae84 | 2010-02-19 11:50:02 -0800 | [diff] [blame] | 238 | * See the Regression Test component on trac: |
| 239 | http://www.openflowswitch.org/bugs/openflow |
| 240 | http://www.openflowswitch.org/bugs/openflow/query?component=Regression+test+suite |
| 241 | |
Dan Talayco | c474796 | 2010-02-19 12:29:17 -0800 | [diff] [blame] | 242 | * Make the framework work with OF versions other than 1.0? |
| 243 | |