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