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 |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 31 | import time |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 32 | |
| 33 | from testutils import * |
| 34 | |
| 35 | #@var port_map Local copy of the configuration map from OF port |
| 36 | # numbers to OS interfaces |
| 37 | pa_port_map = None |
| 38 | #@var pa_logger Local logger object |
| 39 | pa_logger = None |
| 40 | #@var pa_config Local copy of global configuration data |
| 41 | pa_config = None |
| 42 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 43 | # For test priority |
| 44 | #@var test_prio Set test priority for local tests |
| 45 | test_prio = {} |
| 46 | |
| 47 | WILDCARD_VALUES = [ofp.OFPFW_IN_PORT, |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 48 | ofp.OFPFW_DL_VLAN | ofp.OFPFW_DL_VLAN_PCP, |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 49 | ofp.OFPFW_DL_SRC, |
| 50 | ofp.OFPFW_DL_DST, |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 51 | (ofp.OFPFW_DL_TYPE | ofp.OFPFW_NW_SRC_ALL | |
| 52 | ofp.OFPFW_NW_DST_ALL | ofp.OFPFW_NW_TOS | ofp.OFPFW_NW_PROTO | |
| 53 | ofp.OFPFW_TP_SRC | ofp.OFPFW_TP_DST), |
| 54 | (ofp.OFPFW_NW_PROTO | ofp.OFPFW_TP_SRC | ofp.OFPFW_TP_DST), |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 55 | ofp.OFPFW_TP_SRC, |
| 56 | ofp.OFPFW_TP_DST, |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 57 | ofp.OFPFW_NW_SRC_MASK, |
| 58 | ofp.OFPFW_NW_DST_MASK, |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 59 | ofp.OFPFW_DL_VLAN_PCP, |
| 60 | ofp.OFPFW_NW_TOS] |
| 61 | |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 62 | NO_WILDCARD_VALUES = [(ofp.OFPFW_ALL ^ ofp.OFPFW_IN_PORT), |
| 63 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_VLAN), |
| 64 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_SRC), |
| 65 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_DST), |
| 66 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE), |
| 67 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO), |
| 68 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO ^ |
| 69 | ofp.OFPFW_TP_SRC), |
| 70 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO ^ |
| 71 | ofp.OFPFW_TP_DST), |
| 72 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO ^ |
| 73 | ofp.OFPFW_NW_SRC_MASK), |
| 74 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO ^ |
| 75 | ofp.OFPFW_NW_DST_MASK), |
| 76 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_VLAN ^ ofp.OFPFW_DL_VLAN_PCP), |
| 77 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO ^ |
| 78 | ofp.OFPFW_NW_TOS)] |
| 79 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 80 | MODIFY_ACTION_VALUES = [ofp.OFPAT_SET_VLAN_VID, |
| 81 | ofp.OFPAT_SET_VLAN_PCP, |
| 82 | ofp.OFPAT_STRIP_VLAN, |
| 83 | ofp.OFPAT_SET_DL_SRC, |
| 84 | ofp.OFPAT_SET_DL_DST, |
| 85 | ofp.OFPAT_SET_NW_SRC, |
| 86 | ofp.OFPAT_SET_NW_DST, |
| 87 | ofp.OFPAT_SET_NW_TOS, |
| 88 | ofp.OFPAT_SET_TP_SRC, |
| 89 | ofp.OFPAT_SET_TP_DST] |
| 90 | |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 91 | TEST_VID_DEFAULT = 2 |
| 92 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 93 | def test_set_init(config): |
| 94 | """ |
| 95 | Set up function for packet action test classes |
| 96 | |
| 97 | @param config The configuration dictionary; see oft |
| 98 | """ |
| 99 | |
Ed Swierk | 89f7835 | 2012-03-29 12:32:32 -0700 | [diff] [blame] | 100 | basic.test_set_init(config) |
| 101 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 102 | global pa_port_map |
| 103 | global pa_logger |
| 104 | global pa_config |
| 105 | |
| 106 | pa_logger = logging.getLogger("pkt_act") |
| 107 | pa_logger.info("Initializing test set") |
| 108 | pa_port_map = config["port_map"] |
| 109 | pa_config = config |
| 110 | |
| 111 | class DirectPacket(basic.SimpleDataPlane): |
| 112 | """ |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 113 | Send packet to single egress port |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 114 | |
| 115 | Generate a packet |
| 116 | Generate and install a matching flow |
| 117 | Add action to direct the packet to an egress port |
| 118 | Send the packet to ingress dataplane port |
| 119 | Verify the packet is received at the egress port only |
| 120 | """ |
| 121 | def runTest(self): |
Tatsuya Yabe | b8fb3c3 | 2010-06-14 15:48:36 -0700 | [diff] [blame] | 122 | self.handleFlow() |
| 123 | |
| 124 | def handleFlow(self, pkttype='TCP'): |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 125 | of_ports = pa_port_map.keys() |
| 126 | of_ports.sort() |
| 127 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 128 | |
Tatsuya Yabe | b8fb3c3 | 2010-06-14 15:48:36 -0700 | [diff] [blame] | 129 | if (pkttype == 'ICMP'): |
| 130 | pkt = simple_icmp_packet() |
| 131 | else: |
| 132 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 133 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 7dd6cd6 | 2010-03-16 15:02:35 -0700 | [diff] [blame] | 134 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 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 | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 143 | ingress_port = of_ports[idx] |
| 144 | egress_port = of_ports[(idx + 1) % len(of_ports)] |
| 145 | pa_logger.info("Ingress " + str(ingress_port) + |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 146 | " to egress " + str(egress_port)) |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 147 | |
| 148 | match.in_port = ingress_port |
| 149 | |
| 150 | request = message.flow_mod() |
| 151 | request.match = match |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 152 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 153 | request.buffer_id = 0xffffffff |
| 154 | act.port = egress_port |
| 155 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 156 | |
| 157 | pa_logger.info("Inserting flow") |
| 158 | rv = self.controller.message_send(request) |
| 159 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 160 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 161 | |
| 162 | pa_logger.info("Sending packet to dp port " + |
| 163 | str(ingress_port)) |
| 164 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 165 | |
| 166 | exp_pkt_arg = None |
| 167 | exp_port = None |
| 168 | if pa_config["relax"]: |
| 169 | exp_pkt_arg = pkt |
| 170 | exp_port = egress_port |
| 171 | |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 172 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(port_number=exp_port, |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 173 | exp_pkt=exp_pkt_arg) |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 174 | self.assertTrue(rcv_pkt is not None, "Did not receive packet") |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 175 | pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 176 | str(rcv_port)) |
| 177 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 178 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 179 | 'Response packet does not match send packet') |
Tatsuya Yabe | b8fb3c3 | 2010-06-14 15:48:36 -0700 | [diff] [blame] | 180 | |
Rich Lane | 51c23b3 | 2012-07-27 16:37:25 -0700 | [diff] [blame] | 181 | class DirectPacketController(basic.SimpleDataPlane): |
| 182 | """ |
| 183 | Send packet to the controller port |
| 184 | |
| 185 | Generate a packet |
| 186 | Generate and install a matching flow |
| 187 | Add action to direct the packet to the controller port |
| 188 | Send the packet to ingress dataplane port |
| 189 | Verify the packet is received at the controller port |
| 190 | """ |
| 191 | def runTest(self): |
| 192 | self.handleFlow() |
| 193 | |
| 194 | def handleFlow(self, pkttype='TCP'): |
| 195 | of_ports = pa_port_map.keys() |
| 196 | of_ports.sort() |
| 197 | self.assertTrue(len(of_ports) > 0, "Not enough ports for test") |
| 198 | |
| 199 | if (pkttype == 'ICMP'): |
| 200 | pkt = simple_icmp_packet() |
| 201 | else: |
| 202 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 203 | match = packet_to_flow_match(self, pkt) |
Rich Lane | 51c23b3 | 2012-07-27 16:37:25 -0700 | [diff] [blame] | 204 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 205 | self.assertTrue(match is not None, |
| 206 | "Could not generate flow match from pkt") |
| 207 | act = action.action_output() |
| 208 | |
| 209 | rv = delete_all_flows(self.controller, pa_logger) |
| 210 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 211 | |
| 212 | ingress_port = of_ports[0] |
| 213 | match.in_port = ingress_port |
| 214 | |
| 215 | request = message.flow_mod() |
| 216 | request.match = match |
| 217 | |
| 218 | request.buffer_id = 0xffffffff |
| 219 | act.port = ofp.OFPP_CONTROLLER |
| 220 | act.max_len = 65535 |
| 221 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 222 | |
| 223 | pa_logger.info("Inserting flow") |
| 224 | rv = self.controller.message_send(request) |
| 225 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 226 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 227 | |
| 228 | pa_logger.info("Sending packet to dp port " + |
| 229 | str(ingress_port)) |
| 230 | self.dataplane.send(ingress_port, str(pkt)) |
| 231 | |
| 232 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN) |
| 233 | |
| 234 | self.assertTrue(response is not None, |
| 235 | 'Packet in message not received by controller') |
| 236 | if not dataplane.match_exp_pkt(pkt, response.data): |
| 237 | pa_logger.debug("Sent %s" % format_packet(pkt)) |
| 238 | pa_logger.debug("Resp %s" % format_packet(response.data)) |
| 239 | self.assertTrue(False, |
| 240 | 'Response packet does not match send packet' + |
| 241 | ' for controller port') |
| 242 | |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 243 | |
| 244 | class DirectPacketQueue(basic.SimpleDataPlane): |
| 245 | """ |
| 246 | Send packet to single queue on single egress port |
| 247 | |
| 248 | Generate a packet |
| 249 | Generate and install a matching flow |
| 250 | Add action to direct the packet to an egress port and queue |
| 251 | Send the packet to ingress dataplane port |
| 252 | Verify the packet is received at the egress port only |
| 253 | """ |
| 254 | def runTest(self): |
| 255 | self.handleFlow() |
| 256 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 257 | def portQueuesGet(self, queue_stats, port_num): |
| 258 | result = [] |
| 259 | for qs in queue_stats.stats: |
| 260 | if qs.port_no != port_num: |
| 261 | continue |
| 262 | result.append(qs.queue_id) |
| 263 | return result |
| 264 | |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 265 | def handleFlow(self, pkttype='TCP'): |
| 266 | of_ports = pa_port_map.keys() |
| 267 | of_ports.sort() |
| 268 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 269 | |
| 270 | if (pkttype == 'ICMP'): |
| 271 | pkt = simple_icmp_packet() |
| 272 | else: |
| 273 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 274 | match = packet_to_flow_match(self, pkt) |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 275 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 276 | self.assertTrue(match is not None, |
| 277 | "Could not generate flow match from pkt") |
| 278 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 279 | # Get queue stats from switch |
| 280 | |
| 281 | request = message.queue_stats_request() |
| 282 | request.port_no = ofp.OFPP_ALL |
| 283 | request.queue_id = ofp.OFPQ_ALL |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 284 | (queue_stats, p) = self.controller.transact(request) |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 285 | self.assertNotEqual(queue_stats, None, "Queue stats request failed") |
| 286 | |
| 287 | act = action.action_enqueue() |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 288 | |
| 289 | for idx in range(len(of_ports)): |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 290 | ingress_port = of_ports[idx] |
| 291 | egress_port = of_ports[(idx + 1) % len(of_ports)] |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 292 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 293 | for egress_queue_id in self.portQueuesGet(queue_stats, egress_port): |
| 294 | pa_logger.info("Ingress " + str(ingress_port) |
| 295 | + " to egress " + str(egress_port) |
| 296 | + " queue " + str(egress_queue_id) |
| 297 | ) |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 298 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 299 | rv = delete_all_flows(self.controller, pa_logger) |
| 300 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 301 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 302 | match.in_port = ingress_port |
| 303 | |
| 304 | request = message.flow_mod() |
| 305 | request.match = match |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 306 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 307 | request.buffer_id = 0xffffffff |
| 308 | act.port = egress_port |
| 309 | act.queue_id = egress_queue_id |
| 310 | self.assertTrue(request.actions.add(act), "Could not add action") |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 311 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 312 | pa_logger.info("Inserting flow") |
| 313 | rv = self.controller.message_send(request) |
| 314 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 315 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 316 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 317 | # Get current stats for selected egress queue |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 318 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 319 | request = message.queue_stats_request() |
| 320 | request.port_no = egress_port |
| 321 | request.queue_id = egress_queue_id |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 322 | (qs_before, p) = self.controller.transact(request) |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 323 | self.assertNotEqual(qs_before, None, "Queue stats request failed") |
| 324 | |
| 325 | pa_logger.info("Sending packet to dp port " + |
| 326 | str(ingress_port)) |
| 327 | self.dataplane.send(ingress_port, str(pkt)) |
| 328 | |
| 329 | exp_pkt_arg = None |
| 330 | exp_port = None |
| 331 | if pa_config["relax"]: |
| 332 | exp_pkt_arg = pkt |
| 333 | exp_port = egress_port |
| 334 | |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 335 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(port_number=exp_port, |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 336 | exp_pkt=exp_pkt_arg) |
| 337 | self.assertTrue(rcv_pkt is not None, "Did not receive packet") |
| 338 | pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + |
| 339 | str(rcv_port)) |
| 340 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 341 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 342 | 'Response packet does not match send packet') |
| 343 | |
Ed Swierk | b8a8651 | 2012-04-18 18:45:58 -0700 | [diff] [blame] | 344 | # FIXME: instead of sleeping, keep requesting queue stats until |
| 345 | # the expected queue counter increases or some large timeout is |
| 346 | # reached |
| 347 | time.sleep(2) |
| 348 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 349 | # Get current stats for selected egress queue again |
| 350 | |
| 351 | request = message.queue_stats_request() |
| 352 | request.port_no = egress_port |
| 353 | request.queue_id = egress_queue_id |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 354 | (qs_after, p) = self.controller.transact(request) |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 355 | self.assertNotEqual(qs_after, None, "Queue stats request failed") |
| 356 | |
| 357 | # Make sure that tx packet counter for selected egress queue was |
| 358 | # incremented |
| 359 | |
Ed Swierk | 22f5915 | 2012-04-17 16:36:47 -0700 | [diff] [blame] | 360 | self.assertEqual(qs_after.stats[0].tx_packets, \ |
| 361 | qs_before.stats[0].tx_packets + 1, \ |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 362 | "Verification of egress queue tx packet count failed" |
| 363 | ) |
| 364 | |
| 365 | |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 366 | class DirectPacketControllerQueue(basic.SimpleDataPlane): |
| 367 | """ |
| 368 | Send a packet from each of the openflow ports |
| 369 | to each of the queues configured on the controller port. |
| 370 | If no queues have been configured, no packets are sent. |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 371 | |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 372 | Generate a packet |
| 373 | Generate and install a matching flow |
| 374 | Add action to direct the packet to one of the controller port queues |
| 375 | Send the packet to ingress dataplane port |
| 376 | Verify the packet is received on the controller port queue |
| 377 | """ |
| 378 | def runTest(self): |
| 379 | self.handleFlow() |
| 380 | |
| 381 | def portQueuesGet(self, queue_stats, port_num): |
| 382 | result = [] |
| 383 | for qs in queue_stats.stats: |
| 384 | if qs.port_no != port_num: |
| 385 | continue |
| 386 | result.append(qs.queue_id) |
| 387 | return result |
| 388 | |
| 389 | def handleFlow(self, pkttype='TCP'): |
| 390 | of_ports = pa_port_map.keys() |
| 391 | of_ports.sort() |
| 392 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 393 | |
| 394 | if (pkttype == 'ICMP'): |
| 395 | pkt = simple_icmp_packet() |
| 396 | else: |
| 397 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 398 | match = packet_to_flow_match(self, pkt) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 399 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 400 | self.assertTrue(match is not None, |
| 401 | "Could not generate flow match from pkt") |
| 402 | |
| 403 | # Get queue stats from switch |
| 404 | |
| 405 | request = message.queue_stats_request() |
| 406 | request.port_no = ofp.OFPP_CONTROLLER |
| 407 | request.queue_id = ofp.OFPQ_ALL |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 408 | (queue_stats, p) = self.controller.transact(request) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 409 | self.assertNotEqual(queue_stats, None, "Queue stats request failed") |
| 410 | |
| 411 | act = action.action_enqueue() |
| 412 | |
| 413 | for idx in range(len(of_ports)): |
| 414 | ingress_port = of_ports[idx] |
| 415 | egress_port = ofp.OFPP_CONTROLLER |
| 416 | |
| 417 | pa_logger.info("Ingress port " + str(ingress_port) |
| 418 | + ", controller port queues " |
| 419 | + str(self.portQueuesGet(queue_stats, egress_port))) |
| 420 | |
| 421 | for egress_queue_id in self.portQueuesGet(queue_stats, egress_port): |
| 422 | pa_logger.info("Ingress " + str(ingress_port) |
| 423 | + " to egress " + str(egress_port) |
| 424 | + " queue " + str(egress_queue_id) |
| 425 | ) |
| 426 | |
| 427 | rv = delete_all_flows(self.controller, pa_logger) |
| 428 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 429 | |
| 430 | match.in_port = ingress_port |
| 431 | |
| 432 | request = message.flow_mod() |
| 433 | request.match = match |
| 434 | |
| 435 | request.buffer_id = 0xffffffff |
| 436 | act.port = egress_port |
| 437 | act.queue_id = egress_queue_id |
| 438 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 439 | |
| 440 | pa_logger.info("Inserting flow") |
| 441 | rv = self.controller.message_send(request) |
| 442 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 443 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 444 | |
| 445 | # Get current stats for selected egress queue |
| 446 | |
| 447 | request = message.queue_stats_request() |
| 448 | request.port_no = egress_port |
| 449 | request.queue_id = egress_queue_id |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 450 | (qs_before, p) = self.controller.transact(request) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 451 | self.assertNotEqual(qs_before, None, "Queue stats request failed") |
| 452 | |
| 453 | pa_logger.info("Sending packet to dp port " + |
| 454 | str(ingress_port)) |
| 455 | self.dataplane.send(ingress_port, str(pkt)) |
| 456 | |
| 457 | exp_pkt_arg = None |
| 458 | exp_port = None |
| 459 | |
| 460 | while True: |
| 461 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, 2) |
| 462 | if not response: # Timeout |
| 463 | break |
| 464 | if dataplane.match_exp_pkt(pkt, response.data): # Got match |
| 465 | break |
| 466 | if not basic_config["relax"]: # Only one attempt to match |
| 467 | break |
| 468 | count += 1 |
| 469 | if count > 10: # Too many tries |
| 470 | break |
| 471 | |
| 472 | self.assertTrue(response is not None, |
| 473 | 'Packet in message not received by controller') |
| 474 | if not dataplane.match_exp_pkt(pkt, response.data): |
| 475 | basic_logger.debug("Sent %s" % format_packet(pkt)) |
| 476 | basic_logger.debug("Resp %s" % format_packet(response.data)) |
| 477 | self.assertTrue(False, |
| 478 | 'Response packet does not match send packet' + |
| 479 | ' for controller port') |
| 480 | |
| 481 | # FIXME: instead of sleeping, keep requesting queue stats until |
| 482 | # the expected queue counter increases or some large timeout is |
| 483 | # reached |
| 484 | time.sleep(2) |
| 485 | |
| 486 | # Get current stats for selected egress queue again |
| 487 | |
| 488 | request = message.queue_stats_request() |
| 489 | request.port_no = egress_port |
| 490 | request.queue_id = egress_queue_id |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 491 | (qs_after, p) = self.controller.transact(request) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 492 | self.assertNotEqual(qs_after, None, "Queue stats request failed") |
| 493 | |
| 494 | # Make sure that tx packet counter for selected egress queue was |
| 495 | # incremented |
| 496 | |
| 497 | self.assertEqual(qs_after.stats[0].tx_packets, \ |
| 498 | qs_before.stats[0].tx_packets + 1, \ |
| 499 | "Verification of egress queue tx packet count failed" |
| 500 | ) |
| 501 | |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 502 | |
Tatsuya Yabe | b8fb3c3 | 2010-06-14 15:48:36 -0700 | [diff] [blame] | 503 | class DirectPacketICMP(DirectPacket): |
| 504 | """ |
| 505 | Send ICMP packet to single egress port |
| 506 | |
| 507 | Generate a ICMP packet |
| 508 | Generate and install a matching flow |
| 509 | Add action to direct the packet to an egress port |
| 510 | Send the packet to ingress dataplane port |
| 511 | Verify the packet is received at the egress port only |
| 512 | Difference from DirectPacket test is that sent packet is ICMP |
| 513 | """ |
| 514 | def runTest(self): |
| 515 | self.handleFlow(pkttype='ICMP') |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 516 | |
| 517 | class DirectTwoPorts(basic.SimpleDataPlane): |
| 518 | """ |
| 519 | Send packet to two egress ports |
| 520 | |
| 521 | Generate a packet |
| 522 | Generate and install a matching flow |
| 523 | Add action to direct the packet to two egress ports |
| 524 | Send the packet to ingress dataplane port |
| 525 | Verify the packet is received at the two egress ports |
| 526 | """ |
| 527 | def runTest(self): |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 528 | of_ports = pa_port_map.keys() |
| 529 | of_ports.sort() |
| 530 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 531 | |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 532 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 533 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 534 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 535 | self.assertTrue(match is not None, |
| 536 | "Could not generate flow match from pkt") |
| 537 | act = action.action_output() |
| 538 | |
| 539 | for idx in range(len(of_ports)): |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 540 | rv = delete_all_flows(self.controller, pa_logger) |
| 541 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 542 | |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 543 | ingress_port = of_ports[idx] |
| 544 | egress_port1 = of_ports[(idx + 1) % len(of_ports)] |
| 545 | egress_port2 = of_ports[(idx + 2) % len(of_ports)] |
| 546 | pa_logger.info("Ingress " + str(ingress_port) + |
| 547 | " to egress " + str(egress_port1) + " and " + |
| 548 | str(egress_port2)) |
| 549 | |
| 550 | match.in_port = ingress_port |
| 551 | |
| 552 | request = message.flow_mod() |
| 553 | request.match = match |
| 554 | request.buffer_id = 0xffffffff |
| 555 | act.port = egress_port1 |
| 556 | self.assertTrue(request.actions.add(act), "Could not add action1") |
| 557 | act.port = egress_port2 |
| 558 | self.assertTrue(request.actions.add(act), "Could not add action2") |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 559 | # pa_logger.info(request.show()) |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 560 | |
| 561 | pa_logger.info("Inserting flow") |
| 562 | rv = self.controller.message_send(request) |
| 563 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 564 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 565 | |
| 566 | pa_logger.info("Sending packet to dp port " + |
| 567 | str(ingress_port)) |
| 568 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 569 | yes_ports = set([egress_port1, egress_port2]) |
| 570 | no_ports = set(of_ports).difference(yes_ports) |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 571 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 572 | receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 573 | self, pa_logger, pa_config) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 574 | |
| 575 | class DirectMCNonIngress(basic.SimpleDataPlane): |
| 576 | """ |
| 577 | Multicast to all non-ingress ports |
| 578 | |
| 579 | Generate a packet |
| 580 | Generate and install a matching flow |
| 581 | Add action to direct the packet to all non-ingress ports |
| 582 | Send the packet to ingress dataplane port |
| 583 | Verify the packet is received at all non-ingress ports |
| 584 | |
| 585 | Does not use the flood action |
| 586 | """ |
| 587 | def runTest(self): |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 588 | of_ports = pa_port_map.keys() |
| 589 | of_ports.sort() |
| 590 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 591 | |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 592 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 593 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 594 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 595 | self.assertTrue(match is not None, |
| 596 | "Could not generate flow match from pkt") |
| 597 | act = action.action_output() |
| 598 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 599 | for ingress_port in of_ports: |
| 600 | rv = delete_all_flows(self.controller, pa_logger) |
| 601 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 602 | |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 603 | pa_logger.info("Ingress " + str(ingress_port) + |
| 604 | " all non-ingress ports") |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 605 | match.in_port = ingress_port |
| 606 | |
| 607 | request = message.flow_mod() |
| 608 | request.match = match |
| 609 | request.buffer_id = 0xffffffff |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 610 | for egress_port in of_ports: |
| 611 | if egress_port == ingress_port: |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 612 | continue |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 613 | act.port = egress_port |
| 614 | self.assertTrue(request.actions.add(act), |
| 615 | "Could not add output to " + str(egress_port)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 616 | pa_logger.debug(request.show()) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 617 | |
| 618 | pa_logger.info("Inserting flow") |
| 619 | rv = self.controller.message_send(request) |
| 620 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 621 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 622 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 623 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 624 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 625 | yes_ports = set(of_ports).difference([ingress_port]) |
| 626 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 627 | self, pa_logger, pa_config) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 628 | |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 629 | |
| 630 | class DirectMC(basic.SimpleDataPlane): |
| 631 | """ |
| 632 | Multicast to all ports including ingress |
| 633 | |
| 634 | Generate a packet |
| 635 | Generate and install a matching flow |
| 636 | Add action to direct the packet to all non-ingress ports |
| 637 | Send the packet to ingress dataplane port |
| 638 | Verify the packet is received at all ports |
| 639 | |
| 640 | Does not use the flood action |
| 641 | """ |
| 642 | def runTest(self): |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 643 | of_ports = pa_port_map.keys() |
| 644 | of_ports.sort() |
| 645 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 646 | |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 647 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 648 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 649 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 650 | self.assertTrue(match is not None, |
| 651 | "Could not generate flow match from pkt") |
| 652 | act = action.action_output() |
| 653 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 654 | for ingress_port in of_ports: |
| 655 | rv = delete_all_flows(self.controller, pa_logger) |
| 656 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 657 | |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 658 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 659 | match.in_port = ingress_port |
| 660 | |
| 661 | request = message.flow_mod() |
| 662 | request.match = match |
| 663 | request.buffer_id = 0xffffffff |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 664 | for egress_port in of_ports: |
| 665 | if egress_port == ingress_port: |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 666 | act.port = ofp.OFPP_IN_PORT |
| 667 | else: |
| 668 | act.port = egress_port |
| 669 | self.assertTrue(request.actions.add(act), |
| 670 | "Could not add output to " + str(egress_port)) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 671 | # pa_logger.info(request.show()) |
| 672 | |
| 673 | pa_logger.info("Inserting flow") |
| 674 | rv = self.controller.message_send(request) |
| 675 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 676 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 677 | |
| 678 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 679 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 680 | receive_pkt_check(self.dataplane, pkt, of_ports, [], self, |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 681 | pa_logger, pa_config) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 682 | |
| 683 | class Flood(basic.SimpleDataPlane): |
| 684 | """ |
| 685 | Flood to all ports except ingress |
| 686 | |
| 687 | Generate a packet |
| 688 | Generate and install a matching flow |
| 689 | Add action to flood the packet |
| 690 | Send the packet to ingress dataplane port |
| 691 | Verify the packet is received at all other ports |
| 692 | """ |
| 693 | def runTest(self): |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 694 | of_ports = pa_port_map.keys() |
| 695 | of_ports.sort() |
| 696 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 697 | |
| 698 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 699 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 700 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 701 | self.assertTrue(match is not None, |
| 702 | "Could not generate flow match from pkt") |
| 703 | act = action.action_output() |
| 704 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 705 | for ingress_port in of_ports: |
| 706 | rv = delete_all_flows(self.controller, pa_logger) |
| 707 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 708 | |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 709 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 710 | match.in_port = ingress_port |
| 711 | |
| 712 | request = message.flow_mod() |
| 713 | request.match = match |
| 714 | request.buffer_id = 0xffffffff |
| 715 | act.port = ofp.OFPP_FLOOD |
| 716 | self.assertTrue(request.actions.add(act), |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 717 | "Could not add flood port action") |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 718 | pa_logger.info(request.show()) |
| 719 | |
| 720 | pa_logger.info("Inserting flow") |
| 721 | rv = self.controller.message_send(request) |
| 722 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 723 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 724 | |
| 725 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 726 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 727 | yes_ports = set(of_ports).difference([ingress_port]) |
| 728 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 729 | self, pa_logger, pa_config) |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 730 | |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 731 | class FloodPlusIngress(basic.SimpleDataPlane): |
| 732 | """ |
| 733 | Flood to all ports plus send to ingress port |
| 734 | |
| 735 | Generate a packet |
| 736 | Generate and install a matching flow |
| 737 | Add action to flood the packet |
| 738 | Add action to send to ingress port |
| 739 | Send the packet to ingress dataplane port |
| 740 | Verify the packet is received at all other ports |
| 741 | """ |
| 742 | def runTest(self): |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 743 | of_ports = pa_port_map.keys() |
| 744 | of_ports.sort() |
| 745 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 746 | |
| 747 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 748 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 749 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 750 | self.assertTrue(match is not None, |
| 751 | "Could not generate flow match from pkt") |
| 752 | act = action.action_output() |
| 753 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 754 | for ingress_port in of_ports: |
| 755 | rv = delete_all_flows(self.controller, pa_logger) |
| 756 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 757 | |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 758 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 759 | match.in_port = ingress_port |
| 760 | |
| 761 | request = message.flow_mod() |
| 762 | request.match = match |
| 763 | request.buffer_id = 0xffffffff |
| 764 | act.port = ofp.OFPP_FLOOD |
| 765 | self.assertTrue(request.actions.add(act), |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 766 | "Could not add flood port action") |
| 767 | act.port = ofp.OFPP_IN_PORT |
| 768 | self.assertTrue(request.actions.add(act), |
| 769 | "Could not add ingress port for output") |
| 770 | pa_logger.info(request.show()) |
| 771 | |
| 772 | pa_logger.info("Inserting flow") |
| 773 | rv = self.controller.message_send(request) |
| 774 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 775 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 776 | |
| 777 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 778 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 779 | receive_pkt_check(self.dataplane, pkt, of_ports, [], self, |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 780 | pa_logger, pa_config) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 781 | |
| 782 | class All(basic.SimpleDataPlane): |
| 783 | """ |
| 784 | Send to OFPP_ALL port |
| 785 | |
| 786 | Generate a packet |
| 787 | Generate and install a matching flow |
| 788 | Add action to forward to OFPP_ALL |
| 789 | Send the packet to ingress dataplane port |
| 790 | Verify the packet is received at all other ports |
| 791 | """ |
| 792 | def runTest(self): |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 793 | of_ports = pa_port_map.keys() |
| 794 | of_ports.sort() |
| 795 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 796 | |
| 797 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 798 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 799 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 800 | self.assertTrue(match is not None, |
| 801 | "Could not generate flow match from pkt") |
| 802 | act = action.action_output() |
| 803 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 804 | for ingress_port in of_ports: |
| 805 | rv = delete_all_flows(self.controller, pa_logger) |
| 806 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 807 | |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 808 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 809 | match.in_port = ingress_port |
| 810 | |
| 811 | request = message.flow_mod() |
| 812 | request.match = match |
| 813 | request.buffer_id = 0xffffffff |
| 814 | act.port = ofp.OFPP_ALL |
| 815 | self.assertTrue(request.actions.add(act), |
| 816 | "Could not add ALL port action") |
| 817 | pa_logger.info(request.show()) |
| 818 | |
| 819 | pa_logger.info("Inserting flow") |
| 820 | rv = self.controller.message_send(request) |
| 821 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 822 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 823 | |
| 824 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 825 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 826 | yes_ports = set(of_ports).difference([ingress_port]) |
| 827 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 828 | self, pa_logger, pa_config) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 829 | |
| 830 | class AllPlusIngress(basic.SimpleDataPlane): |
| 831 | """ |
| 832 | Send to OFPP_ALL port and ingress port |
| 833 | |
| 834 | Generate a packet |
| 835 | Generate and install a matching flow |
| 836 | Add action to forward to OFPP_ALL |
| 837 | Add action to forward to ingress port |
| 838 | Send the packet to ingress dataplane port |
| 839 | Verify the packet is received at all other ports |
| 840 | """ |
| 841 | def runTest(self): |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 842 | of_ports = pa_port_map.keys() |
| 843 | of_ports.sort() |
| 844 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 845 | |
| 846 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 847 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 848 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 849 | self.assertTrue(match is not None, |
| 850 | "Could not generate flow match from pkt") |
| 851 | act = action.action_output() |
| 852 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 853 | for ingress_port in of_ports: |
| 854 | rv = delete_all_flows(self.controller, pa_logger) |
| 855 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 856 | |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 857 | pa_logger.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 858 | match.in_port = ingress_port |
| 859 | |
| 860 | request = message.flow_mod() |
| 861 | request.match = match |
| 862 | request.buffer_id = 0xffffffff |
| 863 | act.port = ofp.OFPP_ALL |
| 864 | self.assertTrue(request.actions.add(act), |
| 865 | "Could not add ALL port action") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 866 | act.port = ofp.OFPP_IN_PORT |
| 867 | self.assertTrue(request.actions.add(act), |
| 868 | "Could not add ingress port for output") |
| 869 | pa_logger.info(request.show()) |
| 870 | |
| 871 | pa_logger.info("Inserting flow") |
| 872 | rv = self.controller.message_send(request) |
| 873 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 874 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 875 | |
| 876 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 877 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 878 | receive_pkt_check(self.dataplane, pkt, of_ports, [], self, |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 879 | pa_logger, pa_config) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 880 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 881 | class FloodMinusPort(basic.SimpleDataPlane): |
| 882 | """ |
| 883 | Config port with No_Flood and test Flood action |
| 884 | |
| 885 | Generate a packet |
| 886 | Generate a matching flow |
| 887 | Add action to forward to OFPP_ALL |
| 888 | Set port to no-flood |
| 889 | Send the packet to ingress dataplane port |
| 890 | Verify the packet is received at all other ports except |
| 891 | the ingress port and the no_flood port |
| 892 | """ |
| 893 | def runTest(self): |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 894 | of_ports = pa_port_map.keys() |
| 895 | of_ports.sort() |
| 896 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 897 | |
| 898 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 899 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 900 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 901 | self.assertTrue(match is not None, |
| 902 | "Could not generate flow match from pkt") |
| 903 | act = action.action_output() |
| 904 | |
| 905 | for idx in range(len(of_ports)): |
| 906 | rv = delete_all_flows(self.controller, pa_logger) |
| 907 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 908 | |
| 909 | ingress_port = of_ports[idx] |
| 910 | no_flood_idx = (idx + 1) % len(of_ports) |
| 911 | no_flood_port = of_ports[no_flood_idx] |
| 912 | rv = port_config_set(self.controller, no_flood_port, |
| 913 | ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD, |
| 914 | pa_logger) |
| 915 | self.assertEqual(rv, 0, "Failed to set port config") |
| 916 | |
| 917 | match.in_port = ingress_port |
| 918 | |
| 919 | request = message.flow_mod() |
| 920 | request.match = match |
| 921 | request.buffer_id = 0xffffffff |
| 922 | act.port = ofp.OFPP_FLOOD |
| 923 | self.assertTrue(request.actions.add(act), |
| 924 | "Could not add flood port action") |
| 925 | pa_logger.info(request.show()) |
| 926 | |
| 927 | pa_logger.info("Inserting flow") |
| 928 | rv = self.controller.message_send(request) |
| 929 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 930 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 931 | |
| 932 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 933 | pa_logger.info("No flood port is " + str(no_flood_port)) |
| 934 | self.dataplane.send(ingress_port, str(pkt)) |
| 935 | no_ports = set([ingress_port, no_flood_port]) |
| 936 | yes_ports = set(of_ports).difference(no_ports) |
| 937 | receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, self, |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 938 | pa_logger, pa_config) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 939 | |
| 940 | # Turn no flood off again |
| 941 | rv = port_config_set(self.controller, no_flood_port, |
| 942 | 0, ofp.OFPPC_NO_FLOOD, pa_logger) |
| 943 | self.assertEqual(rv, 0, "Failed to reset port config") |
| 944 | |
| 945 | #@todo Should check no other packets received |
| 946 | |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 947 | |
| 948 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 949 | ################################################################ |
| 950 | |
| 951 | class BaseMatchCase(basic.SimpleDataPlane): |
| 952 | def setUp(self): |
| 953 | basic.SimpleDataPlane.setUp(self) |
| 954 | self.logger = pa_logger |
| 955 | def runTest(self): |
| 956 | self.logger.info("BaseMatchCase") |
| 957 | |
| 958 | class ExactMatch(BaseMatchCase): |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 959 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 960 | Exercise exact matching for all port pairs |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 961 | |
| 962 | Generate a packet |
| 963 | Generate and install a matching flow without wildcard mask |
| 964 | Add action to forward to a port |
| 965 | Send the packet to the port |
| 966 | 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] | 967 | """ |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 968 | |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 969 | def runTest(self): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 970 | flow_match_test(self, pa_port_map) |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 971 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 972 | class ExactMatchTagged(BaseMatchCase): |
| 973 | """ |
| 974 | Exact match for all port pairs with tagged pkts |
| 975 | """ |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 976 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 977 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 978 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 979 | flow_match_test(self, pa_port_map, dl_vlan=vid) |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 980 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 981 | class ExactMatchTaggedMany(BaseMatchCase): |
| 982 | """ |
| 983 | ExactMatchTagged with many VLANS |
| 984 | """ |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 985 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 986 | def runTest(self): |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 987 | for vid in range(2,100,10): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 988 | flow_match_test(self, pa_port_map, dl_vlan=vid, max_test=5) |
| 989 | for vid in range(100,4000,389): |
| 990 | flow_match_test(self, pa_port_map, dl_vlan=vid, max_test=5) |
| 991 | 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] | 992 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 993 | # Don't run by default |
| 994 | test_prio["ExactMatchTaggedMany"] = -1 |
Tatsuya Yabe | cdf575e | 2010-05-25 16:56:38 -0700 | [diff] [blame] | 995 | |
Tatsuya Yabe | cdf575e | 2010-05-25 16:56:38 -0700 | [diff] [blame] | 996 | |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 997 | class SingleWildcardMatchPriority(BaseMatchCase): |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 998 | """ |
| 999 | SingleWildcardMatchPriority |
| 1000 | """ |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1001 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1002 | def _Init(self): |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1003 | self.pkt = simple_tcp_packet() |
| 1004 | self.flowMsgs = {} |
| 1005 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1006 | def _ClearTable(self): |
| 1007 | rc = delete_all_flows(self.controller, self.logger) |
| 1008 | self.assertEqual(rc, 0, "Failed to delete all flows") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 1009 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1010 | |
| 1011 | def runTest(self): |
| 1012 | |
| 1013 | self._Init() |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1014 | of_ports = pa_port_map.keys() |
| 1015 | of_ports.sort() |
| 1016 | |
| 1017 | # Delete the initial flow table |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1018 | self._ClearTable() |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1019 | |
| 1020 | # Run several combinations, each at lower priority settings. |
| 1021 | # At the end of each call to runPrioFlows(), the table should |
| 1022 | # be empty. If its not, we'll catch it as the priorities decreases |
| 1023 | portA = of_ports[0] |
| 1024 | portB = of_ports[1] |
| 1025 | portC = of_ports[2] |
| 1026 | |
| 1027 | # TODO -- these priority numbers should be validated somehow? |
| 1028 | self.runPrioFlows(portA, portB, portC, 1000, 999) |
| 1029 | self.runPrioFlows(portB, portC, portA, 998, 997) |
| 1030 | self.runPrioFlows(portC, portA, portB, 996, 995) |
| 1031 | self.runPrioFlows(portA, portC, portB, 994, 993) |
| 1032 | |
| 1033 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1034 | |
| 1035 | def runPrioFlows(self, portA, portB, portC, prioHigher, prioLower, |
| 1036 | clearTable=False): |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1037 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1038 | if clearTable: |
| 1039 | self._ClearTable() |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1040 | |
| 1041 | # Sanity check flow at lower priority from pA to pB |
| 1042 | self.logger.info("runPrioFlows(pA=%d,pB=%d,pC=%d,ph=%d,pl=%d" |
| 1043 | % (portA, portB, portC, prioHigher, prioLower)) |
| 1044 | |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1045 | # Sanity check flow at lower priority from pA to pC |
| 1046 | self.installFlow(prioLower, portA, portC) |
| 1047 | self.verifyFlow(portA, portC) |
| 1048 | self.removeFlow(prioLower) |
| 1049 | |
| 1050 | # Install and verify pA->pB @ prioLower |
| 1051 | self.installFlow(prioLower, portA, portB) |
| 1052 | self.verifyFlow(portA, portB) |
| 1053 | |
| 1054 | # Install and verify pA->pC @ prioHigher, should override pA->pB |
| 1055 | self.installFlow(prioHigher, portA, portC) |
| 1056 | self.verifyFlow(portA, portC) |
| 1057 | # remove pA->pC |
| 1058 | self.removeFlow(prioHigher) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1059 | # Old flow pA -> pB @ prioLower should still be active |
| 1060 | self.verifyFlow(portA, portB) |
| 1061 | self.removeFlow(prioLower) |
| 1062 | |
| 1063 | # Table should be empty at this point, leave it alone as |
| 1064 | # an assumption for future test runs |
| 1065 | |
| 1066 | |
| 1067 | |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1068 | def installFlow(self, prio, inp, egp, |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1069 | wildcards=ofp.OFPFW_DL_SRC): |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1070 | wildcards |= required_wildcards(self) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1071 | request = flow_msg_create(self, self.pkt, ing_port=inp, |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1072 | wildcards=wildcards, |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1073 | egr_ports=egp) |
| 1074 | request.priority = prio |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1075 | self.logger.debug("Install flow with priority " + str(prio)) |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1076 | flow_msg_install(self, request, clear_table_override=False) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1077 | self.flowMsgs[prio] = request |
| 1078 | |
| 1079 | def removeFlow(self, prio): |
| 1080 | if self.flowMsgs.has_key(prio): |
| 1081 | msg = self.flowMsgs[prio] |
| 1082 | msg.command = ofp.OFPFC_DELETE_STRICT |
| 1083 | # This *must* be set for DELETE |
| 1084 | msg.out_port = ofp.OFPP_NONE |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1085 | self.logger.debug("Remove flow with priority " + str(prio)) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1086 | self.controller.message_send(msg) |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 1087 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1088 | else: |
| 1089 | raise Exception("Not initialized") |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1090 | |
| 1091 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1092 | def verifyFlow(self, inp, egp, pkt=None): |
| 1093 | if pkt == None: |
| 1094 | pkt = self.pkt |
| 1095 | |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1096 | self.logger.info("Pkt match test: " + str(inp) + |
| 1097 | " to " + str(egp)) |
| 1098 | self.logger.debug("Send packet: " + str(inp) + " to " |
| 1099 | + str(egp)) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1100 | self.dataplane.send(inp, str(pkt)) |
| 1101 | receive_pkt_verify(self, egp, pkt, inp) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1102 | |
| 1103 | |
| 1104 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1105 | class SingleWildcardMatchPriorityInsertModifyDelete(SingleWildcardMatchPriority): |
| 1106 | |
| 1107 | def runTest(self): |
| 1108 | |
| 1109 | self._Init() |
| 1110 | |
| 1111 | of_ports = pa_port_map.keys() |
| 1112 | of_ports.sort() |
| 1113 | |
| 1114 | # Install an entry from 0 -> 1 @ prio 1000 |
| 1115 | self._ClearTable() |
| 1116 | self.installFlow(1000, of_ports[0], of_ports[1]) |
| 1117 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1118 | self.installFlow(1000, of_ports[1], of_ports[0]) |
| 1119 | self.verifyFlow(of_ports[1], of_ports[0]) |
| 1120 | self.installFlow(1001, of_ports[0], of_ports[1]) |
| 1121 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1122 | self.installFlow(1001, of_ports[1], of_ports[0]) |
| 1123 | self.verifyFlow(of_ports[1], of_ports[0]) |
| 1124 | self.removeFlow(1001) |
| 1125 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1126 | self.removeFlow(1000) |
| 1127 | |
| 1128 | |
| 1129 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1130 | class WildcardPriority(SingleWildcardMatchPriority): |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1131 | """ |
| 1132 | 1. Add wildcard flow, verify packet received. |
| 1133 | 2. Add exact match flow with higher priority, verify packet received |
| 1134 | on port specified by this flow. |
| 1135 | 3. Add wildcard flow with even higher priority, verify packet received |
| 1136 | on port specified by this flow. |
| 1137 | """ |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1138 | |
| 1139 | def runTest(self): |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1140 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1141 | self._Init() |
| 1142 | |
| 1143 | of_ports = pa_port_map.keys() |
| 1144 | of_ports.sort() |
| 1145 | |
| 1146 | self._ClearTable() |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1147 | |
| 1148 | # Install a flow with wildcards |
| 1149 | self.installFlow(999, of_ports[0], of_ports[1], |
| 1150 | wildcards=ofp.OFPFW_DL_DST) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1151 | self.verifyFlow(of_ports[0], of_ports[1]) |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1152 | # Install a flow with no wildcards for our packet |
| 1153 | self.installFlow(1000, of_ports[0], of_ports[2], wildcards=0) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1154 | self.verifyFlow(of_ports[0], of_ports[2]) |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1155 | # Install a flow with wildcards for our packet with higher |
| 1156 | # priority |
| 1157 | self.installFlow(1001, of_ports[0], of_ports[3]) |
| 1158 | self.verifyFlow(of_ports[0], of_ports[3]) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1159 | |
| 1160 | |
Ken Chiang | 3978f24 | 2012-06-13 14:14:09 -0700 | [diff] [blame] | 1161 | class WildcardPriorityWithDelete(SingleWildcardMatchPriority): |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1162 | """ |
| 1163 | 1. Add exact match flow, verify packet received. |
| 1164 | 2. Add wildcard flow with higher priority, verify packet received on port |
| 1165 | specified by this flow. |
| 1166 | 3. Add exact match flow with even higher priority, verify packet received |
| 1167 | on port specified by this flow. |
| 1168 | 4. Delete lowest priority flow, verify packet received on port specified |
| 1169 | by highest priority flow. |
| 1170 | 5. Delete highest priority flow, verify packet received on port specified |
| 1171 | by remaining flow. |
| 1172 | """ |
| 1173 | |
| 1174 | def runTest(self): |
| 1175 | |
| 1176 | self._Init() |
| 1177 | |
| 1178 | of_ports = pa_port_map.keys() |
| 1179 | of_ports.sort() |
| 1180 | |
| 1181 | self._ClearTable() |
| 1182 | |
| 1183 | # Install an exact match flow |
| 1184 | self.installFlow(250, of_ports[0], of_ports[1], wildcards=0) |
| 1185 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1186 | # Install a flow with wildcards of higher priority |
| 1187 | self.installFlow(1250, of_ports[0], of_ports[2], |
| 1188 | wildcards=ofp.OFPFW_DL_DST) |
| 1189 | self.verifyFlow(of_ports[0], of_ports[2]) |
| 1190 | # Install an exact match flow with even higher priority |
| 1191 | self.installFlow(2001, of_ports[0], of_ports[3], wildcards=0) |
| 1192 | self.verifyFlow(of_ports[0], of_ports[3]) |
| 1193 | # Delete lowest priority flow |
| 1194 | self.removeFlow(250) |
| 1195 | self.verifyFlow(of_ports[0], of_ports[3]) |
| 1196 | # Delete highest priority flow |
| 1197 | self.removeFlow(2001) |
| 1198 | self.verifyFlow(of_ports[0], of_ports[2]) |
| 1199 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1200 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1201 | class SingleWildcardMatch(BaseMatchCase): |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 1202 | """ |
| 1203 | Exercise wildcard matching for all ports |
| 1204 | |
| 1205 | Generate a packet |
| 1206 | Generate and install a matching flow with wildcard mask |
| 1207 | Add action to forward to a port |
| 1208 | Send the packet to the port |
| 1209 | 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] | 1210 | Verify flow_expiration message is correct when command option is set |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 1211 | """ |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 1212 | def runTest(self): |
Ken Chiang | 5be06dd | 2012-04-03 10:03:50 -0700 | [diff] [blame] | 1213 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1214 | for wc in WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1215 | wc |= required_wildcards(self) |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1216 | if wc & ofp.OFPFW_DL_VLAN: |
Ken Chiang | 5be06dd | 2012-04-03 10:03:50 -0700 | [diff] [blame] | 1217 | # Set nonzero VLAN id to avoid sending priority-tagged packet |
| 1218 | dl_vlan = vid |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1219 | else: |
| 1220 | dl_vlan = -1 |
| 1221 | flow_match_test(self, pa_port_map, wildcards=wc, |
| 1222 | dl_vlan=dl_vlan, max_test=10) |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 1223 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1224 | class SingleWildcardMatchTagged(BaseMatchCase): |
| 1225 | """ |
| 1226 | SingleWildcardMatch with tagged packets |
| 1227 | """ |
| 1228 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1229 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1230 | for wc in WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1231 | wc |= required_wildcards(self) |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 1232 | flow_match_test(self, pa_port_map, wildcards=wc, dl_vlan=vid, |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1233 | max_test=10) |
| 1234 | |
| 1235 | class AllExceptOneWildcardMatch(BaseMatchCase): |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 1236 | """ |
Dan Talayco | 80b54ed | 2010-07-13 09:48:35 -0700 | [diff] [blame] | 1237 | Match exactly one field |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 1238 | |
| 1239 | Generate a packet |
| 1240 | Generate and install a matching flow with wildcard all except one filed |
| 1241 | Add action to forward to a port |
| 1242 | Send the packet to the port |
| 1243 | Verify the packet is received at all other ports (one port at a time) |
| 1244 | Verify flow_expiration message is correct when command option is set |
| 1245 | """ |
| 1246 | def runTest(self): |
Ken Chiang | 5be06dd | 2012-04-03 10:03:50 -0700 | [diff] [blame] | 1247 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 1248 | for all_exp_one_wildcard in NO_WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1249 | all_exp_one_wildcard |= required_wildcards(self) |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1250 | if all_exp_one_wildcard & ofp.OFPFW_DL_VLAN: |
Ken Chiang | 5be06dd | 2012-04-03 10:03:50 -0700 | [diff] [blame] | 1251 | # Set nonzero VLAN id to avoid sending priority-tagged packet |
| 1252 | dl_vlan = vid |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1253 | else: |
| 1254 | dl_vlan = -1 |
| 1255 | flow_match_test(self, pa_port_map, wildcards=all_exp_one_wildcard, |
| 1256 | dl_vlan=dl_vlan) |
Tatsuya Yabe | e30ebe2 | 2010-05-25 09:30:49 -0700 | [diff] [blame] | 1257 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1258 | class AllExceptOneWildcardMatchTagged(BaseMatchCase): |
| 1259 | """ |
| 1260 | Match one field with tagged packets |
| 1261 | """ |
| 1262 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1263 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 1264 | for all_exp_one_wildcard in NO_WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1265 | all_exp_one_wildcard |= required_wildcards(self) |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 1266 | flow_match_test(self, pa_port_map, wildcards=all_exp_one_wildcard, |
| 1267 | dl_vlan=vid) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1268 | |
| 1269 | class AllWildcardMatch(BaseMatchCase): |
Tatsuya Yabe | e30ebe2 | 2010-05-25 09:30:49 -0700 | [diff] [blame] | 1270 | """ |
| 1271 | Create Wildcard-all flow and exercise for all ports |
| 1272 | |
| 1273 | Generate a packet |
| 1274 | Generate and install a matching flow with wildcard-all |
| 1275 | Add action to forward to a port |
| 1276 | Send the packet to the port |
| 1277 | Verify the packet is received at all other ports (one port at a time) |
| 1278 | Verify flow_expiration message is correct when command option is set |
| 1279 | """ |
| 1280 | def runTest(self): |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 1281 | flow_match_test(self, pa_port_map, wildcards=ofp.OFPFW_ALL) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1282 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1283 | class AllWildcardMatchTagged(BaseMatchCase): |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1284 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1285 | AllWildcardMatch with tagged packets |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1286 | """ |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1287 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1288 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 1289 | flow_match_test(self, pa_port_map, wildcards=ofp.OFPFW_ALL, |
| 1290 | dl_vlan=vid) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1291 | |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1292 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1293 | class AddVLANTag(BaseMatchCase): |
| 1294 | """ |
| 1295 | Add a VLAN tag to an untagged packet |
| 1296 | """ |
| 1297 | def runTest(self): |
| 1298 | new_vid = 2 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1299 | sup_acts = self.supported_actions |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1300 | if not(sup_acts & 1<<ofp.OFPAT_SET_VLAN_VID): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1301 | skip_message_emit(self, "Add VLAN tag test") |
Dan Talayco | f36f108 | 2010-07-13 13:57:17 -0700 | [diff] [blame] | 1302 | return |
Tatsuya Yabe | f5ffb97 | 2010-05-26 15:36:33 -0700 | [diff] [blame] | 1303 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1304 | len = 100 |
| 1305 | len_w_vid = 104 |
| 1306 | pkt = simple_tcp_packet(pktlen=len) |
| 1307 | exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1308 | dl_vlan=new_vid) |
| 1309 | vid_act = action.action_set_vlan_vid() |
| 1310 | vid_act.vlan_vid = new_vid |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1311 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1312 | flow_match_test(self, pa_port_map, pkt=pkt, |
| 1313 | exp_pkt=exp_pkt, action_list=[vid_act]) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1314 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1315 | class PacketOnly(basic.DataPlaneOnly): |
| 1316 | """ |
| 1317 | Just send a packet thru the switch |
| 1318 | """ |
| 1319 | def runTest(self): |
| 1320 | pkt = simple_tcp_packet() |
| 1321 | of_ports = pa_port_map.keys() |
| 1322 | of_ports.sort() |
| 1323 | ing_port = of_ports[0] |
| 1324 | pa_logger.info("Sending packet to " + str(ing_port)) |
| 1325 | pa_logger.debug("Data: " + str(pkt).encode('hex')) |
| 1326 | self.dataplane.send(ing_port, str(pkt)) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1327 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1328 | class PacketOnlyTagged(basic.DataPlaneOnly): |
| 1329 | """ |
| 1330 | Just send a packet thru the switch |
| 1331 | """ |
| 1332 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1333 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1334 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid) |
| 1335 | of_ports = pa_port_map.keys() |
| 1336 | of_ports.sort() |
| 1337 | ing_port = of_ports[0] |
| 1338 | pa_logger.info("Sending packet to " + str(ing_port)) |
| 1339 | pa_logger.debug("Data: " + str(pkt).encode('hex')) |
| 1340 | self.dataplane.send(ing_port, str(pkt)) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1341 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1342 | test_prio["PacketOnly"] = -1 |
| 1343 | test_prio["PacketOnlyTagged"] = -1 |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1344 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1345 | class ModifyVID(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1346 | """ |
| 1347 | Modify the VLAN ID in the VLAN tag of a tagged packet |
| 1348 | """ |
Dan Talayco | af66932 | 2012-09-12 22:51:22 -0700 | [diff] [blame] | 1349 | def setUp(self): |
| 1350 | BaseMatchCase.setUp(self) |
| 1351 | self.ing_port=False |
| 1352 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1353 | def runTest(self): |
| 1354 | old_vid = 2 |
| 1355 | new_vid = 3 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1356 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1357 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1358 | skip_message_emit(self, "Modify VLAN tag test") |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1359 | return |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1360 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1361 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=old_vid) |
| 1362 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=new_vid) |
| 1363 | vid_act = action.action_set_vlan_vid() |
| 1364 | vid_act.vlan_vid = new_vid |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1365 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1366 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
Dan Talayco | af66932 | 2012-09-12 22:51:22 -0700 | [diff] [blame] | 1367 | action_list=[vid_act], ing_port=self.ing_port) |
| 1368 | |
| 1369 | class ModifyVIDToIngress(ModifyVID): |
| 1370 | """ |
| 1371 | Modify the VLAN ID in the VLAN tag of a tagged packet and send to |
| 1372 | ingress port |
| 1373 | """ |
| 1374 | def setUp(self): |
| 1375 | BaseMatchCase.setUp(self) |
| 1376 | self.ing_port=True |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1377 | |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1378 | class ModifyVIDWithTagMatchWildcarded(BaseMatchCase): |
| 1379 | """ |
| 1380 | With vlan ID and priority wildcarded, perform SET_VLAN_VID action. |
| 1381 | The same flow should match on both untagged and tagged packets. |
| 1382 | """ |
| 1383 | def runTest(self): |
| 1384 | old_vid = 2 |
| 1385 | new_vid = 3 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1386 | sup_acts = self.supported_actions |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1387 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID): |
| 1388 | skip_message_emit(self, "ModifyVIDWithTagWildcarded test") |
| 1389 | return |
| 1390 | |
| 1391 | of_ports = pa_port_map.keys() |
| 1392 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 1393 | ing_port = of_ports[0] |
| 1394 | egr_ports = of_ports[1] |
| 1395 | |
| 1396 | rv = delete_all_flows(self.controller, pa_logger) |
| 1397 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 1398 | |
| 1399 | len_untagged = 100 |
| 1400 | len_w_vid = 104 |
| 1401 | untagged_pkt = simple_tcp_packet(pktlen=len_untagged) |
| 1402 | tagged_pkt = simple_tcp_packet(pktlen=len_w_vid, |
| 1403 | dl_vlan_enable=True, dl_vlan=old_vid) |
| 1404 | exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1405 | dl_vlan=new_vid) |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1406 | wildcards = (required_wildcards(self) | ofp.OFPFW_DL_VLAN | |
| 1407 | ofp.OFPFW_DL_VLAN_PCP) |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1408 | vid_act = action.action_set_vlan_vid() |
| 1409 | vid_act.vlan_vid = new_vid |
| 1410 | request = flow_msg_create(self, untagged_pkt, ing_port=ing_port, |
| 1411 | wildcards=wildcards, egr_ports=egr_ports, |
| 1412 | action_list=[vid_act]) |
| 1413 | flow_msg_install(self, request) |
| 1414 | |
| 1415 | pa_logger.debug("Send untagged packet: " + str(ing_port) + " to " + |
| 1416 | str(egr_ports)) |
| 1417 | self.dataplane.send(ing_port, str(untagged_pkt)) |
| 1418 | receive_pkt_verify(self, egr_ports, exp_pkt, ing_port) |
| 1419 | |
| 1420 | pa_logger.debug("Send tagged packet: " + str(ing_port) + " to " + |
| 1421 | str(egr_ports)) |
| 1422 | self.dataplane.send(ing_port, str(tagged_pkt)) |
| 1423 | receive_pkt_verify(self, egr_ports, exp_pkt, ing_port) |
| 1424 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 1425 | class ModifyVlanPcp(BaseMatchCase): |
| 1426 | """ |
| 1427 | Modify the priority field of the VLAN tag of a tagged packet |
| 1428 | """ |
| 1429 | def runTest(self): |
| 1430 | vid = 123 |
| 1431 | old_vlan_pcp = 2 |
| 1432 | new_vlan_pcp = 3 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1433 | sup_acts = self.supported_actions |
Ed Swierk | 8c3af7f | 2012-04-24 14:19:17 -0700 | [diff] [blame] | 1434 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP): |
| 1435 | skip_message_emit(self, "Modify VLAN priority test") |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 1436 | return |
| 1437 | |
| 1438 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=old_vlan_pcp) |
| 1439 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=new_vlan_pcp) |
| 1440 | vid_act = action.action_set_vlan_pcp() |
| 1441 | vid_act.vlan_pcp = new_vlan_pcp |
| 1442 | |
| 1443 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1444 | action_list=[vid_act]) |
| 1445 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1446 | class StripVLANTag(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1447 | """ |
| 1448 | Strip the VLAN tag from a tagged packet |
| 1449 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1450 | def runTest(self): |
| 1451 | old_vid = 2 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1452 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1453 | if not (sup_acts & 1 << ofp.OFPAT_STRIP_VLAN): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1454 | skip_message_emit(self, "Strip VLAN tag test") |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1455 | return |
Dan Talayco | f36f108 | 2010-07-13 13:57:17 -0700 | [diff] [blame] | 1456 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1457 | len_w_vid = 104 |
| 1458 | len = 100 |
| 1459 | pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1460 | dl_vlan=old_vid) |
| 1461 | exp_pkt = simple_tcp_packet(pktlen=len) |
| 1462 | vid_act = action.action_strip_vlan() |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1463 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1464 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1465 | action_list=[vid_act]) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1466 | |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1467 | class StripVLANTagWithTagMatchWildcarded(BaseMatchCase): |
| 1468 | """ |
| 1469 | Strip the VLAN tag from a tagged packet. |
| 1470 | Differs from StripVLANTag in that VID and PCP are both wildcarded. |
| 1471 | """ |
| 1472 | def runTest(self): |
| 1473 | old_vid = 2 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1474 | sup_acts = self.supported_actions |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1475 | if not (sup_acts & 1 << ofp.OFPAT_STRIP_VLAN): |
| 1476 | skip_message_emit(self, "StripVLANTagWithTagWildcarded test") |
| 1477 | return |
| 1478 | |
| 1479 | len_w_vid = 104 |
| 1480 | len_untagged = 100 |
| 1481 | pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1482 | dl_vlan=old_vid) |
| 1483 | exp_pkt = simple_tcp_packet(pktlen=len_untagged) |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1484 | wildcards = (required_wildcards(self) | ofp.OFPFW_DL_VLAN | |
| 1485 | ofp.OFPFW_DL_VLAN_PCP) |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1486 | vid_act = action.action_strip_vlan() |
| 1487 | |
| 1488 | flow_match_test(self, pa_port_map, |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1489 | wildcards=wildcards, |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1490 | pkt=pkt, exp_pkt=exp_pkt, |
| 1491 | action_list=[vid_act]) |
| 1492 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1493 | def init_pkt_args(): |
| 1494 | """ |
| 1495 | Pass back a dictionary with default packet arguments |
| 1496 | """ |
| 1497 | args = {} |
| 1498 | args["dl_src"] = '00:23:45:67:89:AB' |
| 1499 | |
| 1500 | dl_vlan_enable=False |
| 1501 | dl_vlan=-1 |
| 1502 | if pa_config["test-params"]["vid"]: |
| 1503 | dl_vlan_enable=True |
| 1504 | dl_vlan = pa_config["test-params"]["vid"] |
| 1505 | |
| 1506 | # Unpack operator is ** on a dictionary |
| 1507 | |
| 1508 | return args |
| 1509 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1510 | class ModifyL2Src(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1511 | """ |
| 1512 | Modify the source MAC address (TP1) |
| 1513 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1514 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1515 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1516 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1517 | skip_message_emit(self, "ModifyL2Src test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1518 | return |
| 1519 | |
| 1520 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'], |
| 1521 | check_test_params=True) |
| 1522 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1523 | action_list=acts, max_test=2) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1524 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1525 | class ModifyL2Dst(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1526 | """ |
| 1527 | Modify the dest MAC address (TP1) |
| 1528 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1529 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1530 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1531 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1532 | skip_message_emit(self, "ModifyL2dst test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1533 | return |
| 1534 | |
| 1535 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1536 | check_test_params=True) |
| 1537 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1538 | action_list=acts, max_test=2) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1539 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1540 | class ModifyL3Src(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1541 | """ |
| 1542 | Modify the source IP address of an IP packet (TP1) |
| 1543 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1544 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1545 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1546 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_SRC): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1547 | skip_message_emit(self, "ModifyL3Src test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1548 | return |
| 1549 | |
| 1550 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_src'], |
| 1551 | check_test_params=True) |
| 1552 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1553 | action_list=acts, max_test=2) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1554 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1555 | class ModifyL3Dst(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1556 | """ |
| 1557 | Modify the dest IP address of an IP packet (TP1) |
| 1558 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1559 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1560 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1561 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_DST): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1562 | skip_message_emit(self, "ModifyL3Dst test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1563 | return |
| 1564 | |
| 1565 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_dst'], |
| 1566 | check_test_params=True) |
| 1567 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1568 | action_list=acts, max_test=2) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1569 | |
| 1570 | class ModifyL4Src(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1571 | """ |
| 1572 | Modify the source TCP port of a TCP packet (TP1) |
| 1573 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1574 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1575 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1576 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_SRC): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1577 | skip_message_emit(self, "ModifyL4Src test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1578 | return |
| 1579 | |
| 1580 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_sport'], |
| 1581 | check_test_params=True) |
| 1582 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1583 | action_list=acts, max_test=2) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1584 | |
| 1585 | class ModifyL4Dst(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1586 | """ |
| 1587 | Modify the dest TCP port of a TCP packet (TP1) |
| 1588 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1589 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1590 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1591 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1592 | skip_message_emit(self, "ModifyL4Dst test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1593 | return |
| 1594 | |
| 1595 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_dport'], |
| 1596 | check_test_params=True) |
| 1597 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1598 | action_list=acts, max_test=2) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1599 | |
| 1600 | class ModifyTOS(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1601 | """ |
| 1602 | Modify the IP type of service of an IP packet (TP1) |
| 1603 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1604 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1605 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1606 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1607 | skip_message_emit(self, "ModifyTOS test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1608 | return |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1609 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1610 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_tos'], |
| 1611 | check_test_params=True) |
| 1612 | 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] | 1613 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1614 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1615 | class ModifyL2DstMC(BaseMatchCase): |
| 1616 | """ |
| 1617 | Modify the L2 dest and send to 2 ports |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1618 | """ |
| 1619 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1620 | sup_acts = self.supported_actions |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1621 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1622 | skip_message_emit(self, "ModifyL2dstMC test") |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1623 | return |
| 1624 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1625 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1626 | check_test_params=True) |
| 1627 | 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] | 1628 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1629 | |
Dan Talayco | c948d0b | 2012-03-23 12:17:54 -0700 | [diff] [blame] | 1630 | class ModifyL2DstIngress(BaseMatchCase): |
| 1631 | """ |
| 1632 | Modify the L2 dest and send to the ingress port |
| 1633 | """ |
| 1634 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1635 | sup_acts = self.supported_actions |
Dan Talayco | c948d0b | 2012-03-23 12:17:54 -0700 | [diff] [blame] | 1636 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1637 | skip_message_emit(self, "ModifyL2dstIngress test") |
Dan Talayco | c948d0b | 2012-03-23 12:17:54 -0700 | [diff] [blame] | 1638 | return |
| 1639 | |
| 1640 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1641 | check_test_params=True) |
| 1642 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1643 | action_list=acts, max_test=2, egr_count=0, |
| 1644 | ing_port=True) |
| 1645 | |
Dan Talayco | d8ae758 | 2012-03-23 12:24:56 -0700 | [diff] [blame] | 1646 | class ModifyL2DstIngressMC(BaseMatchCase): |
| 1647 | """ |
| 1648 | Modify the L2 dest and send to the ingress port |
| 1649 | """ |
| 1650 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1651 | sup_acts = self.supported_actions |
Dan Talayco | d8ae758 | 2012-03-23 12:24:56 -0700 | [diff] [blame] | 1652 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
| 1653 | skip_message_emit(self, "ModifyL2dstMC test") |
| 1654 | return |
| 1655 | |
| 1656 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1657 | check_test_params=True) |
| 1658 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1659 | action_list=acts, max_test=2, egr_count=-1, |
| 1660 | ing_port=True) |
| 1661 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1662 | class ModifyL2SrcMC(BaseMatchCase): |
| 1663 | """ |
| 1664 | Modify the source MAC address (TP1) and send to multiple |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1665 | """ |
| 1666 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1667 | sup_acts = self.supported_actions |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1668 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC): |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1669 | skip_message_emit(self, "ModifyL2SrcMC test") |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1670 | return |
| 1671 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1672 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'], |
| 1673 | check_test_params=True) |
| 1674 | 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] | 1675 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1676 | |
| 1677 | class ModifyL2SrcDstMC(BaseMatchCase): |
| 1678 | """ |
| 1679 | Modify the L2 source and dest and send to 2 ports |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1680 | """ |
| 1681 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1682 | sup_acts = self.supported_actions |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1683 | if (not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST) or |
| 1684 | not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC)): |
| 1685 | skip_message_emit(self, "ModifyL2SrcDstMC test") |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1686 | return |
| 1687 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1688 | mod_fields = ['dl_dst', 'dl_src'] |
| 1689 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=mod_fields, |
| 1690 | check_test_params=True) |
| 1691 | 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] | 1692 | action_list=acts, max_test=2, egr_count=-1) |
| 1693 | |
| 1694 | class ModifyL2DstVIDMC(BaseMatchCase): |
| 1695 | """ |
| 1696 | Modify the L2 dest and send to 2 ports |
| 1697 | """ |
| 1698 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1699 | sup_acts = self.supported_actions |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1700 | if (not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST) or |
| 1701 | not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID)): |
| 1702 | skip_message_emit(self, "ModifyL2DstVIDMC test") |
| 1703 | return |
| 1704 | |
| 1705 | mod_fields = ['dl_dst', 'dl_vlan'] |
| 1706 | (pkt, exp_pkt, acts) = pkt_action_setup(self, |
| 1707 | start_field_vals={'dl_vlan_enable':True}, mod_fields=mod_fields, |
| 1708 | check_test_params=True) |
| 1709 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1710 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1711 | |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1712 | class FlowToggle(BaseMatchCase): |
| 1713 | """ |
| 1714 | Add flows to the table and modify them repeatedly |
Dan Talayco | f7c4131 | 2012-07-23 12:53:19 -0700 | [diff] [blame] | 1715 | |
| 1716 | This is done by using only "add" flow messages. Since the check overlap |
| 1717 | flag is not set, the switch is supposed to modify the existing flow if |
| 1718 | the match already exists. |
| 1719 | |
| 1720 | Would probably be better to exercise more of the flow modify commands |
| 1721 | (add, modify, delete +/- strict). |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1722 | """ |
| 1723 | def runTest(self): |
Dan Talayco | 50be767 | 2012-04-05 11:38:08 -0700 | [diff] [blame] | 1724 | flow_count = test_param_get(self.config, 'ft_flow_count', default=20) |
| 1725 | iter_count = test_param_get(self.config, 'ft_iter_count', default=10) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1726 | |
| 1727 | pa_logger.info("Running flow toggle with %d flows, %d iterations" % |
| 1728 | (flow_count, iter_count)) |
| 1729 | acts = [] |
| 1730 | acts.append(action.action_output()) |
| 1731 | acts.append(action.action_output()) |
| 1732 | |
| 1733 | of_ports = pa_port_map.keys() |
| 1734 | if len(of_ports) < 3: |
| 1735 | self.assertTrue(False, "Too few ports for test") |
| 1736 | |
| 1737 | for idx in range(2): |
| 1738 | acts[idx].port = of_ports[idx] |
| 1739 | |
| 1740 | flows = [] |
| 1741 | flows.append([]) |
| 1742 | flows.append([]) |
| 1743 | |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1744 | wildcards = (required_wildcards(self) | ofp.OFPFW_DL_SRC | |
| 1745 | ofp.OFPFW_DL_DST) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1746 | # Create up the flows in an array |
| 1747 | for toggle in range(2): |
| 1748 | for f_idx in range(flow_count): |
| 1749 | pkt = simple_tcp_packet(tcp_sport=f_idx) |
| 1750 | msg = message.flow_mod() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1751 | match = packet_to_flow_match(self, pkt) |
Shudong Zhou | 031373c | 2012-07-19 17:37:42 -0700 | [diff] [blame] | 1752 | match.in_port = of_ports[2] |
Dan Talayco | 50be767 | 2012-04-05 11:38:08 -0700 | [diff] [blame] | 1753 | match.wildcards = wildcards |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1754 | msg.match = match |
| 1755 | msg.buffer_id = 0xffffffff |
Dan Talayco | f7c4131 | 2012-07-23 12:53:19 -0700 | [diff] [blame] | 1756 | msg.command = ofp.OFPFC_ADD |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1757 | msg.actions.add(acts[toggle]) |
| 1758 | flows[toggle].append(msg) |
Dan Talayco | 50be767 | 2012-04-05 11:38:08 -0700 | [diff] [blame] | 1759 | |
| 1760 | # Show two sample flows |
| 1761 | pa_logger.debug(flows[0][0].show()) |
| 1762 | pa_logger.debug(flows[1][0].show()) |
| 1763 | |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1764 | # Install the first set of flows |
| 1765 | for f_idx in range(flow_count): |
| 1766 | rv = self.controller.message_send(flows[0][f_idx]) |
| 1767 | self.assertTrue(rv != -1, "Error installing flow %d" % f_idx) |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 1768 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1769 | |
| 1770 | pa_logger.info("Installed %d flows" % flow_count) |
| 1771 | |
| 1772 | # Repeatedly modify all the flows back and forth |
| 1773 | updates = 0 |
| 1774 | # Report status about 5 times |
| 1775 | mod_val = (iter_count / 4) + 1 |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1776 | start = time.time() |
| 1777 | for iter_idx in range(iter_count): |
| 1778 | if not iter_idx % mod_val: |
| 1779 | pa_logger.info("Flow Toggle: iter %d of %d. " % |
| 1780 | (iter_idx, iter_count) + |
| 1781 | "%d updates in %d secs" % |
| 1782 | (updates, time.time() - start)) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1783 | for toggle in range(2): |
| 1784 | t_idx = 1 - toggle |
| 1785 | for f_idx in range(flow_count): |
| 1786 | rv = self.controller.message_send(flows[t_idx][f_idx]) |
| 1787 | updates += 1 |
| 1788 | self.assertTrue(rv != -1, "Error modifying flow %d" % |
| 1789 | f_idx) |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 1790 | self.assertEqual(do_barrier(self.controller), 0, |
| 1791 | "Barrier failed") |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1792 | |
| 1793 | end = time.time() |
| 1794 | divisor = end - start or (end - start + 1) |
| 1795 | pa_logger.info("Flow toggle: %d iterations" % iter_count) |
| 1796 | pa_logger.info(" %d flow mods in %d secs, %d mods/sec" % |
| 1797 | (updates, end - start, updates/divisor)) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1798 | |
| 1799 | |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1800 | # You can pick and choose these by commenting tests in or out |
| 1801 | iter_classes = [ |
| 1802 | basic.PacketIn, |
| 1803 | basic.PacketOut, |
| 1804 | DirectPacket, |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1805 | FlowToggle, |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1806 | DirectTwoPorts, |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1807 | DirectMCNonIngress, |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1808 | AllWildcardMatch, |
| 1809 | AllWildcardMatchTagged, |
| 1810 | SingleWildcardMatch, |
| 1811 | SingleWildcardMatchTagged, |
| 1812 | ExactMatch, |
| 1813 | ExactMatchTagged, |
| 1814 | SingleWildcardMatch, |
| 1815 | ModifyL2Src, |
| 1816 | ModifyL2Dst, |
| 1817 | ModifyL2SrcMC, |
| 1818 | ModifyL2DstMC, |
| 1819 | ModifyL2SrcDstMC |
| 1820 | ] |
| 1821 | |
| 1822 | class IterCases(BaseMatchCase): |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1823 | """ |
| 1824 | Iterate over a bunch of test cases |
| 1825 | |
| 1826 | The cases come from the list above |
| 1827 | """ |
| 1828 | |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1829 | def runTest(self): |
| 1830 | count = test_param_get(self.config, 'iter_count', default=10) |
| 1831 | tests_done = 0 |
| 1832 | pa_logger.info("Running iteration test " + str(count) + " times") |
| 1833 | start = time.time() |
| 1834 | last = start |
| 1835 | for idx in range(count): |
| 1836 | pa_logger.info("Iteration " + str(idx + 1)) |
| 1837 | for cls in iter_classes: |
| 1838 | test = cls() |
| 1839 | test.inheritSetup(self) |
| 1840 | test.runTest() |
| 1841 | tests_done += 1 |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1842 | # Report update about every minute, between tests |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1843 | if time.time() - last > 60: |
| 1844 | last = time.time() |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1845 | pa_logger.info( |
| 1846 | "IterCases: Iter %d of %d; Ran %d tests in %d " % |
| 1847 | (idx, count, tests_done, last - start) + |
| 1848 | "seconds so far") |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1849 | stats = all_stats_get(self) |
| 1850 | last = time.time() |
| 1851 | pa_logger.info("\nIterCases ran %d tests in %d seconds." % |
| 1852 | (tests_done, last - start)) |
| 1853 | pa_logger.info(" flows: %d. packets: %d. bytes: %d" % |
| 1854 | (stats["flows"], stats["packets"], stats["bytes"])) |
| 1855 | pa_logger.info(" active: %d. lookups: %d. matched %d." % |
| 1856 | (stats["active"], stats["lookups"], stats["matched"])) |
| 1857 | |
| 1858 | # Don't run by default |
| 1859 | test_prio["IterCases"] = -1 |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1860 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1861 | #@todo Need to implement tagged versions of the above tests |
| 1862 | # |
| 1863 | #@todo Implement a test case that strips tag 2, adds tag 3 |
| 1864 | # and modifies tag 4 to tag 5. Then verify (in addition) that |
| 1865 | # tag 6 does not get modified. |
| 1866 | |
| 1867 | class MixedVLAN(BaseMatchCase): |
| 1868 | """ |
| 1869 | Test mixture of VLAN tag actions |
| 1870 | |
| 1871 | Strip tag 2 on port 1, send to port 2 |
| 1872 | Add tag 3 on port 1, send to port 2 |
| 1873 | Modify tag 4 to 5 on port 1, send to port 2 |
| 1874 | All other traffic from port 1, send to port 3 |
| 1875 | All traffic from port 2 sent to port 4 |
| 1876 | Use exact matches with different packets for all mods |
| 1877 | Verify the following: (port, vid) |
| 1878 | (port 1, vid 2) => VLAN tag stripped, out port 2 |
| 1879 | (port 1, no tag) => tagged packet w/ vid 2 out port 2 |
| 1880 | (port 1, vid 4) => tagged packet w/ vid 5 out port 2 |
| 1881 | (port 1, vid 5) => tagged packet w/ vid 5 out port 2 |
| 1882 | (port 1, vid 6) => tagged packet w/ vid 6 out port 2 |
| 1883 | (port 2, no tag) => untagged packet out port 4 |
| 1884 | (port 2, vid 2-6) => unmodified packet out port 4 |
| 1885 | |
| 1886 | Variation: Might try sending VID 5 to port 3 and check. |
| 1887 | If only VID 5 distinguishes pkt, this will fail on some platforms |
| 1888 | """ |
| 1889 | |
| 1890 | test_prio["MixedVLAN"] = -1 |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame^] | 1891 | |
| 1892 | class MatchEach(basic.SimpleDataPlane): |
| 1893 | """ |
| 1894 | Check that each match field is actually matched on. |
| 1895 | Installs two flows that differ in one field. The flow that should not |
| 1896 | match has a higher priority, so if that field is ignored during matching |
| 1897 | the packet will be sent out the wrong port. |
| 1898 | |
| 1899 | TODO test UDP, ARP, ICMP, etc. |
| 1900 | """ |
| 1901 | def runTest(self): |
| 1902 | of_ports = pa_port_map.keys() |
| 1903 | of_ports.sort() |
| 1904 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 1905 | |
| 1906 | delete_all_flows(self.controller, pa_logger) |
| 1907 | |
| 1908 | pkt = simple_tcp_packet() |
| 1909 | ingress_port = of_ports[0] |
| 1910 | egress_port = of_ports[1] |
| 1911 | |
| 1912 | def testField(field, mask): |
| 1913 | pa_logger.info("Testing field %s" % field) |
| 1914 | |
| 1915 | def addFlow(matching, priority, output_port): |
| 1916 | match = packet_to_flow_match(self, pkt) |
| 1917 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 1918 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 1919 | match.in_port = ingress_port |
| 1920 | if not matching: |
| 1921 | # Make sure flow doesn't match |
| 1922 | orig = getattr(match, field) |
| 1923 | if isinstance(orig, list): |
| 1924 | new = map(lambda a: ~a[0] & a[1], zip(orig, mask)) |
| 1925 | else: |
| 1926 | new = ~orig & mask |
| 1927 | setattr(match, field, new) |
| 1928 | request = message.flow_mod() |
| 1929 | request.match = match |
| 1930 | request.buffer_id = 0xffffffff |
| 1931 | request.priority = priority |
| 1932 | act = action.action_output() |
| 1933 | act.port = output_port |
| 1934 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 1935 | pa_logger.info("Inserting flow") |
| 1936 | self.controller.message_send(request) |
| 1937 | |
| 1938 | # This flow should match. |
| 1939 | addFlow(matching=True, priority=0, output_port=egress_port) |
| 1940 | # This flow should not match, but it has a higher priority. |
| 1941 | addFlow(matching=False, priority=1, output_port=ofp.OFPP_IN_PORT) |
| 1942 | |
| 1943 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 1944 | |
| 1945 | pa_logger.info("Sending packet to dp port " + str(ingress_port)) |
| 1946 | self.dataplane.send(ingress_port, str(pkt)) |
| 1947 | |
| 1948 | exp_pkt_arg = None |
| 1949 | exp_port = None |
| 1950 | if pa_config["relax"]: |
| 1951 | exp_pkt_arg = pkt |
| 1952 | exp_port = egress_port |
| 1953 | |
| 1954 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(port_number=exp_port, |
| 1955 | exp_pkt=exp_pkt_arg) |
| 1956 | self.assertTrue(rcv_pkt is not None, "Did not receive packet") |
| 1957 | pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + str(rcv_port)) |
| 1958 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 1959 | self.assertEqual(str(pkt), str(rcv_pkt), 'Response packet does not match send packet') |
| 1960 | |
| 1961 | # TODO in_port |
| 1962 | testField("dl_src", [0xff]*6) |
| 1963 | testField("dl_dst", [0xff]*6) |
| 1964 | testField("dl_type", 0xffff) |
| 1965 | testField("dl_vlan", 0xfff) |
| 1966 | # TODO dl_vlan_pcp |
| 1967 | testField("nw_src", 0xffffffff) |
| 1968 | testField("nw_dst", 0xffffffff) |
| 1969 | testField("nw_tos", 0x3f) |
| 1970 | testField("nw_proto", 0xff) |
| 1971 | testField("tp_src", 0xffff) |
| 1972 | testField("tp_dst", 0xffff) |
| 1973 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 1974 | if __name__ == "__main__": |
| 1975 | print "Please run through oft script: ./oft --test_spec=basic" |