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