blob: e1d63cb7f4ecf265baf3801e47d4f46693e4dd00 [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)
478 #add vlan flow table
Flavio Castro34352e72015-12-07 20:01:51 -0500479 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=2, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
Flavio Castro72a45d52015-12-02 16:37:05 -0500480 #add termination flow
481 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
Flavio Castro35e64392015-12-02 16:53:14 -0500482 #add routing flow
Flavio Castro72a45d52015-12-02 16:37:05 -0500483 dst_ip = dip + (vlan_id<<8)
Flavio Castro34352e72015-12-07 20:01:51 -0500484 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
Flavio Castro72a45d52015-12-02 16:37:05 -0500485 #add entries in the Bridging table to avoid packet-in from mac learning
486 group_id = encode_l2_interface_group_id(vlan_id, port)
487 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
488
489 do_barrier(self.controller)
490
491 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
492 for in_port in ports:
493 mac_src='00:00:00:22:22:%02X' % in_port
494 ip_src='192.168.%02d.1' % in_port
495 for out_port in ports:
496 if in_port == out_port:
497 continue
498 ip_dst='192.168.%02d.1' % out_port
499 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
500 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
501 ip_dst=ip_dst)
502 pkt=str(parsed_pkt)
503 self.dataplane.send(in_port, pkt)
504 #build expect packet
505 mac_dst='00:00:00:22:22:%02X' % out_port
506 label = (out_port, 0, 1, 32)
Flavio Castro34352e72015-12-07 20:01:51 -0500507 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 -0500508 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
509 pkt=str(exp_pkt)
510 verify_packet(self, pkt, out_port)
511 verify_no_other_packets(self)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500512
513class MplsTermination(base_tests.SimpleDataPlane):
Flavio Castro34352e72015-12-07 20:01:51 -0500514 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500515 Insert IP packet
516 Receive MPLS packet
Flavio Castro34352e72015-12-07 20:01:51 -0500517 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500518 def runTest(self):
519 delete_all_flows(self.controller)
520 delete_all_groups(self.controller)
521
522 if len(config["port_map"]) <2:
523 logging.info("Port count less than 2, can't run this case")
524 return
525
526 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
527 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
528 dip=0xc0a80001
529 index=1
530 ports = config["port_map"].keys()
531 for port in ports:
532 #add l2 interface group
533 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500534 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, False)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500535 dst_mac[5]=vlan_id
536 #add L3 Unicast group
537 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 -0500538 #add L3 ecmp group
539 ecmp_msg = add_l3_ecmp_group(self.controller, port, [l3_msg.group_id])
Flavio Castrod8f8af22015-12-02 18:19:26 -0500540 #add vlan flow table
541 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
542 #add termination flow
Flavio Castro167f5bd2015-12-02 19:33:53 -0500543 add_termination_flow(self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500544 #add routing flow
545 dst_ip = dip + (vlan_id<<8)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500546 add_mpls_flow(self.controller, ecmp_msg.group_id, port)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500547 #add entries in the Bridging table to avoid packet-in from mac learning
548 group_id = encode_l2_interface_group_id(vlan_id, port)
549 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
550
551 do_barrier(self.controller)
552
553 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
554 for in_port in ports:
555 mac_src='00:00:00:22:22:%02X' % in_port
556 ip_src='192.168.%02d.1' % in_port
557 for out_port in ports:
558 if in_port == out_port:
559 continue
560 ip_dst='192.168.%02d.1' % out_port
Flavio Castro167f5bd2015-12-02 19:33:53 -0500561
562 label = (out_port, 0, 1, 32)
563 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src,
564 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[label])
Flavio Castrod8f8af22015-12-02 18:19:26 -0500565 pkt=str(parsed_pkt)
566 self.dataplane.send(in_port, pkt)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500567
Flavio Castrod8f8af22015-12-02 18:19:26 -0500568 #build expect packet
569 mac_dst='00:00:00:22:22:%02X' % out_port
Flavio Castro167f5bd2015-12-02 19:33:53 -0500570 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
571 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 -0500572 pkt=str(exp_pkt)
573 verify_packet(self, pkt, out_port)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500574 verify_no_other_packets(self)
575
Flavio Castro34352e72015-12-07 20:01:51 -0500576