Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 1 | """ |
Dan Talayco | 79f3608 | 2010-03-11 16:53:53 -0800 | [diff] [blame] | 2 | Basic protocol and dataplane test cases |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 3 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 4 | It is recommended that these definitions be kept in their own |
| 5 | namespace as different groups of tests will likely define |
| 6 | similar identifiers. |
| 7 | |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 8 | Current Assumptions: |
| 9 | |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 10 | The function test_set_init is called with a complete configuration |
| 11 | dictionary prior to the invocation of any tests from this file. |
| 12 | |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 13 | The switch is actively attempting to contact the controller at the address |
| 14 | indicated oin oft_config |
| 15 | |
| 16 | """ |
| 17 | |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 18 | import time |
Dan Talayco | 710438c | 2010-02-18 15:16:07 -0800 | [diff] [blame] | 19 | import signal |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 20 | import sys |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 21 | import logging |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 22 | |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 23 | import unittest |
| 24 | |
| 25 | import oftest.controller as controller |
| 26 | import oftest.cstruct as ofp |
| 27 | import oftest.message as message |
| 28 | import oftest.dataplane as dataplane |
| 29 | import oftest.action as action |
| 30 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 31 | from testutils import * |
| 32 | |
| 33 | #@var basic_port_map Local copy of the configuration map from OF port |
| 34 | # numbers to OS interfaces |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 35 | basic_port_map = None |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 36 | #@var basic_logger Local logger object |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 37 | basic_logger = None |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 38 | #@var basic_config Local copy of global configuration data |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 39 | basic_config = None |
| 40 | |
Dan Talayco | c24aaae | 2010-07-08 14:05:24 -0700 | [diff] [blame] | 41 | test_prio = {} |
| 42 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 43 | def test_set_init(config): |
| 44 | """ |
| 45 | Set up function for basic test classes |
| 46 | |
| 47 | @param config The configuration dictionary; see oft |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 48 | """ |
| 49 | |
| 50 | global basic_port_map |
| 51 | global basic_logger |
| 52 | global basic_config |
| 53 | |
| 54 | basic_logger = logging.getLogger("basic") |
| 55 | basic_logger.info("Initializing test set") |
| 56 | basic_port_map = config["port_map"] |
| 57 | basic_config = config |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 58 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 59 | class SimpleProtocol(unittest.TestCase): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 60 | """ |
| 61 | Root class for setting up the controller |
| 62 | """ |
| 63 | |
Dan Talayco | ef701f4 | 2010-05-07 09:22:35 -0700 | [diff] [blame] | 64 | def sig_handler(self, v1, v2): |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 65 | basic_logger.critical("Received interrupt signal; exiting") |
Dan Talayco | 710438c | 2010-02-18 15:16:07 -0800 | [diff] [blame] | 66 | print "Received interrupt signal; exiting" |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 67 | self.clean_shutdown = False |
| 68 | self.tearDown() |
Dan Talayco | 710438c | 2010-02-18 15:16:07 -0800 | [diff] [blame] | 69 | sys.exit(1) |
| 70 | |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 71 | def setUp(self): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 72 | self.logger = basic_logger |
Dan Talayco | 285a838 | 2010-07-20 14:06:55 -0700 | [diff] [blame^] | 73 | self.config = basic_config |
Dan Talayco | 710438c | 2010-02-18 15:16:07 -0800 | [diff] [blame] | 74 | signal.signal(signal.SIGINT, self.sig_handler) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 75 | basic_logger.info("** START TEST CASE " + str(self)) |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 76 | self.controller = controller.Controller( |
| 77 | host=basic_config["controller_host"], |
| 78 | port=basic_config["controller_port"]) |
Dan Talayco | f8f4140 | 2010-03-12 22:17:39 -0800 | [diff] [blame] | 79 | # clean_shutdown should be set to False to force quit app |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 80 | self.clean_shutdown = True |
Dan Talayco | 710438c | 2010-02-18 15:16:07 -0800 | [diff] [blame] | 81 | self.controller.start() |
Dan Talayco | ef701f4 | 2010-05-07 09:22:35 -0700 | [diff] [blame] | 82 | #@todo Add an option to wait for a pkt transaction to ensure version |
| 83 | # compatibilty? |
Dan Talayco | 710438c | 2010-02-18 15:16:07 -0800 | [diff] [blame] | 84 | self.controller.connect(timeout=20) |
Dan Talayco | ef701f4 | 2010-05-07 09:22:35 -0700 | [diff] [blame] | 85 | if not self.controller.active: |
| 86 | print "Controller startup failed; exiting" |
| 87 | sys.exit(1) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 88 | basic_logger.info("Connected " + str(self.controller.switch_addr)) |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 89 | |
| 90 | def tearDown(self): |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 91 | basic_logger.info("** END TEST CASE " + str(self)) |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 92 | self.controller.shutdown() |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 93 | #@todo Review if join should be done on clean_shutdown |
Dan Talayco | f8f4140 | 2010-03-12 22:17:39 -0800 | [diff] [blame] | 94 | if self.clean_shutdown: |
| 95 | self.controller.join() |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 96 | |
| 97 | def runTest(self): |
Dan Talayco | 710438c | 2010-02-18 15:16:07 -0800 | [diff] [blame] | 98 | # Just a simple sanity check as illustration |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 99 | basic_logger.info("Running simple proto test") |
Dan Talayco | 710438c | 2010-02-18 15:16:07 -0800 | [diff] [blame] | 100 | self.assertTrue(self.controller.switch_socket is not None, |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 101 | str(self) + 'No connection to switch') |
| 102 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 103 | def assertTrue(self, cond, msg): |
| 104 | if not cond: |
| 105 | basic_logger.error("** FAILED ASSERTION: " + msg) |
| 106 | unittest.TestCase.assertTrue(self, cond, msg) |
| 107 | |
Dan Talayco | c24aaae | 2010-07-08 14:05:24 -0700 | [diff] [blame] | 108 | test_prio["SimpleProtocol"] = 1 |
| 109 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 110 | class SimpleDataPlane(SimpleProtocol): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 111 | """ |
| 112 | Root class that sets up the controller and dataplane |
| 113 | """ |
| 114 | def setUp(self): |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 115 | SimpleProtocol.setUp(self) |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 116 | self.dataplane = dataplane.DataPlane() |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 117 | for of_port, ifname in basic_port_map.items(): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 118 | self.dataplane.port_add(ifname, of_port) |
| 119 | |
| 120 | def tearDown(self): |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 121 | basic_logger.info("Teardown for simple dataplane test") |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 122 | SimpleProtocol.tearDown(self) |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 123 | self.dataplane.kill(join_threads=self.clean_shutdown) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 124 | basic_logger.info("Teardown done") |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 125 | |
| 126 | def runTest(self): |
Dan Talayco | 710438c | 2010-02-18 15:16:07 -0800 | [diff] [blame] | 127 | self.assertTrue(self.controller.switch_socket is not None, |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 128 | str(self) + 'No connection to switch') |
| 129 | # self.dataplane.show() |
| 130 | # Would like an assert that checks the data plane |
| 131 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 132 | class DataPlaneOnly(unittest.TestCase): |
| 133 | """ |
| 134 | Root class that sets up only the dataplane |
| 135 | """ |
| 136 | |
| 137 | def sig_handler(self, v1, v2): |
| 138 | basic_logger.critical("Received interrupt signal; exiting") |
| 139 | print "Received interrupt signal; exiting" |
| 140 | self.clean_shutdown = False |
| 141 | self.tearDown() |
| 142 | sys.exit(1) |
| 143 | |
| 144 | def setUp(self): |
| 145 | self.clean_shutdown = False |
| 146 | self.logger = basic_logger |
Dan Talayco | 285a838 | 2010-07-20 14:06:55 -0700 | [diff] [blame^] | 147 | self.config = basic_config |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 148 | signal.signal(signal.SIGINT, self.sig_handler) |
| 149 | basic_logger.info("** START DataPlaneOnly CASE " + str(self)) |
| 150 | self.dataplane = dataplane.DataPlane() |
| 151 | for of_port, ifname in basic_port_map.items(): |
| 152 | self.dataplane.port_add(ifname, of_port) |
| 153 | |
| 154 | def tearDown(self): |
| 155 | basic_logger.info("Teardown for simple dataplane test") |
| 156 | self.dataplane.kill(join_threads=self.clean_shutdown) |
| 157 | basic_logger.info("Teardown done") |
| 158 | |
| 159 | def runTest(self): |
Dan Talayco | 285a838 | 2010-07-20 14:06:55 -0700 | [diff] [blame^] | 160 | print "DataPlaneOnly" |
| 161 | # self.dataplane.show() |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 162 | # Would like an assert that checks the data plane |
| 163 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 164 | class Echo(SimpleProtocol): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 165 | """ |
| 166 | Test echo response with no data |
| 167 | """ |
| 168 | def runTest(self): |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 169 | request = message.echo_request() |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 170 | response, pkt = self.controller.transact(request) |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 171 | self.assertEqual(response.header.type, ofp.OFPT_ECHO_REPLY, |
Dan Talayco | a92e75b | 2010-02-16 20:53:56 -0800 | [diff] [blame] | 172 | 'response is not echo_reply') |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 173 | self.assertEqual(request.header.xid, response.header.xid, |
| 174 | 'response xid != request xid') |
| 175 | self.assertEqual(len(response.data), 0, 'response data non-empty') |
| 176 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 177 | class EchoWithData(SimpleProtocol): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 178 | """ |
| 179 | Test echo response with short string data |
| 180 | """ |
| 181 | def runTest(self): |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 182 | request = message.echo_request() |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 183 | request.data = 'OpenFlow Will Rule The World' |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 184 | response, pkt = self.controller.transact(request) |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 185 | self.assertEqual(response.header.type, ofp.OFPT_ECHO_REPLY, |
Dan Talayco | a92e75b | 2010-02-16 20:53:56 -0800 | [diff] [blame] | 186 | 'response is not echo_reply') |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 187 | self.assertEqual(request.header.xid, response.header.xid, |
| 188 | 'response xid != request xid') |
| 189 | self.assertEqual(request.data, response.data, |
| 190 | 'response data does not match request') |
| 191 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 192 | class PacketIn(SimpleDataPlane): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 193 | """ |
| 194 | Test packet in function |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 195 | |
| 196 | Send a packet to each dataplane port and verify that a packet |
| 197 | in message is received from the controller for each |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 198 | """ |
| 199 | def runTest(self): |
| 200 | # Construct packet to send to dataplane |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 201 | # Send packet to dataplane, once to each port |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 202 | # Poll controller with expect message type packet in |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 203 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 204 | rc = delete_all_flows(self.controller, basic_logger) |
| 205 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 206 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 207 | for of_port in basic_port_map.keys(): |
| 208 | basic_logger.info("PKT IN test, port " + str(of_port)) |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 209 | pkt = simple_tcp_packet() |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 210 | self.dataplane.send(of_port, str(pkt)) |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 211 | #@todo Check for unexpected messages? |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 212 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 213 | |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 214 | self.assertTrue(response is not None, |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 215 | 'Packet in message not received on port ' + |
| 216 | str(of_port)) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 217 | if str(pkt) != response.data: |
Dan Talayco | ef701f4 | 2010-05-07 09:22:35 -0700 | [diff] [blame] | 218 | basic_logger.debug("pkt len " + str(len(str(pkt))) + |
| 219 | ": " + str(pkt)) |
| 220 | basic_logger.debug("resp len " + |
| 221 | str(len(str(response.data))) + |
| 222 | ": " + str(response.data)) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 223 | |
| 224 | self.assertEqual(str(pkt), response.data, |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 225 | 'Response packet does not match send packet' + |
| 226 | ' for port ' + str(of_port)) |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 227 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 228 | class PacketOut(SimpleDataPlane): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 229 | """ |
| 230 | Test packet out function |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 231 | |
| 232 | Send packet out message to controller for each dataplane port and |
| 233 | verify the packet appears on the appropriate dataplane port |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 234 | """ |
| 235 | def runTest(self): |
| 236 | # Construct packet to send to dataplane |
| 237 | # Send packet to dataplane |
| 238 | # Poll controller with expect message type packet in |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 239 | |
| 240 | rc = delete_all_flows(self.controller, basic_logger) |
| 241 | self.assertEqual(rc, 0, "Failed to delete all flows") |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 242 | |
| 243 | # These will get put into function |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 244 | outpkt = simple_tcp_packet() |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 245 | of_ports = basic_port_map.keys() |
| 246 | of_ports.sort() |
| 247 | for dp_port in of_ports: |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 248 | msg = message.packet_out() |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 249 | msg.data = str(outpkt) |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 250 | act = action.action_output() |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 251 | act.port = dp_port |
| 252 | self.assertTrue(msg.actions.add(act), 'Could not add action to msg') |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 253 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 254 | basic_logger.info("PacketOut to: " + str(dp_port)) |
| 255 | rv = self.controller.message_send(msg) |
| 256 | self.assertTrue(rv == 0, "Error sending out message") |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 257 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 258 | (of_port, pkt, pkt_time) = self.dataplane.poll(timeout=1) |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 259 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 260 | self.assertTrue(pkt is not None, 'Packet not received') |
| 261 | basic_logger.info("PacketOut: got pkt from " + str(of_port)) |
| 262 | if of_port is not None: |
| 263 | self.assertEqual(of_port, dp_port, "Unexpected receive port") |
| 264 | self.assertEqual(str(outpkt), str(pkt), |
| 265 | 'Response packet does not match send packet') |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 266 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 267 | class FlowStatsGet(SimpleProtocol): |
| 268 | """ |
| 269 | Get stats |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 270 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 271 | Simply verify stats get transaction |
| 272 | """ |
| 273 | def runTest(self): |
| 274 | basic_logger.info("Running StatsGet") |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 275 | basic_logger.info("Inserting trial flow") |
| 276 | request = message.flow_mod() |
| 277 | request.match.wildcards = ofp.OFPFW_ALL |
| 278 | request.buffer_id = 0xffffffff |
| 279 | rv = self.controller.message_send(request) |
| 280 | self.assertTrue(rv != -1, "Failed to insert test flow") |
| 281 | |
| 282 | basic_logger.info("Sending flow request") |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 283 | request = message.flow_stats_request() |
| 284 | request.out_port = ofp.OFPP_NONE |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 285 | request.table_id = 0xff |
| 286 | request.match.wildcards = 0 # ofp.OFPFW_ALL |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 287 | response, pkt = self.controller.transact(request, timeout=2) |
| 288 | self.assertTrue(response is not None, "Did not get response") |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 289 | basic_logger.debug(response.show()) |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 290 | |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 291 | class TableStatsGet(SimpleProtocol): |
| 292 | """ |
| 293 | Get table stats |
| 294 | |
| 295 | Simply verify table stats get transaction |
| 296 | """ |
| 297 | def runTest(self): |
| 298 | basic_logger.info("Running TableStatsGet") |
| 299 | basic_logger.info("Inserting trial flow") |
| 300 | request = message.flow_mod() |
| 301 | request.match.wildcards = ofp.OFPFW_ALL |
| 302 | request.buffer_id = 0xffffffff |
| 303 | rv = self.controller.message_send(request) |
| 304 | self.assertTrue(rv != -1, "Failed to insert test flow") |
| 305 | |
| 306 | basic_logger.info("Sending table stats request") |
| 307 | request = message.table_stats_request() |
| 308 | response, pkt = self.controller.transact(request, timeout=2) |
| 309 | self.assertTrue(response is not None, "Did not get response") |
| 310 | basic_logger.debug(response.show()) |
| 311 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 312 | class FlowMod(SimpleProtocol): |
| 313 | """ |
| 314 | Insert a flow |
| 315 | |
| 316 | Simple verification of a flow mod transaction |
| 317 | """ |
| 318 | |
| 319 | def runTest(self): |
| 320 | basic_logger.info("Running " + str(self)) |
| 321 | request = message.flow_mod() |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 322 | request.match.wildcards = ofp.OFPFW_ALL |
| 323 | request.buffer_id = 0xffffffff |
| 324 | rv = self.controller.message_send(request) |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 325 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 326 | |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 327 | class PortConfigMod(SimpleProtocol): |
| 328 | """ |
| 329 | Modify a bit in port config and verify changed |
| 330 | |
| 331 | Get the switch configuration, modify the port configuration |
| 332 | and write it back; get the config again and verify changed. |
| 333 | Then set it back to the way it was. |
| 334 | """ |
| 335 | |
| 336 | def runTest(self): |
| 337 | basic_logger.info("Running " + str(self)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 338 | for of_port, ifname in basic_port_map.items(): # Grab first port |
| 339 | break |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 340 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 341 | (hw_addr, config, advert) = \ |
| 342 | port_config_get(self.controller, of_port, basic_logger) |
| 343 | self.assertTrue(config is not None, "Did not get port config") |
| 344 | |
| 345 | basic_logger.debug("No flood bit port " + str(of_port) + " is now " + |
| 346 | str(config & ofp.OFPPC_NO_FLOOD)) |
| 347 | |
| 348 | rv = port_config_set(self.controller, of_port, |
| 349 | config ^ ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD, |
| 350 | basic_logger) |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 351 | self.assertTrue(rv != -1, "Error sending port mod") |
| 352 | |
| 353 | # Verify change took place with same feature request |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 354 | (hw_addr, config2, advert) = \ |
| 355 | port_config_get(self.controller, of_port, basic_logger) |
| 356 | basic_logger.debug("No flood bit port " + str(of_port) + " is now " + |
| 357 | str(config2 & ofp.OFPPC_NO_FLOOD)) |
| 358 | self.assertTrue(config2 is not None, "Did not get port config2") |
| 359 | self.assertTrue(config2 & ofp.OFPPC_NO_FLOOD != |
| 360 | config & ofp.OFPPC_NO_FLOOD, |
| 361 | "Bit change did not take") |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 362 | # Set it back |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 363 | rv = port_config_set(self.controller, of_port, config, |
| 364 | ofp.OFPPC_NO_FLOOD, basic_logger) |
| 365 | self.assertTrue(rv != -1, "Error sending port mod") |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 366 | |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 367 | if __name__ == "__main__": |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 368 | print "Please run through oft script: ./oft --test_spec=basic" |