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 |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 19 | import random |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 20 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 21 | from oftest import config |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 22 | import oftest.controller as controller |
| 23 | import oftest.cstruct as ofp |
| 24 | import oftest.message as message |
| 25 | import oftest.dataplane as dataplane |
| 26 | import oftest.action as action |
| 27 | import oftest.parse as parse |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 28 | import oftest.base_tests as base_tests |
| 29 | import basic # for IterCases |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 30 | |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 31 | from oftest.parse import parse_mac, parse_ip |
| 32 | |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 33 | from oftest.testutils import * |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 34 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 35 | WILDCARD_VALUES = [ofp.OFPFW_IN_PORT, |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 36 | ofp.OFPFW_DL_VLAN | ofp.OFPFW_DL_VLAN_PCP, |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 37 | ofp.OFPFW_DL_SRC, |
| 38 | ofp.OFPFW_DL_DST, |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 39 | (ofp.OFPFW_DL_TYPE | ofp.OFPFW_NW_SRC_ALL | |
| 40 | ofp.OFPFW_NW_DST_ALL | ofp.OFPFW_NW_TOS | ofp.OFPFW_NW_PROTO | |
| 41 | ofp.OFPFW_TP_SRC | ofp.OFPFW_TP_DST), |
| 42 | (ofp.OFPFW_NW_PROTO | ofp.OFPFW_TP_SRC | ofp.OFPFW_TP_DST), |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 43 | ofp.OFPFW_TP_SRC, |
| 44 | ofp.OFPFW_TP_DST, |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 45 | ofp.OFPFW_NW_SRC_MASK, |
| 46 | ofp.OFPFW_NW_DST_MASK, |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 47 | ofp.OFPFW_DL_VLAN_PCP, |
| 48 | ofp.OFPFW_NW_TOS] |
| 49 | |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 50 | NO_WILDCARD_VALUES = [(ofp.OFPFW_ALL ^ ofp.OFPFW_IN_PORT), |
| 51 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_VLAN), |
| 52 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_SRC), |
| 53 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_DST), |
| 54 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE), |
| 55 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO), |
| 56 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO ^ |
| 57 | ofp.OFPFW_TP_SRC), |
| 58 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO ^ |
| 59 | ofp.OFPFW_TP_DST), |
| 60 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO ^ |
| 61 | ofp.OFPFW_NW_SRC_MASK), |
| 62 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO ^ |
| 63 | ofp.OFPFW_NW_DST_MASK), |
| 64 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_VLAN ^ ofp.OFPFW_DL_VLAN_PCP), |
| 65 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO ^ |
| 66 | ofp.OFPFW_NW_TOS)] |
| 67 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 68 | MODIFY_ACTION_VALUES = [ofp.OFPAT_SET_VLAN_VID, |
| 69 | ofp.OFPAT_SET_VLAN_PCP, |
| 70 | ofp.OFPAT_STRIP_VLAN, |
| 71 | ofp.OFPAT_SET_DL_SRC, |
| 72 | ofp.OFPAT_SET_DL_DST, |
| 73 | ofp.OFPAT_SET_NW_SRC, |
| 74 | ofp.OFPAT_SET_NW_DST, |
| 75 | ofp.OFPAT_SET_NW_TOS, |
| 76 | ofp.OFPAT_SET_TP_SRC, |
| 77 | ofp.OFPAT_SET_TP_DST] |
| 78 | |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 79 | TEST_VID_DEFAULT = 2 |
| 80 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 81 | class DirectPacket(base_tests.SimpleDataPlane): |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 82 | """ |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 83 | Send packet to single egress port |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 84 | |
| 85 | Generate a packet |
| 86 | Generate and install a matching flow |
| 87 | Add action to direct the packet to an egress port |
| 88 | Send the packet to ingress dataplane port |
| 89 | Verify the packet is received at the egress port only |
| 90 | """ |
| 91 | def runTest(self): |
Tatsuya Yabe | b8fb3c3 | 2010-06-14 15:48:36 -0700 | [diff] [blame] | 92 | self.handleFlow() |
| 93 | |
| 94 | def handleFlow(self, pkttype='TCP'): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 95 | of_ports = config["port_map"].keys() |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 96 | of_ports.sort() |
| 97 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 98 | |
Tatsuya Yabe | b8fb3c3 | 2010-06-14 15:48:36 -0700 | [diff] [blame] | 99 | if (pkttype == 'ICMP'): |
| 100 | pkt = simple_icmp_packet() |
| 101 | else: |
| 102 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 103 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 7dd6cd6 | 2010-03-16 15:02:35 -0700 | [diff] [blame] | 104 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 105 | self.assertTrue(match is not None, |
| 106 | "Could not generate flow match from pkt") |
| 107 | act = action.action_output() |
| 108 | |
| 109 | for idx in range(len(of_ports)): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 110 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 111 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 112 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 113 | ingress_port = of_ports[idx] |
| 114 | egress_port = of_ports[(idx + 1) % len(of_ports)] |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 115 | logging.info("Ingress " + str(ingress_port) + |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 116 | " to egress " + str(egress_port)) |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 117 | |
| 118 | match.in_port = ingress_port |
| 119 | |
| 120 | request = message.flow_mod() |
| 121 | request.match = match |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 122 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 123 | request.buffer_id = 0xffffffff |
| 124 | act.port = egress_port |
| 125 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 126 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 127 | logging.info("Inserting flow") |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 128 | rv = self.controller.message_send(request) |
| 129 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 130 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 131 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 132 | logging.info("Sending packet to dp port " + |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 133 | str(ingress_port)) |
| 134 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 135 | |
| 136 | exp_pkt_arg = None |
| 137 | exp_port = None |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 138 | if config["relax"]: |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 139 | exp_pkt_arg = pkt |
| 140 | exp_port = egress_port |
| 141 | |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 142 | (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] | 143 | exp_pkt=exp_pkt_arg) |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 144 | self.assertTrue(rcv_pkt is not None, "Did not receive packet") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 145 | logging.debug("Packet len " + str(len(rcv_pkt)) + " in on " + |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 146 | str(rcv_port)) |
| 147 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 148 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 149 | 'Response packet does not match send packet') |
Tatsuya Yabe | b8fb3c3 | 2010-06-14 15:48:36 -0700 | [diff] [blame] | 150 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 151 | class DirectPacketController(base_tests.SimpleDataPlane): |
Rich Lane | 51c23b3 | 2012-07-27 16:37:25 -0700 | [diff] [blame] | 152 | """ |
| 153 | Send packet to the controller port |
| 154 | |
| 155 | Generate a packet |
| 156 | Generate and install a matching flow |
| 157 | Add action to direct the packet to the controller port |
| 158 | Send the packet to ingress dataplane port |
| 159 | Verify the packet is received at the controller port |
| 160 | """ |
| 161 | def runTest(self): |
| 162 | self.handleFlow() |
| 163 | |
| 164 | def handleFlow(self, pkttype='TCP'): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 165 | of_ports = config["port_map"].keys() |
Rich Lane | 51c23b3 | 2012-07-27 16:37:25 -0700 | [diff] [blame] | 166 | of_ports.sort() |
| 167 | self.assertTrue(len(of_ports) > 0, "Not enough ports for test") |
| 168 | |
| 169 | if (pkttype == 'ICMP'): |
| 170 | pkt = simple_icmp_packet() |
| 171 | else: |
| 172 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 173 | match = packet_to_flow_match(self, pkt) |
Rich Lane | 51c23b3 | 2012-07-27 16:37:25 -0700 | [diff] [blame] | 174 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 175 | self.assertTrue(match is not None, |
| 176 | "Could not generate flow match from pkt") |
| 177 | act = action.action_output() |
| 178 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 179 | rv = delete_all_flows(self.controller) |
Rich Lane | 51c23b3 | 2012-07-27 16:37:25 -0700 | [diff] [blame] | 180 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 181 | |
| 182 | ingress_port = of_ports[0] |
| 183 | match.in_port = ingress_port |
| 184 | |
| 185 | request = message.flow_mod() |
| 186 | request.match = match |
| 187 | |
| 188 | request.buffer_id = 0xffffffff |
| 189 | act.port = ofp.OFPP_CONTROLLER |
| 190 | act.max_len = 65535 |
| 191 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 192 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 193 | logging.info("Inserting flow") |
Rich Lane | 51c23b3 | 2012-07-27 16:37:25 -0700 | [diff] [blame] | 194 | rv = self.controller.message_send(request) |
| 195 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 196 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 197 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 198 | logging.info("Sending packet to dp port " + |
Rich Lane | 51c23b3 | 2012-07-27 16:37:25 -0700 | [diff] [blame] | 199 | str(ingress_port)) |
| 200 | self.dataplane.send(ingress_port, str(pkt)) |
| 201 | |
| 202 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN) |
| 203 | |
| 204 | self.assertTrue(response is not None, |
| 205 | 'Packet in message not received by controller') |
| 206 | if not dataplane.match_exp_pkt(pkt, response.data): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 207 | logging.debug("Sent %s" % format_packet(pkt)) |
| 208 | logging.debug("Resp %s" % format_packet(response.data)) |
Rich Lane | 51c23b3 | 2012-07-27 16:37:25 -0700 | [diff] [blame] | 209 | self.assertTrue(False, |
| 210 | 'Response packet does not match send packet' + |
| 211 | ' for controller port') |
| 212 | |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 213 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 214 | class DirectPacketQueue(base_tests.SimpleDataPlane): |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 215 | """ |
| 216 | Send packet to single queue on single egress port |
| 217 | |
| 218 | Generate a packet |
| 219 | Generate and install a matching flow |
| 220 | Add action to direct the packet to an egress port and queue |
| 221 | Send the packet to ingress dataplane port |
| 222 | Verify the packet is received at the egress port only |
| 223 | """ |
| 224 | def runTest(self): |
| 225 | self.handleFlow() |
| 226 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 227 | def portQueuesGet(self, queue_stats, port_num): |
| 228 | result = [] |
| 229 | for qs in queue_stats.stats: |
| 230 | if qs.port_no != port_num: |
| 231 | continue |
| 232 | result.append(qs.queue_id) |
| 233 | return result |
| 234 | |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 235 | def handleFlow(self, pkttype='TCP'): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 236 | of_ports = config["port_map"].keys() |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 237 | of_ports.sort() |
| 238 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 239 | |
| 240 | if (pkttype == 'ICMP'): |
| 241 | pkt = simple_icmp_packet() |
| 242 | else: |
| 243 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 244 | match = packet_to_flow_match(self, pkt) |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 245 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 246 | self.assertTrue(match is not None, |
| 247 | "Could not generate flow match from pkt") |
| 248 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 249 | # Get queue stats from switch |
| 250 | |
| 251 | request = message.queue_stats_request() |
| 252 | request.port_no = ofp.OFPP_ALL |
| 253 | request.queue_id = ofp.OFPQ_ALL |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 254 | (queue_stats, p) = self.controller.transact(request) |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 255 | self.assertNotEqual(queue_stats, None, "Queue stats request failed") |
| 256 | |
| 257 | act = action.action_enqueue() |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 258 | |
| 259 | for idx in range(len(of_ports)): |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 260 | ingress_port = of_ports[idx] |
| 261 | egress_port = of_ports[(idx + 1) % len(of_ports)] |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 262 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 263 | for egress_queue_id in self.portQueuesGet(queue_stats, egress_port): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 264 | logging.info("Ingress " + str(ingress_port) |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 265 | + " to egress " + str(egress_port) |
| 266 | + " queue " + str(egress_queue_id) |
| 267 | ) |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 268 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 269 | rv = delete_all_flows(self.controller) |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 270 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 271 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 272 | match.in_port = ingress_port |
| 273 | |
| 274 | request = message.flow_mod() |
| 275 | request.match = match |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 276 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 277 | request.buffer_id = 0xffffffff |
| 278 | act.port = egress_port |
| 279 | act.queue_id = egress_queue_id |
| 280 | self.assertTrue(request.actions.add(act), "Could not add action") |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 281 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 282 | logging.info("Inserting flow") |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 283 | rv = self.controller.message_send(request) |
| 284 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 285 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 286 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 287 | # Get current stats for selected egress queue |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 288 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 289 | request = message.queue_stats_request() |
| 290 | request.port_no = egress_port |
| 291 | request.queue_id = egress_queue_id |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 292 | (qs_before, p) = self.controller.transact(request) |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 293 | self.assertNotEqual(qs_before, None, "Queue stats request failed") |
| 294 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 295 | logging.info("Sending packet to dp port " + |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 296 | str(ingress_port)) |
| 297 | self.dataplane.send(ingress_port, str(pkt)) |
| 298 | |
| 299 | exp_pkt_arg = None |
| 300 | exp_port = None |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 301 | if config["relax"]: |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 302 | exp_pkt_arg = pkt |
| 303 | exp_port = egress_port |
| 304 | |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 305 | (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] | 306 | exp_pkt=exp_pkt_arg) |
| 307 | self.assertTrue(rcv_pkt is not None, "Did not receive packet") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 308 | logging.debug("Packet len " + str(len(rcv_pkt)) + " in on " + |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 309 | str(rcv_port)) |
| 310 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 311 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 312 | 'Response packet does not match send packet') |
| 313 | |
Ed Swierk | b8a8651 | 2012-04-18 18:45:58 -0700 | [diff] [blame] | 314 | # FIXME: instead of sleeping, keep requesting queue stats until |
| 315 | # the expected queue counter increases or some large timeout is |
| 316 | # reached |
| 317 | time.sleep(2) |
| 318 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 319 | # Get current stats for selected egress queue again |
| 320 | |
| 321 | request = message.queue_stats_request() |
| 322 | request.port_no = egress_port |
| 323 | request.queue_id = egress_queue_id |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 324 | (qs_after, p) = self.controller.transact(request) |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 325 | self.assertNotEqual(qs_after, None, "Queue stats request failed") |
| 326 | |
| 327 | # Make sure that tx packet counter for selected egress queue was |
| 328 | # incremented |
| 329 | |
Ed Swierk | 22f5915 | 2012-04-17 16:36:47 -0700 | [diff] [blame] | 330 | self.assertEqual(qs_after.stats[0].tx_packets, \ |
| 331 | qs_before.stats[0].tx_packets + 1, \ |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 332 | "Verification of egress queue tx packet count failed" |
| 333 | ) |
| 334 | |
| 335 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 336 | class DirectPacketControllerQueue(base_tests.SimpleDataPlane): |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 337 | """ |
| 338 | Send a packet from each of the openflow ports |
| 339 | to each of the queues configured on the controller port. |
| 340 | If no queues have been configured, no packets are sent. |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 341 | |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 342 | Generate a packet |
| 343 | Generate and install a matching flow |
| 344 | Add action to direct the packet to one of the controller port queues |
| 345 | Send the packet to ingress dataplane port |
| 346 | Verify the packet is received on the controller port queue |
| 347 | """ |
| 348 | def runTest(self): |
| 349 | self.handleFlow() |
| 350 | |
| 351 | def portQueuesGet(self, queue_stats, port_num): |
| 352 | result = [] |
| 353 | for qs in queue_stats.stats: |
| 354 | if qs.port_no != port_num: |
| 355 | continue |
| 356 | result.append(qs.queue_id) |
| 357 | return result |
| 358 | |
| 359 | def handleFlow(self, pkttype='TCP'): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 360 | of_ports = config["port_map"].keys() |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 361 | of_ports.sort() |
| 362 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 363 | |
| 364 | if (pkttype == 'ICMP'): |
| 365 | pkt = simple_icmp_packet() |
| 366 | else: |
| 367 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 368 | match = packet_to_flow_match(self, pkt) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 369 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 370 | self.assertTrue(match is not None, |
| 371 | "Could not generate flow match from pkt") |
| 372 | |
| 373 | # Get queue stats from switch |
| 374 | |
| 375 | request = message.queue_stats_request() |
| 376 | request.port_no = ofp.OFPP_CONTROLLER |
| 377 | request.queue_id = ofp.OFPQ_ALL |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 378 | (queue_stats, p) = self.controller.transact(request) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 379 | self.assertNotEqual(queue_stats, None, "Queue stats request failed") |
| 380 | |
| 381 | act = action.action_enqueue() |
| 382 | |
| 383 | for idx in range(len(of_ports)): |
| 384 | ingress_port = of_ports[idx] |
| 385 | egress_port = ofp.OFPP_CONTROLLER |
| 386 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 387 | logging.info("Ingress port " + str(ingress_port) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 388 | + ", controller port queues " |
| 389 | + str(self.portQueuesGet(queue_stats, egress_port))) |
| 390 | |
| 391 | for egress_queue_id in self.portQueuesGet(queue_stats, egress_port): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 392 | logging.info("Ingress " + str(ingress_port) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 393 | + " to egress " + str(egress_port) |
| 394 | + " queue " + str(egress_queue_id) |
| 395 | ) |
| 396 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 397 | rv = delete_all_flows(self.controller) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 398 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 399 | |
| 400 | match.in_port = ingress_port |
| 401 | |
| 402 | request = message.flow_mod() |
| 403 | request.match = match |
| 404 | |
| 405 | request.buffer_id = 0xffffffff |
| 406 | act.port = egress_port |
| 407 | act.queue_id = egress_queue_id |
| 408 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 409 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 410 | logging.info("Inserting flow") |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 411 | rv = self.controller.message_send(request) |
| 412 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 413 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 414 | |
| 415 | # Get current stats for selected egress queue |
| 416 | |
| 417 | request = message.queue_stats_request() |
| 418 | request.port_no = egress_port |
| 419 | request.queue_id = egress_queue_id |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 420 | (qs_before, p) = self.controller.transact(request) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 421 | self.assertNotEqual(qs_before, None, "Queue stats request failed") |
| 422 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 423 | logging.info("Sending packet to dp port " + |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 424 | str(ingress_port)) |
| 425 | self.dataplane.send(ingress_port, str(pkt)) |
| 426 | |
| 427 | exp_pkt_arg = None |
| 428 | exp_port = None |
| 429 | |
Rich Lane | e5779d3 | 2012-10-05 17:56:04 -0700 | [diff] [blame] | 430 | count = 0 |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 431 | while True: |
Dan Talayco | c689a79 | 2012-09-28 14:22:53 -0700 | [diff] [blame] | 432 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 433 | if not response: # Timeout |
| 434 | break |
| 435 | if dataplane.match_exp_pkt(pkt, response.data): # Got match |
| 436 | break |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 437 | if not config["relax"]: # Only one attempt to match |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 438 | break |
| 439 | count += 1 |
| 440 | if count > 10: # Too many tries |
| 441 | break |
| 442 | |
| 443 | self.assertTrue(response is not None, |
| 444 | 'Packet in message not received by controller') |
| 445 | if not dataplane.match_exp_pkt(pkt, response.data): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 446 | logging.debug("Sent %s" % format_packet(pkt)) |
| 447 | logging.debug("Resp %s" % format_packet(response.data)) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 448 | self.assertTrue(False, |
| 449 | 'Response packet does not match send packet' + |
| 450 | ' for controller port') |
| 451 | |
| 452 | # FIXME: instead of sleeping, keep requesting queue stats until |
| 453 | # the expected queue counter increases or some large timeout is |
| 454 | # reached |
| 455 | time.sleep(2) |
| 456 | |
| 457 | # Get current stats for selected egress queue again |
| 458 | |
| 459 | request = message.queue_stats_request() |
| 460 | request.port_no = egress_port |
| 461 | request.queue_id = egress_queue_id |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 462 | (qs_after, p) = self.controller.transact(request) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 463 | self.assertNotEqual(qs_after, None, "Queue stats request failed") |
| 464 | |
| 465 | # Make sure that tx packet counter for selected egress queue was |
| 466 | # incremented |
| 467 | |
| 468 | self.assertEqual(qs_after.stats[0].tx_packets, \ |
| 469 | qs_before.stats[0].tx_packets + 1, \ |
| 470 | "Verification of egress queue tx packet count failed" |
| 471 | ) |
| 472 | |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 473 | |
Tatsuya Yabe | b8fb3c3 | 2010-06-14 15:48:36 -0700 | [diff] [blame] | 474 | class DirectPacketICMP(DirectPacket): |
| 475 | """ |
| 476 | Send ICMP packet to single egress port |
| 477 | |
| 478 | Generate a ICMP packet |
| 479 | Generate and install a matching flow |
| 480 | Add action to direct the packet to an egress port |
| 481 | Send the packet to ingress dataplane port |
| 482 | Verify the packet is received at the egress port only |
| 483 | Difference from DirectPacket test is that sent packet is ICMP |
| 484 | """ |
| 485 | def runTest(self): |
| 486 | self.handleFlow(pkttype='ICMP') |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 487 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 488 | class DirectTwoPorts(base_tests.SimpleDataPlane): |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 489 | """ |
| 490 | Send packet to two egress ports |
| 491 | |
| 492 | Generate a packet |
| 493 | Generate and install a matching flow |
| 494 | Add action to direct the packet to two egress ports |
| 495 | Send the packet to ingress dataplane port |
| 496 | Verify the packet is received at the two egress ports |
| 497 | """ |
| 498 | def runTest(self): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 499 | of_ports = config["port_map"].keys() |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 500 | of_ports.sort() |
| 501 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 502 | |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 503 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 504 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 505 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 506 | self.assertTrue(match is not None, |
| 507 | "Could not generate flow match from pkt") |
| 508 | act = action.action_output() |
| 509 | |
| 510 | for idx in range(len(of_ports)): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 511 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 512 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 513 | |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 514 | ingress_port = of_ports[idx] |
| 515 | egress_port1 = of_ports[(idx + 1) % len(of_ports)] |
| 516 | egress_port2 = of_ports[(idx + 2) % len(of_ports)] |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 517 | logging.info("Ingress " + str(ingress_port) + |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 518 | " to egress " + str(egress_port1) + " and " + |
| 519 | str(egress_port2)) |
| 520 | |
| 521 | match.in_port = ingress_port |
| 522 | |
| 523 | request = message.flow_mod() |
| 524 | request.match = match |
| 525 | request.buffer_id = 0xffffffff |
| 526 | act.port = egress_port1 |
| 527 | self.assertTrue(request.actions.add(act), "Could not add action1") |
| 528 | act.port = egress_port2 |
| 529 | self.assertTrue(request.actions.add(act), "Could not add action2") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 530 | # logging.info(request.show()) |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 531 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 532 | logging.info("Inserting flow") |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 533 | rv = self.controller.message_send(request) |
| 534 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 535 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 536 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 537 | logging.info("Sending packet to dp port " + |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 538 | str(ingress_port)) |
| 539 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 540 | yes_ports = set([egress_port1, egress_port2]) |
| 541 | no_ports = set(of_ports).difference(yes_ports) |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 542 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 543 | receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 544 | self) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 545 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 546 | class DirectMCNonIngress(base_tests.SimpleDataPlane): |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 547 | """ |
| 548 | Multicast to all non-ingress ports |
| 549 | |
| 550 | Generate a packet |
| 551 | Generate and install a matching flow |
| 552 | Add action to direct the packet to all non-ingress ports |
| 553 | Send the packet to ingress dataplane port |
| 554 | Verify the packet is received at all non-ingress ports |
| 555 | |
| 556 | Does not use the flood action |
| 557 | """ |
| 558 | def runTest(self): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 559 | of_ports = config["port_map"].keys() |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 560 | of_ports.sort() |
| 561 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 562 | |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 563 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 564 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 565 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 566 | self.assertTrue(match is not None, |
| 567 | "Could not generate flow match from pkt") |
| 568 | act = action.action_output() |
| 569 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 570 | for ingress_port in of_ports: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 571 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 572 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 573 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 574 | logging.info("Ingress " + str(ingress_port) + |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 575 | " all non-ingress ports") |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 576 | match.in_port = ingress_port |
| 577 | |
| 578 | request = message.flow_mod() |
| 579 | request.match = match |
| 580 | request.buffer_id = 0xffffffff |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 581 | for egress_port in of_ports: |
| 582 | if egress_port == ingress_port: |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 583 | continue |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 584 | act.port = egress_port |
| 585 | self.assertTrue(request.actions.add(act), |
| 586 | "Could not add output to " + str(egress_port)) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 587 | logging.debug(request.show()) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 588 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 589 | logging.info("Inserting flow") |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 590 | rv = self.controller.message_send(request) |
| 591 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 592 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 593 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 594 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 595 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 596 | yes_ports = set(of_ports).difference([ingress_port]) |
| 597 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 598 | self) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 599 | |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 600 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 601 | class DirectMC(base_tests.SimpleDataPlane): |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 602 | """ |
| 603 | Multicast to all ports including ingress |
| 604 | |
| 605 | Generate a packet |
| 606 | Generate and install a matching flow |
| 607 | Add action to direct the packet to all non-ingress ports |
| 608 | Send the packet to ingress dataplane port |
| 609 | Verify the packet is received at all ports |
| 610 | |
| 611 | Does not use the flood action |
| 612 | """ |
| 613 | def runTest(self): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 614 | of_ports = config["port_map"].keys() |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 615 | of_ports.sort() |
| 616 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 617 | |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 618 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 619 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 620 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 621 | self.assertTrue(match is not None, |
| 622 | "Could not generate flow match from pkt") |
| 623 | act = action.action_output() |
| 624 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 625 | for ingress_port in of_ports: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 626 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 627 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 628 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 629 | logging.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 630 | match.in_port = ingress_port |
| 631 | |
| 632 | request = message.flow_mod() |
| 633 | request.match = match |
| 634 | request.buffer_id = 0xffffffff |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 635 | for egress_port in of_ports: |
| 636 | if egress_port == ingress_port: |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 637 | act.port = ofp.OFPP_IN_PORT |
| 638 | else: |
| 639 | act.port = egress_port |
| 640 | self.assertTrue(request.actions.add(act), |
| 641 | "Could not add output to " + str(egress_port)) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 642 | # logging.info(request.show()) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 643 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 644 | logging.info("Inserting flow") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 645 | rv = self.controller.message_send(request) |
| 646 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 647 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 648 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 649 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 650 | self.dataplane.send(ingress_port, str(pkt)) |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 651 | receive_pkt_check(self.dataplane, pkt, of_ports, [], self) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 652 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 653 | class Flood(base_tests.SimpleDataPlane): |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 654 | """ |
| 655 | Flood to all ports except ingress |
| 656 | |
| 657 | Generate a packet |
| 658 | Generate and install a matching flow |
| 659 | Add action to flood the packet |
| 660 | Send the packet to ingress dataplane port |
| 661 | Verify the packet is received at all other ports |
| 662 | """ |
| 663 | def runTest(self): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 664 | of_ports = config["port_map"].keys() |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 665 | of_ports.sort() |
| 666 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 667 | |
| 668 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 669 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 670 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 671 | self.assertTrue(match is not None, |
| 672 | "Could not generate flow match from pkt") |
| 673 | act = action.action_output() |
| 674 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 675 | for ingress_port in of_ports: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 676 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 677 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 678 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 679 | logging.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 680 | match.in_port = ingress_port |
| 681 | |
| 682 | request = message.flow_mod() |
| 683 | request.match = match |
| 684 | request.buffer_id = 0xffffffff |
| 685 | act.port = ofp.OFPP_FLOOD |
| 686 | self.assertTrue(request.actions.add(act), |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 687 | "Could not add flood port action") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 688 | logging.info(request.show()) |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 689 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 690 | logging.info("Inserting flow") |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 691 | rv = self.controller.message_send(request) |
| 692 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 693 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 694 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 695 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 696 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 697 | yes_ports = set(of_ports).difference([ingress_port]) |
| 698 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 699 | self) |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 700 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 701 | class FloodPlusIngress(base_tests.SimpleDataPlane): |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 702 | """ |
| 703 | Flood to all ports plus send to ingress port |
| 704 | |
| 705 | Generate a packet |
| 706 | Generate and install a matching flow |
| 707 | Add action to flood the packet |
| 708 | Add action to send to ingress port |
| 709 | Send the packet to ingress dataplane port |
| 710 | Verify the packet is received at all other ports |
| 711 | """ |
| 712 | def runTest(self): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 713 | of_ports = config["port_map"].keys() |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 714 | of_ports.sort() |
| 715 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 716 | |
| 717 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 718 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 719 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 720 | self.assertTrue(match is not None, |
| 721 | "Could not generate flow match from pkt") |
| 722 | act = action.action_output() |
| 723 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 724 | for ingress_port in of_ports: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 725 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 726 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 727 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 728 | logging.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 729 | match.in_port = ingress_port |
| 730 | |
| 731 | request = message.flow_mod() |
| 732 | request.match = match |
| 733 | request.buffer_id = 0xffffffff |
| 734 | act.port = ofp.OFPP_FLOOD |
| 735 | self.assertTrue(request.actions.add(act), |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 736 | "Could not add flood port action") |
| 737 | act.port = ofp.OFPP_IN_PORT |
| 738 | self.assertTrue(request.actions.add(act), |
| 739 | "Could not add ingress port for output") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 740 | logging.info(request.show()) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 741 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 742 | logging.info("Inserting flow") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 743 | rv = self.controller.message_send(request) |
| 744 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 745 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 746 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 747 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 748 | self.dataplane.send(ingress_port, str(pkt)) |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 749 | receive_pkt_check(self.dataplane, pkt, of_ports, [], self) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 750 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 751 | class All(base_tests.SimpleDataPlane): |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 752 | """ |
| 753 | Send to OFPP_ALL port |
| 754 | |
| 755 | Generate a packet |
| 756 | Generate and install a matching flow |
| 757 | Add action to forward to OFPP_ALL |
| 758 | Send the packet to ingress dataplane port |
| 759 | Verify the packet is received at all other ports |
| 760 | """ |
| 761 | def runTest(self): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 762 | of_ports = config["port_map"].keys() |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 763 | of_ports.sort() |
| 764 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 765 | |
| 766 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 767 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 768 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 769 | self.assertTrue(match is not None, |
| 770 | "Could not generate flow match from pkt") |
| 771 | act = action.action_output() |
| 772 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 773 | for ingress_port in of_ports: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 774 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 775 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 776 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 777 | logging.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 778 | match.in_port = ingress_port |
| 779 | |
| 780 | request = message.flow_mod() |
| 781 | request.match = match |
| 782 | request.buffer_id = 0xffffffff |
| 783 | act.port = ofp.OFPP_ALL |
| 784 | self.assertTrue(request.actions.add(act), |
| 785 | "Could not add ALL port action") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 786 | logging.info(request.show()) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 787 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 788 | logging.info("Inserting flow") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 789 | rv = self.controller.message_send(request) |
| 790 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 791 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 792 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 793 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 794 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 795 | yes_ports = set(of_ports).difference([ingress_port]) |
| 796 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 797 | self) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 798 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 799 | class AllPlusIngress(base_tests.SimpleDataPlane): |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 800 | """ |
| 801 | Send to OFPP_ALL port and ingress port |
| 802 | |
| 803 | Generate a packet |
| 804 | Generate and install a matching flow |
| 805 | Add action to forward to OFPP_ALL |
| 806 | Add action to forward to ingress port |
| 807 | Send the packet to ingress dataplane port |
| 808 | Verify the packet is received at all other ports |
| 809 | """ |
| 810 | def runTest(self): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 811 | of_ports = config["port_map"].keys() |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 812 | of_ports.sort() |
| 813 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 814 | |
| 815 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 816 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 817 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 818 | self.assertTrue(match is not None, |
| 819 | "Could not generate flow match from pkt") |
| 820 | act = action.action_output() |
| 821 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 822 | for ingress_port in of_ports: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 823 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 824 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 825 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 826 | logging.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 827 | match.in_port = ingress_port |
| 828 | |
| 829 | request = message.flow_mod() |
| 830 | request.match = match |
| 831 | request.buffer_id = 0xffffffff |
| 832 | act.port = ofp.OFPP_ALL |
| 833 | self.assertTrue(request.actions.add(act), |
| 834 | "Could not add ALL port action") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 835 | act.port = ofp.OFPP_IN_PORT |
| 836 | self.assertTrue(request.actions.add(act), |
| 837 | "Could not add ingress port for output") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 838 | logging.info(request.show()) |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 839 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 840 | logging.info("Inserting flow") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 841 | rv = self.controller.message_send(request) |
| 842 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 843 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 844 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 845 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 846 | self.dataplane.send(ingress_port, str(pkt)) |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 847 | receive_pkt_check(self.dataplane, pkt, of_ports, [], self) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 848 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 849 | class FloodMinusPort(base_tests.SimpleDataPlane): |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 850 | """ |
| 851 | Config port with No_Flood and test Flood action |
| 852 | |
| 853 | Generate a packet |
| 854 | Generate a matching flow |
| 855 | Add action to forward to OFPP_ALL |
| 856 | Set port to no-flood |
| 857 | Send the packet to ingress dataplane port |
| 858 | Verify the packet is received at all other ports except |
| 859 | the ingress port and the no_flood port |
| 860 | """ |
| 861 | def runTest(self): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 862 | of_ports = config["port_map"].keys() |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 863 | of_ports.sort() |
| 864 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 865 | |
| 866 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 867 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 868 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 869 | self.assertTrue(match is not None, |
| 870 | "Could not generate flow match from pkt") |
| 871 | act = action.action_output() |
| 872 | |
| 873 | for idx in range(len(of_ports)): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 874 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 875 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 876 | |
| 877 | ingress_port = of_ports[idx] |
| 878 | no_flood_idx = (idx + 1) % len(of_ports) |
| 879 | no_flood_port = of_ports[no_flood_idx] |
| 880 | rv = port_config_set(self.controller, no_flood_port, |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 881 | ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 882 | self.assertEqual(rv, 0, "Failed to set port config") |
| 883 | |
| 884 | match.in_port = ingress_port |
| 885 | |
| 886 | request = message.flow_mod() |
| 887 | request.match = match |
| 888 | request.buffer_id = 0xffffffff |
| 889 | act.port = ofp.OFPP_FLOOD |
| 890 | self.assertTrue(request.actions.add(act), |
| 891 | "Could not add flood port action") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 892 | logging.info(request.show()) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 893 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 894 | logging.info("Inserting flow") |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 895 | rv = self.controller.message_send(request) |
| 896 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 897 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 898 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 899 | logging.info("Sending packet to dp port " + str(ingress_port)) |
| 900 | logging.info("No flood port is " + str(no_flood_port)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 901 | self.dataplane.send(ingress_port, str(pkt)) |
| 902 | no_ports = set([ingress_port, no_flood_port]) |
| 903 | yes_ports = set(of_ports).difference(no_ports) |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 904 | receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, self) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 905 | |
| 906 | # Turn no flood off again |
| 907 | rv = port_config_set(self.controller, no_flood_port, |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 908 | 0, ofp.OFPPC_NO_FLOOD) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 909 | self.assertEqual(rv, 0, "Failed to reset port config") |
| 910 | |
| 911 | #@todo Should check no other packets received |
| 912 | |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 913 | |
| 914 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 915 | ################################################################ |
| 916 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 917 | class BaseMatchCase(base_tests.SimpleDataPlane): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 918 | def setUp(self): |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 919 | base_tests.SimpleDataPlane.setUp(self) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 920 | def runTest(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 921 | logging.info("BaseMatchCase") |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 922 | |
| 923 | class ExactMatch(BaseMatchCase): |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 924 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 925 | Exercise exact matching for all port pairs |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 926 | |
| 927 | Generate a packet |
| 928 | Generate and install a matching flow without wildcard mask |
| 929 | Add action to forward to a port |
| 930 | Send the packet to the port |
| 931 | 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] | 932 | """ |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 933 | |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 934 | def runTest(self): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 935 | flow_match_test(self, config["port_map"]) |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 936 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 937 | class ExactMatchTagged(BaseMatchCase): |
| 938 | """ |
| 939 | Exact match for all port pairs with tagged pkts |
| 940 | """ |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 941 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 942 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 943 | vid = test_param_get('vid', default=TEST_VID_DEFAULT) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 944 | flow_match_test(self, config["port_map"], dl_vlan=vid) |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 945 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 946 | class ExactMatchTaggedMany(BaseMatchCase): |
| 947 | """ |
| 948 | ExactMatchTagged with many VLANS |
| 949 | """ |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 950 | |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 951 | priority = -1 |
| 952 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 953 | def runTest(self): |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 954 | for vid in range(2,100,10): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 955 | 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] | 956 | for vid in range(100,4000,389): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 957 | flow_match_test(self, config["port_map"], dl_vlan=vid, max_test=5) |
| 958 | 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] | 959 | |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 960 | class SingleWildcardMatchPriority(BaseMatchCase): |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 961 | """ |
| 962 | SingleWildcardMatchPriority |
| 963 | """ |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 964 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 965 | def _Init(self): |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 966 | self.pkt = simple_tcp_packet() |
| 967 | self.flowMsgs = {} |
| 968 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 969 | def _ClearTable(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 970 | rc = delete_all_flows(self.controller) |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 971 | self.assertEqual(rc, 0, "Failed to delete all flows") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 972 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 973 | |
| 974 | def runTest(self): |
| 975 | |
| 976 | self._Init() |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 977 | of_ports = config["port_map"].keys() |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 978 | of_ports.sort() |
| 979 | |
| 980 | # Delete the initial flow table |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 981 | self._ClearTable() |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 982 | |
| 983 | # Run several combinations, each at lower priority settings. |
| 984 | # At the end of each call to runPrioFlows(), the table should |
| 985 | # be empty. If its not, we'll catch it as the priorities decreases |
| 986 | portA = of_ports[0] |
| 987 | portB = of_ports[1] |
| 988 | portC = of_ports[2] |
| 989 | |
| 990 | # TODO -- these priority numbers should be validated somehow? |
| 991 | self.runPrioFlows(portA, portB, portC, 1000, 999) |
| 992 | self.runPrioFlows(portB, portC, portA, 998, 997) |
| 993 | self.runPrioFlows(portC, portA, portB, 996, 995) |
| 994 | self.runPrioFlows(portA, portC, portB, 994, 993) |
| 995 | |
| 996 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 997 | |
| 998 | def runPrioFlows(self, portA, portB, portC, prioHigher, prioLower, |
| 999 | clearTable=False): |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1000 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1001 | if clearTable: |
| 1002 | self._ClearTable() |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1003 | |
| 1004 | # Sanity check flow at lower priority from pA to pB |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1005 | 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] | 1006 | % (portA, portB, portC, prioHigher, prioLower)) |
| 1007 | |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1008 | # Sanity check flow at lower priority from pA to pC |
| 1009 | self.installFlow(prioLower, portA, portC) |
| 1010 | self.verifyFlow(portA, portC) |
| 1011 | self.removeFlow(prioLower) |
| 1012 | |
| 1013 | # Install and verify pA->pB @ prioLower |
| 1014 | self.installFlow(prioLower, portA, portB) |
| 1015 | self.verifyFlow(portA, portB) |
| 1016 | |
| 1017 | # Install and verify pA->pC @ prioHigher, should override pA->pB |
| 1018 | self.installFlow(prioHigher, portA, portC) |
| 1019 | self.verifyFlow(portA, portC) |
| 1020 | # remove pA->pC |
| 1021 | self.removeFlow(prioHigher) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1022 | # Old flow pA -> pB @ prioLower should still be active |
| 1023 | self.verifyFlow(portA, portB) |
| 1024 | self.removeFlow(prioLower) |
| 1025 | |
| 1026 | # Table should be empty at this point, leave it alone as |
| 1027 | # an assumption for future test runs |
| 1028 | |
| 1029 | |
| 1030 | |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1031 | def installFlow(self, prio, inp, egp, |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1032 | wildcards=ofp.OFPFW_DL_SRC): |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1033 | wildcards |= required_wildcards(self) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1034 | request = flow_msg_create(self, self.pkt, ing_port=inp, |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1035 | wildcards=wildcards, |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1036 | egr_ports=egp) |
| 1037 | request.priority = prio |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1038 | logging.debug("Install flow with priority " + str(prio)) |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1039 | flow_msg_install(self, request, clear_table_override=False) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1040 | self.flowMsgs[prio] = request |
| 1041 | |
| 1042 | def removeFlow(self, prio): |
| 1043 | if self.flowMsgs.has_key(prio): |
| 1044 | msg = self.flowMsgs[prio] |
| 1045 | msg.command = ofp.OFPFC_DELETE_STRICT |
| 1046 | # This *must* be set for DELETE |
| 1047 | msg.out_port = ofp.OFPP_NONE |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1048 | logging.debug("Remove flow with priority " + str(prio)) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1049 | self.controller.message_send(msg) |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 1050 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1051 | else: |
| 1052 | raise Exception("Not initialized") |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1053 | |
| 1054 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1055 | def verifyFlow(self, inp, egp, pkt=None): |
| 1056 | if pkt == None: |
| 1057 | pkt = self.pkt |
| 1058 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1059 | logging.info("Pkt match test: " + str(inp) + " to " + str(egp)) |
| 1060 | logging.debug("Send packet: " + str(inp) + " to " + str(egp)) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1061 | self.dataplane.send(inp, str(pkt)) |
| 1062 | receive_pkt_verify(self, egp, pkt, inp) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1063 | |
| 1064 | |
| 1065 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1066 | class SingleWildcardMatchPriorityInsertModifyDelete(SingleWildcardMatchPriority): |
| 1067 | |
| 1068 | def runTest(self): |
| 1069 | |
| 1070 | self._Init() |
| 1071 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1072 | of_ports = config["port_map"].keys() |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1073 | of_ports.sort() |
| 1074 | |
| 1075 | # Install an entry from 0 -> 1 @ prio 1000 |
| 1076 | self._ClearTable() |
| 1077 | self.installFlow(1000, of_ports[0], of_ports[1]) |
| 1078 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1079 | self.installFlow(1000, of_ports[1], of_ports[0]) |
| 1080 | self.verifyFlow(of_ports[1], of_ports[0]) |
| 1081 | self.installFlow(1001, of_ports[0], of_ports[1]) |
| 1082 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1083 | self.installFlow(1001, of_ports[1], of_ports[0]) |
| 1084 | self.verifyFlow(of_ports[1], of_ports[0]) |
| 1085 | self.removeFlow(1001) |
| 1086 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1087 | self.removeFlow(1000) |
| 1088 | |
| 1089 | |
| 1090 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1091 | class WildcardPriority(SingleWildcardMatchPriority): |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1092 | """ |
| 1093 | 1. Add wildcard flow, verify packet received. |
| 1094 | 2. Add exact match flow with higher priority, verify packet received |
| 1095 | on port specified by this flow. |
| 1096 | 3. Add wildcard flow with even higher priority, verify packet received |
| 1097 | on port specified by this flow. |
| 1098 | """ |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1099 | |
| 1100 | def runTest(self): |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1101 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1102 | self._Init() |
| 1103 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1104 | of_ports = config["port_map"].keys() |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1105 | of_ports.sort() |
| 1106 | |
| 1107 | self._ClearTable() |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1108 | |
| 1109 | # Install a flow with wildcards |
| 1110 | self.installFlow(999, of_ports[0], of_ports[1], |
| 1111 | wildcards=ofp.OFPFW_DL_DST) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1112 | self.verifyFlow(of_ports[0], of_ports[1]) |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1113 | # Install a flow with no wildcards for our packet |
| 1114 | self.installFlow(1000, of_ports[0], of_ports[2], wildcards=0) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1115 | self.verifyFlow(of_ports[0], of_ports[2]) |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1116 | # Install a flow with wildcards for our packet with higher |
| 1117 | # priority |
| 1118 | self.installFlow(1001, of_ports[0], of_ports[3]) |
| 1119 | self.verifyFlow(of_ports[0], of_ports[3]) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1120 | |
| 1121 | |
Ken Chiang | 3978f24 | 2012-06-13 14:14:09 -0700 | [diff] [blame] | 1122 | class WildcardPriorityWithDelete(SingleWildcardMatchPriority): |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1123 | """ |
| 1124 | 1. Add exact match flow, verify packet received. |
| 1125 | 2. Add wildcard flow with higher priority, verify packet received on port |
| 1126 | specified by this flow. |
| 1127 | 3. Add exact match flow with even higher priority, verify packet received |
| 1128 | on port specified by this flow. |
| 1129 | 4. Delete lowest priority flow, verify packet received on port specified |
| 1130 | by highest priority flow. |
| 1131 | 5. Delete highest priority flow, verify packet received on port specified |
| 1132 | by remaining flow. |
| 1133 | """ |
| 1134 | |
| 1135 | def runTest(self): |
| 1136 | |
| 1137 | self._Init() |
| 1138 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1139 | of_ports = config["port_map"].keys() |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1140 | of_ports.sort() |
| 1141 | |
| 1142 | self._ClearTable() |
| 1143 | |
| 1144 | # Install an exact match flow |
| 1145 | self.installFlow(250, of_ports[0], of_ports[1], wildcards=0) |
| 1146 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1147 | # Install a flow with wildcards of higher priority |
| 1148 | self.installFlow(1250, of_ports[0], of_ports[2], |
| 1149 | wildcards=ofp.OFPFW_DL_DST) |
| 1150 | self.verifyFlow(of_ports[0], of_ports[2]) |
| 1151 | # Install an exact match flow with even higher priority |
| 1152 | self.installFlow(2001, of_ports[0], of_ports[3], wildcards=0) |
| 1153 | self.verifyFlow(of_ports[0], of_ports[3]) |
| 1154 | # Delete lowest priority flow |
| 1155 | self.removeFlow(250) |
| 1156 | self.verifyFlow(of_ports[0], of_ports[3]) |
| 1157 | # Delete highest priority flow |
| 1158 | self.removeFlow(2001) |
| 1159 | self.verifyFlow(of_ports[0], of_ports[2]) |
| 1160 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1161 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1162 | class SingleWildcardMatch(BaseMatchCase): |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 1163 | """ |
| 1164 | Exercise wildcard matching for all ports |
| 1165 | |
| 1166 | Generate a packet |
| 1167 | Generate and install a matching flow with wildcard mask |
| 1168 | Add action to forward to a port |
| 1169 | Send the packet to the port |
| 1170 | 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] | 1171 | Verify flow_expiration message is correct when command option is set |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 1172 | """ |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 1173 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1174 | vid = test_param_get('vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1175 | for wc in WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1176 | wc |= required_wildcards(self) |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1177 | if wc & ofp.OFPFW_DL_VLAN: |
Ken Chiang | 5be06dd | 2012-04-03 10:03:50 -0700 | [diff] [blame] | 1178 | # Set nonzero VLAN id to avoid sending priority-tagged packet |
| 1179 | dl_vlan = vid |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1180 | else: |
| 1181 | dl_vlan = -1 |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1182 | flow_match_test(self, config["port_map"], wildcards=wc, |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1183 | dl_vlan=dl_vlan, max_test=10) |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 1184 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1185 | class SingleWildcardMatchTagged(BaseMatchCase): |
| 1186 | """ |
| 1187 | SingleWildcardMatch with tagged packets |
| 1188 | """ |
| 1189 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1190 | vid = test_param_get('vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1191 | for wc in WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1192 | wc |= required_wildcards(self) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1193 | flow_match_test(self, config["port_map"], wildcards=wc, dl_vlan=vid, |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1194 | max_test=10) |
| 1195 | |
| 1196 | class AllExceptOneWildcardMatch(BaseMatchCase): |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 1197 | """ |
Dan Talayco | 80b54ed | 2010-07-13 09:48:35 -0700 | [diff] [blame] | 1198 | Match exactly one field |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 1199 | |
| 1200 | Generate a packet |
| 1201 | Generate and install a matching flow with wildcard all except one filed |
| 1202 | Add action to forward to a port |
| 1203 | Send the packet to the port |
| 1204 | Verify the packet is received at all other ports (one port at a time) |
| 1205 | Verify flow_expiration message is correct when command option is set |
| 1206 | """ |
| 1207 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1208 | vid = test_param_get('vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 1209 | for all_exp_one_wildcard in NO_WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1210 | all_exp_one_wildcard |= required_wildcards(self) |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1211 | if all_exp_one_wildcard & ofp.OFPFW_DL_VLAN: |
Ken Chiang | 5be06dd | 2012-04-03 10:03:50 -0700 | [diff] [blame] | 1212 | # Set nonzero VLAN id to avoid sending priority-tagged packet |
| 1213 | dl_vlan = vid |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1214 | else: |
| 1215 | dl_vlan = -1 |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1216 | flow_match_test(self, config["port_map"], wildcards=all_exp_one_wildcard, |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1217 | dl_vlan=dl_vlan) |
Tatsuya Yabe | e30ebe2 | 2010-05-25 09:30:49 -0700 | [diff] [blame] | 1218 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1219 | class AllExceptOneWildcardMatchTagged(BaseMatchCase): |
| 1220 | """ |
| 1221 | Match one field with tagged packets |
| 1222 | """ |
| 1223 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1224 | vid = test_param_get('vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 1225 | for all_exp_one_wildcard in NO_WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1226 | all_exp_one_wildcard |= required_wildcards(self) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1227 | flow_match_test(self, config["port_map"], wildcards=all_exp_one_wildcard, |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 1228 | dl_vlan=vid) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1229 | |
| 1230 | class AllWildcardMatch(BaseMatchCase): |
Tatsuya Yabe | e30ebe2 | 2010-05-25 09:30:49 -0700 | [diff] [blame] | 1231 | """ |
| 1232 | Create Wildcard-all flow and exercise for all ports |
| 1233 | |
| 1234 | Generate a packet |
| 1235 | Generate and install a matching flow with wildcard-all |
| 1236 | Add action to forward to a port |
| 1237 | Send the packet to the port |
| 1238 | Verify the packet is received at all other ports (one port at a time) |
| 1239 | Verify flow_expiration message is correct when command option is set |
| 1240 | """ |
| 1241 | def runTest(self): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1242 | flow_match_test(self, config["port_map"], wildcards=ofp.OFPFW_ALL) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1243 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1244 | class AllWildcardMatchTagged(BaseMatchCase): |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1245 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1246 | AllWildcardMatch with tagged packets |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1247 | """ |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1248 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1249 | vid = test_param_get('vid', default=TEST_VID_DEFAULT) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1250 | flow_match_test(self, config["port_map"], wildcards=ofp.OFPFW_ALL, |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 1251 | dl_vlan=vid) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1252 | |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1253 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1254 | class AddVLANTag(BaseMatchCase): |
| 1255 | """ |
| 1256 | Add a VLAN tag to an untagged packet |
| 1257 | """ |
| 1258 | def runTest(self): |
| 1259 | new_vid = 2 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1260 | sup_acts = self.supported_actions |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1261 | if not(sup_acts & 1<<ofp.OFPAT_SET_VLAN_VID): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1262 | skip_message_emit(self, "Add VLAN tag test") |
Dan Talayco | f36f108 | 2010-07-13 13:57:17 -0700 | [diff] [blame] | 1263 | return |
Tatsuya Yabe | f5ffb97 | 2010-05-26 15:36:33 -0700 | [diff] [blame] | 1264 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1265 | len = 100 |
| 1266 | len_w_vid = 104 |
| 1267 | pkt = simple_tcp_packet(pktlen=len) |
| 1268 | exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1269 | dl_vlan=new_vid) |
| 1270 | vid_act = action.action_set_vlan_vid() |
| 1271 | vid_act.vlan_vid = new_vid |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1272 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1273 | flow_match_test(self, config["port_map"], pkt=pkt, |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1274 | exp_pkt=exp_pkt, action_list=[vid_act]) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1275 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 1276 | class PacketOnly(base_tests.DataPlaneOnly): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1277 | """ |
| 1278 | Just send a packet thru the switch |
| 1279 | """ |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 1280 | |
| 1281 | priority = -1 |
| 1282 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1283 | def runTest(self): |
| 1284 | pkt = simple_tcp_packet() |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1285 | of_ports = config["port_map"].keys() |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1286 | of_ports.sort() |
| 1287 | ing_port = of_ports[0] |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1288 | logging.info("Sending packet to " + str(ing_port)) |
| 1289 | logging.debug("Data: " + str(pkt).encode('hex')) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1290 | self.dataplane.send(ing_port, str(pkt)) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1291 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 1292 | class PacketOnlyTagged(base_tests.DataPlaneOnly): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1293 | """ |
| 1294 | Just send a packet thru the switch |
| 1295 | """ |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 1296 | |
| 1297 | priority = -1 |
| 1298 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1299 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1300 | vid = test_param_get('vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1301 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1302 | of_ports = config["port_map"].keys() |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1303 | of_ports.sort() |
| 1304 | ing_port = of_ports[0] |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1305 | logging.info("Sending packet to " + str(ing_port)) |
| 1306 | logging.debug("Data: " + str(pkt).encode('hex')) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1307 | self.dataplane.send(ing_port, str(pkt)) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1308 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1309 | class ModifyVID(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1310 | """ |
| 1311 | Modify the VLAN ID in the VLAN tag of a tagged packet |
| 1312 | """ |
Dan Talayco | af66932 | 2012-09-12 22:51:22 -0700 | [diff] [blame] | 1313 | def setUp(self): |
| 1314 | BaseMatchCase.setUp(self) |
| 1315 | self.ing_port=False |
| 1316 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1317 | def runTest(self): |
| 1318 | old_vid = 2 |
| 1319 | new_vid = 3 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1320 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1321 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1322 | skip_message_emit(self, "Modify VLAN tag test") |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1323 | return |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1324 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1325 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=old_vid) |
| 1326 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=new_vid) |
| 1327 | vid_act = action.action_set_vlan_vid() |
| 1328 | vid_act.vlan_vid = new_vid |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1329 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1330 | 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] | 1331 | action_list=[vid_act], ing_port=self.ing_port) |
| 1332 | |
| 1333 | class ModifyVIDToIngress(ModifyVID): |
| 1334 | """ |
| 1335 | Modify the VLAN ID in the VLAN tag of a tagged packet and send to |
| 1336 | ingress port |
| 1337 | """ |
| 1338 | def setUp(self): |
| 1339 | BaseMatchCase.setUp(self) |
| 1340 | self.ing_port=True |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1341 | |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1342 | class ModifyVIDWithTagMatchWildcarded(BaseMatchCase): |
| 1343 | """ |
| 1344 | With vlan ID and priority wildcarded, perform SET_VLAN_VID action. |
| 1345 | The same flow should match on both untagged and tagged packets. |
| 1346 | """ |
| 1347 | def runTest(self): |
| 1348 | old_vid = 2 |
| 1349 | new_vid = 3 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1350 | sup_acts = self.supported_actions |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1351 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID): |
| 1352 | skip_message_emit(self, "ModifyVIDWithTagWildcarded test") |
| 1353 | return |
| 1354 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1355 | of_ports = config["port_map"].keys() |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1356 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 1357 | ing_port = of_ports[0] |
| 1358 | egr_ports = of_ports[1] |
| 1359 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1360 | rv = delete_all_flows(self.controller) |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1361 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 1362 | |
| 1363 | len_untagged = 100 |
| 1364 | len_w_vid = 104 |
| 1365 | untagged_pkt = simple_tcp_packet(pktlen=len_untagged) |
| 1366 | tagged_pkt = simple_tcp_packet(pktlen=len_w_vid, |
| 1367 | dl_vlan_enable=True, dl_vlan=old_vid) |
| 1368 | exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1369 | dl_vlan=new_vid) |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1370 | wildcards = (required_wildcards(self) | ofp.OFPFW_DL_VLAN | |
| 1371 | ofp.OFPFW_DL_VLAN_PCP) |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1372 | vid_act = action.action_set_vlan_vid() |
| 1373 | vid_act.vlan_vid = new_vid |
| 1374 | request = flow_msg_create(self, untagged_pkt, ing_port=ing_port, |
| 1375 | wildcards=wildcards, egr_ports=egr_ports, |
| 1376 | action_list=[vid_act]) |
| 1377 | flow_msg_install(self, request) |
| 1378 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1379 | logging.debug("Send untagged packet: " + str(ing_port) + " to " + |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1380 | str(egr_ports)) |
| 1381 | self.dataplane.send(ing_port, str(untagged_pkt)) |
| 1382 | receive_pkt_verify(self, egr_ports, exp_pkt, ing_port) |
| 1383 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1384 | logging.debug("Send tagged packet: " + str(ing_port) + " to " + |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1385 | str(egr_ports)) |
| 1386 | self.dataplane.send(ing_port, str(tagged_pkt)) |
| 1387 | receive_pkt_verify(self, egr_ports, exp_pkt, ing_port) |
| 1388 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 1389 | class ModifyVlanPcp(BaseMatchCase): |
| 1390 | """ |
| 1391 | Modify the priority field of the VLAN tag of a tagged packet |
| 1392 | """ |
| 1393 | def runTest(self): |
| 1394 | vid = 123 |
| 1395 | old_vlan_pcp = 2 |
| 1396 | new_vlan_pcp = 3 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1397 | sup_acts = self.supported_actions |
Ed Swierk | 8c3af7f | 2012-04-24 14:19:17 -0700 | [diff] [blame] | 1398 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP): |
| 1399 | skip_message_emit(self, "Modify VLAN priority test") |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 1400 | return |
| 1401 | |
| 1402 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=old_vlan_pcp) |
| 1403 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=new_vlan_pcp) |
| 1404 | vid_act = action.action_set_vlan_pcp() |
| 1405 | vid_act.vlan_pcp = new_vlan_pcp |
| 1406 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1407 | 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] | 1408 | action_list=[vid_act]) |
| 1409 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1410 | class StripVLANTag(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1411 | """ |
| 1412 | Strip the VLAN tag from a tagged packet |
| 1413 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1414 | def runTest(self): |
| 1415 | old_vid = 2 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1416 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1417 | if not (sup_acts & 1 << ofp.OFPAT_STRIP_VLAN): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1418 | skip_message_emit(self, "Strip VLAN tag test") |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1419 | return |
Dan Talayco | f36f108 | 2010-07-13 13:57:17 -0700 | [diff] [blame] | 1420 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1421 | len_w_vid = 104 |
| 1422 | len = 100 |
| 1423 | pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1424 | dl_vlan=old_vid) |
| 1425 | exp_pkt = simple_tcp_packet(pktlen=len) |
| 1426 | vid_act = action.action_strip_vlan() |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1427 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1428 | 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] | 1429 | action_list=[vid_act]) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1430 | |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1431 | class StripVLANTagWithTagMatchWildcarded(BaseMatchCase): |
| 1432 | """ |
| 1433 | Strip the VLAN tag from a tagged packet. |
| 1434 | Differs from StripVLANTag in that VID and PCP are both wildcarded. |
| 1435 | """ |
| 1436 | def runTest(self): |
| 1437 | old_vid = 2 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1438 | sup_acts = self.supported_actions |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1439 | if not (sup_acts & 1 << ofp.OFPAT_STRIP_VLAN): |
| 1440 | skip_message_emit(self, "StripVLANTagWithTagWildcarded test") |
| 1441 | return |
| 1442 | |
| 1443 | len_w_vid = 104 |
| 1444 | len_untagged = 100 |
| 1445 | pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1446 | dl_vlan=old_vid) |
| 1447 | exp_pkt = simple_tcp_packet(pktlen=len_untagged) |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1448 | wildcards = (required_wildcards(self) | ofp.OFPFW_DL_VLAN | |
| 1449 | ofp.OFPFW_DL_VLAN_PCP) |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1450 | vid_act = action.action_strip_vlan() |
| 1451 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1452 | flow_match_test(self, config["port_map"], |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1453 | wildcards=wildcards, |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1454 | pkt=pkt, exp_pkt=exp_pkt, |
| 1455 | action_list=[vid_act]) |
| 1456 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1457 | def init_pkt_args(): |
| 1458 | """ |
| 1459 | Pass back a dictionary with default packet arguments |
| 1460 | """ |
| 1461 | args = {} |
| 1462 | args["dl_src"] = '00:23:45:67:89:AB' |
| 1463 | |
| 1464 | dl_vlan_enable=False |
| 1465 | dl_vlan=-1 |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1466 | if config["test-params"]["vid"]: |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1467 | dl_vlan_enable=True |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1468 | dl_vlan = config["test-params"]["vid"] |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1469 | |
| 1470 | # Unpack operator is ** on a dictionary |
| 1471 | |
| 1472 | return args |
| 1473 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1474 | class ModifyL2Src(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1475 | """ |
| 1476 | Modify the source MAC address (TP1) |
| 1477 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1478 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1479 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1480 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1481 | skip_message_emit(self, "ModifyL2Src test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1482 | return |
| 1483 | |
| 1484 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'], |
| 1485 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1486 | 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] | 1487 | action_list=acts, max_test=2) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1488 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1489 | class ModifyL2Dst(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1490 | """ |
| 1491 | Modify the dest MAC address (TP1) |
| 1492 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1493 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1494 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1495 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1496 | skip_message_emit(self, "ModifyL2dst test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1497 | return |
| 1498 | |
| 1499 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1500 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1501 | 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] | 1502 | action_list=acts, max_test=2) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1503 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1504 | class ModifyL3Src(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1505 | """ |
| 1506 | Modify the source IP address of an IP packet (TP1) |
| 1507 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1508 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1509 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1510 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_SRC): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1511 | skip_message_emit(self, "ModifyL3Src test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1512 | return |
| 1513 | |
| 1514 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_src'], |
| 1515 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1516 | 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] | 1517 | action_list=acts, max_test=2) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1518 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1519 | class ModifyL3Dst(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1520 | """ |
| 1521 | Modify the dest IP address of an IP packet (TP1) |
| 1522 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1523 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1524 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1525 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_DST): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1526 | skip_message_emit(self, "ModifyL3Dst test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1527 | return |
| 1528 | |
| 1529 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_dst'], |
| 1530 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1531 | 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] | 1532 | action_list=acts, max_test=2) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1533 | |
| 1534 | class ModifyL4Src(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1535 | """ |
| 1536 | Modify the source TCP port of a TCP packet (TP1) |
| 1537 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1538 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1539 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1540 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_SRC): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1541 | skip_message_emit(self, "ModifyL4Src test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1542 | return |
| 1543 | |
| 1544 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_sport'], |
| 1545 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1546 | 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] | 1547 | action_list=acts, max_test=2) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1548 | |
| 1549 | class ModifyL4Dst(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1550 | """ |
| 1551 | Modify the dest TCP port of a TCP packet (TP1) |
| 1552 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1553 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1554 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1555 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1556 | skip_message_emit(self, "ModifyL4Dst test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1557 | return |
| 1558 | |
| 1559 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_dport'], |
| 1560 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1561 | 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] | 1562 | action_list=acts, max_test=2) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1563 | |
| 1564 | class ModifyTOS(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1565 | """ |
| 1566 | Modify the IP type of service of an IP packet (TP1) |
| 1567 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1568 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1569 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1570 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1571 | skip_message_emit(self, "ModifyTOS test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1572 | return |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1573 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1574 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_tos'], |
| 1575 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1576 | 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] | 1577 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1578 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1579 | class ModifyL2DstMC(BaseMatchCase): |
| 1580 | """ |
| 1581 | Modify the L2 dest and send to 2 ports |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1582 | """ |
| 1583 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1584 | sup_acts = self.supported_actions |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1585 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1586 | skip_message_emit(self, "ModifyL2dstMC test") |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1587 | return |
| 1588 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1589 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1590 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1591 | 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] | 1592 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1593 | |
Dan Talayco | c948d0b | 2012-03-23 12:17:54 -0700 | [diff] [blame] | 1594 | class ModifyL2DstIngress(BaseMatchCase): |
| 1595 | """ |
| 1596 | Modify the L2 dest and send to the ingress port |
| 1597 | """ |
| 1598 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1599 | sup_acts = self.supported_actions |
Dan Talayco | c948d0b | 2012-03-23 12:17:54 -0700 | [diff] [blame] | 1600 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1601 | skip_message_emit(self, "ModifyL2dstIngress test") |
Dan Talayco | c948d0b | 2012-03-23 12:17:54 -0700 | [diff] [blame] | 1602 | return |
| 1603 | |
| 1604 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1605 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1606 | 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] | 1607 | action_list=acts, max_test=2, egr_count=0, |
| 1608 | ing_port=True) |
| 1609 | |
Dan Talayco | d8ae758 | 2012-03-23 12:24:56 -0700 | [diff] [blame] | 1610 | class ModifyL2DstIngressMC(BaseMatchCase): |
| 1611 | """ |
| 1612 | Modify the L2 dest and send to the ingress port |
| 1613 | """ |
| 1614 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1615 | sup_acts = self.supported_actions |
Dan Talayco | d8ae758 | 2012-03-23 12:24:56 -0700 | [diff] [blame] | 1616 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
| 1617 | skip_message_emit(self, "ModifyL2dstMC test") |
| 1618 | return |
| 1619 | |
| 1620 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1621 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1622 | 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] | 1623 | action_list=acts, max_test=2, egr_count=-1, |
| 1624 | ing_port=True) |
| 1625 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1626 | class ModifyL2SrcMC(BaseMatchCase): |
| 1627 | """ |
| 1628 | Modify the source MAC address (TP1) and send to multiple |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1629 | """ |
| 1630 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1631 | sup_acts = self.supported_actions |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1632 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC): |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1633 | skip_message_emit(self, "ModifyL2SrcMC test") |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1634 | return |
| 1635 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1636 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'], |
| 1637 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1638 | 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] | 1639 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1640 | |
| 1641 | class ModifyL2SrcDstMC(BaseMatchCase): |
| 1642 | """ |
| 1643 | Modify the L2 source and dest and send to 2 ports |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1644 | """ |
| 1645 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1646 | sup_acts = self.supported_actions |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1647 | if (not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST) or |
| 1648 | not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC)): |
| 1649 | skip_message_emit(self, "ModifyL2SrcDstMC test") |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1650 | return |
| 1651 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1652 | mod_fields = ['dl_dst', 'dl_src'] |
| 1653 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=mod_fields, |
| 1654 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1655 | 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] | 1656 | action_list=acts, max_test=2, egr_count=-1) |
| 1657 | |
| 1658 | class ModifyL2DstVIDMC(BaseMatchCase): |
| 1659 | """ |
| 1660 | Modify the L2 dest and send to 2 ports |
| 1661 | """ |
| 1662 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1663 | sup_acts = self.supported_actions |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1664 | if (not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST) or |
| 1665 | not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID)): |
| 1666 | skip_message_emit(self, "ModifyL2DstVIDMC test") |
| 1667 | return |
| 1668 | |
| 1669 | mod_fields = ['dl_dst', 'dl_vlan'] |
| 1670 | (pkt, exp_pkt, acts) = pkt_action_setup(self, |
| 1671 | start_field_vals={'dl_vlan_enable':True}, mod_fields=mod_fields, |
| 1672 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1673 | 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] | 1674 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1675 | |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1676 | class FlowToggle(BaseMatchCase): |
| 1677 | """ |
| 1678 | Add flows to the table and modify them repeatedly |
Dan Talayco | f7c4131 | 2012-07-23 12:53:19 -0700 | [diff] [blame] | 1679 | |
| 1680 | This is done by using only "add" flow messages. Since the check overlap |
| 1681 | flag is not set, the switch is supposed to modify the existing flow if |
| 1682 | the match already exists. |
| 1683 | |
| 1684 | Would probably be better to exercise more of the flow modify commands |
| 1685 | (add, modify, delete +/- strict). |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1686 | """ |
| 1687 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1688 | flow_count = test_param_get('ft_flow_count', default=20) |
| 1689 | iter_count = test_param_get('ft_iter_count', default=10) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1690 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1691 | logging.info("Running flow toggle with %d flows, %d iterations" % |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1692 | (flow_count, iter_count)) |
| 1693 | acts = [] |
| 1694 | acts.append(action.action_output()) |
| 1695 | acts.append(action.action_output()) |
| 1696 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1697 | of_ports = config["port_map"].keys() |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1698 | if len(of_ports) < 3: |
| 1699 | self.assertTrue(False, "Too few ports for test") |
| 1700 | |
| 1701 | for idx in range(2): |
| 1702 | acts[idx].port = of_ports[idx] |
| 1703 | |
| 1704 | flows = [] |
| 1705 | flows.append([]) |
| 1706 | flows.append([]) |
| 1707 | |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1708 | wildcards = (required_wildcards(self) | ofp.OFPFW_DL_SRC | |
| 1709 | ofp.OFPFW_DL_DST) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1710 | # Create up the flows in an array |
| 1711 | for toggle in range(2): |
| 1712 | for f_idx in range(flow_count): |
| 1713 | pkt = simple_tcp_packet(tcp_sport=f_idx) |
| 1714 | msg = message.flow_mod() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1715 | match = packet_to_flow_match(self, pkt) |
Shudong Zhou | 031373c | 2012-07-19 17:37:42 -0700 | [diff] [blame] | 1716 | match.in_port = of_ports[2] |
Dan Talayco | 50be767 | 2012-04-05 11:38:08 -0700 | [diff] [blame] | 1717 | match.wildcards = wildcards |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1718 | msg.match = match |
| 1719 | msg.buffer_id = 0xffffffff |
Dan Talayco | f7c4131 | 2012-07-23 12:53:19 -0700 | [diff] [blame] | 1720 | msg.command = ofp.OFPFC_ADD |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1721 | msg.actions.add(acts[toggle]) |
| 1722 | flows[toggle].append(msg) |
Dan Talayco | 50be767 | 2012-04-05 11:38:08 -0700 | [diff] [blame] | 1723 | |
| 1724 | # Show two sample flows |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1725 | logging.debug(flows[0][0].show()) |
| 1726 | logging.debug(flows[1][0].show()) |
Dan Talayco | 50be767 | 2012-04-05 11:38:08 -0700 | [diff] [blame] | 1727 | |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1728 | # Install the first set of flows |
| 1729 | for f_idx in range(flow_count): |
| 1730 | rv = self.controller.message_send(flows[0][f_idx]) |
| 1731 | self.assertTrue(rv != -1, "Error installing flow %d" % f_idx) |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 1732 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1733 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1734 | logging.info("Installed %d flows" % flow_count) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1735 | |
| 1736 | # Repeatedly modify all the flows back and forth |
| 1737 | updates = 0 |
| 1738 | # Report status about 5 times |
| 1739 | mod_val = (iter_count / 4) + 1 |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1740 | start = time.time() |
| 1741 | for iter_idx in range(iter_count): |
| 1742 | if not iter_idx % mod_val: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1743 | logging.info("Flow Toggle: iter %d of %d. " % |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1744 | (iter_idx, iter_count) + |
| 1745 | "%d updates in %d secs" % |
| 1746 | (updates, time.time() - start)) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1747 | for toggle in range(2): |
| 1748 | t_idx = 1 - toggle |
| 1749 | for f_idx in range(flow_count): |
| 1750 | rv = self.controller.message_send(flows[t_idx][f_idx]) |
| 1751 | updates += 1 |
| 1752 | self.assertTrue(rv != -1, "Error modifying flow %d" % |
| 1753 | f_idx) |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 1754 | self.assertEqual(do_barrier(self.controller), 0, |
| 1755 | "Barrier failed") |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1756 | |
| 1757 | end = time.time() |
| 1758 | divisor = end - start or (end - start + 1) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1759 | logging.info("Flow toggle: %d iterations" % iter_count) |
| 1760 | logging.info(" %d flow mods in %d secs, %d mods/sec" % |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1761 | (updates, end - start, updates/divisor)) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1762 | |
| 1763 | |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1764 | # You can pick and choose these by commenting tests in or out |
| 1765 | iter_classes = [ |
| 1766 | basic.PacketIn, |
| 1767 | basic.PacketOut, |
| 1768 | DirectPacket, |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1769 | FlowToggle, |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1770 | DirectTwoPorts, |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1771 | DirectMCNonIngress, |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1772 | AllWildcardMatch, |
| 1773 | AllWildcardMatchTagged, |
| 1774 | SingleWildcardMatch, |
| 1775 | SingleWildcardMatchTagged, |
| 1776 | ExactMatch, |
| 1777 | ExactMatchTagged, |
| 1778 | SingleWildcardMatch, |
| 1779 | ModifyL2Src, |
| 1780 | ModifyL2Dst, |
| 1781 | ModifyL2SrcMC, |
| 1782 | ModifyL2DstMC, |
| 1783 | ModifyL2SrcDstMC |
| 1784 | ] |
| 1785 | |
| 1786 | class IterCases(BaseMatchCase): |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1787 | """ |
| 1788 | Iterate over a bunch of test cases |
| 1789 | |
| 1790 | The cases come from the list above |
| 1791 | """ |
| 1792 | |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 1793 | priority = -1 |
| 1794 | |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1795 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1796 | count = test_param_get('iter_count', default=10) |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1797 | tests_done = 0 |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1798 | logging.info("Running iteration test " + str(count) + " times") |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1799 | start = time.time() |
| 1800 | last = start |
| 1801 | for idx in range(count): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1802 | logging.info("Iteration " + str(idx + 1)) |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1803 | for cls in iter_classes: |
| 1804 | test = cls() |
| 1805 | test.inheritSetup(self) |
| 1806 | test.runTest() |
| 1807 | tests_done += 1 |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1808 | # Report update about every minute, between tests |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1809 | if time.time() - last > 60: |
| 1810 | last = time.time() |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1811 | logging.info( |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1812 | "IterCases: Iter %d of %d; Ran %d tests in %d " % |
| 1813 | (idx, count, tests_done, last - start) + |
| 1814 | "seconds so far") |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1815 | stats = all_stats_get(self) |
| 1816 | last = time.time() |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1817 | logging.info("\nIterCases ran %d tests in %d seconds." % |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1818 | (tests_done, last - start)) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1819 | logging.info(" flows: %d. packets: %d. bytes: %d" % |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1820 | (stats["flows"], stats["packets"], stats["bytes"])) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1821 | logging.info(" active: %d. lookups: %d. matched %d." % |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1822 | (stats["active"], stats["lookups"], stats["matched"])) |
| 1823 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1824 | #@todo Need to implement tagged versions of the above tests |
| 1825 | # |
| 1826 | #@todo Implement a test case that strips tag 2, adds tag 3 |
| 1827 | # and modifies tag 4 to tag 5. Then verify (in addition) that |
| 1828 | # tag 6 does not get modified. |
| 1829 | |
| 1830 | class MixedVLAN(BaseMatchCase): |
| 1831 | """ |
| 1832 | Test mixture of VLAN tag actions |
| 1833 | |
| 1834 | Strip tag 2 on port 1, send to port 2 |
| 1835 | Add tag 3 on port 1, send to port 2 |
| 1836 | Modify tag 4 to 5 on port 1, send to port 2 |
| 1837 | All other traffic from port 1, send to port 3 |
| 1838 | All traffic from port 2 sent to port 4 |
| 1839 | Use exact matches with different packets for all mods |
| 1840 | Verify the following: (port, vid) |
| 1841 | (port 1, vid 2) => VLAN tag stripped, out port 2 |
| 1842 | (port 1, no tag) => tagged packet w/ vid 2 out port 2 |
| 1843 | (port 1, vid 4) => tagged packet w/ vid 5 out port 2 |
| 1844 | (port 1, vid 5) => tagged packet w/ vid 5 out port 2 |
| 1845 | (port 1, vid 6) => tagged packet w/ vid 6 out port 2 |
| 1846 | (port 2, no tag) => untagged packet out port 4 |
| 1847 | (port 2, vid 2-6) => unmodified packet out port 4 |
| 1848 | |
| 1849 | Variation: Might try sending VID 5 to port 3 and check. |
| 1850 | If only VID 5 distinguishes pkt, this will fail on some platforms |
| 1851 | """ |
| 1852 | |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 1853 | priority = -1 |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1854 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 1855 | class MatchEach(base_tests.SimpleDataPlane): |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1856 | """ |
| 1857 | Check that each match field is actually matched on. |
| 1858 | Installs two flows that differ in one field. The flow that should not |
| 1859 | match has a higher priority, so if that field is ignored during matching |
| 1860 | the packet will be sent out the wrong port. |
| 1861 | |
| 1862 | TODO test UDP, ARP, ICMP, etc. |
| 1863 | """ |
| 1864 | def runTest(self): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1865 | of_ports = config["port_map"].keys() |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1866 | of_ports.sort() |
| 1867 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 1868 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1869 | delete_all_flows(self.controller) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1870 | |
| 1871 | pkt = simple_tcp_packet() |
| 1872 | ingress_port = of_ports[0] |
| 1873 | egress_port = of_ports[1] |
| 1874 | |
| 1875 | def testField(field, mask): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1876 | logging.info("Testing field %s" % field) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1877 | |
| 1878 | def addFlow(matching, priority, output_port): |
| 1879 | match = packet_to_flow_match(self, pkt) |
| 1880 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 1881 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 1882 | match.in_port = ingress_port |
| 1883 | if not matching: |
| 1884 | # Make sure flow doesn't match |
| 1885 | orig = getattr(match, field) |
| 1886 | if isinstance(orig, list): |
| 1887 | new = map(lambda a: ~a[0] & a[1], zip(orig, mask)) |
| 1888 | else: |
| 1889 | new = ~orig & mask |
| 1890 | setattr(match, field, new) |
| 1891 | request = message.flow_mod() |
| 1892 | request.match = match |
| 1893 | request.buffer_id = 0xffffffff |
| 1894 | request.priority = priority |
| 1895 | act = action.action_output() |
| 1896 | act.port = output_port |
| 1897 | self.assertTrue(request.actions.add(act), "Could not add action") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1898 | logging.info("Inserting flow") |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1899 | self.controller.message_send(request) |
| 1900 | |
| 1901 | # This flow should match. |
| 1902 | addFlow(matching=True, priority=0, output_port=egress_port) |
| 1903 | # This flow should not match, but it has a higher priority. |
| 1904 | addFlow(matching=False, priority=1, output_port=ofp.OFPP_IN_PORT) |
| 1905 | |
| 1906 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 1907 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1908 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1909 | self.dataplane.send(ingress_port, str(pkt)) |
| 1910 | |
| 1911 | exp_pkt_arg = None |
| 1912 | exp_port = None |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1913 | if config["relax"]: |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1914 | exp_pkt_arg = pkt |
| 1915 | exp_port = egress_port |
| 1916 | |
| 1917 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(port_number=exp_port, |
| 1918 | exp_pkt=exp_pkt_arg) |
| 1919 | self.assertTrue(rcv_pkt is not None, "Did not receive packet") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1920 | 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] | 1921 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 1922 | self.assertEqual(str(pkt), str(rcv_pkt), 'Response packet does not match send packet') |
| 1923 | |
| 1924 | # TODO in_port |
| 1925 | testField("dl_src", [0xff]*6) |
| 1926 | testField("dl_dst", [0xff]*6) |
| 1927 | testField("dl_type", 0xffff) |
| 1928 | testField("dl_vlan", 0xfff) |
| 1929 | # TODO dl_vlan_pcp |
| 1930 | testField("nw_src", 0xffffffff) |
| 1931 | testField("nw_dst", 0xffffffff) |
| 1932 | testField("nw_tos", 0x3f) |
| 1933 | testField("nw_proto", 0xff) |
| 1934 | testField("tp_src", 0xffff) |
| 1935 | testField("tp_dst", 0xffff) |
| 1936 | |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 1937 | class DirectBadPacketBase(base_tests.SimpleDataPlane): |
| 1938 | """ |
| 1939 | Base class for sending single packets with single flow table entries. |
| 1940 | Used to verify matching of unusual packets and parsing/matching of |
| 1941 | corrupted packets. |
| 1942 | |
| 1943 | The idea is to generate packets that may either be totally malformed or |
| 1944 | malformed just enough to trick the flow matcher into making mistakes. |
| 1945 | |
| 1946 | Generate a 'bad' packet |
| 1947 | Generate and install a matching flow |
| 1948 | Add action to direct the packet to an egress port |
| 1949 | Send the packet to ingress dataplane port |
| 1950 | Verify the packet is received at the egress port only |
| 1951 | """ |
| 1952 | |
| 1953 | RESULT_MATCH = "MATCH" |
| 1954 | RESULT_NOMATCH = "NO MATCH" |
| 1955 | RESULT_ANY = "ANY MATCH" |
| 1956 | |
| 1957 | def runTest(self): |
| 1958 | pass |
| 1959 | # TODO: |
| 1960 | # - ICMP? |
| 1961 | # - VLAN? |
| 1962 | # - action |
| 1963 | |
| 1964 | def pktToStr(self, pkt): |
| 1965 | from cStringIO import StringIO |
| 1966 | backup = sys.stdout |
| 1967 | sys.stdout = StringIO() |
| 1968 | pkt.show2() |
| 1969 | out = sys.stdout.getvalue() |
| 1970 | sys.stdout.close() |
| 1971 | sys.stdout = backup |
| 1972 | return out |
| 1973 | |
| 1974 | def createMatch(self, **kwargs): |
| 1975 | match = ofp.ofp_match() |
| 1976 | match.wildcards = ofp.OFPFW_ALL |
| 1977 | fields = { |
| 1978 | 'dl_dst': ofp.OFPFW_DL_DST, |
| 1979 | 'dl_src': ofp.OFPFW_DL_SRC, |
| 1980 | 'dl_type': ofp.OFPFW_DL_TYPE, |
| 1981 | 'dl_vlan': ofp.OFPFW_DL_VLAN, |
| 1982 | 'nw_src': ofp.OFPFW_NW_SRC_MASK, |
| 1983 | 'nw_dst': ofp.OFPFW_NW_DST_MASK, |
| 1984 | 'nw_tos': ofp.OFPFW_NW_TOS, |
| 1985 | 'nw_proto': ofp.OFPFW_NW_PROTO, |
| 1986 | 'tp_src': ofp.OFPFW_TP_SRC, |
| 1987 | 'tp_dst': ofp.OFPFW_TP_DST, |
| 1988 | } |
| 1989 | for key in kwargs: |
| 1990 | setattr(match, key, kwargs[key]) |
| 1991 | match.wildcards &= ~fields[key] |
| 1992 | return match |
| 1993 | |
| 1994 | def testPktsAgainstFlow(self, pkts, acts, match): |
| 1995 | if type(acts) != list: |
| 1996 | acts = [acts] |
| 1997 | for info in pkts: |
| 1998 | title, pkt, expected_result = info |
| 1999 | self.testPktAgainstFlow(title, pkt, acts, match, expected_result) |
| 2000 | |
| 2001 | def testPktAgainstFlow(self, title, pkt, acts, match, expected_result): |
| 2002 | of_ports = config["port_map"].keys() |
| 2003 | of_ports.sort() |
| 2004 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 2005 | |
| 2006 | rv = delete_all_flows(self.controller) |
| 2007 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 2008 | |
| 2009 | ingress_port = of_ports[0] |
| 2010 | egress_port = of_ports[1] |
| 2011 | |
| 2012 | logging.info("Testing packet '%s', expect result %s" % |
| 2013 | (title, expected_result)) |
| 2014 | logging.info("Ingress %s to egress %s" % |
| 2015 | (str(ingress_port), str(egress_port))) |
| 2016 | logging.info("Packet:") |
| 2017 | logging.info(self.pktToStr(pkt)) |
| 2018 | |
| 2019 | match.in_port = ingress_port |
| 2020 | |
| 2021 | request = message.flow_mod() |
| 2022 | request.match = match |
Rich Lane | 44cf12d | 2012-10-15 11:10:45 -0700 | [diff] [blame^] | 2023 | request.priority = 1 |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2024 | |
| 2025 | request.buffer_id = 0xffffffff |
| 2026 | for act in acts: |
| 2027 | act.port = egress_port |
| 2028 | rv = request.actions.add(act) |
| 2029 | self.assertTrue(rv, "Could not add action") |
| 2030 | |
| 2031 | logging.info("Inserting flow") |
| 2032 | rv = self.controller.message_send(request) |
| 2033 | self.assertTrue(rv != -1, "Error installing flow mod") |
Rich Lane | 44cf12d | 2012-10-15 11:10:45 -0700 | [diff] [blame^] | 2034 | |
| 2035 | # This flow speeds up negative tests |
| 2036 | logging.info("Inserting catch-all flow") |
| 2037 | request2 = message.flow_mod() |
| 2038 | request2.match = self.createMatch() |
| 2039 | request2.priority = 0 |
| 2040 | act = action.action_output() |
| 2041 | act.port = ofp.OFPP_IN_PORT |
| 2042 | request2.actions.add(act) |
| 2043 | rv = self.controller.message_send(request2) |
| 2044 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 2045 | |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2046 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 2047 | |
| 2048 | logging.info("Sending packet to dp port " + |
| 2049 | str(ingress_port)) |
| 2050 | self.dataplane.send(ingress_port, str(pkt)) |
| 2051 | |
| 2052 | exp_pkt_arg = None |
| 2053 | exp_port = None |
| 2054 | if config["relax"]: |
| 2055 | exp_pkt_arg = pkt |
| 2056 | exp_port = egress_port |
| 2057 | |
Rich Lane | 44cf12d | 2012-10-15 11:10:45 -0700 | [diff] [blame^] | 2058 | if expected_result == self.RESULT_MATCH: |
| 2059 | timeout = -1 # default timeout |
| 2060 | else: |
| 2061 | timeout = 1 # short timeout for negative tests |
| 2062 | |
| 2063 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(exp_pkt=exp_pkt_arg, |
| 2064 | timeout=timeout) |
| 2065 | if rcv_port == ingress_port: |
| 2066 | logging.debug("Packet matched catch-all flow") |
| 2067 | rcv_pkt = None |
| 2068 | |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2069 | if expected_result == self.RESULT_MATCH: |
| 2070 | self.assertTrue(rcv_pkt is not None, |
| 2071 | "Did not receive packet, expected a match") |
| 2072 | logging.debug("Packet len " + str(len(rcv_pkt)) + " in on " + |
| 2073 | str(rcv_port)) |
| 2074 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 2075 | str_pkt = str(pkt) |
| 2076 | str_rcv_pkt = str(rcv_pkt) |
| 2077 | str_rcv_pkt = str_rcv_pkt[0:len(str_pkt)] |
| 2078 | if str_pkt != str_rcv_pkt: |
| 2079 | logging.error("Response packet does not match send packet") |
| 2080 | logging.info("Response:") |
| 2081 | logging.info(self.pktToStr(scapy.Ether(rcv_pkt))) |
| 2082 | self.assertEqual(str_pkt, str_rcv_pkt, |
| 2083 | 'Response packet does not match send packet') |
| 2084 | elif expected_result == self.RESULT_NOMATCH: |
| 2085 | self.assertTrue(rcv_pkt is None, "Received packet, expected drop") |
| 2086 | else: |
| 2087 | logging.debug("Match or drop accepted. Result = %s" % |
| 2088 | ("match" if rcv_pkt is not None else "drop")) |
| 2089 | |
| 2090 | |
| 2091 | class DirectBadIpTcpPacketsBase(DirectBadPacketBase): |
| 2092 | """ |
| 2093 | Base class for TCP and UDP parsing/matching verification under corruptions |
| 2094 | """ |
| 2095 | def runTest(self): |
| 2096 | pass |
| 2097 | |
| 2098 | def runTestWithProto(self, protoName = 'TCP'): |
| 2099 | dl_dst='00:01:02:03:04:05' |
| 2100 | dl_src='00:06:07:08:09:0a' |
| 2101 | ip_src='192.168.0.1' |
| 2102 | ip_dst='192.168.0.2' |
| 2103 | ip_tos=0 |
| 2104 | tcp_sport=1234 |
| 2105 | tcp_dport=80 |
| 2106 | |
| 2107 | # Generate a proper packet for constructing a match |
| 2108 | tp = None |
| 2109 | if protoName == 'TCP': |
| 2110 | tp = scapy.TCP |
| 2111 | proto = 6 |
| 2112 | elif protoName == 'UDP': |
| 2113 | tp = scapy.UDP |
| 2114 | proto = 17 |
| 2115 | else: |
| 2116 | raise Exception("Passed in unknown proto name") |
| 2117 | |
| 2118 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2119 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos)/ \ |
| 2120 | tp(sport=tcp_sport, dport=tcp_dport) |
| 2121 | match = packet_to_flow_match(self, match_pkt) |
| 2122 | self.assertTrue(match is not None, |
| 2123 | "Could not generate flow match from pkt") |
| 2124 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2125 | |
| 2126 | def testPacket(title, pkt, result): |
| 2127 | act = action.action_output() |
| 2128 | pkts = [ |
| 2129 | [title, pkt, result] |
| 2130 | ] |
| 2131 | self.testPktsAgainstFlow(pkts, act, match) |
| 2132 | |
| 2133 | # Try incomplete IP headers |
| 2134 | testPacket("Incomplete IP header (1 bytes)", |
| 2135 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2136 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:1], |
| 2137 | self.RESULT_NOMATCH, |
| 2138 | ) |
| 2139 | testPacket("Incomplete IP header (2 bytes)", |
| 2140 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2141 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:2], |
| 2142 | self.RESULT_NOMATCH, |
| 2143 | ) |
| 2144 | testPacket("Incomplete IP header (3 bytes)", |
| 2145 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2146 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:3], |
| 2147 | self.RESULT_NOMATCH, |
| 2148 | ) |
| 2149 | testPacket("Incomplete IP header (12 bytes)", |
| 2150 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2151 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:12], |
| 2152 | self.RESULT_NOMATCH, |
| 2153 | ) |
| 2154 | testPacket("Incomplete IP header (16 bytes)", |
| 2155 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2156 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:16], |
| 2157 | self.RESULT_NOMATCH, |
| 2158 | ) |
| 2159 | testPacket("Incomplete IP header (19 bytes)", |
| 2160 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2161 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:19], |
| 2162 | self.RESULT_NOMATCH, |
| 2163 | ) |
| 2164 | |
| 2165 | # Try variations where the TCP header is missing or incomplete. As we |
| 2166 | # saw bugs before where buffers were reused and lengths weren't honored, |
| 2167 | # we initiatlize once with a non-matching full packet and once with a |
| 2168 | # matching full packet. |
| 2169 | testPacket("Non-Matching TCP packet, warming buffer", |
| 2170 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2171 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto)/ \ |
| 2172 | tp(sport=tcp_sport, dport=tcp_dport + 1), |
| 2173 | self.RESULT_NOMATCH, |
| 2174 | ) |
| 2175 | testPacket("Missing TCP header, buffer warmed with non-match", |
| 2176 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2177 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto), |
| 2178 | self.RESULT_NOMATCH, |
| 2179 | ) |
| 2180 | testPacket("Matching TCP packet, warming buffer", |
| 2181 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2182 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto)/ \ |
| 2183 | tp(sport=tcp_sport, dport=tcp_dport), |
| 2184 | self.RESULT_MATCH, |
| 2185 | ) |
| 2186 | testPacket("Missing TCP header, buffer warmed with match", |
| 2187 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2188 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto), |
| 2189 | self.RESULT_NOMATCH, |
| 2190 | ) |
| 2191 | testPacket("Truncated TCP header: 2 bytes", |
| 2192 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2193 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto)/ \ |
| 2194 | (str(tp(sport=tcp_sport, dport=tcp_dport))[0:2]), |
| 2195 | self.RESULT_NOMATCH, |
| 2196 | ) |
| 2197 | |
| 2198 | # Play with IP header length values that put the start of TCP either |
| 2199 | # inside the generated TCP header or beyond. In some cases it may even |
| 2200 | # be beyond the packet boundary. Also play with IP options and more |
| 2201 | # importantly IP total length corruptions. |
| 2202 | testPacket("TCP packet, corrupt ihl (0x6)", |
| 2203 | simple_tcp_packet(ip_ihl=6), |
| 2204 | self.RESULT_NOMATCH, |
| 2205 | ) |
| 2206 | testPacket("TCP packet, corrupt ihl (0xf)", |
| 2207 | simple_tcp_packet(ip_ihl=0xf), # ihl = 15 * 4 = 60 |
| 2208 | self.RESULT_NOMATCH, |
| 2209 | ) |
| 2210 | testPacket("TCP packet, corrupt ihl and total length", |
| 2211 | simple_tcp_packet(ip_ihl=0xf, pktlen=56), # ihl = 15 * 4 = 60, |
| 2212 | self.RESULT_NOMATCH, |
| 2213 | ) |
| 2214 | testPacket("Corrupt IPoption: First 4 bytes of matching TCP header", |
| 2215 | simple_tcp_packet( |
| 2216 | ip_options=scapy.IPOption('\x04\xd2\x00\x50'), |
| 2217 | tcp_dport=2, tcp_sport=2 |
| 2218 | ), |
| 2219 | self.RESULT_NOMATCH, |
| 2220 | ) |
| 2221 | testPacket("Missing TCP header, corrupt ihl", |
| 2222 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2223 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ihl=0xf, proto=proto), |
| 2224 | self.RESULT_NOMATCH, |
| 2225 | ) |
| 2226 | testPacket("Missing TCP header, corrupt total length", |
| 2227 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2228 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto, len= 100), |
| 2229 | self.RESULT_NOMATCH, |
| 2230 | ) |
| 2231 | testPacket("Missing TCP header, corrupt ihl and total length", |
| 2232 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2233 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ihl=0xf, proto=proto, len=43), |
| 2234 | self.RESULT_NOMATCH, |
| 2235 | ) |
| 2236 | testPacket("Incomplete IP header (12 bytes), corrupt ihl and total length", |
| 2237 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2238 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto, ihl=10, len=43))[0:12], |
| 2239 | self.RESULT_NOMATCH, |
| 2240 | ) |
| 2241 | testPacket("Incomplete IP header (16 bytes), corrupt ihl and total length", |
| 2242 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2243 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto, ihl=10, len=43))[0:16], |
| 2244 | self.RESULT_NOMATCH, |
| 2245 | ) |
| 2246 | |
| 2247 | # Try an incomplete TCP header that has enough bytes to carry source and |
| 2248 | # destination ports. As that is all we care about during matching, some |
| 2249 | # implementations may match and some may drop the packet |
| 2250 | testPacket("Incomplete TCP header: src/dst port present", |
| 2251 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2252 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto)/ \ |
| 2253 | (str(tp(sport=tcp_sport, dport=tcp_dport))[0:4]), |
| 2254 | self.RESULT_ANY, |
| 2255 | ) |
| 2256 | |
| 2257 | for i in range(1): |
| 2258 | for length in range(40 / 4): # IPv4 options are a maximum of 40 in length |
| 2259 | bytes = "".join([("%c" % random.randint(0, 255)) for x in range(length * 4)]) |
| 2260 | eth = scapy.Ether(dst=dl_dst, src=dl_src) |
| 2261 | ip = scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ihl=5 + length, proto=proto) |
| 2262 | tcp = tp(sport=tcp_sport, dport=tcp_dport+1) |
| 2263 | pkt = eth / ip |
| 2264 | pkt = pkt / bytes |
| 2265 | pkt = pkt / str(tcp) |
| 2266 | testPacket("Random IP options len = %d - TP match must fail" % length * 4, |
| 2267 | pkt, |
| 2268 | self.RESULT_NOMATCH |
| 2269 | ) |
| 2270 | |
| 2271 | eth = scapy.Ether(dst=dl_dst, src=dl_src) |
| 2272 | ip = scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ihl=5 + length, proto=proto) |
| 2273 | tcp = tp(sport=tcp_sport, dport=tcp_dport) |
| 2274 | pkt = eth / ip |
| 2275 | pkt = pkt / bytes |
| 2276 | pkt = pkt / str(tcp) |
| 2277 | |
| 2278 | testPacket("Random IP options len = %d - May match", |
| 2279 | pkt, |
| 2280 | self.RESULT_ANY |
| 2281 | ) |
| 2282 | |
| 2283 | |
| 2284 | class DirectBadIpTcpPackets(DirectBadIpTcpPacketsBase): |
| 2285 | """ |
| 2286 | Verify IP/TCP parsing and matching. Focus on packet corruptions |
| 2287 | """ |
| 2288 | def runTest(self): |
| 2289 | self.runTestWithProto(protoName = 'TCP') |
| 2290 | |
| 2291 | class DirectBadIpUdpPackets(DirectBadIpTcpPacketsBase): |
| 2292 | """ |
| 2293 | Verify IP/UDP parsing and matching. Focus on packet corruptions |
| 2294 | """ |
| 2295 | def runTest(self): |
| 2296 | self.runTestWithProto(protoName = 'UDP') |
| 2297 | |
| 2298 | class DirectBadLlcPackets(DirectBadPacketBase): |
| 2299 | """ |
| 2300 | Verify LLC/SNAP parsing and matching. Focus on packet corruptions |
| 2301 | """ |
| 2302 | def runTest(self): |
| 2303 | dl_dst='00:01:02:03:04:05' |
| 2304 | dl_src='00:06:07:08:09:0a' |
| 2305 | ip_src='192.168.0.1' |
| 2306 | ip_dst='192.168.0.2' |
| 2307 | ip_tos=0 |
| 2308 | tcp_sport=1234 |
| 2309 | tcp_dport=80 |
| 2310 | |
| 2311 | IS_SNAP_IP = 1 |
| 2312 | IS_SNAP_IP_CORRUPT = 2 |
| 2313 | IS_NOT_SNAP_IP = 3 |
| 2314 | |
| 2315 | def testPacketTcpMatch(title, llc): |
| 2316 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2317 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos)/ \ |
| 2318 | scapy.TCP(sport=tcp_sport, dport=tcp_dport) |
| 2319 | match = packet_to_flow_match(self, match_pkt) |
| 2320 | self.assertTrue(match is not None, |
| 2321 | "Could not generate flow match from pkt") |
| 2322 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2323 | act = action.action_output() |
| 2324 | |
| 2325 | self.testPktsAgainstFlow( |
| 2326 | [[ |
| 2327 | "TCP match - LLC frame correct length - %s" % title, |
| 2328 | scapy.Ether(dst=dl_dst, src=dl_src, type=len(llc)) / llc, |
| 2329 | self.RESULT_ANY, |
| 2330 | ]], |
| 2331 | act, match |
| 2332 | ) |
| 2333 | |
| 2334 | # Corrupt length field |
| 2335 | ethLen = random.randint(0, 1535) |
| 2336 | self.testPktsAgainstFlow( |
| 2337 | [[ |
| 2338 | "TCP match - LLC frame corrupted length - %s" % title, |
| 2339 | scapy.Ether(dst=dl_dst, src=dl_src, type=ethLen) / llc, |
| 2340 | self.RESULT_ANY, |
| 2341 | ]], |
| 2342 | act, match |
| 2343 | ) |
| 2344 | |
| 2345 | def testPacketEthSrcDstMatch(title, llc): |
| 2346 | # Matching based on Ethernet source and destination |
| 2347 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src) |
| 2348 | match = packet_to_flow_match(self, match_pkt) |
| 2349 | self.assertTrue(match is not None, |
| 2350 | "Could not generate flow match from pkt") |
| 2351 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2352 | match.wildcards |= ofp.OFPFW_DL_TYPE |
| 2353 | self.testPktsAgainstFlow( |
| 2354 | [[ |
| 2355 | "Eth addr match - LLC frame correct length- %s" % title, |
| 2356 | scapy.Ether(dst=dl_dst, src=dl_src, type=len(llc)) / llc, |
| 2357 | self.RESULT_MATCH, |
| 2358 | ]], |
| 2359 | action.action_output(), match |
| 2360 | ) |
| 2361 | |
| 2362 | # Corrupt length field |
| 2363 | ethLen = random.randint(0, 1535) |
| 2364 | self.testPktsAgainstFlow( |
| 2365 | [[ |
| 2366 | "Eth addr match - LLC frame corrupted length- %s" % title, |
| 2367 | scapy.Ether(dst=dl_dst, src=dl_src, type=ethLen) / llc, |
| 2368 | self.RESULT_ANY, |
| 2369 | ]], |
| 2370 | action.action_output(), match |
| 2371 | ) |
| 2372 | |
| 2373 | def testPacketEthSrcDstTypeMatch(title, llc, is_snap_ip): |
| 2374 | # Matching based on Ethernet source, destination and type |
| 2375 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src, type=0x800) |
| 2376 | match = packet_to_flow_match(self, match_pkt) |
| 2377 | self.assertTrue(match is not None, |
| 2378 | "Could not generate flow match from pkt") |
| 2379 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2380 | if is_snap_ip == IS_SNAP_IP: |
| 2381 | is_match = self.RESULT_MATCH |
| 2382 | elif is_snap_ip == IS_SNAP_IP_CORRUPT: |
| 2383 | is_match = self.RESULT_ANY |
| 2384 | else: |
| 2385 | is_match = self.RESULT_NOMATCH |
| 2386 | self.testPktsAgainstFlow( |
| 2387 | [[ |
| 2388 | "Eth addr+type match - LLC frame correct length - %s" % title, |
| 2389 | scapy.Ether(dst=dl_dst, src=dl_src, type=len(llc)) / llc, |
| 2390 | is_match, |
| 2391 | ]], |
| 2392 | action.action_output(), match |
| 2393 | ) |
| 2394 | |
| 2395 | # Corrupt length field |
| 2396 | ethLen = random.randint(0, 1535) |
| 2397 | self.testPktsAgainstFlow( |
| 2398 | [[ |
| 2399 | "Eth addr+type match - LLC frame corrupted length - %s" % title, |
| 2400 | scapy.Ether(dst=dl_dst, src=dl_src, type=ethLen) / llc, |
Christian Dickmann | e9b6d25 | 2012-10-08 22:56:50 -0700 | [diff] [blame] | 2401 | self.RESULT_ANY, |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2402 | ]], |
| 2403 | action.action_output(), match |
| 2404 | ) |
| 2405 | |
| 2406 | def testPacket(title, llc, is_snap_ip): |
| 2407 | testPacketTcpMatch(title, llc) |
| 2408 | testPacketEthSrcDstMatch(title, llc) |
| 2409 | testPacketEthSrcDstTypeMatch(title, llc, is_snap_ip) |
| 2410 | |
| 2411 | testPacket("LLC - No SNAP - No Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2412 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2413 | IS_NOT_SNAP_IP, |
| 2414 | ) |
| 2415 | testPacket("LLC - No SNAP - Small Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2416 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * 10), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2417 | IS_NOT_SNAP_IP, |
| 2418 | ) |
| 2419 | testPacket("LLC - No SNAP - Max -1 Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2420 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * (1500 - 3 - 1)), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2421 | IS_NOT_SNAP_IP, |
| 2422 | ) |
| 2423 | testPacket("LLC - No SNAP - Max Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2424 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * (1500 - 3)), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2425 | IS_NOT_SNAP_IP, |
| 2426 | ) |
| 2427 | testPacket("LLC - SNAP - Small bogus payload", |
| 2428 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2429 | scapy.SNAP(OUI=0x000000, code=0x800) / ("S" * 10), |
| 2430 | IS_SNAP_IP_CORRUPT, |
| 2431 | ) |
| 2432 | testPacket("LLC - SNAP - Max -1 bogus payload", |
| 2433 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2434 | scapy.SNAP(OUI=0x000000, code=0x3) / ("S" * (1500 - 3 - 5 - 1)), |
| 2435 | IS_NOT_SNAP_IP, |
| 2436 | ) |
| 2437 | testPacket("LLC - SNAP - Max bogus payload", |
| 2438 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2439 | scapy.SNAP(OUI=0x000000, code=0x3) / ("S" * (1500 - 3 - 5)), |
| 2440 | IS_NOT_SNAP_IP, |
| 2441 | ) |
| 2442 | testPacket("LLC - SNAP - IP - TCP", |
| 2443 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2444 | scapy.SNAP(OUI=0x000000, code=0x800)/ \ |
| 2445 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=6)/ \ |
| 2446 | scapy.TCP(sport=tcp_sport, dport=tcp_dport), |
| 2447 | IS_SNAP_IP, |
| 2448 | ) |
| 2449 | |
| 2450 | |
| 2451 | class DirectLlcPackets(DirectBadPacketBase): |
| 2452 | """ |
| 2453 | Verify LLC/SNAP parsing (valid and corrupted packets) and matching |
| 2454 | """ |
| 2455 | def runTest(self): |
| 2456 | dl_dst='00:01:02:03:04:05' |
| 2457 | dl_src='00:06:07:08:09:0a' |
| 2458 | ip_src='192.168.0.1' |
| 2459 | ip_dst='192.168.0.2' |
| 2460 | ip_tos=0 |
| 2461 | tcp_sport=1234 |
| 2462 | tcp_dport=80 |
| 2463 | |
| 2464 | # Test ethertype in face of LLC/SNAP and OFP_DL_TYPE_NOT_ETH_TYPE |
| 2465 | IS_SNAP_NOT_IP = 1 |
| 2466 | IS_SNAP_AND_IP = 2 |
| 2467 | IS_NOT_SNAP = 3 |
| 2468 | |
| 2469 | def testPacketEthTypeIP(title, llc, is_snap): |
| 2470 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src, type=0x800) |
| 2471 | match = packet_to_flow_match(self, match_pkt) |
| 2472 | self.assertTrue(match is not None, |
| 2473 | "Could not generate flow match from pkt") |
| 2474 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2475 | pkts = [] |
| 2476 | if is_snap == IS_NOT_SNAP or is_snap == IS_SNAP_NOT_IP: |
| 2477 | result = self.RESULT_NOMATCH |
| 2478 | else: |
| 2479 | result = self.RESULT_MATCH |
| 2480 | pkts.append([ |
| 2481 | "Ether type 0x800 match - %s" % title, |
| 2482 | scapy.Ether(dst=dl_dst, src=dl_src, type=len(llc)) / llc, |
| 2483 | result, |
| 2484 | ]) |
| 2485 | act = action.action_output() |
| 2486 | self.testPktsAgainstFlow(pkts, act, match) |
| 2487 | |
| 2488 | def testPacketEthTypeNotEth(title, llc, is_snap): |
| 2489 | match_pkt = scapy.Ether(dst = dl_dst, src = dl_src, |
| 2490 | type = ofp.OFP_DL_TYPE_NOT_ETH_TYPE) |
| 2491 | match = packet_to_flow_match(self, match_pkt) |
| 2492 | self.assertTrue(match is not None, |
| 2493 | "Could not generate flow match from pkt") |
| 2494 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2495 | pkts = [] |
| 2496 | if is_snap == IS_NOT_SNAP: |
| 2497 | result = self.RESULT_MATCH |
| 2498 | else: |
| 2499 | result = self.RESULT_NOMATCH |
| 2500 | pkts.append([ |
| 2501 | "Ether type OFP_DL_TYPE_NOT_ETH_TYPE match - %s" % title, |
| 2502 | scapy.Ether(dst=dl_dst, src=dl_src, type=len(llc)) / llc, |
| 2503 | result, |
| 2504 | ]) |
| 2505 | act = action.action_output() |
| 2506 | self.testPktsAgainstFlow(pkts, act, match) |
| 2507 | |
| 2508 | def testPacket(title, llc, is_snap): |
| 2509 | testPacketEthTypeIP(title, llc, is_snap) |
| 2510 | testPacketEthTypeNotEth(title, llc, is_snap) |
| 2511 | |
| 2512 | testPacket("LLC - No SNAP - No Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2513 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03), |
| 2514 | IS_NOT_SNAP, |
| 2515 | ) |
| 2516 | testPacket("LLC (with information field) - No SNAP - No Payload", |
| 2517 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x12) / "S", |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2518 | IS_NOT_SNAP, |
| 2519 | ) |
| 2520 | testPacket("LLC - No SNAP - Small Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2521 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * 10), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2522 | IS_NOT_SNAP, |
| 2523 | ) |
| 2524 | testPacket("LLC - No SNAP - Max -1 Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2525 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * (1500 - 3 - 1)), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2526 | IS_NOT_SNAP, |
| 2527 | ) |
| 2528 | testPacket("LLC - No SNAP - Max Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2529 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * (1500 - 3)), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2530 | IS_NOT_SNAP, |
| 2531 | ) |
| 2532 | testPacket("LLC - SNAP - Non-default OUI", |
| 2533 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2534 | scapy.SNAP(OUI=0x000001, code=0x800) / ("S" * 10), |
| 2535 | IS_NOT_SNAP, |
| 2536 | ) |
| 2537 | testPacket("LLC - SNAP - Default OUI", |
| 2538 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2539 | scapy.SNAP(OUI=0x000000, code=0x800) / ("S" * 10), |
| 2540 | IS_SNAP_AND_IP, |
| 2541 | ) |
| 2542 | testPacket("LLC - SNAP - Max -1 bogus payload", |
| 2543 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2544 | scapy.SNAP(OUI=0x000000, code=0x3) / ("S" * (1500 - 3 - 5 - 1)), |
| 2545 | IS_SNAP_NOT_IP, |
| 2546 | ) |
| 2547 | testPacket("LLC - SNAP - Max bogus payload", |
| 2548 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2549 | scapy.SNAP(OUI=0x000000, code=0x3) / ("S" * (1500 - 3 - 5)), |
| 2550 | IS_SNAP_NOT_IP, |
| 2551 | ) |
| 2552 | testPacket("LLC - SNAP - IP - TCP", |
| 2553 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2554 | scapy.SNAP(OUI=0x000000, code=0x800)/ \ |
| 2555 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=6)/ \ |
| 2556 | scapy.TCP(sport=tcp_sport, dport=tcp_dport), |
| 2557 | IS_SNAP_AND_IP, |
| 2558 | ) |
| 2559 | |
| 2560 | |
| 2561 | class DirectArpPackets(DirectBadPacketBase): |
| 2562 | """ |
| 2563 | Verify ARP parsing (valid and corrupted packets) and ARP matching |
| 2564 | """ |
| 2565 | def runTest(self): |
| 2566 | self.testArpHandling() |
| 2567 | |
| 2568 | def testArpHandling(self): |
| 2569 | dl_dst='00:01:02:03:04:05' |
| 2570 | dl_src='00:06:07:08:09:0a' |
| 2571 | ip_src='192.168.0.1' |
| 2572 | ip_dst='192.168.0.2' |
| 2573 | ip_src2='192.168.1.1' |
| 2574 | ip_dst2='192.168.1.2' |
| 2575 | ip_tos=0 |
| 2576 | tcp_sport=1234 |
| 2577 | tcp_dport=80 |
| 2578 | |
| 2579 | def testPacket(title, arp_match, arp_pkt, result): |
| 2580 | pkts = [] |
| 2581 | |
| 2582 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src) / arp_match |
| 2583 | match = packet_to_flow_match(self, match_pkt) |
| 2584 | self.assertTrue(match is not None, |
| 2585 | "Could not generate flow match from pkt") |
| 2586 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2587 | |
| 2588 | pkts.append([ |
| 2589 | title, |
| 2590 | scapy.Ether(dst=dl_dst, src=dl_src) / arp_pkt, |
| 2591 | result, |
| 2592 | ]) |
| 2593 | |
| 2594 | act = action.action_output() |
| 2595 | self.testPktsAgainstFlow(pkts, act, match) |
| 2596 | |
| 2597 | testPacket("Basic ARP", |
| 2598 | scapy.ARP(psrc=ip_src, pdst=ip_dst, op = 1), |
| 2599 | scapy.ARP(hwdst = '00:00:00:00:00:00', hwsrc = dl_src, |
| 2600 | psrc = ip_src, pdst = ip_dst, hwlen = 6, plen = 4, |
| 2601 | ptype = 0x800, hwtype = 1, op = 1), |
| 2602 | self.RESULT_MATCH |
| 2603 | ) |
| 2604 | # More stuff: |
| 2605 | # - Non matches on any property |
| 2606 | # - Corrupted hwlen and plen |
| 2607 | # - Other hwtype, ptype |
| 2608 | # - Truncated ARP pkt |
| 2609 | |
| 2610 | |
| 2611 | class DirectVlanPackets(DirectBadPacketBase): |
| 2612 | """ |
| 2613 | Verify VLAN parsing (valid and corrupted packets) and ARP matching |
| 2614 | """ |
| 2615 | def runTest(self): |
| 2616 | dl_dst='00:01:02:03:04:05' |
| 2617 | dl_src='00:06:07:08:09:0a' |
| 2618 | ip_src='192.168.0.1' |
| 2619 | ip_dst='192.168.0.2' |
| 2620 | ip_src2='192.168.1.1' |
| 2621 | ip_dst2='192.168.1.2' |
| 2622 | ip_tos=0 |
| 2623 | tcp_sport=1234 |
| 2624 | tcp_dport=80 |
| 2625 | |
| 2626 | def testPacket(title, match, pkt, result): |
| 2627 | pkts = [] |
| 2628 | |
| 2629 | self.assertTrue(match is not None, |
| 2630 | "Could not generate flow match from pkt") |
| 2631 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2632 | |
| 2633 | pkts.append([ |
| 2634 | "%s" % title, |
| 2635 | pkt, |
| 2636 | result, |
| 2637 | ]) |
| 2638 | |
| 2639 | act = action.action_output() |
| 2640 | self.testPktsAgainstFlow(pkts, act, match) |
| 2641 | |
| 2642 | testPacket("Basic MAC matching - IPv4 payload", |
| 2643 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src)), |
| 2644 | scapy.Ether(dst=dl_dst, src=dl_src, type=0x800) / scapy.IP(), |
| 2645 | self.RESULT_MATCH |
| 2646 | ) |
| 2647 | testPacket("Basic MAC matching - VMware beacon - no payload", |
| 2648 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src)), |
| 2649 | scapy.Ether(dst=dl_dst, src=dl_src, type=0x8922), |
| 2650 | self.RESULT_MATCH |
| 2651 | ) |
| 2652 | testPacket("Basic MAC matching - VMware beacon - with payload", |
| 2653 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src)), |
| 2654 | scapy.Ether(dst=dl_dst, src=dl_src, type=0x8922)/ ("X" * 1), |
| 2655 | self.RESULT_MATCH |
| 2656 | ) |
| 2657 | testPacket("Basic MAC matching - IPv6 payload", |
| 2658 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src)), |
| 2659 | scapy.Ether(dst=dl_dst, src=dl_src) / scapy.IPv6(), |
| 2660 | self.RESULT_MATCH |
| 2661 | ) |
| 2662 | testPacket("Basic MAC matching with VLAN tag present", |
| 2663 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src)), |
| 2664 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2665 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2666 | scapy.IP(), |
| 2667 | self.RESULT_MATCH |
| 2668 | ) |
| 2669 | testPacket("Basic MAC matching with VLAN tag present", |
| 2670 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2671 | dl_type=0x800), |
| 2672 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2673 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2674 | scapy.IP(), |
| 2675 | self.RESULT_MATCH |
| 2676 | ) |
| 2677 | testPacket("Ether matching with VLAN tag present - No type match", |
| 2678 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2679 | dl_type=0x801), |
| 2680 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2681 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2682 | scapy.IP(), |
| 2683 | self.RESULT_NOMATCH |
| 2684 | ) |
| 2685 | testPacket("Ether matching with VLAN tag present - No type match 0x8100", |
| 2686 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2687 | dl_type=0x8100), |
| 2688 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2689 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2690 | scapy.IP(), |
| 2691 | self.RESULT_NOMATCH |
| 2692 | ) |
| 2693 | testPacket("Ether matching with double VLAN tag - Wrong type match", |
| 2694 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2695 | dl_type=0x800), |
| 2696 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2697 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
| 2698 | scapy.Dot1Q(prio=3, vlan=1005)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2699 | scapy.IP(), |
| 2700 | self.RESULT_NOMATCH |
| 2701 | ) |
| 2702 | testPacket("Ether matching with double VLAN tag - Type match", |
| 2703 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2704 | dl_type=0x8100), |
| 2705 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2706 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
| 2707 | scapy.Dot1Q(prio=3, vlan=1005)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2708 | scapy.IP(), |
| 2709 | self.RESULT_MATCH |
| 2710 | ) |
| 2711 | testPacket("IP matching - VLAN tag", |
| 2712 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2713 | dl_type=0x0800, |
| 2714 | nw_src=parse_ip(ip_src), nw_dst=parse_ip(ip_dst)), |
| 2715 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2716 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2717 | scapy.IP(src=ip_src, dst=ip_dst), |
| 2718 | self.RESULT_MATCH |
| 2719 | ) |
| 2720 | # XXX: |
| 2721 | # - Matching on VLAN ID and Prio |
| 2722 | # - Actions |
| 2723 | |
| 2724 | |
| 2725 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 2726 | if __name__ == "__main__": |
| 2727 | print "Please run through oft script: ./oft --test_spec=basic" |