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