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