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 | |
| 10 | The function test_set_init is called with a complete configuration |
| 11 | dictionary prior to the invocation of any tests from this file. |
| 12 | |
| 13 | The switch is actively attempting to contact the controller at the address |
| 14 | indicated oin oft_config |
| 15 | |
| 16 | """ |
| 17 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 18 | import copy |
| 19 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 20 | import logging |
| 21 | |
| 22 | import unittest |
| 23 | |
| 24 | import oftest.controller as controller |
| 25 | import oftest.cstruct as ofp |
| 26 | import oftest.message as message |
| 27 | import oftest.dataplane as dataplane |
| 28 | import oftest.action as action |
| 29 | import oftest.parse as parse |
| 30 | import basic |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 31 | import time |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 32 | |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 33 | from oftest.testutils import * |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 34 | |
| 35 | #@var port_map Local copy of the configuration map from OF port |
| 36 | # numbers to OS interfaces |
| 37 | pa_port_map = None |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 38 | #@var pa_config Local copy of global configuration data |
| 39 | pa_config = None |
| 40 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 41 | # For test priority |
| 42 | #@var test_prio Set test priority for local tests |
| 43 | test_prio = {} |
| 44 | |
| 45 | WILDCARD_VALUES = [ofp.OFPFW_IN_PORT, |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 46 | ofp.OFPFW_DL_VLAN | ofp.OFPFW_DL_VLAN_PCP, |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 47 | ofp.OFPFW_DL_SRC, |
| 48 | ofp.OFPFW_DL_DST, |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 49 | (ofp.OFPFW_DL_TYPE | ofp.OFPFW_NW_SRC_ALL | |
| 50 | ofp.OFPFW_NW_DST_ALL | ofp.OFPFW_NW_TOS | ofp.OFPFW_NW_PROTO | |
| 51 | ofp.OFPFW_TP_SRC | ofp.OFPFW_TP_DST), |
| 52 | (ofp.OFPFW_NW_PROTO | ofp.OFPFW_TP_SRC | ofp.OFPFW_TP_DST), |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 53 | ofp.OFPFW_TP_SRC, |
| 54 | ofp.OFPFW_TP_DST, |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 55 | ofp.OFPFW_NW_SRC_MASK, |
| 56 | ofp.OFPFW_NW_DST_MASK, |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 57 | ofp.OFPFW_DL_VLAN_PCP, |
| 58 | ofp.OFPFW_NW_TOS] |
| 59 | |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 60 | NO_WILDCARD_VALUES = [(ofp.OFPFW_ALL ^ ofp.OFPFW_IN_PORT), |
| 61 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_VLAN), |
| 62 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_SRC), |
| 63 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_DST), |
| 64 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE), |
| 65 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO), |
| 66 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO ^ |
| 67 | ofp.OFPFW_TP_SRC), |
| 68 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO ^ |
| 69 | ofp.OFPFW_TP_DST), |
| 70 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO ^ |
| 71 | ofp.OFPFW_NW_SRC_MASK), |
| 72 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO ^ |
| 73 | ofp.OFPFW_NW_DST_MASK), |
| 74 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_VLAN ^ ofp.OFPFW_DL_VLAN_PCP), |
| 75 | (ofp.OFPFW_ALL ^ ofp.OFPFW_DL_TYPE ^ ofp.OFPFW_NW_PROTO ^ |
| 76 | ofp.OFPFW_NW_TOS)] |
| 77 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 78 | MODIFY_ACTION_VALUES = [ofp.OFPAT_SET_VLAN_VID, |
| 79 | ofp.OFPAT_SET_VLAN_PCP, |
| 80 | ofp.OFPAT_STRIP_VLAN, |
| 81 | ofp.OFPAT_SET_DL_SRC, |
| 82 | ofp.OFPAT_SET_DL_DST, |
| 83 | ofp.OFPAT_SET_NW_SRC, |
| 84 | ofp.OFPAT_SET_NW_DST, |
| 85 | ofp.OFPAT_SET_NW_TOS, |
| 86 | ofp.OFPAT_SET_TP_SRC, |
| 87 | ofp.OFPAT_SET_TP_DST] |
| 88 | |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 89 | TEST_VID_DEFAULT = 2 |
| 90 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 91 | def test_set_init(config): |
| 92 | """ |
| 93 | Set up function for packet action test classes |
| 94 | |
| 95 | @param config The configuration dictionary; see oft |
| 96 | """ |
| 97 | |
Ed Swierk | 89f7835 | 2012-03-29 12:32:32 -0700 | [diff] [blame] | 98 | basic.test_set_init(config) |
| 99 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 100 | global pa_port_map |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 101 | global pa_config |
| 102 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 103 | pa_port_map = config["port_map"] |
| 104 | pa_config = config |
| 105 | |
| 106 | class DirectPacket(basic.SimpleDataPlane): |
| 107 | """ |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 108 | Send packet to single egress port |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 109 | |
| 110 | Generate a packet |
| 111 | Generate and install a matching flow |
| 112 | Add action to direct the packet to an egress port |
| 113 | Send the packet to ingress dataplane port |
| 114 | Verify the packet is received at the egress port only |
| 115 | """ |
| 116 | def runTest(self): |
Tatsuya Yabe | b8fb3c3 | 2010-06-14 15:48:36 -0700 | [diff] [blame] | 117 | self.handleFlow() |
| 118 | |
| 119 | def handleFlow(self, pkttype='TCP'): |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 120 | of_ports = pa_port_map.keys() |
| 121 | of_ports.sort() |
| 122 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 123 | |
Tatsuya Yabe | b8fb3c3 | 2010-06-14 15:48:36 -0700 | [diff] [blame] | 124 | if (pkttype == 'ICMP'): |
| 125 | pkt = simple_icmp_packet() |
| 126 | else: |
| 127 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 128 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 7dd6cd6 | 2010-03-16 15:02:35 -0700 | [diff] [blame] | 129 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 130 | self.assertTrue(match is not None, |
| 131 | "Could not generate flow match from pkt") |
| 132 | act = action.action_output() |
| 133 | |
| 134 | for idx in range(len(of_ports)): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 135 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 136 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 137 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 138 | ingress_port = of_ports[idx] |
| 139 | egress_port = of_ports[(idx + 1) % len(of_ports)] |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 140 | logging.info("Ingress " + str(ingress_port) + |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 141 | " to egress " + str(egress_port)) |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 142 | |
| 143 | match.in_port = ingress_port |
| 144 | |
| 145 | request = message.flow_mod() |
| 146 | request.match = match |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 147 | |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 148 | request.buffer_id = 0xffffffff |
| 149 | act.port = egress_port |
| 150 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 151 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 152 | logging.info("Inserting flow") |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 153 | rv = self.controller.message_send(request) |
| 154 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 155 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 156 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 157 | logging.info("Sending packet to dp port " + |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 158 | str(ingress_port)) |
| 159 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | cf26b7a | 2011-08-05 10:15:35 -0700 | [diff] [blame] | 160 | |
| 161 | exp_pkt_arg = None |
| 162 | exp_port = None |
| 163 | if pa_config["relax"]: |
| 164 | exp_pkt_arg = pkt |
| 165 | exp_port = egress_port |
| 166 | |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 167 | (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] | 168 | exp_pkt=exp_pkt_arg) |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 169 | self.assertTrue(rcv_pkt is not None, "Did not receive packet") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 170 | logging.debug("Packet len " + str(len(rcv_pkt)) + " in on " + |
Dan Talayco | 5eba844 | 2010-03-10 13:58:43 -0800 | [diff] [blame] | 171 | str(rcv_port)) |
| 172 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 173 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 174 | 'Response packet does not match send packet') |
Tatsuya Yabe | b8fb3c3 | 2010-06-14 15:48:36 -0700 | [diff] [blame] | 175 | |
Rich Lane | 51c23b3 | 2012-07-27 16:37:25 -0700 | [diff] [blame] | 176 | class DirectPacketController(basic.SimpleDataPlane): |
| 177 | """ |
| 178 | Send packet to the controller port |
| 179 | |
| 180 | Generate a packet |
| 181 | Generate and install a matching flow |
| 182 | Add action to direct the packet to the controller port |
| 183 | Send the packet to ingress dataplane port |
| 184 | Verify the packet is received at the controller port |
| 185 | """ |
| 186 | def runTest(self): |
| 187 | self.handleFlow() |
| 188 | |
| 189 | def handleFlow(self, pkttype='TCP'): |
| 190 | of_ports = pa_port_map.keys() |
| 191 | of_ports.sort() |
| 192 | self.assertTrue(len(of_ports) > 0, "Not enough ports for test") |
| 193 | |
| 194 | if (pkttype == 'ICMP'): |
| 195 | pkt = simple_icmp_packet() |
| 196 | else: |
| 197 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 198 | match = packet_to_flow_match(self, pkt) |
Rich Lane | 51c23b3 | 2012-07-27 16:37:25 -0700 | [diff] [blame] | 199 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 200 | self.assertTrue(match is not None, |
| 201 | "Could not generate flow match from pkt") |
| 202 | act = action.action_output() |
| 203 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 204 | rv = delete_all_flows(self.controller) |
Rich Lane | 51c23b3 | 2012-07-27 16:37:25 -0700 | [diff] [blame] | 205 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 206 | |
| 207 | ingress_port = of_ports[0] |
| 208 | match.in_port = ingress_port |
| 209 | |
| 210 | request = message.flow_mod() |
| 211 | request.match = match |
| 212 | |
| 213 | request.buffer_id = 0xffffffff |
| 214 | act.port = ofp.OFPP_CONTROLLER |
| 215 | act.max_len = 65535 |
| 216 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 217 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 218 | logging.info("Inserting flow") |
Rich Lane | 51c23b3 | 2012-07-27 16:37:25 -0700 | [diff] [blame] | 219 | rv = self.controller.message_send(request) |
| 220 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 221 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 222 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 223 | logging.info("Sending packet to dp port " + |
Rich Lane | 51c23b3 | 2012-07-27 16:37:25 -0700 | [diff] [blame] | 224 | str(ingress_port)) |
| 225 | self.dataplane.send(ingress_port, str(pkt)) |
| 226 | |
| 227 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN) |
| 228 | |
| 229 | self.assertTrue(response is not None, |
| 230 | 'Packet in message not received by controller') |
| 231 | if not dataplane.match_exp_pkt(pkt, response.data): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 232 | logging.debug("Sent %s" % format_packet(pkt)) |
| 233 | logging.debug("Resp %s" % format_packet(response.data)) |
Rich Lane | 51c23b3 | 2012-07-27 16:37:25 -0700 | [diff] [blame] | 234 | self.assertTrue(False, |
| 235 | 'Response packet does not match send packet' + |
| 236 | ' for controller port') |
| 237 | |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 238 | |
| 239 | class DirectPacketQueue(basic.SimpleDataPlane): |
| 240 | """ |
| 241 | Send packet to single queue on single egress port |
| 242 | |
| 243 | Generate a packet |
| 244 | Generate and install a matching flow |
| 245 | Add action to direct the packet to an egress port and queue |
| 246 | Send the packet to ingress dataplane port |
| 247 | Verify the packet is received at the egress port only |
| 248 | """ |
| 249 | def runTest(self): |
| 250 | self.handleFlow() |
| 251 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 252 | def portQueuesGet(self, queue_stats, port_num): |
| 253 | result = [] |
| 254 | for qs in queue_stats.stats: |
| 255 | if qs.port_no != port_num: |
| 256 | continue |
| 257 | result.append(qs.queue_id) |
| 258 | return result |
| 259 | |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 260 | def handleFlow(self, pkttype='TCP'): |
| 261 | of_ports = pa_port_map.keys() |
| 262 | of_ports.sort() |
| 263 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 264 | |
| 265 | if (pkttype == 'ICMP'): |
| 266 | pkt = simple_icmp_packet() |
| 267 | else: |
| 268 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 269 | match = packet_to_flow_match(self, pkt) |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 270 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 271 | self.assertTrue(match is not None, |
| 272 | "Could not generate flow match from pkt") |
| 273 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 274 | # Get queue stats from switch |
| 275 | |
| 276 | request = message.queue_stats_request() |
| 277 | request.port_no = ofp.OFPP_ALL |
| 278 | request.queue_id = ofp.OFPQ_ALL |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 279 | (queue_stats, p) = self.controller.transact(request) |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 280 | self.assertNotEqual(queue_stats, None, "Queue stats request failed") |
| 281 | |
| 282 | act = action.action_enqueue() |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 283 | |
| 284 | for idx in range(len(of_ports)): |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 285 | ingress_port = of_ports[idx] |
| 286 | egress_port = of_ports[(idx + 1) % len(of_ports)] |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 287 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 288 | for egress_queue_id in self.portQueuesGet(queue_stats, egress_port): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 289 | logging.info("Ingress " + str(ingress_port) |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 290 | + " to egress " + str(egress_port) |
| 291 | + " queue " + str(egress_queue_id) |
| 292 | ) |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 293 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 294 | rv = delete_all_flows(self.controller) |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 295 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 296 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 297 | match.in_port = ingress_port |
| 298 | |
| 299 | request = message.flow_mod() |
| 300 | request.match = match |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 301 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 302 | request.buffer_id = 0xffffffff |
| 303 | act.port = egress_port |
| 304 | act.queue_id = egress_queue_id |
| 305 | self.assertTrue(request.actions.add(act), "Could not add action") |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 306 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 307 | logging.info("Inserting flow") |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 308 | rv = self.controller.message_send(request) |
| 309 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 310 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 311 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 312 | # Get current stats for selected egress queue |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 313 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 314 | request = message.queue_stats_request() |
| 315 | request.port_no = egress_port |
| 316 | request.queue_id = egress_queue_id |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 317 | (qs_before, p) = self.controller.transact(request) |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 318 | self.assertNotEqual(qs_before, None, "Queue stats request failed") |
| 319 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 320 | logging.info("Sending packet to dp port " + |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 321 | str(ingress_port)) |
| 322 | self.dataplane.send(ingress_port, str(pkt)) |
| 323 | |
| 324 | exp_pkt_arg = None |
| 325 | exp_port = None |
| 326 | if pa_config["relax"]: |
| 327 | exp_pkt_arg = pkt |
| 328 | exp_port = egress_port |
| 329 | |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 330 | (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] | 331 | exp_pkt=exp_pkt_arg) |
| 332 | self.assertTrue(rcv_pkt is not None, "Did not receive packet") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 333 | logging.debug("Packet len " + str(len(rcv_pkt)) + " in on " + |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 334 | str(rcv_port)) |
| 335 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 336 | self.assertEqual(str(pkt), str(rcv_pkt), |
| 337 | 'Response packet does not match send packet') |
| 338 | |
Ed Swierk | b8a8651 | 2012-04-18 18:45:58 -0700 | [diff] [blame] | 339 | # FIXME: instead of sleeping, keep requesting queue stats until |
| 340 | # the expected queue counter increases or some large timeout is |
| 341 | # reached |
| 342 | time.sleep(2) |
| 343 | |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 344 | # Get current stats for selected egress queue again |
| 345 | |
| 346 | request = message.queue_stats_request() |
| 347 | request.port_no = egress_port |
| 348 | request.queue_id = egress_queue_id |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 349 | (qs_after, p) = self.controller.transact(request) |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 350 | self.assertNotEqual(qs_after, None, "Queue stats request failed") |
| 351 | |
| 352 | # Make sure that tx packet counter for selected egress queue was |
| 353 | # incremented |
| 354 | |
Ed Swierk | 22f5915 | 2012-04-17 16:36:47 -0700 | [diff] [blame] | 355 | self.assertEqual(qs_after.stats[0].tx_packets, \ |
| 356 | qs_before.stats[0].tx_packets + 1, \ |
Howard Persh | 670b567 | 2012-04-13 09:08:29 -0700 | [diff] [blame] | 357 | "Verification of egress queue tx packet count failed" |
| 358 | ) |
| 359 | |
| 360 | |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 361 | class DirectPacketControllerQueue(basic.SimpleDataPlane): |
| 362 | """ |
| 363 | Send a packet from each of the openflow ports |
| 364 | to each of the queues configured on the controller port. |
| 365 | If no queues have been configured, no packets are sent. |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 366 | |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 367 | Generate a packet |
| 368 | Generate and install a matching flow |
| 369 | Add action to direct the packet to one of the controller port queues |
| 370 | Send the packet to ingress dataplane port |
| 371 | Verify the packet is received on the controller port queue |
| 372 | """ |
| 373 | def runTest(self): |
| 374 | self.handleFlow() |
| 375 | |
| 376 | def portQueuesGet(self, queue_stats, port_num): |
| 377 | result = [] |
| 378 | for qs in queue_stats.stats: |
| 379 | if qs.port_no != port_num: |
| 380 | continue |
| 381 | result.append(qs.queue_id) |
| 382 | return result |
| 383 | |
| 384 | def handleFlow(self, pkttype='TCP'): |
| 385 | of_ports = pa_port_map.keys() |
| 386 | of_ports.sort() |
| 387 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 388 | |
| 389 | if (pkttype == 'ICMP'): |
| 390 | pkt = simple_icmp_packet() |
| 391 | else: |
| 392 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 393 | match = packet_to_flow_match(self, pkt) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 394 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 395 | self.assertTrue(match is not None, |
| 396 | "Could not generate flow match from pkt") |
| 397 | |
| 398 | # Get queue stats from switch |
| 399 | |
| 400 | request = message.queue_stats_request() |
| 401 | request.port_no = ofp.OFPP_CONTROLLER |
| 402 | request.queue_id = ofp.OFPQ_ALL |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 403 | (queue_stats, p) = self.controller.transact(request) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 404 | self.assertNotEqual(queue_stats, None, "Queue stats request failed") |
| 405 | |
| 406 | act = action.action_enqueue() |
| 407 | |
| 408 | for idx in range(len(of_ports)): |
| 409 | ingress_port = of_ports[idx] |
| 410 | egress_port = ofp.OFPP_CONTROLLER |
| 411 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 412 | logging.info("Ingress port " + str(ingress_port) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 413 | + ", controller port queues " |
| 414 | + str(self.portQueuesGet(queue_stats, egress_port))) |
| 415 | |
| 416 | for egress_queue_id in self.portQueuesGet(queue_stats, egress_port): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 417 | logging.info("Ingress " + str(ingress_port) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 418 | + " to egress " + str(egress_port) |
| 419 | + " queue " + str(egress_queue_id) |
| 420 | ) |
| 421 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 422 | rv = delete_all_flows(self.controller) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 423 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 424 | |
| 425 | match.in_port = ingress_port |
| 426 | |
| 427 | request = message.flow_mod() |
| 428 | request.match = match |
| 429 | |
| 430 | request.buffer_id = 0xffffffff |
| 431 | act.port = egress_port |
| 432 | act.queue_id = egress_queue_id |
| 433 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 434 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 435 | logging.info("Inserting flow") |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 436 | rv = self.controller.message_send(request) |
| 437 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 438 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 439 | |
| 440 | # Get current stats for selected egress queue |
| 441 | |
| 442 | request = message.queue_stats_request() |
| 443 | request.port_no = egress_port |
| 444 | request.queue_id = egress_queue_id |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 445 | (qs_before, p) = self.controller.transact(request) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 446 | self.assertNotEqual(qs_before, None, "Queue stats request failed") |
| 447 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 448 | logging.info("Sending packet to dp port " + |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 449 | str(ingress_port)) |
| 450 | self.dataplane.send(ingress_port, str(pkt)) |
| 451 | |
| 452 | exp_pkt_arg = None |
| 453 | exp_port = None |
| 454 | |
| 455 | while True: |
Dan Talayco | c689a79 | 2012-09-28 14:22:53 -0700 | [diff] [blame] | 456 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 457 | if not response: # Timeout |
| 458 | break |
| 459 | if dataplane.match_exp_pkt(pkt, response.data): # Got match |
| 460 | break |
| 461 | if not basic_config["relax"]: # Only one attempt to match |
| 462 | break |
| 463 | count += 1 |
| 464 | if count > 10: # Too many tries |
| 465 | break |
| 466 | |
| 467 | self.assertTrue(response is not None, |
| 468 | 'Packet in message not received by controller') |
| 469 | if not dataplane.match_exp_pkt(pkt, response.data): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 470 | logging.debug("Sent %s" % format_packet(pkt)) |
| 471 | logging.debug("Resp %s" % format_packet(response.data)) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 472 | self.assertTrue(False, |
| 473 | 'Response packet does not match send packet' + |
| 474 | ' for controller port') |
| 475 | |
| 476 | # FIXME: instead of sleeping, keep requesting queue stats until |
| 477 | # the expected queue counter increases or some large timeout is |
| 478 | # reached |
| 479 | time.sleep(2) |
| 480 | |
| 481 | # Get current stats for selected egress queue again |
| 482 | |
| 483 | request = message.queue_stats_request() |
| 484 | request.port_no = egress_port |
| 485 | request.queue_id = egress_queue_id |
Rich Lane | c8aaa3e | 2012-07-26 19:28:02 -0700 | [diff] [blame] | 486 | (qs_after, p) = self.controller.transact(request) |
Ken Chiang | 899ff8e | 2012-05-23 18:26:12 -0700 | [diff] [blame] | 487 | self.assertNotEqual(qs_after, None, "Queue stats request failed") |
| 488 | |
| 489 | # Make sure that tx packet counter for selected egress queue was |
| 490 | # incremented |
| 491 | |
| 492 | self.assertEqual(qs_after.stats[0].tx_packets, \ |
| 493 | qs_before.stats[0].tx_packets + 1, \ |
| 494 | "Verification of egress queue tx packet count failed" |
| 495 | ) |
| 496 | |
Howard Persh | f97840f | 2012-04-10 16:30:42 -0700 | [diff] [blame] | 497 | |
Tatsuya Yabe | b8fb3c3 | 2010-06-14 15:48:36 -0700 | [diff] [blame] | 498 | class DirectPacketICMP(DirectPacket): |
| 499 | """ |
| 500 | Send ICMP packet to single egress port |
| 501 | |
| 502 | Generate a ICMP packet |
| 503 | Generate and install a matching flow |
| 504 | Add action to direct the packet to an egress port |
| 505 | Send the packet to ingress dataplane port |
| 506 | Verify the packet is received at the egress port only |
| 507 | Difference from DirectPacket test is that sent packet is ICMP |
| 508 | """ |
| 509 | def runTest(self): |
| 510 | self.handleFlow(pkttype='ICMP') |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 511 | |
| 512 | class DirectTwoPorts(basic.SimpleDataPlane): |
| 513 | """ |
| 514 | Send packet to two egress ports |
| 515 | |
| 516 | Generate a packet |
| 517 | Generate and install a matching flow |
| 518 | Add action to direct the packet to two egress ports |
| 519 | Send the packet to ingress dataplane port |
| 520 | Verify the packet is received at the two egress ports |
| 521 | """ |
| 522 | def runTest(self): |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 523 | of_ports = pa_port_map.keys() |
| 524 | of_ports.sort() |
| 525 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 526 | |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 527 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 528 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 529 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 530 | self.assertTrue(match is not None, |
| 531 | "Could not generate flow match from pkt") |
| 532 | act = action.action_output() |
| 533 | |
| 534 | for idx in range(len(of_ports)): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 535 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 536 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 537 | |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 538 | ingress_port = of_ports[idx] |
| 539 | egress_port1 = of_ports[(idx + 1) % len(of_ports)] |
| 540 | egress_port2 = of_ports[(idx + 2) % len(of_ports)] |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 541 | logging.info("Ingress " + str(ingress_port) + |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 542 | " to egress " + str(egress_port1) + " and " + |
| 543 | str(egress_port2)) |
| 544 | |
| 545 | match.in_port = ingress_port |
| 546 | |
| 547 | request = message.flow_mod() |
| 548 | request.match = match |
| 549 | request.buffer_id = 0xffffffff |
| 550 | act.port = egress_port1 |
| 551 | self.assertTrue(request.actions.add(act), "Could not add action1") |
| 552 | act.port = egress_port2 |
| 553 | self.assertTrue(request.actions.add(act), "Could not add action2") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 554 | # logging.info(request.show()) |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 555 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 556 | logging.info("Inserting flow") |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 557 | rv = self.controller.message_send(request) |
| 558 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 559 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 560 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 561 | logging.info("Sending packet to dp port " + |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 562 | str(ingress_port)) |
| 563 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 564 | yes_ports = set([egress_port1, egress_port2]) |
| 565 | no_ports = set(of_ports).difference(yes_ports) |
Dan Talayco | 2d0d49a | 2010-05-11 15:29:08 -0700 | [diff] [blame] | 566 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 567 | receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 568 | self, pa_config) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 569 | |
| 570 | class DirectMCNonIngress(basic.SimpleDataPlane): |
| 571 | """ |
| 572 | Multicast to all non-ingress ports |
| 573 | |
| 574 | Generate a packet |
| 575 | Generate and install a matching flow |
| 576 | Add action to direct the packet to all non-ingress ports |
| 577 | Send the packet to ingress dataplane port |
| 578 | Verify the packet is received at all non-ingress ports |
| 579 | |
| 580 | Does not use the flood action |
| 581 | """ |
| 582 | def runTest(self): |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 583 | of_ports = pa_port_map.keys() |
| 584 | of_ports.sort() |
| 585 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 586 | |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 587 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 588 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 589 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 590 | self.assertTrue(match is not None, |
| 591 | "Could not generate flow match from pkt") |
| 592 | act = action.action_output() |
| 593 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 594 | for ingress_port in of_ports: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 595 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 596 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 597 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 598 | logging.info("Ingress " + str(ingress_port) + |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 599 | " all non-ingress ports") |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 600 | match.in_port = ingress_port |
| 601 | |
| 602 | request = message.flow_mod() |
| 603 | request.match = match |
| 604 | request.buffer_id = 0xffffffff |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 605 | for egress_port in of_ports: |
| 606 | if egress_port == ingress_port: |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 607 | continue |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 608 | act.port = egress_port |
| 609 | self.assertTrue(request.actions.add(act), |
| 610 | "Could not add output to " + str(egress_port)) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 611 | logging.debug(request.show()) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 612 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 613 | logging.info("Inserting flow") |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 614 | rv = self.controller.message_send(request) |
| 615 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 616 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 617 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 618 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 619 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 620 | yes_ports = set(of_ports).difference([ingress_port]) |
| 621 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 622 | self, pa_config) |
Dan Talayco | b0b0fdb | 2010-05-11 15:44:56 -0700 | [diff] [blame] | 623 | |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 624 | |
| 625 | class DirectMC(basic.SimpleDataPlane): |
| 626 | """ |
| 627 | Multicast to all ports including ingress |
| 628 | |
| 629 | Generate a packet |
| 630 | Generate and install a matching flow |
| 631 | Add action to direct the packet to all non-ingress ports |
| 632 | Send the packet to ingress dataplane port |
| 633 | Verify the packet is received at all ports |
| 634 | |
| 635 | Does not use the flood action |
| 636 | """ |
| 637 | def runTest(self): |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 638 | of_ports = pa_port_map.keys() |
| 639 | of_ports.sort() |
| 640 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 641 | |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 642 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 643 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 644 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 645 | self.assertTrue(match is not None, |
| 646 | "Could not generate flow match from pkt") |
| 647 | act = action.action_output() |
| 648 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 649 | for ingress_port in of_ports: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 650 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 651 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 652 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 653 | logging.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 654 | match.in_port = ingress_port |
| 655 | |
| 656 | request = message.flow_mod() |
| 657 | request.match = match |
| 658 | request.buffer_id = 0xffffffff |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 659 | for egress_port in of_ports: |
| 660 | if egress_port == ingress_port: |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 661 | act.port = ofp.OFPP_IN_PORT |
| 662 | else: |
| 663 | act.port = egress_port |
| 664 | self.assertTrue(request.actions.add(act), |
| 665 | "Could not add output to " + str(egress_port)) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 666 | # logging.info(request.show()) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 667 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 668 | logging.info("Inserting flow") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 669 | rv = self.controller.message_send(request) |
| 670 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 671 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 672 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 673 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 674 | self.dataplane.send(ingress_port, str(pkt)) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 675 | receive_pkt_check(self.dataplane, pkt, of_ports, [], self, pa_config) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 676 | |
| 677 | class Flood(basic.SimpleDataPlane): |
| 678 | """ |
| 679 | Flood to all ports except ingress |
| 680 | |
| 681 | Generate a packet |
| 682 | Generate and install a matching flow |
| 683 | Add action to flood the packet |
| 684 | Send the packet to ingress dataplane port |
| 685 | Verify the packet is received at all other ports |
| 686 | """ |
| 687 | def runTest(self): |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 688 | of_ports = pa_port_map.keys() |
| 689 | of_ports.sort() |
| 690 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 691 | |
| 692 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 693 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 694 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 695 | self.assertTrue(match is not None, |
| 696 | "Could not generate flow match from pkt") |
| 697 | act = action.action_output() |
| 698 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 699 | for ingress_port in of_ports: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 700 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 701 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 702 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 703 | logging.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 2e77a84 | 2010-05-12 15:39:46 -0700 | [diff] [blame] | 704 | match.in_port = ingress_port |
| 705 | |
| 706 | request = message.flow_mod() |
| 707 | request.match = match |
| 708 | request.buffer_id = 0xffffffff |
| 709 | act.port = ofp.OFPP_FLOOD |
| 710 | self.assertTrue(request.actions.add(act), |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 711 | "Could not add flood port action") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 712 | logging.info(request.show()) |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 713 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 714 | logging.info("Inserting flow") |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 715 | rv = self.controller.message_send(request) |
| 716 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 717 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 718 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 719 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Dan Talayco | 32fa654 | 2010-05-11 15:54:08 -0700 | [diff] [blame] | 720 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 721 | yes_ports = set(of_ports).difference([ingress_port]) |
| 722 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 723 | self, pa_config) |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 724 | |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 725 | class FloodPlusIngress(basic.SimpleDataPlane): |
| 726 | """ |
| 727 | Flood to all ports plus send to ingress port |
| 728 | |
| 729 | Generate a packet |
| 730 | Generate and install a matching flow |
| 731 | Add action to flood the packet |
| 732 | Add action to send to ingress port |
| 733 | Send the packet to ingress dataplane port |
| 734 | Verify the packet is received at all other ports |
| 735 | """ |
| 736 | def runTest(self): |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 737 | of_ports = pa_port_map.keys() |
| 738 | of_ports.sort() |
| 739 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 740 | |
| 741 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 742 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 743 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 744 | self.assertTrue(match is not None, |
| 745 | "Could not generate flow match from pkt") |
| 746 | act = action.action_output() |
| 747 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 748 | for ingress_port in of_ports: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 749 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 750 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 751 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 752 | logging.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 753 | match.in_port = ingress_port |
| 754 | |
| 755 | request = message.flow_mod() |
| 756 | request.match = match |
| 757 | request.buffer_id = 0xffffffff |
| 758 | act.port = ofp.OFPP_FLOOD |
| 759 | self.assertTrue(request.actions.add(act), |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 760 | "Could not add flood port action") |
| 761 | act.port = ofp.OFPP_IN_PORT |
| 762 | self.assertTrue(request.actions.add(act), |
| 763 | "Could not add ingress port for output") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 764 | logging.info(request.show()) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 765 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 766 | logging.info("Inserting flow") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 767 | rv = self.controller.message_send(request) |
| 768 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 769 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 770 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 771 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 772 | self.dataplane.send(ingress_port, str(pkt)) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 773 | receive_pkt_check(self.dataplane, pkt, of_ports, [], self, pa_config) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 774 | |
| 775 | class All(basic.SimpleDataPlane): |
| 776 | """ |
| 777 | Send to OFPP_ALL port |
| 778 | |
| 779 | Generate a packet |
| 780 | Generate and install a matching flow |
| 781 | Add action to forward to OFPP_ALL |
| 782 | Send the packet to ingress dataplane port |
| 783 | Verify the packet is received at all other ports |
| 784 | """ |
| 785 | def runTest(self): |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 786 | of_ports = pa_port_map.keys() |
| 787 | of_ports.sort() |
| 788 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 789 | |
| 790 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 791 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 792 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 793 | self.assertTrue(match is not None, |
| 794 | "Could not generate flow match from pkt") |
| 795 | act = action.action_output() |
| 796 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 797 | for ingress_port in of_ports: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 798 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 799 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 800 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 801 | logging.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 802 | match.in_port = ingress_port |
| 803 | |
| 804 | request = message.flow_mod() |
| 805 | request.match = match |
| 806 | request.buffer_id = 0xffffffff |
| 807 | act.port = ofp.OFPP_ALL |
| 808 | self.assertTrue(request.actions.add(act), |
| 809 | "Could not add ALL port action") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 810 | logging.info(request.show()) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 811 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 812 | logging.info("Inserting flow") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 813 | rv = self.controller.message_send(request) |
| 814 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 815 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 816 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 817 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 818 | self.dataplane.send(ingress_port, str(pkt)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 819 | yes_ports = set(of_ports).difference([ingress_port]) |
| 820 | receive_pkt_check(self.dataplane, pkt, yes_ports, [ingress_port], |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 821 | self, pa_config) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 822 | |
| 823 | class AllPlusIngress(basic.SimpleDataPlane): |
| 824 | """ |
| 825 | Send to OFPP_ALL port and ingress port |
| 826 | |
| 827 | Generate a packet |
| 828 | Generate and install a matching flow |
| 829 | Add action to forward to OFPP_ALL |
| 830 | Add action to forward to ingress port |
| 831 | Send the packet to ingress dataplane port |
| 832 | Verify the packet is received at all other ports |
| 833 | """ |
| 834 | def runTest(self): |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 835 | of_ports = pa_port_map.keys() |
| 836 | of_ports.sort() |
| 837 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 838 | |
| 839 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 840 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 841 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 842 | self.assertTrue(match is not None, |
| 843 | "Could not generate flow match from pkt") |
| 844 | act = action.action_output() |
| 845 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 846 | for ingress_port in of_ports: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 847 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 848 | self.assertEqual(rv, 0, "Failed to delete all flows") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 849 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 850 | logging.info("Ingress " + str(ingress_port) + " to all ports") |
Dan Talayco | 4aa1312 | 2010-05-12 15:54:44 -0700 | [diff] [blame] | 851 | match.in_port = ingress_port |
| 852 | |
| 853 | request = message.flow_mod() |
| 854 | request.match = match |
| 855 | request.buffer_id = 0xffffffff |
| 856 | act.port = ofp.OFPP_ALL |
| 857 | self.assertTrue(request.actions.add(act), |
| 858 | "Could not add ALL port action") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 859 | act.port = ofp.OFPP_IN_PORT |
| 860 | self.assertTrue(request.actions.add(act), |
| 861 | "Could not add ingress port for output") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 862 | logging.info(request.show()) |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 863 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 864 | logging.info("Inserting flow") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 865 | rv = self.controller.message_send(request) |
| 866 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 867 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 868 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 869 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Dan Talayco | 3be5b06 | 2010-05-12 15:46:21 -0700 | [diff] [blame] | 870 | self.dataplane.send(ingress_port, str(pkt)) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 871 | receive_pkt_check(self.dataplane, pkt, of_ports, [], self, pa_config) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 872 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 873 | class FloodMinusPort(basic.SimpleDataPlane): |
| 874 | """ |
| 875 | Config port with No_Flood and test Flood action |
| 876 | |
| 877 | Generate a packet |
| 878 | Generate a matching flow |
| 879 | Add action to forward to OFPP_ALL |
| 880 | Set port to no-flood |
| 881 | Send the packet to ingress dataplane port |
| 882 | Verify the packet is received at all other ports except |
| 883 | the ingress port and the no_flood port |
| 884 | """ |
| 885 | def runTest(self): |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 886 | of_ports = pa_port_map.keys() |
| 887 | of_ports.sort() |
| 888 | self.assertTrue(len(of_ports) > 2, "Not enough ports for test") |
| 889 | |
| 890 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 891 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 892 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 893 | self.assertTrue(match is not None, |
| 894 | "Could not generate flow match from pkt") |
| 895 | act = action.action_output() |
| 896 | |
| 897 | for idx in range(len(of_ports)): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 898 | rv = delete_all_flows(self.controller) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 899 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 900 | |
| 901 | ingress_port = of_ports[idx] |
| 902 | no_flood_idx = (idx + 1) % len(of_ports) |
| 903 | no_flood_port = of_ports[no_flood_idx] |
| 904 | rv = port_config_set(self.controller, no_flood_port, |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 905 | ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 906 | self.assertEqual(rv, 0, "Failed to set port config") |
| 907 | |
| 908 | match.in_port = ingress_port |
| 909 | |
| 910 | request = message.flow_mod() |
| 911 | request.match = match |
| 912 | request.buffer_id = 0xffffffff |
| 913 | act.port = ofp.OFPP_FLOOD |
| 914 | self.assertTrue(request.actions.add(act), |
| 915 | "Could not add flood port action") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 916 | logging.info(request.show()) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 917 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 918 | logging.info("Inserting flow") |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 919 | rv = self.controller.message_send(request) |
| 920 | self.assertTrue(rv != -1, "Error installing flow mod") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 921 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 922 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 923 | logging.info("Sending packet to dp port " + str(ingress_port)) |
| 924 | logging.info("No flood port is " + str(no_flood_port)) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 925 | self.dataplane.send(ingress_port, str(pkt)) |
| 926 | no_ports = set([ingress_port, no_flood_port]) |
| 927 | yes_ports = set(of_ports).difference(no_ports) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 928 | receive_pkt_check(self.dataplane, pkt, yes_ports, no_ports, self, pa_config) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 929 | |
| 930 | # Turn no flood off again |
| 931 | rv = port_config_set(self.controller, no_flood_port, |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 932 | 0, ofp.OFPPC_NO_FLOOD) |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 933 | self.assertEqual(rv, 0, "Failed to reset port config") |
| 934 | |
| 935 | #@todo Should check no other packets received |
| 936 | |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 937 | |
| 938 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 939 | ################################################################ |
| 940 | |
| 941 | class BaseMatchCase(basic.SimpleDataPlane): |
| 942 | def setUp(self): |
| 943 | basic.SimpleDataPlane.setUp(self) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 944 | def runTest(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 945 | logging.info("BaseMatchCase") |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 946 | |
| 947 | class ExactMatch(BaseMatchCase): |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 948 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 949 | Exercise exact matching for all port pairs |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 950 | |
| 951 | Generate a packet |
| 952 | Generate and install a matching flow without wildcard mask |
| 953 | Add action to forward to a port |
| 954 | Send the packet to the port |
| 955 | 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] | 956 | """ |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 957 | |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 958 | def runTest(self): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 959 | flow_match_test(self, pa_port_map) |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 960 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 961 | class ExactMatchTagged(BaseMatchCase): |
| 962 | """ |
| 963 | Exact match for all port pairs with tagged pkts |
| 964 | """ |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 965 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 966 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 967 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 968 | flow_match_test(self, pa_port_map, dl_vlan=vid) |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 969 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 970 | class ExactMatchTaggedMany(BaseMatchCase): |
| 971 | """ |
| 972 | ExactMatchTagged with many VLANS |
| 973 | """ |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 974 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 975 | def runTest(self): |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 976 | for vid in range(2,100,10): |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 977 | flow_match_test(self, pa_port_map, dl_vlan=vid, max_test=5) |
| 978 | for vid in range(100,4000,389): |
| 979 | flow_match_test(self, pa_port_map, dl_vlan=vid, max_test=5) |
| 980 | flow_match_test(self, pa_port_map, dl_vlan=4094, max_test=5) |
Tatsuya Yabe | cdf575e | 2010-05-25 16:56:38 -0700 | [diff] [blame] | 981 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 982 | # Don't run by default |
| 983 | test_prio["ExactMatchTaggedMany"] = -1 |
Tatsuya Yabe | cdf575e | 2010-05-25 16:56:38 -0700 | [diff] [blame] | 984 | |
Tatsuya Yabe | cdf575e | 2010-05-25 16:56:38 -0700 | [diff] [blame] | 985 | |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 986 | class SingleWildcardMatchPriority(BaseMatchCase): |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 987 | """ |
| 988 | SingleWildcardMatchPriority |
| 989 | """ |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 990 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 991 | def _Init(self): |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 992 | self.pkt = simple_tcp_packet() |
| 993 | self.flowMsgs = {} |
| 994 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 995 | def _ClearTable(self): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 996 | rc = delete_all_flows(self.controller) |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 997 | self.assertEqual(rc, 0, "Failed to delete all flows") |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 998 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 999 | |
| 1000 | def runTest(self): |
| 1001 | |
| 1002 | self._Init() |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1003 | of_ports = pa_port_map.keys() |
| 1004 | of_ports.sort() |
| 1005 | |
| 1006 | # Delete the initial flow table |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1007 | self._ClearTable() |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1008 | |
| 1009 | # Run several combinations, each at lower priority settings. |
| 1010 | # At the end of each call to runPrioFlows(), the table should |
| 1011 | # be empty. If its not, we'll catch it as the priorities decreases |
| 1012 | portA = of_ports[0] |
| 1013 | portB = of_ports[1] |
| 1014 | portC = of_ports[2] |
| 1015 | |
| 1016 | # TODO -- these priority numbers should be validated somehow? |
| 1017 | self.runPrioFlows(portA, portB, portC, 1000, 999) |
| 1018 | self.runPrioFlows(portB, portC, portA, 998, 997) |
| 1019 | self.runPrioFlows(portC, portA, portB, 996, 995) |
| 1020 | self.runPrioFlows(portA, portC, portB, 994, 993) |
| 1021 | |
| 1022 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1023 | |
| 1024 | def runPrioFlows(self, portA, portB, portC, prioHigher, prioLower, |
| 1025 | clearTable=False): |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1026 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1027 | if clearTable: |
| 1028 | self._ClearTable() |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1029 | |
| 1030 | # Sanity check flow at lower priority from pA to pB |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1031 | 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] | 1032 | % (portA, portB, portC, prioHigher, prioLower)) |
| 1033 | |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1034 | # Sanity check flow at lower priority from pA to pC |
| 1035 | self.installFlow(prioLower, portA, portC) |
| 1036 | self.verifyFlow(portA, portC) |
| 1037 | self.removeFlow(prioLower) |
| 1038 | |
| 1039 | # Install and verify pA->pB @ prioLower |
| 1040 | self.installFlow(prioLower, portA, portB) |
| 1041 | self.verifyFlow(portA, portB) |
| 1042 | |
| 1043 | # Install and verify pA->pC @ prioHigher, should override pA->pB |
| 1044 | self.installFlow(prioHigher, portA, portC) |
| 1045 | self.verifyFlow(portA, portC) |
| 1046 | # remove pA->pC |
| 1047 | self.removeFlow(prioHigher) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1048 | # Old flow pA -> pB @ prioLower should still be active |
| 1049 | self.verifyFlow(portA, portB) |
| 1050 | self.removeFlow(prioLower) |
| 1051 | |
| 1052 | # Table should be empty at this point, leave it alone as |
| 1053 | # an assumption for future test runs |
| 1054 | |
| 1055 | |
| 1056 | |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1057 | def installFlow(self, prio, inp, egp, |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1058 | wildcards=ofp.OFPFW_DL_SRC): |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1059 | wildcards |= required_wildcards(self) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1060 | request = flow_msg_create(self, self.pkt, ing_port=inp, |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1061 | wildcards=wildcards, |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1062 | egr_ports=egp) |
| 1063 | request.priority = prio |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1064 | logging.debug("Install flow with priority " + str(prio)) |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1065 | flow_msg_install(self, request, clear_table_override=False) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1066 | self.flowMsgs[prio] = request |
| 1067 | |
| 1068 | def removeFlow(self, prio): |
| 1069 | if self.flowMsgs.has_key(prio): |
| 1070 | msg = self.flowMsgs[prio] |
| 1071 | msg.command = ofp.OFPFC_DELETE_STRICT |
| 1072 | # This *must* be set for DELETE |
| 1073 | msg.out_port = ofp.OFPP_NONE |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1074 | logging.debug("Remove flow with priority " + str(prio)) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1075 | self.controller.message_send(msg) |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 1076 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1077 | else: |
| 1078 | raise Exception("Not initialized") |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1079 | |
| 1080 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1081 | def verifyFlow(self, inp, egp, pkt=None): |
| 1082 | if pkt == None: |
| 1083 | pkt = self.pkt |
| 1084 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1085 | logging.info("Pkt match test: " + str(inp) + " to " + str(egp)) |
| 1086 | logging.debug("Send packet: " + str(inp) + " to " + str(egp)) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1087 | self.dataplane.send(inp, str(pkt)) |
| 1088 | receive_pkt_verify(self, egp, pkt, inp) |
Jeffrey Townsend | 2a300e4 | 2012-03-28 17:24:02 -0700 | [diff] [blame] | 1089 | |
| 1090 | |
| 1091 | |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1092 | class SingleWildcardMatchPriorityInsertModifyDelete(SingleWildcardMatchPriority): |
| 1093 | |
| 1094 | def runTest(self): |
| 1095 | |
| 1096 | self._Init() |
| 1097 | |
| 1098 | of_ports = pa_port_map.keys() |
| 1099 | of_ports.sort() |
| 1100 | |
| 1101 | # Install an entry from 0 -> 1 @ prio 1000 |
| 1102 | self._ClearTable() |
| 1103 | self.installFlow(1000, of_ports[0], of_ports[1]) |
| 1104 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1105 | self.installFlow(1000, of_ports[1], of_ports[0]) |
| 1106 | self.verifyFlow(of_ports[1], of_ports[0]) |
| 1107 | self.installFlow(1001, of_ports[0], of_ports[1]) |
| 1108 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1109 | self.installFlow(1001, of_ports[1], of_ports[0]) |
| 1110 | self.verifyFlow(of_ports[1], of_ports[0]) |
| 1111 | self.removeFlow(1001) |
| 1112 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1113 | self.removeFlow(1000) |
| 1114 | |
| 1115 | |
| 1116 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1117 | class WildcardPriority(SingleWildcardMatchPriority): |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1118 | """ |
| 1119 | 1. Add wildcard flow, verify packet received. |
| 1120 | 2. Add exact match flow with higher priority, verify packet received |
| 1121 | on port specified by this flow. |
| 1122 | 3. Add wildcard flow with even higher priority, verify packet received |
| 1123 | on port specified by this flow. |
| 1124 | """ |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1125 | |
| 1126 | def runTest(self): |
Jeffrey Townsend | 50c8246 | 2012-03-28 18:26:14 -0700 | [diff] [blame] | 1127 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1128 | self._Init() |
| 1129 | |
| 1130 | of_ports = pa_port_map.keys() |
| 1131 | of_ports.sort() |
| 1132 | |
| 1133 | self._ClearTable() |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1134 | |
| 1135 | # Install a flow with wildcards |
| 1136 | self.installFlow(999, of_ports[0], of_ports[1], |
| 1137 | wildcards=ofp.OFPFW_DL_DST) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1138 | self.verifyFlow(of_ports[0], of_ports[1]) |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1139 | # Install a flow with no wildcards for our packet |
| 1140 | self.installFlow(1000, of_ports[0], of_ports[2], wildcards=0) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1141 | self.verifyFlow(of_ports[0], of_ports[2]) |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1142 | # Install a flow with wildcards for our packet with higher |
| 1143 | # priority |
| 1144 | self.installFlow(1001, of_ports[0], of_ports[3]) |
| 1145 | self.verifyFlow(of_ports[0], of_ports[3]) |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1146 | |
| 1147 | |
Ken Chiang | 3978f24 | 2012-06-13 14:14:09 -0700 | [diff] [blame] | 1148 | class WildcardPriorityWithDelete(SingleWildcardMatchPriority): |
Ken Chiang | 38d7a15 | 2012-05-24 15:33:50 -0700 | [diff] [blame] | 1149 | """ |
| 1150 | 1. Add exact match flow, verify packet received. |
| 1151 | 2. Add wildcard flow with higher priority, verify packet received on port |
| 1152 | specified by this flow. |
| 1153 | 3. Add exact match flow with even higher priority, verify packet received |
| 1154 | on port specified by this flow. |
| 1155 | 4. Delete lowest priority flow, verify packet received on port specified |
| 1156 | by highest priority flow. |
| 1157 | 5. Delete highest priority flow, verify packet received on port specified |
| 1158 | by remaining flow. |
| 1159 | """ |
| 1160 | |
| 1161 | def runTest(self): |
| 1162 | |
| 1163 | self._Init() |
| 1164 | |
| 1165 | of_ports = pa_port_map.keys() |
| 1166 | of_ports.sort() |
| 1167 | |
| 1168 | self._ClearTable() |
| 1169 | |
| 1170 | # Install an exact match flow |
| 1171 | self.installFlow(250, of_ports[0], of_ports[1], wildcards=0) |
| 1172 | self.verifyFlow(of_ports[0], of_ports[1]) |
| 1173 | # Install a flow with wildcards of higher priority |
| 1174 | self.installFlow(1250, of_ports[0], of_ports[2], |
| 1175 | wildcards=ofp.OFPFW_DL_DST) |
| 1176 | self.verifyFlow(of_ports[0], of_ports[2]) |
| 1177 | # Install an exact match flow with even higher priority |
| 1178 | self.installFlow(2001, of_ports[0], of_ports[3], wildcards=0) |
| 1179 | self.verifyFlow(of_ports[0], of_ports[3]) |
| 1180 | # Delete lowest priority flow |
| 1181 | self.removeFlow(250) |
| 1182 | self.verifyFlow(of_ports[0], of_ports[3]) |
| 1183 | # Delete highest priority flow |
| 1184 | self.removeFlow(2001) |
| 1185 | self.verifyFlow(of_ports[0], of_ports[2]) |
| 1186 | |
Jeffrey Townsend | 8364b16 | 2012-04-12 13:45:40 -0700 | [diff] [blame] | 1187 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1188 | class SingleWildcardMatch(BaseMatchCase): |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 1189 | """ |
| 1190 | Exercise wildcard matching for all ports |
| 1191 | |
| 1192 | Generate a packet |
| 1193 | Generate and install a matching flow with wildcard mask |
| 1194 | Add action to forward to a port |
| 1195 | Send the packet to the port |
| 1196 | 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] | 1197 | Verify flow_expiration message is correct when command option is set |
Tatsuya Yabe | 6a6f38a | 2010-05-22 23:48:04 -0700 | [diff] [blame] | 1198 | """ |
Tatsuya Yabe | 0718ad3 | 2010-05-24 15:22:10 -0700 | [diff] [blame] | 1199 | def runTest(self): |
Ken Chiang | 5be06dd | 2012-04-03 10:03:50 -0700 | [diff] [blame] | 1200 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1201 | for wc in WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1202 | wc |= required_wildcards(self) |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1203 | if wc & ofp.OFPFW_DL_VLAN: |
Ken Chiang | 5be06dd | 2012-04-03 10:03:50 -0700 | [diff] [blame] | 1204 | # Set nonzero VLAN id to avoid sending priority-tagged packet |
| 1205 | dl_vlan = vid |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1206 | else: |
| 1207 | dl_vlan = -1 |
| 1208 | flow_match_test(self, pa_port_map, wildcards=wc, |
| 1209 | dl_vlan=dl_vlan, max_test=10) |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 1210 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1211 | class SingleWildcardMatchTagged(BaseMatchCase): |
| 1212 | """ |
| 1213 | SingleWildcardMatch with tagged packets |
| 1214 | """ |
| 1215 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1216 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1217 | for wc in WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1218 | wc |= required_wildcards(self) |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 1219 | flow_match_test(self, pa_port_map, wildcards=wc, dl_vlan=vid, |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1220 | max_test=10) |
| 1221 | |
| 1222 | class AllExceptOneWildcardMatch(BaseMatchCase): |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 1223 | """ |
Dan Talayco | 80b54ed | 2010-07-13 09:48:35 -0700 | [diff] [blame] | 1224 | Match exactly one field |
Tatsuya Yabe | 4fad7e3 | 2010-05-24 15:24:50 -0700 | [diff] [blame] | 1225 | |
| 1226 | Generate a packet |
| 1227 | Generate and install a matching flow with wildcard all except one filed |
| 1228 | Add action to forward to a port |
| 1229 | Send the packet to the port |
| 1230 | Verify the packet is received at all other ports (one port at a time) |
| 1231 | Verify flow_expiration message is correct when command option is set |
| 1232 | """ |
| 1233 | def runTest(self): |
Ken Chiang | 5be06dd | 2012-04-03 10:03:50 -0700 | [diff] [blame] | 1234 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 1235 | for all_exp_one_wildcard in NO_WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1236 | all_exp_one_wildcard |= required_wildcards(self) |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1237 | if all_exp_one_wildcard & ofp.OFPFW_DL_VLAN: |
Ken Chiang | 5be06dd | 2012-04-03 10:03:50 -0700 | [diff] [blame] | 1238 | # Set nonzero VLAN id to avoid sending priority-tagged packet |
| 1239 | dl_vlan = vid |
Dan Talayco | 4431d54 | 2012-03-21 16:42:16 -0700 | [diff] [blame] | 1240 | else: |
| 1241 | dl_vlan = -1 |
| 1242 | flow_match_test(self, pa_port_map, wildcards=all_exp_one_wildcard, |
| 1243 | dl_vlan=dl_vlan) |
Tatsuya Yabe | e30ebe2 | 2010-05-25 09:30:49 -0700 | [diff] [blame] | 1244 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1245 | class AllExceptOneWildcardMatchTagged(BaseMatchCase): |
| 1246 | """ |
| 1247 | Match one field with tagged packets |
| 1248 | """ |
| 1249 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1250 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 488fbc5 | 2012-04-09 16:30:41 -0700 | [diff] [blame] | 1251 | for all_exp_one_wildcard in NO_WILDCARD_VALUES: |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1252 | all_exp_one_wildcard |= required_wildcards(self) |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 1253 | flow_match_test(self, pa_port_map, wildcards=all_exp_one_wildcard, |
| 1254 | dl_vlan=vid) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1255 | |
| 1256 | class AllWildcardMatch(BaseMatchCase): |
Tatsuya Yabe | e30ebe2 | 2010-05-25 09:30:49 -0700 | [diff] [blame] | 1257 | """ |
| 1258 | Create Wildcard-all flow and exercise for all ports |
| 1259 | |
| 1260 | Generate a packet |
| 1261 | Generate and install a matching flow with wildcard-all |
| 1262 | Add action to forward to a port |
| 1263 | Send the packet to the port |
| 1264 | Verify the packet is received at all other ports (one port at a time) |
| 1265 | Verify flow_expiration message is correct when command option is set |
| 1266 | """ |
| 1267 | def runTest(self): |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 1268 | flow_match_test(self, pa_port_map, wildcards=ofp.OFPFW_ALL) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1269 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1270 | class AllWildcardMatchTagged(BaseMatchCase): |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1271 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1272 | AllWildcardMatch with tagged packets |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1273 | """ |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1274 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1275 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 2138156 | 2010-07-17 00:34:47 -0700 | [diff] [blame] | 1276 | flow_match_test(self, pa_port_map, wildcards=ofp.OFPFW_ALL, |
| 1277 | dl_vlan=vid) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1278 | |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1279 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1280 | class AddVLANTag(BaseMatchCase): |
| 1281 | """ |
| 1282 | Add a VLAN tag to an untagged packet |
| 1283 | """ |
| 1284 | def runTest(self): |
| 1285 | new_vid = 2 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1286 | sup_acts = self.supported_actions |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1287 | if not(sup_acts & 1<<ofp.OFPAT_SET_VLAN_VID): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1288 | skip_message_emit(self, "Add VLAN tag test") |
Dan Talayco | f36f108 | 2010-07-13 13:57:17 -0700 | [diff] [blame] | 1289 | return |
Tatsuya Yabe | f5ffb97 | 2010-05-26 15:36:33 -0700 | [diff] [blame] | 1290 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1291 | len = 100 |
| 1292 | len_w_vid = 104 |
| 1293 | pkt = simple_tcp_packet(pktlen=len) |
| 1294 | exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1295 | dl_vlan=new_vid) |
| 1296 | vid_act = action.action_set_vlan_vid() |
| 1297 | vid_act.vlan_vid = new_vid |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1298 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1299 | flow_match_test(self, pa_port_map, pkt=pkt, |
| 1300 | exp_pkt=exp_pkt, action_list=[vid_act]) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1301 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1302 | class PacketOnly(basic.DataPlaneOnly): |
| 1303 | """ |
| 1304 | Just send a packet thru the switch |
| 1305 | """ |
| 1306 | def runTest(self): |
| 1307 | pkt = simple_tcp_packet() |
| 1308 | of_ports = pa_port_map.keys() |
| 1309 | of_ports.sort() |
| 1310 | ing_port = of_ports[0] |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1311 | logging.info("Sending packet to " + str(ing_port)) |
| 1312 | logging.debug("Data: " + str(pkt).encode('hex')) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1313 | self.dataplane.send(ing_port, str(pkt)) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1314 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1315 | class PacketOnlyTagged(basic.DataPlaneOnly): |
| 1316 | """ |
| 1317 | Just send a packet thru the switch |
| 1318 | """ |
| 1319 | def runTest(self): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1320 | vid = test_param_get(self.config, 'vid', default=TEST_VID_DEFAULT) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1321 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid) |
| 1322 | of_ports = pa_port_map.keys() |
| 1323 | of_ports.sort() |
| 1324 | ing_port = of_ports[0] |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1325 | logging.info("Sending packet to " + str(ing_port)) |
| 1326 | logging.debug("Data: " + str(pkt).encode('hex')) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1327 | self.dataplane.send(ing_port, str(pkt)) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1328 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1329 | test_prio["PacketOnly"] = -1 |
| 1330 | test_prio["PacketOnlyTagged"] = -1 |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1331 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1332 | class ModifyVID(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1333 | """ |
| 1334 | Modify the VLAN ID in the VLAN tag of a tagged packet |
| 1335 | """ |
Dan Talayco | af66932 | 2012-09-12 22:51:22 -0700 | [diff] [blame] | 1336 | def setUp(self): |
| 1337 | BaseMatchCase.setUp(self) |
| 1338 | self.ing_port=False |
| 1339 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1340 | def runTest(self): |
| 1341 | old_vid = 2 |
| 1342 | new_vid = 3 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1343 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1344 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1345 | skip_message_emit(self, "Modify VLAN tag test") |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1346 | return |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1347 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1348 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=old_vid) |
| 1349 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=new_vid) |
| 1350 | vid_act = action.action_set_vlan_vid() |
| 1351 | vid_act.vlan_vid = new_vid |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1352 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1353 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
Dan Talayco | af66932 | 2012-09-12 22:51:22 -0700 | [diff] [blame] | 1354 | action_list=[vid_act], ing_port=self.ing_port) |
| 1355 | |
| 1356 | class ModifyVIDToIngress(ModifyVID): |
| 1357 | """ |
| 1358 | Modify the VLAN ID in the VLAN tag of a tagged packet and send to |
| 1359 | ingress port |
| 1360 | """ |
| 1361 | def setUp(self): |
| 1362 | BaseMatchCase.setUp(self) |
| 1363 | self.ing_port=True |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1364 | |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1365 | class ModifyVIDWithTagMatchWildcarded(BaseMatchCase): |
| 1366 | """ |
| 1367 | With vlan ID and priority wildcarded, perform SET_VLAN_VID action. |
| 1368 | The same flow should match on both untagged and tagged packets. |
| 1369 | """ |
| 1370 | def runTest(self): |
| 1371 | old_vid = 2 |
| 1372 | new_vid = 3 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1373 | sup_acts = self.supported_actions |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1374 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID): |
| 1375 | skip_message_emit(self, "ModifyVIDWithTagWildcarded test") |
| 1376 | return |
| 1377 | |
| 1378 | of_ports = pa_port_map.keys() |
| 1379 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 1380 | ing_port = of_ports[0] |
| 1381 | egr_ports = of_ports[1] |
| 1382 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1383 | rv = delete_all_flows(self.controller) |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1384 | self.assertEqual(rv, 0, "Failed to delete all flows") |
| 1385 | |
| 1386 | len_untagged = 100 |
| 1387 | len_w_vid = 104 |
| 1388 | untagged_pkt = simple_tcp_packet(pktlen=len_untagged) |
| 1389 | tagged_pkt = simple_tcp_packet(pktlen=len_w_vid, |
| 1390 | dl_vlan_enable=True, dl_vlan=old_vid) |
| 1391 | exp_pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1392 | dl_vlan=new_vid) |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1393 | wildcards = (required_wildcards(self) | ofp.OFPFW_DL_VLAN | |
| 1394 | ofp.OFPFW_DL_VLAN_PCP) |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1395 | vid_act = action.action_set_vlan_vid() |
| 1396 | vid_act.vlan_vid = new_vid |
| 1397 | request = flow_msg_create(self, untagged_pkt, ing_port=ing_port, |
| 1398 | wildcards=wildcards, egr_ports=egr_ports, |
| 1399 | action_list=[vid_act]) |
| 1400 | flow_msg_install(self, request) |
| 1401 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1402 | logging.debug("Send untagged packet: " + str(ing_port) + " to " + |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1403 | str(egr_ports)) |
| 1404 | self.dataplane.send(ing_port, str(untagged_pkt)) |
| 1405 | receive_pkt_verify(self, egr_ports, exp_pkt, ing_port) |
| 1406 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1407 | logging.debug("Send tagged packet: " + str(ing_port) + " to " + |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1408 | str(egr_ports)) |
| 1409 | self.dataplane.send(ing_port, str(tagged_pkt)) |
| 1410 | receive_pkt_verify(self, egr_ports, exp_pkt, ing_port) |
| 1411 | |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 1412 | class ModifyVlanPcp(BaseMatchCase): |
| 1413 | """ |
| 1414 | Modify the priority field of the VLAN tag of a tagged packet |
| 1415 | """ |
| 1416 | def runTest(self): |
| 1417 | vid = 123 |
| 1418 | old_vlan_pcp = 2 |
| 1419 | new_vlan_pcp = 3 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1420 | sup_acts = self.supported_actions |
Ed Swierk | 8c3af7f | 2012-04-24 14:19:17 -0700 | [diff] [blame] | 1421 | if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_PCP): |
| 1422 | skip_message_emit(self, "Modify VLAN priority test") |
Howard Persh | c1199d5 | 2012-04-11 14:21:32 -0700 | [diff] [blame] | 1423 | return |
| 1424 | |
| 1425 | pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=old_vlan_pcp) |
| 1426 | exp_pkt = simple_tcp_packet(dl_vlan_enable=True, dl_vlan=vid, dl_vlan_pcp=new_vlan_pcp) |
| 1427 | vid_act = action.action_set_vlan_pcp() |
| 1428 | vid_act.vlan_pcp = new_vlan_pcp |
| 1429 | |
| 1430 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1431 | action_list=[vid_act]) |
| 1432 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1433 | class StripVLANTag(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1434 | """ |
| 1435 | Strip the VLAN tag from a tagged packet |
| 1436 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1437 | def runTest(self): |
| 1438 | old_vid = 2 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1439 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1440 | if not (sup_acts & 1 << ofp.OFPAT_STRIP_VLAN): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1441 | skip_message_emit(self, "Strip VLAN tag test") |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1442 | return |
Dan Talayco | f36f108 | 2010-07-13 13:57:17 -0700 | [diff] [blame] | 1443 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1444 | len_w_vid = 104 |
| 1445 | len = 100 |
| 1446 | pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1447 | dl_vlan=old_vid) |
| 1448 | exp_pkt = simple_tcp_packet(pktlen=len) |
| 1449 | vid_act = action.action_strip_vlan() |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1450 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1451 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1452 | action_list=[vid_act]) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1453 | |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1454 | class StripVLANTagWithTagMatchWildcarded(BaseMatchCase): |
| 1455 | """ |
| 1456 | Strip the VLAN tag from a tagged packet. |
| 1457 | Differs from StripVLANTag in that VID and PCP are both wildcarded. |
| 1458 | """ |
| 1459 | def runTest(self): |
| 1460 | old_vid = 2 |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1461 | sup_acts = self.supported_actions |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1462 | if not (sup_acts & 1 << ofp.OFPAT_STRIP_VLAN): |
| 1463 | skip_message_emit(self, "StripVLANTagWithTagWildcarded test") |
| 1464 | return |
| 1465 | |
| 1466 | len_w_vid = 104 |
| 1467 | len_untagged = 100 |
| 1468 | pkt = simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, |
| 1469 | dl_vlan=old_vid) |
| 1470 | exp_pkt = simple_tcp_packet(pktlen=len_untagged) |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1471 | wildcards = (required_wildcards(self) | ofp.OFPFW_DL_VLAN | |
| 1472 | ofp.OFPFW_DL_VLAN_PCP) |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1473 | vid_act = action.action_strip_vlan() |
| 1474 | |
| 1475 | flow_match_test(self, pa_port_map, |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1476 | wildcards=wildcards, |
Ken Chiang | e9a211d | 2012-04-20 14:52:11 -0700 | [diff] [blame] | 1477 | pkt=pkt, exp_pkt=exp_pkt, |
| 1478 | action_list=[vid_act]) |
| 1479 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1480 | def init_pkt_args(): |
| 1481 | """ |
| 1482 | Pass back a dictionary with default packet arguments |
| 1483 | """ |
| 1484 | args = {} |
| 1485 | args["dl_src"] = '00:23:45:67:89:AB' |
| 1486 | |
| 1487 | dl_vlan_enable=False |
| 1488 | dl_vlan=-1 |
| 1489 | if pa_config["test-params"]["vid"]: |
| 1490 | dl_vlan_enable=True |
| 1491 | dl_vlan = pa_config["test-params"]["vid"] |
| 1492 | |
| 1493 | # Unpack operator is ** on a dictionary |
| 1494 | |
| 1495 | return args |
| 1496 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1497 | class ModifyL2Src(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1498 | """ |
| 1499 | Modify the source MAC address (TP1) |
| 1500 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1501 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1502 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1503 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1504 | skip_message_emit(self, "ModifyL2Src test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1505 | return |
| 1506 | |
| 1507 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'], |
| 1508 | check_test_params=True) |
| 1509 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1510 | action_list=acts, max_test=2) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1511 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1512 | class ModifyL2Dst(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1513 | """ |
| 1514 | Modify the dest MAC address (TP1) |
| 1515 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1516 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1517 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1518 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1519 | skip_message_emit(self, "ModifyL2dst test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1520 | return |
| 1521 | |
| 1522 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1523 | check_test_params=True) |
| 1524 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1525 | action_list=acts, max_test=2) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1526 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1527 | class ModifyL3Src(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1528 | """ |
| 1529 | Modify the source IP address of an IP packet (TP1) |
| 1530 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1531 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1532 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1533 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_SRC): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1534 | skip_message_emit(self, "ModifyL3Src test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1535 | return |
| 1536 | |
| 1537 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_src'], |
| 1538 | check_test_params=True) |
| 1539 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1540 | action_list=acts, max_test=2) |
Tatsuya Yabe | e6cae8b | 2010-05-25 18:20:04 -0700 | [diff] [blame] | 1541 | |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1542 | class ModifyL3Dst(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1543 | """ |
| 1544 | Modify the dest IP address of an IP packet (TP1) |
| 1545 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1546 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1547 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1548 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_DST): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1549 | skip_message_emit(self, "ModifyL3Dst test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1550 | return |
| 1551 | |
| 1552 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_dst'], |
| 1553 | check_test_params=True) |
| 1554 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1555 | action_list=acts, max_test=2) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1556 | |
| 1557 | class ModifyL4Src(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1558 | """ |
| 1559 | Modify the source TCP port of a TCP packet (TP1) |
| 1560 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1561 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1562 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1563 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_SRC): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1564 | skip_message_emit(self, "ModifyL4Src test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1565 | return |
| 1566 | |
| 1567 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_sport'], |
| 1568 | check_test_params=True) |
| 1569 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1570 | action_list=acts, max_test=2) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1571 | |
| 1572 | class ModifyL4Dst(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1573 | """ |
| 1574 | Modify the dest TCP port of a TCP packet (TP1) |
| 1575 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1576 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1577 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1578 | if not (sup_acts & 1 << ofp.OFPAT_SET_TP_DST): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1579 | skip_message_emit(self, "ModifyL4Dst test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1580 | return |
| 1581 | |
| 1582 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['tcp_dport'], |
| 1583 | check_test_params=True) |
| 1584 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1585 | action_list=acts, max_test=2) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1586 | |
| 1587 | class ModifyTOS(BaseMatchCase): |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1588 | """ |
| 1589 | Modify the IP type of service of an IP packet (TP1) |
| 1590 | """ |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1591 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1592 | sup_acts = self.supported_actions |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1593 | if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS): |
Dan Talayco | ba3745c | 2010-07-21 21:51:08 -0700 | [diff] [blame] | 1594 | skip_message_emit(self, "ModifyTOS test") |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1595 | return |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1596 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1597 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['ip_tos'], |
| 1598 | check_test_params=True) |
| 1599 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1600 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | 551befa | 2010-07-15 17:05:32 -0700 | [diff] [blame] | 1601 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1602 | class ModifyL2DstMC(BaseMatchCase): |
| 1603 | """ |
| 1604 | Modify the L2 dest and send to 2 ports |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1605 | """ |
| 1606 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1607 | sup_acts = self.supported_actions |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1608 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1609 | skip_message_emit(self, "ModifyL2dstMC test") |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1610 | return |
| 1611 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1612 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1613 | check_test_params=True) |
| 1614 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1615 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1616 | |
Dan Talayco | c948d0b | 2012-03-23 12:17:54 -0700 | [diff] [blame] | 1617 | class ModifyL2DstIngress(BaseMatchCase): |
| 1618 | """ |
| 1619 | Modify the L2 dest and send to the ingress port |
| 1620 | """ |
| 1621 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1622 | sup_acts = self.supported_actions |
Dan Talayco | c948d0b | 2012-03-23 12:17:54 -0700 | [diff] [blame] | 1623 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1624 | skip_message_emit(self, "ModifyL2dstIngress test") |
Dan Talayco | c948d0b | 2012-03-23 12:17:54 -0700 | [diff] [blame] | 1625 | return |
| 1626 | |
| 1627 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1628 | check_test_params=True) |
| 1629 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1630 | action_list=acts, max_test=2, egr_count=0, |
| 1631 | ing_port=True) |
| 1632 | |
Dan Talayco | d8ae758 | 2012-03-23 12:24:56 -0700 | [diff] [blame] | 1633 | class ModifyL2DstIngressMC(BaseMatchCase): |
| 1634 | """ |
| 1635 | Modify the L2 dest and send to the ingress port |
| 1636 | """ |
| 1637 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1638 | sup_acts = self.supported_actions |
Dan Talayco | d8ae758 | 2012-03-23 12:24:56 -0700 | [diff] [blame] | 1639 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST): |
| 1640 | skip_message_emit(self, "ModifyL2dstMC test") |
| 1641 | return |
| 1642 | |
| 1643 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_dst'], |
| 1644 | check_test_params=True) |
| 1645 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1646 | action_list=acts, max_test=2, egr_count=-1, |
| 1647 | ing_port=True) |
| 1648 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1649 | class ModifyL2SrcMC(BaseMatchCase): |
| 1650 | """ |
| 1651 | Modify the source MAC address (TP1) and send to multiple |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1652 | """ |
| 1653 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1654 | sup_acts = self.supported_actions |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1655 | if not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC): |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1656 | skip_message_emit(self, "ModifyL2SrcMC test") |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1657 | return |
| 1658 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1659 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=['dl_src'], |
| 1660 | check_test_params=True) |
| 1661 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1662 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1663 | |
| 1664 | class ModifyL2SrcDstMC(BaseMatchCase): |
| 1665 | """ |
| 1666 | Modify the L2 source and dest and send to 2 ports |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1667 | """ |
| 1668 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1669 | sup_acts = self.supported_actions |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1670 | if (not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST) or |
| 1671 | not (sup_acts & 1 << ofp.OFPAT_SET_DL_SRC)): |
| 1672 | skip_message_emit(self, "ModifyL2SrcDstMC test") |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1673 | return |
| 1674 | |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1675 | mod_fields = ['dl_dst', 'dl_src'] |
| 1676 | (pkt, exp_pkt, acts) = pkt_action_setup(self, mod_fields=mod_fields, |
| 1677 | check_test_params=True) |
| 1678 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1679 | action_list=acts, max_test=2, egr_count=-1) |
| 1680 | |
| 1681 | class ModifyL2DstVIDMC(BaseMatchCase): |
| 1682 | """ |
| 1683 | Modify the L2 dest and send to 2 ports |
| 1684 | """ |
| 1685 | def runTest(self): |
Ed Swierk | c7193a2 | 2012-08-22 06:51:02 -0700 | [diff] [blame] | 1686 | sup_acts = self.supported_actions |
Dan Talayco | cfa172f | 2012-03-23 12:03:00 -0700 | [diff] [blame] | 1687 | if (not (sup_acts & 1 << ofp.OFPAT_SET_DL_DST) or |
| 1688 | not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID)): |
| 1689 | skip_message_emit(self, "ModifyL2DstVIDMC test") |
| 1690 | return |
| 1691 | |
| 1692 | mod_fields = ['dl_dst', 'dl_vlan'] |
| 1693 | (pkt, exp_pkt, acts) = pkt_action_setup(self, |
| 1694 | start_field_vals={'dl_vlan_enable':True}, mod_fields=mod_fields, |
| 1695 | check_test_params=True) |
| 1696 | flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, |
| 1697 | action_list=acts, max_test=2, egr_count=-1) |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1698 | |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1699 | class FlowToggle(BaseMatchCase): |
| 1700 | """ |
| 1701 | Add flows to the table and modify them repeatedly |
Dan Talayco | f7c4131 | 2012-07-23 12:53:19 -0700 | [diff] [blame] | 1702 | |
| 1703 | This is done by using only "add" flow messages. Since the check overlap |
| 1704 | flag is not set, the switch is supposed to modify the existing flow if |
| 1705 | the match already exists. |
| 1706 | |
| 1707 | Would probably be better to exercise more of the flow modify commands |
| 1708 | (add, modify, delete +/- strict). |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1709 | """ |
| 1710 | def runTest(self): |
Dan Talayco | 50be767 | 2012-04-05 11:38:08 -0700 | [diff] [blame] | 1711 | flow_count = test_param_get(self.config, 'ft_flow_count', default=20) |
| 1712 | iter_count = test_param_get(self.config, 'ft_iter_count', default=10) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1713 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1714 | logging.info("Running flow toggle with %d flows, %d iterations" % |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1715 | (flow_count, iter_count)) |
| 1716 | acts = [] |
| 1717 | acts.append(action.action_output()) |
| 1718 | acts.append(action.action_output()) |
| 1719 | |
| 1720 | of_ports = pa_port_map.keys() |
| 1721 | if len(of_ports) < 3: |
| 1722 | self.assertTrue(False, "Too few ports for test") |
| 1723 | |
| 1724 | for idx in range(2): |
| 1725 | acts[idx].port = of_ports[idx] |
| 1726 | |
| 1727 | flows = [] |
| 1728 | flows.append([]) |
| 1729 | flows.append([]) |
| 1730 | |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1731 | wildcards = (required_wildcards(self) | ofp.OFPFW_DL_SRC | |
| 1732 | ofp.OFPFW_DL_DST) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1733 | # Create up the flows in an array |
| 1734 | for toggle in range(2): |
| 1735 | for f_idx in range(flow_count): |
| 1736 | pkt = simple_tcp_packet(tcp_sport=f_idx) |
| 1737 | msg = message.flow_mod() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 1738 | match = packet_to_flow_match(self, pkt) |
Shudong Zhou | 031373c | 2012-07-19 17:37:42 -0700 | [diff] [blame] | 1739 | match.in_port = of_ports[2] |
Dan Talayco | 50be767 | 2012-04-05 11:38:08 -0700 | [diff] [blame] | 1740 | match.wildcards = wildcards |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1741 | msg.match = match |
| 1742 | msg.buffer_id = 0xffffffff |
Dan Talayco | f7c4131 | 2012-07-23 12:53:19 -0700 | [diff] [blame] | 1743 | msg.command = ofp.OFPFC_ADD |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1744 | msg.actions.add(acts[toggle]) |
| 1745 | flows[toggle].append(msg) |
Dan Talayco | 50be767 | 2012-04-05 11:38:08 -0700 | [diff] [blame] | 1746 | |
| 1747 | # Show two sample flows |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1748 | logging.debug(flows[0][0].show()) |
| 1749 | logging.debug(flows[1][0].show()) |
Dan Talayco | 50be767 | 2012-04-05 11:38:08 -0700 | [diff] [blame] | 1750 | |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1751 | # Install the first set of flows |
| 1752 | for f_idx in range(flow_count): |
| 1753 | rv = self.controller.message_send(flows[0][f_idx]) |
| 1754 | self.assertTrue(rv != -1, "Error installing flow %d" % f_idx) |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 1755 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1756 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1757 | logging.info("Installed %d flows" % flow_count) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1758 | |
| 1759 | # Repeatedly modify all the flows back and forth |
| 1760 | updates = 0 |
| 1761 | # Report status about 5 times |
| 1762 | mod_val = (iter_count / 4) + 1 |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1763 | start = time.time() |
| 1764 | for iter_idx in range(iter_count): |
| 1765 | if not iter_idx % mod_val: |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1766 | logging.info("Flow Toggle: iter %d of %d. " % |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1767 | (iter_idx, iter_count) + |
| 1768 | "%d updates in %d secs" % |
| 1769 | (updates, time.time() - start)) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1770 | for toggle in range(2): |
| 1771 | t_idx = 1 - toggle |
| 1772 | for f_idx in range(flow_count): |
| 1773 | rv = self.controller.message_send(flows[t_idx][f_idx]) |
| 1774 | updates += 1 |
| 1775 | self.assertTrue(rv != -1, "Error modifying flow %d" % |
| 1776 | f_idx) |
Dan Talayco | 0fc08bd | 2012-04-09 16:56:18 -0700 | [diff] [blame] | 1777 | self.assertEqual(do_barrier(self.controller), 0, |
| 1778 | "Barrier failed") |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1779 | |
| 1780 | end = time.time() |
| 1781 | divisor = end - start or (end - start + 1) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1782 | logging.info("Flow toggle: %d iterations" % iter_count) |
| 1783 | logging.info(" %d flow mods in %d secs, %d mods/sec" % |
Dan Talayco | abbfdbb | 2012-04-05 10:29:26 -0700 | [diff] [blame] | 1784 | (updates, end - start, updates/divisor)) |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1785 | |
| 1786 | |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1787 | # You can pick and choose these by commenting tests in or out |
| 1788 | iter_classes = [ |
| 1789 | basic.PacketIn, |
| 1790 | basic.PacketOut, |
| 1791 | DirectPacket, |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1792 | FlowToggle, |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1793 | DirectTwoPorts, |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1794 | DirectMCNonIngress, |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1795 | AllWildcardMatch, |
| 1796 | AllWildcardMatchTagged, |
| 1797 | SingleWildcardMatch, |
| 1798 | SingleWildcardMatchTagged, |
| 1799 | ExactMatch, |
| 1800 | ExactMatchTagged, |
| 1801 | SingleWildcardMatch, |
| 1802 | ModifyL2Src, |
| 1803 | ModifyL2Dst, |
| 1804 | ModifyL2SrcMC, |
| 1805 | ModifyL2DstMC, |
| 1806 | ModifyL2SrcDstMC |
| 1807 | ] |
| 1808 | |
| 1809 | class IterCases(BaseMatchCase): |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1810 | """ |
| 1811 | Iterate over a bunch of test cases |
| 1812 | |
| 1813 | The cases come from the list above |
| 1814 | """ |
| 1815 | |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1816 | def runTest(self): |
| 1817 | count = test_param_get(self.config, 'iter_count', default=10) |
| 1818 | tests_done = 0 |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1819 | logging.info("Running iteration test " + str(count) + " times") |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1820 | start = time.time() |
| 1821 | last = start |
| 1822 | for idx in range(count): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1823 | logging.info("Iteration " + str(idx + 1)) |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1824 | for cls in iter_classes: |
| 1825 | test = cls() |
| 1826 | test.inheritSetup(self) |
| 1827 | test.runTest() |
| 1828 | tests_done += 1 |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1829 | # Report update about every minute, between tests |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1830 | if time.time() - last > 60: |
| 1831 | last = time.time() |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1832 | logging.info( |
Dan Talayco | fa6454f | 2012-04-05 10:04:13 -0700 | [diff] [blame] | 1833 | "IterCases: Iter %d of %d; Ran %d tests in %d " % |
| 1834 | (idx, count, tests_done, last - start) + |
| 1835 | "seconds so far") |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1836 | stats = all_stats_get(self) |
| 1837 | last = time.time() |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1838 | logging.info("\nIterCases ran %d tests in %d seconds." % |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1839 | (tests_done, last - start)) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1840 | logging.info(" flows: %d. packets: %d. bytes: %d" % |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1841 | (stats["flows"], stats["packets"], stats["bytes"])) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1842 | logging.info(" active: %d. lookups: %d. matched %d." % |
Dan Talayco | 8a64e33 | 2012-03-28 14:53:20 -0700 | [diff] [blame] | 1843 | (stats["active"], stats["lookups"], stats["matched"])) |
| 1844 | |
| 1845 | # Don't run by default |
| 1846 | test_prio["IterCases"] = -1 |
Dan Talayco | f6e76c0 | 2012-03-23 10:56:12 -0700 | [diff] [blame] | 1847 | |
Dan Talayco | 4b2bee6 | 2010-07-20 14:10:05 -0700 | [diff] [blame] | 1848 | #@todo Need to implement tagged versions of the above tests |
| 1849 | # |
| 1850 | #@todo Implement a test case that strips tag 2, adds tag 3 |
| 1851 | # and modifies tag 4 to tag 5. Then verify (in addition) that |
| 1852 | # tag 6 does not get modified. |
| 1853 | |
| 1854 | class MixedVLAN(BaseMatchCase): |
| 1855 | """ |
| 1856 | Test mixture of VLAN tag actions |
| 1857 | |
| 1858 | Strip tag 2 on port 1, send to port 2 |
| 1859 | Add tag 3 on port 1, send to port 2 |
| 1860 | Modify tag 4 to 5 on port 1, send to port 2 |
| 1861 | All other traffic from port 1, send to port 3 |
| 1862 | All traffic from port 2 sent to port 4 |
| 1863 | Use exact matches with different packets for all mods |
| 1864 | Verify the following: (port, vid) |
| 1865 | (port 1, vid 2) => VLAN tag stripped, out port 2 |
| 1866 | (port 1, no tag) => tagged packet w/ vid 2 out port 2 |
| 1867 | (port 1, vid 4) => tagged packet w/ vid 5 out port 2 |
| 1868 | (port 1, vid 5) => tagged packet w/ vid 5 out port 2 |
| 1869 | (port 1, vid 6) => tagged packet w/ vid 6 out port 2 |
| 1870 | (port 2, no tag) => untagged packet out port 4 |
| 1871 | (port 2, vid 2-6) => unmodified packet out port 4 |
| 1872 | |
| 1873 | Variation: Might try sending VID 5 to port 3 and check. |
| 1874 | If only VID 5 distinguishes pkt, this will fail on some platforms |
| 1875 | """ |
| 1876 | |
| 1877 | test_prio["MixedVLAN"] = -1 |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1878 | |
| 1879 | class MatchEach(basic.SimpleDataPlane): |
| 1880 | """ |
| 1881 | Check that each match field is actually matched on. |
| 1882 | Installs two flows that differ in one field. The flow that should not |
| 1883 | match has a higher priority, so if that field is ignored during matching |
| 1884 | the packet will be sent out the wrong port. |
| 1885 | |
| 1886 | TODO test UDP, ARP, ICMP, etc. |
| 1887 | """ |
| 1888 | def runTest(self): |
| 1889 | of_ports = pa_port_map.keys() |
| 1890 | of_ports.sort() |
| 1891 | self.assertTrue(len(of_ports) > 1, "Not enough ports for test") |
| 1892 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1893 | delete_all_flows(self.controller) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1894 | |
| 1895 | pkt = simple_tcp_packet() |
| 1896 | ingress_port = of_ports[0] |
| 1897 | egress_port = of_ports[1] |
| 1898 | |
| 1899 | def testField(field, mask): |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1900 | logging.info("Testing field %s" % field) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1901 | |
| 1902 | def addFlow(matching, priority, output_port): |
| 1903 | match = packet_to_flow_match(self, pkt) |
| 1904 | self.assertTrue(match is not None, "Could not generate flow match from pkt") |
| 1905 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 1906 | match.in_port = ingress_port |
| 1907 | if not matching: |
| 1908 | # Make sure flow doesn't match |
| 1909 | orig = getattr(match, field) |
| 1910 | if isinstance(orig, list): |
| 1911 | new = map(lambda a: ~a[0] & a[1], zip(orig, mask)) |
| 1912 | else: |
| 1913 | new = ~orig & mask |
| 1914 | setattr(match, field, new) |
| 1915 | request = message.flow_mod() |
| 1916 | request.match = match |
| 1917 | request.buffer_id = 0xffffffff |
| 1918 | request.priority = priority |
| 1919 | act = action.action_output() |
| 1920 | act.port = output_port |
| 1921 | self.assertTrue(request.actions.add(act), "Could not add action") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1922 | logging.info("Inserting flow") |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1923 | self.controller.message_send(request) |
| 1924 | |
| 1925 | # This flow should match. |
| 1926 | addFlow(matching=True, priority=0, output_port=egress_port) |
| 1927 | # This flow should not match, but it has a higher priority. |
| 1928 | addFlow(matching=False, priority=1, output_port=ofp.OFPP_IN_PORT) |
| 1929 | |
| 1930 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 1931 | |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1932 | logging.info("Sending packet to dp port " + str(ingress_port)) |
Rich Lane | 8d6ab27 | 2012-09-23 18:06:20 -0700 | [diff] [blame] | 1933 | self.dataplane.send(ingress_port, str(pkt)) |
| 1934 | |
| 1935 | exp_pkt_arg = None |
| 1936 | exp_port = None |
| 1937 | if pa_config["relax"]: |
| 1938 | exp_pkt_arg = pkt |
| 1939 | exp_port = egress_port |
| 1940 | |
| 1941 | (rcv_port, rcv_pkt, pkt_time) = self.dataplane.poll(port_number=exp_port, |
| 1942 | exp_pkt=exp_pkt_arg) |
| 1943 | self.assertTrue(rcv_pkt is not None, "Did not receive packet") |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame^] | 1944 | 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] | 1945 | self.assertEqual(rcv_port, egress_port, "Unexpected receive port") |
| 1946 | self.assertEqual(str(pkt), str(rcv_pkt), 'Response packet does not match send packet') |
| 1947 | |
| 1948 | # TODO in_port |
| 1949 | testField("dl_src", [0xff]*6) |
| 1950 | testField("dl_dst", [0xff]*6) |
| 1951 | testField("dl_type", 0xffff) |
| 1952 | testField("dl_vlan", 0xfff) |
| 1953 | # TODO dl_vlan_pcp |
| 1954 | testField("nw_src", 0xffffffff) |
| 1955 | testField("nw_dst", 0xffffffff) |
| 1956 | testField("nw_tos", 0x3f) |
| 1957 | testField("nw_proto", 0xff) |
| 1958 | testField("tp_src", 0xffff) |
| 1959 | testField("tp_dst", 0xffff) |
| 1960 | |
Dan Talayco | 9f47f4d | 2010-06-03 13:54:37 -0700 | [diff] [blame] | 1961 | if __name__ == "__main__": |
| 1962 | print "Please run through oft script: ./oft --test_spec=basic" |