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 | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 119 | request = ofp.message.flow_mod() |
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 | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 183 | request = ofp.message.flow_mod() |
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 = [] |
| 226 | for qs in queue_stats.stats: |
| 227 | if qs.port_no != port_num: |
| 228 | continue |
| 229 | result.append(qs.queue_id) |
| 230 | return result |
| 231 | |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 232 | def handleFlow(self, pkttype='TCP'): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 233 | of_ports = config["port_map"].keys() |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 234 | of_ports.sort() |
| 235 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 236 | |
| 237 | if (pkttype == 'ICMP'): |
| 238 | pkt = simple_icmp_packet() |
| 239 | else: |
| 240 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 241 | match = packet_to_flow_match(self, pkt) |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 242 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 243 | self.assertTrue(match is not None, |
| 244 | "Could not generate flow match from pkt") |
| 245 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 246 | # Get queue stats from switch |
| 247 | |
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 | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 270 | request = ofp.message.flow_mod() |
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 | |
Ed Swierk | 22f5915 | 2012-04-17 16:36:47 -0700 | [diff] [blame] | 325 | self.assertEqual(qs_after.stats[0].tx_packets, \ |
| 326 | qs_before.stats[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 = [] |
| 348 | for qs in queue_stats.stats: |
| 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 | b8c845a | 2012-12-31 17:23:51 -0800 | [diff] [blame] | 375 | if queue_stats.header.type == ofp.OFPT_ERROR: |
| 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 | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 399 | request = ofp.message.flow_mod() |
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 | |
| 464 | self.assertEqual(qs_after.stats[0].tx_packets, \ |
| 465 | qs_before.stats[0].tx_packets + 1, \ |
| 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 | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 517 | request = ofp.message.flow_mod() |
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 | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 567 | request = ofp.message.flow_mod() |
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 | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 616 | request = ofp.message.flow_mod() |
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 | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 673 | request = ofp.message.flow_mod() |
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 | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 718 | request = ofp.message.flow_mod() |
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 | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 761 | request = ofp.message.flow_mod() |
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 | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 806 | request = ofp.message.flow_mod() |
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 | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 863 | request = ofp.message.flow_mod() |
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 | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 927 | flow_match_test(self, config["port_map"], dl_vlan=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 | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 937 | flow_match_test(self, config["port_map"], dl_vlan=vid, max_test=5) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 938 | for vid in range(100,4000,389): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 939 | flow_match_test(self, config["port_map"], dl_vlan=vid, max_test=5) |
| 940 | flow_match_test(self, config["port_map"], dl_vlan=4094, max_test=5) |
Tatsuya Yabe | cdf575e | 2010-05-25 16:56:38 -0700 | [diff] [blame] | 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): |
| 1025 | msg = self.flowMsgs[prio] |
| 1026 | msg.command = ofp.OFPFC_DELETE_STRICT |
| 1027 | # This *must* be set for DELETE |
| 1028 | msg.out_port = ofp.OFPP_NONE |
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 |
| 1164 | dl_vlan = vid |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1165 | else: |
| 1166 | dl_vlan = -1 |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1167 | flow_match_test(self, config["port_map"], wildcards=wc, |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1168 | dl_vlan=dl_vlan, 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 | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1178 | flow_match_test(self, config["port_map"], wildcards=wc, dl_vlan=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 |
| 1198 | dl_vlan = vid |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1199 | else: |
| 1200 | dl_vlan = -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, |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1202 | dl_vlan=dl_vlan) |
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, |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 1213 | dl_vlan=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, |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 1236 | dl_vlan=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, |
| 1254 | dl_vlan=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) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1284 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=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 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1308 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=old_vid) |
| 1309 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=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, |
| 1349 | dl_vlan_enable=True, dl_vlan=old_vid) |
| 1350 | exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1351 | dl_vlan=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 | |
| 1384 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=old_vlan_pcp) |
| 1385 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_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, |
| 1406 | dl_vlan=old_vid) |
| 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, |
| 1428 | dl_vlan=old_vid) |
| 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 = {} |
| 1444 | args["dl_src"] = '00:23:45:67:89:AB' |
| 1445 | |
| 1446 | dl_vlan_enable=False |
| 1447 | dl_vlan=-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 | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1450 | dl_vlan = 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 | |
| 1466 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'], |
| 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 | |
| 1481 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 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 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1601 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1602 | check_test_params=True) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1603 | flow_match_test(self, config["port_map"], pkt=pkt, exp_pkt=exp_pkt, |
Dan Talayco | 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 | |
| 1616 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 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 | |
| 1632 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 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 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1648 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'], |
| 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 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1664 | mod_fields = ['dl_dst', 'dl_src'] |
| 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 | |
| 1681 | mod_fields = ['dl_dst', 'dl_vlan'] |
| 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 = { |
| 1697 | "dl_dst" : ofp.OFPAT_SET_DL_DST, |
| 1698 | "dl_src" : ofp.OFPAT_SET_DL_SRC, |
| 1699 | "dl_vlan_enable" : ofp.OFPAT_SET_VLAN_VID, |
| 1700 | "dl_vlan" : ofp.OFPAT_SET_VLAN_VID, |
| 1701 | "dl_vlan_pcp" : ofp.OFPAT_SET_VLAN_PCP, |
| 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 | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 1761 | msg = ofp.message.flow_mod() |
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 |
Dan Talayco | f7c4131 | 2012-07-23 12:53:19 -0700 | [diff] [blame] | 1767 | msg.command = ofp.OFPFC_ADD |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 1768 | msg.actions.append(acts[toggle]) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1769 | flows[toggle].append(msg) |
Dan Talayco | 50be767 | 2012-04-05 11:38:08 -0700 | [diff] [blame] | 1770 | |
| 1771 | # Show two sample flows |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1772 | logging.debug(flows[0][0].show()) |
| 1773 | logging.debug(flows[1][0].show()) |
Dan Talayco | 50be767 | 2012-04-05 11:38:08 -0700 | [diff] [blame] | 1774 | |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1775 | # Install the first set of flows |
| 1776 | for f_idx in range(flow_count): |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 1777 | self.controller.message_send(flows[0][f_idx]) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 1778 | do_barrier(self.controller) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1779 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1780 | logging.info("Installed %d flows" % flow_count) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1781 | |
| 1782 | # Repeatedly modify all the flows back and forth |
| 1783 | updates = 0 |
| 1784 | # Report status about 5 times |
| 1785 | mod_val = (iter_count / 4) + 1 |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1786 | start = time.time() |
| 1787 | for iter_idx in range(iter_count): |
| 1788 | if not iter_idx % mod_val: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1789 | logging.info("Flow Toggle: iter %d of %d. " % |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1790 | (iter_idx, iter_count) + |
| 1791 | "%d updates in %d secs" % |
| 1792 | (updates, time.time() - start)) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1793 | for toggle in range(2): |
| 1794 | t_idx = 1 - toggle |
| 1795 | for f_idx in range(flow_count): |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 1796 | self.controller.message_send(flows[t_idx][f_idx]) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1797 | updates += 1 |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 1798 | do_barrier(self.controller) |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1799 | |
| 1800 | end = time.time() |
| 1801 | divisor = end - start or (end - start + 1) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1802 | logging.info("Flow toggle: %d iterations" % iter_count) |
| 1803 | logging.info(" %d flow mods in %d secs, %d mods/sec" % |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1804 | (updates, end - start, updates/divisor)) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1805 | |
| 1806 | |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1807 | # You can pick and choose these by commenting tests in or out |
| 1808 | iter_classes = [ |
| 1809 | basic.PacketIn, |
| 1810 | basic.PacketOut, |
| 1811 | DirectPacket, |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1812 | FlowToggle, |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1813 | DirectTwoPorts, |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1814 | DirectMCNonIngress, |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1815 | AllWildcardMatch, |
| 1816 | AllWildcardMatchTagged, |
| 1817 | SingleWildcardMatch, |
| 1818 | SingleWildcardMatchTagged, |
| 1819 | ExactMatch, |
| 1820 | ExactMatchTagged, |
| 1821 | SingleWildcardMatch, |
| 1822 | ModifyL2Src, |
| 1823 | ModifyL2Dst, |
| 1824 | ModifyL2SrcMC, |
| 1825 | ModifyL2DstMC, |
| 1826 | ModifyL2SrcDstMC |
| 1827 | ] |
| 1828 | |
Rich Lane | 0a4f637 | 2013-01-02 14:40:22 -0800 | [diff] [blame] | 1829 | @disabled |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1830 | class IterCases(BaseMatchCase): |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1831 | """ |
| 1832 | Iterate over a bunch of test cases |
| 1833 | |
| 1834 | The cases come from the list above |
| 1835 | """ |
| 1836 | |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1837 | def runTest(self): |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 1838 | count = test_param_get('iter_count', default=10) |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1839 | tests_done = 0 |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1840 | logging.info("Running iteration test " + str(count) + " times") |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1841 | start = time.time() |
| 1842 | last = start |
| 1843 | for idx in range(count): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1844 | logging.info("Iteration " + str(idx + 1)) |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1845 | for cls in iter_classes: |
| 1846 | test = cls() |
| 1847 | test.inheritSetup(self) |
| 1848 | test.runTest() |
| 1849 | tests_done += 1 |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1850 | # Report update about every minute, between tests |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1851 | if time.time() - last > 60: |
| 1852 | last = time.time() |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1853 | logging.info( |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1854 | "IterCases: Iter %d of %d; Ran %d tests in %d " % |
| 1855 | (idx, count, tests_done, last - start) + |
| 1856 | "seconds so far") |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1857 | stats = all_stats_get(self) |
| 1858 | last = time.time() |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1859 | logging.info("\nIterCases ran %d tests in %d seconds." % |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1860 | (tests_done, last - start)) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1861 | logging.info(" flows: %d. packets: %d. bytes: %d" % |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1862 | (stats["flows"], stats["packets"], stats["bytes"])) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1863 | logging.info(" active: %d. lookups: %d. matched %d." % |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1864 | (stats["active"], stats["lookups"], stats["matched"])) |
| 1865 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1866 | #@todo Need to implement tagged versions of the above tests |
| 1867 | # |
| 1868 | #@todo Implement a test case that strips tag 2, adds tag 3 |
| 1869 | # and modifies tag 4 to tag 5. Then verify (in addition) that |
| 1870 | # tag 6 does not get modified. |
| 1871 | |
Rich Lane | 0a4f637 | 2013-01-02 14:40:22 -0800 | [diff] [blame] | 1872 | @disabled |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1873 | class MixedVLAN(BaseMatchCase): |
| 1874 | """ |
| 1875 | Test mixture of VLAN tag actions |
| 1876 | |
| 1877 | Strip tag 2 on port 1, send to port 2 |
| 1878 | Add tag 3 on port 1, send to port 2 |
| 1879 | Modify tag 4 to 5 on port 1, send to port 2 |
| 1880 | All other traffic from port 1, send to port 3 |
| 1881 | All traffic from port 2 sent to port 4 |
| 1882 | Use exact matches with different packets for all mods |
| 1883 | Verify the following: (port, vid) |
| 1884 | (port 1, vid 2) => VLAN tag stripped, out port 2 |
| 1885 | (port 1, no tag) => tagged packet w/ vid 2 out port 2 |
| 1886 | (port 1, vid 4) => tagged packet w/ vid 5 out port 2 |
| 1887 | (port 1, vid 5) => tagged packet w/ vid 5 out port 2 |
| 1888 | (port 1, vid 6) => tagged packet w/ vid 6 out port 2 |
| 1889 | (port 2, no tag) => untagged packet out port 4 |
| 1890 | (port 2, vid 2-6) => unmodified packet out port 4 |
| 1891 | |
| 1892 | Variation: Might try sending VID 5 to port 3 and check. |
| 1893 | If only VID 5 distinguishes pkt, this will fail on some platforms |
| 1894 | """ |
| 1895 | |
Rich Lane | 97e9965 | 2013-01-02 17:23:20 -0800 | [diff] [blame] | 1896 | @group('smoke') |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 1897 | class MatchEach(base_tests.SimpleDataPlane): |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1898 | """ |
| 1899 | Check that each match field is actually matched on. |
| 1900 | Installs two flows that differ in one field. The flow that should not |
| 1901 | match has a higher priority, so if that field is ignored during matching |
| 1902 | the packet will be sent out the wrong port. |
| 1903 | |
| 1904 | TODO test UDP, ARP, ICMP, etc. |
| 1905 | """ |
| 1906 | def runTest(self): |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1907 | of_ports = config["port_map"].keys() |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1908 | of_ports.sort() |
| 1909 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 1910 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1911 | delete_all_flows(self.controller) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1912 | |
Ed Swierk | 7040a8d | 2012-12-11 16:30:13 -0800 | [diff] [blame] | 1913 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=2) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1914 | ingress_port = of_ports[0] |
| 1915 | egress_port = of_ports[1] |
| 1916 | |
| 1917 | def testField(field, mask): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1918 | logging.info("Testing field %s" % field) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1919 | |
| 1920 | def addFlow(matching, priority, output_port): |
| 1921 | match = packet_to_flow_match(self, pkt) |
| 1922 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 1923 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 1924 | match.in_port = ingress_port |
| 1925 | if not matching: |
| 1926 | # Make sure flow doesn't match |
| 1927 | orig = getattr(match, field) |
| 1928 | if isinstance(orig, list): |
| 1929 | new = map(lambda a: ~a[0] & a[1], zip(orig, mask)) |
| 1930 | else: |
| 1931 | new = ~orig & mask |
| 1932 | setattr(match, field, new) |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 1933 | request = ofp.message.flow_mod() |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1934 | request.match = match |
| 1935 | request.buffer_id = 0xffffffff |
| 1936 | request.priority = priority |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 1937 | act = ofp.action.output() |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1938 | act.port = output_port |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 1939 | request.actions.append(act) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1940 | logging.info("Inserting flow") |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1941 | self.controller.message_send(request) |
| 1942 | |
| 1943 | # This flow should match. |
| 1944 | addFlow(matching=True, priority=0, output_port=egress_port) |
| 1945 | # This flow should not match, but it has a higher priority. |
| 1946 | addFlow(matching=False, priority=1, output_port=ofp.OFPP_IN_PORT) |
| 1947 | |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 1948 | do_barrier(self.controller) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1949 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1950 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1951 | self.dataplane.send(ingress_port, str(pkt)) |
| 1952 | |
| 1953 | exp_pkt_arg = None |
| 1954 | exp_port = None |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 1955 | if config["relax"]: |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1956 | exp_pkt_arg = pkt |
| 1957 | exp_port = egress_port |
| 1958 | |
| 1959 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(port_number=exp_port, |
| 1960 | exp_pkt=exp_pkt_arg) |
| 1961 | self.assertTrue(rcv_pkt is not None, "Did not receive packet") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 1962 | 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] | 1963 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 1964 | self.assertEqual(str(pkt), str(rcv_pkt), 'Response packet does not match send packet') |
| 1965 | |
Ed Swierk | b603b19 | 2012-12-12 15:38:49 -0800 | [diff] [blame] | 1966 | wildcards = required_wildcards(self) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1967 | # TODO in_port |
Ed Swierk | b603b19 | 2012-12-12 15:38:49 -0800 | [diff] [blame] | 1968 | if not (wildcards & ofp.OFPFW_DL_SRC): |
| 1969 | testField("dl_src", [0xff]*6) |
| 1970 | if not (wildcards & ofp.OFPFW_DL_DST): |
| 1971 | testField("dl_dst", [0xff]*6) |
| 1972 | if not (wildcards & ofp.OFPFW_DL_TYPE): |
| 1973 | testField("dl_type", 0xffff) |
| 1974 | if not (wildcards & ofp.OFPFW_DL_VLAN): |
| 1975 | testField("dl_vlan", 0xfff) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1976 | # TODO dl_vlan_pcp |
Ed Swierk | b603b19 | 2012-12-12 15:38:49 -0800 | [diff] [blame] | 1977 | if not (wildcards & ofp.OFPFW_NW_SRC_ALL): |
| 1978 | testField("nw_src", 0xffffffff) |
| 1979 | if not (wildcards & ofp.OFPFW_NW_DST_ALL): |
| 1980 | testField("nw_dst", 0xffffffff) |
| 1981 | if not (wildcards & ofp.OFPFW_NW_TOS): |
| 1982 | testField("nw_tos", 0x3f) |
| 1983 | if not (wildcards & ofp.OFPFW_NW_PROTO): |
| 1984 | testField("nw_proto", 0xff) |
| 1985 | if not (wildcards & ofp.OFPFW_TP_SRC): |
| 1986 | testField("tp_src", 0xffff) |
| 1987 | if not (wildcards & ofp.OFPFW_TP_DST): |
| 1988 | testField("tp_dst", 0xffff) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1989 | |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 1990 | class DirectBadPacketBase(base_tests.SimpleDataPlane): |
| 1991 | """ |
| 1992 | Base class for sending single packets with single flow table entries. |
| 1993 | Used to verify matching of unusual packets and parsing/matching of |
| 1994 | corrupted packets. |
| 1995 | |
| 1996 | The idea is to generate packets that may either be totally malformed or |
| 1997 | malformed just enough to trick the flow matcher into making mistakes. |
| 1998 | |
| 1999 | Generate a 'bad' packet |
| 2000 | Generate and install a matching flow |
| 2001 | Add action to direct the packet to an egress port |
| 2002 | Send the packet to ingress dataplane port |
| 2003 | Verify the packet is received at the egress port only |
| 2004 | """ |
| 2005 | |
| 2006 | RESULT_MATCH = "MATCH" |
| 2007 | RESULT_NOMATCH = "NO MATCH" |
| 2008 | RESULT_ANY = "ANY MATCH" |
| 2009 | |
| 2010 | def runTest(self): |
| 2011 | pass |
| 2012 | # TODO: |
| 2013 | # - ICMP? |
| 2014 | # - VLAN? |
| 2015 | # - action |
| 2016 | |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2017 | def createMatch(self, **kwargs): |
| 2018 | match = ofp.ofp_match() |
| 2019 | match.wildcards = ofp.OFPFW_ALL |
| 2020 | fields = { |
| 2021 | 'dl_dst': ofp.OFPFW_DL_DST, |
| 2022 | 'dl_src': ofp.OFPFW_DL_SRC, |
| 2023 | 'dl_type': ofp.OFPFW_DL_TYPE, |
| 2024 | 'dl_vlan': ofp.OFPFW_DL_VLAN, |
| 2025 | 'nw_src': ofp.OFPFW_NW_SRC_MASK, |
| 2026 | 'nw_dst': ofp.OFPFW_NW_DST_MASK, |
| 2027 | 'nw_tos': ofp.OFPFW_NW_TOS, |
| 2028 | 'nw_proto': ofp.OFPFW_NW_PROTO, |
| 2029 | 'tp_src': ofp.OFPFW_TP_SRC, |
| 2030 | 'tp_dst': ofp.OFPFW_TP_DST, |
| 2031 | } |
| 2032 | for key in kwargs: |
| 2033 | setattr(match, key, kwargs[key]) |
| 2034 | match.wildcards &= ~fields[key] |
| 2035 | return match |
| 2036 | |
| 2037 | def testPktsAgainstFlow(self, pkts, acts, match): |
| 2038 | if type(acts) != list: |
| 2039 | acts = [acts] |
| 2040 | for info in pkts: |
| 2041 | title, pkt, expected_result = info |
| 2042 | self.testPktAgainstFlow(title, pkt, acts, match, expected_result) |
| 2043 | |
| 2044 | def testPktAgainstFlow(self, title, pkt, acts, match, expected_result): |
| 2045 | of_ports = config["port_map"].keys() |
| 2046 | of_ports.sort() |
| 2047 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 2048 | |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 2049 | delete_all_flows(self.controller) |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2050 | |
| 2051 | ingress_port = of_ports[0] |
| 2052 | egress_port = of_ports[1] |
| 2053 | |
| 2054 | logging.info("Testing packet '%s', expect result %s" % |
| 2055 | (title, expected_result)) |
| 2056 | logging.info("Ingress %s to egress %s" % |
| 2057 | (str(ingress_port), str(egress_port))) |
| 2058 | logging.info("Packet:") |
Rich Lane | 5d7e89a | 2012-10-26 16:43:13 -0700 | [diff] [blame] | 2059 | logging.info(inspect_packet(pkt)) |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2060 | |
| 2061 | match.in_port = ingress_port |
| 2062 | |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 2063 | request = ofp.message.flow_mod() |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2064 | request.match = match |
Rich Lane | 44cf12d | 2012-10-15 11:10:45 -0700 | [diff] [blame] | 2065 | request.priority = 1 |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2066 | |
| 2067 | request.buffer_id = 0xffffffff |
| 2068 | for act in acts: |
| 2069 | act.port = egress_port |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 2070 | request.actions.append(act) |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2071 | |
| 2072 | logging.info("Inserting flow") |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 2073 | self.controller.message_send(request) |
Rich Lane | 44cf12d | 2012-10-15 11:10:45 -0700 | [diff] [blame] | 2074 | |
| 2075 | # This flow speeds up negative tests |
| 2076 | logging.info("Inserting catch-all flow") |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 2077 | request2 = ofp.message.flow_mod() |
Rich Lane | 44cf12d | 2012-10-15 11:10:45 -0700 | [diff] [blame] | 2078 | request2.match = self.createMatch() |
Dan Talayco | 3bfc822 | 2013-02-13 18:18:57 -0800 | [diff] [blame] | 2079 | request2.match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2080 | request2.match.in_port = ingress_port |
| 2081 | |
Rich Lane | 44cf12d | 2012-10-15 11:10:45 -0700 | [diff] [blame] | 2082 | request2.priority = 0 |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 2083 | act = ofp.action.output() |
Rich Lane | 44cf12d | 2012-10-15 11:10:45 -0700 | [diff] [blame] | 2084 | act.port = ofp.OFPP_IN_PORT |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 2085 | request2.actions.append(act) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 2086 | self.controller.message_send(request2) |
Rich Lane | 44cf12d | 2012-10-15 11:10:45 -0700 | [diff] [blame] | 2087 | |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 2088 | do_barrier(self.controller) |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2089 | |
Dan Talayco | 3bfc822 | 2013-02-13 18:18:57 -0800 | [diff] [blame] | 2090 | pkt_str = str(pkt) |
| 2091 | if config["minsize"] > len(str(pkt)): |
| 2092 | pkt_str += '0' * (config["minsize"] - len(str(pkt))) |
| 2093 | |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2094 | logging.info("Sending packet to dp port " + |
| 2095 | str(ingress_port)) |
Dan Talayco | 3bfc822 | 2013-02-13 18:18:57 -0800 | [diff] [blame] | 2096 | self.dataplane.send(ingress_port, pkt_str) |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2097 | |
| 2098 | exp_pkt_arg = None |
| 2099 | exp_port = None |
| 2100 | if config["relax"]: |
| 2101 | exp_pkt_arg = pkt |
| 2102 | exp_port = egress_port |
| 2103 | |
Rich Lane | 44cf12d | 2012-10-15 11:10:45 -0700 | [diff] [blame] | 2104 | if expected_result == self.RESULT_MATCH: |
| 2105 | timeout = -1 # default timeout |
| 2106 | else: |
| 2107 | timeout = 1 # short timeout for negative tests |
| 2108 | |
| 2109 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(exp_pkt=exp_pkt_arg, |
| 2110 | timeout=timeout) |
| 2111 | if rcv_port == ingress_port: |
| 2112 | logging.debug("Packet matched catch-all flow") |
| 2113 | rcv_pkt = None |
| 2114 | |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2115 | if expected_result == self.RESULT_MATCH: |
| 2116 | self.assertTrue(rcv_pkt is not None, |
| 2117 | "Did not receive packet, expected a match") |
| 2118 | logging.debug("Packet len " + str(len(rcv_pkt)) + " in on " + |
| 2119 | str(rcv_port)) |
| 2120 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 2121 | str_pkt = str(pkt) |
| 2122 | str_rcv_pkt = str(rcv_pkt) |
| 2123 | str_rcv_pkt = str_rcv_pkt[0:len(str_pkt)] |
| 2124 | if str_pkt != str_rcv_pkt: |
| 2125 | logging.error("Response packet does not match send packet") |
| 2126 | logging.info("Response:") |
Rich Lane | 5d7e89a | 2012-10-26 16:43:13 -0700 | [diff] [blame] | 2127 | logging.info(inspect_packet(scapy.Ether(rcv_pkt))) |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2128 | self.assertEqual(str_pkt, str_rcv_pkt, |
| 2129 | 'Response packet does not match send packet') |
| 2130 | elif expected_result == self.RESULT_NOMATCH: |
| 2131 | self.assertTrue(rcv_pkt is None, "Received packet, expected drop") |
| 2132 | else: |
| 2133 | logging.debug("Match or drop accepted. Result = %s" % |
| 2134 | ("match" if rcv_pkt is not None else "drop")) |
| 2135 | |
| 2136 | |
| 2137 | class DirectBadIpTcpPacketsBase(DirectBadPacketBase): |
| 2138 | """ |
| 2139 | Base class for TCP and UDP parsing/matching verification under corruptions |
| 2140 | """ |
| 2141 | def runTest(self): |
| 2142 | pass |
| 2143 | |
| 2144 | def runTestWithProto(self, protoName = 'TCP'): |
| 2145 | dl_dst='00:01:02:03:04:05' |
| 2146 | dl_src='00:06:07:08:09:0a' |
| 2147 | ip_src='192.168.0.1' |
| 2148 | ip_dst='192.168.0.2' |
| 2149 | ip_tos=0 |
| 2150 | tcp_sport=1234 |
| 2151 | tcp_dport=80 |
| 2152 | |
| 2153 | # Generate a proper packet for constructing a match |
| 2154 | tp = None |
| 2155 | if protoName == 'TCP': |
| 2156 | tp = scapy.TCP |
| 2157 | proto = 6 |
| 2158 | elif protoName == 'UDP': |
| 2159 | tp = scapy.UDP |
| 2160 | proto = 17 |
| 2161 | else: |
| 2162 | raise Exception("Passed in unknown proto name") |
| 2163 | |
| 2164 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2165 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos)/ \ |
| 2166 | tp(sport=tcp_sport, dport=tcp_dport) |
| 2167 | match = packet_to_flow_match(self, match_pkt) |
| 2168 | self.assertTrue(match is not None, |
| 2169 | "Could not generate flow match from pkt") |
| 2170 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2171 | |
| 2172 | def testPacket(title, pkt, result): |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 2173 | act = ofp.action.output() |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2174 | pkts = [ |
| 2175 | [title, pkt, result] |
| 2176 | ] |
| 2177 | self.testPktsAgainstFlow(pkts, act, match) |
| 2178 | |
| 2179 | # Try incomplete IP headers |
| 2180 | testPacket("Incomplete IP header (1 bytes)", |
| 2181 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2182 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:1], |
| 2183 | self.RESULT_NOMATCH, |
| 2184 | ) |
| 2185 | testPacket("Incomplete IP header (2 bytes)", |
| 2186 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2187 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:2], |
| 2188 | self.RESULT_NOMATCH, |
| 2189 | ) |
| 2190 | testPacket("Incomplete IP header (3 bytes)", |
| 2191 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2192 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:3], |
| 2193 | self.RESULT_NOMATCH, |
| 2194 | ) |
| 2195 | testPacket("Incomplete IP header (12 bytes)", |
| 2196 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2197 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:12], |
| 2198 | self.RESULT_NOMATCH, |
| 2199 | ) |
| 2200 | testPacket("Incomplete IP header (16 bytes)", |
| 2201 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2202 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:16], |
| 2203 | self.RESULT_NOMATCH, |
| 2204 | ) |
| 2205 | testPacket("Incomplete IP header (19 bytes)", |
| 2206 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2207 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto))[0:19], |
| 2208 | self.RESULT_NOMATCH, |
| 2209 | ) |
| 2210 | |
| 2211 | # Try variations where the TCP header is missing or incomplete. As we |
| 2212 | # saw bugs before where buffers were reused and lengths weren't honored, |
| 2213 | # we initiatlize once with a non-matching full packet and once with a |
| 2214 | # matching full packet. |
| 2215 | testPacket("Non-Matching TCP packet, warming buffer", |
| 2216 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2217 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto)/ \ |
| 2218 | tp(sport=tcp_sport, dport=tcp_dport + 1), |
| 2219 | self.RESULT_NOMATCH, |
| 2220 | ) |
| 2221 | testPacket("Missing TCP header, buffer warmed with non-match", |
| 2222 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2223 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto), |
| 2224 | self.RESULT_NOMATCH, |
| 2225 | ) |
| 2226 | testPacket("Matching TCP packet, warming buffer", |
| 2227 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2228 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto)/ \ |
| 2229 | tp(sport=tcp_sport, dport=tcp_dport), |
| 2230 | self.RESULT_MATCH, |
| 2231 | ) |
| 2232 | testPacket("Missing TCP header, buffer warmed with match", |
| 2233 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2234 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto), |
| 2235 | self.RESULT_NOMATCH, |
| 2236 | ) |
| 2237 | testPacket("Truncated TCP header: 2 bytes", |
| 2238 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2239 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto)/ \ |
| 2240 | (str(tp(sport=tcp_sport, dport=tcp_dport))[0:2]), |
| 2241 | self.RESULT_NOMATCH, |
| 2242 | ) |
| 2243 | |
| 2244 | # Play with IP header length values that put the start of TCP either |
| 2245 | # inside the generated TCP header or beyond. In some cases it may even |
| 2246 | # be beyond the packet boundary. Also play with IP options and more |
| 2247 | # importantly IP total length corruptions. |
| 2248 | testPacket("TCP packet, corrupt ihl (0x6)", |
| 2249 | simple_tcp_packet(ip_ihl=6), |
| 2250 | self.RESULT_NOMATCH, |
| 2251 | ) |
| 2252 | testPacket("TCP packet, corrupt ihl (0xf)", |
| 2253 | simple_tcp_packet(ip_ihl=0xf), # ihl = 15 * 4 = 60 |
| 2254 | self.RESULT_NOMATCH, |
| 2255 | ) |
| 2256 | testPacket("TCP packet, corrupt ihl and total length", |
| 2257 | simple_tcp_packet(ip_ihl=0xf, pktlen=56), # ihl = 15 * 4 = 60, |
| 2258 | self.RESULT_NOMATCH, |
| 2259 | ) |
| 2260 | testPacket("Corrupt IPoption: First 4 bytes of matching TCP header", |
| 2261 | simple_tcp_packet( |
| 2262 | ip_options=scapy.IPOption('\x04\xd2\x00\x50'), |
| 2263 | tcp_dport=2, tcp_sport=2 |
| 2264 | ), |
| 2265 | self.RESULT_NOMATCH, |
| 2266 | ) |
| 2267 | testPacket("Missing TCP header, corrupt ihl", |
| 2268 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2269 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ihl=0xf, proto=proto), |
| 2270 | self.RESULT_NOMATCH, |
| 2271 | ) |
| 2272 | testPacket("Missing TCP header, corrupt total length", |
| 2273 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2274 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto, len= 100), |
| 2275 | self.RESULT_NOMATCH, |
| 2276 | ) |
| 2277 | testPacket("Missing TCP header, corrupt ihl and total length", |
| 2278 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2279 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ihl=0xf, proto=proto, len=43), |
| 2280 | self.RESULT_NOMATCH, |
| 2281 | ) |
| 2282 | testPacket("Incomplete IP header (12 bytes), corrupt ihl and total length", |
| 2283 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2284 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto, ihl=10, len=43))[0:12], |
| 2285 | self.RESULT_NOMATCH, |
| 2286 | ) |
| 2287 | testPacket("Incomplete IP header (16 bytes), corrupt ihl and total length", |
| 2288 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2289 | str(scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto, ihl=10, len=43))[0:16], |
| 2290 | self.RESULT_NOMATCH, |
| 2291 | ) |
| 2292 | |
| 2293 | # Try an incomplete TCP header that has enough bytes to carry source and |
| 2294 | # destination ports. As that is all we care about during matching, some |
| 2295 | # implementations may match and some may drop the packet |
| 2296 | testPacket("Incomplete TCP header: src/dst port present", |
| 2297 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2298 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=proto)/ \ |
| 2299 | (str(tp(sport=tcp_sport, dport=tcp_dport))[0:4]), |
| 2300 | self.RESULT_ANY, |
| 2301 | ) |
| 2302 | |
| 2303 | for i in range(1): |
| 2304 | for length in range(40 / 4): # IPv4 options are a maximum of 40 in length |
| 2305 | bytes = "".join([("%c" % random.randint(0, 255)) for x in range(length * 4)]) |
| 2306 | eth = scapy.Ether(dst=dl_dst, src=dl_src) |
| 2307 | ip = scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ihl=5 + length, proto=proto) |
| 2308 | tcp = tp(sport=tcp_sport, dport=tcp_dport+1) |
| 2309 | pkt = eth / ip |
| 2310 | pkt = pkt / bytes |
| 2311 | pkt = pkt / str(tcp) |
| 2312 | testPacket("Random IP options len = %d - TP match must fail" % length * 4, |
| 2313 | pkt, |
| 2314 | self.RESULT_NOMATCH |
| 2315 | ) |
| 2316 | |
| 2317 | eth = scapy.Ether(dst=dl_dst, src=dl_src) |
| 2318 | ip = scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, ihl=5 + length, proto=proto) |
| 2319 | tcp = tp(sport=tcp_sport, dport=tcp_dport) |
| 2320 | pkt = eth / ip |
| 2321 | pkt = pkt / bytes |
| 2322 | pkt = pkt / str(tcp) |
| 2323 | |
| 2324 | testPacket("Random IP options len = %d - May match", |
| 2325 | pkt, |
| 2326 | self.RESULT_ANY |
| 2327 | ) |
| 2328 | |
| 2329 | |
| 2330 | class DirectBadIpTcpPackets(DirectBadIpTcpPacketsBase): |
| 2331 | """ |
| 2332 | Verify IP/TCP parsing and matching. Focus on packet corruptions |
| 2333 | """ |
| 2334 | def runTest(self): |
| 2335 | self.runTestWithProto(protoName = 'TCP') |
| 2336 | |
| 2337 | class DirectBadIpUdpPackets(DirectBadIpTcpPacketsBase): |
| 2338 | """ |
| 2339 | Verify IP/UDP parsing and matching. Focus on packet corruptions |
| 2340 | """ |
| 2341 | def runTest(self): |
| 2342 | self.runTestWithProto(protoName = 'UDP') |
| 2343 | |
| 2344 | class DirectBadLlcPackets(DirectBadPacketBase): |
| 2345 | """ |
| 2346 | Verify LLC/SNAP parsing and matching. Focus on packet corruptions |
| 2347 | """ |
| 2348 | def runTest(self): |
| 2349 | dl_dst='00:01:02:03:04:05' |
| 2350 | dl_src='00:06:07:08:09:0a' |
| 2351 | ip_src='192.168.0.1' |
| 2352 | ip_dst='192.168.0.2' |
| 2353 | ip_tos=0 |
| 2354 | tcp_sport=1234 |
| 2355 | tcp_dport=80 |
| 2356 | |
| 2357 | IS_SNAP_IP = 1 |
| 2358 | IS_SNAP_IP_CORRUPT = 2 |
| 2359 | IS_NOT_SNAP_IP = 3 |
| 2360 | |
| 2361 | def testPacketTcpMatch(title, llc): |
| 2362 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2363 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos)/ \ |
| 2364 | scapy.TCP(sport=tcp_sport, dport=tcp_dport) |
| 2365 | match = packet_to_flow_match(self, match_pkt) |
| 2366 | self.assertTrue(match is not None, |
| 2367 | "Could not generate flow match from pkt") |
| 2368 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 2369 | act = ofp.action.output() |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2370 | |
| 2371 | self.testPktsAgainstFlow( |
| 2372 | [[ |
| 2373 | "TCP match - LLC frame correct length - %s" % title, |
| 2374 | scapy.Ether(dst=dl_dst, src=dl_src, type=len(llc)) / llc, |
| 2375 | self.RESULT_ANY, |
| 2376 | ]], |
| 2377 | act, match |
| 2378 | ) |
| 2379 | |
| 2380 | # Corrupt length field |
| 2381 | ethLen = random.randint(0, 1535) |
| 2382 | self.testPktsAgainstFlow( |
| 2383 | [[ |
| 2384 | "TCP match - LLC frame corrupted length - %s" % title, |
| 2385 | scapy.Ether(dst=dl_dst, src=dl_src, type=ethLen) / llc, |
| 2386 | self.RESULT_ANY, |
| 2387 | ]], |
| 2388 | act, match |
| 2389 | ) |
| 2390 | |
| 2391 | def testPacketEthSrcDstMatch(title, llc): |
| 2392 | # Matching based on Ethernet source and destination |
| 2393 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src) |
| 2394 | match = packet_to_flow_match(self, match_pkt) |
| 2395 | self.assertTrue(match is not None, |
| 2396 | "Could not generate flow match from pkt") |
| 2397 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2398 | match.wildcards |= ofp.OFPFW_DL_TYPE |
| 2399 | self.testPktsAgainstFlow( |
| 2400 | [[ |
| 2401 | "Eth addr match - LLC frame correct length- %s" % title, |
| 2402 | scapy.Ether(dst=dl_dst, src=dl_src, type=len(llc)) / llc, |
| 2403 | self.RESULT_MATCH, |
| 2404 | ]], |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 2405 | ofp.action.output(), match |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2406 | ) |
| 2407 | |
| 2408 | # Corrupt length field |
| 2409 | ethLen = random.randint(0, 1535) |
| 2410 | self.testPktsAgainstFlow( |
| 2411 | [[ |
| 2412 | "Eth addr match - LLC frame corrupted length- %s" % title, |
| 2413 | scapy.Ether(dst=dl_dst, src=dl_src, type=ethLen) / llc, |
| 2414 | self.RESULT_ANY, |
| 2415 | ]], |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 2416 | ofp.action.output(), match |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2417 | ) |
| 2418 | |
| 2419 | def testPacketEthSrcDstTypeMatch(title, llc, is_snap_ip): |
| 2420 | # Matching based on Ethernet source, destination and type |
| 2421 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src, type=0x800) |
| 2422 | match = packet_to_flow_match(self, match_pkt) |
| 2423 | self.assertTrue(match is not None, |
| 2424 | "Could not generate flow match from pkt") |
| 2425 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2426 | if is_snap_ip == IS_SNAP_IP: |
| 2427 | is_match = self.RESULT_MATCH |
| 2428 | elif is_snap_ip == IS_SNAP_IP_CORRUPT: |
| 2429 | is_match = self.RESULT_ANY |
| 2430 | else: |
| 2431 | is_match = self.RESULT_NOMATCH |
| 2432 | self.testPktsAgainstFlow( |
| 2433 | [[ |
| 2434 | "Eth addr+type match - LLC frame correct length - %s" % title, |
| 2435 | scapy.Ether(dst=dl_dst, src=dl_src, type=len(llc)) / llc, |
| 2436 | is_match, |
| 2437 | ]], |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 2438 | ofp.action.output(), match |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2439 | ) |
| 2440 | |
| 2441 | # Corrupt length field |
| 2442 | ethLen = random.randint(0, 1535) |
| 2443 | self.testPktsAgainstFlow( |
| 2444 | [[ |
| 2445 | "Eth addr+type match - LLC frame corrupted length - %s" % title, |
| 2446 | scapy.Ether(dst=dl_dst, src=dl_src, type=ethLen) / llc, |
Christian Dickmann | e9b6d25 | 2012-10-08 22:56:50 -0700 | [diff] [blame] | 2447 | self.RESULT_ANY, |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2448 | ]], |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 2449 | ofp.action.output(), match |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2450 | ) |
| 2451 | |
| 2452 | def testPacket(title, llc, is_snap_ip): |
| 2453 | testPacketTcpMatch(title, llc) |
| 2454 | testPacketEthSrcDstMatch(title, llc) |
| 2455 | testPacketEthSrcDstTypeMatch(title, llc, is_snap_ip) |
| 2456 | |
| 2457 | testPacket("LLC - No SNAP - No Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2458 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2459 | IS_NOT_SNAP_IP, |
| 2460 | ) |
| 2461 | testPacket("LLC - No SNAP - Small Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2462 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * 10), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2463 | IS_NOT_SNAP_IP, |
| 2464 | ) |
| 2465 | testPacket("LLC - No SNAP - Max -1 Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2466 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * (1500 - 3 - 1)), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2467 | IS_NOT_SNAP_IP, |
| 2468 | ) |
| 2469 | testPacket("LLC - No SNAP - Max Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2470 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * (1500 - 3)), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2471 | IS_NOT_SNAP_IP, |
| 2472 | ) |
| 2473 | testPacket("LLC - SNAP - Small bogus payload", |
| 2474 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2475 | scapy.SNAP(OUI=0x000000, code=0x800) / ("S" * 10), |
| 2476 | IS_SNAP_IP_CORRUPT, |
| 2477 | ) |
| 2478 | testPacket("LLC - SNAP - Max -1 bogus payload", |
| 2479 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2480 | scapy.SNAP(OUI=0x000000, code=0x3) / ("S" * (1500 - 3 - 5 - 1)), |
| 2481 | IS_NOT_SNAP_IP, |
| 2482 | ) |
| 2483 | testPacket("LLC - SNAP - Max bogus payload", |
| 2484 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2485 | scapy.SNAP(OUI=0x000000, code=0x3) / ("S" * (1500 - 3 - 5)), |
| 2486 | IS_NOT_SNAP_IP, |
| 2487 | ) |
| 2488 | testPacket("LLC - SNAP - IP - TCP", |
| 2489 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2490 | scapy.SNAP(OUI=0x000000, code=0x800)/ \ |
| 2491 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=6)/ \ |
| 2492 | scapy.TCP(sport=tcp_sport, dport=tcp_dport), |
| 2493 | IS_SNAP_IP, |
| 2494 | ) |
| 2495 | |
| 2496 | |
| 2497 | class DirectLlcPackets(DirectBadPacketBase): |
| 2498 | """ |
| 2499 | Verify LLC/SNAP parsing (valid and corrupted packets) and matching |
| 2500 | """ |
| 2501 | def runTest(self): |
| 2502 | dl_dst='00:01:02:03:04:05' |
| 2503 | dl_src='00:06:07:08:09:0a' |
| 2504 | ip_src='192.168.0.1' |
| 2505 | ip_dst='192.168.0.2' |
| 2506 | ip_tos=0 |
| 2507 | tcp_sport=1234 |
| 2508 | tcp_dport=80 |
| 2509 | |
| 2510 | # Test ethertype in face of LLC/SNAP and OFP_DL_TYPE_NOT_ETH_TYPE |
| 2511 | IS_SNAP_NOT_IP = 1 |
| 2512 | IS_SNAP_AND_IP = 2 |
| 2513 | IS_NOT_SNAP = 3 |
| 2514 | |
| 2515 | def testPacketEthTypeIP(title, llc, is_snap): |
| 2516 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src, type=0x800) |
| 2517 | match = packet_to_flow_match(self, match_pkt) |
| 2518 | self.assertTrue(match is not None, |
| 2519 | "Could not generate flow match from pkt") |
| 2520 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2521 | pkts = [] |
| 2522 | if is_snap == IS_NOT_SNAP or is_snap == IS_SNAP_NOT_IP: |
| 2523 | result = self.RESULT_NOMATCH |
| 2524 | else: |
| 2525 | result = self.RESULT_MATCH |
| 2526 | pkts.append([ |
| 2527 | "Ether type 0x800 match - %s" % title, |
| 2528 | scapy.Ether(dst=dl_dst, src=dl_src, type=len(llc)) / llc, |
| 2529 | result, |
| 2530 | ]) |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 2531 | act = ofp.action.output() |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2532 | self.testPktsAgainstFlow(pkts, act, match) |
| 2533 | |
| 2534 | def testPacketEthTypeNotEth(title, llc, is_snap): |
| 2535 | match_pkt = scapy.Ether(dst = dl_dst, src = dl_src, |
| 2536 | type = ofp.OFP_DL_TYPE_NOT_ETH_TYPE) |
| 2537 | match = packet_to_flow_match(self, match_pkt) |
| 2538 | self.assertTrue(match is not None, |
| 2539 | "Could not generate flow match from pkt") |
| 2540 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2541 | pkts = [] |
| 2542 | if is_snap == IS_NOT_SNAP: |
| 2543 | result = self.RESULT_MATCH |
| 2544 | else: |
| 2545 | result = self.RESULT_NOMATCH |
| 2546 | pkts.append([ |
| 2547 | "Ether type OFP_DL_TYPE_NOT_ETH_TYPE match - %s" % title, |
| 2548 | scapy.Ether(dst=dl_dst, src=dl_src, type=len(llc)) / llc, |
| 2549 | result, |
| 2550 | ]) |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 2551 | act = ofp.action.output() |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2552 | self.testPktsAgainstFlow(pkts, act, match) |
| 2553 | |
| 2554 | def testPacket(title, llc, is_snap): |
| 2555 | testPacketEthTypeIP(title, llc, is_snap) |
| 2556 | testPacketEthTypeNotEth(title, llc, is_snap) |
| 2557 | |
| 2558 | testPacket("LLC - No SNAP - No Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2559 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03), |
| 2560 | IS_NOT_SNAP, |
| 2561 | ) |
| 2562 | testPacket("LLC (with information field) - No SNAP - No Payload", |
| 2563 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x12) / "S", |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2564 | IS_NOT_SNAP, |
| 2565 | ) |
| 2566 | testPacket("LLC - No SNAP - Small Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2567 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * 10), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2568 | IS_NOT_SNAP, |
| 2569 | ) |
| 2570 | testPacket("LLC - No SNAP - Max -1 Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2571 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * (1500 - 3 - 1)), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2572 | IS_NOT_SNAP, |
| 2573 | ) |
| 2574 | testPacket("LLC - No SNAP - Max Payload", |
Rich Lane | 6508ea0 | 2012-10-12 15:27:11 -0700 | [diff] [blame] | 2575 | scapy.LLC(dsap=0x33, ssap=0x44, ctrl=0x03) / ("S" * (1500 - 3)), |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2576 | IS_NOT_SNAP, |
| 2577 | ) |
| 2578 | testPacket("LLC - SNAP - Non-default OUI", |
| 2579 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2580 | scapy.SNAP(OUI=0x000001, code=0x800) / ("S" * 10), |
| 2581 | IS_NOT_SNAP, |
| 2582 | ) |
| 2583 | testPacket("LLC - SNAP - Default OUI", |
| 2584 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2585 | scapy.SNAP(OUI=0x000000, code=0x800) / ("S" * 10), |
| 2586 | IS_SNAP_AND_IP, |
| 2587 | ) |
| 2588 | testPacket("LLC - SNAP - Max -1 bogus payload", |
| 2589 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2590 | scapy.SNAP(OUI=0x000000, code=0x3) / ("S" * (1500 - 3 - 5 - 1)), |
| 2591 | IS_SNAP_NOT_IP, |
| 2592 | ) |
| 2593 | testPacket("LLC - SNAP - Max bogus payload", |
| 2594 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2595 | scapy.SNAP(OUI=0x000000, code=0x3) / ("S" * (1500 - 3 - 5)), |
| 2596 | IS_SNAP_NOT_IP, |
| 2597 | ) |
| 2598 | testPacket("LLC - SNAP - IP - TCP", |
| 2599 | scapy.LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03)/ \ |
| 2600 | scapy.SNAP(OUI=0x000000, code=0x800)/ \ |
| 2601 | scapy.IP(src=ip_src, dst=ip_dst, tos=ip_tos, proto=6)/ \ |
| 2602 | scapy.TCP(sport=tcp_sport, dport=tcp_dport), |
| 2603 | IS_SNAP_AND_IP, |
| 2604 | ) |
| 2605 | |
| 2606 | |
| 2607 | class DirectArpPackets(DirectBadPacketBase): |
| 2608 | """ |
| 2609 | Verify ARP parsing (valid and corrupted packets) and ARP matching |
| 2610 | """ |
| 2611 | def runTest(self): |
| 2612 | self.testArpHandling() |
| 2613 | |
| 2614 | def testArpHandling(self): |
| 2615 | dl_dst='00:01:02:03:04:05' |
| 2616 | dl_src='00:06:07:08:09:0a' |
| 2617 | ip_src='192.168.0.1' |
| 2618 | ip_dst='192.168.0.2' |
| 2619 | ip_src2='192.168.1.1' |
| 2620 | ip_dst2='192.168.1.2' |
| 2621 | ip_tos=0 |
| 2622 | tcp_sport=1234 |
| 2623 | tcp_dport=80 |
| 2624 | |
| 2625 | def testPacket(title, arp_match, arp_pkt, result): |
| 2626 | pkts = [] |
| 2627 | |
| 2628 | match_pkt = scapy.Ether(dst=dl_dst, src=dl_src) / arp_match |
| 2629 | match = packet_to_flow_match(self, match_pkt) |
| 2630 | self.assertTrue(match is not None, |
| 2631 | "Could not generate flow match from pkt") |
| 2632 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2633 | |
| 2634 | pkts.append([ |
| 2635 | title, |
| 2636 | scapy.Ether(dst=dl_dst, src=dl_src) / arp_pkt, |
| 2637 | result, |
| 2638 | ]) |
| 2639 | |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 2640 | act = ofp.action.output() |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2641 | self.testPktsAgainstFlow(pkts, act, match) |
| 2642 | |
| 2643 | testPacket("Basic ARP", |
| 2644 | scapy.ARP(psrc=ip_src, pdst=ip_dst, op = 1), |
| 2645 | scapy.ARP(hwdst = '00:00:00:00:00:00', hwsrc = dl_src, |
| 2646 | psrc = ip_src, pdst = ip_dst, hwlen = 6, plen = 4, |
| 2647 | ptype = 0x800, hwtype = 1, op = 1), |
| 2648 | self.RESULT_MATCH |
| 2649 | ) |
| 2650 | # More stuff: |
| 2651 | # - Non matches on any property |
| 2652 | # - Corrupted hwlen and plen |
| 2653 | # - Other hwtype, ptype |
| 2654 | # - Truncated ARP pkt |
| 2655 | |
| 2656 | |
| 2657 | class DirectVlanPackets(DirectBadPacketBase): |
| 2658 | """ |
| 2659 | Verify VLAN parsing (valid and corrupted packets) and ARP matching |
| 2660 | """ |
| 2661 | def runTest(self): |
| 2662 | dl_dst='00:01:02:03:04:05' |
| 2663 | dl_src='00:06:07:08:09:0a' |
| 2664 | ip_src='192.168.0.1' |
| 2665 | ip_dst='192.168.0.2' |
| 2666 | ip_src2='192.168.1.1' |
| 2667 | ip_dst2='192.168.1.2' |
| 2668 | ip_tos=0 |
| 2669 | tcp_sport=1234 |
| 2670 | tcp_dport=80 |
| 2671 | |
| 2672 | def testPacket(title, match, pkt, result): |
| 2673 | pkts = [] |
| 2674 | |
| 2675 | self.assertTrue(match is not None, |
| 2676 | "Could not generate flow match from pkt") |
| 2677 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2678 | |
| 2679 | pkts.append([ |
| 2680 | "%s" % title, |
| 2681 | pkt, |
| 2682 | result, |
| 2683 | ]) |
| 2684 | |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 2685 | act = ofp.action.output() |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2686 | self.testPktsAgainstFlow(pkts, act, match) |
| 2687 | |
| 2688 | testPacket("Basic MAC matching - IPv4 payload", |
| 2689 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src)), |
| 2690 | scapy.Ether(dst=dl_dst, src=dl_src, type=0x800) / scapy.IP(), |
| 2691 | self.RESULT_MATCH |
| 2692 | ) |
| 2693 | testPacket("Basic MAC matching - VMware beacon - no payload", |
| 2694 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src)), |
| 2695 | scapy.Ether(dst=dl_dst, src=dl_src, type=0x8922), |
| 2696 | self.RESULT_MATCH |
| 2697 | ) |
| 2698 | testPacket("Basic MAC matching - VMware beacon - with payload", |
| 2699 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src)), |
| 2700 | scapy.Ether(dst=dl_dst, src=dl_src, type=0x8922)/ ("X" * 1), |
| 2701 | self.RESULT_MATCH |
| 2702 | ) |
| 2703 | testPacket("Basic MAC matching - IPv6 payload", |
| 2704 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src)), |
| 2705 | scapy.Ether(dst=dl_dst, src=dl_src) / scapy.IPv6(), |
| 2706 | self.RESULT_MATCH |
| 2707 | ) |
| 2708 | testPacket("Basic MAC matching with VLAN tag present", |
| 2709 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src)), |
| 2710 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2711 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2712 | scapy.IP(), |
| 2713 | self.RESULT_MATCH |
| 2714 | ) |
| 2715 | testPacket("Basic MAC matching with VLAN tag present", |
| 2716 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2717 | dl_type=0x800), |
| 2718 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2719 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2720 | scapy.IP(), |
| 2721 | self.RESULT_MATCH |
| 2722 | ) |
| 2723 | testPacket("Ether matching with VLAN tag present - No type match", |
| 2724 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2725 | dl_type=0x801), |
| 2726 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2727 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2728 | scapy.IP(), |
| 2729 | self.RESULT_NOMATCH |
| 2730 | ) |
| 2731 | testPacket("Ether matching with VLAN tag present - No type match 0x8100", |
| 2732 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2733 | dl_type=0x8100), |
| 2734 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2735 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2736 | scapy.IP(), |
| 2737 | self.RESULT_NOMATCH |
| 2738 | ) |
Dan Talayco | a3bf965 | 2013-02-19 23:40:50 -0800 | [diff] [blame] | 2739 | testPacket("IP matching - VLAN tag", |
| 2740 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2741 | dl_type=0x0800, |
| 2742 | nw_src=parse_ip(ip_src), nw_dst=parse_ip(ip_dst)), |
| 2743 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
| 2744 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
| 2745 | scapy.IP(src=ip_src, dst=ip_dst), |
| 2746 | self.RESULT_MATCH |
| 2747 | ) |
| 2748 | # XXX: |
| 2749 | # - Matching on VLAN ID and Prio |
| 2750 | # - Actions |
| 2751 | |
| 2752 | @nonstandard |
| 2753 | class DirectVlanPacketsDoubleTagged(DirectVlanPackets): |
| 2754 | """ |
| 2755 | VLAN parsing for double tagged packets. Spec is ambiguous about |
| 2756 | the treatment of these cases, so broken out to be non-standard |
| 2757 | """ |
| 2758 | def runTest(self): |
| 2759 | dl_dst='00:01:02:03:04:05' |
| 2760 | dl_src='00:06:07:08:09:0a' |
| 2761 | ip_src='192.168.0.1' |
| 2762 | ip_dst='192.168.0.2' |
| 2763 | ip_src2='192.168.1.1' |
| 2764 | ip_dst2='192.168.1.2' |
| 2765 | ip_tos=0 |
| 2766 | tcp_sport=1234 |
| 2767 | tcp_dport=80 |
| 2768 | |
| 2769 | def testPacket(title, match, pkt, result): |
| 2770 | pkts = [] |
| 2771 | |
| 2772 | self.assertTrue(match is not None, |
| 2773 | "Could not generate flow match from pkt") |
| 2774 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 2775 | |
| 2776 | pkts.append([ |
| 2777 | "%s" % title, |
| 2778 | pkt, |
| 2779 | result, |
| 2780 | ]) |
| 2781 | |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 2782 | act = ofp.action.output() |
Dan Talayco | a3bf965 | 2013-02-19 23:40:50 -0800 | [diff] [blame] | 2783 | self.testPktsAgainstFlow(pkts, act, match) |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2784 | testPacket("Ether matching with double VLAN tag - Wrong type match", |
| 2785 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2786 | dl_type=0x800), |
| 2787 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2788 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
| 2789 | scapy.Dot1Q(prio=3, vlan=1005)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2790 | scapy.IP(), |
| 2791 | self.RESULT_NOMATCH |
| 2792 | ) |
| 2793 | testPacket("Ether matching with double VLAN tag - Type match", |
| 2794 | self.createMatch(dl_dst=parse_mac(dl_dst), dl_src=parse_mac(dl_src), |
| 2795 | dl_type=0x8100), |
| 2796 | scapy.Ether(dst=dl_dst, src=dl_src)/ \ |
Christian Dickmann | 8ac5525 | 2012-10-08 22:53:49 -0700 | [diff] [blame] | 2797 | scapy.Dot1Q(prio=5, vlan=1000)/ \ |
| 2798 | scapy.Dot1Q(prio=3, vlan=1005)/ \ |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2799 | scapy.IP(), |
| 2800 | self.RESULT_MATCH |
| 2801 | ) |
Christian Dickmann | 8b59b4b | 2012-09-23 16:48:30 -0700 | [diff] [blame] | 2802 | |
| 2803 | |
| 2804 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 2805 | if __name__ == "__main__": |
| 2806 | print "Please run through oft script: ./oft --test_spec=basic" |