blob: ad6a1903d7b2ff1526d58445fef579fef4f8aa2c [file] [log] [blame]
Flavio Castro05d20bc2015-11-16 15:06:14 -05001"""
Flavio Castroc36621e2015-12-08 12:57:07 -05002The following tests are being done here
Flavio Castro3aec8902015-11-20 10:51:38 -050031) PacketInSrcMacMiss
castroflavio9e715f32015-12-08 14:04:12 -050042) VlanSupport
53) L2FloodQinQ
64) L2FloodTagged
75) L2Flood Tagged Unknown Src
86) L2 Unicast Tagged
97) MTU 1500
108) MTU 4100
119) MTU 4500
1210) L3UnicastTagged
1311) L3VPNMPLS
1412) MPLS Termination
Flavio Castro05d20bc2015-11-16 15:06:14 -050015"""
Flavio Castro1c9b1252016-02-04 18:42:58 -050016import Queue
Flavio Castro05d20bc2015-11-16 15:06:14 -050017
Flavio Castro05d20bc2015-11-16 15:06:14 -050018from oftest import config
Flavio Castro67d8bd52016-02-03 14:22:14 -050019import inspect
Flavio Castro167f5bd2015-12-02 19:33:53 -050020import logging
21import oftest.base_tests as base_tests
Flavio Castro05d20bc2015-11-16 15:06:14 -050022import ofp
23from oftest.testutils import *
24from accton_util import *
Flavio Castrod8f8af22015-12-02 18:19:26 -050025
Flavio Castro1c9b1252016-02-04 18:42:58 -050026
Flavio Castro7fb6ca92015-12-16 15:50:14 -050027class PacketInUDP(base_tests.SimpleDataPlane):
Flavio Castro6d498522015-12-15 14:05:04 -050028 """
Flavio Castro1c9b1252016-02-04 18:42:58 -050029 Verify a ACL rule that matches on IP_PROTO 2 will not match a UDP packet.
30 Next it verify a rule that matches on IP_PROTO 17 WILL match a UDP packet.
Flavio Castro6d498522015-12-15 14:05:04 -050031 """
32
33 def runTest(self):
Flavio Castro1c9b1252016-02-04 18:42:58 -050034 parsed_vlan_pkt = simple_udp_packet(pktlen=104,
35 vlan_vid=0x1001,
36 dl_vlan_enable=True)
Flavio Castro6d498522015-12-15 14:05:04 -050037 vlan_pkt = str(parsed_vlan_pkt)
Flavio Castro6d498522015-12-15 14:05:04 -050038 # create match
39 match = ofp.match()
40 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
Flavio Castro1c9b1252016-02-04 18:42:58 -050041 match.oxm_list.append(ofp.oxm.ip_proto(2))
Flavio Castro6d498522015-12-15 14:05:04 -050042 request = ofp.message.flow_add(
Flavio Castro1c9b1252016-02-04 18:42:58 -050043 table_id=60,
44 cookie=42,
45 match=match,
46 instructions=[
47 ofp.instruction.apply_actions(
48 actions=[
49 ofp.action.output(
50 port=ofp.OFPP_CONTROLLER,
51 max_len=ofp.OFPCML_NO_BUFFER)]), ],
52 buffer_id=ofp.OFP_NO_BUFFER,
53 priority=1)
54 logging.info("Inserting packet in flow to controller")
55 self.controller.message_send(request)
56
57 for of_port in config["port_map"].keys():
58 logging.info("PacketInMiss test, port %d", of_port)
59 self.dataplane.send(of_port, vlan_pkt)
60
61 verify_no_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
Flavio Castro6d498522015-12-15 14:05:04 -050062
63 logging.info("Inserting packet in flow to controller")
64 self.controller.message_send(request)
65 do_barrier(self.controller)
66
Flavio Castro1c9b1252016-02-04 18:42:58 -050067 delete_all_flows(self.controller)
68
69 match = ofp.match()
70 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
71 match.oxm_list.append(ofp.oxm.ip_proto(17))
72 request = ofp.message.flow_add(
73 table_id=60,
74 cookie=42,
75 match=match,
76 instructions=[
77 ofp.instruction.apply_actions(
78 actions=[
79 ofp.action.output(
80 port=ofp.OFPP_CONTROLLER,
81 max_len=ofp.OFPCML_NO_BUFFER)]), ],
82 buffer_id=ofp.OFP_NO_BUFFER,
83 priority=1)
84 logging.info("Inserting packet in flow to controller")
85 self.controller.message_send(request)
86
Flavio Castro6d498522015-12-15 14:05:04 -050087 for of_port in config["port_map"].keys():
88 logging.info("PacketInMiss test, port %d", of_port)
89 self.dataplane.send(of_port, vlan_pkt)
90
91 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
92
93 verify_no_other_packets(self)
Flavio Castroaf2b4502016-02-02 17:41:32 -050094
Flavio Castro1c9b1252016-02-04 18:42:58 -050095 delete_all_flows(self.controller)
96
Flavio Castroaf2b4502016-02-02 17:41:32 -050097
Flavio Castro67d8bd52016-02-03 14:22:14 -050098@disabled
Flavio Castro7fb6ca92015-12-16 15:50:14 -050099class ArpNL2(base_tests.SimpleDataPlane):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500100 def runTest(self):
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500101 delete_all_flows(self.controller)
102 delete_all_groups(self.controller)
103
104 ports = sorted(config["port_map"].keys())
105 match = ofp.match()
106 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
107 request = ofp.message.flow_add(
Flavio Castro1c9b1252016-02-04 18:42:58 -0500108 table_id=60,
109 cookie=42,
110 match=match,
111 instructions=[
112 ofp.instruction.apply_actions(
113 actions=[
114 ofp.action.output(
115 port=ofp.OFPP_CONTROLLER,
116 max_len=ofp.OFPCML_NO_BUFFER)]),
117 ],
118 buffer_id=ofp.OFP_NO_BUFFER,
119 priority=40000)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500120 self.controller.message_send(request)
121 for port in ports:
Flavio Castro932014b2016-01-05 18:29:15 -0500122 add_one_l2_interface_group(self.controller, port, 1, False, False)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500123 add_one_vlan_table_flow(self.controller, port, 1,
124 flag=VLAN_TABLE_FLAG_ONLY_BOTH)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500125 group_id = encode_l2_interface_group_id(1, port)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500126 add_bridge_flow(self.controller,
127 [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id,
128 True)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500129 do_barrier(self.controller)
130 parsed_arp_pkt = simple_arp_packet()
131 arp_pkt = str(parsed_arp_pkt)
132
133 for out_port in ports:
134 self.dataplane.send(out_port, arp_pkt)
135 verify_packet_in(self, arp_pkt, out_port, ofp.OFPR_ACTION)
136 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500137 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500138 for in_port in ports:
139 if in_port == out_port:
140 continue
141 # change source based on port number to avoid packet-ins from learning
Flavio Castro1c9b1252016-02-04 18:42:58 -0500142 mac_src = '00:12:34:56:78:%02X' % in_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500143 parsed_pkt = simple_tcp_packet(eth_dst=mac_dst, eth_src=mac_src)
144 pkt = str(parsed_pkt)
145 self.dataplane.send(in_port, pkt)
146
147 for ofport in ports:
148 if ofport in [out_port]:
149 verify_packet(self, pkt, ofport)
150 else:
151 verify_no_packet(self, pkt, ofport)
152
153 verify_no_other_packets(self)
154
Flavio Castro1c9b1252016-02-04 18:42:58 -0500155
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500156class PacketInArp(base_tests.SimpleDataPlane):
157 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500158 Verify an ACL rule matching on ethertyper 0x806 will result in a packet-in
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500159 """
160
161 def runTest(self):
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500162 parsed_arp_pkt = simple_arp_packet()
163 arp_pkt = str(parsed_arp_pkt)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500164 # create match
165 match = ofp.match()
166 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
167 request = ofp.message.flow_add(
Flavio Castro1c9b1252016-02-04 18:42:58 -0500168 table_id=60,
169 cookie=42,
170 match=match,
171 instructions=[
172 ofp.instruction.apply_actions(
173 actions=[
174 ofp.action.output(
175 port=ofp.OFPP_CONTROLLER,
176 max_len=ofp.OFPCML_NO_BUFFER)]),
177 ],
178 buffer_id=ofp.OFP_NO_BUFFER,
179 priority=1)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500180
181 logging.info("Inserting packet in flow to controller")
182 self.controller.message_send(request)
183 do_barrier(self.controller)
184
185 for of_port in config["port_map"].keys():
186 logging.info("PacketInMiss test, port %d", of_port)
187 self.dataplane.send(of_port, arp_pkt)
188
189 verify_packet_in(self, arp_pkt, of_port, ofp.OFPR_ACTION)
190
191 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500192 delete_all_flows(self.controller)
193
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500194
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500195class L2FloodQinQ(base_tests.SimpleDataPlane):
196 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500197 Verify a tagged frame can be flooded based on its outer vlan
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500198 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500199
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500200 def runTest(self):
201 ports = sorted(config["port_map"].keys())
Flavio Castro1c9b1252016-02-04 18:42:58 -0500202 vlan_id = 1
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500203
Flavio Castro1c9b1252016-02-04 18:42:58 -0500204 Groups = Queue.LifoQueue()
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500205 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500206 L2gid, l2msg = add_one_l2_interface_group(self.controller, port,
207 vlan_id, True, False)
208 add_one_vlan_table_flow(self.controller, port, vlan_id,
209 flag=VLAN_TABLE_FLAG_ONLY_TAG)
210 Groups.put(L2gid)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500211
Flavio Castro1c9b1252016-02-04 18:42:58 -0500212 msg = add_l2_flood_group(self.controller, ports, vlan_id, vlan_id)
Flavio Castro8628adb2016-02-03 17:30:57 -0500213 add_bridge_flow(self.controller, None, vlan_id, msg.group_id, True)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500214 do_barrier(self.controller)
215
Flavio Castro1c9b1252016-02-04 18:42:58 -0500216 # verify flood
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500217 for ofport in ports:
218 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500219 mac_src = '00:12:34:56:78:%02X' % ofport
220 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108,
221 out_dl_vlan_enable=True,
222 out_vlan_vid=vlan_id,
223 in_dl_vlan_enable=True,
224 in_vlan_vid=10,
225 eth_dst='00:12:34:56:78:9a',
226 eth_src=mac_src)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500227 pkt = str(parsed_pkt)
228 self.dataplane.send(ofport, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500229 # self won't rx packet
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500230 verify_no_packet(self, pkt, ofport)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500231 # others will rx packet
232 tmp_ports = list(ports)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500233 tmp_ports.remove(ofport)
234 verify_packets(self, pkt, tmp_ports)
235
236 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500237 delete_all_flows(self.controller)
238 delete_groups(self.controller, Groups)
239
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500240
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500241@disabled
Flavio Castro184cefe2015-11-19 20:52:49 -0500242class L2FloodTagged(base_tests.SimpleDataPlane):
243 """
244 Test L2 flood to a vlan
245 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
Flavio Castro184cefe2015-11-19 20:52:49 -0500246 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500247
Flavio Castro184cefe2015-11-19 20:52:49 -0500248 def runTest(self):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500249 # Hashes Test Name and uses it as id for installing unique groups
250 vlan_id = abs(hash(inspect.stack()[0][3])) % (256)
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500251 print vlan_id
Flavio Castroaba28ff2016-02-03 16:47:48 -0500252
Flavio Castro184cefe2015-11-19 20:52:49 -0500253 ports = sorted(config["port_map"].keys())
Flavio Castro34352e72015-12-07 20:01:51 -0500254
Flavio Castro184cefe2015-11-19 20:52:49 -0500255 delete_all_flows(self.controller)
256 delete_all_groups(self.controller)
257
Flavio Castro184cefe2015-11-19 20:52:49 -0500258 # Installing flows to avoid packet-in
259 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500260 add_one_l2_interface_group(self.controller, port, vlan_id, True,
261 False)
262 add_one_vlan_table_flow(self.controller, port, vlan_id,
263 flag=VLAN_TABLE_FLAG_ONLY_TAG)
264 msg = add_l2_flood_group(self.controller, ports, vlan_id, vlan_id)
Flavio Castroaba28ff2016-02-03 16:47:48 -0500265 add_bridge_flow(self.controller, None, vlan_id, msg.group_id, True)
Flavio Castro184cefe2015-11-19 20:52:49 -0500266 do_barrier(self.controller)
267
Flavio Castro1c9b1252016-02-04 18:42:58 -0500268 # verify flood
Flavio Castro184cefe2015-11-19 20:52:49 -0500269 for ofport in ports:
270 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500271 pkt = str(simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vlan_id,
272 eth_dst='00:12:34:56:78:9a'))
Flavio Castro184cefe2015-11-19 20:52:49 -0500273 self.dataplane.send(ofport, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500274 # self won't rx packet
Flavio Castro184cefe2015-11-19 20:52:49 -0500275 verify_no_packet(self, pkt, ofport)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500276 # others will rx packet
277 tmp_ports = list(ports)
Flavio Castro184cefe2015-11-19 20:52:49 -0500278 tmp_ports.remove(ofport)
279 verify_packets(self, pkt, tmp_ports)
Flavio Castro184cefe2015-11-19 20:52:49 -0500280 verify_no_other_packets(self)
Flavio Castroaabb5792015-11-18 19:03:50 -0500281
Flavio Castro1c9b1252016-02-04 18:42:58 -0500282
Flavio Castroaabb5792015-11-18 19:03:50 -0500283class L2UnicastTagged(base_tests.SimpleDataPlane):
284 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500285 Verify L2 forwarding works
Flavio Castroaabb5792015-11-18 19:03:50 -0500286 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500287
Flavio Castroaabb5792015-11-18 19:03:50 -0500288 def runTest(self):
289 ports = sorted(config["port_map"].keys())
Flavio Castro1c9b1252016-02-04 18:42:58 -0500290 vlan_id = 1;
291 Groups = Queue.LifoQueue()
Flavio Castroaabb5792015-11-18 19:03:50 -0500292 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500293 L2gid, l2msg = add_one_l2_interface_group(self.controller, port,
294 vlan_id, True, False)
295 add_one_vlan_table_flow(self.controller, port, vlan_id,
296 flag=VLAN_TABLE_FLAG_ONLY_TAG)
297 Groups.put(L2gid)
298 add_bridge_flow(self.controller,
299 [0x00, 0x12, 0x34, 0x56, 0x78, port], vlan_id,
300 L2gid, True)
Flavio Castro6efe1862015-11-18 16:28:06 -0500301 do_barrier(self.controller)
302
Flavio Castroaabb5792015-11-18 19:03:50 -0500303 for out_port in ports:
304 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500305 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castroaabb5792015-11-18 19:03:50 -0500306 for in_port in ports:
307 if in_port == out_port:
308 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -0500309 pkt = str(
310 simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vlan_id,
311 eth_dst=mac_dst))
Flavio Castroaabb5792015-11-18 19:03:50 -0500312 self.dataplane.send(in_port, pkt)
Flavio Castroaabb5792015-11-18 19:03:50 -0500313 for ofport in ports:
314 if ofport in [out_port]:
315 verify_packet(self, pkt, ofport)
316 else:
317 verify_no_packet(self, pkt, ofport)
Flavio Castroaabb5792015-11-18 19:03:50 -0500318 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500319 delete_all_flows(self.controller)
320 delete_groups(self.controller, Groups)
321
Flavio Castro6efe1862015-11-18 16:28:06 -0500322
Flavio Castrob6773032015-11-19 22:49:24 -0500323class Mtu1500(base_tests.SimpleDataPlane):
Flavio Castrob6773032015-11-19 22:49:24 -0500324 def runTest(self):
325 ports = sorted(config["port_map"].keys())
Flavio Castro1c9b1252016-02-04 18:42:58 -0500326 vlan_id = 18
327 Groups = Queue.LifoQueue()
Flavio Castrob6773032015-11-19 22:49:24 -0500328 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500329 L2gid, msg = add_one_l2_interface_group(self.controller, port,
330 vlan_id, True, False)
331 add_one_vlan_table_flow(self.controller, port, vlan_id,
332 flag=VLAN_TABLE_FLAG_ONLY_TAG)
333 Groups.put(L2gid)
334 add_bridge_flow(self.controller,
335 [0x00, 0x12, 0x34, 0x56, 0x78, port], vlan_id,
336 L2gid, True)
Flavio Castrob6773032015-11-19 22:49:24 -0500337 do_barrier(self.controller)
338
339 for out_port in ports:
340 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500341 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castrob6773032015-11-19 22:49:24 -0500342 for in_port in ports:
343 if in_port == out_port:
344 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -0500345 pkt = str(simple_tcp_packet(pktlen=1500, dl_vlan_enable=True,
346 vlan_vid=vlan_id, eth_dst=mac_dst))
Flavio Castrob6773032015-11-19 22:49:24 -0500347 self.dataplane.send(in_port, pkt)
Flavio Castrob6773032015-11-19 22:49:24 -0500348 for ofport in ports:
349 if ofport in [out_port]:
350 verify_packet(self, pkt, ofport)
351 else:
352 verify_no_packet(self, pkt, ofport)
Flavio Castrob6773032015-11-19 22:49:24 -0500353 verify_no_other_packets(self)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500354 delete_all_flows(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500355 delete_groups(self.controller, Groups)
356
357
358class _32UcastTagged(base_tests.SimpleDataPlane):
359 """
360 Verify a IP forwarding works for a /32 rule to L3 Unicast Interface
361 """
362
363 def runTest(self):
364 test_id = 26
365 if len(config["port_map"]) < 2:
Flavio Castro05d20bc2015-11-16 15:06:14 -0500366 logging.info("Port count less than 2, can't run this case")
367 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500368
Flavio Castro1c9b1252016-02-04 18:42:58 -0500369 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
370 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
371 dip = 0xc0a80001
Flavio Castroa8233862015-12-02 14:41:11 -0500372 ports = config["port_map"].keys()
Flavio Castro1c9b1252016-02-04 18:42:58 -0500373 Groups = Queue.LifoQueue()
Flavio Castroa8233862015-12-02 14:41:11 -0500374 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500375 # add l2 interface group
376 vlan_id = port + test_id
377 l2gid, msg = add_one_l2_interface_group(self.controller, port,
378 vlan_id=vlan_id,
379 is_tagged=True,
380 send_barrier=False)
381 dst_mac[5] = vlan_id
382 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
383 id=vlan_id, src_mac=intf_src_mac,
384 dst_mac=dst_mac)
385 # add vlan flow table
386 add_one_vlan_table_flow(self.controller, port, vlan_id,
387 flag=VLAN_TABLE_FLAG_ONLY_TAG)
388 # add termination flow
389 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
390 vlan_id)
391 # add unicast routing flow
392 dst_ip = dip + (vlan_id << 8)
393 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
394 0xffffffff, l3_msg.group_id)
395 Groups.put(l2gid)
396 Groups.put(l3_msg.group_id)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500397 do_barrier(self.controller)
398
Flavio Castro05d20bc2015-11-16 15:06:14 -0500399 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
Flavio Castroa8233862015-12-02 14:41:11 -0500400 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500401 mac_src = '00:00:00:22:22:%02X' % (test_id + in_port)
402 ip_src = '192.168.%02d.1' % (test_id + in_port)
Flavio Castroa8233862015-12-02 14:41:11 -0500403 for out_port in ports:
404 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500405 continue
406 ip_dst = '192.168.%02d.1' % (test_id + out_port)
407 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
408 vlan_vid=(test_id + in_port),
409 eth_dst=switch_mac,
410 eth_src=mac_src, ip_ttl=64,
411 ip_src=ip_src,
412 ip_dst=ip_dst)
413 pkt = str(parsed_pkt)
Flavio Castroa8233862015-12-02 14:41:11 -0500414 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500415 # build expected packet
416 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
417 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
418 vlan_vid=(test_id + out_port),
419 eth_dst=mac_dst, eth_src=switch_mac,
420 ip_ttl=63,
421 ip_src=ip_src, ip_dst=ip_dst)
422 pkt = str(exp_pkt)
Flavio Castroa8233862015-12-02 14:41:11 -0500423 verify_packet(self, pkt, out_port)
424 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500425 delete_all_flows(self.controller)
426 delete_groups(self.controller, Groups)
427
Flavio Castro05d20bc2015-11-16 15:06:14 -0500428
Flavio Castrod8f8af22015-12-02 18:19:26 -0500429class L3VPNMPLS(base_tests.SimpleDataPlane):
430 """
431 Insert IP packet
432 Receive MPLS packet
433 """
Flavio Castro72a45d52015-12-02 16:37:05 -0500434
Flavio Castro1c9b1252016-02-04 18:42:58 -0500435 def runTest(self):
436 if len(config["port_map"]) < 2:
Flavio Castro72a45d52015-12-02 16:37:05 -0500437 logging.info("Port count less than 2, can't run this case")
438 return
Flavio Castro1c9b1252016-02-04 18:42:58 -0500439 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
440 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
441 dip = 0xc0a80001
442 Groups = Queue.LifoQueue()
Flavio Castro72a45d52015-12-02 16:37:05 -0500443 ports = config["port_map"].keys()
444 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500445 # add l2 interface group
446 id = port
447 vlan_id = id
448 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
449 vlan_id, True, True)
450 dst_mac[5] = vlan_id
451 # add MPLS interface group
452 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
453 dst_mac, intf_src_mac,
454 vlan_id, id)
455 # add MPLS L3 VPN group
456 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
457 self.controller,
458 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
459 index=id, ref_gid=mpls_gid, push_mpls_header=True,
460 set_mpls_label=port, set_bos=1, set_ttl=32)
461 ecmp_msg = add_l3_ecmp_group(self.controller, id, [mpls_label_gid])
Flavio Castro80730822015-12-11 15:38:47 -0500462 do_barrier(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500463 # add vlan flow table
464 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0,
465 flag=VLAN_TABLE_FLAG_ONLY_TAG)
466 # add termination flow
467 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
468 vlan_id)
469 # add routing flow
470 dst_ip = dip + (vlan_id << 8)
471 # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
472 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
473 0xffffff00, ecmp_msg.group_id, vrf=0)
474 Groups._put(l2_gid)
475 Groups._put(mpls_gid)
476 Groups._put(mpls_label_gid)
477 Groups._put(ecmp_msg.group_id)
Flavio Castro80730822015-12-11 15:38:47 -0500478
479 do_barrier(self.controller)
480
481 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
482 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500483 mac_src = '00:00:00:22:22:%02X' % (in_port)
484 ip_src = '192.168.%02d.1' % (in_port)
Flavio Castro80730822015-12-11 15:38:47 -0500485 for out_port in ports:
486 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500487 continue
488 ip_dst = '192.168.%02d.1' % (out_port)
489 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
490 vlan_vid=(in_port),
491 eth_dst=switch_mac,
492 eth_src=mac_src, ip_ttl=64,
493 ip_src=ip_src,
494 ip_dst=ip_dst)
495 pkt = str(parsed_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500496 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500497 # build expect packet
498 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castro80730822015-12-11 15:38:47 -0500499 label = (out_port, 0, 1, 32)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500500 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
501 vlan_vid=(out_port), ip_ttl=63,
502 ip_src=ip_src,
503 ip_dst=ip_dst, eth_dst=mac_dst,
504 eth_src=switch_mac, label=[label])
505 pkt = str(exp_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500506 verify_packet(self, pkt, out_port)
507 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500508 delete_all_flows(self.controller)
509 delete_groups(self.controller, Groups)
510
castroflavioee294842016-01-06 15:54:28 -0800511
Flavio Castro67d8bd52016-02-03 14:22:14 -0500512class _32VPN(base_tests.SimpleDataPlane):
Flavio Castro80730822015-12-11 15:38:47 -0500513 """
514 Insert IP packet
515 Receive MPLS packet
516 """
Flavio Castro80730822015-12-11 15:38:47 -0500517
Flavio Castro1c9b1252016-02-04 18:42:58 -0500518 def runTest(self):
519 if len(config["port_map"]) < 2:
Flavio Castro80730822015-12-11 15:38:47 -0500520 logging.info("Port count less than 2, can't run this case")
521 return
522
Flavio Castro1c9b1252016-02-04 18:42:58 -0500523 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
524 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
525 dip = 0xc0a80001
Flavio Castro80730822015-12-11 15:38:47 -0500526 ports = config["port_map"].keys()
Flavio Castro1c9b1252016-02-04 18:42:58 -0500527 Groups = Queue.LifoQueue()
Flavio Castro80730822015-12-11 15:38:47 -0500528 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500529 # add l2 interface group
530 id = port
531 vlan_id = port
532 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
533 vlan_id, True, True)
534 dst_mac[5] = vlan_id
535 # add MPLS interface group
536 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
537 dst_mac, intf_src_mac,
538 vlan_id, id)
539 # add MPLS L3 VPN group
540 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
541 self.controller,
542 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
543 index=id, ref_gid=mpls_gid, push_mpls_header=True,
544 set_mpls_label=port, set_bos=1, set_ttl=32)
545 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castro80730822015-12-11 15:38:47 -0500546 do_barrier(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500547 # add vlan flow table
548 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0,
549 flag=VLAN_TABLE_FLAG_ONLY_TAG)
550 # add termination flow
551 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
552 vlan_id)
553 # add routing flow
554 dst_ip = dip + (vlan_id << 8)
555 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
556 0xffffffff, mpls_label_gid)
557 Groups._put(l2_gid)
558 Groups._put(mpls_gid)
559 Groups._put(mpls_label_gid)
Flavio Castro72a45d52015-12-02 16:37:05 -0500560 do_barrier(self.controller)
561
562 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
563 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500564 ip_src = '192.168.%02d.1' % (in_port)
Flavio Castro72a45d52015-12-02 16:37:05 -0500565 for out_port in ports:
566 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500567 continue
568 ip_dst = '192.168.%02d.1' % (out_port)
569 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
570 vlan_vid=(in_port),
571 eth_dst=switch_mac, ip_ttl=64,
572 ip_src=ip_src,
573 ip_dst=ip_dst)
574 pkt = str(parsed_pkt)
Flavio Castro72a45d52015-12-02 16:37:05 -0500575 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500576 # build expect packet
577 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castro72a45d52015-12-02 16:37:05 -0500578 label = (out_port, 0, 1, 32)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500579 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
580 vlan_vid=(out_port), ip_ttl=63,
581 ip_src=ip_src,
582 ip_dst=ip_dst, eth_dst=mac_dst,
583 eth_src=switch_mac, label=[label])
584 pkt = str(exp_pkt)
Flavio Castro72a45d52015-12-02 16:37:05 -0500585 verify_packet(self, pkt, out_port)
586 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500587 delete_all_flows(self.controller)
588 delete_groups(self.controller, Groups)
589
590
Flavio Castroaba28ff2016-02-03 16:47:48 -0500591@disabled
Flavio Castro80730822015-12-11 15:38:47 -0500592class MPLSBUG(base_tests.SimpleDataPlane):
Flavio Castro80730822015-12-11 15:38:47 -0500593 def runTest(self):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500594 if len(config["port_map"]) < 2:
Flavio Castro80730822015-12-11 15:38:47 -0500595 logging.info("Port count less than 2, can't run this case")
596 return
Flavio Castro1c9b1252016-02-04 18:42:58 -0500597 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
598 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
599 dip = 0xc0a80001
600 Groups = Queue.LifoQueue()
Flavio Castro80730822015-12-11 15:38:47 -0500601 ports = config["port_map"].keys()
602 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500603 # add l2 interface group
604 vlan_id = port
605 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
606 vlan_id, True, False)
607 dst_mac[5] = vlan_id
608 # add L3 Unicast group
609 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
610 id=vlan_id, src_mac=intf_src_mac,
611 dst_mac=dst_mac)
612 # add vlan flow table
613 add_one_vlan_table_flow(self.controller, port, vlan_id,
614 flag=VLAN_TABLE_FLAG_ONLY_BOTH)
615 # add termination flow
616 add_termination_flow(self.controller, port, 0x8847, intf_src_mac,
617 vlan_id, goto_table=24)
618 # add mpls flow
Flavio Castro80730822015-12-11 15:38:47 -0500619 add_mpls_flow(self.controller, l3_msg.group_id, port)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500620 # add termination flow
621 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
622 vlan_id)
623 # add unicast routing flow
624 dst_ip = dip + (vlan_id << 8)
625 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
626 0xffffffff, l3_msg.group_id)
627 Groups._put(l2_gid)
628 Groups._put(l3_msg.group_id)
Flavio Castro80730822015-12-11 15:38:47 -0500629 do_barrier(self.controller)
630
631 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
632 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500633 mac_src = '00:00:00:22:22:%02X' % in_port
634 ip_src = '192.168.%02d.1' % in_port
Flavio Castro80730822015-12-11 15:38:47 -0500635 for out_port in ports:
636 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500637 continue
638 ip_dst = '192.168.%02d.1' % out_port
Flavio Castro80730822015-12-11 15:38:47 -0500639 switch_mac = "00:00:00:cc:cc:cc"
640 label = (out_port, 0, 1, 32)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500641 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
642 vlan_vid=in_port, ip_src=ip_src,
643 ip_dst=ip_dst, eth_dst=switch_mac,
644 eth_src=mac_src, label=[label])
645 pkt = str(parsed_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500646 self.dataplane.send(in_port, pkt)
647
Flavio Castro1c9b1252016-02-04 18:42:58 -0500648 # build expect packet
649 mac_dst = '00:00:00:22:22:%02X' % out_port
650 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
651 vlan_vid=out_port,
652 eth_dst=mac_dst, eth_src=switch_mac,
653 ip_ttl=31, ip_src=ip_src,
654 ip_dst=ip_dst)
655 pkt = str(exp_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500656 verify_packet(self, pkt, out_port)
657 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500658
659 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
660 vlan_vid=in_port,
661 eth_dst=switch_mac,
662 eth_src=mac_src, ip_ttl=64,
663 ip_src=ip_src,
664 ip_dst=ip_dst)
665 pkt = str(parsed_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500666 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500667 # build expected packet
668 mac_dst = '00:00:00:22:22:%02X' % out_port
669 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
670 vlan_vid=out_port,
671 eth_dst=mac_dst, eth_src=switch_mac,
672 ip_ttl=63,
673 ip_src=ip_src, ip_dst=ip_dst)
674 pkt = str(exp_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500675 verify_packet(self, pkt, out_port)
676 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500677 delete_all_flows(self.controller)
678 delete_groups(self.controller, Groups)
679
Flavio Castro80730822015-12-11 15:38:47 -0500680
Flavio Castro12296312015-12-15 17:48:26 -0500681class L3McastToL2(base_tests.SimpleDataPlane):
castroflaviocc403a92015-12-15 14:04:19 -0500682 """
Flavio Castro12296312015-12-15 17:48:26 -0500683 Mcast routing to L2
castroflaviocc403a92015-12-15 14:04:19 -0500684 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500685
castroflaviocc403a92015-12-15 14:04:19 -0500686 def runTest(self):
687 """
688 port1 (vlan 300)-> All Ports (vlan 300)
689 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500690 if len(config["port_map"]) < 3:
castroflavio4a09c962016-01-05 13:13:41 -0800691 logging.info("Port count less than 3, can't run this case")
Flavio Castro1c9b1252016-02-04 18:42:58 -0500692 assert (False)
castroflaviocc403a92015-12-15 14:04:19 -0500693 return
Flavio Castro1c9b1252016-02-04 18:42:58 -0500694 Groups = Queue.LifoQueue()
695 vlan_id = 300
696 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
697 intf_src_mac_str = ':'.join(['%02X' % x for x in intf_src_mac])
698 dst_mac = [0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
699 dst_mac_str = ':'.join(['%02X' % x for x in dst_mac])
700 port1_mac = [0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
701 port1_mac_str = ':'.join(['%02X' % x for x in port1_mac])
702 src_ip = 0xc0a80101
703 src_ip_str = "192.168.1.1"
704 dst_ip = 0xe0010101
705 dst_ip_str = "224.1.1.1"
castroflaviocc403a92015-12-15 14:04:19 -0500706
Flavio Castro1c9b1252016-02-04 18:42:58 -0500707 port1 = config["port_map"].keys()[0]
708 port2 = config["port_map"].keys()[1]
castroflaviocc403a92015-12-15 14:04:19 -0500709
710 switch_mac = [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00]
711
Flavio Castro1c9b1252016-02-04 18:42:58 -0500712 # add l2 interface group
713 l2_intf_group_list = []
castroflaviocc403a92015-12-15 14:04:19 -0500714 for port in config["port_map"].keys():
Flavio Castro1c9b1252016-02-04 18:42:58 -0500715 add_one_vlan_table_flow(self.controller, port, vlan_id,
716 flag=VLAN_TABLE_FLAG_ONLY_TAG)
castroflaviocc403a92015-12-15 14:04:19 -0500717 if port == port2:
718 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -0500719 l2_intf_gid, msg = add_one_l2_interface_group(self.controller, port,
720 vlan_id=vlan_id,
721 is_tagged=True,
722 send_barrier=False)
castroflaviocc403a92015-12-15 14:04:19 -0500723 l2_intf_group_list.append(l2_intf_gid)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500724 Groups.put(l2_intf_gid)
castroflaviocc403a92015-12-15 14:04:19 -0500725
Flavio Castro1c9b1252016-02-04 18:42:58 -0500726 # add termination flow
727 add_termination_flow(self.controller, port1, 0x0800, switch_mac,
728 vlan_id)
castroflaviocc403a92015-12-15 14:04:19 -0500729
Flavio Castro1c9b1252016-02-04 18:42:58 -0500730 # add l3 interface group
731 mcat_group_msg = add_l3_mcast_group(self.controller, vlan_id, 2,
732 l2_intf_group_list)
733 add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip,
734 mcat_group_msg.group_id)
735 Groups._put(mcat_group_msg.group_id)
castroflaviocc403a92015-12-15 14:04:19 -0500736
Flavio Castro1c9b1252016-02-04 18:42:58 -0500737 parsed_pkt = simple_udp_packet(pktlen=100,
Flavio Castro89933f22016-02-03 15:53:16 -0500738 dl_vlan_enable=True,
739 vlan_vid=vlan_id,
castroflaviocc403a92015-12-15 14:04:19 -0500740 eth_dst=dst_mac_str,
741 eth_src=port1_mac_str,
742 ip_ttl=64,
743 ip_src=src_ip_str,
744 ip_dst=dst_ip_str)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500745 pkt = str(parsed_pkt)
castroflaviocc403a92015-12-15 14:04:19 -0500746 self.dataplane.send(port1, pkt)
747 for port in config["port_map"].keys():
Flavio Castro12296312015-12-15 17:48:26 -0500748 if port == port2 or port == port1:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500749 verify_no_packet(self, pkt, port)
750 continue
castroflaviocc403a92015-12-15 14:04:19 -0500751 verify_packet(self, pkt, port)
752 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500753 delete_all_flows(self.controller)
754 delete_groups(self.controller, Groups)
755
castroflaviocc403a92015-12-15 14:04:19 -0500756
Flavio Castro12296312015-12-15 17:48:26 -0500757class L3McastToL3(base_tests.SimpleDataPlane):
758 """
759 Mcast routing
760 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500761
762 def runTest(self):
Flavio Castro12296312015-12-15 17:48:26 -0500763 """
764 port1 (vlan 1)-> port 2 (vlan 2)
765 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500766 Groups = Queue.LifoQueue()
767 if len(config["port_map"]) < 3:
castroflavio4a09c962016-01-05 13:13:41 -0800768 logging.info("Port count less than 3, can't run this case")
Flavio Castro1c9b1252016-02-04 18:42:58 -0500769 assert (False)
Flavio Castro12296312015-12-15 17:48:26 -0500770 return
771
Flavio Castro1c9b1252016-02-04 18:42:58 -0500772 vlan_id = 1
773 port2_out_vlan = 2
774 port3_out_vlan = 3
775 in_vlan = 1 # macast group vid shall use input vlan diffe from l3 interface use output vlan
776 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
777 intf_src_mac_str = ':'.join(['%02X' % x for x in intf_src_mac])
778 dst_mac = [0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
779 dst_mac_str = ':'.join(['%02X' % x for x in dst_mac])
780 port1_mac = [0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
781 port1_mac_str = ':'.join(['%02X' % x for x in port1_mac])
782 src_ip = 0xc0a80101
783 src_ip_str = "192.168.1.1"
784 dst_ip = 0xe0010101
785 dst_ip_str = "224.1.1.1"
Flavio Castro12296312015-12-15 17:48:26 -0500786
Flavio Castro1c9b1252016-02-04 18:42:58 -0500787 port1 = config["port_map"].keys()[0]
788 port2 = config["port_map"].keys()[1]
789 port3 = config["port_map"].keys()[2]
Flavio Castro12296312015-12-15 17:48:26 -0500790
Flavio Castro1c9b1252016-02-04 18:42:58 -0500791 # add l2 interface group
792 for port in config["port_map"].keys():
793 l2gid, msg = add_one_l2_interface_group(self.controller, port,
794 vlan_id=vlan_id,
795 is_tagged=False,
796 send_barrier=False)
797 # add vlan flow table
798 add_one_vlan_table_flow(self.controller, port, vlan_id,
799 flag=VLAN_TABLE_FLAG_ONLY_TAG)
800 vlan_id += 1
801 Groups._put(l2gid)
Flavio Castro12296312015-12-15 17:48:26 -0500802
Flavio Castro1c9b1252016-02-04 18:42:58 -0500803 # add termination flow
804 add_termination_flow(self.controller, port1, 0x0800,
805 [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
806
807 # add l3 interface group
808 port2_ucast_msg = add_l3_interface_group(self.controller, port2,
809 port2_out_vlan, 2,
810 intf_src_mac)
811 port3_ucast_msg = add_l3_interface_group(self.controller, port3,
812 port3_out_vlan, 3,
813 intf_src_mac)
814 mcat_group_msg = add_l3_mcast_group(self.controller, in_vlan, 2,
815 [port2_ucast_msg.group_id,
816 port3_ucast_msg.group_id])
817 add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip,
818 mcat_group_msg.group_id)
819 Groups._put(port2_ucast_msg.group_id)
820 Groups._put(port3_ucast_msg.group_id)
821 Groups._put(mcat_group_msg.group_id)
822 parsed_pkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
823 vlan_vid=1,
Flavio Castro12296312015-12-15 17:48:26 -0500824 eth_dst=dst_mac_str,
825 eth_src=port1_mac_str,
826 ip_ttl=64,
827 ip_src=src_ip_str,
828 ip_dst=dst_ip_str)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500829 pkt = str(parsed_pkt)
830 self.dataplane.send(port1, pkt)
831 parsed_pkt = simple_udp_packet(pktlen=96,
Flavio Castro12296312015-12-15 17:48:26 -0500832 eth_dst=dst_mac_str,
833 eth_src=intf_src_mac_str,
834 ip_ttl=63,
835 ip_src=src_ip_str,
836 ip_dst=dst_ip_str)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500837 pkt = str(parsed_pkt)
Flavio Castro12296312015-12-15 17:48:26 -0500838 verify_packet(self, pkt, port2)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500839 verify_packet(self, pkt, port3)
840 verify_no_other_packets(self)
841 delete_all_flows(self.controller)
842 delete_groups(self.controller, Groups)
Flavio Castro54947942016-02-03 16:05:20 -0500843
844
Flavio Castrof54be492016-02-03 16:26:22 -0500845class _MplsTermination(base_tests.SimpleDataPlane):
Flavio Castro12296312015-12-15 17:48:26 -0500846 """
Flavio Castro54947942016-02-03 16:05:20 -0500847 Insert IP packet
848 Receive MPLS packet
castroflavio30c6cc52016-01-07 15:19:42 -0800849 """
castroflavio30c6cc52016-01-07 15:19:42 -0800850
Flavio Castro1c9b1252016-02-04 18:42:58 -0500851 def runTest(self):
852 Groups = Queue.LifoQueue()
853 if len(config["port_map"]) < 2:
castroflavio30c6cc52016-01-07 15:19:42 -0800854 logging.info("Port count less than 2, can't run this case")
855 return
856
Flavio Castro1c9b1252016-02-04 18:42:58 -0500857 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
858 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
859 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
castroflavio30c6cc52016-01-07 15:19:42 -0800860 ports = config["port_map"].keys()
861 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500862 # add l2 interface group
863 id = port
864 vlan_id = id
865 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
866 vlan_id, True, False)
867 dst_mac[5] = vlan_id
868 # add L3 Unicast group
869 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
870 id=id, src_mac=intf_src_mac,
871 dst_mac=dst_mac)
872 # add L3 ecmp group
Flavio Castro54947942016-02-03 16:05:20 -0500873 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
Flavio Castro1c9b1252016-02-04 18:42:58 -0500874 # add vlan flow table
875 add_one_vlan_table_flow(self.controller, port, vlan_id,
876 flag=VLAN_TABLE_FLAG_ONLY_TAG)
877 # add termination flow
878 add_termination_flow(self.controller, port, 0x8847, intf_src_mac,
879 vlan_id, goto_table=24)
Flavio Castro54947942016-02-03 16:05:20 -0500880 add_mpls_flow(self.controller, ecmp_msg.group_id, port)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500881 Groups._put(l2_gid)
882 Groups._put(l3_msg.group_id)
883 Groups._put(ecmp_msg.group_id)
castroflavio30c6cc52016-01-07 15:19:42 -0800884 do_barrier(self.controller)
885
886 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
887 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500888 ip_src = '192.168.%02d.1' % (in_port)
castroflavio30c6cc52016-01-07 15:19:42 -0800889 for out_port in ports:
890 if in_port == out_port:
Flavio Castro54947942016-02-03 16:05:20 -0500891 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -0500892 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castro54947942016-02-03 16:05:20 -0500893
894 label = (out_port, 0, 1, 32)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500895 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
896 vlan_vid=(in_port), ip_src=ip_src,
897 ip_dst=ip_dst, eth_dst=switch_mac,
898 label=[label])
899 pkt = str(parsed_pkt)
castroflavio30c6cc52016-01-07 15:19:42 -0800900 self.dataplane.send(in_port, pkt)
Flavio Castro54947942016-02-03 16:05:20 -0500901
Flavio Castro1c9b1252016-02-04 18:42:58 -0500902 # build expect packet
903 mac_dst = '00:00:00:22:22:%02X' % (out_port)
904 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
905 vlan_vid=(out_port),
906 eth_dst=mac_dst, eth_src=switch_mac,
907 ip_ttl=31, ip_src=ip_src,
908 ip_dst=ip_dst)
909 pkt = str(exp_pkt)
castroflavio30c6cc52016-01-07 15:19:42 -0800910 verify_packet(self, pkt, out_port)
911 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500912 delete_all_flows(self.controller)
913 delete_groups(self.controller, Groups)
914
Flavio Castrod0619992016-02-04 15:10:28 -0500915
916class _32ECMPL3(base_tests.SimpleDataPlane):
917 """
918 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
919 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
920 """
Flavio Castrod0619992016-02-04 15:10:28 -0500921
Flavio Castro1c9b1252016-02-04 18:42:58 -0500922 def runTest(self):
923 Groups = Queue.LifoQueue()
924 if len(config["port_map"]) < 2:
Flavio Castrod0619992016-02-04 15:10:28 -0500925 logging.info("Port count less than 2, can't run this case")
926 return
927
Flavio Castro1c9b1252016-02-04 18:42:58 -0500928 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
929 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
930 dip = 0xc0a80001
931 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castrod0619992016-02-04 15:10:28 -0500932 ports = config["port_map"].keys()
933 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500934 vlan_id = port
935 id = port
936 # add l2 interface group
937 l2_gid, msg = add_one_l2_interface_group(self.controller, port,
938 vlan_id=vlan_id,
939 is_tagged=True,
940 send_barrier=False)
941 dst_mac[5] = vlan_id
942 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
943 id=id, src_mac=intf_src_mac,
944 dst_mac=dst_mac)
945 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
946 # add vlan flow table
947 add_one_vlan_table_flow(self.controller, port, vlan_id,
948 flag=VLAN_TABLE_FLAG_ONLY_TAG)
949 # add termination flow
950 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
951 vlan_id)
952 # add unicast routing flow
953 dst_ip = dip + (vlan_id << 8)
954 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
955 0xffffffff, ecmp_msg.group_id)
956 Groups._put(l2_gid)
957 Groups._put(l3_msg.group_id)
958 Groups._put(ecmp_msg.group_id)
Flavio Castrod0619992016-02-04 15:10:28 -0500959 do_barrier(self.controller)
960
961 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
962 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500963 mac_src = '00:00:00:22:22:%02X' % in_port
964 ip_src = '192.168.%02d.1' % in_port
Flavio Castrod0619992016-02-04 15:10:28 -0500965 for out_port in ports:
966 if in_port == out_port:
967 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -0500968 ip_dst = '192.168.%02d.1' % out_port
969 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
970 vlan_vid=in_port,
971 eth_dst=switch_mac,
972 eth_src=mac_src, ip_ttl=64,
973 ip_src=ip_src,
Flavio Castrod0619992016-02-04 15:10:28 -0500974 ip_dst=ip_dst)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500975 pkt = str(parsed_pkt)
Flavio Castrod0619992016-02-04 15:10:28 -0500976 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500977 # build expected packet
978 mac_dst = '00:00:00:22:22:%02X' % out_port
979 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
980 vlan_vid=out_port,
981 eth_dst=mac_dst, eth_src=switch_mac,
982 ip_ttl=63,
Flavio Castrod0619992016-02-04 15:10:28 -0500983 ip_src=ip_src, ip_dst=ip_dst)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500984 pkt = str(exp_pkt)
Flavio Castrod0619992016-02-04 15:10:28 -0500985 verify_packet(self, pkt, out_port)
986 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500987 delete_all_flows(self.controller)
988 delete_groups(self.controller, Groups)
Flavio Castrod0619992016-02-04 15:10:28 -0500989
Flavio Castro1c9b1252016-02-04 18:42:58 -0500990
991class _24ECMPL3(base_tests.SimpleDataPlane):
992 """
993 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
994 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
995 """
996
997 def runTest(self):
998 Groups = Queue.LifoQueue()
999 if len(config["port_map"]) < 2:
1000 logging.info("Port count less than 2, can't run this case")
1001 return
1002
1003 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1004 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1005 dip = 0xc0a80001
1006 # Hashes Test Name and uses it as id for installing unique groups
1007 ports = config["port_map"].keys()
1008 for port in ports:
1009 vlan_id = port
1010 id = port
1011 # add l2 interface group
1012 l2_gid, msg = add_one_l2_interface_group(self.controller, port,
1013 vlan_id=vlan_id,
1014 is_tagged=True,
1015 send_barrier=False)
1016 dst_mac[5] = vlan_id
1017 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
1018 id=id, src_mac=intf_src_mac,
1019 dst_mac=dst_mac)
1020 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
1021 # add vlan flow table
1022 add_one_vlan_table_flow(self.controller, port, vlan_id,
1023 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1024 # add termination flow
1025 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
1026 vlan_id)
1027 # add unicast routing flow
1028 dst_ip = dip + (vlan_id << 8)
1029 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
1030 0xffffff00, ecmp_msg.group_id)
1031 Groups._put(l2_gid)
1032 Groups._put(l3_msg.group_id)
1033 Groups._put(ecmp_msg.group_id)
1034 do_barrier(self.controller)
1035
1036 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1037 for in_port in ports:
1038 mac_src = '00:00:00:22:22:%02X' % in_port
1039 ip_src = '192.168.%02d.1' % in_port
1040 for out_port in ports:
1041 if in_port == out_port:
1042 continue
1043 ip_dst = '192.168.%02d.1' % out_port
1044 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1045 vlan_vid=in_port,
1046 eth_dst=switch_mac,
1047 eth_src=mac_src, ip_ttl=64,
1048 ip_src=ip_src,
1049 ip_dst=ip_dst)
1050 pkt = str(parsed_pkt)
1051 self.dataplane.send(in_port, pkt)
1052 # build expected packet
1053 mac_dst = '00:00:00:22:22:%02X' % out_port
1054 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1055 vlan_vid=out_port,
1056 eth_dst=mac_dst, eth_src=switch_mac,
1057 ip_ttl=63,
1058 ip_src=ip_src, ip_dst=ip_dst)
1059 pkt = str(exp_pkt)
1060 verify_packet(self, pkt, out_port)
1061 verify_no_other_packets(self)
1062 delete_all_flows(self.controller)
1063 delete_groups(self.controller, Groups)
1064
1065
1066class _24UcastTagged(base_tests.SimpleDataPlane):
1067 """
1068 Verify a IP forwarding works for a /32 rule to L3 Unicast Interface
1069 """
1070
1071 def runTest(self):
1072 test_id = 26
1073 if len(config["port_map"]) < 2:
1074 logging.info("Port count less than 2, can't run this case")
1075 return
1076
1077 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1078 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1079 dip = 0xc0a80001
1080 ports = config["port_map"].keys()
1081 Groups = Queue.LifoQueue()
1082 for port in ports:
1083 # add l2 interface group
1084 vlan_id = port + test_id
1085 l2gid, msg = add_one_l2_interface_group(self.controller, port,
1086 vlan_id=vlan_id,
1087 is_tagged=True,
1088 send_barrier=False)
1089 dst_mac[5] = vlan_id
1090 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
1091 id=vlan_id, src_mac=intf_src_mac,
1092 dst_mac=dst_mac)
1093 # add vlan flow table
1094 add_one_vlan_table_flow(self.controller, port, vlan_id,
1095 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1096 # add termination flow
1097 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
1098 vlan_id)
1099 # add unicast routing flow
1100 dst_ip = dip + (vlan_id << 8)
1101 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
1102 0xffffff00, l3_msg.group_id)
1103 Groups.put(l2gid)
1104 Groups.put(l3_msg.group_id)
1105 do_barrier(self.controller)
1106
1107 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1108 for in_port in ports:
1109 mac_src = '00:00:00:22:22:%02X' % (test_id + in_port)
1110 ip_src = '192.168.%02d.1' % (test_id + in_port)
1111 for out_port in ports:
1112 if in_port == out_port:
1113 continue
1114 ip_dst = '192.168.%02d.1' % (test_id + out_port)
1115 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1116 vlan_vid=(test_id + in_port),
1117 eth_dst=switch_mac,
1118 eth_src=mac_src, ip_ttl=64,
1119 ip_src=ip_src,
1120 ip_dst=ip_dst)
1121 pkt = str(parsed_pkt)
1122 self.dataplane.send(in_port, pkt)
1123 # build expected packet
1124 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
1125 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1126 vlan_vid=(test_id + out_port),
1127 eth_dst=mac_dst, eth_src=switch_mac,
1128 ip_ttl=63,
1129 ip_src=ip_src, ip_dst=ip_dst)
1130 pkt = str(exp_pkt)
1131 verify_packet(self, pkt, out_port)
1132 verify_no_other_packets(self)
1133 delete_all_flows(self.controller)
1134 delete_groups(self.controller, Groups)