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