Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 1 | """ |
| 2 | Test cases for testing actions taken on packets |
| 3 | |
| 4 | See basic.py for other info. |
| 5 | |
| 6 | It is recommended that these definitions be kept in their own |
| 7 | namespace as different groups of tests will likely define |
| 8 | similar identifiers. |
| 9 | |
| 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 | |
| 13 | The switch is actively attempting to contact the controller at the address |
| 14 | indicated oin oft_config |
| 15 | |
| 16 | """ |
| 17 | |
| 18 | import logging |
| 19 | |
| 20 | import unittest |
| 21 | |
| 22 | import oftest.controller as controller |
| 23 | import oftest.cstruct as ofp |
| 24 | import oftest.message as message |
| 25 | import oftest.dataplane as dataplane |
| 26 | import oftest.action as action |
| 27 | import oftest.parse as parse |
| 28 | import basic |
| 29 | |
| 30 | from testutils import * |
| 31 | |
| 32 | #@var port_map Local copy of the configuration map from OF port |
| 33 | # numbers to OS interfaces |
| 34 | pa_port_map = None |
| 35 | #@var pa_logger Local logger object |
| 36 | pa_logger = None |
| 37 | #@var pa_config Local copy of global configuration data |
| 38 | pa_config = None |
| 39 | |
| 40 | def test_set_init(config): |
| 41 | """ |
| 42 | Set up function for packet action test classes |
| 43 | |
| 44 | @param config The configuration dictionary; see oft |
| 45 | """ |
| 46 | |
| 47 | global pa_port_map |
| 48 | global pa_logger |
| 49 | global pa_config |
| 50 | |
| 51 | pa_logger = logging.getLogger("pkt_act") |
| 52 | pa_logger.info("Initializing test set") |
| 53 | pa_port_map = config["port_map"] |
| 54 | pa_config = config |
| 55 | |
| 56 | class DirectPacket(basic.SimpleDataPlane): |
| 57 | """ |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 58 | Send packet to single egress port |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 59 | |
| 60 | Generate a packet |
| 61 | Generate and install a matching flow |
| 62 | Add action to direct the packet to an egress port |
| 63 | Send the packet to ingress dataplane port |
| 64 | Verify the packet is received at the egress port only |
| 65 | """ |
| 66 | def runTest(self): |
| 67 | global pa_port_map |
| 68 | of_ports = pa_port_map.keys() |
| 69 | of_ports.sort() |
| 70 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 71 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 72 | pkt = simple_tcp_packet() |
| 73 | match = parse.packet_to_flow_match(pkt) |
Dan Talayco | 7dd6cd6 | 2010-03-16 15:02:35 -0700 | [diff] [blame] | 74 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 75 | self.assertTrue(match is not None, |
| 76 | "Could not generate flow match from pkt") |
| 77 | act = action.action_output() |
| 78 | |
| 79 | for idx in range(len(of_ports)): |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 80 | rc = delete_all_flows(self.controller, pa_logger) |
| 81 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 82 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 83 | ingress_port = of_ports[idx] |
| 84 | egress_port = of_ports[(idx + 1) % len(of_ports)] |
| 85 | pa_logger.info("Ingress " + str(ingress_port) + |
| 86 | " to egress " + str(egress_port)) |
| 87 | |
| 88 | match.in_port = ingress_port |
| 89 | |
| 90 | request = message.flow_mod() |
| 91 | request.match = match |
| 92 | request.buffer_id = 0xffffffff |
| 93 | act.port = egress_port |
| 94 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 95 | |
| 96 | pa_logger.info("Inserting flow") |
| 97 | rv = self.controller.message_send(request) |
| 98 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 99 | do_barrier(self.controller) |
| 100 | |
| 101 | pa_logger.info("Sending packet to dp port " + |
| 102 | str(ingress_port)) |
| 103 | self.dataplane.send(ingress_port, str(pkt)) |
| 104 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(timeout=1) |
| 105 | self.assertTrue(rcv_pkt is not None, "Did not receive packet") |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 106 | pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 107 | str(rcv_port)) |
| 108 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 109 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 110 | 'Response packet does not match send packet') |
| 111 | |
| 112 | |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 113 | |
| 114 | class DirectTwoPorts(basic.SimpleDataPlane): |
| 115 | """ |
| 116 | Send packet to two egress ports |
| 117 | |
| 118 | Generate a packet |
| 119 | Generate and install a matching flow |
| 120 | Add action to direct the packet to two egress ports |
| 121 | Send the packet to ingress dataplane port |
| 122 | Verify the packet is received at the two egress ports |
| 123 | """ |
| 124 | def runTest(self): |
| 125 | global pa_port_map |
| 126 | of_ports = pa_port_map.keys() |
| 127 | of_ports.sort() |
| 128 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 129 | |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 130 | pkt = simple_tcp_packet() |
| 131 | match = parse.packet_to_flow_match(pkt) |
| 132 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 133 | self.assertTrue(match is not None, |
| 134 | "Could not generate flow match from pkt") |
| 135 | act = action.action_output() |
| 136 | |
| 137 | for idx in range(len(of_ports)): |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 138 | rc = delete_all_flows(self.controller, pa_logger) |
| 139 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 140 | |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 141 | ingress_port = of_ports[idx] |
| 142 | egress_port1 = of_ports[(idx + 1) % len(of_ports)] |
| 143 | egress_port2 = of_ports[(idx + 2) % len(of_ports)] |
| 144 | pa_logger.info("Ingress " + str(ingress_port) + |
| 145 | " to egress " + str(egress_port1) + " and " + |
| 146 | str(egress_port2)) |
| 147 | |
| 148 | match.in_port = ingress_port |
| 149 | |
| 150 | request = message.flow_mod() |
| 151 | request.match = match |
| 152 | request.buffer_id = 0xffffffff |
| 153 | act.port = egress_port1 |
| 154 | self.assertTrue(request.actions.add(act), "Could not add action1") |
| 155 | act.port = egress_port2 |
| 156 | self.assertTrue(request.actions.add(act), "Could not add action2") |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 157 | # pa_logger.info(request.show()) |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 158 | |
| 159 | pa_logger.info("Inserting flow") |
| 160 | rv = self.controller.message_send(request) |
| 161 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 162 | do_barrier(self.controller) |
| 163 | |
| 164 | pa_logger.info("Sending packet to dp port " + |
| 165 | str(ingress_port)) |
| 166 | self.dataplane.send(ingress_port, str(pkt)) |
| 167 | (rcv_port1, rcv_pkt1, pkt_time1) = self.dataplane.poll(timeout=1) |
| 168 | (rcv_port2, rcv_pkt2, pkt_time2) = self.dataplane.poll(timeout=1) |
| 169 | self.assertTrue(rcv_pkt1 is not None, "Did not receive packet 1") |
| 170 | self.assertTrue(rcv_pkt2 is not None, "Did not receive packet 2") |
| 171 | pa_logger.debug("Packet len " + str(len(rcv_pkt1)) + " in on " + |
| 172 | str(rcv_port1)) |
| 173 | pa_logger.debug("Packet len " + str(len(rcv_pkt2)) + " in on " + |
| 174 | str(rcv_port2)) |
| 175 | |
| 176 | # Check if ports swapped |
| 177 | if (rcv_port1 == egress_port2 and rcv_port2 == egress_port1): |
| 178 | (rcv_port2, rcv_port1) = (rcv_port1, rcv_port2) |
| 179 | (rcv_pkt2, rcv_pkt1) = (rcv_pkt1, rcv_pkt2) |
| 180 | self.assertEqual(rcv_port1, egress_port1, |
| 181 | "Unexpected receive port 1") |
| 182 | self.assertEqual(rcv_port2, egress_port2, |
| 183 | "Unexpected receive port 2") |
| 184 | self.assertEqual(str(pkt), str(rcv_pkt1), |
| 185 | 'Response packet does not match send packet 1') |
| 186 | self.assertEqual(str(pkt), str(rcv_pkt2), |
| 187 | 'Response packet does not match send packet 2') |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 188 | |
| 189 | class DirectMCNonIngress(basic.SimpleDataPlane): |
| 190 | """ |
| 191 | Multicast to all non-ingress ports |
| 192 | |
| 193 | Generate a packet |
| 194 | Generate and install a matching flow |
| 195 | Add action to direct the packet to all non-ingress ports |
| 196 | Send the packet to ingress dataplane port |
| 197 | Verify the packet is received at all non-ingress ports |
| 198 | |
| 199 | Does not use the flood action |
| 200 | """ |
| 201 | def runTest(self): |
| 202 | global pa_port_map |
| 203 | of_ports = pa_port_map.keys() |
| 204 | of_ports.sort() |
| 205 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 206 | |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 207 | pkt = simple_tcp_packet() |
| 208 | match = parse.packet_to_flow_match(pkt) |
| 209 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 210 | self.assertTrue(match is not None, |
| 211 | "Could not generate flow match from pkt") |
| 212 | act = action.action_output() |
| 213 | |
| 214 | for idx in range(len(of_ports)): |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 215 | rc = delete_all_flows(self.controller, pa_logger) |
| 216 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 217 | |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 218 | ingress_port = of_ports[idx] |
| 219 | pa_logger.info("Ingress " + str(ingress_port) + |
| 220 | " all non-ingress ports") |
| 221 | |
| 222 | match.in_port = ingress_port |
| 223 | |
| 224 | request = message.flow_mod() |
| 225 | request.match = match |
| 226 | request.buffer_id = 0xffffffff |
| 227 | for egr_idx in range(len(of_ports)): |
| 228 | if egr_idx == idx: |
| 229 | continue |
| 230 | egress_port = of_ports[egr_idx] |
| 231 | act.port = egress_port |
| 232 | self.assertTrue(request.actions.add(act), |
| 233 | "Could not add output to " + str(egress_port)) |
| 234 | pa_logger.info(request.show()) |
| 235 | |
| 236 | pa_logger.info("Inserting flow") |
| 237 | rv = self.controller.message_send(request) |
| 238 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 239 | do_barrier(self.controller) |
| 240 | |
| 241 | pa_logger.info("Sending packet to dp port " + |
| 242 | str(ingress_port)) |
| 243 | self.dataplane.send(ingress_port, str(pkt)) |
| 244 | for egr_idx in range(len(of_ports)): |
| 245 | if egr_idx == idx: |
| 246 | continue |
| 247 | ofport = of_ports[egr_idx] |
| 248 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll( |
| 249 | port_number=ofport, timeout=1) |
| 250 | self.assertTrue(rcv_pkt is not None, |
| 251 | "Did not receive packet port " + str(ofport)) |
| 252 | pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " |
| 253 | + str(rcv_port)) |
| 254 | |
| 255 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 256 | 'Response packet does not match send packet ' + |
| 257 | "on port " + str(ofport)) |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 258 | |
| 259 | class DirectMC(basic.SimpleDataPlane): |
| 260 | """ |
| 261 | Multicast to all ports including ingress |
| 262 | |
| 263 | Generate a packet |
| 264 | Generate and install a matching flow |
| 265 | Add action to direct the packet to all non-ingress ports |
| 266 | Send the packet to ingress dataplane port |
| 267 | Verify the packet is received at all ports |
| 268 | |
| 269 | Does not use the flood action |
| 270 | """ |
| 271 | def runTest(self): |
| 272 | global pa_port_map |
| 273 | of_ports = pa_port_map.keys() |
| 274 | of_ports.sort() |
| 275 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 276 | |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 277 | pkt = simple_tcp_packet() |
| 278 | match = parse.packet_to_flow_match(pkt) |
| 279 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 280 | self.assertTrue(match is not None, |
| 281 | "Could not generate flow match from pkt") |
| 282 | act = action.action_output() |
| 283 | |
| 284 | for idx in range(len(of_ports)): |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 285 | rc = delete_all_flows(self.controller, pa_logger) |
| 286 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 287 | |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 288 | ingress_port = of_ports[idx] |
| 289 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
| 290 | |
| 291 | match.in_port = ingress_port |
| 292 | |
| 293 | request = message.flow_mod() |
| 294 | request.match = match |
| 295 | request.buffer_id = 0xffffffff |
| 296 | for egr_idx in range(len(of_ports)): |
| 297 | egress_port = of_ports[egr_idx] |
| 298 | if egr_idx == idx: |
| 299 | act.port = ofp.OFPP_IN_PORT |
| 300 | else: |
| 301 | act.port = egress_port |
| 302 | self.assertTrue(request.actions.add(act), |
| 303 | "Could not add output to " + str(egress_port)) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 304 | # pa_logger.info(request.show()) |
| 305 | |
| 306 | pa_logger.info("Inserting flow") |
| 307 | rv = self.controller.message_send(request) |
| 308 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 309 | do_barrier(self.controller) |
| 310 | |
| 311 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 312 | self.dataplane.send(ingress_port, str(pkt)) |
| 313 | for egr_idx in range(len(of_ports)): |
| 314 | ofport = of_ports[egr_idx] |
| 315 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll( |
| 316 | port_number=ofport, timeout=1) |
| 317 | self.assertTrue(rcv_pkt is not None, |
| 318 | "Did not receive packet port " + str(ofport)) |
| 319 | pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " |
| 320 | + str(rcv_port)) |
| 321 | |
| 322 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 323 | 'Response packet does not match send packet ' + |
| 324 | "on port " + str(ofport)) |
| 325 | |
| 326 | class Flood(basic.SimpleDataPlane): |
| 327 | """ |
| 328 | Flood to all ports except ingress |
| 329 | |
| 330 | Generate a packet |
| 331 | Generate and install a matching flow |
| 332 | Add action to flood the packet |
| 333 | Send the packet to ingress dataplane port |
| 334 | Verify the packet is received at all other ports |
| 335 | """ |
| 336 | def runTest(self): |
| 337 | global pa_port_map |
| 338 | of_ports = pa_port_map.keys() |
| 339 | of_ports.sort() |
| 340 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 341 | |
| 342 | pkt = simple_tcp_packet() |
| 343 | match = parse.packet_to_flow_match(pkt) |
| 344 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 345 | self.assertTrue(match is not None, |
| 346 | "Could not generate flow match from pkt") |
| 347 | act = action.action_output() |
| 348 | |
| 349 | for idx in range(len(of_ports)): |
| 350 | rc = delete_all_flows(self.controller, pa_logger) |
| 351 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 352 | |
| 353 | ingress_port = of_ports[idx] |
| 354 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
| 355 | |
| 356 | match.in_port = ingress_port |
| 357 | |
| 358 | request = message.flow_mod() |
| 359 | request.match = match |
| 360 | request.buffer_id = 0xffffffff |
| 361 | act.port = ofp.OFPP_FLOOD |
| 362 | self.assertTrue(request.actions.add(act), |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 363 | "Could not add flood port action") |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 364 | pa_logger.info(request.show()) |
| 365 | |
| 366 | pa_logger.info("Inserting flow") |
| 367 | rv = self.controller.message_send(request) |
| 368 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 369 | do_barrier(self.controller) |
| 370 | |
| 371 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 372 | self.dataplane.send(ingress_port, str(pkt)) |
| 373 | for egr_idx in range(len(of_ports)): |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 374 | if egr_idx == idx: |
| 375 | continue |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 376 | ofport = of_ports[egr_idx] |
| 377 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll( |
| 378 | port_number=ofport, timeout=1) |
| 379 | self.assertTrue(rcv_pkt is not None, |
| 380 | "Did not receive packet port " + str(ofport)) |
| 381 | pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " |
| 382 | + str(rcv_port)) |
| 383 | |
| 384 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 385 | 'Response packet does not match send packet ' + |
| 386 | "on port " + str(ofport)) |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 387 | |
| 388 | |
| 389 | class FloodPlusIngress(basic.SimpleDataPlane): |
| 390 | """ |
| 391 | Flood to all ports plus send to ingress port |
| 392 | |
| 393 | Generate a packet |
| 394 | Generate and install a matching flow |
| 395 | Add action to flood the packet |
| 396 | Add action to send to ingress port |
| 397 | Send the packet to ingress dataplane port |
| 398 | Verify the packet is received at all other ports |
| 399 | """ |
| 400 | def runTest(self): |
| 401 | global pa_port_map |
| 402 | of_ports = pa_port_map.keys() |
| 403 | of_ports.sort() |
| 404 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 405 | |
| 406 | pkt = simple_tcp_packet() |
| 407 | match = parse.packet_to_flow_match(pkt) |
| 408 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 409 | self.assertTrue(match is not None, |
| 410 | "Could not generate flow match from pkt") |
| 411 | act = action.action_output() |
| 412 | |
| 413 | for idx in range(len(of_ports)): |
| 414 | rc = delete_all_flows(self.controller, pa_logger) |
| 415 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 416 | |
| 417 | ingress_port = of_ports[idx] |
| 418 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
| 419 | |
| 420 | match.in_port = ingress_port |
| 421 | |
| 422 | request = message.flow_mod() |
| 423 | request.match = match |
| 424 | request.buffer_id = 0xffffffff |
| 425 | act.port = ofp.OFPP_FLOOD |
| 426 | self.assertTrue(request.actions.add(act), |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 427 | "Could not add flood port action") |
| 428 | act.port = ofp.OFPP_IN_PORT |
| 429 | self.assertTrue(request.actions.add(act), |
| 430 | "Could not add ingress port for output") |
| 431 | pa_logger.info(request.show()) |
| 432 | |
| 433 | pa_logger.info("Inserting flow") |
| 434 | rv = self.controller.message_send(request) |
| 435 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 436 | do_barrier(self.controller) |
| 437 | |
| 438 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 439 | self.dataplane.send(ingress_port, str(pkt)) |
| 440 | for egr_idx in range(len(of_ports)): |
| 441 | ofport = of_ports[egr_idx] |
| 442 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll( |
| 443 | port_number=ofport, timeout=1) |
| 444 | self.assertTrue(rcv_pkt is not None, |
| 445 | "Did not receive packet port " + str(ofport)) |
| 446 | pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " |
| 447 | + str(rcv_port)) |
| 448 | |
| 449 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 450 | 'Response packet does not match send packet ' + |
| 451 | "on port " + str(ofport)) |
| 452 | |
| 453 | class All(basic.SimpleDataPlane): |
| 454 | """ |
| 455 | Send to OFPP_ALL port |
| 456 | |
| 457 | Generate a packet |
| 458 | Generate and install a matching flow |
| 459 | Add action to forward to OFPP_ALL |
| 460 | Send the packet to ingress dataplane port |
| 461 | Verify the packet is received at all other ports |
| 462 | """ |
| 463 | def runTest(self): |
| 464 | global pa_port_map |
| 465 | of_ports = pa_port_map.keys() |
| 466 | of_ports.sort() |
| 467 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 468 | |
| 469 | pkt = simple_tcp_packet() |
| 470 | match = parse.packet_to_flow_match(pkt) |
| 471 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 472 | self.assertTrue(match is not None, |
| 473 | "Could not generate flow match from pkt") |
| 474 | act = action.action_output() |
| 475 | |
| 476 | for idx in range(len(of_ports)): |
| 477 | rc = delete_all_flows(self.controller, pa_logger) |
| 478 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 479 | |
| 480 | ingress_port = of_ports[idx] |
| 481 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
| 482 | |
| 483 | match.in_port = ingress_port |
| 484 | |
| 485 | request = message.flow_mod() |
| 486 | request.match = match |
| 487 | request.buffer_id = 0xffffffff |
| 488 | act.port = ofp.OFPP_ALL |
| 489 | self.assertTrue(request.actions.add(act), |
| 490 | "Could not add ALL port action") |
| 491 | pa_logger.info(request.show()) |
| 492 | |
| 493 | pa_logger.info("Inserting flow") |
| 494 | rv = self.controller.message_send(request) |
| 495 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 496 | do_barrier(self.controller) |
| 497 | |
| 498 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 499 | self.dataplane.send(ingress_port, str(pkt)) |
| 500 | for egr_idx in range(len(of_ports)): |
| 501 | if egr_idx == idx: |
| 502 | continue |
| 503 | ofport = of_ports[egr_idx] |
| 504 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll( |
| 505 | port_number=ofport, timeout=1) |
| 506 | self.assertTrue(rcv_pkt is not None, |
| 507 | "Did not receive packet port " + str(ofport)) |
| 508 | pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " |
| 509 | + str(rcv_port)) |
| 510 | |
| 511 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 512 | 'Response packet does not match send packet ' + |
| 513 | "on port " + str(ofport)) |
| 514 | |
| 515 | class AllPlusIngress(basic.SimpleDataPlane): |
| 516 | """ |
| 517 | Send to OFPP_ALL port and ingress port |
| 518 | |
| 519 | Generate a packet |
| 520 | Generate and install a matching flow |
| 521 | Add action to forward to OFPP_ALL |
| 522 | Add action to forward to ingress port |
| 523 | Send the packet to ingress dataplane port |
| 524 | Verify the packet is received at all other ports |
| 525 | """ |
| 526 | def runTest(self): |
| 527 | global pa_port_map |
| 528 | of_ports = pa_port_map.keys() |
| 529 | of_ports.sort() |
| 530 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 531 | |
| 532 | pkt = simple_tcp_packet() |
| 533 | match = parse.packet_to_flow_match(pkt) |
| 534 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 535 | self.assertTrue(match is not None, |
| 536 | "Could not generate flow match from pkt") |
| 537 | act = action.action_output() |
| 538 | |
| 539 | for idx in range(len(of_ports)): |
| 540 | rc = delete_all_flows(self.controller, pa_logger) |
| 541 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 542 | |
| 543 | ingress_port = of_ports[idx] |
| 544 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
| 545 | |
| 546 | match.in_port = ingress_port |
| 547 | |
| 548 | request = message.flow_mod() |
| 549 | request.match = match |
| 550 | request.buffer_id = 0xffffffff |
| 551 | act.port = ofp.OFPP_ALL |
| 552 | self.assertTrue(request.actions.add(act), |
| 553 | "Could not add ALL port action") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 554 | act.port = ofp.OFPP_IN_PORT |
| 555 | self.assertTrue(request.actions.add(act), |
| 556 | "Could not add ingress port for output") |
| 557 | pa_logger.info(request.show()) |
| 558 | |
| 559 | pa_logger.info("Inserting flow") |
| 560 | rv = self.controller.message_send(request) |
| 561 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 562 | do_barrier(self.controller) |
| 563 | |
| 564 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 565 | self.dataplane.send(ingress_port, str(pkt)) |
| 566 | for egr_idx in range(len(of_ports)): |
| 567 | ofport = of_ports[egr_idx] |
| 568 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll( |
| 569 | port_number=ofport, timeout=1) |
| 570 | self.assertTrue(rcv_pkt is not None, |
| 571 | "Did not receive packet port " + str(ofport)) |
| 572 | pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " |
| 573 | + str(rcv_port)) |
| 574 | |
| 575 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 576 | 'Response packet does not match send packet ' + |
| 577 | "on port " + str(ofport)) |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 578 | |
| 579 | class SimpleExactMatch(basic.SimpleDataPlane): |
| 580 | """ |
| 581 | Exercise exact matching for all ports |
| 582 | |
| 583 | Generate a packet |
| 584 | Generate and install a matching flow without wildcard mask |
| 585 | Add action to forward to a port |
| 586 | Send the packet to the port |
| 587 | Verify the packet is received at all other ports (one port at a time) |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 588 | Verify flow_expiration message is correct when command option is set |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 589 | """ |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 590 | IP_ETHTYPE = 0x800 |
| 591 | TCP_PROTOCOL = 0x6 |
| 592 | UDP_PROTOCOL = 0x11 |
| 593 | |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 594 | def runTest(self): |
| 595 | self.flowMatchTest() |
| 596 | |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 597 | def flowMatchTest(self, wildcards=0, check_expire=False): |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 598 | global pa_port_map |
| 599 | of_ports = pa_port_map.keys() |
| 600 | of_ports.sort() |
| 601 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 602 | |
| 603 | pkt = simple_tcp_packet() |
| 604 | match = parse.packet_to_flow_match(pkt) |
| 605 | self.assertTrue(match is not None, |
| 606 | "Could not generate flow match from pkt") |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 607 | match.dl_vlan = ofp.OFP_VLAN_NONE |
| 608 | match.nw_proto = self.TCP_PROTOCOL |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 609 | match.wildcards = wildcards |
| 610 | |
| 611 | act = action.action_output() |
| 612 | |
| 613 | for idx in range(len(of_ports)): |
| 614 | rc = delete_all_flows(self.controller, pa_logger) |
| 615 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 616 | |
| 617 | ingress_port = of_ports[idx] |
| 618 | pa_logger.info("Ingress " + str(ingress_port) + " to all the other ports") |
| 619 | |
| 620 | match.in_port = ingress_port |
| 621 | |
| 622 | request = message.flow_mod() |
| 623 | request.match = match |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 624 | request.buffer_id = 0xffffffff |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 625 | #@todo Need UI to setup FLAGS parameter for flow_mod |
| 626 | if(check_expire): |
| 627 | request.flags |= ofp.OFPFF_SEND_FLOW_REM |
| 628 | request.hard_timeout = 1 |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 629 | |
| 630 | for egr_idx in range(len(of_ports)): |
| 631 | if egr_idx == idx: |
| 632 | continue |
| 633 | act.port = of_ports[egr_idx] |
| 634 | self.assertTrue(request.actions.add(act), |
| 635 | "Could not add output action") |
| 636 | pa_logger.info(request.show()) |
| 637 | |
| 638 | pa_logger.info("Inserting flow") |
| 639 | rv = self.controller.message_send(request) |
| 640 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 641 | do_barrier(self.controller) |
| 642 | |
| 643 | pa_logger.info("Sending packet to dp port " +str(ingress_port)) |
| 644 | self.dataplane.send(ingress_port, str(pkt)) |
| 645 | |
| 646 | ofport = of_ports[egr_idx] |
| 647 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll( |
| 648 | port_number=ofport, timeout=1) |
| 649 | self.assertTrue(rcv_pkt is not None, |
| 650 | "Did not receive packet port " + str(ofport)) |
| 651 | pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " |
| 652 | + str(rcv_port)) |
| 653 | |
| 654 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 655 | 'Response packet does not match send packet ' + |
| 656 | "on port " + str(ofport)) |
| 657 | |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 658 | #@todo Need UI for enabling response-verification |
| 659 | if(check_expire): |
| 660 | (response, raw) \ |
| 661 | = self.controller.poll(ofp.OFPT_FLOW_REMOVED, 2) |
| 662 | self.assertTrue(response is not None, |
| 663 | 'Flow removed message not received') |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 664 | |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 665 | req_match = request.match |
| 666 | res_match = response.match |
| 667 | if(req_match != res_match): |
| 668 | self.verifMatchField(req_match, res_match) |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 669 | |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 670 | self.assertEqual(request.cookie, response.cookie, |
| 671 | self.matchErrStr('cookie')) |
| 672 | if (wildcards != 0): |
| 673 | self.assertEqual(request.priority, response.priority, |
| 674 | self.matchErrStr('priority')) |
| 675 | self.assertEqual(response.reason, ofp.OFPRR_HARD_TIMEOUT, |
| 676 | 'Reason is not HARD TIMEOUT') |
| 677 | self.assertEqual(response.packet_count, 1, |
| 678 | 'Packet count is not correct') |
| 679 | self.assertEqual(response.byte_count, len(pkt), |
| 680 | 'Packet length is not correct') |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 681 | |
| 682 | def verifMatchField(self, req_match, res_match): |
| 683 | self.assertEqual(str(req_match.wildcards), str(res_match.wildcards), |
| 684 | self.matchErrStr('wildcards')) |
| 685 | self.assertEqual(str(req_match.in_port), str(res_match.in_port), |
| 686 | self.matchErrStr('in_port')) |
| 687 | self.assertEqual(str(req_match.dl_src), str(res_match.dl_src), |
| 688 | self.matchErrStr('dl_src')) |
| 689 | self.assertEqual(str(req_match.dl_dst), str(res_match.dl_dst), |
| 690 | self.matchErrStr('dl_dst')) |
| 691 | self.assertEqual(str(req_match.dl_vlan), str(res_match.dl_vlan), |
| 692 | self.matchErrStr('dl_vlan')) |
| 693 | self.assertEqual(str(req_match.dl_vlan_pcp), str(res_match.dl_vlan_pcp), |
| 694 | self.matchErrStr('dl_vlan_pcp')) |
| 695 | self.assertEqual(str(req_match.dl_type), str(res_match.dl_type), |
| 696 | self.matchErrStr('dl_type')) |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 697 | if(not(req_match.wildcards & ofp.OFPFW_DL_TYPE) |
| 698 | and (req_match.dl_type == self.IP_ETHERTYPE)): |
| 699 | self.assertEqual(str(req_match.nw_tos), str(res_match.nw_tos), |
| 700 | self.matchErrStr('nw_tos')) |
| 701 | self.assertEqual(str(req_match.nw_proto), str(res_match.nw_proto), |
| 702 | self.matchErrStr('nw_proto')) |
| 703 | self.assertEqual(str(req_match.nw_src), str(res_match.nw_src), |
| 704 | self.matchErrStr('nw_src')) |
| 705 | self.assertEqual(str(req_match.nw_dst), str(res_match.nw_dst), |
| 706 | self.matchErrStr('nw_dst')) |
| 707 | if(not(req_match.wildcards & ofp.OFPFW_NW_PROTO) |
| 708 | and ((req_match.nw_proto == self.TCP_PROTOCOL) |
| 709 | or (req_match.nw_proto == self.UDP_PROTOCOL))): |
| 710 | self.assertEqual(str(req_match.tp_src), str(res_match.tp_src), |
| 711 | self.matchErrStr('tp_src')) |
| 712 | self.assertEqual(str(req_match.tp_dst), str(res_match.tp_dst), |
| 713 | self.matchErrStr('tp_dst')) |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 714 | |
| 715 | def matchErrStr(self, field): |
| 716 | return ('Response Match_' + field + ' does not match send message') |
| 717 | |
| 718 | class SingleWildcardMatch(SimpleExactMatch): |
| 719 | """ |
| 720 | Exercise wildcard matching for all ports |
| 721 | |
| 722 | Generate a packet |
| 723 | Generate and install a matching flow with wildcard mask |
| 724 | Add action to forward to a port |
| 725 | Send the packet to the port |
| 726 | Verify the packet is received at all other ports (one port at a time) |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 727 | Verify flow_expiration message is correct when command option is set |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 728 | """ |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 729 | def __init__(self): |
| 730 | SimpleExactMatch.__init__(self) |
| 731 | self.wildcards = [ofp.OFPFW_IN_PORT, |
| 732 | ofp.OFPFW_DL_VLAN, |
| 733 | ofp.OFPFW_DL_SRC, |
| 734 | ofp.OFPFW_DL_DST, |
| 735 | ofp.OFPFW_DL_TYPE, |
| 736 | ofp.OFPFW_NW_PROTO, |
| 737 | ofp.OFPFW_TP_SRC, |
| 738 | ofp.OFPFW_TP_DST, |
| 739 | 0x3F << ofp.OFPFW_NW_SRC_SHIFT, |
| 740 | 0x3F << ofp.OFPFW_NW_DST_SHIFT, |
| 741 | ofp.OFPFW_DL_VLAN_PCP, |
| 742 | ofp.OFPFW_NW_TOS] |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 743 | |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 744 | def runTest(self): |
| 745 | for exec_wildcard in range(len(self.wildcards)): |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 746 | self.flowMatchTest(exec_wildcard) |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 747 | |
| 748 | class AllExceptOneWildcardMatch(SingleWildcardMatch): |
| 749 | """ |
| 750 | Create All-execpt-one-field wildcard and exercise for all ports |
| 751 | |
| 752 | Generate a packet |
| 753 | Generate and install a matching flow with wildcard all except one filed |
| 754 | Add action to forward to a port |
| 755 | Send the packet to the port |
| 756 | Verify the packet is received at all other ports (one port at a time) |
| 757 | Verify flow_expiration message is correct when command option is set |
| 758 | """ |
| 759 | def runTest(self): |
| 760 | for exec_wildcard in range(len(self.wildcards)): |
| 761 | all_exp_one_wildcard = ofp.OFPFW_ALL ^ self.wildcards[exec_wildcard] |
| 762 | self.flowMatchTest(all_exp_one_wildcard) |
Tatsuya Yabe | e30ebe2 | 2010-05-25 09:30:49 -0700 | [diff] [blame^] | 763 | |
| 764 | class AllWildcardMatch(SingleWildcardMatch): |
| 765 | """ |
| 766 | Create Wildcard-all flow and exercise for all ports |
| 767 | |
| 768 | Generate a packet |
| 769 | Generate and install a matching flow with wildcard-all |
| 770 | Add action to forward to a port |
| 771 | Send the packet to the port |
| 772 | Verify the packet is received at all other ports (one port at a time) |
| 773 | Verify flow_expiration message is correct when command option is set |
| 774 | """ |
| 775 | def runTest(self): |
| 776 | self.flowMatchTest(ofp.OFPFW_ALL) |