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 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 42 | # For test priority |
| 43 | #@var test_prio Set test priority for local tests |
| 44 | test_prio = {} |
| 45 | |
| 46 | WILDCARD_VALUES = [ofp.OFPFW_IN_PORT, |
| 47 | ofp.OFPFW_DL_VLAN, |
| 48 | ofp.OFPFW_DL_SRC, |
| 49 | ofp.OFPFW_DL_DST, |
| 50 | ofp.OFPFW_DL_TYPE, |
| 51 | ofp.OFPFW_NW_PROTO, |
| 52 | ofp.OFPFW_TP_SRC, |
| 53 | ofp.OFPFW_TP_DST, |
| 54 | 0x3F << ofp.OFPFW_NW_SRC_SHIFT, |
| 55 | 0x3F << ofp.OFPFW_NW_DST_SHIFT, |
| 56 | ofp.OFPFW_DL_VLAN_PCP, |
| 57 | ofp.OFPFW_NW_TOS] |
| 58 | |
| 59 | MODIFY_ACTION_VALUES = [ofp.OFPAT_SET_VLAN_VID, |
| 60 | ofp.OFPAT_SET_VLAN_PCP, |
| 61 | ofp.OFPAT_STRIP_VLAN, |
| 62 | ofp.OFPAT_SET_DL_SRC, |
| 63 | ofp.OFPAT_SET_DL_DST, |
| 64 | ofp.OFPAT_SET_NW_SRC, |
| 65 | ofp.OFPAT_SET_NW_DST, |
| 66 | ofp.OFPAT_SET_NW_TOS, |
| 67 | ofp.OFPAT_SET_TP_SRC, |
| 68 | ofp.OFPAT_SET_TP_DST] |
| 69 | |
| 70 | # Cache supported features to avoid transaction overhead |
| 71 | cached_supported_actions = None |
| 72 | |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 73 | TEST_VID_DEFAULT = 2 |
| 74 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 75 | def test_set_init(config): |
| 76 | """ |
| 77 | Set up function for packet action test classes |
| 78 | |
| 79 | @param config The configuration dictionary; see oft |
| 80 | """ |
| 81 | |
Ed Swierk | 6ccbb07 | 2012-03-19 14:48:40 -0700 | [diff] [blame] | 82 | basic.test_set_init(config) |
| 83 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 84 | global pa_port_map |
| 85 | global pa_logger |
| 86 | global pa_config |
| 87 | |
| 88 | pa_logger = logging.getLogger("pkt_act") |
| 89 | pa_logger.info("Initializing test set") |
| 90 | pa_port_map = config["port_map"] |
| 91 | pa_config = config |
| 92 | |
| 93 | class DirectPacket(basic.SimpleDataPlane): |
| 94 | """ |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 95 | Send packet to single egress port |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 96 | |
| 97 | Generate a packet |
| 98 | Generate and install a matching flow |
| 99 | Add action to direct the packet to an egress port |
| 100 | Send the packet to ingress dataplane port |
| 101 | Verify the packet is received at the egress port only |
| 102 | """ |
| 103 | def runTest(self): |
Tatsuya Yabe | b8fb3c3 | 2010-06-14 15:48:36 -0700 | [diff] [blame] | 104 | self.handleFlow() |
| 105 | |
| 106 | def handleFlow(self, pkttype='TCP'): |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 107 | of_ports = pa_port_map.keys() |
| 108 | of_ports.sort() |
| 109 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 110 | |
Tatsuya Yabe | b8fb3c3 | 2010-06-14 15:48:36 -0700 | [diff] [blame] | 111 | if (pkttype == 'ICMP'): |
| 112 | pkt = simple_icmp_packet() |
| 113 | else: |
| 114 | pkt = simple_tcp_packet() |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 115 | match = parse.packet_to_flow_match(pkt) |
Dan Talayco | 7dd6cd6 | 2010-03-16 15:02:35 -0700 | [diff] [blame] | 116 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 117 | self.assertTrue(match is not None, |
| 118 | "Could not generate flow match from pkt") |
| 119 | act = action.action_output() |
| 120 | |
| 121 | for idx in range(len(of_ports)): |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 122 | rv = delete_all_flows(self.controller, pa_logger) |
| 123 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 124 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 125 | ingress_port = of_ports[idx] |
| 126 | egress_port = of_ports[(idx + 1) % len(of_ports)] |
| 127 | pa_logger.info("Ingress " + str(ingress_port) + |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 128 | " to egress " + str(egress_port)) |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 129 | |
| 130 | match.in_port = ingress_port |
| 131 | |
| 132 | request = message.flow_mod() |
| 133 | request.match = match |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame^] | 134 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 135 | request.buffer_id = 0xffffffff |
| 136 | act.port = egress_port |
| 137 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 138 | |
| 139 | pa_logger.info("Inserting flow") |
| 140 | rv = self.controller.message_send(request) |
| 141 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 142 | do_barrier(self.controller) |
| 143 | |
| 144 | pa_logger.info("Sending packet to dp port " + |
| 145 | str(ingress_port)) |
| 146 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 147 | |
| 148 | exp_pkt_arg = None |
| 149 | exp_port = None |
| 150 | if pa_config["relax"]: |
| 151 | exp_pkt_arg = pkt |
| 152 | exp_port = egress_port |
| 153 | |
| 154 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(timeout=1, |
| 155 | port_number=exp_port, |
| 156 | exp_pkt=exp_pkt_arg) |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 157 | self.assertTrue(rcv_pkt is not None, "Did not receive packet") |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 158 | pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 159 | str(rcv_port)) |
| 160 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 161 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 162 | 'Response packet does not match send packet') |
Tatsuya Yabe | b8fb3c3 | 2010-06-14 15:48:36 -0700 | [diff] [blame] | 163 | |
| 164 | class DirectPacketICMP(DirectPacket): |
| 165 | """ |
| 166 | Send ICMP packet to single egress port |
| 167 | |
| 168 | Generate a ICMP packet |
| 169 | Generate and install a matching flow |
| 170 | Add action to direct the packet to an egress port |
| 171 | Send the packet to ingress dataplane port |
| 172 | Verify the packet is received at the egress port only |
| 173 | Difference from DirectPacket test is that sent packet is ICMP |
| 174 | """ |
| 175 | def runTest(self): |
| 176 | self.handleFlow(pkttype='ICMP') |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 177 | |
| 178 | class DirectTwoPorts(basic.SimpleDataPlane): |
| 179 | """ |
| 180 | Send packet to two egress ports |
| 181 | |
| 182 | Generate a packet |
| 183 | Generate and install a matching flow |
| 184 | Add action to direct the packet to two egress ports |
| 185 | Send the packet to ingress dataplane port |
| 186 | Verify the packet is received at the two egress ports |
| 187 | """ |
| 188 | def runTest(self): |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 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 | 2d0d49a | 2010-05-11 15:29:08 -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 | |
| 200 | for idx in range(len(of_ports)): |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 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 | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 204 | ingress_port = of_ports[idx] |
| 205 | egress_port1 = of_ports[(idx + 1) % len(of_ports)] |
| 206 | egress_port2 = of_ports[(idx + 2) % len(of_ports)] |
| 207 | pa_logger.info("Ingress " + str(ingress_port) + |
| 208 | " to egress " + str(egress_port1) + " and " + |
| 209 | str(egress_port2)) |
| 210 | |
| 211 | match.in_port = ingress_port |
| 212 | |
| 213 | request = message.flow_mod() |
| 214 | request.match = match |
| 215 | request.buffer_id = 0xffffffff |
| 216 | act.port = egress_port1 |
| 217 | self.assertTrue(request.actions.add(act), "Could not add action1") |
| 218 | act.port = egress_port2 |
| 219 | self.assertTrue(request.actions.add(act), "Could not add action2") |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 220 | # pa_logger.info(request.show()) |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 221 | |
| 222 | pa_logger.info("Inserting flow") |
| 223 | rv = self.controller.message_send(request) |
| 224 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 225 | do_barrier(self.controller) |
| 226 | |
| 227 | pa_logger.info("Sending packet to dp port " + |
| 228 | str(ingress_port)) |
| 229 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 230 | yes_ports = set([egress_port1, egress_port2]) |
| 231 | no_ports = set(of_ports).difference(yes_ports) |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 232 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 233 | receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 234 | self, pa_logger, pa_config) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 235 | |
| 236 | class DirectMCNonIngress(basic.SimpleDataPlane): |
| 237 | """ |
| 238 | Multicast to all non-ingress ports |
| 239 | |
| 240 | Generate a packet |
| 241 | Generate and install a matching flow |
| 242 | Add action to direct the packet to all non-ingress ports |
| 243 | Send the packet to ingress dataplane port |
| 244 | Verify the packet is received at all non-ingress ports |
| 245 | |
| 246 | Does not use the flood action |
| 247 | """ |
| 248 | def runTest(self): |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 249 | of_ports = pa_port_map.keys() |
| 250 | of_ports.sort() |
| 251 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 252 | |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 253 | pkt = simple_tcp_packet() |
| 254 | match = parse.packet_to_flow_match(pkt) |
| 255 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 256 | self.assertTrue(match is not None, |
| 257 | "Could not generate flow match from pkt") |
| 258 | act = action.action_output() |
| 259 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 260 | for ingress_port in of_ports: |
| 261 | rv = delete_all_flows(self.controller, pa_logger) |
| 262 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 263 | |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 264 | pa_logger.info("Ingress " + str(ingress_port) + |
| 265 | " all non-ingress ports") |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 266 | match.in_port = ingress_port |
| 267 | |
| 268 | request = message.flow_mod() |
| 269 | request.match = match |
| 270 | request.buffer_id = 0xffffffff |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 271 | for egress_port in of_ports: |
| 272 | if egress_port == ingress_port: |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 273 | continue |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 274 | act.port = egress_port |
| 275 | self.assertTrue(request.actions.add(act), |
| 276 | "Could not add output to " + str(egress_port)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 277 | pa_logger.debug(request.show()) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 278 | |
| 279 | pa_logger.info("Inserting flow") |
| 280 | rv = self.controller.message_send(request) |
| 281 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 282 | do_barrier(self.controller) |
| 283 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 284 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 285 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 286 | yes_ports = set(of_ports).difference([ingress_port]) |
| 287 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 288 | self, pa_logger, pa_config) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 289 | |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 290 | |
| 291 | class DirectMC(basic.SimpleDataPlane): |
| 292 | """ |
| 293 | Multicast to all ports including ingress |
| 294 | |
| 295 | Generate a packet |
| 296 | Generate and install a matching flow |
| 297 | Add action to direct the packet to all non-ingress ports |
| 298 | Send the packet to ingress dataplane port |
| 299 | Verify the packet is received at all ports |
| 300 | |
| 301 | Does not use the flood action |
| 302 | """ |
| 303 | def runTest(self): |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 304 | of_ports = pa_port_map.keys() |
| 305 | of_ports.sort() |
| 306 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 307 | |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 308 | pkt = simple_tcp_packet() |
| 309 | match = parse.packet_to_flow_match(pkt) |
| 310 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 311 | self.assertTrue(match is not None, |
| 312 | "Could not generate flow match from pkt") |
| 313 | act = action.action_output() |
| 314 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 315 | for ingress_port in of_ports: |
| 316 | rv = delete_all_flows(self.controller, pa_logger) |
| 317 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 318 | |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 319 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 320 | match.in_port = ingress_port |
| 321 | |
| 322 | request = message.flow_mod() |
| 323 | request.match = match |
| 324 | request.buffer_id = 0xffffffff |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 325 | for egress_port in of_ports: |
| 326 | if egress_port == ingress_port: |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 327 | act.port = ofp.OFPP_IN_PORT |
| 328 | else: |
| 329 | act.port = egress_port |
| 330 | self.assertTrue(request.actions.add(act), |
| 331 | "Could not add output to " + str(egress_port)) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 332 | # pa_logger.info(request.show()) |
| 333 | |
| 334 | pa_logger.info("Inserting flow") |
| 335 | rv = self.controller.message_send(request) |
| 336 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 337 | do_barrier(self.controller) |
| 338 | |
| 339 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 340 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 341 | receive_pkt_check(self.dataplane, pkt, of_ports, [], self, |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 342 | pa_logger, pa_config) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 343 | |
| 344 | class Flood(basic.SimpleDataPlane): |
| 345 | """ |
| 346 | Flood to all ports except ingress |
| 347 | |
| 348 | Generate a packet |
| 349 | Generate and install a matching flow |
| 350 | Add action to flood the packet |
| 351 | Send the packet to ingress dataplane port |
| 352 | Verify the packet is received at all other ports |
| 353 | """ |
| 354 | def runTest(self): |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 355 | of_ports = pa_port_map.keys() |
| 356 | of_ports.sort() |
| 357 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 358 | |
| 359 | pkt = simple_tcp_packet() |
| 360 | match = parse.packet_to_flow_match(pkt) |
| 361 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 362 | self.assertTrue(match is not None, |
| 363 | "Could not generate flow match from pkt") |
| 364 | act = action.action_output() |
| 365 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 366 | for ingress_port in of_ports: |
| 367 | rv = delete_all_flows(self.controller, pa_logger) |
| 368 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 369 | |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 370 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 371 | match.in_port = ingress_port |
| 372 | |
| 373 | request = message.flow_mod() |
| 374 | request.match = match |
| 375 | request.buffer_id = 0xffffffff |
| 376 | act.port = ofp.OFPP_FLOOD |
| 377 | self.assertTrue(request.actions.add(act), |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 378 | "Could not add flood port action") |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 379 | pa_logger.info(request.show()) |
| 380 | |
| 381 | pa_logger.info("Inserting flow") |
| 382 | rv = self.controller.message_send(request) |
| 383 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 384 | do_barrier(self.controller) |
| 385 | |
| 386 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 387 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 388 | yes_ports = set(of_ports).difference([ingress_port]) |
| 389 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 390 | self, pa_logger, pa_config) |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 391 | |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 392 | class FloodPlusIngress(basic.SimpleDataPlane): |
| 393 | """ |
| 394 | Flood to all ports plus send to ingress port |
| 395 | |
| 396 | Generate a packet |
| 397 | Generate and install a matching flow |
| 398 | Add action to flood the packet |
| 399 | Add action to send to ingress port |
| 400 | Send the packet to ingress dataplane port |
| 401 | Verify the packet is received at all other ports |
| 402 | """ |
| 403 | def runTest(self): |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 404 | of_ports = pa_port_map.keys() |
| 405 | of_ports.sort() |
| 406 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 407 | |
| 408 | pkt = simple_tcp_packet() |
| 409 | match = parse.packet_to_flow_match(pkt) |
| 410 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 411 | self.assertTrue(match is not None, |
| 412 | "Could not generate flow match from pkt") |
| 413 | act = action.action_output() |
| 414 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 415 | for ingress_port in of_ports: |
| 416 | rv = delete_all_flows(self.controller, pa_logger) |
| 417 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 418 | |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 419 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 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)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 440 | receive_pkt_check(self.dataplane, pkt, of_ports, [], self, |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 441 | pa_logger, pa_config) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 442 | |
| 443 | class All(basic.SimpleDataPlane): |
| 444 | """ |
| 445 | Send to OFPP_ALL port |
| 446 | |
| 447 | Generate a packet |
| 448 | Generate and install a matching flow |
| 449 | Add action to forward to OFPP_ALL |
| 450 | Send the packet to ingress dataplane port |
| 451 | Verify the packet is received at all other ports |
| 452 | """ |
| 453 | def runTest(self): |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 454 | of_ports = pa_port_map.keys() |
| 455 | of_ports.sort() |
| 456 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 457 | |
| 458 | pkt = simple_tcp_packet() |
| 459 | match = parse.packet_to_flow_match(pkt) |
| 460 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 461 | self.assertTrue(match is not None, |
| 462 | "Could not generate flow match from pkt") |
| 463 | act = action.action_output() |
| 464 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 465 | for ingress_port in of_ports: |
| 466 | rv = delete_all_flows(self.controller, pa_logger) |
| 467 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 468 | |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 469 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 470 | match.in_port = ingress_port |
| 471 | |
| 472 | request = message.flow_mod() |
| 473 | request.match = match |
| 474 | request.buffer_id = 0xffffffff |
| 475 | act.port = ofp.OFPP_ALL |
| 476 | self.assertTrue(request.actions.add(act), |
| 477 | "Could not add ALL port action") |
| 478 | pa_logger.info(request.show()) |
| 479 | |
| 480 | pa_logger.info("Inserting flow") |
| 481 | rv = self.controller.message_send(request) |
| 482 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 483 | do_barrier(self.controller) |
| 484 | |
| 485 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 486 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 487 | yes_ports = set(of_ports).difference([ingress_port]) |
| 488 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 489 | self, pa_logger, pa_config) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 490 | |
| 491 | class AllPlusIngress(basic.SimpleDataPlane): |
| 492 | """ |
| 493 | Send to OFPP_ALL port and ingress port |
| 494 | |
| 495 | Generate a packet |
| 496 | Generate and install a matching flow |
| 497 | Add action to forward to OFPP_ALL |
| 498 | Add action to forward to ingress port |
| 499 | Send the packet to ingress dataplane port |
| 500 | Verify the packet is received at all other ports |
| 501 | """ |
| 502 | def runTest(self): |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 503 | of_ports = pa_port_map.keys() |
| 504 | of_ports.sort() |
| 505 | self.assertTrue(len(of_ports) > 1, "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 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 514 | for ingress_port in of_ports: |
| 515 | rv = delete_all_flows(self.controller, pa_logger) |
| 516 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 517 | |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 518 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 519 | match.in_port = ingress_port |
| 520 | |
| 521 | request = message.flow_mod() |
| 522 | request.match = match |
| 523 | request.buffer_id = 0xffffffff |
| 524 | act.port = ofp.OFPP_ALL |
| 525 | self.assertTrue(request.actions.add(act), |
| 526 | "Could not add ALL port action") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 527 | act.port = ofp.OFPP_IN_PORT |
| 528 | self.assertTrue(request.actions.add(act), |
| 529 | "Could not add ingress port for output") |
| 530 | pa_logger.info(request.show()) |
| 531 | |
| 532 | pa_logger.info("Inserting flow") |
| 533 | rv = self.controller.message_send(request) |
| 534 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 535 | do_barrier(self.controller) |
| 536 | |
| 537 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 538 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 539 | receive_pkt_check(self.dataplane, pkt, of_ports, [], self, |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 540 | pa_logger, pa_config) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 541 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 542 | class FloodMinusPort(basic.SimpleDataPlane): |
| 543 | """ |
| 544 | Config port with No_Flood and test Flood action |
| 545 | |
| 546 | Generate a packet |
| 547 | Generate a matching flow |
| 548 | Add action to forward to OFPP_ALL |
| 549 | Set port to no-flood |
| 550 | Send the packet to ingress dataplane port |
| 551 | Verify the packet is received at all other ports except |
| 552 | the ingress port and the no_flood port |
| 553 | """ |
| 554 | def runTest(self): |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 555 | of_ports = pa_port_map.keys() |
| 556 | of_ports.sort() |
| 557 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 558 | |
| 559 | pkt = simple_tcp_packet() |
| 560 | match = parse.packet_to_flow_match(pkt) |
| 561 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 562 | self.assertTrue(match is not None, |
| 563 | "Could not generate flow match from pkt") |
| 564 | act = action.action_output() |
| 565 | |
| 566 | for idx in range(len(of_ports)): |
| 567 | rv = delete_all_flows(self.controller, pa_logger) |
| 568 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 569 | |
| 570 | ingress_port = of_ports[idx] |
| 571 | no_flood_idx = (idx + 1) % len(of_ports) |
| 572 | no_flood_port = of_ports[no_flood_idx] |
| 573 | rv = port_config_set(self.controller, no_flood_port, |
| 574 | ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD, |
| 575 | pa_logger) |
| 576 | self.assertEqual(rv, 0, "Failed to set port config") |
| 577 | |
| 578 | match.in_port = ingress_port |
| 579 | |
| 580 | request = message.flow_mod() |
| 581 | request.match = match |
| 582 | request.buffer_id = 0xffffffff |
| 583 | act.port = ofp.OFPP_FLOOD |
| 584 | self.assertTrue(request.actions.add(act), |
| 585 | "Could not add flood port action") |
| 586 | pa_logger.info(request.show()) |
| 587 | |
| 588 | pa_logger.info("Inserting flow") |
| 589 | rv = self.controller.message_send(request) |
| 590 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 591 | do_barrier(self.controller) |
| 592 | |
| 593 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 594 | pa_logger.info("No flood port is " + str(no_flood_port)) |
| 595 | self.dataplane.send(ingress_port, str(pkt)) |
| 596 | no_ports = set([ingress_port, no_flood_port]) |
| 597 | yes_ports = set(of_ports).difference(no_ports) |
| 598 | receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, self, |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 599 | pa_logger, pa_config) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 600 | |
| 601 | # Turn no flood off again |
| 602 | rv = port_config_set(self.controller, no_flood_port, |
| 603 | 0, ofp.OFPPC_NO_FLOOD, pa_logger) |
| 604 | self.assertEqual(rv, 0, "Failed to reset port config") |
| 605 | |
| 606 | #@todo Should check no other packets received |
| 607 | |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 608 | |
| 609 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 610 | ################################################################ |
| 611 | |
| 612 | class BaseMatchCase(basic.SimpleDataPlane): |
| 613 | def setUp(self): |
| 614 | basic.SimpleDataPlane.setUp(self) |
| 615 | self.logger = pa_logger |
| 616 | def runTest(self): |
| 617 | self.logger.info("BaseMatchCase") |
| 618 | |
| 619 | class ExactMatch(BaseMatchCase): |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 620 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 621 | Exercise exact matching for all port pairs |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 622 | |
| 623 | Generate a packet |
| 624 | Generate and install a matching flow without wildcard mask |
| 625 | Add action to forward to a port |
| 626 | Send the packet to the port |
| 627 | Verify the packet is received at all other ports (one port at a time) |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 628 | """ |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 629 | |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 630 | def runTest(self): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 631 | flow_match_test(self, pa_port_map) |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 632 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 633 | class ExactMatchTagged(BaseMatchCase): |
| 634 | """ |
| 635 | Exact match for all port pairs with tagged pkts |
| 636 | """ |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 637 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 638 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 639 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 640 | flow_match_test(self, pa_port_map, dl_vlan=vid) |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 641 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 642 | class ExactMatchTaggedMany(BaseMatchCase): |
| 643 | """ |
| 644 | ExactMatchTagged with many VLANS |
| 645 | """ |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 646 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 647 | def runTest(self): |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 648 | for vid in range(2,100,10): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 649 | flow_match_test(self, pa_port_map, dl_vlan=vid, max_test=5) |
| 650 | for vid in range(100,4000,389): |
| 651 | flow_match_test(self, pa_port_map, dl_vlan=vid, max_test=5) |
| 652 | flow_match_test(self, pa_port_map, dl_vlan=4094, max_test=5) |
Tatsuya Yabe | cdf575e | 2010-05-25 16:56:38 -0700 | [diff] [blame] | 653 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 654 | # Don't run by default |
| 655 | test_prio["ExactMatchTaggedMany"] = -1 |
Tatsuya Yabe | cdf575e | 2010-05-25 16:56:38 -0700 | [diff] [blame] | 656 | |
Tatsuya Yabe | cdf575e | 2010-05-25 16:56:38 -0700 | [diff] [blame] | 657 | |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame^] | 658 | class SingleWildcardMatchPriority(BaseMatchCase): |
| 659 | |
| 660 | def runTest(self): |
| 661 | self.pkt = simple_tcp_packet() |
| 662 | self.flowMsgs = {} |
| 663 | |
| 664 | of_ports = pa_port_map.keys() |
| 665 | of_ports.sort() |
| 666 | |
| 667 | # Delete the initial flow table |
| 668 | rc = delete_all_flows(self.controller, self.logger) |
| 669 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 670 | do_barrier(self.controller) |
| 671 | |
| 672 | # Run several combinations, each at lower priority settings. |
| 673 | # At the end of each call to runPrioFlows(), the table should |
| 674 | # be empty. If its not, we'll catch it as the priorities decreases |
| 675 | portA = of_ports[0] |
| 676 | portB = of_ports[1] |
| 677 | portC = of_ports[2] |
| 678 | |
| 679 | # TODO -- these priority numbers should be validated somehow? |
| 680 | self.runPrioFlows(portA, portB, portC, 1000, 999) |
| 681 | self.runPrioFlows(portB, portC, portA, 998, 997) |
| 682 | self.runPrioFlows(portC, portA, portB, 996, 995) |
| 683 | self.runPrioFlows(portA, portC, portB, 994, 993) |
| 684 | |
| 685 | |
| 686 | |
| 687 | def runPrioFlows(self, portA, portB, portC, prioHigher, prioLower): |
| 688 | |
| 689 | # Sanity check flow at lower priority from pA to pB |
| 690 | self.logger.info("runPrioFlows(pA=%d,pB=%d,pC=%d,ph=%d,pl=%d" |
| 691 | % (portA, portB, portC, prioHigher, prioLower)) |
| 692 | |
| 693 | self.installFlow(prioLower, portA, portB) |
| 694 | self.verifyFlow(portA, portB) |
| 695 | self.removeFlow(prioLower) |
| 696 | # Sanity check flow at lower priority from pA to pC |
| 697 | self.installFlow(prioLower, portA, portC) |
| 698 | self.verifyFlow(portA, portC) |
| 699 | self.removeFlow(prioLower) |
| 700 | |
| 701 | # Install and verify pA->pB @ prioLower |
| 702 | self.installFlow(prioLower, portA, portB) |
| 703 | self.verifyFlow(portA, portB) |
| 704 | |
| 705 | # Install and verify pA->pC @ prioHigher, should override pA->pB |
| 706 | self.installFlow(prioHigher, portA, portC) |
| 707 | self.verifyFlow(portA, portC) |
| 708 | # remove pA->pC |
| 709 | self.removeFlow(prioHigher) |
| 710 | |
| 711 | # Old flow pA -> pB @ prioLower should still be active |
| 712 | self.verifyFlow(portA, portB) |
| 713 | self.removeFlow(prioLower) |
| 714 | |
| 715 | # Table should be empty at this point, leave it alone as |
| 716 | # an assumption for future test runs |
| 717 | |
| 718 | |
| 719 | |
| 720 | def installFlow(self, prio, inp, egp, clearTable=False): |
| 721 | request = flow_msg_create(self, self.pkt, ing_port=inp, |
| 722 | wildcards=ofp.OFPFW_DL_SRC, |
| 723 | egr_ports=egp) |
| 724 | request.priority = prio |
| 725 | flow_msg_install(self, request, clear_table=clearTable) |
| 726 | self.flowMsgs[prio] = request |
| 727 | |
| 728 | def removeFlow(self, prio): |
| 729 | if self.flowMsgs.has_key(prio): |
| 730 | msg = self.flowMsgs[prio] |
| 731 | msg.command = ofp.OFPFC_DELETE_STRICT |
| 732 | # This *must* be set for DELETE |
| 733 | msg.out_port = ofp.OFPP_NONE |
| 734 | self.controller.message_send(msg) |
| 735 | do_barrier(self.controller) |
| 736 | |
| 737 | |
| 738 | def verifyFlow(self, inp, egp): |
| 739 | self.logger.info("Pkt match test: " + str(inp) + |
| 740 | " to " + str(egp)) |
| 741 | self.logger.debug("Send packet: " + str(inp) + " to " |
| 742 | + str(egp)) |
| 743 | self.dataplane.send(inp, str(self.pkt)) |
| 744 | receive_pkt_verify(self, egp, self.pkt, inp) |
| 745 | |
| 746 | |
| 747 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 748 | class SingleWildcardMatch(BaseMatchCase): |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 749 | """ |
| 750 | Exercise wildcard matching for all ports |
| 751 | |
| 752 | Generate a packet |
| 753 | Generate and install a matching flow with wildcard mask |
| 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) |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 757 | Verify flow_expiration message is correct when command option is set |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 758 | """ |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 759 | def runTest(self): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 760 | for wc in WILDCARD_VALUES: |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 761 | if wc & ofp.OFPFW_DL_VLAN: |
| 762 | dl_vlan = 0 |
| 763 | else: |
| 764 | dl_vlan = -1 |
| 765 | flow_match_test(self, pa_port_map, wildcards=wc, |
| 766 | dl_vlan=dl_vlan, max_test=10) |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 767 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 768 | class SingleWildcardMatchTagged(BaseMatchCase): |
| 769 | """ |
| 770 | SingleWildcardMatch with tagged packets |
| 771 | """ |
| 772 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 773 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 774 | for wc in WILDCARD_VALUES: |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 775 | flow_match_test(self, pa_port_map, wildcards=wc, dl_vlan=vid, |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 776 | max_test=10) |
| 777 | |
| 778 | class AllExceptOneWildcardMatch(BaseMatchCase): |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 779 | """ |
Dan Talayco | 80b54ed | 2010-07-13 09:48:35 -0700 | [diff] [blame] | 780 | Match exactly one field |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 781 | |
| 782 | Generate a packet |
| 783 | Generate and install a matching flow with wildcard all except one filed |
| 784 | Add action to forward to a port |
| 785 | Send the packet to the port |
| 786 | Verify the packet is received at all other ports (one port at a time) |
| 787 | Verify flow_expiration message is correct when command option is set |
| 788 | """ |
| 789 | def runTest(self): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 790 | for wc in WILDCARD_VALUES: |
| 791 | all_exp_one_wildcard = ofp.OFPFW_ALL ^ wc |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 792 | if all_exp_one_wildcard & ofp.OFPFW_DL_VLAN: |
| 793 | dl_vlan = 0 |
| 794 | else: |
| 795 | dl_vlan = -1 |
| 796 | flow_match_test(self, pa_port_map, wildcards=all_exp_one_wildcard, |
| 797 | dl_vlan=dl_vlan) |
Tatsuya Yabe | e30ebe2 | 2010-05-25 09:30:49 -0700 | [diff] [blame] | 798 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 799 | class AllExceptOneWildcardMatchTagged(BaseMatchCase): |
| 800 | """ |
| 801 | Match one field with tagged packets |
| 802 | """ |
| 803 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 804 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 805 | for wc in WILDCARD_VALUES: |
| 806 | all_exp_one_wildcard = ofp.OFPFW_ALL ^ wc |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 807 | flow_match_test(self, pa_port_map, wildcards=all_exp_one_wildcard, |
| 808 | dl_vlan=vid) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 809 | |
| 810 | class AllWildcardMatch(BaseMatchCase): |
Tatsuya Yabe | e30ebe2 | 2010-05-25 09:30:49 -0700 | [diff] [blame] | 811 | """ |
| 812 | Create Wildcard-all flow and exercise for all ports |
| 813 | |
| 814 | Generate a packet |
| 815 | Generate and install a matching flow with wildcard-all |
| 816 | Add action to forward to a port |
| 817 | Send the packet to the port |
| 818 | Verify the packet is received at all other ports (one port at a time) |
| 819 | Verify flow_expiration message is correct when command option is set |
| 820 | """ |
| 821 | def runTest(self): |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 822 | flow_match_test(self, pa_port_map, wildcards=ofp.OFPFW_ALL) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 823 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 824 | class AllWildcardMatchTagged(BaseMatchCase): |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 825 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 826 | AllWildcardMatch with tagged packets |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 827 | """ |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 828 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 829 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 830 | flow_match_test(self, pa_port_map, wildcards=ofp.OFPFW_ALL, |
| 831 | dl_vlan=vid) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 832 | |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 833 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 834 | class AddVLANTag(BaseMatchCase): |
| 835 | """ |
| 836 | Add a VLAN tag to an untagged packet |
| 837 | """ |
| 838 | def runTest(self): |
| 839 | new_vid = 2 |
| 840 | sup_acts = supported_actions_get(self) |
| 841 | if not(sup_acts & 1<<ofp.OFPAT_SET_VLAN_VID): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 842 | skip_message_emit(self, "Add VLAN tag test") |
Dan Talayco | f36f108 | 2010-07-13 13:57:17 -0700 | [diff] [blame] | 843 | return |
Tatsuya Yabe | f5ffb97 | 2010-05-26 15:36:33 -0700 | [diff] [blame] | 844 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 845 | len = 100 |
| 846 | len_w_vid = 104 |
| 847 | pkt = simple_tcp_packet(pktlen=len) |
| 848 | exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 849 | dl_vlan=new_vid) |
| 850 | vid_act = action.action_set_vlan_vid() |
| 851 | vid_act.vlan_vid = new_vid |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 852 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 853 | flow_match_test(self, pa_port_map, pkt=pkt, |
| 854 | exp_pkt=exp_pkt, action_list=[vid_act]) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 855 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 856 | class PacketOnly(basic.DataPlaneOnly): |
| 857 | """ |
| 858 | Just send a packet thru the switch |
| 859 | """ |
| 860 | def runTest(self): |
| 861 | pkt = simple_tcp_packet() |
| 862 | of_ports = pa_port_map.keys() |
| 863 | of_ports.sort() |
| 864 | ing_port = of_ports[0] |
| 865 | pa_logger.info("Sending packet to " + str(ing_port)) |
| 866 | pa_logger.debug("Data: " + str(pkt).encode('hex')) |
| 867 | self.dataplane.send(ing_port, str(pkt)) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 868 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 869 | class PacketOnlyTagged(basic.DataPlaneOnly): |
| 870 | """ |
| 871 | Just send a packet thru the switch |
| 872 | """ |
| 873 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 874 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 875 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid) |
| 876 | of_ports = pa_port_map.keys() |
| 877 | of_ports.sort() |
| 878 | ing_port = of_ports[0] |
| 879 | pa_logger.info("Sending packet to " + str(ing_port)) |
| 880 | pa_logger.debug("Data: " + str(pkt).encode('hex')) |
| 881 | self.dataplane.send(ing_port, str(pkt)) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 882 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 883 | test_prio["PacketOnly"] = -1 |
| 884 | test_prio["PacketOnlyTagged"] = -1 |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 885 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 886 | class ModifyVID(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 887 | """ |
| 888 | Modify the VLAN ID in the VLAN tag of a tagged packet |
| 889 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 890 | def runTest(self): |
| 891 | old_vid = 2 |
| 892 | new_vid = 3 |
| 893 | sup_acts = supported_actions_get(self) |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 894 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 895 | skip_message_emit(self, "Modify VLAN tag test") |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 896 | return |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 897 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 898 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=old_vid) |
| 899 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=new_vid) |
| 900 | vid_act = action.action_set_vlan_vid() |
| 901 | vid_act.vlan_vid = new_vid |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 902 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 903 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 904 | action_list=[vid_act]) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 905 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 906 | class StripVLANTag(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 907 | """ |
| 908 | Strip the VLAN tag from a tagged packet |
| 909 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 910 | def runTest(self): |
| 911 | old_vid = 2 |
| 912 | sup_acts = supported_actions_get(self) |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 913 | if not (sup_acts & 1 << ofp.OFPAT_STRIP_VLAN): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 914 | skip_message_emit(self, "Strip VLAN tag test") |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 915 | return |
Dan Talayco | f36f108 | 2010-07-13 13:57:17 -0700 | [diff] [blame] | 916 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 917 | len_w_vid = 104 |
| 918 | len = 100 |
| 919 | pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 920 | dl_vlan=old_vid) |
| 921 | exp_pkt = simple_tcp_packet(pktlen=len) |
| 922 | vid_act = action.action_strip_vlan() |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 923 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 924 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 925 | action_list=[vid_act]) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 926 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 927 | def init_pkt_args(): |
| 928 | """ |
| 929 | Pass back a dictionary with default packet arguments |
| 930 | """ |
| 931 | args = {} |
| 932 | args["dl_src"] = '00:23:45:67:89:AB' |
| 933 | |
| 934 | dl_vlan_enable=False |
| 935 | dl_vlan=-1 |
| 936 | if pa_config["test-params"]["vid"]: |
| 937 | dl_vlan_enable=True |
| 938 | dl_vlan = pa_config["test-params"]["vid"] |
| 939 | |
| 940 | # Unpack operator is ** on a dictionary |
| 941 | |
| 942 | return args |
| 943 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 944 | class ModifyL2Src(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 945 | """ |
| 946 | Modify the source MAC address (TP1) |
| 947 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 948 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 949 | sup_acts = supported_actions_get(self) |
| 950 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 951 | skip_message_emit(self, "ModifyL2Src test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 952 | return |
| 953 | |
| 954 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'], |
| 955 | check_test_params=True) |
| 956 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 957 | action_list=acts, max_test=2) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 958 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 959 | class ModifyL2Dst(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 960 | """ |
| 961 | Modify the dest MAC address (TP1) |
| 962 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 963 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 964 | sup_acts = supported_actions_get(self) |
| 965 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 966 | skip_message_emit(self, "ModifyL2dst test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 967 | return |
| 968 | |
| 969 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 970 | check_test_params=True) |
| 971 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 972 | action_list=acts, max_test=2) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 973 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 974 | class ModifyL3Src(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 975 | """ |
| 976 | Modify the source IP address of an IP packet (TP1) |
| 977 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 978 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 979 | sup_acts = supported_actions_get(self) |
| 980 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_SRC): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 981 | skip_message_emit(self, "ModifyL3Src test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 982 | return |
| 983 | |
| 984 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_src'], |
| 985 | check_test_params=True) |
| 986 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 987 | action_list=acts, max_test=2) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 988 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 989 | class ModifyL3Dst(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 990 | """ |
| 991 | Modify the dest IP address of an IP packet (TP1) |
| 992 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 993 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 994 | sup_acts = supported_actions_get(self) |
| 995 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_DST): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 996 | skip_message_emit(self, "ModifyL3Dst test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 997 | return |
| 998 | |
| 999 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_dst'], |
| 1000 | check_test_params=True) |
| 1001 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1002 | action_list=acts, max_test=2) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1003 | |
| 1004 | class ModifyL4Src(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1005 | """ |
| 1006 | Modify the source TCP port of a TCP packet (TP1) |
| 1007 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1008 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1009 | sup_acts = supported_actions_get(self) |
| 1010 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_SRC): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1011 | skip_message_emit(self, "ModifyL4Src test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1012 | return |
| 1013 | |
| 1014 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_sport'], |
| 1015 | check_test_params=True) |
| 1016 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1017 | action_list=acts, max_test=2) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1018 | |
| 1019 | class ModifyL4Dst(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1020 | """ |
| 1021 | Modify the dest TCP port of a TCP packet (TP1) |
| 1022 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1023 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1024 | sup_acts = supported_actions_get(self) |
| 1025 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1026 | skip_message_emit(self, "ModifyL4Dst test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1027 | return |
| 1028 | |
| 1029 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_dport'], |
| 1030 | check_test_params=True) |
| 1031 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1032 | action_list=acts, max_test=2) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1033 | |
| 1034 | class ModifyTOS(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1035 | """ |
| 1036 | Modify the IP type of service of an IP packet (TP1) |
| 1037 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1038 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1039 | sup_acts = supported_actions_get(self) |
| 1040 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1041 | skip_message_emit(self, "ModifyTOS test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1042 | return |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1043 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1044 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_tos'], |
| 1045 | check_test_params=True) |
| 1046 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1047 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1048 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1049 | class ModifyL2DstMC(BaseMatchCase): |
| 1050 | """ |
| 1051 | Modify the L2 dest and send to 2 ports |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1052 | """ |
| 1053 | def runTest(self): |
| 1054 | sup_acts = supported_actions_get(self) |
| 1055 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1056 | skip_message_emit(self, "ModifyL2dstMC test") |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1057 | return |
| 1058 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1059 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1060 | check_test_params=True) |
| 1061 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1062 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1063 | |
Dan Talayco | c948d0b | 2012-03-23 12:17:54 -0700 | [diff] [blame] | 1064 | class ModifyL2DstIngress(BaseMatchCase): |
| 1065 | """ |
| 1066 | Modify the L2 dest and send to the ingress port |
| 1067 | """ |
| 1068 | def runTest(self): |
| 1069 | sup_acts = supported_actions_get(self) |
| 1070 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
| 1071 | skip_message_emit(self, "ModifyL2dstMC test") |
| 1072 | return |
| 1073 | |
| 1074 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1075 | check_test_params=True) |
| 1076 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1077 | action_list=acts, max_test=2, egr_count=0, |
| 1078 | ing_port=True) |
| 1079 | |
Dan Talayco | d8ae758 | 2012-03-23 12:24:56 -0700 | [diff] [blame] | 1080 | class ModifyL2DstIngressMC(BaseMatchCase): |
| 1081 | """ |
| 1082 | Modify the L2 dest and send to the ingress port |
| 1083 | """ |
| 1084 | def runTest(self): |
| 1085 | sup_acts = supported_actions_get(self) |
| 1086 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
| 1087 | skip_message_emit(self, "ModifyL2dstMC test") |
| 1088 | return |
| 1089 | |
| 1090 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1091 | check_test_params=True) |
| 1092 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1093 | action_list=acts, max_test=2, egr_count=-1, |
| 1094 | ing_port=True) |
| 1095 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1096 | class ModifyL2SrcMC(BaseMatchCase): |
| 1097 | """ |
| 1098 | Modify the source MAC address (TP1) and send to multiple |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1099 | """ |
| 1100 | def runTest(self): |
| 1101 | sup_acts = supported_actions_get(self) |
| 1102 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC): |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1103 | skip_message_emit(self, "ModifyL2SrcMC test") |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1104 | return |
| 1105 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1106 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'], |
| 1107 | check_test_params=True) |
| 1108 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1109 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1110 | |
| 1111 | class ModifyL2SrcDstMC(BaseMatchCase): |
| 1112 | """ |
| 1113 | Modify the L2 source and dest and send to 2 ports |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1114 | """ |
| 1115 | def runTest(self): |
| 1116 | sup_acts = supported_actions_get(self) |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1117 | if (not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST) or |
| 1118 | not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC)): |
| 1119 | skip_message_emit(self, "ModifyL2SrcDstMC test") |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1120 | return |
| 1121 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1122 | mod_fields = ['dl_dst', 'dl_src'] |
| 1123 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=mod_fields, |
| 1124 | check_test_params=True) |
| 1125 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1126 | action_list=acts, max_test=2, egr_count=-1) |
| 1127 | |
| 1128 | class ModifyL2DstVIDMC(BaseMatchCase): |
| 1129 | """ |
| 1130 | Modify the L2 dest and send to 2 ports |
| 1131 | """ |
| 1132 | def runTest(self): |
| 1133 | sup_acts = supported_actions_get(self) |
| 1134 | if (not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST) or |
| 1135 | not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID)): |
| 1136 | skip_message_emit(self, "ModifyL2DstVIDMC test") |
| 1137 | return |
| 1138 | |
| 1139 | mod_fields = ['dl_dst', 'dl_vlan'] |
| 1140 | (pkt, exp_pkt, acts) = pkt_action_setup(self, |
| 1141 | start_field_vals={'dl_vlan_enable':True}, mod_fields=mod_fields, |
| 1142 | check_test_params=True) |
| 1143 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1144 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1145 | |
| 1146 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1147 | #@todo Need to implement tagged versions of the above tests |
| 1148 | # |
| 1149 | #@todo Implement a test case that strips tag 2, adds tag 3 |
| 1150 | # and modifies tag 4 to tag 5. Then verify (in addition) that |
| 1151 | # tag 6 does not get modified. |
| 1152 | |
| 1153 | class MixedVLAN(BaseMatchCase): |
| 1154 | """ |
| 1155 | Test mixture of VLAN tag actions |
| 1156 | |
| 1157 | Strip tag 2 on port 1, send to port 2 |
| 1158 | Add tag 3 on port 1, send to port 2 |
| 1159 | Modify tag 4 to 5 on port 1, send to port 2 |
| 1160 | All other traffic from port 1, send to port 3 |
| 1161 | All traffic from port 2 sent to port 4 |
| 1162 | Use exact matches with different packets for all mods |
| 1163 | Verify the following: (port, vid) |
| 1164 | (port 1, vid 2) => VLAN tag stripped, out port 2 |
| 1165 | (port 1, no tag) => tagged packet w/ vid 2 out port 2 |
| 1166 | (port 1, vid 4) => tagged packet w/ vid 5 out port 2 |
| 1167 | (port 1, vid 5) => tagged packet w/ vid 5 out port 2 |
| 1168 | (port 1, vid 6) => tagged packet w/ vid 6 out port 2 |
| 1169 | (port 2, no tag) => untagged packet out port 4 |
| 1170 | (port 2, vid 2-6) => unmodified packet out port 4 |
| 1171 | |
| 1172 | Variation: Might try sending VID 5 to port 3 and check. |
| 1173 | If only VID 5 distinguishes pkt, this will fail on some platforms |
| 1174 | """ |
| 1175 | |
| 1176 | test_prio["MixedVLAN"] = -1 |
| 1177 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1178 | def supported_actions_get(parent, use_cache=True): |
| 1179 | """ |
| 1180 | Get the bitmap of supported actions from the switch |
| 1181 | If use_cache is false, the cached value will be updated |
| 1182 | """ |
| 1183 | global cached_supported_actions |
| 1184 | if cached_supported_actions is None or not use_cache: |
| 1185 | request = message.features_request() |
| 1186 | (reply, pkt) = parent.controller.transact(request, timeout=2) |
| 1187 | parent.assertTrue(reply is not None, "Did not get response to ftr req") |
| 1188 | cached_supported_actions = reply.actions |
| 1189 | pa_logger.info("Supported actions: " + hex(cached_supported_actions)) |
| 1190 | |
| 1191 | return cached_supported_actions |
Tatsuya Yabe | 9c31e22 | 2010-06-16 13:48:02 -0700 | [diff] [blame] | 1192 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 1193 | if __name__ == "__main__": |
| 1194 | print "Please run through oft script: ./oft --test_spec=basic" |