blob: d365be6af726346ecbfa7b4f2e629b23821df8d3 [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 Castro05d20bc2015-11-16 15:06:14 -050024
Flavio Castroaabb5792015-11-18 19:03:50 -050025class PacketInSrcMacMiss(base_tests.SimpleDataPlane):
26 """
27 Test packet in function on a src-mac miss
28 Send a packet to each dataplane port and verify that a packet
29 in message is received from the controller for each
30 #todo verify you stop receiving after adding rule
31 """
32
Flavio Castro6efe1862015-11-18 16:28:06 -050033 def runTest(self):
34 delete_all_flows(self.controller)
35 delete_all_groups(self.controller)
36
Flavio Castro34352e72015-12-07 20:01:51 -050037 ports = sorted(config["port_map"].keys())
38 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -050039 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -050040 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
41
Flavio Castroaabb5792015-11-18 19:03:50 -050042 parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
43 vlan_vid=0x1001, dl_vlan_enable=True)
44 vlan_pkt = str(parsed_vlan_pkt)
Flavio Castro6efe1862015-11-18 16:28:06 -050045
Flavio Castroaabb5792015-11-18 19:03:50 -050046 for of_port in config["port_map"].keys():
47 logging.info("PacketInMiss test, port %d", of_port)
48 self.dataplane.send(of_port, vlan_pkt)
49
50 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH)
51
52 verify_no_other_packets(self)
53
Flavio Castro1b5c21d2015-12-08 12:41:56 -050054class VlanSupport(base_tests.SimpleDataPlane):
Flavio Castroc36621e2015-12-08 12:57:07 -050055 """
castroflavio046c1fe2015-12-08 14:33:32 -050056 Test L2 forwarding of both, untagged and double-tagged packets
Flavio Castroc36621e2015-12-08 12:57:07 -050057 Sends a packet and expects the same packet on the other port
castroflavio046c1fe2015-12-08 14:33:32 -050058 Repeats for double tagged
Flavio Castroc36621e2015-12-08 12:57:07 -050059 """
Flavio Castrod4c44d12015-12-08 14:44:18 -050060 def runTest(self):
Flavio Castro1b5c21d2015-12-08 12:41:56 -050061 delete_all_flows(self.controller)
62 delete_all_groups(self.controller)
63 ports = sorted(config["port_map"].keys())
64 # group table
65 # set up untag groups for each port
Flavio Castrod4c44d12015-12-08 14:44:18 -050066 add_l2_interface_group(self.controller, config["port_map"].keys(), 4093, False, 1)
Flavio Castro1b5c21d2015-12-08 12:41:56 -050067 for port in ports:
68 add_one_vlan_table_flow(self.controller, port, 4093, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
69 group_id = encode_l2_interface_group_id(4093, port)
70 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 4093, group_id, True)
71 #add flow match for vlan 300
castroflavio046c1fe2015-12-08 14:33:32 -050072 add_one_l2_interface_group(self.controller, port, 300, True, False)
Flavio Castro1b5c21d2015-12-08 12:41:56 -050073 add_one_vlan_table_flow(self.controller, port, 300, flag=VLAN_TABLE_FLAG_ONLY_TAG)
castroflavio046c1fe2015-12-08 14:33:32 -050074 msg=add_l2_flood_group(self.controller, ports, 300, 1)
75 add_bridge_flow(self.controller, None, 300, msg.group_id, True)
castroflavio21894482015-12-08 15:29:55 -050076 msg=add_l2_flood_group(self.controller, ports, 4093, 1)
77 add_bridge_flow(self.controller, None, 4093, msg.group_id, True)
Flavio Castro1b5c21d2015-12-08 12:41:56 -050078 do_barrier(self.controller)
79
80 for out_port in ports:
81 # change dest based on port number
82 mac_dst= '00:12:34:56:78:%02X' % out_port
83
84 for in_port in ports:
85 if in_port == out_port:
86 continue
87 # change source based on port number to avoid packet-ins from learning
88 mac_src= '00:12:34:56:78:%02X' % in_port
Flavio Castroc36621e2015-12-08 12:57:07 -050089 #sends an untagged packet
Flavio Castro1b5c21d2015-12-08 12:41:56 -050090 parsed_pkt = simple_tcp_packet(dl_vlan_enable=False, vlan_vid=4093, eth_dst=mac_dst, eth_src=mac_src)
91 pkt = str(parsed_pkt)
92 logging.info("OutputExact test, ports %d to %d", in_port, out_port)
93 self.dataplane.send(in_port, pkt)
94
95 for ofport in ports:
96 if ofport in [out_port]:
97 verify_packet(self, pkt, ofport)
98 else:
99 verify_no_packet(self, pkt, ofport)
100
101 verify_no_other_packets(self)
castroflavio046c1fe2015-12-08 14:33:32 -0500102 # sends a double tagged packet
103 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108, out_dl_vlan_enable=True, out_vlan_vid=300,
104 in_dl_vlan_enable=True, in_vlan_vid=10, eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500105 pkt = str(parsed_pkt)
106 logging.info("OutputExact test, ports %d to %d", in_port, out_port)
107 self.dataplane.send(in_port, pkt)
108
109 for ofport in ports:
110 if ofport in [out_port]:
111 verify_packet(self, pkt, ofport)
112 else:
113 verify_no_packet(self, pkt, ofport)
114
115 verify_no_other_packets(self)
116
117class L2FloodQinQ(base_tests.SimpleDataPlane):
118 """
Flavio Castroc36621e2015-12-08 12:57:07 -0500119 Test L2 flood of double tagged vlan packets (802.1Q)
120 Sends a double tagged packet and verifies flooding behavior according to outer vlan
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500121 """
122 def runTest(self):
123 ports = sorted(config["port_map"].keys())
124
125 delete_all_flows(self.controller)
126 delete_all_groups(self.controller)
127
128 # Installing flows to avoid packet-in
129 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500130 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500131 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
132
133 group_id = encode_l2_interface_group_id(1, port)
134 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
135 msg=add_l2_flood_group(self.controller, ports, 1, 1)
136 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
137 do_barrier(self.controller)
138
139 #verify flood
140 for ofport in ports:
141 # change dest based on port number
142 mac_src= '00:12:34:56:78:%02X' % ofport
143 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108, out_dl_vlan_enable=True, out_vlan_vid=1,
144 in_dl_vlan_enable=True, in_vlan_vid=10, eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
145 pkt = str(parsed_pkt)
146 self.dataplane.send(ofport, pkt)
147 #self won't rx packet
148 verify_no_packet(self, pkt, ofport)
149 #others will rx packet
150 tmp_ports=list(ports)
151 tmp_ports.remove(ofport)
152 verify_packets(self, pkt, tmp_ports)
153
154 verify_no_other_packets(self)
155
156
Flavio Castro184cefe2015-11-19 20:52:49 -0500157class L2FloodTagged(base_tests.SimpleDataPlane):
158 """
159 Test L2 flood to a vlan
160 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
161 #todo take in account unknown src
162 """
163 def runTest(self):
164 ports = sorted(config["port_map"].keys())
Flavio Castro34352e72015-12-07 20:01:51 -0500165
Flavio Castro184cefe2015-11-19 20:52:49 -0500166 delete_all_flows(self.controller)
167 delete_all_groups(self.controller)
168
Flavio Castro184cefe2015-11-19 20:52:49 -0500169 # Installing flows to avoid packet-in
170 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500171 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500172 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
173
Flavio Castro184cefe2015-11-19 20:52:49 -0500174 group_id = encode_l2_interface_group_id(1, port)
175 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
Flavio Castro34352e72015-12-07 20:01:51 -0500176 msg=add_l2_flood_group(self.controller, ports, 1, 1)
177 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
Flavio Castro184cefe2015-11-19 20:52:49 -0500178 do_barrier(self.controller)
179
180 #verify flood
181 for ofport in ports:
182 # change dest based on port number
183 mac_src= '00:12:34:56:78:%02X' % ofport
184 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
185 pkt = str(parsed_pkt)
186 self.dataplane.send(ofport, pkt)
187 #self won't rx packet
188 verify_no_packet(self, pkt, ofport)
189 #others will rx packet
190 tmp_ports=list(ports)
191 tmp_ports.remove(ofport)
192 verify_packets(self, pkt, tmp_ports)
193
194 verify_no_other_packets(self)
195
Flavio Castroaabb5792015-11-18 19:03:50 -0500196class L2FloodTaggedUnknownSrc(base_tests.SimpleDataPlane):
197 """
198 Test L2 flood to a vlan
199 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
200 #todo take in account unknown src
201 """
202 def runTest(self):
Flavio Castroaabb5792015-11-18 19:03:50 -0500203 delete_all_flows(self.controller)
204 delete_all_groups(self.controller)
205
Flavio Castro34352e72015-12-07 20:01:51 -0500206 ports = sorted(config["port_map"].keys())
207 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500208 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500209 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castroaabb5792015-11-18 19:03:50 -0500210
211 msg=add_l2_flood_group(self.controller, ports, 1, 1)
212 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
213
214 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a')
215 pkt = str(parsed_pkt)
216 #verify flood
217 for ofport in ports:
218 self.dataplane.send(ofport, pkt)
219 #self won't rx packet
220 verify_no_packet(self, pkt, ofport)
221 #others will rx packet
222 tmp_ports=list(ports)
223 tmp_ports.remove(ofport)
224 verify_packets(self, pkt, tmp_ports)
225
226 verify_no_other_packets(self)
227
Flavio Castroaabb5792015-11-18 19:03:50 -0500228class L2UnicastTagged(base_tests.SimpleDataPlane):
229 """
230 Test output function for an exact-match flow
231
232 For each port A, adds a flow directing matching packets to that port.
233 Then, for all other ports B != A, verifies that sending a matching packet
234 to B results in an output to A.
235 """
236 def runTest(self):
237 ports = sorted(config["port_map"].keys())
238
239 delete_all_flows(self.controller)
240 delete_all_groups(self.controller)
241
Flavio Castroaabb5792015-11-18 19:03:50 -0500242 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500243 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500244 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castroaabb5792015-11-18 19:03:50 -0500245 group_id = encode_l2_interface_group_id(1, port)
246 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
Flavio Castro6efe1862015-11-18 16:28:06 -0500247 do_barrier(self.controller)
248
Flavio Castroaabb5792015-11-18 19:03:50 -0500249 for out_port in ports:
250 # change dest based on port number
251 mac_dst= '00:12:34:56:78:%02X' % out_port
252 for in_port in ports:
253 if in_port == out_port:
254 continue
255 # change source based on port number to avoid packet-ins from learning
256 mac_src= '00:12:34:56:78:%02X' % in_port
257 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
258 pkt = str(parsed_pkt)
259 self.dataplane.send(in_port, pkt)
260
261 for ofport in ports:
262 if ofport in [out_port]:
263 verify_packet(self, pkt, ofport)
264 else:
265 verify_no_packet(self, pkt, ofport)
266
267 verify_no_other_packets(self)
Flavio Castro6efe1862015-11-18 16:28:06 -0500268
269
Flavio Castrob6773032015-11-19 22:49:24 -0500270class Mtu4500(base_tests.SimpleDataPlane):
271
272 def runTest(self):
273 ports = sorted(config["port_map"].keys())
274
275 delete_all_flows(self.controller)
276 delete_all_groups(self.controller)
277
Flavio Castrob6773032015-11-19 22:49:24 -0500278 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500279 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500280 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrob6773032015-11-19 22:49:24 -0500281 group_id = encode_l2_interface_group_id(1, port)
282 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
283 do_barrier(self.controller)
284
285 for out_port in ports:
286 # change dest based on port number
287 mac_dst= '00:12:34:56:78:%02X' % out_port
288 for in_port in ports:
289 if in_port == out_port:
290 continue
291 # change source based on port number to avoid packet-ins from learning
292 mac_src= '00:12:34:56:78:%02X' % in_port
293 parsed_pkt = simple_tcp_packet(pktlen=4500,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
294 pkt = str(parsed_pkt)
295 self.dataplane.send(in_port, pkt)
296
297 for ofport in ports:
298 if ofport in [out_port]:
299 verify_packet(self, pkt, ofport)
300 else:
301 verify_no_packet(self, pkt, ofport)
302
303 verify_no_other_packets(self)
304
305
306class Mtu1500(base_tests.SimpleDataPlane):
307
308 def runTest(self):
309 ports = sorted(config["port_map"].keys())
310
311 delete_all_flows(self.controller)
312 delete_all_groups(self.controller)
313
Flavio Castro34352e72015-12-07 20:01:51 -0500314 # set up tag groups for each port
Flavio Castrod4c44d12015-12-08 14:44:18 -0500315 add_l2_interface_group(self.controller, ports, 1, True, 1)
Flavio Castrob6773032015-11-19 22:49:24 -0500316
Flavio Castro34352e72015-12-07 20:01:51 -0500317 add_vlan_table_flow(self.controller, ports)
Flavio Castrob6773032015-11-19 22:49:24 -0500318
319 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500320 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500321 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrob6773032015-11-19 22:49:24 -0500322 group_id = encode_l2_interface_group_id(1, port)
323 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
324 do_barrier(self.controller)
325
326 for out_port in ports:
327 # change dest based on port number
328 mac_dst= '00:12:34:56:78:%02X' % out_port
329 for in_port in ports:
330 if in_port == out_port:
331 continue
332 # change source based on port number to avoid packet-ins from learning
333 mac_src= '00:12:34:56:78:%02X' % in_port
334 parsed_pkt = simple_tcp_packet(pktlen=1500,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
335 pkt = str(parsed_pkt)
336 self.dataplane.send(in_port, pkt)
337
338 for ofport in ports:
339 if ofport in [out_port]:
340 verify_packet(self, pkt, ofport)
341 else:
342 verify_no_packet(self, pkt, ofport)
343
344 verify_no_other_packets(self)
345
346
347class Mtu4000(base_tests.SimpleDataPlane):
348 """
349 Test output function for an exact-match flow
350 For each port A, adds a flow directing matching packets to that port.
351 Then, for all other ports B != A, verifies that sending a matching packet
352 to B results in an output to A.
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
360 add_vlan_table_flow(self.controller, config["port_map"].keys())
361
362 # set up tag groups for each port
Flavio Castrod4c44d12015-12-08 14:44:18 -0500363 add_l2_interface_group(self.controller, config["port_map"].keys(), 1, True, 1)
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=4000,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)
Flavio Castroaabb5792015-11-18 19:03:50 -0500391
392class L3UcastTagged(base_tests.SimpleDataPlane):
Flavio Castro05d20bc2015-11-16 15:06:14 -0500393 """
Flavio Castro35e64392015-12-02 16:53:14 -0500394 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
395 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500396 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500397 def runTest(self):
Flavio Castro05d20bc2015-11-16 15:06:14 -0500398 delete_all_flows(self.controller)
399 delete_all_groups(self.controller)
400
401 if len(config["port_map"]) <2:
402 logging.info("Port count less than 2, can't run this case")
403 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500404
Flavio Castro05d20bc2015-11-16 15:06:14 -0500405 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
406 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
407 dip=0xc0a80001
Flavio Castroa8233862015-12-02 14:41:11 -0500408 ports = config["port_map"].keys()
409 for port in ports:
Flavio Castro05d20bc2015-11-16 15:06:14 -0500410 #add l2 interface group
Flavio Castroa8233862015-12-02 14:41:11 -0500411 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500412 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 -0500413 dst_mac[5]=vlan_id
414 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
415 #add vlan flow table
Flavio Castro34352e72015-12-07 20:01:51 -0500416 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500417 #add termination flow
Flavio Castrod8f8af22015-12-02 18:19:26 -0500418 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500419 #add unicast routing flow
Flavio Castrod8f8af22015-12-02 18:19:26 -0500420 dst_ip = dip + (vlan_id<<8)
Flavio Castro6efe1862015-11-18 16:28:06 -0500421 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
Flavio Castro6efe1862015-11-18 16:28:06 -0500422 #add entries in the Bridging table to avoid packet-in from mac learning
423 group_id = encode_l2_interface_group_id(vlan_id, port)
424 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500425
426 do_barrier(self.controller)
427
Flavio Castro05d20bc2015-11-16 15:06:14 -0500428 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
Flavio Castroa8233862015-12-02 14:41:11 -0500429 for in_port in ports:
430 mac_src='00:00:00:22:22:%02X' % in_port
431 ip_src='192.168.%02d.1' % in_port
432 for out_port in ports:
433 if in_port == out_port:
434 continue
435 ip_dst='192.168.%02d.1' % out_port
436 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
437 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
Flavio Castrod8f8af22015-12-02 18:19:26 -0500438 ip_dst=ip_dst)
Flavio Castroa8233862015-12-02 14:41:11 -0500439 pkt=str(parsed_pkt)
440 self.dataplane.send(in_port, pkt)
Flavio Castro72a45d52015-12-02 16:37:05 -0500441 #build expected packet
Flavio Castroa8233862015-12-02 14:41:11 -0500442 mac_dst='00:00:00:22:22:%02X' % out_port
Flavio Castrod8f8af22015-12-02 18:19:26 -0500443 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
Flavio Castroa8233862015-12-02 14:41:11 -0500444 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
445 ip_src=ip_src, ip_dst=ip_dst)
446 pkt=str(exp_pkt)
447 verify_packet(self, pkt, out_port)
448 verify_no_other_packets(self)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500449
Flavio Castrod8f8af22015-12-02 18:19:26 -0500450class L3VPNMPLS(base_tests.SimpleDataPlane):
451 """
452 Insert IP packet
453 Receive MPLS packet
454 """
Flavio Castro72a45d52015-12-02 16:37:05 -0500455 def runTest(self):
456 delete_all_flows(self.controller)
457 delete_all_groups(self.controller)
458
459 if len(config["port_map"]) <2:
460 logging.info("Port count less than 2, can't run this case")
461 return
462
463 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
464 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
465 dip=0xc0a80001
466 index=1
467 ports = config["port_map"].keys()
468 for port in ports:
469 #add l2 interface group
470 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500471 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
Flavio Castro72a45d52015-12-02 16:37:05 -0500472 dst_mac[5]=vlan_id
Flavio Castro35e64392015-12-02 16:53:14 -0500473 #add MPLS interface group
Flavio Castro72a45d52015-12-02 16:37:05 -0500474 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 -0500475 #add MPLS L3 VPN group
Flavio Castrod8f8af22015-12-02 18:19:26 -0500476 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 -0500477 index=port, 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 -0500478 #ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
479 do_barrier(self.controller)
Flavio Castro72a45d52015-12-02 16:37:05 -0500480 #add vlan flow table
Flavio Castro80730822015-12-11 15:38:47 -0500481 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 -0500482 #add termination flow
483 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
Flavio Castro35e64392015-12-02 16:53:14 -0500484 #add routing flow
Flavio Castro72a45d52015-12-02 16:37:05 -0500485 dst_ip = dip + (vlan_id<<8)
Flavio Castro80730822015-12-11 15:38:47 -0500486 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, mpls_label_gid, vrf=2)
487 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id, vrf=2)
488 #add entries in the Bridging table to avoid packet-in from mac learning
489 group_id = encode_l2_interface_group_id(vlan_id, port)
490 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
491
492 do_barrier(self.controller)
493
494 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
495 for in_port in ports:
496 mac_src='00:00:00:22:22:%02X' % in_port
497 ip_src='192.168.%02d.1' % in_port
498 for out_port in ports:
499 if in_port == out_port:
500 continue
501 ip_dst='192.168.%02d.1' % out_port
502 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
503 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
504 ip_dst=ip_dst)
505 pkt=str(parsed_pkt)
506 self.dataplane.send(in_port, pkt)
507 #build expect packet
508 mac_dst='00:00:00:22:22:%02X' % out_port
509 label = (out_port, 0, 1, 32)
510 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=63, ip_src=ip_src,
511 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
512 pkt=str(exp_pkt)
513 verify_packet(self, pkt, out_port)
514 verify_no_other_packets(self)
515
516class L3VPN_32(base_tests.SimpleDataPlane):
517 """
518 Insert IP packet
519 Receive MPLS packet
520 """
521 def runTest(self):
522 delete_all_flows(self.controller)
523 delete_all_groups(self.controller)
524
525 if len(config["port_map"]) <2:
526 logging.info("Port count less than 2, can't run this case")
527 return
528
529 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
530 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
531 dip=0xc0a80001
532 index=1
533 ports = config["port_map"].keys()
534 for port in ports:
535 #add l2 interface group
536 vlan_id=port
537 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
538 dst_mac[5]=vlan_id
539 #add MPLS interface group
540 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, port)
541 #add MPLS L3 VPN group
542 mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
543 index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32)
544 #ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
545 do_barrier(self.controller)
546 #add vlan flow table
547 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=2, flag=VLAN_TABLE_FLAG_ONLY_TAG)
548 #add termination flow
549 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
550 #add routing flow
551 dst_ip = dip + (vlan_id<<8)
552 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_gid, vrf=2)
553 #ecmp_msg.group_id, vrf=2)
Flavio Castro72a45d52015-12-02 16:37:05 -0500554 #add entries in the Bridging table to avoid packet-in from mac learning
555 group_id = encode_l2_interface_group_id(vlan_id, port)
556 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
557
558 do_barrier(self.controller)
559
560 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
561 for in_port in ports:
562 mac_src='00:00:00:22:22:%02X' % in_port
563 ip_src='192.168.%02d.1' % in_port
564 for out_port in ports:
565 if in_port == out_port:
566 continue
567 ip_dst='192.168.%02d.1' % out_port
568 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
569 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
570 ip_dst=ip_dst)
571 pkt=str(parsed_pkt)
572 self.dataplane.send(in_port, pkt)
573 #build expect packet
574 mac_dst='00:00:00:22:22:%02X' % out_port
575 label = (out_port, 0, 1, 32)
Flavio Castro34352e72015-12-07 20:01:51 -0500576 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 -0500577 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
578 pkt=str(exp_pkt)
579 verify_packet(self, pkt, out_port)
580 verify_no_other_packets(self)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500581
582class MplsTermination(base_tests.SimpleDataPlane):
Flavio Castro34352e72015-12-07 20:01:51 -0500583 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500584 Insert IP packet
585 Receive MPLS packet
Flavio Castro34352e72015-12-07 20:01:51 -0500586 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500587 def runTest(self):
588 delete_all_flows(self.controller)
589 delete_all_groups(self.controller)
590
591 if len(config["port_map"]) <2:
592 logging.info("Port count less than 2, can't run this case")
593 return
594
595 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
596 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
597 dip=0xc0a80001
598 index=1
599 ports = config["port_map"].keys()
600 for port in ports:
601 #add l2 interface group
602 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500603 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, False)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500604 dst_mac[5]=vlan_id
605 #add L3 Unicast group
606 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 -0500607 #add L3 ecmp group
608 ecmp_msg = add_l3_ecmp_group(self.controller, port, [l3_msg.group_id])
Flavio Castrod8f8af22015-12-02 18:19:26 -0500609 #add vlan flow table
Flavio Castro80730822015-12-11 15:38:47 -0500610 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500611 #add termination flow
Flavio Castro167f5bd2015-12-02 19:33:53 -0500612 add_termination_flow(self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500613 #add routing flow
614 dst_ip = dip + (vlan_id<<8)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500615 add_mpls_flow(self.controller, ecmp_msg.group_id, port)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500616 #add entries in the Bridging table to avoid packet-in from mac learning
617 group_id = encode_l2_interface_group_id(vlan_id, port)
618 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
619
620 do_barrier(self.controller)
621
622 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
623 for in_port in ports:
624 mac_src='00:00:00:22:22:%02X' % in_port
625 ip_src='192.168.%02d.1' % in_port
626 for out_port in ports:
627 if in_port == out_port:
628 continue
629 ip_dst='192.168.%02d.1' % out_port
Flavio Castro167f5bd2015-12-02 19:33:53 -0500630
631 label = (out_port, 0, 1, 32)
632 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src,
633 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[label])
Flavio Castrod8f8af22015-12-02 18:19:26 -0500634 pkt=str(parsed_pkt)
635 self.dataplane.send(in_port, pkt)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500636
Flavio Castrod8f8af22015-12-02 18:19:26 -0500637 #build expect packet
638 mac_dst='00:00:00:22:22:%02X' % out_port
Flavio Castro167f5bd2015-12-02 19:33:53 -0500639 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
640 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 -0500641 pkt=str(exp_pkt)
642 verify_packet(self, pkt, out_port)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500643 verify_no_other_packets(self)
644
Flavio Castro80730822015-12-11 15:38:47 -0500645class MPLSBUG(base_tests.SimpleDataPlane):
646
647 def runTest(self):
648 delete_all_flows(self.controller)
649 delete_all_groups(self.controller)
650
651 if len(config["port_map"]) <2:
652 logging.info("Port count less than 2, can't run this case")
653 return
654
655 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
656 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
657 dip=0xc0a80001
658 index=1
659 ports = config["port_map"].keys()
660 for port in ports:
661 #add l2 interface group
662 vlan_id=port
663 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, False)
664 dst_mac[5]=vlan_id
665 #add L3 Unicast group
666 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
667 #add vlan flow table
668 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
669 #add termination flow
670 add_termination_flow(self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24)
671 #add mpls flow
672 add_mpls_flow(self.controller, l3_msg.group_id, port)
673 #add termination flow
674 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
675 #add unicast routing flow
676 dst_ip = dip + (vlan_id<<8)
677 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
678
679 #add entries in the Bridging table to avoid packet-in from mac learning
680 group_id = encode_l2_interface_group_id(vlan_id, port)
681 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
682
683 do_barrier(self.controller)
684
685 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
686 for in_port in ports:
687 mac_src='00:00:00:22:22:%02X' % in_port
688 ip_src='192.168.%02d.1' % in_port
689 for out_port in ports:
690 if in_port == out_port:
691 continue
692 ip_dst='192.168.%02d.1' % out_port
693 switch_mac = "00:00:00:cc:cc:cc"
694 label = (out_port, 0, 1, 32)
695 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src,
696 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[label])
697 pkt=str(parsed_pkt)
698 self.dataplane.send(in_port, pkt)
699
700 #build expect packet
701 mac_dst='00:00:00:22:22:%02X' % out_port
702 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
703 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst)
704 pkt=str(exp_pkt)
705 verify_packet(self, pkt, out_port)
706 verify_no_other_packets(self)
707
708 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
709 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
710 ip_dst=ip_dst)
711 pkt=str(parsed_pkt)
712 self.dataplane.send(in_port, pkt)
713 #build expected packet
714 mac_dst='00:00:00:22:22:%02X' % out_port
715 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
716 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
717 ip_src=ip_src, ip_dst=ip_dst)
718 pkt=str(exp_pkt)
719 verify_packet(self, pkt, out_port)
720 verify_no_other_packets(self)
721
Flavio Castro34352e72015-12-07 20:01:51 -0500722