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 | 677c0b7 | 2011-08-23 22:53:38 -0700 | [diff] [blame] | 88 | if self.controller.switch_addr is None: |
| 89 | print "Controller startup failed (no switch addr); exiting" |
| 90 | sys.exit(1) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 91 | basic_logger.info("Connected " + str(self.controller.switch_addr)) |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 92 | |
| 93 | def tearDown(self): |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 94 | basic_logger.info("** END TEST CASE " + str(self)) |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 95 | self.controller.shutdown() |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 96 | #@todo Review if join should be done on clean_shutdown |
Dan Talayco | f8f4140 | 2010-03-12 22:17:39 -0800 | [diff] [blame] | 97 | if self.clean_shutdown: |
| 98 | self.controller.join() |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 99 | |
| 100 | def runTest(self): |
Dan Talayco | 710438c | 2010-02-18 15:16:07 -0800 | [diff] [blame] | 101 | # Just a simple sanity check as illustration |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 102 | basic_logger.info("Running simple proto test") |
Dan Talayco | 710438c | 2010-02-18 15:16:07 -0800 | [diff] [blame] | 103 | self.assertTrue(self.controller.switch_socket is not None, |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 104 | str(self) + 'No connection to switch') |
| 105 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 106 | def assertTrue(self, cond, msg): |
| 107 | if not cond: |
| 108 | basic_logger.error("** FAILED ASSERTION: " + msg) |
| 109 | unittest.TestCase.assertTrue(self, cond, msg) |
| 110 | |
Dan Talayco | c24aaae | 2010-07-08 14:05:24 -0700 | [diff] [blame] | 111 | test_prio["SimpleProtocol"] = 1 |
| 112 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 113 | class SimpleDataPlane(SimpleProtocol): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 114 | """ |
| 115 | Root class that sets up the controller and dataplane |
| 116 | """ |
| 117 | def setUp(self): |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 118 | SimpleProtocol.setUp(self) |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 119 | self.dataplane = dataplane.DataPlane() |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 120 | for of_port, ifname in basic_port_map.items(): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 121 | self.dataplane.port_add(ifname, of_port) |
| 122 | |
| 123 | def tearDown(self): |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 124 | basic_logger.info("Teardown for simple dataplane test") |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 125 | SimpleProtocol.tearDown(self) |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 126 | self.dataplane.kill(join_threads=self.clean_shutdown) |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 127 | basic_logger.info("Teardown done") |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 128 | |
| 129 | def runTest(self): |
Dan Talayco | 710438c | 2010-02-18 15:16:07 -0800 | [diff] [blame] | 130 | self.assertTrue(self.controller.switch_socket is not None, |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 131 | str(self) + 'No connection to switch') |
| 132 | # self.dataplane.show() |
| 133 | # Would like an assert that checks the data plane |
| 134 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 135 | class DataPlaneOnly(unittest.TestCase): |
| 136 | """ |
| 137 | Root class that sets up only the dataplane |
| 138 | """ |
| 139 | |
| 140 | def sig_handler(self, v1, v2): |
| 141 | basic_logger.critical("Received interrupt signal; exiting") |
| 142 | print "Received interrupt signal; exiting" |
| 143 | self.clean_shutdown = False |
| 144 | self.tearDown() |
| 145 | sys.exit(1) |
| 146 | |
| 147 | def setUp(self): |
| 148 | self.clean_shutdown = False |
| 149 | self.logger = basic_logger |
Dan Talayco | 285a838 | 2010-07-20 14:06:55 -0700 | [diff] [blame] | 150 | self.config = basic_config |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 151 | signal.signal(signal.SIGINT, self.sig_handler) |
| 152 | basic_logger.info("** START DataPlaneOnly CASE " + str(self)) |
| 153 | self.dataplane = dataplane.DataPlane() |
| 154 | for of_port, ifname in basic_port_map.items(): |
| 155 | self.dataplane.port_add(ifname, of_port) |
| 156 | |
| 157 | def tearDown(self): |
| 158 | basic_logger.info("Teardown for simple dataplane test") |
| 159 | self.dataplane.kill(join_threads=self.clean_shutdown) |
| 160 | basic_logger.info("Teardown done") |
| 161 | |
| 162 | def runTest(self): |
Dan Talayco | ba4fd4f | 2010-07-21 21:49:41 -0700 | [diff] [blame] | 163 | basic_logger.info("DataPlaneOnly") |
Dan Talayco | 285a838 | 2010-07-20 14:06:55 -0700 | [diff] [blame] | 164 | # self.dataplane.show() |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 165 | # Would like an assert that checks the data plane |
| 166 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 167 | class Echo(SimpleProtocol): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 168 | """ |
| 169 | Test echo response with no data |
| 170 | """ |
| 171 | def runTest(self): |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 172 | request = message.echo_request() |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 173 | response, pkt = self.controller.transact(request) |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 174 | self.assertEqual(response.header.type, ofp.OFPT_ECHO_REPLY, |
Dan Talayco | a92e75b | 2010-02-16 20:53:56 -0800 | [diff] [blame] | 175 | 'response is not echo_reply') |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 176 | self.assertEqual(request.header.xid, response.header.xid, |
| 177 | 'response xid != request xid') |
| 178 | self.assertEqual(len(response.data), 0, 'response data non-empty') |
| 179 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 180 | class EchoWithData(SimpleProtocol): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 181 | """ |
| 182 | Test echo response with short string data |
| 183 | """ |
| 184 | def runTest(self): |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 185 | request = message.echo_request() |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 186 | request.data = 'OpenFlow Will Rule The World' |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 187 | response, pkt = self.controller.transact(request) |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 188 | self.assertEqual(response.header.type, ofp.OFPT_ECHO_REPLY, |
Dan Talayco | a92e75b | 2010-02-16 20:53:56 -0800 | [diff] [blame] | 189 | 'response is not echo_reply') |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 190 | self.assertEqual(request.header.xid, response.header.xid, |
| 191 | 'response xid != request xid') |
| 192 | self.assertEqual(request.data, response.data, |
| 193 | 'response data does not match request') |
| 194 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 195 | class PacketIn(SimpleDataPlane): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 196 | """ |
| 197 | Test packet in function |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 198 | |
| 199 | Send a packet to each dataplane port and verify that a packet |
| 200 | in message is received from the controller for each |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 201 | """ |
| 202 | def runTest(self): |
| 203 | # Construct packet to send to dataplane |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 204 | # Send packet to dataplane, once to each port |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 205 | # Poll controller with expect message type packet in |
Dan Talayco | e226eb1 | 2010-02-18 23:06:30 -0800 | [diff] [blame] | 206 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 207 | rc = delete_all_flows(self.controller, basic_logger) |
| 208 | self.assertEqual(rc, 0, "Failed to delete all flows") |
Ed Swierk | 0caeb1e | 2012-03-19 15:01:56 -0700 | [diff] [blame] | 209 | do_barrier(self.controller) |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 210 | |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 211 | for of_port in basic_port_map.keys(): |
Ed Swierk | 0aeff8c | 2012-03-23 20:27:18 -0700 | [diff] [blame^] | 212 | for pkt, pt in [ |
| 213 | (simple_tcp_packet(), "simple TCP packet"), |
| 214 | (simple_eth_packet(), "simple Ethernet packet"), |
| 215 | (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]: |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 216 | |
Ed Swierk | 0aeff8c | 2012-03-23 20:27:18 -0700 | [diff] [blame^] | 217 | basic_logger.info("PKT IN test with %s, port %s" % (pt, of_port)) |
| 218 | self.dataplane.send(of_port, str(pkt)) |
| 219 | #@todo Check for unexpected messages? |
| 220 | count = 0 |
| 221 | while True: |
| 222 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) |
| 223 | if not response: # Timeout |
| 224 | break |
| 225 | if str(pkt) == response.data[:len(str(pkt))]: # Got match |
| 226 | break |
| 227 | if not basic_config["relax"]: # Only one attempt to match |
| 228 | break |
| 229 | count += 1 |
| 230 | if count > 10: # Too many tries |
| 231 | break |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 232 | |
Ed Swierk | 0aeff8c | 2012-03-23 20:27:18 -0700 | [diff] [blame^] | 233 | self.assertTrue(response is not None, |
| 234 | 'Packet in message not received on port ' + |
| 235 | str(of_port)) |
| 236 | if str(pkt) != response.data[:len(str(pkt))]: |
| 237 | basic_logger.debug("pkt len " + str(len(str(pkt))) + |
| 238 | ": " + str(pkt)) |
| 239 | basic_logger.debug("resp len " + |
| 240 | str(len(str(response.data))) + |
| 241 | ": " + str(response.data)) |
| 242 | self.assertTrue(False, |
| 243 | 'Response packet does not match send packet' + |
| 244 | ' for port ' + str(of_port)) |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 245 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 246 | class PacketOut(SimpleDataPlane): |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 247 | """ |
| 248 | Test packet out function |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 249 | |
| 250 | Send packet out message to controller for each dataplane port and |
| 251 | verify the packet appears on the appropriate dataplane port |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 252 | """ |
| 253 | def runTest(self): |
| 254 | # Construct packet to send to dataplane |
| 255 | # Send packet to dataplane |
| 256 | # Poll controller with expect message type packet in |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 257 | |
| 258 | rc = delete_all_flows(self.controller, basic_logger) |
| 259 | self.assertEqual(rc, 0, "Failed to delete all flows") |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 260 | |
| 261 | # These will get put into function |
Dan Talayco | 4837010 | 2010-03-03 15:17:33 -0800 | [diff] [blame] | 262 | of_ports = basic_port_map.keys() |
| 263 | of_ports.sort() |
| 264 | for dp_port in of_ports: |
Ed Swierk | 0aeff8c | 2012-03-23 20:27:18 -0700 | [diff] [blame^] | 265 | for outpkt, opt in [ |
| 266 | (simple_tcp_packet(), "simple TCP packet"), |
| 267 | (simple_eth_packet(), "simple Ethernet packet"), |
| 268 | (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]: |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 269 | |
Ed Swierk | 0aeff8c | 2012-03-23 20:27:18 -0700 | [diff] [blame^] | 270 | basic_logger.info("PKT OUT test with %s, port %s" % (opt, dp_port)) |
| 271 | msg = message.packet_out() |
| 272 | msg.data = str(outpkt) |
| 273 | act = action.action_output() |
| 274 | act.port = dp_port |
| 275 | self.assertTrue(msg.actions.add(act), 'Could not add action to msg') |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 276 | |
Ed Swierk | 0aeff8c | 2012-03-23 20:27:18 -0700 | [diff] [blame^] | 277 | basic_logger.info("PacketOut to: " + str(dp_port)) |
| 278 | rv = self.controller.message_send(msg) |
| 279 | self.assertTrue(rv == 0, "Error sending out message") |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 280 | |
Ed Swierk | 0aeff8c | 2012-03-23 20:27:18 -0700 | [diff] [blame^] | 281 | exp_pkt_arg = None |
| 282 | exp_port = None |
| 283 | if basic_config["relax"]: |
| 284 | exp_pkt_arg = outpkt |
| 285 | exp_port = dp_port |
| 286 | (of_port, pkt, pkt_time) = self.dataplane.poll(timeout=1, |
| 287 | port_number=exp_port, |
| 288 | exp_pkt=exp_pkt_arg) |
| 289 | |
| 290 | self.assertTrue(pkt is not None, 'Packet not received') |
| 291 | basic_logger.info("PacketOut: got pkt from " + str(of_port)) |
| 292 | if of_port is not None: |
| 293 | self.assertEqual(of_port, dp_port, "Unexpected receive port") |
| 294 | self.assertEqual(str(outpkt), str(pkt)[:len(str(outpkt))], |
| 295 | 'Response packet does not match send packet') |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 296 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 297 | class FlowStatsGet(SimpleProtocol): |
| 298 | """ |
| 299 | Get stats |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 300 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 301 | Simply verify stats get transaction |
| 302 | """ |
| 303 | def runTest(self): |
| 304 | basic_logger.info("Running StatsGet") |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 305 | basic_logger.info("Inserting trial flow") |
Dan Talayco | 677c0b7 | 2011-08-23 22:53:38 -0700 | [diff] [blame] | 306 | request = flow_mod_gen(basic_port_map, True) |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 307 | rv = self.controller.message_send(request) |
| 308 | self.assertTrue(rv != -1, "Failed to insert test flow") |
| 309 | |
| 310 | basic_logger.info("Sending flow request") |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 311 | request = message.flow_stats_request() |
| 312 | request.out_port = ofp.OFPP_NONE |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 313 | request.table_id = 0xff |
| 314 | request.match.wildcards = 0 # ofp.OFPFW_ALL |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 315 | response, pkt = self.controller.transact(request, timeout=2) |
| 316 | self.assertTrue(response is not None, "Did not get response") |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 317 | basic_logger.debug(response.show()) |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 318 | |
Dan Talayco | 677c0b7 | 2011-08-23 22:53:38 -0700 | [diff] [blame] | 319 | test_prio["FlowStatsGet"] = -1 |
| 320 | |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 321 | class TableStatsGet(SimpleProtocol): |
| 322 | """ |
| 323 | Get table stats |
| 324 | |
| 325 | Simply verify table stats get transaction |
| 326 | """ |
| 327 | def runTest(self): |
| 328 | basic_logger.info("Running TableStatsGet") |
| 329 | basic_logger.info("Inserting trial flow") |
Dan Talayco | 677c0b7 | 2011-08-23 22:53:38 -0700 | [diff] [blame] | 330 | request = flow_mod_gen(basic_port_map, True) |
Dan Talayco | 79c6c4d | 2010-06-08 14:01:53 -0700 | [diff] [blame] | 331 | rv = self.controller.message_send(request) |
| 332 | self.assertTrue(rv != -1, "Failed to insert test flow") |
| 333 | |
| 334 | basic_logger.info("Sending table stats request") |
| 335 | request = message.table_stats_request() |
| 336 | response, pkt = self.controller.transact(request, timeout=2) |
| 337 | self.assertTrue(response is not None, "Did not get response") |
| 338 | basic_logger.debug(response.show()) |
| 339 | |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 340 | class FlowMod(SimpleProtocol): |
| 341 | """ |
| 342 | Insert a flow |
| 343 | |
| 344 | Simple verification of a flow mod transaction |
| 345 | """ |
| 346 | |
| 347 | def runTest(self): |
| 348 | basic_logger.info("Running " + str(self)) |
Dan Talayco | 677c0b7 | 2011-08-23 22:53:38 -0700 | [diff] [blame] | 349 | request = flow_mod_gen(basic_port_map, True) |
Dan Talayco | 6ce963a | 2010-03-07 21:58:13 -0800 | [diff] [blame] | 350 | rv = self.controller.message_send(request) |
Dan Talayco | 41eae8b | 2010-03-10 13:57:06 -0800 | [diff] [blame] | 351 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 352 | |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 353 | class PortConfigMod(SimpleProtocol): |
| 354 | """ |
| 355 | Modify a bit in port config and verify changed |
| 356 | |
| 357 | Get the switch configuration, modify the port configuration |
| 358 | and write it back; get the config again and verify changed. |
| 359 | Then set it back to the way it was. |
| 360 | """ |
| 361 | |
| 362 | def runTest(self): |
| 363 | basic_logger.info("Running " + str(self)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 364 | for of_port, ifname in basic_port_map.items(): # Grab first port |
| 365 | break |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 366 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 367 | (hw_addr, config, advert) = \ |
| 368 | port_config_get(self.controller, of_port, basic_logger) |
| 369 | self.assertTrue(config is not None, "Did not get port config") |
| 370 | |
| 371 | basic_logger.debug("No flood bit port " + str(of_port) + " is now " + |
| 372 | str(config & ofp.OFPPC_NO_FLOOD)) |
| 373 | |
| 374 | rv = port_config_set(self.controller, of_port, |
| 375 | config ^ ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD, |
| 376 | basic_logger) |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 377 | self.assertTrue(rv != -1, "Error sending port mod") |
| 378 | |
| 379 | # Verify change took place with same feature request |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 380 | (hw_addr, config2, advert) = \ |
| 381 | port_config_get(self.controller, of_port, basic_logger) |
| 382 | basic_logger.debug("No flood bit port " + str(of_port) + " is now " + |
| 383 | str(config2 & ofp.OFPPC_NO_FLOOD)) |
| 384 | self.assertTrue(config2 is not None, "Did not get port config2") |
| 385 | self.assertTrue(config2 & ofp.OFPPC_NO_FLOOD != |
| 386 | config & ofp.OFPPC_NO_FLOOD, |
| 387 | "Bit change did not take") |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 388 | # Set it back |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 389 | rv = port_config_set(self.controller, of_port, config, |
| 390 | ofp.OFPPC_NO_FLOOD, basic_logger) |
| 391 | self.assertTrue(rv != -1, "Error sending port mod") |
Dan Talayco | b3f43fe | 2010-05-13 14:24:20 -0700 | [diff] [blame] | 392 | |
Dan Talayco | dba244e | 2010-02-15 14:08:53 -0800 | [diff] [blame] | 393 | if __name__ == "__main__": |
Dan Talayco | 2c0dba3 | 2010-03-06 22:47:06 -0800 | [diff] [blame] | 394 | print "Please run through oft script: ./oft --test_spec=basic" |