blob: 52d43765094d6efef3ecf645d61b1096f0dd74f2 [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
Flavio Castro6da7e462016-02-04 18:56:29 -050061 verify_no_packet_in(self, vlan_pkt, of_port)
62 delete_all_flows(self.controller)
Flavio Castro6d498522015-12-15 14:05:04 -050063 do_barrier(self.controller)
64
Flavio Castro1c9b1252016-02-04 18:42:58 -050065 match = ofp.match()
66 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
67 match.oxm_list.append(ofp.oxm.ip_proto(17))
68 request = ofp.message.flow_add(
69 table_id=60,
70 cookie=42,
71 match=match,
72 instructions=[
73 ofp.instruction.apply_actions(
74 actions=[
75 ofp.action.output(
76 port=ofp.OFPP_CONTROLLER,
77 max_len=ofp.OFPCML_NO_BUFFER)]), ],
78 buffer_id=ofp.OFP_NO_BUFFER,
79 priority=1)
80 logging.info("Inserting packet in flow to controller")
81 self.controller.message_send(request)
Flavio Castro6da7e462016-02-04 18:56:29 -050082 do_barrier(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -050083
Flavio Castro6d498522015-12-15 14:05:04 -050084 for of_port in config["port_map"].keys():
85 logging.info("PacketInMiss test, port %d", of_port)
86 self.dataplane.send(of_port, vlan_pkt)
87
88 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
89
90 verify_no_other_packets(self)
Flavio Castroaf2b4502016-02-02 17:41:32 -050091
Flavio Castro1c9b1252016-02-04 18:42:58 -050092 delete_all_flows(self.controller)
93
Flavio Castroaf2b4502016-02-02 17:41:32 -050094
Flavio Castro67d8bd52016-02-03 14:22:14 -050095@disabled
Flavio Castro7fb6ca92015-12-16 15:50:14 -050096class ArpNL2(base_tests.SimpleDataPlane):
Flavio Castro1c9b1252016-02-04 18:42:58 -050097 def runTest(self):
Flavio Castro7fb6ca92015-12-16 15:50:14 -050098 delete_all_flows(self.controller)
99 delete_all_groups(self.controller)
100
101 ports = sorted(config["port_map"].keys())
102 match = ofp.match()
103 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
104 request = ofp.message.flow_add(
Flavio Castro1c9b1252016-02-04 18:42:58 -0500105 table_id=60,
106 cookie=42,
107 match=match,
108 instructions=[
109 ofp.instruction.apply_actions(
110 actions=[
111 ofp.action.output(
112 port=ofp.OFPP_CONTROLLER,
113 max_len=ofp.OFPCML_NO_BUFFER)]),
114 ],
115 buffer_id=ofp.OFP_NO_BUFFER,
116 priority=40000)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500117 self.controller.message_send(request)
118 for port in ports:
Flavio Castro932014b2016-01-05 18:29:15 -0500119 add_one_l2_interface_group(self.controller, port, 1, False, False)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500120 add_one_vlan_table_flow(self.controller, port, 1,
121 flag=VLAN_TABLE_FLAG_ONLY_BOTH)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500122 group_id = encode_l2_interface_group_id(1, port)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500123 add_bridge_flow(self.controller,
124 [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id,
125 True)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500126 do_barrier(self.controller)
127 parsed_arp_pkt = simple_arp_packet()
128 arp_pkt = str(parsed_arp_pkt)
129
130 for out_port in ports:
131 self.dataplane.send(out_port, arp_pkt)
132 verify_packet_in(self, arp_pkt, out_port, ofp.OFPR_ACTION)
133 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500134 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500135 for in_port in ports:
136 if in_port == out_port:
137 continue
138 # change source based on port number to avoid packet-ins from learning
Flavio Castro1c9b1252016-02-04 18:42:58 -0500139 mac_src = '00:12:34:56:78:%02X' % in_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500140 parsed_pkt = simple_tcp_packet(eth_dst=mac_dst, eth_src=mac_src)
141 pkt = str(parsed_pkt)
142 self.dataplane.send(in_port, pkt)
143
144 for ofport in ports:
145 if ofport in [out_port]:
146 verify_packet(self, pkt, ofport)
147 else:
148 verify_no_packet(self, pkt, ofport)
149
150 verify_no_other_packets(self)
151
Flavio Castro1c9b1252016-02-04 18:42:58 -0500152
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500153class PacketInArp(base_tests.SimpleDataPlane):
154 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500155 Verify an ACL rule matching on ethertyper 0x806 will result in a packet-in
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500156 """
157
158 def runTest(self):
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500159 parsed_arp_pkt = simple_arp_packet()
160 arp_pkt = str(parsed_arp_pkt)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500161 # create match
162 match = ofp.match()
163 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
164 request = ofp.message.flow_add(
Flavio Castro1c9b1252016-02-04 18:42:58 -0500165 table_id=60,
166 cookie=42,
167 match=match,
168 instructions=[
169 ofp.instruction.apply_actions(
170 actions=[
171 ofp.action.output(
172 port=ofp.OFPP_CONTROLLER,
173 max_len=ofp.OFPCML_NO_BUFFER)]),
174 ],
175 buffer_id=ofp.OFP_NO_BUFFER,
176 priority=1)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500177
178 logging.info("Inserting packet in flow to controller")
179 self.controller.message_send(request)
180 do_barrier(self.controller)
181
182 for of_port in config["port_map"].keys():
183 logging.info("PacketInMiss test, port %d", of_port)
184 self.dataplane.send(of_port, arp_pkt)
185
186 verify_packet_in(self, arp_pkt, of_port, ofp.OFPR_ACTION)
187
188 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500189 delete_all_flows(self.controller)
190
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500191
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500192class L2FloodQinQ(base_tests.SimpleDataPlane):
193 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500194 Verify a tagged frame can be flooded based on its outer vlan
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500195 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500196
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500197 def runTest(self):
198 ports = sorted(config["port_map"].keys())
Flavio Castro1c9b1252016-02-04 18:42:58 -0500199 vlan_id = 1
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500200
Flavio Castro1c9b1252016-02-04 18:42:58 -0500201 Groups = Queue.LifoQueue()
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500202 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500203 L2gid, l2msg = add_one_l2_interface_group(self.controller, port,
204 vlan_id, True, False)
205 add_one_vlan_table_flow(self.controller, port, vlan_id,
206 flag=VLAN_TABLE_FLAG_ONLY_TAG)
207 Groups.put(L2gid)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500208
Flavio Castro1c9b1252016-02-04 18:42:58 -0500209 msg = add_l2_flood_group(self.controller, ports, vlan_id, vlan_id)
Flavio Castro6da7e462016-02-04 18:56:29 -0500210 Groups.put(msg.group_id)
Flavio Castro8628adb2016-02-03 17:30:57 -0500211 add_bridge_flow(self.controller, None, vlan_id, msg.group_id, True)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500212 do_barrier(self.controller)
213
Flavio Castro1c9b1252016-02-04 18:42:58 -0500214 # verify flood
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500215 for ofport in ports:
216 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500217 mac_src = '00:12:34:56:78:%02X' % ofport
218 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108,
219 out_dl_vlan_enable=True,
220 out_vlan_vid=vlan_id,
221 in_dl_vlan_enable=True,
222 in_vlan_vid=10,
223 eth_dst='00:12:34:56:78:9a',
224 eth_src=mac_src)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500225 pkt = str(parsed_pkt)
226 self.dataplane.send(ofport, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500227 # self won't rx packet
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500228 verify_no_packet(self, pkt, ofport)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500229 # others will rx packet
230 tmp_ports = list(ports)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500231 tmp_ports.remove(ofport)
232 verify_packets(self, pkt, tmp_ports)
233
234 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500235 delete_all_flows(self.controller)
236 delete_groups(self.controller, Groups)
237
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500238
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500239@disabled
Flavio Castro184cefe2015-11-19 20:52:49 -0500240class L2FloodTagged(base_tests.SimpleDataPlane):
241 """
242 Test L2 flood to a vlan
243 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 -0500244 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500245
Flavio Castro184cefe2015-11-19 20:52:49 -0500246 def runTest(self):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500247 # Hashes Test Name and uses it as id for installing unique groups
248 vlan_id = abs(hash(inspect.stack()[0][3])) % (256)
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500249 print vlan_id
Flavio Castroaba28ff2016-02-03 16:47:48 -0500250
Flavio Castro184cefe2015-11-19 20:52:49 -0500251 ports = sorted(config["port_map"].keys())
Flavio Castro34352e72015-12-07 20:01:51 -0500252
Flavio Castro184cefe2015-11-19 20:52:49 -0500253 delete_all_flows(self.controller)
254 delete_all_groups(self.controller)
255
Flavio Castro184cefe2015-11-19 20:52:49 -0500256 # Installing flows to avoid packet-in
257 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500258 add_one_l2_interface_group(self.controller, port, vlan_id, True,
259 False)
260 add_one_vlan_table_flow(self.controller, port, vlan_id,
261 flag=VLAN_TABLE_FLAG_ONLY_TAG)
262 msg = add_l2_flood_group(self.controller, ports, vlan_id, vlan_id)
Flavio Castroaba28ff2016-02-03 16:47:48 -0500263 add_bridge_flow(self.controller, None, vlan_id, msg.group_id, True)
Flavio Castro184cefe2015-11-19 20:52:49 -0500264 do_barrier(self.controller)
265
Flavio Castro1c9b1252016-02-04 18:42:58 -0500266 # verify flood
Flavio Castro184cefe2015-11-19 20:52:49 -0500267 for ofport in ports:
268 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500269 pkt = str(simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vlan_id,
270 eth_dst='00:12:34:56:78:9a'))
Flavio Castro184cefe2015-11-19 20:52:49 -0500271 self.dataplane.send(ofport, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500272 # self won't rx packet
Flavio Castro184cefe2015-11-19 20:52:49 -0500273 verify_no_packet(self, pkt, ofport)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500274 # others will rx packet
275 tmp_ports = list(ports)
Flavio Castro184cefe2015-11-19 20:52:49 -0500276 tmp_ports.remove(ofport)
277 verify_packets(self, pkt, tmp_ports)
Flavio Castro184cefe2015-11-19 20:52:49 -0500278 verify_no_other_packets(self)
Flavio Castroaabb5792015-11-18 19:03:50 -0500279
Flavio Castro1c9b1252016-02-04 18:42:58 -0500280
Flavio Castroaabb5792015-11-18 19:03:50 -0500281class L2UnicastTagged(base_tests.SimpleDataPlane):
282 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500283 Verify L2 forwarding works
Flavio Castroaabb5792015-11-18 19:03:50 -0500284 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500285
Flavio Castroaabb5792015-11-18 19:03:50 -0500286 def runTest(self):
287 ports = sorted(config["port_map"].keys())
Flavio Castro1c9b1252016-02-04 18:42:58 -0500288 vlan_id = 1;
289 Groups = Queue.LifoQueue()
Flavio Castroaabb5792015-11-18 19:03:50 -0500290 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500291 L2gid, l2msg = add_one_l2_interface_group(self.controller, port,
292 vlan_id, True, False)
293 add_one_vlan_table_flow(self.controller, port, vlan_id,
294 flag=VLAN_TABLE_FLAG_ONLY_TAG)
295 Groups.put(L2gid)
296 add_bridge_flow(self.controller,
297 [0x00, 0x12, 0x34, 0x56, 0x78, port], vlan_id,
298 L2gid, True)
Flavio Castro6efe1862015-11-18 16:28:06 -0500299 do_barrier(self.controller)
300
Flavio Castroaabb5792015-11-18 19:03:50 -0500301 for out_port in ports:
302 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500303 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castroaabb5792015-11-18 19:03:50 -0500304 for in_port in ports:
305 if in_port == out_port:
306 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -0500307 pkt = str(
308 simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vlan_id,
309 eth_dst=mac_dst))
Flavio Castroaabb5792015-11-18 19:03:50 -0500310 self.dataplane.send(in_port, pkt)
Flavio Castroaabb5792015-11-18 19:03:50 -0500311 for ofport in ports:
312 if ofport in [out_port]:
313 verify_packet(self, pkt, ofport)
314 else:
315 verify_no_packet(self, pkt, ofport)
Flavio Castroaabb5792015-11-18 19:03:50 -0500316 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500317 delete_all_flows(self.controller)
318 delete_groups(self.controller, Groups)
319
Flavio Castro6efe1862015-11-18 16:28:06 -0500320
Flavio Castrob6773032015-11-19 22:49:24 -0500321class Mtu1500(base_tests.SimpleDataPlane):
Flavio Castrob6773032015-11-19 22:49:24 -0500322 def runTest(self):
323 ports = sorted(config["port_map"].keys())
Flavio Castro1c9b1252016-02-04 18:42:58 -0500324 vlan_id = 18
325 Groups = Queue.LifoQueue()
Flavio Castrob6773032015-11-19 22:49:24 -0500326 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500327 L2gid, msg = add_one_l2_interface_group(self.controller, port,
328 vlan_id, True, False)
329 add_one_vlan_table_flow(self.controller, port, vlan_id,
330 flag=VLAN_TABLE_FLAG_ONLY_TAG)
331 Groups.put(L2gid)
332 add_bridge_flow(self.controller,
333 [0x00, 0x12, 0x34, 0x56, 0x78, port], vlan_id,
334 L2gid, True)
Flavio Castrob6773032015-11-19 22:49:24 -0500335 do_barrier(self.controller)
336
337 for out_port in ports:
338 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500339 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castrob6773032015-11-19 22:49:24 -0500340 for in_port in ports:
341 if in_port == out_port:
342 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -0500343 pkt = str(simple_tcp_packet(pktlen=1500, dl_vlan_enable=True,
344 vlan_vid=vlan_id, eth_dst=mac_dst))
Flavio Castrob6773032015-11-19 22:49:24 -0500345 self.dataplane.send(in_port, pkt)
Flavio Castrob6773032015-11-19 22:49:24 -0500346 for ofport in ports:
347 if ofport in [out_port]:
348 verify_packet(self, pkt, ofport)
349 else:
350 verify_no_packet(self, pkt, ofport)
Flavio Castrob6773032015-11-19 22:49:24 -0500351 verify_no_other_packets(self)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500352 delete_all_flows(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500353 delete_groups(self.controller, Groups)
354
355
356class _32UcastTagged(base_tests.SimpleDataPlane):
357 """
358 Verify a IP forwarding works for a /32 rule to L3 Unicast Interface
359 """
360
361 def runTest(self):
362 test_id = 26
363 if len(config["port_map"]) < 2:
Flavio Castro05d20bc2015-11-16 15:06:14 -0500364 logging.info("Port count less than 2, can't run this case")
365 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500366
Flavio Castro1c9b1252016-02-04 18:42:58 -0500367 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
368 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
369 dip = 0xc0a80001
Flavio Castroa8233862015-12-02 14:41:11 -0500370 ports = config["port_map"].keys()
Flavio Castro1c9b1252016-02-04 18:42:58 -0500371 Groups = Queue.LifoQueue()
Flavio Castroa8233862015-12-02 14:41:11 -0500372 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500373 # add l2 interface group
374 vlan_id = port + test_id
375 l2gid, msg = add_one_l2_interface_group(self.controller, port,
376 vlan_id=vlan_id,
377 is_tagged=True,
378 send_barrier=False)
379 dst_mac[5] = vlan_id
380 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
381 id=vlan_id, src_mac=intf_src_mac,
382 dst_mac=dst_mac)
383 # add vlan flow table
384 add_one_vlan_table_flow(self.controller, port, vlan_id,
385 flag=VLAN_TABLE_FLAG_ONLY_TAG)
386 # add termination flow
387 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
388 vlan_id)
389 # add unicast routing flow
390 dst_ip = dip + (vlan_id << 8)
391 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
392 0xffffffff, l3_msg.group_id)
393 Groups.put(l2gid)
394 Groups.put(l3_msg.group_id)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500395 do_barrier(self.controller)
396
Flavio Castro05d20bc2015-11-16 15:06:14 -0500397 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
Flavio Castroa8233862015-12-02 14:41:11 -0500398 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500399 mac_src = '00:00:00:22:22:%02X' % (test_id + in_port)
400 ip_src = '192.168.%02d.1' % (test_id + in_port)
Flavio Castroa8233862015-12-02 14:41:11 -0500401 for out_port in ports:
402 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500403 continue
404 ip_dst = '192.168.%02d.1' % (test_id + out_port)
405 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
406 vlan_vid=(test_id + in_port),
407 eth_dst=switch_mac,
408 eth_src=mac_src, ip_ttl=64,
409 ip_src=ip_src,
410 ip_dst=ip_dst)
411 pkt = str(parsed_pkt)
Flavio Castroa8233862015-12-02 14:41:11 -0500412 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500413 # build expected packet
414 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
415 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
416 vlan_vid=(test_id + out_port),
417 eth_dst=mac_dst, eth_src=switch_mac,
418 ip_ttl=63,
419 ip_src=ip_src, ip_dst=ip_dst)
420 pkt = str(exp_pkt)
Flavio Castroa8233862015-12-02 14:41:11 -0500421 verify_packet(self, pkt, out_port)
422 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500423 delete_all_flows(self.controller)
424 delete_groups(self.controller, Groups)
425
Flavio Castro05d20bc2015-11-16 15:06:14 -0500426
Flavio Castrod8f8af22015-12-02 18:19:26 -0500427class L3VPNMPLS(base_tests.SimpleDataPlane):
428 """
429 Insert IP packet
430 Receive MPLS packet
431 """
Flavio Castro72a45d52015-12-02 16:37:05 -0500432
Flavio Castro1c9b1252016-02-04 18:42:58 -0500433 def runTest(self):
434 if len(config["port_map"]) < 2:
Flavio Castro72a45d52015-12-02 16:37:05 -0500435 logging.info("Port count less than 2, can't run this case")
436 return
Flavio Castro1c9b1252016-02-04 18:42:58 -0500437 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
438 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
439 dip = 0xc0a80001
440 Groups = Queue.LifoQueue()
Flavio Castro72a45d52015-12-02 16:37:05 -0500441 ports = config["port_map"].keys()
442 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500443 # add l2 interface group
444 id = port
445 vlan_id = id
446 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
447 vlan_id, True, True)
448 dst_mac[5] = vlan_id
449 # add MPLS interface group
450 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
451 dst_mac, intf_src_mac,
452 vlan_id, id)
453 # add MPLS L3 VPN group
454 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
455 self.controller,
456 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
457 index=id, ref_gid=mpls_gid, push_mpls_header=True,
458 set_mpls_label=port, set_bos=1, set_ttl=32)
459 ecmp_msg = add_l3_ecmp_group(self.controller, id, [mpls_label_gid])
Flavio Castro80730822015-12-11 15:38:47 -0500460 do_barrier(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500461 # add vlan flow table
462 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0,
463 flag=VLAN_TABLE_FLAG_ONLY_TAG)
464 # add termination flow
465 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
466 vlan_id)
467 # add routing flow
468 dst_ip = dip + (vlan_id << 8)
469 # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
470 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
471 0xffffff00, ecmp_msg.group_id, vrf=0)
472 Groups._put(l2_gid)
473 Groups._put(mpls_gid)
474 Groups._put(mpls_label_gid)
475 Groups._put(ecmp_msg.group_id)
Flavio Castro80730822015-12-11 15:38:47 -0500476
477 do_barrier(self.controller)
478
479 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
480 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500481 mac_src = '00:00:00:22:22:%02X' % (in_port)
482 ip_src = '192.168.%02d.1' % (in_port)
Flavio Castro80730822015-12-11 15:38:47 -0500483 for out_port in ports:
484 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500485 continue
486 ip_dst = '192.168.%02d.1' % (out_port)
487 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
488 vlan_vid=(in_port),
489 eth_dst=switch_mac,
490 eth_src=mac_src, ip_ttl=64,
491 ip_src=ip_src,
492 ip_dst=ip_dst)
493 pkt = str(parsed_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500494 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500495 # build expect packet
496 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castro80730822015-12-11 15:38:47 -0500497 label = (out_port, 0, 1, 32)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500498 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
499 vlan_vid=(out_port), ip_ttl=63,
500 ip_src=ip_src,
501 ip_dst=ip_dst, eth_dst=mac_dst,
502 eth_src=switch_mac, label=[label])
503 pkt = str(exp_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500504 verify_packet(self, pkt, out_port)
505 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500506 delete_all_flows(self.controller)
507 delete_groups(self.controller, Groups)
508
castroflavioee294842016-01-06 15:54:28 -0800509
Flavio Castro67d8bd52016-02-03 14:22:14 -0500510class _32VPN(base_tests.SimpleDataPlane):
Flavio Castro80730822015-12-11 15:38:47 -0500511 """
512 Insert IP packet
513 Receive MPLS packet
514 """
Flavio Castro80730822015-12-11 15:38:47 -0500515
Flavio Castro1c9b1252016-02-04 18:42:58 -0500516 def runTest(self):
517 if len(config["port_map"]) < 2:
Flavio Castro80730822015-12-11 15:38:47 -0500518 logging.info("Port count less than 2, can't run this case")
519 return
520
Flavio Castro1c9b1252016-02-04 18:42:58 -0500521 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
522 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
523 dip = 0xc0a80001
Flavio Castro80730822015-12-11 15:38:47 -0500524 ports = config["port_map"].keys()
Flavio Castro1c9b1252016-02-04 18:42:58 -0500525 Groups = Queue.LifoQueue()
Flavio Castro80730822015-12-11 15:38:47 -0500526 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500527 # add l2 interface group
528 id = port
529 vlan_id = port
530 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
531 vlan_id, True, True)
532 dst_mac[5] = vlan_id
533 # add MPLS interface group
534 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
535 dst_mac, intf_src_mac,
536 vlan_id, id)
537 # add MPLS L3 VPN group
538 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
539 self.controller,
540 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
541 index=id, ref_gid=mpls_gid, push_mpls_header=True,
542 set_mpls_label=port, set_bos=1, set_ttl=32)
543 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castro80730822015-12-11 15:38:47 -0500544 do_barrier(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500545 # add vlan flow table
546 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0,
547 flag=VLAN_TABLE_FLAG_ONLY_TAG)
548 # add termination flow
549 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
550 vlan_id)
551 # add routing flow
552 dst_ip = dip + (vlan_id << 8)
553 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
554 0xffffffff, mpls_label_gid)
555 Groups._put(l2_gid)
556 Groups._put(mpls_gid)
557 Groups._put(mpls_label_gid)
Flavio Castro72a45d52015-12-02 16:37:05 -0500558 do_barrier(self.controller)
559
560 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
561 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500562 ip_src = '192.168.%02d.1' % (in_port)
Flavio Castro72a45d52015-12-02 16:37:05 -0500563 for out_port in ports:
564 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500565 continue
566 ip_dst = '192.168.%02d.1' % (out_port)
567 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
568 vlan_vid=(in_port),
569 eth_dst=switch_mac, ip_ttl=64,
570 ip_src=ip_src,
571 ip_dst=ip_dst)
572 pkt = str(parsed_pkt)
Flavio Castro72a45d52015-12-02 16:37:05 -0500573 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500574 # build expect packet
575 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castro72a45d52015-12-02 16:37:05 -0500576 label = (out_port, 0, 1, 32)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500577 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
578 vlan_vid=(out_port), ip_ttl=63,
579 ip_src=ip_src,
580 ip_dst=ip_dst, eth_dst=mac_dst,
581 eth_src=switch_mac, label=[label])
582 pkt = str(exp_pkt)
Flavio Castro72a45d52015-12-02 16:37:05 -0500583 verify_packet(self, pkt, out_port)
584 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500585 delete_all_flows(self.controller)
586 delete_groups(self.controller, Groups)
587
588
Flavio Castroaba28ff2016-02-03 16:47:48 -0500589@disabled
Flavio Castro80730822015-12-11 15:38:47 -0500590class MPLSBUG(base_tests.SimpleDataPlane):
Flavio Castro80730822015-12-11 15:38:47 -0500591 def runTest(self):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500592 if len(config["port_map"]) < 2:
Flavio Castro80730822015-12-11 15:38:47 -0500593 logging.info("Port count less than 2, can't run this case")
594 return
Flavio Castro1c9b1252016-02-04 18:42:58 -0500595 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
596 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
597 dip = 0xc0a80001
598 Groups = Queue.LifoQueue()
Flavio Castro80730822015-12-11 15:38:47 -0500599 ports = config["port_map"].keys()
600 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500601 # add l2 interface group
602 vlan_id = port
603 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
604 vlan_id, True, False)
605 dst_mac[5] = vlan_id
606 # add L3 Unicast group
607 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
608 id=vlan_id, src_mac=intf_src_mac,
609 dst_mac=dst_mac)
610 # add vlan flow table
611 add_one_vlan_table_flow(self.controller, port, vlan_id,
612 flag=VLAN_TABLE_FLAG_ONLY_BOTH)
613 # add termination flow
614 add_termination_flow(self.controller, port, 0x8847, intf_src_mac,
615 vlan_id, goto_table=24)
616 # add mpls flow
Flavio Castro80730822015-12-11 15:38:47 -0500617 add_mpls_flow(self.controller, l3_msg.group_id, port)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500618 # add termination flow
619 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
620 vlan_id)
621 # add unicast routing flow
622 dst_ip = dip + (vlan_id << 8)
623 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
624 0xffffffff, l3_msg.group_id)
625 Groups._put(l2_gid)
626 Groups._put(l3_msg.group_id)
Flavio Castro80730822015-12-11 15:38:47 -0500627 do_barrier(self.controller)
628
629 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
630 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500631 mac_src = '00:00:00:22:22:%02X' % in_port
632 ip_src = '192.168.%02d.1' % in_port
Flavio Castro80730822015-12-11 15:38:47 -0500633 for out_port in ports:
634 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500635 continue
636 ip_dst = '192.168.%02d.1' % out_port
Flavio Castro80730822015-12-11 15:38:47 -0500637 switch_mac = "00:00:00:cc:cc:cc"
638 label = (out_port, 0, 1, 32)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500639 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
640 vlan_vid=in_port, ip_src=ip_src,
641 ip_dst=ip_dst, eth_dst=switch_mac,
642 eth_src=mac_src, label=[label])
643 pkt = str(parsed_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500644 self.dataplane.send(in_port, pkt)
645
Flavio Castro1c9b1252016-02-04 18:42:58 -0500646 # build expect packet
647 mac_dst = '00:00:00:22:22:%02X' % out_port
648 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
649 vlan_vid=out_port,
650 eth_dst=mac_dst, eth_src=switch_mac,
651 ip_ttl=31, ip_src=ip_src,
652 ip_dst=ip_dst)
653 pkt = str(exp_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500654 verify_packet(self, pkt, out_port)
655 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500656
657 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
658 vlan_vid=in_port,
659 eth_dst=switch_mac,
660 eth_src=mac_src, ip_ttl=64,
661 ip_src=ip_src,
662 ip_dst=ip_dst)
663 pkt = str(parsed_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500664 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500665 # build expected packet
666 mac_dst = '00:00:00:22:22:%02X' % out_port
667 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
668 vlan_vid=out_port,
669 eth_dst=mac_dst, eth_src=switch_mac,
670 ip_ttl=63,
671 ip_src=ip_src, ip_dst=ip_dst)
672 pkt = str(exp_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500673 verify_packet(self, pkt, out_port)
674 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500675 delete_all_flows(self.controller)
676 delete_groups(self.controller, Groups)
677
Flavio Castro80730822015-12-11 15:38:47 -0500678
Flavio Castro12296312015-12-15 17:48:26 -0500679class L3McastToL2(base_tests.SimpleDataPlane):
castroflaviocc403a92015-12-15 14:04:19 -0500680 """
Flavio Castro12296312015-12-15 17:48:26 -0500681 Mcast routing to L2
castroflaviocc403a92015-12-15 14:04:19 -0500682 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500683
castroflaviocc403a92015-12-15 14:04:19 -0500684 def runTest(self):
685 """
686 port1 (vlan 300)-> All Ports (vlan 300)
687 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500688 if len(config["port_map"]) < 3:
castroflavio4a09c962016-01-05 13:13:41 -0800689 logging.info("Port count less than 3, can't run this case")
Flavio Castro1c9b1252016-02-04 18:42:58 -0500690 assert (False)
castroflaviocc403a92015-12-15 14:04:19 -0500691 return
Flavio Castro1c9b1252016-02-04 18:42:58 -0500692 Groups = Queue.LifoQueue()
693 vlan_id = 300
694 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
695 intf_src_mac_str = ':'.join(['%02X' % x for x in intf_src_mac])
696 dst_mac = [0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
697 dst_mac_str = ':'.join(['%02X' % x for x in dst_mac])
698 port1_mac = [0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
699 port1_mac_str = ':'.join(['%02X' % x for x in port1_mac])
700 src_ip = 0xc0a80101
701 src_ip_str = "192.168.1.1"
702 dst_ip = 0xe0010101
703 dst_ip_str = "224.1.1.1"
castroflaviocc403a92015-12-15 14:04:19 -0500704
Flavio Castro1c9b1252016-02-04 18:42:58 -0500705 port1 = config["port_map"].keys()[0]
706 port2 = config["port_map"].keys()[1]
castroflaviocc403a92015-12-15 14:04:19 -0500707
708 switch_mac = [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00]
709
Flavio Castro1c9b1252016-02-04 18:42:58 -0500710 # add l2 interface group
711 l2_intf_group_list = []
castroflaviocc403a92015-12-15 14:04:19 -0500712 for port in config["port_map"].keys():
Flavio Castro1c9b1252016-02-04 18:42:58 -0500713 add_one_vlan_table_flow(self.controller, port, vlan_id,
714 flag=VLAN_TABLE_FLAG_ONLY_TAG)
castroflaviocc403a92015-12-15 14:04:19 -0500715 if port == port2:
716 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -0500717 l2_intf_gid, msg = add_one_l2_interface_group(self.controller, port,
718 vlan_id=vlan_id,
719 is_tagged=True,
720 send_barrier=False)
castroflaviocc403a92015-12-15 14:04:19 -0500721 l2_intf_group_list.append(l2_intf_gid)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500722 Groups.put(l2_intf_gid)
castroflaviocc403a92015-12-15 14:04:19 -0500723
Flavio Castro1c9b1252016-02-04 18:42:58 -0500724 # add termination flow
725 add_termination_flow(self.controller, port1, 0x0800, switch_mac,
726 vlan_id)
castroflaviocc403a92015-12-15 14:04:19 -0500727
Flavio Castro1c9b1252016-02-04 18:42:58 -0500728 # add l3 interface group
729 mcat_group_msg = add_l3_mcast_group(self.controller, vlan_id, 2,
730 l2_intf_group_list)
731 add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip,
732 mcat_group_msg.group_id)
733 Groups._put(mcat_group_msg.group_id)
castroflaviocc403a92015-12-15 14:04:19 -0500734
Flavio Castro1c9b1252016-02-04 18:42:58 -0500735 parsed_pkt = simple_udp_packet(pktlen=100,
Flavio Castro89933f22016-02-03 15:53:16 -0500736 dl_vlan_enable=True,
737 vlan_vid=vlan_id,
castroflaviocc403a92015-12-15 14:04:19 -0500738 eth_dst=dst_mac_str,
739 eth_src=port1_mac_str,
740 ip_ttl=64,
741 ip_src=src_ip_str,
742 ip_dst=dst_ip_str)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500743 pkt = str(parsed_pkt)
castroflaviocc403a92015-12-15 14:04:19 -0500744 self.dataplane.send(port1, pkt)
745 for port in config["port_map"].keys():
Flavio Castro12296312015-12-15 17:48:26 -0500746 if port == port2 or port == port1:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500747 verify_no_packet(self, pkt, port)
748 continue
castroflaviocc403a92015-12-15 14:04:19 -0500749 verify_packet(self, pkt, port)
750 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500751 delete_all_flows(self.controller)
752 delete_groups(self.controller, Groups)
753
castroflaviocc403a92015-12-15 14:04:19 -0500754
Flavio Castro12296312015-12-15 17:48:26 -0500755class L3McastToL3(base_tests.SimpleDataPlane):
756 """
757 Mcast routing
758 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500759
760 def runTest(self):
Flavio Castro12296312015-12-15 17:48:26 -0500761 """
762 port1 (vlan 1)-> port 2 (vlan 2)
763 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500764 Groups = Queue.LifoQueue()
765 if len(config["port_map"]) < 3:
castroflavio4a09c962016-01-05 13:13:41 -0800766 logging.info("Port count less than 3, can't run this case")
Flavio Castro1c9b1252016-02-04 18:42:58 -0500767 assert (False)
Flavio Castro12296312015-12-15 17:48:26 -0500768 return
769
Flavio Castro1c9b1252016-02-04 18:42:58 -0500770 vlan_id = 1
771 port2_out_vlan = 2
772 port3_out_vlan = 3
773 in_vlan = 1 # macast group vid shall use input vlan diffe from l3 interface use output vlan
774 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
775 intf_src_mac_str = ':'.join(['%02X' % x for x in intf_src_mac])
776 dst_mac = [0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
777 dst_mac_str = ':'.join(['%02X' % x for x in dst_mac])
778 port1_mac = [0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
779 port1_mac_str = ':'.join(['%02X' % x for x in port1_mac])
780 src_ip = 0xc0a80101
781 src_ip_str = "192.168.1.1"
782 dst_ip = 0xe0010101
783 dst_ip_str = "224.1.1.1"
Flavio Castro12296312015-12-15 17:48:26 -0500784
Flavio Castro1c9b1252016-02-04 18:42:58 -0500785 port1 = config["port_map"].keys()[0]
786 port2 = config["port_map"].keys()[1]
787 port3 = config["port_map"].keys()[2]
Flavio Castro12296312015-12-15 17:48:26 -0500788
Flavio Castro1c9b1252016-02-04 18:42:58 -0500789 # add l2 interface group
790 for port in config["port_map"].keys():
791 l2gid, msg = add_one_l2_interface_group(self.controller, port,
792 vlan_id=vlan_id,
793 is_tagged=False,
794 send_barrier=False)
795 # add vlan flow table
796 add_one_vlan_table_flow(self.controller, port, vlan_id,
797 flag=VLAN_TABLE_FLAG_ONLY_TAG)
798 vlan_id += 1
799 Groups._put(l2gid)
Flavio Castro12296312015-12-15 17:48:26 -0500800
Flavio Castro1c9b1252016-02-04 18:42:58 -0500801 # add termination flow
802 add_termination_flow(self.controller, port1, 0x0800,
803 [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
804
805 # add l3 interface group
806 port2_ucast_msg = add_l3_interface_group(self.controller, port2,
807 port2_out_vlan, 2,
808 intf_src_mac)
809 port3_ucast_msg = add_l3_interface_group(self.controller, port3,
810 port3_out_vlan, 3,
811 intf_src_mac)
812 mcat_group_msg = add_l3_mcast_group(self.controller, in_vlan, 2,
813 [port2_ucast_msg.group_id,
814 port3_ucast_msg.group_id])
815 add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip,
816 mcat_group_msg.group_id)
817 Groups._put(port2_ucast_msg.group_id)
818 Groups._put(port3_ucast_msg.group_id)
819 Groups._put(mcat_group_msg.group_id)
820 parsed_pkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
821 vlan_vid=1,
Flavio Castro12296312015-12-15 17:48:26 -0500822 eth_dst=dst_mac_str,
823 eth_src=port1_mac_str,
824 ip_ttl=64,
825 ip_src=src_ip_str,
826 ip_dst=dst_ip_str)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500827 pkt = str(parsed_pkt)
828 self.dataplane.send(port1, pkt)
829 parsed_pkt = simple_udp_packet(pktlen=96,
Flavio Castro12296312015-12-15 17:48:26 -0500830 eth_dst=dst_mac_str,
831 eth_src=intf_src_mac_str,
832 ip_ttl=63,
833 ip_src=src_ip_str,
834 ip_dst=dst_ip_str)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500835 pkt = str(parsed_pkt)
Flavio Castro12296312015-12-15 17:48:26 -0500836 verify_packet(self, pkt, port2)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500837 verify_packet(self, pkt, port3)
838 verify_no_other_packets(self)
839 delete_all_flows(self.controller)
840 delete_groups(self.controller, Groups)
Flavio Castro54947942016-02-03 16:05:20 -0500841
842
Flavio Castrof54be492016-02-03 16:26:22 -0500843class _MplsTermination(base_tests.SimpleDataPlane):
Flavio Castro12296312015-12-15 17:48:26 -0500844 """
Flavio Castro54947942016-02-03 16:05:20 -0500845 Insert IP packet
846 Receive MPLS packet
castroflavio30c6cc52016-01-07 15:19:42 -0800847 """
castroflavio30c6cc52016-01-07 15:19:42 -0800848
Flavio Castro1c9b1252016-02-04 18:42:58 -0500849 def runTest(self):
850 Groups = Queue.LifoQueue()
851 if len(config["port_map"]) < 2:
castroflavio30c6cc52016-01-07 15:19:42 -0800852 logging.info("Port count less than 2, can't run this case")
853 return
854
Flavio Castro1c9b1252016-02-04 18:42:58 -0500855 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
856 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
857 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
castroflavio30c6cc52016-01-07 15:19:42 -0800858 ports = config["port_map"].keys()
859 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500860 # add l2 interface group
861 id = port
862 vlan_id = id
863 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
864 vlan_id, True, False)
865 dst_mac[5] = vlan_id
866 # add L3 Unicast group
867 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
868 id=id, src_mac=intf_src_mac,
869 dst_mac=dst_mac)
870 # add L3 ecmp group
Flavio Castro54947942016-02-03 16:05:20 -0500871 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
Flavio Castro1c9b1252016-02-04 18:42:58 -0500872 # add vlan flow table
873 add_one_vlan_table_flow(self.controller, port, vlan_id,
874 flag=VLAN_TABLE_FLAG_ONLY_TAG)
875 # add termination flow
876 add_termination_flow(self.controller, port, 0x8847, intf_src_mac,
877 vlan_id, goto_table=24)
Flavio Castro54947942016-02-03 16:05:20 -0500878 add_mpls_flow(self.controller, ecmp_msg.group_id, port)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500879 Groups._put(l2_gid)
880 Groups._put(l3_msg.group_id)
881 Groups._put(ecmp_msg.group_id)
castroflavio30c6cc52016-01-07 15:19:42 -0800882 do_barrier(self.controller)
883
884 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
885 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500886 ip_src = '192.168.%02d.1' % (in_port)
castroflavio30c6cc52016-01-07 15:19:42 -0800887 for out_port in ports:
888 if in_port == out_port:
Flavio Castro54947942016-02-03 16:05:20 -0500889 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -0500890 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castro54947942016-02-03 16:05:20 -0500891
892 label = (out_port, 0, 1, 32)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500893 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
894 vlan_vid=(in_port), ip_src=ip_src,
895 ip_dst=ip_dst, eth_dst=switch_mac,
896 label=[label])
897 pkt = str(parsed_pkt)
castroflavio30c6cc52016-01-07 15:19:42 -0800898 self.dataplane.send(in_port, pkt)
Flavio Castro54947942016-02-03 16:05:20 -0500899
Flavio Castro1c9b1252016-02-04 18:42:58 -0500900 # build expect packet
901 mac_dst = '00:00:00:22:22:%02X' % (out_port)
902 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
903 vlan_vid=(out_port),
904 eth_dst=mac_dst, eth_src=switch_mac,
905 ip_ttl=31, ip_src=ip_src,
906 ip_dst=ip_dst)
907 pkt = str(exp_pkt)
castroflavio30c6cc52016-01-07 15:19:42 -0800908 verify_packet(self, pkt, out_port)
909 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500910 delete_all_flows(self.controller)
911 delete_groups(self.controller, Groups)
912
Flavio Castrod0619992016-02-04 15:10:28 -0500913
914class _32ECMPL3(base_tests.SimpleDataPlane):
915 """
916 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
917 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
918 """
Flavio Castrod0619992016-02-04 15:10:28 -0500919
Flavio Castro1c9b1252016-02-04 18:42:58 -0500920 def runTest(self):
921 Groups = Queue.LifoQueue()
922 if len(config["port_map"]) < 2:
Flavio Castrod0619992016-02-04 15:10:28 -0500923 logging.info("Port count less than 2, can't run this case")
924 return
925
Flavio Castro1c9b1252016-02-04 18:42:58 -0500926 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
927 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
928 dip = 0xc0a80001
929 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castrod0619992016-02-04 15:10:28 -0500930 ports = config["port_map"].keys()
931 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500932 vlan_id = port
933 id = port
934 # add l2 interface group
935 l2_gid, msg = add_one_l2_interface_group(self.controller, port,
936 vlan_id=vlan_id,
937 is_tagged=True,
938 send_barrier=False)
939 dst_mac[5] = vlan_id
940 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
941 id=id, src_mac=intf_src_mac,
942 dst_mac=dst_mac)
943 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
944 # add vlan flow table
945 add_one_vlan_table_flow(self.controller, port, vlan_id,
946 flag=VLAN_TABLE_FLAG_ONLY_TAG)
947 # add termination flow
948 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
949 vlan_id)
950 # add unicast routing flow
951 dst_ip = dip + (vlan_id << 8)
952 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
953 0xffffffff, ecmp_msg.group_id)
954 Groups._put(l2_gid)
955 Groups._put(l3_msg.group_id)
956 Groups._put(ecmp_msg.group_id)
Flavio Castrod0619992016-02-04 15:10:28 -0500957 do_barrier(self.controller)
958
959 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
960 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500961 mac_src = '00:00:00:22:22:%02X' % in_port
962 ip_src = '192.168.%02d.1' % in_port
Flavio Castrod0619992016-02-04 15:10:28 -0500963 for out_port in ports:
964 if in_port == out_port:
965 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -0500966 ip_dst = '192.168.%02d.1' % out_port
967 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
968 vlan_vid=in_port,
969 eth_dst=switch_mac,
970 eth_src=mac_src, ip_ttl=64,
971 ip_src=ip_src,
Flavio Castrod0619992016-02-04 15:10:28 -0500972 ip_dst=ip_dst)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500973 pkt = str(parsed_pkt)
Flavio Castrod0619992016-02-04 15:10:28 -0500974 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500975 # build expected packet
976 mac_dst = '00:00:00:22:22:%02X' % out_port
977 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
978 vlan_vid=out_port,
979 eth_dst=mac_dst, eth_src=switch_mac,
980 ip_ttl=63,
Flavio Castrod0619992016-02-04 15:10:28 -0500981 ip_src=ip_src, ip_dst=ip_dst)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500982 pkt = str(exp_pkt)
Flavio Castrod0619992016-02-04 15:10:28 -0500983 verify_packet(self, pkt, out_port)
984 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500985 delete_all_flows(self.controller)
986 delete_groups(self.controller, Groups)
Flavio Castrod0619992016-02-04 15:10:28 -0500987
Flavio Castro1c9b1252016-02-04 18:42:58 -0500988
989class _24ECMPL3(base_tests.SimpleDataPlane):
990 """
991 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
992 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
993 """
994
995 def runTest(self):
996 Groups = Queue.LifoQueue()
997 if len(config["port_map"]) < 2:
998 logging.info("Port count less than 2, can't run this case")
999 return
1000
1001 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1002 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1003 dip = 0xc0a80001
1004 # Hashes Test Name and uses it as id for installing unique groups
1005 ports = config["port_map"].keys()
1006 for port in ports:
1007 vlan_id = port
1008 id = port
1009 # add l2 interface group
1010 l2_gid, msg = add_one_l2_interface_group(self.controller, port,
1011 vlan_id=vlan_id,
1012 is_tagged=True,
1013 send_barrier=False)
1014 dst_mac[5] = vlan_id
1015 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
1016 id=id, src_mac=intf_src_mac,
1017 dst_mac=dst_mac)
1018 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
1019 # add vlan flow table
1020 add_one_vlan_table_flow(self.controller, port, vlan_id,
1021 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1022 # add termination flow
1023 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
1024 vlan_id)
1025 # add unicast routing flow
1026 dst_ip = dip + (vlan_id << 8)
1027 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
1028 0xffffff00, ecmp_msg.group_id)
1029 Groups._put(l2_gid)
1030 Groups._put(l3_msg.group_id)
1031 Groups._put(ecmp_msg.group_id)
1032 do_barrier(self.controller)
1033
1034 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1035 for in_port in ports:
1036 mac_src = '00:00:00:22:22:%02X' % in_port
1037 ip_src = '192.168.%02d.1' % in_port
1038 for out_port in ports:
1039 if in_port == out_port:
1040 continue
1041 ip_dst = '192.168.%02d.1' % out_port
1042 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1043 vlan_vid=in_port,
1044 eth_dst=switch_mac,
1045 eth_src=mac_src, ip_ttl=64,
1046 ip_src=ip_src,
1047 ip_dst=ip_dst)
1048 pkt = str(parsed_pkt)
1049 self.dataplane.send(in_port, pkt)
1050 # build expected packet
1051 mac_dst = '00:00:00:22:22:%02X' % out_port
1052 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1053 vlan_vid=out_port,
1054 eth_dst=mac_dst, eth_src=switch_mac,
1055 ip_ttl=63,
1056 ip_src=ip_src, ip_dst=ip_dst)
1057 pkt = str(exp_pkt)
1058 verify_packet(self, pkt, out_port)
1059 verify_no_other_packets(self)
1060 delete_all_flows(self.controller)
1061 delete_groups(self.controller, Groups)
1062
1063
1064class _24UcastTagged(base_tests.SimpleDataPlane):
1065 """
1066 Verify a IP forwarding works for a /32 rule to L3 Unicast Interface
1067 """
1068
1069 def runTest(self):
1070 test_id = 26
1071 if len(config["port_map"]) < 2:
1072 logging.info("Port count less than 2, can't run this case")
1073 return
1074
1075 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1076 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1077 dip = 0xc0a80001
1078 ports = config["port_map"].keys()
1079 Groups = Queue.LifoQueue()
1080 for port in ports:
1081 # add l2 interface group
1082 vlan_id = port + test_id
1083 l2gid, msg = add_one_l2_interface_group(self.controller, port,
1084 vlan_id=vlan_id,
1085 is_tagged=True,
1086 send_barrier=False)
1087 dst_mac[5] = vlan_id
1088 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
1089 id=vlan_id, src_mac=intf_src_mac,
1090 dst_mac=dst_mac)
1091 # add vlan flow table
1092 add_one_vlan_table_flow(self.controller, port, vlan_id,
1093 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1094 # add termination flow
1095 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
1096 vlan_id)
1097 # add unicast routing flow
1098 dst_ip = dip + (vlan_id << 8)
1099 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
1100 0xffffff00, l3_msg.group_id)
1101 Groups.put(l2gid)
1102 Groups.put(l3_msg.group_id)
1103 do_barrier(self.controller)
1104
1105 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1106 for in_port in ports:
1107 mac_src = '00:00:00:22:22:%02X' % (test_id + in_port)
1108 ip_src = '192.168.%02d.1' % (test_id + in_port)
1109 for out_port in ports:
1110 if in_port == out_port:
1111 continue
1112 ip_dst = '192.168.%02d.1' % (test_id + out_port)
1113 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1114 vlan_vid=(test_id + in_port),
1115 eth_dst=switch_mac,
1116 eth_src=mac_src, ip_ttl=64,
1117 ip_src=ip_src,
1118 ip_dst=ip_dst)
1119 pkt = str(parsed_pkt)
1120 self.dataplane.send(in_port, pkt)
1121 # build expected packet
1122 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
1123 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1124 vlan_vid=(test_id + out_port),
1125 eth_dst=mac_dst, eth_src=switch_mac,
1126 ip_ttl=63,
1127 ip_src=ip_src, ip_dst=ip_dst)
1128 pkt = str(exp_pkt)
1129 verify_packet(self, pkt, out_port)
1130 verify_no_other_packets(self)
1131 delete_all_flows(self.controller)
1132 delete_groups(self.controller, Groups)