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 | |
Rich Lane | 4b9e38c | 2012-12-06 16:33:20 -0800 | [diff] [blame] | 873 | # Clear OFPPC_NO_FLOOD on each port |
| 874 | for of_port in of_ports: |
| 875 | rv = port_config_set(self.controller, of_port, |
| 876 | 0, ofp.OFPPC_NO_FLOOD) |
| 877 | self.assertEqual(rv, 0, "Failed to set port config") |
| 878 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 879 | for idx in range(len(of_ports)): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 880 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 881 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 882 | |
| 883 | ingress_port = of_ports[idx] |
| 884 | no_flood_idx = (idx + 1) % len(of_ports) |
| 885 | no_flood_port = of_ports[no_flood_idx] |
| 886 | rv = port_config_set(self.controller, no_flood_port, |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 887 | ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 888 | self.assertEqual(rv, 0, "Failed to set port config") |
| 889 | |
| 890 | match.in_port = ingress_port |
| 891 | |
| 892 | request = message.flow_mod() |
| 893 | request.match = match |
| 894 | request.buffer_id = 0xffffffff |
| 895 | act.port = ofp.OFPP_FLOOD |
| 896 | self.assertTrue(request.actions.add(act), |
| 897 | "Could not add flood port action") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 898 | logging.info(request.show()) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 899 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 900 | logging.info("Inserting flow") |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 901 | rv = self.controller.message_send(request) |
| 902 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 903 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 904 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 905 | logging.info("Sending packet to dp port " + str(ingress_port)) |
| 906 | logging.info("No flood port is " + str(no_flood_port)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 907 | self.dataplane.send(ingress_port, str(pkt)) |
| 908 | no_ports = set([ingress_port, no_flood_port]) |
| 909 | yes_ports = set(of_ports).difference(no_ports) |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 910 | receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, self) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 911 | |
| 912 | # Turn no flood off again |
| 913 | rv = port_config_set(self.controller, no_flood_port, |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 914 | 0, ofp.OFPPC_NO_FLOOD) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 915 | self.assertEqual(rv, 0, "Failed to reset port config") |
Rich Lane | 4ecc1f4 | 2012-12-06 16:35:24 -0800 | [diff] [blame] | 916 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 917 | |
| 918 | # Check that packets are now flooded to no_flood_port |
| 919 | logging.info("Sending packet to dp port " + str(ingress_port)) |
| 920 | self.dataplane.send(ingress_port, str(pkt)) |
| 921 | no_ports = set([ingress_port]) |
| 922 | yes_ports = set(of_ports).difference(no_ports) |
| 923 | receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, self) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 924 | |
| 925 | #@todo Should check no other packets received |
| 926 | |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 927 | |
| 928 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 929 | ################################################################ |
| 930 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 931 | class BaseMatchCase(base_tests.SimpleDataPlane): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 932 | def setUp(self): |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 933 | base_tests.SimpleDataPlane.setUp(self) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 934 | def runTest(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 935 | logging.info("BaseMatchCase") |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 936 | |
| 937 | class ExactMatch(BaseMatchCase): |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 938 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 939 | Exercise exact matching for all port pairs |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 940 | |
| 941 | Generate a packet |
| 942 | Generate and install a matching flow without wildcard mask |
| 943 | Add action to forward to a port |
| 944 | Send the packet to the port |
| 945 | 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] | 946 | """ |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 947 | |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 948 | def runTest(self): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 949 | flow_match_test(self, config["port_map"]) |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 950 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 951 | class ExactMatchTagged(BaseMatchCase): |
| 952 | """ |
| 953 | Exact match for all port pairs with tagged pkts |
| 954 | """ |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 955 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 956 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 957 | vid = test_param_get('vid', default=TEST_VID_DEFAULT) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 958 | flow_match_test(self, config["port_map"], dl_vlan=vid) |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 959 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 960 | class ExactMatchTaggedMany(BaseMatchCase): |
| 961 | """ |
| 962 | ExactMatchTagged with many VLANS |
| 963 | """ |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 964 | |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 965 | priority = -1 |
| 966 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 967 | def runTest(self): |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 968 | for vid in range(2,100,10): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 969 | 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] | 970 | for vid in range(100,4000,389): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 971 | flow_match_test(self, config["port_map"], dl_vlan=vid, max_test=5) |
| 972 | 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] | 973 | |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 974 | class SingleWildcardMatchPriority(BaseMatchCase): |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 975 | """ |
| 976 | SingleWildcardMatchPriority |
| 977 | """ |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 978 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 979 | def _Init(self): |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 980 | self.pkt = simple_tcp_packet() |
| 981 | self.flowMsgs = {} |
| 982 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 983 | def _ClearTable(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 984 | rc = delete_all_flows(self.controller) |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 985 | self.assertEqual(rc, 0, "Failed to delete all flows") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 986 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 987 | |
| 988 | def runTest(self): |
| 989 | |
| 990 | self._Init() |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 991 | of_ports = config["port_map"].keys() |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 992 | of_ports.sort() |
| 993 | |
| 994 | # Delete the initial flow table |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 995 | self._ClearTable() |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 996 | |
| 997 | # Run several combinations, each at lower priority settings. |
| 998 | # At the end of each call to runPrioFlows(), the table should |
| 999 | # be empty. If its not, we'll catch it as the priorities decreases |
| 1000 | portA = of_ports[0] |
| 1001 | portB = of_ports[1] |
| 1002 | portC = of_ports[2] |
| 1003 | |
| 1004 | # TODO -- these priority numbers should be validated somehow? |
| 1005 | self.runPrioFlows(portA, portB, portC, 1000, 999) |
| 1006 | self.runPrioFlows(portB, portC, portA, 998, 997) |
| 1007 | self.runPrioFlows(portC, portA, portB, 996, 995) |
| 1008 | self.runPrioFlows(portA, portC, portB, 994, 993) |
| 1009 | |
| 1010 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1011 | |
| 1012 | def runPrioFlows(self, portA, portB, portC, prioHigher, prioLower, |
| 1013 | clearTable=False): |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1014 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1015 | if clearTable: |
| 1016 | self._ClearTable() |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1017 | |
| 1018 | # Sanity check flow at lower priority from pA to pB |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1019 | 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] | 1020 | % (portA, portB, portC, prioHigher, prioLower)) |
| 1021 | |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1022 | # Sanity check flow at lower priority from pA to pC |
| 1023 | self.installFlow(prioLower, portA, portC) |
| 1024 | self.verifyFlow(portA, portC) |
| 1025 | self.removeFlow(prioLower) |
| 1026 | |
| 1027 | # Install and verify pA->pB @ prioLower |
| 1028 | self.installFlow(prioLower, portA, portB) |
| 1029 | self.verifyFlow(portA, portB) |
| 1030 | |
| 1031 | # Install and verify pA->pC @ prioHigher, should override pA->pB |
| 1032 | self.installFlow(prioHigher, portA, portC) |
| 1033 | self.verifyFlow(portA, portC) |
| 1034 | # remove pA->pC |
| 1035 | self.removeFlow(prioHigher) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1036 | # Old flow pA -> pB @ prioLower should still be active |
| 1037 | self.verifyFlow(portA, portB) |
| 1038 | self.removeFlow(prioLower) |
| 1039 | |
| 1040 | # Table should be empty at this point, leave it alone as |
| 1041 | # an assumption for future test runs |
| 1042 | |
| 1043 | |
| 1044 | |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1045 | def installFlow(self, prio, inp, egp, |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1046 | wildcards=ofp.OFPFW_DL_SRC): |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1047 | wildcards |= required_wildcards(self) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1048 | request = flow_msg_create(self, self.pkt, ing_port=inp, |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1049 | wildcards=wildcards, |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1050 | egr_ports=egp) |
| 1051 | request.priority = prio |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1052 | logging.debug("Install flow with priority " + str(prio)) |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1053 | flow_msg_install(self, request, clear_table_override=False) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1054 | self.flowMsgs[prio] = request |
| 1055 | |
| 1056 | def removeFlow(self, prio): |
| 1057 | if self.flowMsgs.has_key(prio): |
| 1058 | msg = self.flowMsgs[prio] |
| 1059 | msg.command = ofp.OFPFC_DELETE_STRICT |
| 1060 | # This *must* be set for DELETE |
| 1061 | msg.out_port = ofp.OFPP_NONE |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1062 | logging.debug("Remove flow with priority " + str(prio)) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1063 | self.controller.message_send(msg) |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 1064 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1065 | else: |
| 1066 | raise Exception("Not initialized") |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1067 | |
| 1068 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1069 | def verifyFlow(self, inp, egp, pkt=None): |
| 1070 | if pkt == None: |
| 1071 | pkt = self.pkt |
| 1072 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1073 | logging.info("Pkt match test: " + str(inp) + " to " + str(egp)) |
| 1074 | logging.debug("Send packet: " + str(inp) + " to " + str(egp)) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1075 | self.dataplane.send(inp, str(pkt)) |
| 1076 | receive_pkt_verify(self, egp, pkt, inp) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1077 | |
| 1078 | |
| 1079 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1080 | class SingleWildcardMatchPriorityInsertModifyDelete(SingleWildcardMatchPriority): |
| 1081 | |
| 1082 | def runTest(self): |
| 1083 | |
| 1084 | self._Init() |
| 1085 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1086 | of_ports = config["port_map"].keys() |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1087 | of_ports.sort() |
| 1088 | |
| 1089 | # Install an entry from 0 -> 1 @ prio 1000 |
| 1090 | self._ClearTable() |
| 1091 | self.installFlow(1000, of_ports[0], of_ports[1]) |
| 1092 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1093 | self.installFlow(1000, of_ports[1], of_ports[0]) |
| 1094 | self.verifyFlow(of_ports[1], of_ports[0]) |
| 1095 | self.installFlow(1001, of_ports[0], of_ports[1]) |
| 1096 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1097 | self.installFlow(1001, of_ports[1], of_ports[0]) |
| 1098 | self.verifyFlow(of_ports[1], of_ports[0]) |
| 1099 | self.removeFlow(1001) |
| 1100 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1101 | self.removeFlow(1000) |
| 1102 | |
| 1103 | |
| 1104 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1105 | class WildcardPriority(SingleWildcardMatchPriority): |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1106 | """ |
| 1107 | 1. Add wildcard flow, verify packet received. |
| 1108 | 2. Add exact match flow with higher priority, verify packet received |
| 1109 | on port specified by this flow. |
| 1110 | 3. Add wildcard flow with even higher priority, verify packet received |
| 1111 | on port specified by this flow. |
Rich Lane | b839208 | 2012-11-21 15:52:54 -0800 | [diff] [blame] | 1112 | 4. Add wildcard flow with lower priority, verify packet received |
| 1113 | on port specified by the highest priority flow. |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1114 | """ |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1115 | |
| 1116 | def runTest(self): |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1117 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1118 | self._Init() |
| 1119 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1120 | of_ports = config["port_map"].keys() |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1121 | of_ports.sort() |
| 1122 | |
| 1123 | self._ClearTable() |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1124 | |
| 1125 | # Install a flow with wildcards |
| 1126 | self.installFlow(999, of_ports[0], of_ports[1], |
| 1127 | wildcards=ofp.OFPFW_DL_DST) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1128 | self.verifyFlow(of_ports[0], of_ports[1]) |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1129 | # Install a flow with no wildcards for our packet |
| 1130 | self.installFlow(1000, of_ports[0], of_ports[2], wildcards=0) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1131 | self.verifyFlow(of_ports[0], of_ports[2]) |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1132 | # Install a flow with wildcards for our packet with higher |
| 1133 | # priority |
| 1134 | self.installFlow(1001, of_ports[0], of_ports[3]) |
| 1135 | self.verifyFlow(of_ports[0], of_ports[3]) |
Rich Lane | b839208 | 2012-11-21 15:52:54 -0800 | [diff] [blame] | 1136 | # Install a flow with wildcards for our packet with lower |
| 1137 | # priority |
| 1138 | self.installFlow(999, of_ports[0], of_ports[1], |
| 1139 | wildcards=ofp.OFPFW_DL_SRC) |
| 1140 | self.verifyFlow(of_ports[0], of_ports[3]) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1141 | |
| 1142 | |
Ken Chiang | 3978f24 | 2012-06-13 14:14:09 -0700 | [diff] [blame] | 1143 | class WildcardPriorityWithDelete(SingleWildcardMatchPriority): |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1144 | """ |
| 1145 | 1. Add exact match flow, verify packet received. |
| 1146 | 2. Add wildcard flow with higher priority, verify packet received on port |
| 1147 | specified by this flow. |
| 1148 | 3. Add exact match flow with even higher priority, verify packet received |
| 1149 | on port specified by this flow. |
| 1150 | 4. Delete lowest priority flow, verify packet received on port specified |
| 1151 | by highest priority flow. |
| 1152 | 5. Delete highest priority flow, verify packet received on port specified |
| 1153 | by remaining flow. |
| 1154 | """ |
| 1155 | |
| 1156 | def runTest(self): |
| 1157 | |
| 1158 | self._Init() |
| 1159 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1160 | of_ports = config["port_map"].keys() |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1161 | of_ports.sort() |
| 1162 | |
| 1163 | self._ClearTable() |
| 1164 | |
| 1165 | # Install an exact match flow |
| 1166 | self.installFlow(250, of_ports[0], of_ports[1], wildcards=0) |
| 1167 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1168 | # Install a flow with wildcards of higher priority |
| 1169 | self.installFlow(1250, of_ports[0], of_ports[2], |
| 1170 | wildcards=ofp.OFPFW_DL_DST) |
| 1171 | self.verifyFlow(of_ports[0], of_ports[2]) |
| 1172 | # Install an exact match flow with even higher priority |
| 1173 | self.installFlow(2001, of_ports[0], of_ports[3], wildcards=0) |
| 1174 | self.verifyFlow(of_ports[0], of_ports[3]) |
| 1175 | # Delete lowest priority flow |
| 1176 | self.removeFlow(250) |
| 1177 | self.verifyFlow(of_ports[0], of_ports[3]) |
| 1178 | # Delete highest priority flow |
| 1179 | self.removeFlow(2001) |
| 1180 | self.verifyFlow(of_ports[0], of_ports[2]) |
| 1181 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1182 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1183 | class SingleWildcardMatch(BaseMatchCase): |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 1184 | """ |
| 1185 | Exercise wildcard matching for all ports |
| 1186 | |
| 1187 | Generate a packet |
| 1188 | Generate and install a matching flow with wildcard mask |
| 1189 | Add action to forward to a port |
| 1190 | Send the packet to the port |
| 1191 | 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] | 1192 | Verify flow_expiration message is correct when command option is set |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 1193 | """ |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 1194 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1195 | vid = test_param_get('vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1196 | for wc in WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1197 | wc |= required_wildcards(self) |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1198 | if wc & ofp.OFPFW_DL_VLAN: |
Ken Chiang | 5be06dd | 2012-04-03 10:03:50 -0700 | [diff] [blame] | 1199 | # Set nonzero VLAN id to avoid sending priority-tagged packet |
| 1200 | dl_vlan = vid |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1201 | else: |
| 1202 | dl_vlan = -1 |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1203 | flow_match_test(self, config["port_map"], wildcards=wc, |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1204 | dl_vlan=dl_vlan, max_test=10) |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 1205 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1206 | class SingleWildcardMatchTagged(BaseMatchCase): |
| 1207 | """ |
| 1208 | SingleWildcardMatch with tagged packets |
| 1209 | """ |
| 1210 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1211 | vid = test_param_get('vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1212 | for wc in WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1213 | wc |= required_wildcards(self) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1214 | flow_match_test(self, config["port_map"], wildcards=wc, dl_vlan=vid, |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1215 | max_test=10) |
| 1216 | |
| 1217 | class AllExceptOneWildcardMatch(BaseMatchCase): |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 1218 | """ |
Dan Talayco | 80b54ed | 2010-07-13 09:48:35 -0700 | [diff] [blame] | 1219 | Match exactly one field |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 1220 | |
| 1221 | Generate a packet |
| 1222 | Generate and install a matching flow with wildcard all except one filed |
| 1223 | Add action to forward to a port |
| 1224 | Send the packet to the port |
| 1225 | Verify the packet is received at all other ports (one port at a time) |
| 1226 | Verify flow_expiration message is correct when command option is set |
| 1227 | """ |
| 1228 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1229 | vid = test_param_get('vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 1230 | for all_exp_one_wildcard in NO_WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1231 | all_exp_one_wildcard |= required_wildcards(self) |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1232 | if all_exp_one_wildcard & ofp.OFPFW_DL_VLAN: |
Ken Chiang | 5be06dd | 2012-04-03 10:03:50 -0700 | [diff] [blame] | 1233 | # Set nonzero VLAN id to avoid sending priority-tagged packet |
| 1234 | dl_vlan = vid |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1235 | else: |
| 1236 | dl_vlan = -1 |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1237 | flow_match_test(self, config["port_map"], wildcards=all_exp_one_wildcard, |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1238 | dl_vlan=dl_vlan) |
Tatsuya Yabe | e30ebe2 | 2010-05-25 09:30:49 -0700 | [diff] [blame] | 1239 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1240 | class AllExceptOneWildcardMatchTagged(BaseMatchCase): |
| 1241 | """ |
| 1242 | Match one field with tagged packets |
| 1243 | """ |
| 1244 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1245 | vid = test_param_get('vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 1246 | for all_exp_one_wildcard in NO_WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1247 | all_exp_one_wildcard |= required_wildcards(self) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1248 | flow_match_test(self, config["port_map"], wildcards=all_exp_one_wildcard, |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 1249 | dl_vlan=vid) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1250 | |
| 1251 | class AllWildcardMatch(BaseMatchCase): |
Tatsuya Yabe | e30ebe2 | 2010-05-25 09:30:49 -0700 | [diff] [blame] | 1252 | """ |
| 1253 | Create Wildcard-all flow and exercise for all ports |
| 1254 | |
| 1255 | Generate a packet |
| 1256 | Generate and install a matching flow with wildcard-all |
| 1257 | Add action to forward to a port |
| 1258 | Send the packet to the port |
| 1259 | Verify the packet is received at all other ports (one port at a time) |
| 1260 | Verify flow_expiration message is correct when command option is set |
| 1261 | """ |
| 1262 | def runTest(self): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1263 | flow_match_test(self, config["port_map"], wildcards=ofp.OFPFW_ALL) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1264 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1265 | class AllWildcardMatchTagged(BaseMatchCase): |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1266 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1267 | AllWildcardMatch with tagged packets |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1268 | """ |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1269 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1270 | vid = test_param_get('vid', default=TEST_VID_DEFAULT) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1271 | flow_match_test(self, config["port_map"], wildcards=ofp.OFPFW_ALL, |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 1272 | dl_vlan=vid) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1273 | |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1274 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1275 | class AddVLANTag(BaseMatchCase): |
| 1276 | """ |
| 1277 | Add a VLAN tag to an untagged packet |
| 1278 | """ |
| 1279 | def runTest(self): |
| 1280 | new_vid = 2 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1281 | sup_acts = self.supported_actions |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1282 | if not(sup_acts & 1<<ofp.OFPAT_SET_VLAN_VID): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1283 | skip_message_emit(self, "Add VLAN tag test") |
Dan Talayco | f36f108 | 2010-07-13 13:57:17 -0700 | [diff] [blame] | 1284 | return |
Tatsuya Yabe | f5ffb97 | 2010-05-26 15:36:33 -0700 | [diff] [blame] | 1285 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1286 | len = 100 |
| 1287 | len_w_vid = 104 |
| 1288 | pkt = simple_tcp_packet(pktlen=len) |
| 1289 | exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1290 | dl_vlan=new_vid) |
| 1291 | vid_act = action.action_set_vlan_vid() |
| 1292 | vid_act.vlan_vid = new_vid |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1293 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1294 | flow_match_test(self, config["port_map"], pkt=pkt, |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1295 | exp_pkt=exp_pkt, action_list=[vid_act]) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1296 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 1297 | class PacketOnly(base_tests.DataPlaneOnly): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1298 | """ |
| 1299 | Just send a packet thru the switch |
| 1300 | """ |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 1301 | |
| 1302 | priority = -1 |
| 1303 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1304 | def runTest(self): |
| 1305 | pkt = simple_tcp_packet() |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1306 | of_ports = config["port_map"].keys() |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1307 | of_ports.sort() |
| 1308 | ing_port = of_ports[0] |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1309 | logging.info("Sending packet to " + str(ing_port)) |
| 1310 | logging.debug("Data: " + str(pkt).encode('hex')) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1311 | self.dataplane.send(ing_port, str(pkt)) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1312 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 1313 | class PacketOnlyTagged(base_tests.DataPlaneOnly): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1314 | """ |
| 1315 | Just send a packet thru the switch |
| 1316 | """ |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 1317 | |
| 1318 | priority = -1 |
| 1319 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1320 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1321 | vid = test_param_get('vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1322 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1323 | of_ports = config["port_map"].keys() |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1324 | of_ports.sort() |
| 1325 | ing_port = of_ports[0] |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1326 | logging.info("Sending packet to " + str(ing_port)) |
| 1327 | logging.debug("Data: " + str(pkt).encode('hex')) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1328 | self.dataplane.send(ing_port, str(pkt)) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1329 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1330 | class ModifyVID(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1331 | """ |
| 1332 | Modify the VLAN ID in the VLAN tag of a tagged packet |
| 1333 | """ |
Dan Talayco | af66932 | 2012-09-12 22:51:22 -0700 | [diff] [blame] | 1334 | def setUp(self): |
| 1335 | BaseMatchCase.setUp(self) |
| 1336 | self.ing_port=False |
| 1337 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1338 | def runTest(self): |
| 1339 | old_vid = 2 |
| 1340 | new_vid = 3 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1341 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1342 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1343 | skip_message_emit(self, "Modify VLAN tag test") |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1344 | return |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1345 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1346 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=old_vid) |
| 1347 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=new_vid) |
| 1348 | vid_act = action.action_set_vlan_vid() |
| 1349 | vid_act.vlan_vid = new_vid |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1350 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1351 | 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] | 1352 | action_list=[vid_act], ing_port=self.ing_port) |
| 1353 | |
| 1354 | class ModifyVIDToIngress(ModifyVID): |
| 1355 | """ |
| 1356 | Modify the VLAN ID in the VLAN tag of a tagged packet and send to |
| 1357 | ingress port |
| 1358 | """ |
| 1359 | def setUp(self): |
| 1360 | BaseMatchCase.setUp(self) |
| 1361 | self.ing_port=True |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1362 | |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1363 | class ModifyVIDWithTagMatchWildcarded(BaseMatchCase): |
| 1364 | """ |
| 1365 | With vlan ID and priority wildcarded, perform SET_VLAN_VID action. |
| 1366 | The same flow should match on both untagged and tagged packets. |
| 1367 | """ |
| 1368 | def runTest(self): |
| 1369 | old_vid = 2 |
| 1370 | new_vid = 3 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1371 | sup_acts = self.supported_actions |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1372 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID): |
| 1373 | skip_message_emit(self, "ModifyVIDWithTagWildcarded test") |
| 1374 | return |
| 1375 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1376 | of_ports = config["port_map"].keys() |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1377 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 1378 | ing_port = of_ports[0] |
| 1379 | egr_ports = of_ports[1] |
| 1380 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1381 | rv = delete_all_flows(self.controller) |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1382 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 1383 | |
| 1384 | len_untagged = 100 |
| 1385 | len_w_vid = 104 |
| 1386 | untagged_pkt = simple_tcp_packet(pktlen=len_untagged) |
| 1387 | tagged_pkt = simple_tcp_packet(pktlen=len_w_vid, |
| 1388 | dl_vlan_enable=True, dl_vlan=old_vid) |
| 1389 | exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1390 | dl_vlan=new_vid) |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1391 | wildcards = (required_wildcards(self) | ofp.OFPFW_DL_VLAN | |
| 1392 | ofp.OFPFW_DL_VLAN_PCP) |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1393 | vid_act = action.action_set_vlan_vid() |
| 1394 | vid_act.vlan_vid = new_vid |
| 1395 | request = flow_msg_create(self, untagged_pkt, ing_port=ing_port, |
| 1396 | wildcards=wildcards, egr_ports=egr_ports, |
| 1397 | action_list=[vid_act]) |
| 1398 | flow_msg_install(self, request) |
| 1399 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1400 | logging.debug("Send untagged packet: " + str(ing_port) + " to " + |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1401 | str(egr_ports)) |
| 1402 | self.dataplane.send(ing_port, str(untagged_pkt)) |
| 1403 | receive_pkt_verify(self, egr_ports, exp_pkt, ing_port) |
| 1404 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1405 | logging.debug("Send tagged packet: " + str(ing_port) + " to " + |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1406 | str(egr_ports)) |
| 1407 | self.dataplane.send(ing_port, str(tagged_pkt)) |
| 1408 | receive_pkt_verify(self, egr_ports, exp_pkt, ing_port) |
| 1409 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 1410 | class ModifyVlanPcp(BaseMatchCase): |
| 1411 | """ |
| 1412 | Modify the priority field of the VLAN tag of a tagged packet |
| 1413 | """ |
| 1414 | def runTest(self): |
| 1415 | vid = 123 |
| 1416 | old_vlan_pcp = 2 |
| 1417 | new_vlan_pcp = 3 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1418 | sup_acts = self.supported_actions |
Ed Swierk | 8c3af7f | 2012-04-24 14:19:17 -0700 | [diff] [blame] | 1419 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP): |
| 1420 | skip_message_emit(self, "Modify VLAN priority test") |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 1421 | return |
| 1422 | |
| 1423 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=old_vlan_pcp) |
| 1424 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=new_vlan_pcp) |
| 1425 | vid_act = action.action_set_vlan_pcp() |
| 1426 | vid_act.vlan_pcp = new_vlan_pcp |
| 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, |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 1429 | action_list=[vid_act]) |
| 1430 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1431 | class StripVLANTag(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1432 | """ |
| 1433 | Strip the VLAN tag from a tagged packet |
| 1434 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1435 | def runTest(self): |
| 1436 | old_vid = 2 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1437 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1438 | if not (sup_acts & 1 << ofp.OFPAT_STRIP_VLAN): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1439 | skip_message_emit(self, "Strip VLAN tag test") |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1440 | return |
Dan Talayco | f36f108 | 2010-07-13 13:57:17 -0700 | [diff] [blame] | 1441 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1442 | len_w_vid = 104 |
| 1443 | len = 100 |
| 1444 | pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1445 | dl_vlan=old_vid) |
| 1446 | exp_pkt = simple_tcp_packet(pktlen=len) |
| 1447 | vid_act = action.action_strip_vlan() |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1448 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1449 | 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] | 1450 | action_list=[vid_act]) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1451 | |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1452 | class StripVLANTagWithTagMatchWildcarded(BaseMatchCase): |
| 1453 | """ |
| 1454 | Strip the VLAN tag from a tagged packet. |
| 1455 | Differs from StripVLANTag in that VID and PCP are both wildcarded. |
| 1456 | """ |
| 1457 | def runTest(self): |
| 1458 | old_vid = 2 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1459 | sup_acts = self.supported_actions |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1460 | if not (sup_acts & 1 << ofp.OFPAT_STRIP_VLAN): |
| 1461 | skip_message_emit(self, "StripVLANTagWithTagWildcarded test") |
| 1462 | return |
| 1463 | |
| 1464 | len_w_vid = 104 |
| 1465 | len_untagged = 100 |
| 1466 | pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1467 | dl_vlan=old_vid) |
| 1468 | exp_pkt = simple_tcp_packet(pktlen=len_untagged) |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1469 | wildcards = (required_wildcards(self) | ofp.OFPFW_DL_VLAN | |
| 1470 | ofp.OFPFW_DL_VLAN_PCP) |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1471 | vid_act = action.action_strip_vlan() |
| 1472 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1473 | flow_match_test(self, config["port_map"], |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1474 | wildcards=wildcards, |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1475 | pkt=pkt, exp_pkt=exp_pkt, |
| 1476 | action_list=[vid_act]) |
| 1477 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1478 | def init_pkt_args(): |
| 1479 | """ |
| 1480 | Pass back a dictionary with default packet arguments |
| 1481 | """ |
| 1482 | args = {} |
| 1483 | args["dl_src"] = '00:23:45:67:89:AB' |
| 1484 | |
| 1485 | dl_vlan_enable=False |
| 1486 | dl_vlan=-1 |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1487 | if config["test-params"]["vid"]: |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1488 | dl_vlan_enable=True |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1489 | dl_vlan = config["test-params"]["vid"] |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1490 | |
| 1491 | # Unpack operator is ** on a dictionary |
| 1492 | |
| 1493 | return args |
| 1494 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1495 | class ModifyL2Src(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1496 | """ |
| 1497 | Modify the source MAC address (TP1) |
| 1498 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1499 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1500 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1501 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1502 | skip_message_emit(self, "ModifyL2Src test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1503 | return |
| 1504 | |
| 1505 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'], |
| 1506 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1507 | 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] | 1508 | action_list=acts, max_test=2) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1509 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1510 | class ModifyL2Dst(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1511 | """ |
| 1512 | Modify the dest MAC address (TP1) |
| 1513 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1514 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1515 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1516 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1517 | skip_message_emit(self, "ModifyL2dst test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1518 | return |
| 1519 | |
| 1520 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1521 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1522 | 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] | 1523 | action_list=acts, max_test=2) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1524 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1525 | class ModifyL3Src(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1526 | """ |
| 1527 | Modify the source IP address of an IP packet (TP1) |
| 1528 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1529 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1530 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1531 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_SRC): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1532 | skip_message_emit(self, "ModifyL3Src test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1533 | return |
| 1534 | |
| 1535 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_src'], |
| 1536 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1537 | 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] | 1538 | action_list=acts, max_test=2) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1539 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1540 | class ModifyL3Dst(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1541 | """ |
| 1542 | Modify the dest IP address of an IP packet (TP1) |
| 1543 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1544 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1545 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1546 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_DST): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1547 | skip_message_emit(self, "ModifyL3Dst test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1548 | return |
| 1549 | |
| 1550 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_dst'], |
| 1551 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1552 | 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] | 1553 | action_list=acts, max_test=2) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1554 | |
| 1555 | class ModifyL4Src(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1556 | """ |
| 1557 | Modify the source TCP port of a TCP packet (TP1) |
| 1558 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1559 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1560 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1561 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_SRC): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1562 | skip_message_emit(self, "ModifyL4Src test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1563 | return |
| 1564 | |
| 1565 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_sport'], |
| 1566 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1567 | 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] | 1568 | action_list=acts, max_test=2) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1569 | |
Rich Lane | 01c2b86 | 2012-10-26 16:26:25 -0700 | [diff] [blame] | 1570 | class ModifyL4SrcUdp(BaseMatchCase): |
| 1571 | """ |
| 1572 | Modify the source UDP port of a UDP packet |
| 1573 | """ |
| 1574 | def runTest(self): |
| 1575 | sup_acts = self.supported_actions |
| 1576 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST): |
| 1577 | skip_message_emit(self, "ModifyL4SrcUdp test") |
| 1578 | return |
| 1579 | |
| 1580 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['udp_sport'], |
| 1581 | check_test_params=True, tp="udp") |
| 1582 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
| 1583 | action_list=acts, max_test=2) |
| 1584 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1585 | class ModifyL4Dst(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1586 | """ |
| 1587 | Modify the dest TCP port of a TCP packet (TP1) |
| 1588 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1589 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1590 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1591 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1592 | skip_message_emit(self, "ModifyL4Dst test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1593 | return |
| 1594 | |
| 1595 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_dport'], |
| 1596 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1597 | 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] | 1598 | action_list=acts, max_test=2) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1599 | |
Rich Lane | 01c2b86 | 2012-10-26 16:26:25 -0700 | [diff] [blame] | 1600 | class ModifyL4DstUdp(BaseMatchCase): |
| 1601 | """ |
| 1602 | Modify the dest UDP port of a UDP packet |
| 1603 | """ |
| 1604 | def runTest(self): |
| 1605 | sup_acts = self.supported_actions |
| 1606 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST): |
| 1607 | skip_message_emit(self, "ModifyL4DstUdp test") |
| 1608 | return |
| 1609 | |
| 1610 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['udp_dport'], |
| 1611 | check_test_params=True, tp="udp") |
| 1612 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
| 1613 | action_list=acts, max_test=2) |
| 1614 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1615 | class ModifyTOS(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1616 | """ |
| 1617 | Modify the IP type of service of an IP packet (TP1) |
| 1618 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1619 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1620 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1621 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1622 | skip_message_emit(self, "ModifyTOS test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1623 | return |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1624 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1625 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_tos'], |
| 1626 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1627 | 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] | 1628 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1629 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1630 | class ModifyL2DstMC(BaseMatchCase): |
| 1631 | """ |
| 1632 | Modify the L2 dest and send to 2 ports |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1633 | """ |
| 1634 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1635 | sup_acts = self.supported_actions |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1636 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1637 | skip_message_emit(self, "ModifyL2dstMC test") |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1638 | return |
| 1639 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1640 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1641 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1642 | 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] | 1643 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1644 | |
Dan Talayco | c948d0b | 2012-03-23 12:17:54 -0700 | [diff] [blame] | 1645 | class ModifyL2DstIngress(BaseMatchCase): |
| 1646 | """ |
| 1647 | Modify the L2 dest and send to the ingress port |
| 1648 | """ |
| 1649 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1650 | sup_acts = self.supported_actions |
Dan Talayco | c948d0b | 2012-03-23 12:17:54 -0700 | [diff] [blame] | 1651 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1652 | skip_message_emit(self, "ModifyL2dstIngress test") |
Dan Talayco | c948d0b | 2012-03-23 12:17:54 -0700 | [diff] [blame] | 1653 | return |
| 1654 | |
| 1655 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1656 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1657 | 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] | 1658 | action_list=acts, max_test=2, egr_count=0, |
| 1659 | ing_port=True) |
| 1660 | |
Dan Talayco | d8ae758 | 2012-03-23 12:24:56 -0700 | [diff] [blame] | 1661 | class ModifyL2DstIngressMC(BaseMatchCase): |
| 1662 | """ |
| 1663 | Modify the L2 dest and send to the ingress port |
| 1664 | """ |
| 1665 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1666 | sup_acts = self.supported_actions |
Dan Talayco | d8ae758 | 2012-03-23 12:24:56 -0700 | [diff] [blame] | 1667 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
| 1668 | skip_message_emit(self, "ModifyL2dstMC test") |
| 1669 | return |
| 1670 | |
| 1671 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 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 | d8ae758 | 2012-03-23 12:24:56 -0700 | [diff] [blame] | 1674 | action_list=acts, max_test=2, egr_count=-1, |
| 1675 | ing_port=True) |
| 1676 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1677 | class ModifyL2SrcMC(BaseMatchCase): |
| 1678 | """ |
| 1679 | Modify the source MAC address (TP1) and send to multiple |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1680 | """ |
| 1681 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1682 | sup_acts = self.supported_actions |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1683 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC): |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1684 | skip_message_emit(self, "ModifyL2SrcMC test") |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1685 | return |
| 1686 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1687 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'], |
| 1688 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1689 | 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] | 1690 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1691 | |
| 1692 | class ModifyL2SrcDstMC(BaseMatchCase): |
| 1693 | """ |
| 1694 | Modify the L2 source and dest and send to 2 ports |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1695 | """ |
| 1696 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1697 | sup_acts = self.supported_actions |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1698 | if (not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST) or |
| 1699 | not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC)): |
| 1700 | skip_message_emit(self, "ModifyL2SrcDstMC test") |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1701 | return |
| 1702 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1703 | mod_fields = ['dl_dst', 'dl_src'] |
| 1704 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=mod_fields, |
| 1705 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1706 | 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] | 1707 | action_list=acts, max_test=2, egr_count=-1) |
| 1708 | |
| 1709 | class ModifyL2DstVIDMC(BaseMatchCase): |
| 1710 | """ |
| 1711 | Modify the L2 dest and send to 2 ports |
| 1712 | """ |
| 1713 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1714 | sup_acts = self.supported_actions |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1715 | if (not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST) or |
| 1716 | not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID)): |
| 1717 | skip_message_emit(self, "ModifyL2DstVIDMC test") |
| 1718 | return |
| 1719 | |
| 1720 | mod_fields = ['dl_dst', 'dl_vlan'] |
| 1721 | (pkt, exp_pkt, acts) = pkt_action_setup(self, |
| 1722 | start_field_vals={'dl_vlan_enable':True}, mod_fields=mod_fields, |
| 1723 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1724 | 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] | 1725 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1726 | |
Rich Lane | 22e74c1 | 2012-11-12 15:06:06 -0800 | [diff] [blame] | 1727 | class ModifyAll(BaseMatchCase): |
| 1728 | """ |
| 1729 | Modify all supported fields and output to a port |
| 1730 | """ |
| 1731 | def runTest(self): |
| 1732 | sup_acts = self.supported_actions |
| 1733 | |
| 1734 | sup_map = { |
| 1735 | "dl_dst" : ofp.OFPAT_SET_DL_DST, |
| 1736 | "dl_src" : ofp.OFPAT_SET_DL_SRC, |
| 1737 | "dl_vlan_enable" : ofp.OFPAT_SET_VLAN_VID, |
| 1738 | "dl_vlan" : ofp.OFPAT_SET_VLAN_VID, |
| 1739 | "dl_vlan_pcp" : ofp.OFPAT_SET_VLAN_PCP, |
| 1740 | "ip_src" : ofp.OFPAT_SET_NW_SRC, |
| 1741 | "ip_dst" : ofp.OFPAT_SET_NW_DST, |
| 1742 | "ip_tos" : ofp.OFPAT_SET_NW_TOS, |
| 1743 | "tcp_sport" : ofp.OFPAT_SET_TP_SRC, |
| 1744 | "tcp_dport" : ofp.OFPAT_SET_TP_DST, |
| 1745 | } |
| 1746 | |
| 1747 | mod_fields = [field for (field, bit) in sup_map.items() if (sup_acts & 1 << bit)] |
| 1748 | random.shuffle(mod_fields) |
| 1749 | start_field_vals = { "dl_vlan_enable" : True } |
| 1750 | mod_field_vals = { "dl_vlan_enable" : True } |
| 1751 | logging.info("modifying fields: %s" % repr(mod_fields)) |
| 1752 | |
| 1753 | (pkt, exp_pkt, acts) = pkt_action_setup(self, |
| 1754 | mod_fields=mod_fields, |
| 1755 | start_field_vals=start_field_vals, |
| 1756 | mod_field_vals=mod_field_vals, |
| 1757 | check_test_params=True) |
| 1758 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
| 1759 | action_list=acts, max_test=2) |
| 1760 | |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1761 | class FlowToggle(BaseMatchCase): |
| 1762 | """ |
| 1763 | Add flows to the table and modify them repeatedly |
Dan Talayco | f7c4131 | 2012-07-23 12:53:19 -0700 | [diff] [blame] | 1764 | |
| 1765 | This is done by using only "add" flow messages. Since the check overlap |
| 1766 | flag is not set, the switch is supposed to modify the existing flow if |
| 1767 | the match already exists. |
| 1768 | |
| 1769 | Would probably be better to exercise more of the flow modify commands |
| 1770 | (add, modify, delete +/- strict). |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1771 | """ |
| 1772 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1773 | flow_count = test_param_get('ft_flow_count', default=20) |
| 1774 | iter_count = test_param_get('ft_iter_count', default=10) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1775 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1776 | logging.info("Running flow toggle with %d flows, %d iterations" % |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1777 | (flow_count, iter_count)) |
| 1778 | acts = [] |
| 1779 | acts.append(action.action_output()) |
| 1780 | acts.append(action.action_output()) |
| 1781 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1782 | of_ports = config["port_map"].keys() |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1783 | if len(of_ports) < 3: |
| 1784 | self.assertTrue(False, "Too few ports for test") |
| 1785 | |
| 1786 | for idx in range(2): |
| 1787 | acts[idx].port = of_ports[idx] |
| 1788 | |
| 1789 | flows = [] |
| 1790 | flows.append([]) |
| 1791 | flows.append([]) |
| 1792 | |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1793 | wildcards = (required_wildcards(self) | ofp.OFPFW_DL_SRC | |
| 1794 | ofp.OFPFW_DL_DST) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1795 | # Create up the flows in an array |
| 1796 | for toggle in range(2): |
| 1797 | for f_idx in range(flow_count): |
| 1798 | pkt = simple_tcp_packet(tcp_sport=f_idx) |
| 1799 | msg = message.flow_mod() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1800 | match = packet_to_flow_match(self, pkt) |
Shudong Zhou | 031373c | 2012-07-19 17:37:42 -0700 | [diff] [blame] | 1801 | match.in_port = of_ports[2] |
Dan Talayco | 50be767 | 2012-04-05 11:38:08 -0700 | [diff] [blame] | 1802 | match.wildcards = wildcards |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1803 | msg.match = match |
| 1804 | msg.buffer_id = 0xffffffff |
Dan Talayco | f7c4131 | 2012-07-23 12:53:19 -0700 | [diff] [blame] | 1805 | msg.command = ofp.OFPFC_ADD |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1806 | msg.actions.add(acts[toggle]) |
| 1807 | flows[toggle].append(msg) |
Dan Talayco | 50be767 | 2012-04-05 11:38:08 -0700 | [diff] [blame] | 1808 | |
| 1809 | # Show two sample flows |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1810 | logging.debug(flows[0][0].show()) |
| 1811 | logging.debug(flows[1][0].show()) |
Dan Talayco | 50be767 | 2012-04-05 11:38:08 -0700 | [diff] [blame] | 1812 | |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1813 | # Install the first set of flows |
| 1814 | for f_idx in range(flow_count): |
| 1815 | rv = self.controller.message_send(flows[0][f_idx]) |
| 1816 | self.assertTrue(rv != -1, "Error installing flow %d" % f_idx) |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 1817 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1818 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1819 | logging.info("Installed %d flows" % flow_count) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1820 | |
| 1821 | # Repeatedly modify all the flows back and forth |
| 1822 | updates = 0 |
| 1823 | # Report status about 5 times |
| 1824 | mod_val = (iter_count / 4) + 1 |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1825 | start = time.time() |
| 1826 | for iter_idx in range(iter_count): |
| 1827 | if not iter_idx % mod_val: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1828 | logging.info("Flow Toggle: iter %d of %d. " % |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1829 | (iter_idx, iter_count) + |
| 1830 | "%d updates in %d secs" % |
| 1831 | (updates, time.time() - start)) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1832 | for toggle in range(2): |
| 1833 | t_idx = 1 - toggle |
| 1834 | for f_idx in range(flow_count): |
| 1835 | rv = self.controller.message_send(flows[t_idx][f_idx]) |
| 1836 | updates += 1 |
| 1837 | self.assertTrue(rv != -1, "Error modifying flow %d" % |
| 1838 | f_idx) |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 1839 | self.assertEqual(do_barrier(self.controller), 0, |
| 1840 | "Barrier failed") |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1841 | |
| 1842 | end = time.time() |
| 1843 | divisor = end - start or (end - start + 1) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1844 | logging.info("Flow toggle: %d iterations" % iter_count) |
| 1845 | logging.info(" %d flow mods in %d secs, %d mods/sec" % |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1846 | (updates, end - start, updates/divisor)) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1847 | |
| 1848 | |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1849 | # You can pick and choose these by commenting tests in or out |
| 1850 | iter_classes = [ |
| 1851 | basic.PacketIn, |
| 1852 | basic.PacketOut, |
| 1853 | DirectPacket, |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1854 | FlowToggle, |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1855 | DirectTwoPorts, |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1856 | DirectMCNonIngress, |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1857 | AllWildcardMatch, |
| 1858 | AllWildcardMatchTagged, |
| 1859 | SingleWildcardMatch, |
| 1860 | SingleWildcardMatchTagged, |
| 1861 | ExactMatch, |
| 1862 | ExactMatchTagged, |
| 1863 | SingleWildcardMatch, |
| 1864 | ModifyL2Src, |
| 1865 | ModifyL2Dst, |
| 1866 | ModifyL2SrcMC, |
| 1867 | ModifyL2DstMC, |
| 1868 | ModifyL2SrcDstMC |
| 1869 | ] |
| 1870 | |
| 1871 | class IterCases(BaseMatchCase): |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1872 | """ |
| 1873 | Iterate over a bunch of test cases |
| 1874 | |
| 1875 | The cases come from the list above |
| 1876 | """ |
| 1877 | |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 1878 | priority = -1 |
| 1879 | |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1880 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1881 | count = test_param_get('iter_count', default=10) |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1882 | tests_done = 0 |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1883 | logging.info("Running iteration test " + str(count) + " times") |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1884 | start = time.time() |
| 1885 | last = start |
| 1886 | for idx in range(count): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1887 | logging.info("Iteration " + str(idx + 1)) |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1888 | for cls in iter_classes: |
| 1889 | test = cls() |
| 1890 | test.inheritSetup(self) |
| 1891 | test.runTest() |
| 1892 | tests_done += 1 |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1893 | # Report update about every minute, between tests |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1894 | if time.time() - last > 60: |
| 1895 | last = time.time() |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1896 | logging.info( |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1897 | "IterCases: Iter %d of %d; Ran %d tests in %d " % |
| 1898 | (idx, count, tests_done, last - start) + |
| 1899 | "seconds so far") |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1900 | stats = all_stats_get(self) |
| 1901 | last = time.time() |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1902 | logging.info("\nIterCases ran %d tests in %d seconds." % |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1903 | (tests_done, last - start)) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1904 | logging.info(" flows: %d. packets: %d. bytes: %d" % |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1905 | (stats["flows"], stats["packets"], stats["bytes"])) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1906 | logging.info(" active: %d. lookups: %d. matched %d." % |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1907 | (stats["active"], stats["lookups"], stats["matched"])) |
| 1908 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1909 | #@todo Need to implement tagged versions of the above tests |
| 1910 | # |
| 1911 | #@todo Implement a test case that strips tag 2, adds tag 3 |
| 1912 | # and modifies tag 4 to tag 5. Then verify (in addition) that |
| 1913 | # tag 6 does not get modified. |
| 1914 | |
| 1915 | class MixedVLAN(BaseMatchCase): |
| 1916 | """ |
| 1917 | Test mixture of VLAN tag actions |
| 1918 | |
| 1919 | Strip tag 2 on port 1, send to port 2 |
| 1920 | Add tag 3 on port 1, send to port 2 |
| 1921 | Modify tag 4 to 5 on port 1, send to port 2 |
| 1922 | All other traffic from port 1, send to port 3 |
| 1923 | All traffic from port 2 sent to port 4 |
| 1924 | Use exact matches with different packets for all mods |
| 1925 | Verify the following: (port, vid) |
| 1926 | (port 1, vid 2) => VLAN tag stripped, out port 2 |
| 1927 | (port 1, no tag) => tagged packet w/ vid 2 out port 2 |
| 1928 | (port 1, vid 4) => tagged packet w/ vid 5 out port 2 |
| 1929 | (port 1, vid 5) => tagged packet w/ vid 5 out port 2 |
| 1930 | (port 1, vid 6) => tagged packet w/ vid 6 out port 2 |
| 1931 | (port 2, no tag) => untagged packet out port 4 |
| 1932 | (port 2, vid 2-6) => unmodified packet out port 4 |
| 1933 | |
| 1934 | Variation: Might try sending VID 5 to port 3 and check. |
| 1935 | If only VID 5 distinguishes pkt, this will fail on some platforms |
| 1936 | """ |
| 1937 | |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 1938 | priority = -1 |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1939 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 1940 | class MatchEach(base_tests.SimpleDataPlane): |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1941 | """ |
| 1942 | Check that each match field is actually matched on. |
| 1943 | Installs two flows that differ in one field. The flow that should not |
| 1944 | match has a higher priority, so if that field is ignored during matching |
| 1945 | the packet will be sent out the wrong port. |
| 1946 | |
| 1947 | TODO test UDP, ARP, ICMP, etc. |
| 1948 | """ |
| 1949 | def runTest(self): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1950 | of_ports = config["port_map"].keys() |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1951 | of_ports.sort() |
| 1952 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 1953 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1954 | delete_all_flows(self.controller) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1955 | |
Ed Swierk | 7040a8d | 2012-12-11 16:30:13 -0800 | [diff] [blame^] | 1956 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=2) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1957 | ingress_port = of_ports[0] |
| 1958 | egress_port = of_ports[1] |
| 1959 | |
| 1960 | def testField(field, mask): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1961 | logging.info("Testing field %s" % field) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1962 | |
| 1963 | def addFlow(matching, priority, output_port): |
| 1964 | match = packet_to_flow_match(self, pkt) |
| 1965 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 1966 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 1967 | match.in_port = ingress_port |
| 1968 | if not matching: |
| 1969 | # Make sure flow doesn't match |
| 1970 | orig = getattr(match, field) |
| 1971 | if isinstance(orig, list): |
| 1972 | new = map(lambda a: ~a[0] & a[1], zip(orig, mask)) |
| 1973 | else: |
| 1974 | new = ~orig & mask |
| 1975 | setattr(match, field, new) |
| 1976 | request = message.flow_mod() |
| 1977 | request.match = match |
| 1978 | request.buffer_id = 0xffffffff |
| 1979 | request.priority = priority |
| 1980 | act = action.action_output() |
| 1981 | act.port = output_port |
| 1982 | self.assertTrue(request.actions.add(act), "Could not add action") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1983 | logging.info("Inserting flow") |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1984 | self.controller.message_send(request) |
| 1985 | |
| 1986 | # This flow should match. |
| 1987 | addFlow(matching=True, priority=0, output_port=egress_port) |
| 1988 | # This flow should not match, but it has a higher priority. |
| 1989 | addFlow(matching=False, priority=1, output_port=ofp.OFPP_IN_PORT) |
| 1990 | |
| 1991 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 1992 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1993 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1994 | self.dataplane.send(ingress_port, str(pkt)) |
| 1995 | |
| 1996 | exp_pkt_arg = None |
| 1997 | exp_port = None |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1998 | if config["relax"]: |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1999 | exp_pkt_arg = pkt |
| 2000 | exp_port = egress_port |
| 2001 | |
| 2002 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(port_number=exp_port, |
| 2003 | exp_pkt=exp_pkt_arg) |
| 2004 | self.assertTrue(rcv_pkt is not None, "Did not receive packet") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 2005 | 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] | 2006 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 2007 | self.assertEqual(str(pkt), str(rcv_pkt), 'Response packet does not match send packet') |
| 2008 | |
| 2009 | # TODO in_port |
| 2010 | testField("dl_src", [0xff]*6) |
| 2011 | testField("dl_dst", [0xff]*6) |
| 2012 | testField("dl_type", 0xffff) |
| 2013 | testField("dl_vlan", 0xfff) |
| 2014 | # TODO dl_vlan_pcp |
| 2015 | testField("nw_src", 0xffffffff) |
| 2016 | testField("nw_dst", 0xffffffff) |
| 2017 | testField("nw_tos", 0x3f) |
| 2018 | testField("nw_proto", 0xff) |
| 2019 | testField("tp_src", 0xffff) |
| 2020 | testField("tp_dst", 0xffff) |
| 2021 | |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2022 | class DirectBadPacketBase(base_tests.SimpleDataPlane): |
| 2023 | """ |
| 2024 | Base class for sending single packets with single flow table entries. |
| 2025 | Used to verify matching of unusual packets and parsing/matching of |
| 2026 | corrupted packets. |
| 2027 | |
| 2028 | The idea is to generate packets that may either be totally malformed or |
| 2029 | malformed just enough to trick the flow matcher into making mistakes. |
| 2030 | |
| 2031 | Generate a 'bad' packet |
| 2032 | Generate and install a matching flow |
| 2033 | Add action to direct the packet to an egress port |
| 2034 | Send the packet to ingress dataplane port |
| 2035 | Verify the packet is received at the egress port only |
| 2036 | """ |
| 2037 | |
| 2038 | RESULT_MATCH = "MATCH" |
| 2039 | RESULT_NOMATCH = "NO MATCH" |
| 2040 | RESULT_ANY = "ANY MATCH" |
| 2041 | |
| 2042 | def runTest(self): |
| 2043 | pass |
| 2044 | # TODO: |
| 2045 | # - ICMP? |
| 2046 | # - VLAN? |
| 2047 | # - action |
| 2048 | |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2049 | def createMatch(self, **kwargs): |
| 2050 | match = ofp.ofp_match() |
| 2051 | match.wildcards = ofp.OFPFW_ALL |
| 2052 | fields = { |
| 2053 | 'dl_dst': ofp.OFPFW_DL_DST, |
| 2054 | 'dl_src': ofp.OFPFW_DL_SRC, |
| 2055 | 'dl_type': ofp.OFPFW_DL_TYPE, |
| 2056 | 'dl_vlan': ofp.OFPFW_DL_VLAN, |
| 2057 | 'nw_src': ofp.OFPFW_NW_SRC_MASK, |
| 2058 | 'nw_dst': ofp.OFPFW_NW_DST_MASK, |
| 2059 | 'nw_tos': ofp.OFPFW_NW_TOS, |
| 2060 | 'nw_proto': ofp.OFPFW_NW_PROTO, |
| 2061 | 'tp_src': ofp.OFPFW_TP_SRC, |
| 2062 | 'tp_dst': ofp.OFPFW_TP_DST, |
| 2063 | } |
| 2064 | for key in kwargs: |
| 2065 | setattr(match, key, kwargs[key]) |
| 2066 | match.wildcards &= ~fields[key] |
| 2067 | return match |
| 2068 | |
| 2069 | def testPktsAgainstFlow(self, pkts, acts, match): |
| 2070 | if type(acts) != list: |
| 2071 | acts = [acts] |
| 2072 | for info in pkts: |
| 2073 | title, pkt, expected_result = info |
| 2074 | self.testPktAgainstFlow(title, pkt, acts, match, expected_result) |
| 2075 | |
| 2076 | def testPktAgainstFlow(self, title, pkt, acts, match, expected_result): |
| 2077 | of_ports = config["port_map"].keys() |
| 2078 | of_ports.sort() |
| 2079 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 2080 | |
| 2081 | rv = delete_all_flows(self.controller) |
| 2082 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 2083 | |
| 2084 | ingress_port = of_ports[0] |
| 2085 | egress_port = of_ports[1] |
| 2086 | |
| 2087 | logging.info("Testing packet '%s', expect result %s" % |
| 2088 | (title, expected_result)) |
| 2089 | logging.info("Ingress %s to egress %s" % |
| 2090 | (str(ingress_port), str(egress_port))) |
| 2091 | logging.info("Packet:") |
Rich Lane | 5d7e89a | 2012-10-26 16:43:13 -0700 | [diff] [blame] | 2092 | logging.info(inspect_packet(pkt)) |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2093 | |
| 2094 | match.in_port = ingress_port |
| 2095 | |
| 2096 | request = message.flow_mod() |
| 2097 | request.match = match |
Rich Lane | 44cf12d | 2012-10-15 11:10:45 -0700 | [diff] [blame] | 2098 | request.priority = 1 |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2099 | |
| 2100 | request.buffer_id = 0xffffffff |
| 2101 | for act in acts: |
| 2102 | act.port = egress_port |
| 2103 | rv = request.actions.add(act) |
| 2104 | self.assertTrue(rv, "Could not add action") |
| 2105 | |
| 2106 | logging.info("Inserting flow") |
| 2107 | rv = self.controller.message_send(request) |
| 2108 | self.assertTrue(rv != -1, "Error installing flow mod") |
Rich Lane | 44cf12d | 2012-10-15 11:10:45 -0700 | [diff] [blame] | 2109 | |
| 2110 | # This flow speeds up negative tests |
| 2111 | logging.info("Inserting catch-all flow") |
| 2112 | request2 = message.flow_mod() |
| 2113 | request2.match = self.createMatch() |
| 2114 | request2.priority = 0 |
| 2115 | act = action.action_output() |
| 2116 | act.port = ofp.OFPP_IN_PORT |
| 2117 | request2.actions.add(act) |
| 2118 | rv = self.controller.message_send(request2) |
| 2119 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 2120 | |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2121 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 2122 | |
| 2123 | logging.info("Sending packet to dp port " + |
| 2124 | str(ingress_port)) |
| 2125 | self.dataplane.send(ingress_port, str(pkt)) |
| 2126 | |
| 2127 | exp_pkt_arg = None |
| 2128 | exp_port = None |
| 2129 | if config["relax"]: |
| 2130 | exp_pkt_arg = pkt |
| 2131 | exp_port = egress_port |
| 2132 | |
Rich Lane | 44cf12d | 2012-10-15 11:10:45 -0700 | [diff] [blame] | 2133 | if expected_result == self.RESULT_MATCH: |
| 2134 | timeout = -1 # default timeout |
| 2135 | else: |
| 2136 | timeout = 1 # short timeout for negative tests |
| 2137 | |
| 2138 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(exp_pkt=exp_pkt_arg, |
| 2139 | timeout=timeout) |
| 2140 | if rcv_port == ingress_port: |
| 2141 | logging.debug("Packet matched catch-all flow") |
| 2142 | rcv_pkt = None |
| 2143 | |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2144 | if expected_result == self.RESULT_MATCH: |
| 2145 | self.assertTrue(rcv_pkt is not None, |
| 2146 | "Did not receive packet, expected a match") |
| 2147 | logging.debug("Packet len " + str(len(rcv_pkt)) + " in on " + |
| 2148 | str(rcv_port)) |
| 2149 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 2150 | str_pkt = str(pkt) |
| 2151 | str_rcv_pkt = str(rcv_pkt) |
| 2152 | str_rcv_pkt = str_rcv_pkt[0:len(str_pkt)] |
| 2153 | if str_pkt != str_rcv_pkt: |
| 2154 | logging.error("Response packet does not match send packet") |
| 2155 | logging.info("Response:") |
Rich Lane | 5d7e89a | 2012-10-26 16:43:13 -0700 | [diff] [blame] | 2156 | logging.info(inspect_packet(scapy.Ether(rcv_pkt))) |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2157 | self.assertEqual(str_pkt, str_rcv_pkt, |
| 2158 | 'Response packet does not match send packet') |
| 2159 | elif expected_result == self.RESULT_NOMATCH: |
| 2160 | self.assertTrue(rcv_pkt is None, "Received packet, expected drop") |
| 2161 | else: |
| 2162 | logging.debug("Match or drop accepted. Result = %s" % |
| 2163 | ("match" if rcv_pkt is not None else "drop")) |
| 2164 | |
| 2165 | |
| 2166 | class DirectBadIpTcpPacketsBase(DirectBadPacketBase): |
| 2167 | """ |
| 2168 | Base class for TCP and UDP parsing/matching verification under corruptions |
| 2169 | """ |
| 2170 | def runTest(self): |
| 2171 | pass |
| 2172 | |
| 2173 | def runTestWithProto(self, protoName = 'TCP'): |
| 2174 | dl_dst='00:01:02:03:04:05' |
| 2175 | dl_src='00:06:07:08:09:0a' |
| 2176 | ip_src='192.168.0.1' |
| 2177 | ip_dst='192.168.0.2' |
| 2178 | ip_tos=0 |
| 2179 | tcp_sport=1234 |
| 2180 | tcp_dport=80 |
| 2181 | |
| 2182 | # Generate a proper packet for constructing a match |
| 2183 | tp = None |
| 2184 | if protoName == 'TCP': |
| 2185 | tp = scapy.TCP |
| 2186 | proto = 6 |
| 2187 | elif protoName == 'UDP': |
| 2188 | tp = scapy.UDP |
| 2189 | proto = 17 |
| 2190 | else: |
| 2191 | raise Exception("Passed in unknown proto name") |
| 2192 | |
| 2193 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2194 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos)/ \ |
| 2195 | tp(sport=tcp_sport, dport=tcp_dport) |
| 2196 | match = packet_to_flow_match(self, match_pkt) |
| 2197 | self.assertTrue(match is not None, |
| 2198 | "Could not generate flow match from pkt") |
| 2199 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2200 | |
| 2201 | def testPacket(title, pkt, result): |
| 2202 | act = action.action_output() |
| 2203 | pkts = [ |
| 2204 | [title, pkt, result] |
| 2205 | ] |
| 2206 | self.testPktsAgainstFlow(pkts, act, match) |
| 2207 | |
| 2208 | # Try incomplete IP headers |
| 2209 | testPacket("Incomplete IP header (1 bytes)", |
| 2210 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2211 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:1], |
| 2212 | self.RESULT_NOMATCH, |
| 2213 | ) |
| 2214 | testPacket("Incomplete IP header (2 bytes)", |
| 2215 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2216 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:2], |
| 2217 | self.RESULT_NOMATCH, |
| 2218 | ) |
| 2219 | testPacket("Incomplete IP header (3 bytes)", |
| 2220 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2221 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:3], |
| 2222 | self.RESULT_NOMATCH, |
| 2223 | ) |
| 2224 | testPacket("Incomplete IP header (12 bytes)", |
| 2225 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2226 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:12], |
| 2227 | self.RESULT_NOMATCH, |
| 2228 | ) |
| 2229 | testPacket("Incomplete IP header (16 bytes)", |
| 2230 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2231 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:16], |
| 2232 | self.RESULT_NOMATCH, |
| 2233 | ) |
| 2234 | testPacket("Incomplete IP header (19 bytes)", |
| 2235 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2236 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:19], |
| 2237 | self.RESULT_NOMATCH, |
| 2238 | ) |
| 2239 | |
| 2240 | # Try variations where the TCP header is missing or incomplete. As we |
| 2241 | # saw bugs before where buffers were reused and lengths weren't honored, |
| 2242 | # we initiatlize once with a non-matching full packet and once with a |
| 2243 | # matching full packet. |
| 2244 | testPacket("Non-Matching TCP packet, warming buffer", |
| 2245 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2246 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto)/ \ |
| 2247 | tp(sport=tcp_sport, dport=tcp_dport + 1), |
| 2248 | self.RESULT_NOMATCH, |
| 2249 | ) |
| 2250 | testPacket("Missing TCP header, buffer warmed with non-match", |
| 2251 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2252 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto), |
| 2253 | self.RESULT_NOMATCH, |
| 2254 | ) |
| 2255 | testPacket("Matching TCP packet, warming buffer", |
| 2256 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2257 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto)/ \ |
| 2258 | tp(sport=tcp_sport, dport=tcp_dport), |
| 2259 | self.RESULT_MATCH, |
| 2260 | ) |
| 2261 | testPacket("Missing TCP header, buffer warmed with match", |
| 2262 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2263 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto), |
| 2264 | self.RESULT_NOMATCH, |
| 2265 | ) |
| 2266 | testPacket("Truncated TCP header: 2 bytes", |
| 2267 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2268 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto)/ \ |
| 2269 | (str(tp(sport=tcp_sport, dport=tcp_dport))[0:2]), |
| 2270 | self.RESULT_NOMATCH, |
| 2271 | ) |
| 2272 | |
| 2273 | # Play with IP header length values that put the start of TCP either |
| 2274 | # inside the generated TCP header or beyond. In some cases it may even |
| 2275 | # be beyond the packet boundary. Also play with IP options and more |
| 2276 | # importantly IP total length corruptions. |
| 2277 | testPacket("TCP packet, corrupt ihl (0x6)", |
| 2278 | simple_tcp_packet(ip_ihl=6), |
| 2279 | self.RESULT_NOMATCH, |
| 2280 | ) |
| 2281 | testPacket("TCP packet, corrupt ihl (0xf)", |
| 2282 | simple_tcp_packet(ip_ihl=0xf), # ihl = 15 * 4 = 60 |
| 2283 | self.RESULT_NOMATCH, |
| 2284 | ) |
| 2285 | testPacket("TCP packet, corrupt ihl and total length", |
| 2286 | simple_tcp_packet(ip_ihl=0xf, pktlen=56), # ihl = 15 * 4 = 60, |
| 2287 | self.RESULT_NOMATCH, |
| 2288 | ) |
| 2289 | testPacket("Corrupt IPoption: First 4 bytes of matching TCP header", |
| 2290 | simple_tcp_packet( |
| 2291 | ip_options=scapy.IPOption('\x04\xd2\x00\x50'), |
| 2292 | tcp_dport=2, tcp_sport=2 |
| 2293 | ), |
| 2294 | self.RESULT_NOMATCH, |
| 2295 | ) |
| 2296 | testPacket("Missing TCP header, corrupt ihl", |
| 2297 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2298 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ihl=0xf, proto=proto), |
| 2299 | self.RESULT_NOMATCH, |
| 2300 | ) |
| 2301 | testPacket("Missing TCP header, corrupt total length", |
| 2302 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2303 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto, len= 100), |
| 2304 | self.RESULT_NOMATCH, |
| 2305 | ) |
| 2306 | testPacket("Missing TCP header, corrupt ihl and total length", |
| 2307 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2308 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ihl=0xf, proto=proto, len=43), |
| 2309 | self.RESULT_NOMATCH, |
| 2310 | ) |
| 2311 | testPacket("Incomplete IP header (12 bytes), corrupt ihl and total length", |
| 2312 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2313 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto, ihl=10, len=43))[0:12], |
| 2314 | self.RESULT_NOMATCH, |
| 2315 | ) |
| 2316 | testPacket("Incomplete IP header (16 bytes), corrupt ihl and total length", |
| 2317 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2318 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto, ihl=10, len=43))[0:16], |
| 2319 | self.RESULT_NOMATCH, |
| 2320 | ) |
| 2321 | |
| 2322 | # Try an incomplete TCP header that has enough bytes to carry source and |
| 2323 | # destination ports. As that is all we care about during matching, some |
| 2324 | # implementations may match and some may drop the packet |
| 2325 | testPacket("Incomplete TCP header: src/dst port present", |
| 2326 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2327 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto)/ \ |
| 2328 | (str(tp(sport=tcp_sport, dport=tcp_dport))[0:4]), |
| 2329 | self.RESULT_ANY, |
| 2330 | ) |
| 2331 | |
| 2332 | for i in range(1): |
| 2333 | for length in range(40 / 4): # IPv4 options are a maximum of 40 in length |
| 2334 | bytes = "".join([("%c" % random.randint(0, 255)) for x in range(length * 4)]) |
| 2335 | eth = scapy.Ether(dst=dl_dst, src=dl_src) |
| 2336 | ip = scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ihl=5 + length, proto=proto) |
| 2337 | tcp = tp(sport=tcp_sport, dport=tcp_dport+1) |
| 2338 | pkt = eth / ip |
| 2339 | pkt = pkt / bytes |
| 2340 | pkt = pkt / str(tcp) |
| 2341 | testPacket("Random IP options len = %d - TP match must fail" % length * 4, |
| 2342 | pkt, |
| 2343 | self.RESULT_NOMATCH |
| 2344 | ) |
| 2345 | |
| 2346 | eth = scapy.Ether(dst=dl_dst, src=dl_src) |
| 2347 | ip = scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ihl=5 + length, proto=proto) |
| 2348 | tcp = tp(sport=tcp_sport, dport=tcp_dport) |
| 2349 | pkt = eth / ip |
| 2350 | pkt = pkt / bytes |
| 2351 | pkt = pkt / str(tcp) |
| 2352 | |
| 2353 | testPacket("Random IP options len = %d - May match", |
| 2354 | pkt, |
| 2355 | self.RESULT_ANY |
| 2356 | ) |
| 2357 | |
| 2358 | |
| 2359 | class DirectBadIpTcpPackets(DirectBadIpTcpPacketsBase): |
| 2360 | """ |
| 2361 | Verify IP/TCP parsing and matching. Focus on packet corruptions |
| 2362 | """ |
| 2363 | def runTest(self): |
| 2364 | self.runTestWithProto(protoName = 'TCP') |
| 2365 | |
| 2366 | class DirectBadIpUdpPackets(DirectBadIpTcpPacketsBase): |
| 2367 | """ |
| 2368 | Verify IP/UDP parsing and matching. Focus on packet corruptions |
| 2369 | """ |
| 2370 | def runTest(self): |
| 2371 | self.runTestWithProto(protoName = 'UDP') |
| 2372 | |
| 2373 | class DirectBadLlcPackets(DirectBadPacketBase): |
| 2374 | """ |
| 2375 | Verify LLC/SNAP parsing and matching. Focus on packet corruptions |
| 2376 | """ |
| 2377 | def runTest(self): |
| 2378 | dl_dst='00:01:02:03:04:05' |
| 2379 | dl_src='00:06:07:08:09:0a' |
| 2380 | ip_src='192.168.0.1' |
| 2381 | ip_dst='192.168.0.2' |
| 2382 | ip_tos=0 |
| 2383 | tcp_sport=1234 |
| 2384 | tcp_dport=80 |
| 2385 | |
| 2386 | IS_SNAP_IP = 1 |
| 2387 | IS_SNAP_IP_CORRUPT = 2 |
| 2388 | IS_NOT_SNAP_IP = 3 |
| 2389 | |
| 2390 | def testPacketTcpMatch(title, llc): |
| 2391 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2392 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos)/ \ |
| 2393 | scapy.TCP(sport=tcp_sport, dport=tcp_dport) |
| 2394 | match = packet_to_flow_match(self, match_pkt) |
| 2395 | self.assertTrue(match is not None, |
| 2396 | "Could not generate flow match from pkt") |
| 2397 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2398 | act = action.action_output() |
| 2399 | |
| 2400 | self.testPktsAgainstFlow( |
| 2401 | [[ |
| 2402 | "TCP match - LLC frame correct length - %s" % title, |
| 2403 | scapy.Ether(dst=dl_dst, src=dl_src, type=len(llc)) / llc, |
| 2404 | self.RESULT_ANY, |
| 2405 | ]], |
| 2406 | act, match |
| 2407 | ) |
| 2408 | |
| 2409 | # Corrupt length field |
| 2410 | ethLen = random.randint(0, 1535) |
| 2411 | self.testPktsAgainstFlow( |
| 2412 | [[ |
| 2413 | "TCP match - LLC frame corrupted length - %s" % title, |
| 2414 | scapy.Ether(dst=dl_dst, src=dl_src, type=ethLen) / llc, |
| 2415 | self.RESULT_ANY, |
| 2416 | ]], |
| 2417 | act, match |
| 2418 | ) |
| 2419 | |
| 2420 | def testPacketEthSrcDstMatch(title, llc): |
| 2421 | # Matching based on Ethernet source and destination |
| 2422 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src) |
| 2423 | match = packet_to_flow_match(self, match_pkt) |
| 2424 | self.assertTrue(match is not None, |
| 2425 | "Could not generate flow match from pkt") |
| 2426 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2427 | match.wildcards |= ofp.OFPFW_DL_TYPE |
| 2428 | self.testPktsAgainstFlow( |
| 2429 | [[ |
| 2430 | "Eth addr match - LLC frame correct length- %s" % title, |
| 2431 | scapy.Ether(dst=dl_dst, src=dl_src, type=len(llc)) / llc, |
| 2432 | self.RESULT_MATCH, |
| 2433 | ]], |
| 2434 | action.action_output(), match |
| 2435 | ) |
| 2436 | |
| 2437 | # Corrupt length field |
| 2438 | ethLen = random.randint(0, 1535) |
| 2439 | self.testPktsAgainstFlow( |
| 2440 | [[ |
| 2441 | "Eth addr match - LLC frame corrupted length- %s" % title, |
| 2442 | scapy.Ether(dst=dl_dst, src=dl_src, type=ethLen) / llc, |
| 2443 | self.RESULT_ANY, |
| 2444 | ]], |
| 2445 | action.action_output(), match |
| 2446 | ) |
| 2447 | |
| 2448 | def testPacketEthSrcDstTypeMatch(title, llc, is_snap_ip): |
| 2449 | # Matching based on Ethernet source, destination and type |
| 2450 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src, type=0x800) |
| 2451 | match = packet_to_flow_match(self, match_pkt) |
| 2452 | self.assertTrue(match is not None, |
| 2453 | "Could not generate flow match from pkt") |
| 2454 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2455 | if is_snap_ip == IS_SNAP_IP: |
| 2456 | is_match = self.RESULT_MATCH |
| 2457 | elif is_snap_ip == IS_SNAP_IP_CORRUPT: |
| 2458 | is_match = self.RESULT_ANY |
| 2459 | else: |
| 2460 | is_match = self.RESULT_NOMATCH |
| 2461 | self.testPktsAgainstFlow( |
| 2462 | [[ |
| 2463 | "Eth addr+type match - LLC frame correct length - %s" % title, |
| 2464 | scapy.Ether(dst=dl_dst, src=dl_src, type=len(llc)) / llc, |
| 2465 | is_match, |
| 2466 | ]], |
| 2467 | action.action_output(), match |
| 2468 | ) |
| 2469 | |
| 2470 | # Corrupt length field |
| 2471 | ethLen = random.randint(0, 1535) |
| 2472 | self.testPktsAgainstFlow( |
| 2473 | [[ |
| 2474 | "Eth addr+type match - LLC frame corrupted length - %s" % title, |
| 2475 | scapy.Ether(dst=dl_dst, src=dl_src, type=ethLen) / llc, |
Christian Dickmann | e9b6d25 | 2012-10-08 22:56:50 -0700 | [diff] [blame] | 2476 | self.RESULT_ANY, |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2477 | ]], |
| 2478 | action.action_output(), match |
| 2479 | ) |
| 2480 | |
| 2481 | def testPacket(title, llc, is_snap_ip): |
| 2482 | testPacketTcpMatch(title, llc) |
| 2483 | testPacketEthSrcDstMatch(title, llc) |
| 2484 | testPacketEthSrcDstTypeMatch(title, llc, is_snap_ip) |
| 2485 | |
| 2486 | testPacket("LLC - No SNAP - No Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2487 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2488 | IS_NOT_SNAP_IP, |
| 2489 | ) |
| 2490 | testPacket("LLC - No SNAP - Small Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2491 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * 10), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2492 | IS_NOT_SNAP_IP, |
| 2493 | ) |
| 2494 | testPacket("LLC - No SNAP - Max -1 Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2495 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * (1500 - 3 - 1)), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2496 | IS_NOT_SNAP_IP, |
| 2497 | ) |
| 2498 | testPacket("LLC - No SNAP - Max Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2499 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * (1500 - 3)), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2500 | IS_NOT_SNAP_IP, |
| 2501 | ) |
| 2502 | testPacket("LLC - SNAP - Small bogus payload", |
| 2503 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2504 | scapy.SNAP(OUI=0x000000, code=0x800) / ("S" * 10), |
| 2505 | IS_SNAP_IP_CORRUPT, |
| 2506 | ) |
| 2507 | testPacket("LLC - SNAP - Max -1 bogus payload", |
| 2508 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2509 | scapy.SNAP(OUI=0x000000, code=0x3) / ("S" * (1500 - 3 - 5 - 1)), |
| 2510 | IS_NOT_SNAP_IP, |
| 2511 | ) |
| 2512 | testPacket("LLC - SNAP - Max bogus payload", |
| 2513 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2514 | scapy.SNAP(OUI=0x000000, code=0x3) / ("S" * (1500 - 3 - 5)), |
| 2515 | IS_NOT_SNAP_IP, |
| 2516 | ) |
| 2517 | testPacket("LLC - SNAP - IP - TCP", |
| 2518 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2519 | scapy.SNAP(OUI=0x000000, code=0x800)/ \ |
| 2520 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=6)/ \ |
| 2521 | scapy.TCP(sport=tcp_sport, dport=tcp_dport), |
| 2522 | IS_SNAP_IP, |
| 2523 | ) |
| 2524 | |
| 2525 | |
| 2526 | class DirectLlcPackets(DirectBadPacketBase): |
| 2527 | """ |
| 2528 | Verify LLC/SNAP parsing (valid and corrupted packets) and matching |
| 2529 | """ |
| 2530 | def runTest(self): |
| 2531 | dl_dst='00:01:02:03:04:05' |
| 2532 | dl_src='00:06:07:08:09:0a' |
| 2533 | ip_src='192.168.0.1' |
| 2534 | ip_dst='192.168.0.2' |
| 2535 | ip_tos=0 |
| 2536 | tcp_sport=1234 |
| 2537 | tcp_dport=80 |
| 2538 | |
| 2539 | # Test ethertype in face of LLC/SNAP and OFP_DL_TYPE_NOT_ETH_TYPE |
| 2540 | IS_SNAP_NOT_IP = 1 |
| 2541 | IS_SNAP_AND_IP = 2 |
| 2542 | IS_NOT_SNAP = 3 |
| 2543 | |
| 2544 | def testPacketEthTypeIP(title, llc, is_snap): |
| 2545 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src, type=0x800) |
| 2546 | match = packet_to_flow_match(self, match_pkt) |
| 2547 | self.assertTrue(match is not None, |
| 2548 | "Could not generate flow match from pkt") |
| 2549 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2550 | pkts = [] |
| 2551 | if is_snap == IS_NOT_SNAP or is_snap == IS_SNAP_NOT_IP: |
| 2552 | result = self.RESULT_NOMATCH |
| 2553 | else: |
| 2554 | result = self.RESULT_MATCH |
| 2555 | pkts.append([ |
| 2556 | "Ether type 0x800 match - %s" % title, |
| 2557 | scapy.Ether(dst=dl_dst, src=dl_src, type=len(llc)) / llc, |
| 2558 | result, |
| 2559 | ]) |
| 2560 | act = action.action_output() |
| 2561 | self.testPktsAgainstFlow(pkts, act, match) |
| 2562 | |
| 2563 | def testPacketEthTypeNotEth(title, llc, is_snap): |
| 2564 | match_pkt = scapy.Ether(dst = dl_dst, src = dl_src, |
| 2565 | type = ofp.OFP_DL_TYPE_NOT_ETH_TYPE) |
| 2566 | match = packet_to_flow_match(self, match_pkt) |
| 2567 | self.assertTrue(match is not None, |
| 2568 | "Could not generate flow match from pkt") |
| 2569 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2570 | pkts = [] |
| 2571 | if is_snap == IS_NOT_SNAP: |
| 2572 | result = self.RESULT_MATCH |
| 2573 | else: |
| 2574 | result = self.RESULT_NOMATCH |
| 2575 | pkts.append([ |
| 2576 | "Ether type OFP_DL_TYPE_NOT_ETH_TYPE match - %s" % title, |
| 2577 | scapy.Ether(dst=dl_dst, src=dl_src, type=len(llc)) / llc, |
| 2578 | result, |
| 2579 | ]) |
| 2580 | act = action.action_output() |
| 2581 | self.testPktsAgainstFlow(pkts, act, match) |
| 2582 | |
| 2583 | def testPacket(title, llc, is_snap): |
| 2584 | testPacketEthTypeIP(title, llc, is_snap) |
| 2585 | testPacketEthTypeNotEth(title, llc, is_snap) |
| 2586 | |
| 2587 | testPacket("LLC - No SNAP - No Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2588 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03), |
| 2589 | IS_NOT_SNAP, |
| 2590 | ) |
| 2591 | testPacket("LLC (with information field) - No SNAP - No Payload", |
| 2592 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x12) / "S", |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2593 | IS_NOT_SNAP, |
| 2594 | ) |
| 2595 | testPacket("LLC - No SNAP - Small Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2596 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * 10), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2597 | IS_NOT_SNAP, |
| 2598 | ) |
| 2599 | testPacket("LLC - No SNAP - Max -1 Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2600 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * (1500 - 3 - 1)), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2601 | IS_NOT_SNAP, |
| 2602 | ) |
| 2603 | testPacket("LLC - No SNAP - Max Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2604 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * (1500 - 3)), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2605 | IS_NOT_SNAP, |
| 2606 | ) |
| 2607 | testPacket("LLC - SNAP - Non-default OUI", |
| 2608 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2609 | scapy.SNAP(OUI=0x000001, code=0x800) / ("S" * 10), |
| 2610 | IS_NOT_SNAP, |
| 2611 | ) |
| 2612 | testPacket("LLC - SNAP - Default OUI", |
| 2613 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2614 | scapy.SNAP(OUI=0x000000, code=0x800) / ("S" * 10), |
| 2615 | IS_SNAP_AND_IP, |
| 2616 | ) |
| 2617 | testPacket("LLC - SNAP - Max -1 bogus payload", |
| 2618 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2619 | scapy.SNAP(OUI=0x000000, code=0x3) / ("S" * (1500 - 3 - 5 - 1)), |
| 2620 | IS_SNAP_NOT_IP, |
| 2621 | ) |
| 2622 | testPacket("LLC - SNAP - Max bogus payload", |
| 2623 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2624 | scapy.SNAP(OUI=0x000000, code=0x3) / ("S" * (1500 - 3 - 5)), |
| 2625 | IS_SNAP_NOT_IP, |
| 2626 | ) |
| 2627 | testPacket("LLC - SNAP - IP - TCP", |
| 2628 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2629 | scapy.SNAP(OUI=0x000000, code=0x800)/ \ |
| 2630 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=6)/ \ |
| 2631 | scapy.TCP(sport=tcp_sport, dport=tcp_dport), |
| 2632 | IS_SNAP_AND_IP, |
| 2633 | ) |
| 2634 | |
| 2635 | |
| 2636 | class DirectArpPackets(DirectBadPacketBase): |
| 2637 | """ |
| 2638 | Verify ARP parsing (valid and corrupted packets) and ARP matching |
| 2639 | """ |
| 2640 | def runTest(self): |
| 2641 | self.testArpHandling() |
| 2642 | |
| 2643 | def testArpHandling(self): |
| 2644 | dl_dst='00:01:02:03:04:05' |
| 2645 | dl_src='00:06:07:08:09:0a' |
| 2646 | ip_src='192.168.0.1' |
| 2647 | ip_dst='192.168.0.2' |
| 2648 | ip_src2='192.168.1.1' |
| 2649 | ip_dst2='192.168.1.2' |
| 2650 | ip_tos=0 |
| 2651 | tcp_sport=1234 |
| 2652 | tcp_dport=80 |
| 2653 | |
| 2654 | def testPacket(title, arp_match, arp_pkt, result): |
| 2655 | pkts = [] |
| 2656 | |
| 2657 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src) / arp_match |
| 2658 | match = packet_to_flow_match(self, match_pkt) |
| 2659 | self.assertTrue(match is not None, |
| 2660 | "Could not generate flow match from pkt") |
| 2661 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2662 | |
| 2663 | pkts.append([ |
| 2664 | title, |
| 2665 | scapy.Ether(dst=dl_dst, src=dl_src) / arp_pkt, |
| 2666 | result, |
| 2667 | ]) |
| 2668 | |
| 2669 | act = action.action_output() |
| 2670 | self.testPktsAgainstFlow(pkts, act, match) |
| 2671 | |
| 2672 | testPacket("Basic ARP", |
| 2673 | scapy.ARP(psrc=ip_src, pdst=ip_dst, op = 1), |
| 2674 | scapy.ARP(hwdst = '00:00:00:00:00:00', hwsrc = dl_src, |
| 2675 | psrc = ip_src, pdst = ip_dst, hwlen = 6, plen = 4, |
| 2676 | ptype = 0x800, hwtype = 1, op = 1), |
| 2677 | self.RESULT_MATCH |
| 2678 | ) |
| 2679 | # More stuff: |
| 2680 | # - Non matches on any property |
| 2681 | # - Corrupted hwlen and plen |
| 2682 | # - Other hwtype, ptype |
| 2683 | # - Truncated ARP pkt |
| 2684 | |
| 2685 | |
| 2686 | class DirectVlanPackets(DirectBadPacketBase): |
| 2687 | """ |
| 2688 | Verify VLAN parsing (valid and corrupted packets) and ARP matching |
| 2689 | """ |
| 2690 | def runTest(self): |
| 2691 | dl_dst='00:01:02:03:04:05' |
| 2692 | dl_src='00:06:07:08:09:0a' |
| 2693 | ip_src='192.168.0.1' |
| 2694 | ip_dst='192.168.0.2' |
| 2695 | ip_src2='192.168.1.1' |
| 2696 | ip_dst2='192.168.1.2' |
| 2697 | ip_tos=0 |
| 2698 | tcp_sport=1234 |
| 2699 | tcp_dport=80 |
| 2700 | |
| 2701 | def testPacket(title, match, pkt, result): |
| 2702 | pkts = [] |
| 2703 | |
| 2704 | self.assertTrue(match is not None, |
| 2705 | "Could not generate flow match from pkt") |
| 2706 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2707 | |
| 2708 | pkts.append([ |
| 2709 | "%s" % title, |
| 2710 | pkt, |
| 2711 | result, |
| 2712 | ]) |
| 2713 | |
| 2714 | act = action.action_output() |
| 2715 | self.testPktsAgainstFlow(pkts, act, match) |
| 2716 | |
| 2717 | testPacket("Basic MAC matching - IPv4 payload", |
| 2718 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src)), |
| 2719 | scapy.Ether(dst=dl_dst, src=dl_src, type=0x800) / scapy.IP(), |
| 2720 | self.RESULT_MATCH |
| 2721 | ) |
| 2722 | testPacket("Basic MAC matching - VMware beacon - no payload", |
| 2723 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src)), |
| 2724 | scapy.Ether(dst=dl_dst, src=dl_src, type=0x8922), |
| 2725 | self.RESULT_MATCH |
| 2726 | ) |
| 2727 | testPacket("Basic MAC matching - VMware beacon - with payload", |
| 2728 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src)), |
| 2729 | scapy.Ether(dst=dl_dst, src=dl_src, type=0x8922)/ ("X" * 1), |
| 2730 | self.RESULT_MATCH |
| 2731 | ) |
| 2732 | testPacket("Basic MAC matching - IPv6 payload", |
| 2733 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src)), |
| 2734 | scapy.Ether(dst=dl_dst, src=dl_src) / scapy.IPv6(), |
| 2735 | self.RESULT_MATCH |
| 2736 | ) |
| 2737 | testPacket("Basic MAC matching with VLAN tag present", |
| 2738 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src)), |
| 2739 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2740 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2741 | scapy.IP(), |
| 2742 | self.RESULT_MATCH |
| 2743 | ) |
| 2744 | testPacket("Basic MAC matching with VLAN tag present", |
| 2745 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2746 | dl_type=0x800), |
| 2747 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2748 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2749 | scapy.IP(), |
| 2750 | self.RESULT_MATCH |
| 2751 | ) |
| 2752 | testPacket("Ether matching with VLAN tag present - No type match", |
| 2753 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2754 | dl_type=0x801), |
| 2755 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2756 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2757 | scapy.IP(), |
| 2758 | self.RESULT_NOMATCH |
| 2759 | ) |
| 2760 | testPacket("Ether matching with VLAN tag present - No type match 0x8100", |
| 2761 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2762 | dl_type=0x8100), |
| 2763 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2764 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2765 | scapy.IP(), |
| 2766 | self.RESULT_NOMATCH |
| 2767 | ) |
| 2768 | testPacket("Ether matching with double VLAN tag - Wrong type match", |
| 2769 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2770 | dl_type=0x800), |
| 2771 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2772 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
| 2773 | scapy.Dot1Q(prio=3, vlan=1005)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2774 | scapy.IP(), |
| 2775 | self.RESULT_NOMATCH |
| 2776 | ) |
| 2777 | testPacket("Ether matching with double VLAN tag - Type match", |
| 2778 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2779 | dl_type=0x8100), |
| 2780 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2781 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
| 2782 | scapy.Dot1Q(prio=3, vlan=1005)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2783 | scapy.IP(), |
| 2784 | self.RESULT_MATCH |
| 2785 | ) |
| 2786 | testPacket("IP matching - VLAN tag", |
| 2787 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2788 | dl_type=0x0800, |
| 2789 | nw_src=parse_ip(ip_src), nw_dst=parse_ip(ip_dst)), |
| 2790 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2791 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2792 | scapy.IP(src=ip_src, dst=ip_dst), |
| 2793 | self.RESULT_MATCH |
| 2794 | ) |
| 2795 | # XXX: |
| 2796 | # - Matching on VLAN ID and Prio |
| 2797 | # - Actions |
| 2798 | |
| 2799 | |
| 2800 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 2801 | if __name__ == "__main__": |
| 2802 | print "Please run through oft script: ./oft --test_spec=basic" |