blob: 38e5684fb5442a18a17c33ce7960a24af0080287 [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 Castro167f5bd2015-12-02 19:33:53 -050018import logging
19import oftest.base_tests as base_tests
Flavio Castro05d20bc2015-11-16 15:06:14 -050020import ofp
21from oftest.testutils import *
22from accton_util import *
Flavio Castrod8f8af22015-12-02 18:19:26 -050023
Flavio Castroaabb5792015-11-18 19:03:50 -050024class PacketInSrcMacMiss(base_tests.SimpleDataPlane):
25 """
26 Test packet in function on a src-mac miss
27 Send a packet to each dataplane port and verify that a packet
28 in message is received from the controller for each
29 #todo verify you stop receiving after adding rule
30 """
31
Flavio Castro6efe1862015-11-18 16:28:06 -050032 def runTest(self):
33 delete_all_flows(self.controller)
34 delete_all_groups(self.controller)
35
Flavio Castro34352e72015-12-07 20:01:51 -050036 ports = sorted(config["port_map"].keys())
37 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -050038 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -050039 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
40
Flavio Castroaabb5792015-11-18 19:03:50 -050041 parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
42 vlan_vid=0x1001, dl_vlan_enable=True)
43 vlan_pkt = str(parsed_vlan_pkt)
Flavio Castro6efe1862015-11-18 16:28:06 -050044
Flavio Castroaabb5792015-11-18 19:03:50 -050045 for of_port in config["port_map"].keys():
46 logging.info("PacketInMiss test, port %d", of_port)
47 self.dataplane.send(of_port, vlan_pkt)
48
49 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH)
50
51 verify_no_other_packets(self)
52
Flavio Castro7fb6ca92015-12-16 15:50:14 -050053class PacketInUDP(base_tests.SimpleDataPlane):
Flavio Castro6d498522015-12-15 14:05:04 -050054 """
55 Test packet in function for a table-miss flow
56 Send a packet to each dataplane port and verify that a packet
57 in message is received from the controller for each
58
59 NOTE: Verify This case the oft option shall not use --switch-ip
60 """
61
62 def runTest(self):
63 delete_all_flows(self.controller)
64 delete_all_groups(self.controller)
65
66 parsed_vlan_pkt = simple_udp_packet(pktlen=104,
67 vlan_vid=0x1001, dl_vlan_enable=True)
68 vlan_pkt = str(parsed_vlan_pkt)
Flavio Castro6d498522015-12-15 14:05:04 -050069 # create match
70 match = ofp.match()
71 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
castroflavio4a09c962016-01-05 13:13:41 -080072 match.oxm_list.append(ofp.oxm.ip_proto(17))
Flavio Castro6d498522015-12-15 14:05:04 -050073 request = ofp.message.flow_add(
74 table_id=60,
75 cookie=42,
76 match=match,
77 instructions=[
78 ofp.instruction.apply_actions(
79 actions=[
80 ofp.action.output(
81 port=ofp.OFPP_CONTROLLER,
82 max_len=ofp.OFPCML_NO_BUFFER)]),
83 ],
84 buffer_id=ofp.OFP_NO_BUFFER,
85 priority=1)
86
87 logging.info("Inserting packet in flow to controller")
88 self.controller.message_send(request)
89 do_barrier(self.controller)
90
91 for of_port in config["port_map"].keys():
92 logging.info("PacketInMiss test, port %d", of_port)
93 self.dataplane.send(of_port, vlan_pkt)
94
95 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
96
97 verify_no_other_packets(self)
98
Flavio Castro7fb6ca92015-12-16 15:50:14 -050099class ArpNL2(base_tests.SimpleDataPlane):
100 def runTest(self):
101 delete_all_flows(self.controller)
102 delete_all_groups(self.controller)
103
104 ports = sorted(config["port_map"].keys())
105 match = ofp.match()
106 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
107 request = ofp.message.flow_add(
108 table_id=60,
109 cookie=42,
110 match=match,
111 instructions=[
112 ofp.instruction.apply_actions(
113 actions=[
114 ofp.action.output(
115 port=ofp.OFPP_CONTROLLER,
116 max_len=ofp.OFPCML_NO_BUFFER)]),
117 ],
118 buffer_id=ofp.OFP_NO_BUFFER,
119 priority=40000)
120 self.controller.message_send(request)
121 for port in ports:
Flavio Castro932014b2016-01-05 18:29:15 -0500122 add_one_l2_interface_group(self.controller, port, 1, False, False)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500123 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
124 group_id = encode_l2_interface_group_id(1, port)
125 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
126 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
134 mac_dst= '00:12:34:56:78:%02X' % out_port
135 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
139 mac_src= '00:12:34:56:78:%02X' % in_port
140 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 Castro7fb6ca92015-12-16 15:50:14 -0500152class PacketInArp(base_tests.SimpleDataPlane):
153 """
154 Test packet in function for a table-miss flow
155 Send a packet to each dataplane port and verify that a packet
156 in message is received from the controller for each
157
158 NOTE: Verify This case the oft option shall not use --switch-ip
159 """
160
161 def runTest(self):
162 delete_all_flows(self.controller)
163 delete_all_groups(self.controller)
164
165 parsed_arp_pkt = simple_arp_packet()
166 arp_pkt = str(parsed_arp_pkt)
167 ports = sorted(config["port_map"].keys())
168 #for port in ports:
169 # add_one_l2_interface_group(self.controller, port, 1, True, False)
170 # add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
171
172 # create match
173 match = ofp.match()
174 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
175 request = ofp.message.flow_add(
176 table_id=60,
177 cookie=42,
178 match=match,
179 instructions=[
180 ofp.instruction.apply_actions(
181 actions=[
182 ofp.action.output(
183 port=ofp.OFPP_CONTROLLER,
184 max_len=ofp.OFPCML_NO_BUFFER)]),
185 ],
186 buffer_id=ofp.OFP_NO_BUFFER,
187 priority=1)
188
189 logging.info("Inserting packet in flow to controller")
190 self.controller.message_send(request)
191 do_barrier(self.controller)
192
193 for of_port in config["port_map"].keys():
194 logging.info("PacketInMiss test, port %d", of_port)
195 self.dataplane.send(of_port, arp_pkt)
196
197 verify_packet_in(self, arp_pkt, of_port, ofp.OFPR_ACTION)
198
199 verify_no_other_packets(self)
200
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500201class L2FloodQinQ(base_tests.SimpleDataPlane):
202 """
Flavio Castroc36621e2015-12-08 12:57:07 -0500203 Test L2 flood of double tagged vlan packets (802.1Q)
204 Sends a double tagged packet and verifies flooding behavior according to outer vlan
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500205 """
206 def runTest(self):
207 ports = sorted(config["port_map"].keys())
208
209 delete_all_flows(self.controller)
210 delete_all_groups(self.controller)
211
212 # Installing flows to avoid packet-in
213 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500214 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500215 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
216
217 group_id = encode_l2_interface_group_id(1, port)
218 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
219 msg=add_l2_flood_group(self.controller, ports, 1, 1)
220 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
221 do_barrier(self.controller)
222
223 #verify flood
224 for ofport in ports:
225 # change dest based on port number
226 mac_src= '00:12:34:56:78:%02X' % ofport
227 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108, out_dl_vlan_enable=True, out_vlan_vid=1,
228 in_dl_vlan_enable=True, in_vlan_vid=10, eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
229 pkt = str(parsed_pkt)
230 self.dataplane.send(ofport, pkt)
231 #self won't rx packet
232 verify_no_packet(self, pkt, ofport)
233 #others will rx packet
234 tmp_ports=list(ports)
235 tmp_ports.remove(ofport)
236 verify_packets(self, pkt, tmp_ports)
237
238 verify_no_other_packets(self)
239
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
244 #todo take in account unknown src
245 """
246 def runTest(self):
247 ports = sorted(config["port_map"].keys())
Flavio Castro34352e72015-12-07 20:01:51 -0500248
Flavio Castro184cefe2015-11-19 20:52:49 -0500249 delete_all_flows(self.controller)
250 delete_all_groups(self.controller)
251
Flavio Castro184cefe2015-11-19 20:52:49 -0500252 # Installing flows to avoid packet-in
253 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500254 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500255 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
256
Flavio Castro184cefe2015-11-19 20:52:49 -0500257 group_id = encode_l2_interface_group_id(1, port)
258 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
Flavio Castro34352e72015-12-07 20:01:51 -0500259 msg=add_l2_flood_group(self.controller, ports, 1, 1)
260 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
Flavio Castro184cefe2015-11-19 20:52:49 -0500261 do_barrier(self.controller)
262
263 #verify flood
264 for ofport in ports:
265 # change dest based on port number
266 mac_src= '00:12:34:56:78:%02X' % ofport
267 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
268 pkt = str(parsed_pkt)
269 self.dataplane.send(ofport, pkt)
270 #self won't rx packet
271 verify_no_packet(self, pkt, ofport)
272 #others will rx packet
273 tmp_ports=list(ports)
274 tmp_ports.remove(ofport)
275 verify_packets(self, pkt, tmp_ports)
276
277 verify_no_other_packets(self)
278
Flavio Castroaabb5792015-11-18 19:03:50 -0500279class L2FloodTaggedUnknownSrc(base_tests.SimpleDataPlane):
280 """
281 Test L2 flood to a vlan
282 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
283 #todo take in account unknown src
284 """
285 def runTest(self):
Flavio Castroaabb5792015-11-18 19:03:50 -0500286 delete_all_flows(self.controller)
287 delete_all_groups(self.controller)
288
Flavio Castro34352e72015-12-07 20:01:51 -0500289 ports = sorted(config["port_map"].keys())
290 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500291 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500292 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castroaabb5792015-11-18 19:03:50 -0500293
294 msg=add_l2_flood_group(self.controller, ports, 1, 1)
295 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
296
297 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a')
298 pkt = str(parsed_pkt)
299 #verify flood
300 for ofport in ports:
301 self.dataplane.send(ofport, pkt)
302 #self won't rx packet
303 verify_no_packet(self, pkt, ofport)
304 #others will rx packet
305 tmp_ports=list(ports)
306 tmp_ports.remove(ofport)
307 verify_packets(self, pkt, tmp_ports)
308
309 verify_no_other_packets(self)
310
Flavio Castroaabb5792015-11-18 19:03:50 -0500311class L2UnicastTagged(base_tests.SimpleDataPlane):
312 """
313 Test output function for an exact-match flow
314
315 For each port A, adds a flow directing matching packets to that port.
316 Then, for all other ports B != A, verifies that sending a matching packet
317 to B results in an output to A.
318 """
319 def runTest(self):
320 ports = sorted(config["port_map"].keys())
321
322 delete_all_flows(self.controller)
323 delete_all_groups(self.controller)
324
Flavio Castroaabb5792015-11-18 19:03:50 -0500325 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500326 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500327 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castroaabb5792015-11-18 19:03:50 -0500328 group_id = encode_l2_interface_group_id(1, port)
329 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
Flavio Castro6efe1862015-11-18 16:28:06 -0500330 do_barrier(self.controller)
331
Flavio Castroaabb5792015-11-18 19:03:50 -0500332 for out_port in ports:
333 # change dest based on port number
334 mac_dst= '00:12:34:56:78:%02X' % out_port
335 for in_port in ports:
336 if in_port == out_port:
337 continue
338 # change source based on port number to avoid packet-ins from learning
339 mac_src= '00:12:34:56:78:%02X' % in_port
340 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
341 pkt = str(parsed_pkt)
342 self.dataplane.send(in_port, pkt)
343
344 for ofport in ports:
345 if ofport in [out_port]:
346 verify_packet(self, pkt, ofport)
347 else:
348 verify_no_packet(self, pkt, ofport)
349
350 verify_no_other_packets(self)
Flavio Castro6efe1862015-11-18 16:28:06 -0500351
Flavio Castrob6773032015-11-19 22:49:24 -0500352class Mtu1500(base_tests.SimpleDataPlane):
353
354 def runTest(self):
355 ports = sorted(config["port_map"].keys())
356
357 delete_all_flows(self.controller)
358 delete_all_groups(self.controller)
359
Flavio Castro34352e72015-12-07 20:01:51 -0500360 # set up tag groups for each port
Flavio Castrod4c44d12015-12-08 14:44:18 -0500361 add_l2_interface_group(self.controller, ports, 1, True, 1)
Flavio Castrob6773032015-11-19 22:49:24 -0500362
Flavio Castro34352e72015-12-07 20:01:51 -0500363 add_vlan_table_flow(self.controller, ports)
Flavio Castrob6773032015-11-19 22:49:24 -0500364
365 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500366 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500367 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrob6773032015-11-19 22:49:24 -0500368 group_id = encode_l2_interface_group_id(1, port)
369 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
370 do_barrier(self.controller)
371
372 for out_port in ports:
373 # change dest based on port number
374 mac_dst= '00:12:34:56:78:%02X' % out_port
375 for in_port in ports:
376 if in_port == out_port:
377 continue
378 # change source based on port number to avoid packet-ins from learning
379 mac_src= '00:12:34:56:78:%02X' % in_port
380 parsed_pkt = simple_tcp_packet(pktlen=1500,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
381 pkt = str(parsed_pkt)
382 self.dataplane.send(in_port, pkt)
383
384 for ofport in ports:
385 if ofport in [out_port]:
386 verify_packet(self, pkt, ofport)
387 else:
388 verify_no_packet(self, pkt, ofport)
389
390 verify_no_other_packets(self)
391
392
393class Mtu4000(base_tests.SimpleDataPlane):
394 """
395 Test output function for an exact-match flow
396 For each port A, adds a flow directing matching packets to that port.
397 Then, for all other ports B != A, verifies that sending a matching packet
398 to B results in an output to A.
399 """
400 def runTest(self):
401 ports = sorted(config["port_map"].keys())
402
403 delete_all_flows(self.controller)
404 delete_all_groups(self.controller)
405
406 add_vlan_table_flow(self.controller, config["port_map"].keys())
407
408 # set up tag groups for each port
Flavio Castrod4c44d12015-12-08 14:44:18 -0500409 add_l2_interface_group(self.controller, config["port_map"].keys(), 1, True, 1)
Flavio Castrob6773032015-11-19 22:49:24 -0500410
411 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500412 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500413 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrob6773032015-11-19 22:49:24 -0500414 group_id = encode_l2_interface_group_id(1, port)
415 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
416 do_barrier(self.controller)
417
418 for out_port in ports:
419 # change dest based on port number
420 mac_dst= '00:12:34:56:78:%02X' % out_port
421 for in_port in ports:
422 if in_port == out_port:
423 continue
424 # change source based on port number to avoid packet-ins from learning
425 mac_src= '00:12:34:56:78:%02X' % in_port
426 parsed_pkt = simple_tcp_packet(pktlen=4000,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
427 pkt = str(parsed_pkt)
428 self.dataplane.send(in_port, pkt)
429
430 for ofport in ports:
431 if ofport in [out_port]:
432 verify_packet(self, pkt, ofport)
433 else:
434 verify_no_packet(self, pkt, ofport)
435
436 verify_no_other_packets(self)
Flavio Castroaabb5792015-11-18 19:03:50 -0500437
438class L3UcastTagged(base_tests.SimpleDataPlane):
Flavio Castro05d20bc2015-11-16 15:06:14 -0500439 """
Flavio Castro35e64392015-12-02 16:53:14 -0500440 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
441 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500442 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500443 def runTest(self):
Flavio Castro05d20bc2015-11-16 15:06:14 -0500444 delete_all_flows(self.controller)
445 delete_all_groups(self.controller)
446
447 if len(config["port_map"]) <2:
448 logging.info("Port count less than 2, can't run this case")
449 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500450
Flavio Castro05d20bc2015-11-16 15:06:14 -0500451 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
452 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
453 dip=0xc0a80001
Flavio Castroa8233862015-12-02 14:41:11 -0500454 ports = config["port_map"].keys()
455 for port in ports:
Flavio Castro05d20bc2015-11-16 15:06:14 -0500456 #add l2 interface group
Flavio Castroa8233862015-12-02 14:41:11 -0500457 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500458 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 -0500459 dst_mac[5]=vlan_id
460 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
461 #add vlan flow table
Flavio Castro34352e72015-12-07 20:01:51 -0500462 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500463 #add termination flow
Flavio Castrod8f8af22015-12-02 18:19:26 -0500464 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500465 #add unicast routing flow
Flavio Castrod8f8af22015-12-02 18:19:26 -0500466 dst_ip = dip + (vlan_id<<8)
Flavio Castro6efe1862015-11-18 16:28:06 -0500467 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
Flavio Castro6efe1862015-11-18 16:28:06 -0500468 #add entries in the Bridging table to avoid packet-in from mac learning
469 group_id = encode_l2_interface_group_id(vlan_id, port)
470 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500471
472 do_barrier(self.controller)
473
Flavio Castro05d20bc2015-11-16 15:06:14 -0500474 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
Flavio Castroa8233862015-12-02 14:41:11 -0500475 for in_port in ports:
476 mac_src='00:00:00:22:22:%02X' % in_port
477 ip_src='192.168.%02d.1' % in_port
478 for out_port in ports:
479 if in_port == out_port:
480 continue
481 ip_dst='192.168.%02d.1' % out_port
482 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
483 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
Flavio Castrod8f8af22015-12-02 18:19:26 -0500484 ip_dst=ip_dst)
Flavio Castroa8233862015-12-02 14:41:11 -0500485 pkt=str(parsed_pkt)
486 self.dataplane.send(in_port, pkt)
Flavio Castro72a45d52015-12-02 16:37:05 -0500487 #build expected packet
Flavio Castroa8233862015-12-02 14:41:11 -0500488 mac_dst='00:00:00:22:22:%02X' % out_port
Flavio Castrod8f8af22015-12-02 18:19:26 -0500489 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
Flavio Castroa8233862015-12-02 14:41:11 -0500490 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
491 ip_src=ip_src, ip_dst=ip_dst)
492 pkt=str(exp_pkt)
493 verify_packet(self, pkt, out_port)
494 verify_no_other_packets(self)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500495
Flavio Castrod8f8af22015-12-02 18:19:26 -0500496class L3VPNMPLS(base_tests.SimpleDataPlane):
497 """
498 Insert IP packet
499 Receive MPLS packet
500 """
Flavio Castro72a45d52015-12-02 16:37:05 -0500501 def runTest(self):
502 delete_all_flows(self.controller)
503 delete_all_groups(self.controller)
504
505 if len(config["port_map"]) <2:
506 logging.info("Port count less than 2, can't run this case")
507 return
508
509 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
510 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
511 dip=0xc0a80001
512 index=1
513 ports = config["port_map"].keys()
514 for port in ports:
515 #add l2 interface group
516 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500517 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
Flavio Castro72a45d52015-12-02 16:37:05 -0500518 dst_mac[5]=vlan_id
Flavio Castro35e64392015-12-02 16:53:14 -0500519 #add MPLS interface group
Flavio Castro72a45d52015-12-02 16:37:05 -0500520 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 -0500521 #add MPLS L3 VPN group
Flavio Castrod8f8af22015-12-02 18:19:26 -0500522 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 -0500523 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 -0500524 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castro80730822015-12-11 15:38:47 -0500525 do_barrier(self.controller)
Flavio Castro72a45d52015-12-02 16:37:05 -0500526 #add vlan flow table
Flavio Castro80730822015-12-11 15:38:47 -0500527 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 -0500528 #add termination flow
529 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
Flavio Castro35e64392015-12-02 16:53:14 -0500530 #add routing flow
Flavio Castro5edf3132016-01-27 15:45:08 -0500531 dst_ip = 0
532 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
533 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id, vrf=2)
Flavio Castro80730822015-12-11 15:38:47 -0500534 #add entries in the Bridging table to avoid packet-in from mac learning
535 group_id = encode_l2_interface_group_id(vlan_id, port)
536 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
537
538 do_barrier(self.controller)
539
540 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
541 for in_port in ports:
542 mac_src='00:00:00:22:22:%02X' % in_port
543 ip_src='192.168.%02d.1' % in_port
544 for out_port in ports:
545 if in_port == out_port:
546 continue
547 ip_dst='192.168.%02d.1' % out_port
548 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
549 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
550 ip_dst=ip_dst)
551 pkt=str(parsed_pkt)
552 self.dataplane.send(in_port, pkt)
553 #build expect packet
554 mac_dst='00:00:00:22:22:%02X' % out_port
555 label = (out_port, 0, 1, 32)
556 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=63, ip_src=ip_src,
557 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
558 pkt=str(exp_pkt)
559 verify_packet(self, pkt, out_port)
560 verify_no_other_packets(self)
castroflavioee294842016-01-06 15:54:28 -0800561
Flavio Castro80730822015-12-11 15:38:47 -0500562
563class L3VPN_32(base_tests.SimpleDataPlane):
564 """
565 Insert IP packet
566 Receive MPLS packet
567 """
568 def runTest(self):
569 delete_all_flows(self.controller)
570 delete_all_groups(self.controller)
571
572 if len(config["port_map"]) <2:
573 logging.info("Port count less than 2, can't run this case")
574 return
575
576 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
577 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
578 dip=0xc0a80001
579 index=1
580 ports = config["port_map"].keys()
581 for port in ports:
582 #add l2 interface group
583 vlan_id=port
584 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
585 dst_mac[5]=vlan_id
586 #add MPLS interface group
587 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, port)
588 #add MPLS L3 VPN group
589 mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
590 index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32)
591 #ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
592 do_barrier(self.controller)
593 #add vlan flow table
594 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=2, flag=VLAN_TABLE_FLAG_ONLY_TAG)
595 #add termination flow
596 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
597 #add routing flow
598 dst_ip = dip + (vlan_id<<8)
599 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_gid, vrf=2)
600 #ecmp_msg.group_id, vrf=2)
Flavio Castro72a45d52015-12-02 16:37:05 -0500601 #add entries in the Bridging table to avoid packet-in from mac learning
602 group_id = encode_l2_interface_group_id(vlan_id, port)
603 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
604
605 do_barrier(self.controller)
606
607 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
608 for in_port in ports:
609 mac_src='00:00:00:22:22:%02X' % in_port
610 ip_src='192.168.%02d.1' % in_port
611 for out_port in ports:
612 if in_port == out_port:
613 continue
614 ip_dst='192.168.%02d.1' % out_port
615 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
616 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
617 ip_dst=ip_dst)
618 pkt=str(parsed_pkt)
619 self.dataplane.send(in_port, pkt)
620 #build expect packet
621 mac_dst='00:00:00:22:22:%02X' % out_port
622 label = (out_port, 0, 1, 32)
Flavio Castro34352e72015-12-07 20:01:51 -0500623 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 -0500624 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
625 pkt=str(exp_pkt)
626 verify_packet(self, pkt, out_port)
627 verify_no_other_packets(self)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500628
629class MplsTermination(base_tests.SimpleDataPlane):
Flavio Castro34352e72015-12-07 20:01:51 -0500630 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500631 Insert IP packet
632 Receive MPLS packet
Flavio Castro34352e72015-12-07 20:01:51 -0500633 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500634 def runTest(self):
635 delete_all_flows(self.controller)
636 delete_all_groups(self.controller)
637
638 if len(config["port_map"]) <2:
639 logging.info("Port count less than 2, can't run this case")
640 return
641
642 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
643 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500644 mcast_mac = [0x01, 0x00, 0x5e, 0x00, 0x00, 0x01]
645
Flavio Castrod8f8af22015-12-02 18:19:26 -0500646 dip=0xc0a80001
647 index=1
648 ports = config["port_map"].keys()
649 for port in ports:
650 #add l2 interface group
651 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500652 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, False)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500653 dst_mac[5]=vlan_id
654 #add L3 Unicast group
Flavio Castro932014b2016-01-05 18:29:15 -0500655 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 -0500656 #add L3 ecmp group
657 ecmp_msg = add_l3_ecmp_group(self.controller, port, [l3_msg.group_id])
Flavio Castrod8f8af22015-12-02 18:19:26 -0500658 #add vlan flow table
Flavio Castro80730822015-12-11 15:38:47 -0500659 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500660 #add termination flow
Flavio Castro167f5bd2015-12-02 19:33:53 -0500661 add_termination_flow(self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500662 #add routing flow
663 dst_ip = dip + (vlan_id<<8)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500664 add_mpls_flow(self.controller, ecmp_msg.group_id, port)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500665 #add entries in the Bridging table to avoid packet-in from mac learning
666 group_id = encode_l2_interface_group_id(vlan_id, port)
667 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
668
669 do_barrier(self.controller)
670
671 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
672 for in_port in ports:
673 mac_src='00:00:00:22:22:%02X' % in_port
674 ip_src='192.168.%02d.1' % in_port
675 for out_port in ports:
676 if in_port == out_port:
677 continue
678 ip_dst='192.168.%02d.1' % out_port
Flavio Castro167f5bd2015-12-02 19:33:53 -0500679
680 label = (out_port, 0, 1, 32)
681 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src,
682 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[label])
Flavio Castrod8f8af22015-12-02 18:19:26 -0500683 pkt=str(parsed_pkt)
684 self.dataplane.send(in_port, pkt)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500685
Flavio Castrod8f8af22015-12-02 18:19:26 -0500686 #build expect packet
687 mac_dst='00:00:00:22:22:%02X' % out_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500688 mcast='01:00:5e:00:00:01'
Flavio Castro167f5bd2015-12-02 19:33:53 -0500689 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
Flavio Castro932014b2016-01-05 18:29:15 -0500690 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 -0500691 pkt=str(exp_pkt)
692 verify_packet(self, pkt, out_port)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500693 verify_no_other_packets(self)
694
Flavio Castro80730822015-12-11 15:38:47 -0500695class MPLSBUG(base_tests.SimpleDataPlane):
696
697 def runTest(self):
698 delete_all_flows(self.controller)
699 delete_all_groups(self.controller)
700
701 if len(config["port_map"]) <2:
702 logging.info("Port count less than 2, can't run this case")
703 return
704
705 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
706 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
707 dip=0xc0a80001
708 index=1
709 ports = config["port_map"].keys()
710 for port in ports:
711 #add l2 interface group
712 vlan_id=port
713 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, False)
714 dst_mac[5]=vlan_id
715 #add L3 Unicast group
716 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
717 #add vlan flow table
718 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
719 #add termination flow
720 add_termination_flow(self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24)
721 #add mpls flow
722 add_mpls_flow(self.controller, l3_msg.group_id, port)
723 #add termination flow
724 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
725 #add unicast routing flow
726 dst_ip = dip + (vlan_id<<8)
727 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
728
729 #add entries in the Bridging table to avoid packet-in from mac learning
730 group_id = encode_l2_interface_group_id(vlan_id, port)
731 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
732
733 do_barrier(self.controller)
734
735 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
736 for in_port in ports:
737 mac_src='00:00:00:22:22:%02X' % in_port
738 ip_src='192.168.%02d.1' % in_port
739 for out_port in ports:
740 if in_port == out_port:
741 continue
742 ip_dst='192.168.%02d.1' % out_port
743 switch_mac = "00:00:00:cc:cc:cc"
744 label = (out_port, 0, 1, 32)
745 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src,
746 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[label])
747 pkt=str(parsed_pkt)
748 self.dataplane.send(in_port, pkt)
749
750 #build expect packet
751 mac_dst='00:00:00:22:22:%02X' % out_port
752 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
753 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst)
754 pkt=str(exp_pkt)
755 verify_packet(self, pkt, out_port)
756 verify_no_other_packets(self)
757
758 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
759 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
760 ip_dst=ip_dst)
761 pkt=str(parsed_pkt)
762 self.dataplane.send(in_port, pkt)
763 #build expected packet
764 mac_dst='00:00:00:22:22:%02X' % out_port
765 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
766 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
767 ip_src=ip_src, ip_dst=ip_dst)
768 pkt=str(exp_pkt)
769 verify_packet(self, pkt, out_port)
770 verify_no_other_packets(self)
771
Flavio Castro12296312015-12-15 17:48:26 -0500772class L3McastToL2(base_tests.SimpleDataPlane):
castroflaviocc403a92015-12-15 14:04:19 -0500773 """
Flavio Castro12296312015-12-15 17:48:26 -0500774 Mcast routing to L2
castroflaviocc403a92015-12-15 14:04:19 -0500775 """
776 def runTest(self):
777 """
778 port1 (vlan 300)-> All Ports (vlan 300)
779 """
Flavio Castro932014b2016-01-05 18:29:15 -0500780 #delete_all_flows(self.controller)
781 #delete_all_groups(self.controller)
castroflaviocc403a92015-12-15 14:04:19 -0500782
castroflavio4a09c962016-01-05 13:13:41 -0800783 if len(config["port_map"]) <3:
784 logging.info("Port count less than 3, can't run this case")
785 assert(False)
castroflaviocc403a92015-12-15 14:04:19 -0500786 return
787
788 vlan_id =300
789 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
790 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
791 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
792 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
793 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
794 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
795 src_ip=0xc0a80101
796 src_ip_str="192.168.1.1"
797 dst_ip=0xe0010101
798 dst_ip_str="224.1.1.1"
799
800 port1=config["port_map"].keys()[0]
801 port2=config["port_map"].keys()[1]
802
803 switch_mac = [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00]
804
805
806 #add l2 interface group
807 l2_intf_group_list=[]
808 for port in config["port_map"].keys():
Flavio Castro932014b2016-01-05 18:29:15 -0500809 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=4)
castroflaviocc403a92015-12-15 14:04:19 -0500810 if port == port2:
811 continue
Flavio Castro12296312015-12-15 17:48:26 -0500812 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 -0500813 l2_intf_group_list.append(l2_intf_gid)
castroflaviocc403a92015-12-15 14:04:19 -0500814
815 #add termination flow
816 add_termination_flow(self.controller, port1, 0x0800, switch_mac, vlan_id)
817
818 #add l3 interface group
819 mcat_group_msg=add_l3_mcast_group(self.controller, vlan_id, 2, l2_intf_group_list)
820 add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip, mcat_group_msg.group_id)
821
Flavio Castro932014b2016-01-05 18:29:15 -0500822 parsed_pkt = simple_udp_packet(pktlen=100,
823 dl_vlan_enable=True,
castroflaviocc403a92015-12-15 14:04:19 -0500824 eth_dst=dst_mac_str,
825 eth_src=port1_mac_str,
826 ip_ttl=64,
827 ip_src=src_ip_str,
828 ip_dst=dst_ip_str)
829 pkt=str(parsed_pkt)
830 self.dataplane.send(port1, pkt)
831 for port in config["port_map"].keys():
Flavio Castro12296312015-12-15 17:48:26 -0500832 if port == port2 or port == port1:
castroflaviocc403a92015-12-15 14:04:19 -0500833 verify_no_packet(self, pkt, port)
Flavio Castro12296312015-12-15 17:48:26 -0500834 continue
castroflaviocc403a92015-12-15 14:04:19 -0500835 verify_packet(self, pkt, port)
836 verify_no_other_packets(self)
837
Flavio Castro12296312015-12-15 17:48:26 -0500838class L3McastToL3(base_tests.SimpleDataPlane):
839 """
840 Mcast routing
841 """
842 def runTest(self):
843 """
844 port1 (vlan 1)-> port 2 (vlan 2)
845 """
846 delete_all_flows(self.controller)
847 delete_all_groups(self.controller)
848
849 if len(config["port_map"]) <3:
castroflavio4a09c962016-01-05 13:13:41 -0800850 logging.info("Port count less than 3, can't run this case")
851 assert(False)
Flavio Castro12296312015-12-15 17:48:26 -0500852 return
853
854 vlan_id =1
855 port2_out_vlan=2
856 port3_out_vlan=3
857 in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan
858 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
859 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
860 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
861 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
862 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
863 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
864 src_ip=0xc0a80101
865 src_ip_str="192.168.1.1"
866 dst_ip=0xe0010101
867 dst_ip_str="224.1.1.1"
868
869 port1=config["port_map"].keys()[0]
870 port2=config["port_map"].keys()[1]
871 port3=config["port_map"].keys()[2]
872
873 #add l2 interface group
874 for port in config["port_map"].keys():
875 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
876 #add vlan flow table
877 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
878 vlan_id +=1
879
880 #add termination flow
881 add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
882
883 #add l3 interface group
884 port2_ucast_msg=add_l3_interface_group(self.controller, port2, port2_out_vlan, 2, intf_src_mac)
885 port3_ucast_msg=add_l3_interface_group(self.controller, port3, port3_out_vlan, 3, intf_src_mac)
886 mcat_group_msg=add_l3_mcast_group(self.controller, in_vlan, 2, [port2_ucast_msg.group_id, port3_ucast_msg.group_id])
887 add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id)
888
889 parsed_pkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=1,
890 eth_dst=dst_mac_str,
891 eth_src=port1_mac_str,
892 ip_ttl=64,
893 ip_src=src_ip_str,
894 ip_dst=dst_ip_str)
895 pkt=str(parsed_pkt)
896 self.dataplane.send(port1, pkt)
897 parsed_pkt = simple_udp_packet(pktlen=96,
898 eth_dst=dst_mac_str,
899 eth_src=intf_src_mac_str,
900 ip_ttl=63,
901 ip_src=src_ip_str,
902 ip_dst=dst_ip_str)
903 pkt=str(parsed_pkt)
904 verify_packet(self, pkt, port2)
905 verify_packet(self, pkt, port3)
906 verify_no_other_packets(self)
907
908class L3McastToVPN(base_tests.SimpleDataPlane):
909 """
910 Mcast routing
911 """
912 def runTest(self):
913 """
914 port1 (vlan 1)-> port 2 (vlan 2)
915 """
916 #delete_all_flows(self.controller)
917 #delete_all_groups(self.controller)
918
919 if len(config["port_map"]) <3:
castroflavio4a09c962016-01-05 13:13:41 -0800920 logging.info("Port count less than 3, can't run this case")
921 assert(False)
Flavio Castro12296312015-12-15 17:48:26 -0500922 return
923
924 vlan_id =1
925 port2_out_vlan=2
926 port3_out_vlan=3
927 in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan
928 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
929 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
930 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
931 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
932 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
933 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
934 src_ip=0xc0a80101
935 src_ip_str="192.168.1.1"
936 dst_ip=0xe0010101
937 dst_ip_str="224.1.1.1"
938
939 port1=config["port_map"].keys()[0]
940 port2=config["port_map"].keys()[1]
941 port3=config["port_map"].keys()[2]
942
943 #add l2 interface group
944 for port in config["port_map"].keys():
945 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
946 #add vlan flow table
947 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
948 vlan_id +=1
949
950 #add termination flow
951 add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
952
953 #add MPLS interface group
954 l2_gid = encode_l2_interface_group_id(port2_out_vlan, port2)
955 mpls_gid2, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, port2_out_vlan, port2)
956 l2_gid3 = encode_l2_interface_group_id(port3_out_vlan, port3)
957 mpls_gid3, mpls_msg = add_mpls_intf_group(self.controller, l2_gid3, dst_mac, intf_src_mac, port3_out_vlan, port3)
958 #add L3VPN groups
959 mpls_label_gid2, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
960 index=(0x20000+port2), ref_gid= mpls_gid2, push_mpls_header=True, set_mpls_label=port2, set_bos=1, cpy_ttl_outward=True)
961 mpls_label_gid3, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
962 index=(0x10000+port3), ref_gid= mpls_gid3, push_mpls_header=True, set_mpls_label=port3, set_bos=1, cpy_ttl_outward=True)
963
Flavio Castro12296312015-12-15 17:48:26 -0500964 mcat_group_msg=add_l3_mcast_group(self.controller, in_vlan, 2, [0x92020022 , 0x92010023])
965 add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id)
966
967 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=1,
968 eth_dst=dst_mac_str,
969 eth_src=port1_mac_str,
970 ip_ttl=64,
971 ip_src=src_ip_str,
972 ip_dst=dst_ip_str)
973 pkt=str(parsed_pkt)
974 self.dataplane.send(port1, pkt)
975 label = (in_vlan, 0, 1, 63)
976 parsed_pkt = mpls_packet(pktlen=100,
977 eth_dst=dst_mac_str,
978 eth_src=intf_src_mac_str,
979 ip_ttl=63,
980 ip_src=src_ip_str, label= [label],
981 ip_dst=dst_ip_str)
982 pkt=str(parsed_pkt)
983 verify_packet(self, pkt, port2)
984 verify_packet(self, pkt, port3)
985 verify_no_other_packets(self)
castroflavio30c6cc52016-01-07 15:19:42 -0800986
987class LPM(base_tests.SimpleDataPlane):
988 """
989 Insert IP packet
990 Receive MPLS packet
991 """
992 def runTest(self):
993 delete_all_flows(self.controller)
994 delete_all_groups(self.controller)
995
996 if len(config["port_map"]) <2:
997 logging.info("Port count less than 2, can't run this case")
998 return
999
1000 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1001 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1002 dip=0xc0a80001
1003 index=1
1004 ports = config["port_map"].keys()
1005 for port in ports:
1006 #add l2 interface group
1007 vlan_id=port
1008 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
1009 dst_mac[5]=vlan_id
1010 #add MPLS interface group
1011 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, port)
1012 #add MPLS L3 VPN group
1013 mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
1014 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 -05001015 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
castroflavio30c6cc52016-01-07 15:19:42 -08001016 do_barrier(self.controller)
1017 #add vlan flow table
1018 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=2, flag=VLAN_TABLE_FLAG_ONLY_TAG)
1019 #add termination flow
1020 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
1021 #add routing flow
1022 dst_ip = dip + (vlan_id<<8)
Flavio Castro5edf3132016-01-27 15:45:08 -05001023 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, mpls_label_gid, vrf=2)
1024 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id, vrf=2)
castroflavio30c6cc52016-01-07 15:19:42 -08001025 #add entries in the Bridging table to avoid packet-in from mac learning
1026 group_id = encode_l2_interface_group_id(vlan_id, port)
1027 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
1028 port = ports[0]
1029 #add l2 interface group
1030 vlan_id=port
1031 l2_gid = encode_l2_interface_group_id(vlan_id, port)
1032 dst_mac[5]=vlan_id
1033 #add MPLS interface group
1034 mpls_gid = encode_mpls_interface_group_id(0, port)
1035 #add MPLS L3 VPN group
1036 mpls_label_gid = encode_mpls_label_group_id(OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=port)
Flavio Castro5edf3132016-01-27 15:45:08 -05001037 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
castroflavio30c6cc52016-01-07 15:19:42 -08001038 do_barrier(self.controller)
1039 #add routing flow
1040 dst_ip = 0x0
Flavio Castro5edf3132016-01-27 15:45:08 -05001041 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, mpls_label_gid, vrf=2)
1042 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, ecmp_msg.group_id, vrf=2)
castroflavio30c6cc52016-01-07 15:19:42 -08001043
1044 do_barrier(self.controller)
1045
1046 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1047 for in_port in ports:
1048 mac_src='00:00:00:22:22:%02X' % in_port
1049 ip_src='192.168.%02d.1' % in_port
1050 for out_port in ports:
1051 if in_port == out_port:
1052 continue
1053 ip_dst='192.168.%02d.1' % out_port
1054 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
1055 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
1056 ip_dst=ip_dst)
1057 pkt=str(parsed_pkt)
1058 self.dataplane.send(in_port, pkt)
1059 #build expect packet
1060 mac_dst='00:00:00:22:22:%02X' % out_port
1061 label = (out_port, 0, 1, 32)
1062 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=63, ip_src=ip_src,
1063 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
1064 pkt=str(exp_pkt)
1065 verify_packet(self, pkt, out_port)
1066 verify_no_other_packets(self)
1067 ip_dst='1.168.%02d.1' % out_port
1068 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
1069 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst)
1070 pkt=str(parsed_pkt)
1071 self.dataplane.send(in_port, pkt)
1072 #build expect packet
1073 mac_dst='00:00:00:22:22:%02X' % out_port
1074 label = (out_port, 0, 1, 32)
1075 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=63, ip_src=ip_src,
1076 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
1077 pkt=str(exp_pkt)
1078 verify_packet(self, pkt, out_port)
1079 verify_no_other_packets(self)