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