blob: 013bc6b5706c10a0e8b89c245ccf398dc30a53a4 [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"""
16
Flavio Castro05d20bc2015-11-16 15:06:14 -050017from oftest import config
Flavio Castro67d8bd52016-02-03 14:22:14 -050018import inspect
Flavio Castro167f5bd2015-12-02 19:33:53 -050019import logging
20import oftest.base_tests as base_tests
Flavio Castro05d20bc2015-11-16 15:06:14 -050021import ofp
22from oftest.testutils import *
23from accton_util import *
Flavio Castrod8f8af22015-12-02 18:19:26 -050024
Flavio Castro67d8bd52016-02-03 14:22:14 -050025@disabled
Flavio Castroaabb5792015-11-18 19:03:50 -050026class PacketInSrcMacMiss(base_tests.SimpleDataPlane):
27 """
28 Test packet in function on a src-mac miss
29 Send a packet to each dataplane port and verify that a packet
30 in message is received from the controller for each
31 #todo verify you stop receiving after adding rule
32 """
33
Flavio Castro6efe1862015-11-18 16:28:06 -050034 def runTest(self):
35 delete_all_flows(self.controller)
36 delete_all_groups(self.controller)
37
Flavio Castro34352e72015-12-07 20:01:51 -050038 ports = sorted(config["port_map"].keys())
39 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -050040 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -050041 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
42
Flavio Castroaabb5792015-11-18 19:03:50 -050043 parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
44 vlan_vid=0x1001, dl_vlan_enable=True)
45 vlan_pkt = str(parsed_vlan_pkt)
Flavio Castro6efe1862015-11-18 16:28:06 -050046
Flavio Castroaabb5792015-11-18 19:03:50 -050047 for of_port in config["port_map"].keys():
48 logging.info("PacketInMiss test, port %d", of_port)
49 self.dataplane.send(of_port, vlan_pkt)
50
51 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH)
52
53 verify_no_other_packets(self)
54
Flavio Castro7fb6ca92015-12-16 15:50:14 -050055class PacketInUDP(base_tests.SimpleDataPlane):
Flavio Castro6d498522015-12-15 14:05:04 -050056 """
57 Test packet in function for a table-miss flow
58 Send a packet to each dataplane port and verify that a packet
59 in message is received from the controller for each
60
61 NOTE: Verify This case the oft option shall not use --switch-ip
62 """
63
64 def runTest(self):
65 delete_all_flows(self.controller)
66 delete_all_groups(self.controller)
67
68 parsed_vlan_pkt = simple_udp_packet(pktlen=104,
69 vlan_vid=0x1001, dl_vlan_enable=True)
70 vlan_pkt = str(parsed_vlan_pkt)
Flavio Castro6d498522015-12-15 14:05:04 -050071 # create match
72 match = ofp.match()
73 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
castroflavio4a09c962016-01-05 13:13:41 -080074 match.oxm_list.append(ofp.oxm.ip_proto(17))
Flavio Castro6d498522015-12-15 14:05:04 -050075 request = ofp.message.flow_add(
76 table_id=60,
77 cookie=42,
78 match=match,
79 instructions=[
80 ofp.instruction.apply_actions(
81 actions=[
82 ofp.action.output(
83 port=ofp.OFPP_CONTROLLER,
84 max_len=ofp.OFPCML_NO_BUFFER)]),
85 ],
86 buffer_id=ofp.OFP_NO_BUFFER,
87 priority=1)
88
89 logging.info("Inserting packet in flow to controller")
90 self.controller.message_send(request)
91 do_barrier(self.controller)
92
93 for of_port in config["port_map"].keys():
94 logging.info("PacketInMiss test, port %d", of_port)
95 self.dataplane.send(of_port, vlan_pkt)
96
97 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
98
99 verify_no_other_packets(self)
Flavio Castro67d8bd52016-02-03 14:22:14 -0500100@disabled
Flavio Castroaf2b4502016-02-02 17:41:32 -0500101class PacketInIPTable(base_tests.SimpleDataPlane):
102 """
103 Test packet in function on IPTABLE
104 Send a packet to each dataplane port and verify that a packet
105 in message is received from the controller for each
106 #todo verify you stop receiving after adding rule
107 """
108
109 def runTest(self):
110 delete_all_flows(self.controller)
111 delete_all_groups(self.controller)
112
113 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
114 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
115 dip=0xc0a80001
116 ports = sorted(config["port_map"].keys())
117 for port in ports:
118 #add l2 interface group
119 vlan_id=port
120 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
121 dst_mac[5]=vlan_id
122 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
123 #add vlan flow table
124 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
125 #add termination flow
126 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
127 #add unicast routing flow
128 dst_ip = dip + (vlan_id<<8)
129 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xfffffff0, l3_msg.group_id, send_ctrl=True)
130
131 do_barrier(self.controller)
132
133 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
134 for in_port in ports:
135 mac_src='00:00:00:22:22:%02X' % in_port
136 ip_src='192.168.%02d.1' % in_port
137 for out_port in ports:
138 if in_port == out_port:
139 continue
140 ip_dst='192.168.%02d.1' % out_port
141 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
142 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
143 ip_dst=ip_dst)
144 pkt=str(parsed_pkt)
145 self.dataplane.send(in_port, pkt)
146 verify_packet_in(self, pkt, in_port, ofp.OFPR_ACTION)
147 #verify_no_other_packets(self)
148
Flavio Castro67d8bd52016-02-03 14:22:14 -0500149@disabled
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500150class ArpNL2(base_tests.SimpleDataPlane):
151 def runTest(self):
152 delete_all_flows(self.controller)
153 delete_all_groups(self.controller)
154
155 ports = sorted(config["port_map"].keys())
156 match = ofp.match()
157 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
158 request = ofp.message.flow_add(
159 table_id=60,
160 cookie=42,
161 match=match,
162 instructions=[
163 ofp.instruction.apply_actions(
164 actions=[
165 ofp.action.output(
166 port=ofp.OFPP_CONTROLLER,
167 max_len=ofp.OFPCML_NO_BUFFER)]),
168 ],
169 buffer_id=ofp.OFP_NO_BUFFER,
170 priority=40000)
171 self.controller.message_send(request)
172 for port in ports:
Flavio Castro932014b2016-01-05 18:29:15 -0500173 add_one_l2_interface_group(self.controller, port, 1, False, False)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500174 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
175 group_id = encode_l2_interface_group_id(1, port)
176 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
177 do_barrier(self.controller)
178 parsed_arp_pkt = simple_arp_packet()
179 arp_pkt = str(parsed_arp_pkt)
180
181 for out_port in ports:
182 self.dataplane.send(out_port, arp_pkt)
183 verify_packet_in(self, arp_pkt, out_port, ofp.OFPR_ACTION)
184 # change dest based on port number
185 mac_dst= '00:12:34:56:78:%02X' % out_port
186 for in_port in ports:
187 if in_port == out_port:
188 continue
189 # change source based on port number to avoid packet-ins from learning
190 mac_src= '00:12:34:56:78:%02X' % in_port
191 parsed_pkt = simple_tcp_packet(eth_dst=mac_dst, eth_src=mac_src)
192 pkt = str(parsed_pkt)
193 self.dataplane.send(in_port, pkt)
194
195 for ofport in ports:
196 if ofport in [out_port]:
197 verify_packet(self, pkt, ofport)
198 else:
199 verify_no_packet(self, pkt, ofport)
200
201 verify_no_other_packets(self)
202
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500203class PacketInArp(base_tests.SimpleDataPlane):
204 """
205 Test packet in function for a table-miss flow
206 Send a packet to each dataplane port and verify that a packet
207 in message is received from the controller for each
208
209 NOTE: Verify This case the oft option shall not use --switch-ip
210 """
211
212 def runTest(self):
213 delete_all_flows(self.controller)
214 delete_all_groups(self.controller)
215
216 parsed_arp_pkt = simple_arp_packet()
217 arp_pkt = str(parsed_arp_pkt)
218 ports = sorted(config["port_map"].keys())
219 #for port in ports:
220 # add_one_l2_interface_group(self.controller, port, 1, True, False)
221 # add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
222
223 # create match
224 match = ofp.match()
225 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
226 request = ofp.message.flow_add(
227 table_id=60,
228 cookie=42,
229 match=match,
230 instructions=[
231 ofp.instruction.apply_actions(
232 actions=[
233 ofp.action.output(
234 port=ofp.OFPP_CONTROLLER,
235 max_len=ofp.OFPCML_NO_BUFFER)]),
236 ],
237 buffer_id=ofp.OFP_NO_BUFFER,
238 priority=1)
239
240 logging.info("Inserting packet in flow to controller")
241 self.controller.message_send(request)
242 do_barrier(self.controller)
243
244 for of_port in config["port_map"].keys():
245 logging.info("PacketInMiss test, port %d", of_port)
246 self.dataplane.send(of_port, arp_pkt)
247
248 verify_packet_in(self, arp_pkt, of_port, ofp.OFPR_ACTION)
249
250 verify_no_other_packets(self)
251
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500252class L2FloodQinQ(base_tests.SimpleDataPlane):
253 """
Flavio Castroc36621e2015-12-08 12:57:07 -0500254 Test L2 flood of double tagged vlan packets (802.1Q)
255 Sends a double tagged packet and verifies flooding behavior according to outer vlan
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500256 """
257 def runTest(self):
258 ports = sorted(config["port_map"].keys())
259
260 delete_all_flows(self.controller)
261 delete_all_groups(self.controller)
262
263 # Installing flows to avoid packet-in
264 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500265 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500266 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
267
268 group_id = encode_l2_interface_group_id(1, port)
269 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
270 msg=add_l2_flood_group(self.controller, ports, 1, 1)
271 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
272 do_barrier(self.controller)
273
274 #verify flood
275 for ofport in ports:
276 # change dest based on port number
277 mac_src= '00:12:34:56:78:%02X' % ofport
278 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108, out_dl_vlan_enable=True, out_vlan_vid=1,
279 in_dl_vlan_enable=True, in_vlan_vid=10, eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
280 pkt = str(parsed_pkt)
281 self.dataplane.send(ofport, pkt)
282 #self won't rx packet
283 verify_no_packet(self, pkt, ofport)
284 #others will rx packet
285 tmp_ports=list(ports)
286 tmp_ports.remove(ofport)
287 verify_packets(self, pkt, tmp_ports)
288
289 verify_no_other_packets(self)
290
Flavio Castro184cefe2015-11-19 20:52:49 -0500291class L2FloodTagged(base_tests.SimpleDataPlane):
292 """
293 Test L2 flood to a vlan
294 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
295 #todo take in account unknown src
296 """
297 def runTest(self):
298 ports = sorted(config["port_map"].keys())
Flavio Castro34352e72015-12-07 20:01:51 -0500299
Flavio Castro184cefe2015-11-19 20:52:49 -0500300 delete_all_flows(self.controller)
301 delete_all_groups(self.controller)
302
Flavio Castro184cefe2015-11-19 20:52:49 -0500303 # Installing flows to avoid packet-in
304 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500305 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500306 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
307
Flavio Castro184cefe2015-11-19 20:52:49 -0500308 group_id = encode_l2_interface_group_id(1, port)
309 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
Flavio Castro34352e72015-12-07 20:01:51 -0500310 msg=add_l2_flood_group(self.controller, ports, 1, 1)
311 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
Flavio Castro184cefe2015-11-19 20:52:49 -0500312 do_barrier(self.controller)
313
314 #verify flood
315 for ofport in ports:
316 # change dest based on port number
317 mac_src= '00:12:34:56:78:%02X' % ofport
318 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
319 pkt = str(parsed_pkt)
320 self.dataplane.send(ofport, pkt)
321 #self won't rx packet
322 verify_no_packet(self, pkt, ofport)
323 #others will rx packet
324 tmp_ports=list(ports)
325 tmp_ports.remove(ofport)
326 verify_packets(self, pkt, tmp_ports)
327
328 verify_no_other_packets(self)
Flavio Castro67d8bd52016-02-03 14:22:14 -0500329@disabled
Flavio Castroaabb5792015-11-18 19:03:50 -0500330class L2FloodTaggedUnknownSrc(base_tests.SimpleDataPlane):
331 """
332 Test L2 flood to a vlan
333 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
334 #todo take in account unknown src
335 """
336 def runTest(self):
Flavio Castroaabb5792015-11-18 19:03:50 -0500337 delete_all_flows(self.controller)
338 delete_all_groups(self.controller)
339
Flavio Castro34352e72015-12-07 20:01:51 -0500340 ports = sorted(config["port_map"].keys())
341 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500342 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500343 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castroaabb5792015-11-18 19:03:50 -0500344
345 msg=add_l2_flood_group(self.controller, ports, 1, 1)
346 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
347
348 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a')
349 pkt = str(parsed_pkt)
350 #verify flood
351 for ofport in ports:
352 self.dataplane.send(ofport, pkt)
353 #self won't rx packet
354 verify_no_packet(self, pkt, ofport)
355 #others will rx packet
356 tmp_ports=list(ports)
357 tmp_ports.remove(ofport)
358 verify_packets(self, pkt, tmp_ports)
359
360 verify_no_other_packets(self)
361
Flavio Castroaabb5792015-11-18 19:03:50 -0500362class L2UnicastTagged(base_tests.SimpleDataPlane):
363 """
364 Test output function for an exact-match flow
365
366 For each port A, adds a flow directing matching packets to that port.
367 Then, for all other ports B != A, verifies that sending a matching packet
368 to B results in an output to A.
369 """
370 def runTest(self):
371 ports = sorted(config["port_map"].keys())
372
373 delete_all_flows(self.controller)
374 delete_all_groups(self.controller)
375
Flavio Castroaabb5792015-11-18 19:03:50 -0500376 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500377 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500378 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castroaabb5792015-11-18 19:03:50 -0500379 group_id = encode_l2_interface_group_id(1, port)
380 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
Flavio Castro6efe1862015-11-18 16:28:06 -0500381 do_barrier(self.controller)
382
Flavio Castroaabb5792015-11-18 19:03:50 -0500383 for out_port in ports:
384 # change dest based on port number
385 mac_dst= '00:12:34:56:78:%02X' % out_port
386 for in_port in ports:
387 if in_port == out_port:
388 continue
389 # change source based on port number to avoid packet-ins from learning
390 mac_src= '00:12:34:56:78:%02X' % in_port
391 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
392 pkt = str(parsed_pkt)
393 self.dataplane.send(in_port, pkt)
394
395 for ofport in ports:
396 if ofport in [out_port]:
397 verify_packet(self, pkt, ofport)
398 else:
399 verify_no_packet(self, pkt, ofport)
400
401 verify_no_other_packets(self)
Flavio Castro6efe1862015-11-18 16:28:06 -0500402
Flavio Castrob6773032015-11-19 22:49:24 -0500403class Mtu1500(base_tests.SimpleDataPlane):
404
405 def runTest(self):
406 ports = sorted(config["port_map"].keys())
407
408 delete_all_flows(self.controller)
409 delete_all_groups(self.controller)
410
Flavio Castro34352e72015-12-07 20:01:51 -0500411 # set up tag groups for each port
Flavio Castrod4c44d12015-12-08 14:44:18 -0500412 add_l2_interface_group(self.controller, ports, 1, True, 1)
Flavio Castrob6773032015-11-19 22:49:24 -0500413
Flavio Castro34352e72015-12-07 20:01:51 -0500414 add_vlan_table_flow(self.controller, ports)
Flavio Castrob6773032015-11-19 22:49:24 -0500415
416 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500417 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500418 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrob6773032015-11-19 22:49:24 -0500419 group_id = encode_l2_interface_group_id(1, port)
420 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
421 do_barrier(self.controller)
422
423 for out_port in ports:
424 # change dest based on port number
425 mac_dst= '00:12:34:56:78:%02X' % out_port
426 for in_port in ports:
427 if in_port == out_port:
428 continue
429 # change source based on port number to avoid packet-ins from learning
430 mac_src= '00:12:34:56:78:%02X' % in_port
431 parsed_pkt = simple_tcp_packet(pktlen=1500,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
432 pkt = str(parsed_pkt)
433 self.dataplane.send(in_port, pkt)
434
435 for ofport in ports:
436 if ofport in [out_port]:
437 verify_packet(self, pkt, ofport)
438 else:
439 verify_no_packet(self, pkt, ofport)
440
441 verify_no_other_packets(self)
442
Flavio Castro67d8bd52016-02-03 14:22:14 -0500443@disabled
Flavio Castrob6773032015-11-19 22:49:24 -0500444class Mtu4000(base_tests.SimpleDataPlane):
445 """
446 Test output function for an exact-match flow
447 For each port A, adds a flow directing matching packets to that port.
448 Then, for all other ports B != A, verifies that sending a matching packet
449 to B results in an output to A.
450 """
451 def runTest(self):
452 ports = sorted(config["port_map"].keys())
453
454 delete_all_flows(self.controller)
455 delete_all_groups(self.controller)
456
457 add_vlan_table_flow(self.controller, config["port_map"].keys())
458
459 # set up tag groups for each port
Flavio Castrod4c44d12015-12-08 14:44:18 -0500460 add_l2_interface_group(self.controller, config["port_map"].keys(), 1, True, 1)
Flavio Castrob6773032015-11-19 22:49:24 -0500461
462 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500463 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500464 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrob6773032015-11-19 22:49:24 -0500465 group_id = encode_l2_interface_group_id(1, port)
466 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
467 do_barrier(self.controller)
468
469 for out_port in ports:
470 # change dest based on port number
471 mac_dst= '00:12:34:56:78:%02X' % out_port
472 for in_port in ports:
473 if in_port == out_port:
474 continue
475 # change source based on port number to avoid packet-ins from learning
476 mac_src= '00:12:34:56:78:%02X' % in_port
477 parsed_pkt = simple_tcp_packet(pktlen=4000,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
478 pkt = str(parsed_pkt)
479 self.dataplane.send(in_port, pkt)
480
481 for ofport in ports:
482 if ofport in [out_port]:
483 verify_packet(self, pkt, ofport)
484 else:
485 verify_no_packet(self, pkt, ofport)
486
487 verify_no_other_packets(self)
Flavio Castroaabb5792015-11-18 19:03:50 -0500488
489class L3UcastTagged(base_tests.SimpleDataPlane):
Flavio Castro05d20bc2015-11-16 15:06:14 -0500490 """
Flavio Castro35e64392015-12-02 16:53:14 -0500491 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
492 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500493 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500494 def runTest(self):
Flavio Castro05d20bc2015-11-16 15:06:14 -0500495 delete_all_flows(self.controller)
496 delete_all_groups(self.controller)
497
498 if len(config["port_map"]) <2:
499 logging.info("Port count less than 2, can't run this case")
500 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500501
Flavio Castro05d20bc2015-11-16 15:06:14 -0500502 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
503 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
504 dip=0xc0a80001
Flavio Castroa8233862015-12-02 14:41:11 -0500505 ports = config["port_map"].keys()
506 for port in ports:
Flavio Castro05d20bc2015-11-16 15:06:14 -0500507 #add l2 interface group
Flavio Castroa8233862015-12-02 14:41:11 -0500508 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500509 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500510 dst_mac[5]=vlan_id
511 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
512 #add vlan flow table
Flavio Castro34352e72015-12-07 20:01:51 -0500513 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500514 #add termination flow
Flavio Castrod8f8af22015-12-02 18:19:26 -0500515 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500516 #add unicast routing flow
Flavio Castrod8f8af22015-12-02 18:19:26 -0500517 dst_ip = dip + (vlan_id<<8)
Flavio Castroaf2b4502016-02-02 17:41:32 -0500518 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id)
Flavio Castro6efe1862015-11-18 16:28:06 -0500519 #add entries in the Bridging table to avoid packet-in from mac learning
520 group_id = encode_l2_interface_group_id(vlan_id, port)
521 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500522
523 do_barrier(self.controller)
524
Flavio Castro05d20bc2015-11-16 15:06:14 -0500525 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
Flavio Castroa8233862015-12-02 14:41:11 -0500526 for in_port in ports:
527 mac_src='00:00:00:22:22:%02X' % in_port
528 ip_src='192.168.%02d.1' % in_port
529 for out_port in ports:
530 if in_port == out_port:
531 continue
532 ip_dst='192.168.%02d.1' % out_port
533 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
534 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
Flavio Castrod8f8af22015-12-02 18:19:26 -0500535 ip_dst=ip_dst)
Flavio Castroa8233862015-12-02 14:41:11 -0500536 pkt=str(parsed_pkt)
537 self.dataplane.send(in_port, pkt)
Flavio Castro72a45d52015-12-02 16:37:05 -0500538 #build expected packet
Flavio Castroa8233862015-12-02 14:41:11 -0500539 mac_dst='00:00:00:22:22:%02X' % out_port
Flavio Castrod8f8af22015-12-02 18:19:26 -0500540 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
Flavio Castroa8233862015-12-02 14:41:11 -0500541 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
542 ip_src=ip_src, ip_dst=ip_dst)
543 pkt=str(exp_pkt)
544 verify_packet(self, pkt, out_port)
545 verify_no_other_packets(self)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500546
Flavio Castrod8f8af22015-12-02 18:19:26 -0500547class L3VPNMPLS(base_tests.SimpleDataPlane):
548 """
549 Insert IP packet
550 Receive MPLS packet
551 """
Flavio Castro72a45d52015-12-02 16:37:05 -0500552 def runTest(self):
553 delete_all_flows(self.controller)
554 delete_all_groups(self.controller)
555
556 if len(config["port_map"]) <2:
557 logging.info("Port count less than 2, can't run this case")
558 return
559
560 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
561 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
562 dip=0xc0a80001
563 index=1
564 ports = config["port_map"].keys()
565 for port in ports:
566 #add l2 interface group
567 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500568 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
Flavio Castro72a45d52015-12-02 16:37:05 -0500569 dst_mac[5]=vlan_id
Flavio Castro35e64392015-12-02 16:53:14 -0500570 #add MPLS interface group
Flavio Castro72a45d52015-12-02 16:37:05 -0500571 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, port)
Flavio Castro35e64392015-12-02 16:53:14 -0500572 #add MPLS L3 VPN group
Flavio Castrod8f8af22015-12-02 18:19:26 -0500573 mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
Flavio Castro72a45d52015-12-02 16:37:05 -0500574 index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32)
Flavio Castro5edf3132016-01-27 15:45:08 -0500575 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castro80730822015-12-11 15:38:47 -0500576 do_barrier(self.controller)
Flavio Castro72a45d52015-12-02 16:37:05 -0500577 #add vlan flow table
Flavio Castro80730822015-12-11 15:38:47 -0500578 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=2, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castro72a45d52015-12-02 16:37:05 -0500579 #add termination flow
580 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
Flavio Castro35e64392015-12-02 16:53:14 -0500581 #add routing flow
Flavio Castroaf2b4502016-02-02 17:41:32 -0500582 dst_ip = dip + (vlan_id<<8)
Flavio Castro5edf3132016-01-27 15:45:08 -0500583 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
584 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id, vrf=2)
Flavio Castro80730822015-12-11 15:38:47 -0500585 #add entries in the Bridging table to avoid packet-in from mac learning
586 group_id = encode_l2_interface_group_id(vlan_id, port)
587 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
588
589 do_barrier(self.controller)
590
591 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
592 for in_port in ports:
593 mac_src='00:00:00:22:22:%02X' % in_port
594 ip_src='192.168.%02d.1' % in_port
595 for out_port in ports:
596 if in_port == out_port:
597 continue
598 ip_dst='192.168.%02d.1' % out_port
599 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
600 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
601 ip_dst=ip_dst)
602 pkt=str(parsed_pkt)
603 self.dataplane.send(in_port, pkt)
604 #build expect packet
605 mac_dst='00:00:00:22:22:%02X' % out_port
606 label = (out_port, 0, 1, 32)
607 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=63, ip_src=ip_src,
608 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
609 pkt=str(exp_pkt)
610 verify_packet(self, pkt, out_port)
611 verify_no_other_packets(self)
castroflavioee294842016-01-06 15:54:28 -0800612
Flavio Castro80730822015-12-11 15:38:47 -0500613
Flavio Castro67d8bd52016-02-03 14:22:14 -0500614class _32VPN(base_tests.SimpleDataPlane):
Flavio Castro80730822015-12-11 15:38:47 -0500615 """
616 Insert IP packet
617 Receive MPLS packet
618 """
619 def runTest(self):
620 delete_all_flows(self.controller)
621 delete_all_groups(self.controller)
622
623 if len(config["port_map"]) <2:
624 logging.info("Port count less than 2, can't run this case")
625 return
626
627 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
628 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
629 dip=0xc0a80001
Flavio Castro67d8bd52016-02-03 14:22:14 -0500630 #Hashes Test Name and uses it as id for installing unique groups
631 id=abs(hash(inspect.stack()[0][3])) % (256)
Flavio Castro80730822015-12-11 15:38:47 -0500632 ports = config["port_map"].keys()
633 for port in ports:
634 #add l2 interface group
635 vlan_id=port
636 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
637 dst_mac[5]=vlan_id
638 #add MPLS interface group
Flavio Castro67d8bd52016-02-03 14:22:14 -0500639 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, id)
Flavio Castro80730822015-12-11 15:38:47 -0500640 #add MPLS L3 VPN group
641 mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
Flavio Castro67d8bd52016-02-03 14:22:14 -0500642 index=id, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32)
Flavio Castro80730822015-12-11 15:38:47 -0500643 #ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
644 do_barrier(self.controller)
645 #add vlan flow table
Flavio Castro67d8bd52016-02-03 14:22:14 -0500646 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castro80730822015-12-11 15:38:47 -0500647 #add termination flow
648 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
649 #add routing flow
650 dst_ip = dip + (vlan_id<<8)
Flavio Castro67d8bd52016-02-03 14:22:14 -0500651 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffffff, mpls_label_gid)
Flavio Castro72a45d52015-12-02 16:37:05 -0500652
653 do_barrier(self.controller)
654
655 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
656 for in_port in ports:
Flavio Castro72a45d52015-12-02 16:37:05 -0500657 ip_src='192.168.%02d.1' % in_port
658 for out_port in ports:
659 if in_port == out_port:
660 continue
661 ip_dst='192.168.%02d.1' % out_port
662 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
Flavio Castro67d8bd52016-02-03 14:22:14 -0500663 eth_dst=switch_mac, ip_ttl=64, ip_src=ip_src,
Flavio Castro72a45d52015-12-02 16:37:05 -0500664 ip_dst=ip_dst)
665 pkt=str(parsed_pkt)
666 self.dataplane.send(in_port, pkt)
667 #build expect packet
668 mac_dst='00:00:00:22:22:%02X' % out_port
669 label = (out_port, 0, 1, 32)
Flavio Castro34352e72015-12-07 20:01:51 -0500670 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=63, ip_src=ip_src,
Flavio Castro72a45d52015-12-02 16:37:05 -0500671 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
672 pkt=str(exp_pkt)
673 verify_packet(self, pkt, out_port)
674 verify_no_other_packets(self)
Flavio Castro67d8bd52016-02-03 14:22:14 -0500675@disabled
676class UniqueMplsTermination(base_tests.SimpleDataPlane):
Flavio Castro34352e72015-12-07 20:01:51 -0500677 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500678 Insert IP packet
679 Receive MPLS packet
Flavio Castro34352e72015-12-07 20:01:51 -0500680 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500681 def runTest(self):
682 delete_all_flows(self.controller)
683 delete_all_groups(self.controller)
684
685 if len(config["port_map"]) <2:
686 logging.info("Port count less than 2, can't run this case")
687 return
688
689 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
690 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500691 mcast_mac = [0x01, 0x00, 0x5e, 0x00, 0x00, 0x01]
692
Flavio Castrod8f8af22015-12-02 18:19:26 -0500693 dip=0xc0a80001
694 index=1
695 ports = config["port_map"].keys()
696 for port in ports:
697 #add l2 interface group
698 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500699 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, False)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500700 dst_mac[5]=vlan_id
701 #add L3 Unicast group
Flavio Castro932014b2016-01-05 18:29:15 -0500702 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500703 #add L3 ecmp group
704 ecmp_msg = add_l3_ecmp_group(self.controller, port, [l3_msg.group_id])
Flavio Castrod8f8af22015-12-02 18:19:26 -0500705 #add vlan flow table
Flavio Castro80730822015-12-11 15:38:47 -0500706 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500707 #add termination flow
Flavio Castro167f5bd2015-12-02 19:33:53 -0500708 add_termination_flow(self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500709 #add routing flow
710 dst_ip = dip + (vlan_id<<8)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500711 add_mpls_flow(self.controller, ecmp_msg.group_id, port)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500712 #add entries in the Bridging table to avoid packet-in from mac learning
713 group_id = encode_l2_interface_group_id(vlan_id, port)
714 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
715
716 do_barrier(self.controller)
717
718 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
719 for in_port in ports:
720 mac_src='00:00:00:22:22:%02X' % in_port
721 ip_src='192.168.%02d.1' % in_port
722 for out_port in ports:
723 if in_port == out_port:
724 continue
725 ip_dst='192.168.%02d.1' % out_port
Flavio Castro167f5bd2015-12-02 19:33:53 -0500726
727 label = (out_port, 0, 1, 32)
728 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src,
729 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[label])
Flavio Castrod8f8af22015-12-02 18:19:26 -0500730 pkt=str(parsed_pkt)
731 self.dataplane.send(in_port, pkt)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500732
Flavio Castrod8f8af22015-12-02 18:19:26 -0500733 #build expect packet
734 mac_dst='00:00:00:22:22:%02X' % out_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500735 mcast='01:00:5e:00:00:01'
Flavio Castro167f5bd2015-12-02 19:33:53 -0500736 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
Flavio Castro932014b2016-01-05 18:29:15 -0500737 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500738 pkt=str(exp_pkt)
739 verify_packet(self, pkt, out_port)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500740 verify_no_other_packets(self)
741
Flavio Castro80730822015-12-11 15:38:47 -0500742class MPLSBUG(base_tests.SimpleDataPlane):
743
744 def runTest(self):
745 delete_all_flows(self.controller)
746 delete_all_groups(self.controller)
747
748 if len(config["port_map"]) <2:
749 logging.info("Port count less than 2, can't run this case")
750 return
751
752 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
753 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
754 dip=0xc0a80001
755 index=1
756 ports = config["port_map"].keys()
757 for port in ports:
758 #add l2 interface group
759 vlan_id=port
760 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, False)
761 dst_mac[5]=vlan_id
762 #add L3 Unicast group
763 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
764 #add vlan flow table
765 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
766 #add termination flow
767 add_termination_flow(self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24)
768 #add mpls flow
769 add_mpls_flow(self.controller, l3_msg.group_id, port)
770 #add termination flow
771 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
772 #add unicast routing flow
773 dst_ip = dip + (vlan_id<<8)
Flavio Castroaf2b4502016-02-02 17:41:32 -0500774 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id)
Flavio Castro80730822015-12-11 15:38:47 -0500775
776 #add entries in the Bridging table to avoid packet-in from mac learning
777 group_id = encode_l2_interface_group_id(vlan_id, port)
778 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
779
780 do_barrier(self.controller)
781
782 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
783 for in_port in ports:
784 mac_src='00:00:00:22:22:%02X' % in_port
785 ip_src='192.168.%02d.1' % in_port
786 for out_port in ports:
787 if in_port == out_port:
788 continue
789 ip_dst='192.168.%02d.1' % out_port
790 switch_mac = "00:00:00:cc:cc:cc"
791 label = (out_port, 0, 1, 32)
792 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src,
793 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[label])
794 pkt=str(parsed_pkt)
795 self.dataplane.send(in_port, pkt)
796
797 #build expect packet
798 mac_dst='00:00:00:22:22:%02X' % out_port
799 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
800 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst)
801 pkt=str(exp_pkt)
802 verify_packet(self, pkt, out_port)
803 verify_no_other_packets(self)
804
805 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
806 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
807 ip_dst=ip_dst)
808 pkt=str(parsed_pkt)
809 self.dataplane.send(in_port, pkt)
810 #build expected packet
811 mac_dst='00:00:00:22:22:%02X' % out_port
812 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
813 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
814 ip_src=ip_src, ip_dst=ip_dst)
815 pkt=str(exp_pkt)
816 verify_packet(self, pkt, out_port)
817 verify_no_other_packets(self)
818
Flavio Castro12296312015-12-15 17:48:26 -0500819class L3McastToL2(base_tests.SimpleDataPlane):
castroflaviocc403a92015-12-15 14:04:19 -0500820 """
Flavio Castro12296312015-12-15 17:48:26 -0500821 Mcast routing to L2
castroflaviocc403a92015-12-15 14:04:19 -0500822 """
823 def runTest(self):
824 """
825 port1 (vlan 300)-> All Ports (vlan 300)
826 """
Flavio Castro932014b2016-01-05 18:29:15 -0500827 #delete_all_flows(self.controller)
828 #delete_all_groups(self.controller)
castroflaviocc403a92015-12-15 14:04:19 -0500829
castroflavio4a09c962016-01-05 13:13:41 -0800830 if len(config["port_map"]) <3:
831 logging.info("Port count less than 3, can't run this case")
832 assert(False)
castroflaviocc403a92015-12-15 14:04:19 -0500833 return
834
835 vlan_id =300
836 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
837 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
838 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
839 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
840 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
841 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
842 src_ip=0xc0a80101
843 src_ip_str="192.168.1.1"
844 dst_ip=0xe0010101
845 dst_ip_str="224.1.1.1"
846
847 port1=config["port_map"].keys()[0]
848 port2=config["port_map"].keys()[1]
849
850 switch_mac = [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00]
851
852
853 #add l2 interface group
854 l2_intf_group_list=[]
855 for port in config["port_map"].keys():
Flavio Castro932014b2016-01-05 18:29:15 -0500856 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=4)
castroflaviocc403a92015-12-15 14:04:19 -0500857 if port == port2:
858 continue
Flavio Castro12296312015-12-15 17:48:26 -0500859 l2_intf_gid, msg=add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
castroflaviocc403a92015-12-15 14:04:19 -0500860 l2_intf_group_list.append(l2_intf_gid)
castroflaviocc403a92015-12-15 14:04:19 -0500861
862 #add termination flow
863 add_termination_flow(self.controller, port1, 0x0800, switch_mac, vlan_id)
864
865 #add l3 interface group
866 mcat_group_msg=add_l3_mcast_group(self.controller, vlan_id, 2, l2_intf_group_list)
867 add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip, mcat_group_msg.group_id)
868
Flavio Castro932014b2016-01-05 18:29:15 -0500869 parsed_pkt = simple_udp_packet(pktlen=100,
870 dl_vlan_enable=True,
castroflaviocc403a92015-12-15 14:04:19 -0500871 eth_dst=dst_mac_str,
872 eth_src=port1_mac_str,
873 ip_ttl=64,
874 ip_src=src_ip_str,
875 ip_dst=dst_ip_str)
876 pkt=str(parsed_pkt)
877 self.dataplane.send(port1, pkt)
878 for port in config["port_map"].keys():
Flavio Castro12296312015-12-15 17:48:26 -0500879 if port == port2 or port == port1:
castroflaviocc403a92015-12-15 14:04:19 -0500880 verify_no_packet(self, pkt, port)
Flavio Castro12296312015-12-15 17:48:26 -0500881 continue
castroflaviocc403a92015-12-15 14:04:19 -0500882 verify_packet(self, pkt, port)
883 verify_no_other_packets(self)
884
Flavio Castro12296312015-12-15 17:48:26 -0500885class L3McastToL3(base_tests.SimpleDataPlane):
886 """
887 Mcast routing
888 """
889 def runTest(self):
890 """
891 port1 (vlan 1)-> port 2 (vlan 2)
892 """
893 delete_all_flows(self.controller)
894 delete_all_groups(self.controller)
895
896 if len(config["port_map"]) <3:
castroflavio4a09c962016-01-05 13:13:41 -0800897 logging.info("Port count less than 3, can't run this case")
898 assert(False)
Flavio Castro12296312015-12-15 17:48:26 -0500899 return
900
901 vlan_id =1
902 port2_out_vlan=2
903 port3_out_vlan=3
904 in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan
905 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
906 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
907 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
908 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
909 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
910 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
911 src_ip=0xc0a80101
912 src_ip_str="192.168.1.1"
913 dst_ip=0xe0010101
914 dst_ip_str="224.1.1.1"
915
916 port1=config["port_map"].keys()[0]
917 port2=config["port_map"].keys()[1]
918 port3=config["port_map"].keys()[2]
919
920 #add l2 interface group
921 for port in config["port_map"].keys():
922 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
923 #add vlan flow table
924 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
925 vlan_id +=1
926
927 #add termination flow
928 add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
929
930 #add l3 interface group
931 port2_ucast_msg=add_l3_interface_group(self.controller, port2, port2_out_vlan, 2, intf_src_mac)
932 port3_ucast_msg=add_l3_interface_group(self.controller, port3, port3_out_vlan, 3, intf_src_mac)
933 mcat_group_msg=add_l3_mcast_group(self.controller, in_vlan, 2, [port2_ucast_msg.group_id, port3_ucast_msg.group_id])
934 add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id)
935
936 parsed_pkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=1,
937 eth_dst=dst_mac_str,
938 eth_src=port1_mac_str,
939 ip_ttl=64,
940 ip_src=src_ip_str,
941 ip_dst=dst_ip_str)
942 pkt=str(parsed_pkt)
943 self.dataplane.send(port1, pkt)
944 parsed_pkt = simple_udp_packet(pktlen=96,
945 eth_dst=dst_mac_str,
946 eth_src=intf_src_mac_str,
947 ip_ttl=63,
948 ip_src=src_ip_str,
949 ip_dst=dst_ip_str)
950 pkt=str(parsed_pkt)
951 verify_packet(self, pkt, port2)
952 verify_packet(self, pkt, port3)
953 verify_no_other_packets(self)
954
955class L3McastToVPN(base_tests.SimpleDataPlane):
956 """
957 Mcast routing
958 """
959 def runTest(self):
960 """
961 port1 (vlan 1)-> port 2 (vlan 2)
962 """
963 #delete_all_flows(self.controller)
964 #delete_all_groups(self.controller)
965
966 if len(config["port_map"]) <3:
castroflavio4a09c962016-01-05 13:13:41 -0800967 logging.info("Port count less than 3, can't run this case")
968 assert(False)
Flavio Castro12296312015-12-15 17:48:26 -0500969 return
970
971 vlan_id =1
972 port2_out_vlan=2
973 port3_out_vlan=3
974 in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan
975 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
976 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
977 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
978 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
979 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
980 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
981 src_ip=0xc0a80101
982 src_ip_str="192.168.1.1"
983 dst_ip=0xe0010101
984 dst_ip_str="224.1.1.1"
985
986 port1=config["port_map"].keys()[0]
987 port2=config["port_map"].keys()[1]
988 port3=config["port_map"].keys()[2]
989
990 #add l2 interface group
991 for port in config["port_map"].keys():
992 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
993 #add vlan flow table
994 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
995 vlan_id +=1
996
997 #add termination flow
998 add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
999
1000 #add MPLS interface group
1001 l2_gid = encode_l2_interface_group_id(port2_out_vlan, port2)
1002 mpls_gid2, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, port2_out_vlan, port2)
1003 l2_gid3 = encode_l2_interface_group_id(port3_out_vlan, port3)
1004 mpls_gid3, mpls_msg = add_mpls_intf_group(self.controller, l2_gid3, dst_mac, intf_src_mac, port3_out_vlan, port3)
1005 #add L3VPN groups
1006 mpls_label_gid2, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
1007 index=(0x20000+port2), ref_gid= mpls_gid2, push_mpls_header=True, set_mpls_label=port2, set_bos=1, cpy_ttl_outward=True)
1008 mpls_label_gid3, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
1009 index=(0x10000+port3), ref_gid= mpls_gid3, push_mpls_header=True, set_mpls_label=port3, set_bos=1, cpy_ttl_outward=True)
1010
Flavio Castro12296312015-12-15 17:48:26 -05001011 mcat_group_msg=add_l3_mcast_group(self.controller, in_vlan, 2, [0x92020022 , 0x92010023])
1012 add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id)
1013
1014 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=1,
1015 eth_dst=dst_mac_str,
1016 eth_src=port1_mac_str,
1017 ip_ttl=64,
1018 ip_src=src_ip_str,
1019 ip_dst=dst_ip_str)
1020 pkt=str(parsed_pkt)
1021 self.dataplane.send(port1, pkt)
1022 label = (in_vlan, 0, 1, 63)
1023 parsed_pkt = mpls_packet(pktlen=100,
1024 eth_dst=dst_mac_str,
1025 eth_src=intf_src_mac_str,
1026 ip_ttl=63,
1027 ip_src=src_ip_str, label= [label],
1028 ip_dst=dst_ip_str)
1029 pkt=str(parsed_pkt)
1030 verify_packet(self, pkt, port2)
1031 verify_packet(self, pkt, port3)
1032 verify_no_other_packets(self)
Flavio Castro67d8bd52016-02-03 14:22:14 -05001033@disabled
castroflavio30c6cc52016-01-07 15:19:42 -08001034class LPM(base_tests.SimpleDataPlane):
1035 """
1036 Insert IP packet
1037 Receive MPLS packet
1038 """
1039 def runTest(self):
1040 delete_all_flows(self.controller)
1041 delete_all_groups(self.controller)
1042
1043 if len(config["port_map"]) <2:
1044 logging.info("Port count less than 2, can't run this case")
1045 return
1046
1047 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1048 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1049 dip=0xc0a80001
1050 index=1
1051 ports = config["port_map"].keys()
1052 for port in ports:
1053 #add l2 interface group
1054 vlan_id=port
1055 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
1056 dst_mac[5]=vlan_id
1057 #add MPLS interface group
1058 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, port)
1059 #add MPLS L3 VPN group
1060 mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
1061 index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32)
Flavio Castro5edf3132016-01-27 15:45:08 -05001062 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
castroflavio30c6cc52016-01-07 15:19:42 -08001063 do_barrier(self.controller)
1064 #add vlan flow table
Flavio Castroaf2b4502016-02-02 17:41:32 -05001065 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG)
castroflavio30c6cc52016-01-07 15:19:42 -08001066 #add termination flow
1067 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
1068 #add routing flow
1069 dst_ip = dip + (vlan_id<<8)
Flavio Castro5edf3132016-01-27 15:45:08 -05001070 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, mpls_label_gid, vrf=2)
Flavio Castroaf2b4502016-02-02 17:41:32 -05001071 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id)
castroflavio30c6cc52016-01-07 15:19:42 -08001072 #add entries in the Bridging table to avoid packet-in from mac learning
1073 group_id = encode_l2_interface_group_id(vlan_id, port)
1074 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
1075 port = ports[0]
1076 #add l2 interface group
1077 vlan_id=port
1078 l2_gid = encode_l2_interface_group_id(vlan_id, port)
1079 dst_mac[5]=vlan_id
1080 #add MPLS interface group
1081 mpls_gid = encode_mpls_interface_group_id(0, port)
1082 #add MPLS L3 VPN group
1083 mpls_label_gid = encode_mpls_label_group_id(OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=port)
Flavio Castro5edf3132016-01-27 15:45:08 -05001084 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
castroflavio30c6cc52016-01-07 15:19:42 -08001085 do_barrier(self.controller)
1086 #add routing flow
1087 dst_ip = 0x0
Flavio Castro5edf3132016-01-27 15:45:08 -05001088 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, mpls_label_gid, vrf=2)
Flavio Castroaf2b4502016-02-02 17:41:32 -05001089 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, ecmp_msg.group_id)
castroflavio30c6cc52016-01-07 15:19:42 -08001090
1091 do_barrier(self.controller)
1092
1093 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1094 for in_port in ports:
1095 mac_src='00:00:00:22:22:%02X' % in_port
1096 ip_src='192.168.%02d.1' % in_port
1097 for out_port in ports:
1098 if in_port == out_port:
1099 continue
1100 ip_dst='192.168.%02d.1' % out_port
1101 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
1102 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
1103 ip_dst=ip_dst)
1104 pkt=str(parsed_pkt)
1105 self.dataplane.send(in_port, pkt)
1106 #build expect packet
1107 mac_dst='00:00:00:22:22:%02X' % out_port
1108 label = (out_port, 0, 1, 32)
1109 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=63, ip_src=ip_src,
1110 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
1111 pkt=str(exp_pkt)
1112 verify_packet(self, pkt, out_port)
1113 verify_no_other_packets(self)
Flavio Castroaf2b4502016-02-02 17:41:32 -05001114 ip_dst='1.168.%02d.1' % ports[0]
castroflavio30c6cc52016-01-07 15:19:42 -08001115 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
1116 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst)
1117 pkt=str(parsed_pkt)
1118 self.dataplane.send(in_port, pkt)
1119 #build expect packet
Flavio Castroaf2b4502016-02-02 17:41:32 -05001120 mac_dst='00:00:00:22:22:%02X' % ports[0]
1121 label = (ports[0], 0, 1, 32)
1122 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=ports[0], ip_ttl=63, ip_src=ip_src,
castroflavio30c6cc52016-01-07 15:19:42 -08001123 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
1124 pkt=str(exp_pkt)
Flavio Castroaf2b4502016-02-02 17:41:32 -05001125 verify_packet(self, pkt, ports[0])
castroflavio30c6cc52016-01-07 15:19:42 -08001126 verify_no_other_packets(self)