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 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 18 | import copy |
| 19 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 20 | import logging |
| 21 | |
| 22 | import unittest |
| 23 | |
| 24 | import oftest.controller as controller |
| 25 | import oftest.cstruct as ofp |
| 26 | import oftest.message as message |
| 27 | import oftest.dataplane as dataplane |
| 28 | import oftest.action as action |
| 29 | import oftest.parse as parse |
| 30 | import basic |
| 31 | |
| 32 | from testutils import * |
| 33 | |
| 34 | #@var port_map Local copy of the configuration map from OF port |
| 35 | # numbers to OS interfaces |
| 36 | pa_port_map = None |
| 37 | #@var pa_logger Local logger object |
| 38 | pa_logger = None |
| 39 | #@var pa_config Local copy of global configuration data |
| 40 | pa_config = None |
| 41 | |
| 42 | def test_set_init(config): |
| 43 | """ |
| 44 | Set up function for packet action test classes |
| 45 | |
| 46 | @param config The configuration dictionary; see oft |
| 47 | """ |
| 48 | |
| 49 | global pa_port_map |
| 50 | global pa_logger |
| 51 | global pa_config |
| 52 | |
| 53 | pa_logger = logging.getLogger("pkt_act") |
| 54 | pa_logger.info("Initializing test set") |
| 55 | pa_port_map = config["port_map"] |
| 56 | pa_config = config |
| 57 | |
| 58 | class DirectPacket(basic.SimpleDataPlane): |
| 59 | """ |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 60 | Send packet to single egress port |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 61 | |
| 62 | Generate a packet |
| 63 | Generate and install a matching flow |
| 64 | Add action to direct the packet to an egress port |
| 65 | Send the packet to ingress dataplane port |
| 66 | Verify the packet is received at the egress port only |
| 67 | """ |
| 68 | def runTest(self): |
| 69 | global pa_port_map |
| 70 | of_ports = pa_port_map.keys() |
| 71 | of_ports.sort() |
| 72 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 73 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 74 | pkt = simple_tcp_packet() |
| 75 | match = parse.packet_to_flow_match(pkt) |
Dan Talayco | 7dd6cd6 | 2010-03-16 15:02:35 -0700 | [diff] [blame] | 76 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 77 | self.assertTrue(match is not None, |
| 78 | "Could not generate flow match from pkt") |
| 79 | act = action.action_output() |
| 80 | |
| 81 | for idx in range(len(of_ports)): |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 82 | rv = delete_all_flows(self.controller, pa_logger) |
| 83 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 84 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 85 | ingress_port = of_ports[idx] |
| 86 | egress_port = of_ports[(idx + 1) % len(of_ports)] |
| 87 | pa_logger.info("Ingress " + str(ingress_port) + |
| 88 | " to egress " + str(egress_port)) |
| 89 | |
| 90 | match.in_port = ingress_port |
| 91 | |
| 92 | request = message.flow_mod() |
| 93 | request.match = match |
| 94 | request.buffer_id = 0xffffffff |
| 95 | act.port = egress_port |
| 96 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 97 | |
| 98 | pa_logger.info("Inserting flow") |
| 99 | rv = self.controller.message_send(request) |
| 100 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 101 | do_barrier(self.controller) |
| 102 | |
| 103 | pa_logger.info("Sending packet to dp port " + |
| 104 | str(ingress_port)) |
| 105 | self.dataplane.send(ingress_port, str(pkt)) |
| 106 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(timeout=1) |
| 107 | self.assertTrue(rcv_pkt is not None, "Did not receive packet") |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 108 | pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 109 | str(rcv_port)) |
| 110 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 111 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 112 | 'Response packet does not match send packet') |
| 113 | |
| 114 | |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 115 | |
| 116 | class DirectTwoPorts(basic.SimpleDataPlane): |
| 117 | """ |
| 118 | Send packet to two egress ports |
| 119 | |
| 120 | Generate a packet |
| 121 | Generate and install a matching flow |
| 122 | Add action to direct the packet to two egress ports |
| 123 | Send the packet to ingress dataplane port |
| 124 | Verify the packet is received at the two egress ports |
| 125 | """ |
| 126 | def runTest(self): |
| 127 | global pa_port_map |
| 128 | of_ports = pa_port_map.keys() |
| 129 | of_ports.sort() |
| 130 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 131 | |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 132 | pkt = simple_tcp_packet() |
| 133 | match = parse.packet_to_flow_match(pkt) |
| 134 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 135 | self.assertTrue(match is not None, |
| 136 | "Could not generate flow match from pkt") |
| 137 | act = action.action_output() |
| 138 | |
| 139 | for idx in range(len(of_ports)): |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 140 | rv = delete_all_flows(self.controller, pa_logger) |
| 141 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 142 | |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 143 | ingress_port = of_ports[idx] |
| 144 | egress_port1 = of_ports[(idx + 1) % len(of_ports)] |
| 145 | egress_port2 = of_ports[(idx + 2) % len(of_ports)] |
| 146 | pa_logger.info("Ingress " + str(ingress_port) + |
| 147 | " to egress " + str(egress_port1) + " and " + |
| 148 | str(egress_port2)) |
| 149 | |
| 150 | match.in_port = ingress_port |
| 151 | |
| 152 | request = message.flow_mod() |
| 153 | request.match = match |
| 154 | request.buffer_id = 0xffffffff |
| 155 | act.port = egress_port1 |
| 156 | self.assertTrue(request.actions.add(act), "Could not add action1") |
| 157 | act.port = egress_port2 |
| 158 | self.assertTrue(request.actions.add(act), "Could not add action2") |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 159 | # pa_logger.info(request.show()) |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 160 | |
| 161 | pa_logger.info("Inserting flow") |
| 162 | rv = self.controller.message_send(request) |
| 163 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 164 | do_barrier(self.controller) |
| 165 | |
| 166 | pa_logger.info("Sending packet to dp port " + |
| 167 | str(ingress_port)) |
| 168 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 169 | yes_ports = set([egress_port1, egress_port2]) |
| 170 | no_ports = set(of_ports).difference(yes_ports) |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 171 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 172 | receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, |
| 173 | self, pa_logger) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 174 | |
| 175 | class DirectMCNonIngress(basic.SimpleDataPlane): |
| 176 | """ |
| 177 | Multicast to all non-ingress ports |
| 178 | |
| 179 | Generate a packet |
| 180 | Generate and install a matching flow |
| 181 | Add action to direct the packet to all non-ingress ports |
| 182 | Send the packet to ingress dataplane port |
| 183 | Verify the packet is received at all non-ingress ports |
| 184 | |
| 185 | Does not use the flood action |
| 186 | """ |
| 187 | def runTest(self): |
| 188 | global pa_port_map |
| 189 | of_ports = pa_port_map.keys() |
| 190 | of_ports.sort() |
| 191 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 192 | |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 193 | pkt = simple_tcp_packet() |
| 194 | match = parse.packet_to_flow_match(pkt) |
| 195 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 196 | self.assertTrue(match is not None, |
| 197 | "Could not generate flow match from pkt") |
| 198 | act = action.action_output() |
| 199 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 200 | for ingress_port in of_ports: |
| 201 | rv = delete_all_flows(self.controller, pa_logger) |
| 202 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 203 | |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 204 | pa_logger.info("Ingress " + str(ingress_port) + |
| 205 | " all non-ingress ports") |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 206 | match.in_port = ingress_port |
| 207 | |
| 208 | request = message.flow_mod() |
| 209 | request.match = match |
| 210 | request.buffer_id = 0xffffffff |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 211 | for egress_port in of_ports: |
| 212 | if egress_port == ingress_port: |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 213 | continue |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 214 | act.port = egress_port |
| 215 | self.assertTrue(request.actions.add(act), |
| 216 | "Could not add output to " + str(egress_port)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 217 | pa_logger.debug(request.show()) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 218 | |
| 219 | pa_logger.info("Inserting flow") |
| 220 | rv = self.controller.message_send(request) |
| 221 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 222 | do_barrier(self.controller) |
| 223 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 224 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 225 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 226 | yes_ports = set(of_ports).difference([ingress_port]) |
| 227 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
| 228 | self, pa_logger) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 229 | |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 230 | |
| 231 | class DirectMC(basic.SimpleDataPlane): |
| 232 | """ |
| 233 | Multicast to all ports including ingress |
| 234 | |
| 235 | Generate a packet |
| 236 | Generate and install a matching flow |
| 237 | Add action to direct the packet to all non-ingress ports |
| 238 | Send the packet to ingress dataplane port |
| 239 | Verify the packet is received at all ports |
| 240 | |
| 241 | Does not use the flood action |
| 242 | """ |
| 243 | def runTest(self): |
| 244 | global pa_port_map |
| 245 | of_ports = pa_port_map.keys() |
| 246 | of_ports.sort() |
| 247 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 248 | |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 249 | pkt = simple_tcp_packet() |
| 250 | match = parse.packet_to_flow_match(pkt) |
| 251 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 252 | self.assertTrue(match is not None, |
| 253 | "Could not generate flow match from pkt") |
| 254 | act = action.action_output() |
| 255 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 256 | for ingress_port in of_ports: |
| 257 | rv = delete_all_flows(self.controller, pa_logger) |
| 258 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 259 | |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 260 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 261 | match.in_port = ingress_port |
| 262 | |
| 263 | request = message.flow_mod() |
| 264 | request.match = match |
| 265 | request.buffer_id = 0xffffffff |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 266 | for egress_port in of_ports: |
| 267 | if egress_port == ingress_port: |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 268 | act.port = ofp.OFPP_IN_PORT |
| 269 | else: |
| 270 | act.port = egress_port |
| 271 | self.assertTrue(request.actions.add(act), |
| 272 | "Could not add output to " + str(egress_port)) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 273 | # pa_logger.info(request.show()) |
| 274 | |
| 275 | pa_logger.info("Inserting flow") |
| 276 | rv = self.controller.message_send(request) |
| 277 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 278 | do_barrier(self.controller) |
| 279 | |
| 280 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 281 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 282 | receive_pkt_check(self.dataplane, pkt, of_ports, [], self, |
| 283 | pa_logger) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 284 | |
| 285 | class Flood(basic.SimpleDataPlane): |
| 286 | """ |
| 287 | Flood to all ports except ingress |
| 288 | |
| 289 | Generate a packet |
| 290 | Generate and install a matching flow |
| 291 | Add action to flood the packet |
| 292 | Send the packet to ingress dataplane port |
| 293 | Verify the packet is received at all other ports |
| 294 | """ |
| 295 | def runTest(self): |
| 296 | global pa_port_map |
| 297 | of_ports = pa_port_map.keys() |
| 298 | of_ports.sort() |
| 299 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 300 | |
| 301 | pkt = simple_tcp_packet() |
| 302 | match = parse.packet_to_flow_match(pkt) |
| 303 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 304 | self.assertTrue(match is not None, |
| 305 | "Could not generate flow match from pkt") |
| 306 | act = action.action_output() |
| 307 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 308 | for ingress_port in of_ports: |
| 309 | rv = delete_all_flows(self.controller, pa_logger) |
| 310 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 311 | |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 312 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 313 | match.in_port = ingress_port |
| 314 | |
| 315 | request = message.flow_mod() |
| 316 | request.match = match |
| 317 | request.buffer_id = 0xffffffff |
| 318 | act.port = ofp.OFPP_FLOOD |
| 319 | self.assertTrue(request.actions.add(act), |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 320 | "Could not add flood port action") |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 321 | pa_logger.info(request.show()) |
| 322 | |
| 323 | pa_logger.info("Inserting flow") |
| 324 | rv = self.controller.message_send(request) |
| 325 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 326 | do_barrier(self.controller) |
| 327 | |
| 328 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 329 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 330 | yes_ports = set(of_ports).difference([ingress_port]) |
| 331 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
| 332 | self, pa_logger) |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 333 | |
| 334 | |
| 335 | class FloodPlusIngress(basic.SimpleDataPlane): |
| 336 | """ |
| 337 | Flood to all ports plus send to ingress port |
| 338 | |
| 339 | Generate a packet |
| 340 | Generate and install a matching flow |
| 341 | Add action to flood the packet |
| 342 | Add action to send to ingress port |
| 343 | Send the packet to ingress dataplane port |
| 344 | Verify the packet is received at all other ports |
| 345 | """ |
| 346 | def runTest(self): |
| 347 | global pa_port_map |
| 348 | of_ports = pa_port_map.keys() |
| 349 | of_ports.sort() |
| 350 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 351 | |
| 352 | pkt = simple_tcp_packet() |
| 353 | match = parse.packet_to_flow_match(pkt) |
| 354 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 355 | self.assertTrue(match is not None, |
| 356 | "Could not generate flow match from pkt") |
| 357 | act = action.action_output() |
| 358 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 359 | for ingress_port in of_ports: |
| 360 | rv = delete_all_flows(self.controller, pa_logger) |
| 361 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 362 | |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 363 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 364 | match.in_port = ingress_port |
| 365 | |
| 366 | request = message.flow_mod() |
| 367 | request.match = match |
| 368 | request.buffer_id = 0xffffffff |
| 369 | act.port = ofp.OFPP_FLOOD |
| 370 | self.assertTrue(request.actions.add(act), |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 371 | "Could not add flood port action") |
| 372 | act.port = ofp.OFPP_IN_PORT |
| 373 | self.assertTrue(request.actions.add(act), |
| 374 | "Could not add ingress port for output") |
| 375 | pa_logger.info(request.show()) |
| 376 | |
| 377 | pa_logger.info("Inserting flow") |
| 378 | rv = self.controller.message_send(request) |
| 379 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 380 | do_barrier(self.controller) |
| 381 | |
| 382 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 383 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 384 | receive_pkt_check(self.dataplane, pkt, of_ports, [], self, |
| 385 | pa_logger) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 386 | |
| 387 | class All(basic.SimpleDataPlane): |
| 388 | """ |
| 389 | Send to OFPP_ALL port |
| 390 | |
| 391 | Generate a packet |
| 392 | Generate and install a matching flow |
| 393 | Add action to forward to OFPP_ALL |
| 394 | Send the packet to ingress dataplane port |
| 395 | Verify the packet is received at all other ports |
| 396 | """ |
| 397 | def runTest(self): |
| 398 | global pa_port_map |
| 399 | of_ports = pa_port_map.keys() |
| 400 | of_ports.sort() |
| 401 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 402 | |
| 403 | pkt = simple_tcp_packet() |
| 404 | match = parse.packet_to_flow_match(pkt) |
| 405 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 406 | self.assertTrue(match is not None, |
| 407 | "Could not generate flow match from pkt") |
| 408 | act = action.action_output() |
| 409 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 410 | for ingress_port in of_ports: |
| 411 | rv = delete_all_flows(self.controller, pa_logger) |
| 412 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 413 | |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 414 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 415 | match.in_port = ingress_port |
| 416 | |
| 417 | request = message.flow_mod() |
| 418 | request.match = match |
| 419 | request.buffer_id = 0xffffffff |
| 420 | act.port = ofp.OFPP_ALL |
| 421 | self.assertTrue(request.actions.add(act), |
| 422 | "Could not add ALL port action") |
| 423 | pa_logger.info(request.show()) |
| 424 | |
| 425 | pa_logger.info("Inserting flow") |
| 426 | rv = self.controller.message_send(request) |
| 427 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 428 | do_barrier(self.controller) |
| 429 | |
| 430 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 431 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 432 | yes_ports = set(of_ports).difference([ingress_port]) |
| 433 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
| 434 | self, pa_logger) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 435 | |
| 436 | class AllPlusIngress(basic.SimpleDataPlane): |
| 437 | """ |
| 438 | Send to OFPP_ALL port and ingress port |
| 439 | |
| 440 | Generate a packet |
| 441 | Generate and install a matching flow |
| 442 | Add action to forward to OFPP_ALL |
| 443 | Add action to forward to ingress port |
| 444 | Send the packet to ingress dataplane port |
| 445 | Verify the packet is received at all other ports |
| 446 | """ |
| 447 | def runTest(self): |
| 448 | global pa_port_map |
| 449 | of_ports = pa_port_map.keys() |
| 450 | of_ports.sort() |
| 451 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 452 | |
| 453 | pkt = simple_tcp_packet() |
| 454 | match = parse.packet_to_flow_match(pkt) |
| 455 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 456 | self.assertTrue(match is not None, |
| 457 | "Could not generate flow match from pkt") |
| 458 | act = action.action_output() |
| 459 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 460 | for ingress_port in of_ports: |
| 461 | rv = delete_all_flows(self.controller, pa_logger) |
| 462 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 463 | |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 464 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 465 | match.in_port = ingress_port |
| 466 | |
| 467 | request = message.flow_mod() |
| 468 | request.match = match |
| 469 | request.buffer_id = 0xffffffff |
| 470 | act.port = ofp.OFPP_ALL |
| 471 | self.assertTrue(request.actions.add(act), |
| 472 | "Could not add ALL port action") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 473 | act.port = ofp.OFPP_IN_PORT |
| 474 | self.assertTrue(request.actions.add(act), |
| 475 | "Could not add ingress port for output") |
| 476 | pa_logger.info(request.show()) |
| 477 | |
| 478 | pa_logger.info("Inserting flow") |
| 479 | rv = self.controller.message_send(request) |
| 480 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 481 | do_barrier(self.controller) |
| 482 | |
| 483 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 484 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 485 | receive_pkt_check(self.dataplane, pkt, of_ports, [], self, |
| 486 | pa_logger) |
| 487 | |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 488 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 489 | class FloodMinusPort(basic.SimpleDataPlane): |
| 490 | """ |
| 491 | Config port with No_Flood and test Flood action |
| 492 | |
| 493 | Generate a packet |
| 494 | Generate a matching flow |
| 495 | Add action to forward to OFPP_ALL |
| 496 | Set port to no-flood |
| 497 | Send the packet to ingress dataplane port |
| 498 | Verify the packet is received at all other ports except |
| 499 | the ingress port and the no_flood port |
| 500 | """ |
| 501 | def runTest(self): |
| 502 | global pa_port_map |
| 503 | of_ports = pa_port_map.keys() |
| 504 | of_ports.sort() |
| 505 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 506 | |
| 507 | pkt = simple_tcp_packet() |
| 508 | match = parse.packet_to_flow_match(pkt) |
| 509 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 510 | self.assertTrue(match is not None, |
| 511 | "Could not generate flow match from pkt") |
| 512 | act = action.action_output() |
| 513 | |
| 514 | for idx in range(len(of_ports)): |
| 515 | rv = delete_all_flows(self.controller, pa_logger) |
| 516 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 517 | |
| 518 | ingress_port = of_ports[idx] |
| 519 | no_flood_idx = (idx + 1) % len(of_ports) |
| 520 | no_flood_port = of_ports[no_flood_idx] |
| 521 | rv = port_config_set(self.controller, no_flood_port, |
| 522 | ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD, |
| 523 | pa_logger) |
| 524 | self.assertEqual(rv, 0, "Failed to set port config") |
| 525 | |
| 526 | match.in_port = ingress_port |
| 527 | |
| 528 | request = message.flow_mod() |
| 529 | request.match = match |
| 530 | request.buffer_id = 0xffffffff |
| 531 | act.port = ofp.OFPP_FLOOD |
| 532 | self.assertTrue(request.actions.add(act), |
| 533 | "Could not add flood port action") |
| 534 | pa_logger.info(request.show()) |
| 535 | |
| 536 | pa_logger.info("Inserting flow") |
| 537 | rv = self.controller.message_send(request) |
| 538 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 539 | do_barrier(self.controller) |
| 540 | |
| 541 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 542 | pa_logger.info("No flood port is " + str(no_flood_port)) |
| 543 | self.dataplane.send(ingress_port, str(pkt)) |
| 544 | no_ports = set([ingress_port, no_flood_port]) |
| 545 | yes_ports = set(of_ports).difference(no_ports) |
| 546 | receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, self, |
| 547 | pa_logger) |
| 548 | |
| 549 | # Turn no flood off again |
| 550 | rv = port_config_set(self.controller, no_flood_port, |
| 551 | 0, ofp.OFPPC_NO_FLOOD, pa_logger) |
| 552 | self.assertEqual(rv, 0, "Failed to reset port config") |
| 553 | |
| 554 | #@todo Should check no other packets received |
| 555 | |
| 556 | if __name__ == "__main__": |
| 557 | print "Please run through oft script: ./oft --test_spec=basic" |