blob: 02cd55059e469599b9dc5fd357e95fae7ef1e6eb [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 """
56 Test L2 forwarding of both, untagged and tagged packets
57 Sends a packet and expects the same packet on the other port
58 Repeats for tagged
59 """
Flavio Castro1b5c21d2015-12-08 12:41:56 -050060 def runTest(self):
61 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
66 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 4093, False, 1)
67 #set up tagged groups
68 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 300, True, 1)
69 for port in ports:
70 add_one_vlan_table_flow(self.controller, port, 4093, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
71 group_id = encode_l2_interface_group_id(4093, port)
72 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 4093, group_id, True)
73 #add flow match for vlan 300
74 add_one_vlan_table_flow(self.controller, port, 300, flag=VLAN_TABLE_FLAG_ONLY_TAG)
75 group_id = encode_l2_interface_group_id(300, port)
76 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 300, group_id, True)
77 do_barrier(self.controller)
78
79 for out_port in ports:
80 # change dest based on port number
81 mac_dst= '00:12:34:56:78:%02X' % out_port
82
83 for in_port in ports:
84 if in_port == out_port:
85 continue
86 # change source based on port number to avoid packet-ins from learning
87 mac_src= '00:12:34:56:78:%02X' % in_port
Flavio Castroc36621e2015-12-08 12:57:07 -050088 #sends an untagged packet
Flavio Castro1b5c21d2015-12-08 12:41:56 -050089 parsed_pkt = simple_tcp_packet(dl_vlan_enable=False, vlan_vid=4093, eth_dst=mac_dst, eth_src=mac_src)
90 pkt = str(parsed_pkt)
91 logging.info("OutputExact test, ports %d to %d", in_port, out_port)
92 self.dataplane.send(in_port, pkt)
93
94 for ofport in ports:
95 if ofport in [out_port]:
96 verify_packet(self, pkt, ofport)
97 else:
98 verify_no_packet(self, pkt, ofport)
99
100 verify_no_other_packets(self)
Flavio Castroc36621e2015-12-08 12:57:07 -0500101 # sends a tagged packet
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500102 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=300, eth_dst=mac_dst, eth_src=mac_src)
103 pkt = str(parsed_pkt)
104 logging.info("OutputExact test, ports %d to %d", in_port, out_port)
105 self.dataplane.send(in_port, pkt)
106
107 for ofport in ports:
108 if ofport in [out_port]:
109 verify_packet(self, pkt, ofport)
110 else:
111 verify_no_packet(self, pkt, ofport)
112
113 verify_no_other_packets(self)
114
115class L2FloodQinQ(base_tests.SimpleDataPlane):
116 """
Flavio Castroc36621e2015-12-08 12:57:07 -0500117 Test L2 flood of double tagged vlan packets (802.1Q)
118 Sends a double tagged packet and verifies flooding behavior according to outer vlan
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500119 """
120 def runTest(self):
121 ports = sorted(config["port_map"].keys())
122
123 delete_all_flows(self.controller)
124 delete_all_groups(self.controller)
125
126 # Installing flows to avoid packet-in
127 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500128 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500129 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
130
131 group_id = encode_l2_interface_group_id(1, port)
132 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
133 msg=add_l2_flood_group(self.controller, ports, 1, 1)
134 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
135 do_barrier(self.controller)
136
137 #verify flood
138 for ofport in ports:
139 # change dest based on port number
140 mac_src= '00:12:34:56:78:%02X' % ofport
141 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108, out_dl_vlan_enable=True, out_vlan_vid=1,
142 in_dl_vlan_enable=True, in_vlan_vid=10, eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
143 pkt = str(parsed_pkt)
144 self.dataplane.send(ofport, pkt)
145 #self won't rx packet
146 verify_no_packet(self, pkt, ofport)
147 #others will rx packet
148 tmp_ports=list(ports)
149 tmp_ports.remove(ofport)
150 verify_packets(self, pkt, tmp_ports)
151
152 verify_no_other_packets(self)
153
154
Flavio Castro184cefe2015-11-19 20:52:49 -0500155class L2FloodTagged(base_tests.SimpleDataPlane):
156 """
157 Test L2 flood to a vlan
158 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
159 #todo take in account unknown src
160 """
161 def runTest(self):
162 ports = sorted(config["port_map"].keys())
Flavio Castro34352e72015-12-07 20:01:51 -0500163
Flavio Castro184cefe2015-11-19 20:52:49 -0500164 delete_all_flows(self.controller)
165 delete_all_groups(self.controller)
166
Flavio Castro184cefe2015-11-19 20:52:49 -0500167 # Installing flows to avoid packet-in
168 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500169 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500170 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
171
Flavio Castro184cefe2015-11-19 20:52:49 -0500172 group_id = encode_l2_interface_group_id(1, port)
173 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
Flavio Castro34352e72015-12-07 20:01:51 -0500174 msg=add_l2_flood_group(self.controller, ports, 1, 1)
175 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
Flavio Castro184cefe2015-11-19 20:52:49 -0500176 do_barrier(self.controller)
177
178 #verify flood
179 for ofport in ports:
180 # change dest based on port number
181 mac_src= '00:12:34:56:78:%02X' % ofport
182 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
183 pkt = str(parsed_pkt)
184 self.dataplane.send(ofport, pkt)
185 #self won't rx packet
186 verify_no_packet(self, pkt, ofport)
187 #others will rx packet
188 tmp_ports=list(ports)
189 tmp_ports.remove(ofport)
190 verify_packets(self, pkt, tmp_ports)
191
192 verify_no_other_packets(self)
193
Flavio Castroaabb5792015-11-18 19:03:50 -0500194class L2FloodTaggedUnknownSrc(base_tests.SimpleDataPlane):
195 """
196 Test L2 flood to a vlan
197 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
198 #todo take in account unknown src
199 """
200 def runTest(self):
Flavio Castroaabb5792015-11-18 19:03:50 -0500201 delete_all_flows(self.controller)
202 delete_all_groups(self.controller)
203
Flavio Castro34352e72015-12-07 20:01:51 -0500204 ports = sorted(config["port_map"].keys())
205 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500206 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500207 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castroaabb5792015-11-18 19:03:50 -0500208
209 msg=add_l2_flood_group(self.controller, ports, 1, 1)
210 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
211
212 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a')
213 pkt = str(parsed_pkt)
214 #verify flood
215 for ofport in ports:
216 self.dataplane.send(ofport, pkt)
217 #self won't rx packet
218 verify_no_packet(self, pkt, ofport)
219 #others will rx packet
220 tmp_ports=list(ports)
221 tmp_ports.remove(ofport)
222 verify_packets(self, pkt, tmp_ports)
223
224 verify_no_other_packets(self)
225
Flavio Castroaabb5792015-11-18 19:03:50 -0500226class L2UnicastTagged(base_tests.SimpleDataPlane):
227 """
228 Test output function for an exact-match flow
229
230 For each port A, adds a flow directing matching packets to that port.
231 Then, for all other ports B != A, verifies that sending a matching packet
232 to B results in an output to A.
233 """
234 def runTest(self):
235 ports = sorted(config["port_map"].keys())
236
237 delete_all_flows(self.controller)
238 delete_all_groups(self.controller)
239
Flavio Castroaabb5792015-11-18 19:03:50 -0500240 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500241 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500242 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castroaabb5792015-11-18 19:03:50 -0500243 group_id = encode_l2_interface_group_id(1, port)
244 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
Flavio Castro6efe1862015-11-18 16:28:06 -0500245 do_barrier(self.controller)
246
Flavio Castroaabb5792015-11-18 19:03:50 -0500247 for out_port in ports:
248 # change dest based on port number
249 mac_dst= '00:12:34:56:78:%02X' % out_port
250 for in_port in ports:
251 if in_port == out_port:
252 continue
253 # change source based on port number to avoid packet-ins from learning
254 mac_src= '00:12:34:56:78:%02X' % in_port
255 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
256 pkt = str(parsed_pkt)
257 self.dataplane.send(in_port, pkt)
258
259 for ofport in ports:
260 if ofport in [out_port]:
261 verify_packet(self, pkt, ofport)
262 else:
263 verify_no_packet(self, pkt, ofport)
264
265 verify_no_other_packets(self)
Flavio Castro6efe1862015-11-18 16:28:06 -0500266
267
Flavio Castrob6773032015-11-19 22:49:24 -0500268class Mtu4500(base_tests.SimpleDataPlane):
269
270 def runTest(self):
271 ports = sorted(config["port_map"].keys())
272
273 delete_all_flows(self.controller)
274 delete_all_groups(self.controller)
275
Flavio Castrob6773032015-11-19 22:49:24 -0500276 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500277 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500278 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrob6773032015-11-19 22:49:24 -0500279 group_id = encode_l2_interface_group_id(1, port)
280 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
281 do_barrier(self.controller)
282
283 for out_port in ports:
284 # change dest based on port number
285 mac_dst= '00:12:34:56:78:%02X' % out_port
286 for in_port in ports:
287 if in_port == out_port:
288 continue
289 # change source based on port number to avoid packet-ins from learning
290 mac_src= '00:12:34:56:78:%02X' % in_port
291 parsed_pkt = simple_tcp_packet(pktlen=4500,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
292 pkt = str(parsed_pkt)
293 self.dataplane.send(in_port, pkt)
294
295 for ofport in ports:
296 if ofport in [out_port]:
297 verify_packet(self, pkt, ofport)
298 else:
299 verify_no_packet(self, pkt, ofport)
300
301 verify_no_other_packets(self)
302
303
304class Mtu1500(base_tests.SimpleDataPlane):
305
306 def runTest(self):
307 ports = sorted(config["port_map"].keys())
308
309 delete_all_flows(self.controller)
310 delete_all_groups(self.controller)
311
Flavio Castro34352e72015-12-07 20:01:51 -0500312 # set up tag groups for each port
313 add_l2_interface_grouop(self.controller, ports, 1, True, 1)
Flavio Castrob6773032015-11-19 22:49:24 -0500314
Flavio Castro34352e72015-12-07 20:01:51 -0500315 add_vlan_table_flow(self.controller, ports)
Flavio Castrob6773032015-11-19 22:49:24 -0500316
317 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500318 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500319 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrob6773032015-11-19 22:49:24 -0500320 group_id = encode_l2_interface_group_id(1, port)
321 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
322 do_barrier(self.controller)
323
324 for out_port in ports:
325 # change dest based on port number
326 mac_dst= '00:12:34:56:78:%02X' % out_port
327 for in_port in ports:
328 if in_port == out_port:
329 continue
330 # change source based on port number to avoid packet-ins from learning
331 mac_src= '00:12:34:56:78:%02X' % in_port
332 parsed_pkt = simple_tcp_packet(pktlen=1500,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
333 pkt = str(parsed_pkt)
334 self.dataplane.send(in_port, pkt)
335
336 for ofport in ports:
337 if ofport in [out_port]:
338 verify_packet(self, pkt, ofport)
339 else:
340 verify_no_packet(self, pkt, ofport)
341
342 verify_no_other_packets(self)
343
344
345class Mtu4000(base_tests.SimpleDataPlane):
346 """
347 Test output function for an exact-match flow
348 For each port A, adds a flow directing matching packets to that port.
349 Then, for all other ports B != A, verifies that sending a matching packet
350 to B results in an output to A.
351 """
352 def runTest(self):
353 ports = sorted(config["port_map"].keys())
354
355 delete_all_flows(self.controller)
356 delete_all_groups(self.controller)
357
358 add_vlan_table_flow(self.controller, config["port_map"].keys())
359
360 # set up tag groups for each port
361 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1)
362
363 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500364 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500365 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrob6773032015-11-19 22:49:24 -0500366 group_id = encode_l2_interface_group_id(1, port)
367 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
368 do_barrier(self.controller)
369
370 for out_port in ports:
371 # change dest based on port number
372 mac_dst= '00:12:34:56:78:%02X' % out_port
373 for in_port in ports:
374 if in_port == out_port:
375 continue
376 # change source based on port number to avoid packet-ins from learning
377 mac_src= '00:12:34:56:78:%02X' % in_port
378 parsed_pkt = simple_tcp_packet(pktlen=4000,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
379 pkt = str(parsed_pkt)
380 self.dataplane.send(in_port, pkt)
381
382 for ofport in ports:
383 if ofport in [out_port]:
384 verify_packet(self, pkt, ofport)
385 else:
386 verify_no_packet(self, pkt, ofport)
387
388 verify_no_other_packets(self)
Flavio Castroaabb5792015-11-18 19:03:50 -0500389
390class L3UcastTagged(base_tests.SimpleDataPlane):
Flavio Castro05d20bc2015-11-16 15:06:14 -0500391 """
Flavio Castro35e64392015-12-02 16:53:14 -0500392 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
393 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500394 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500395 def runTest(self):
Flavio Castro05d20bc2015-11-16 15:06:14 -0500396 delete_all_flows(self.controller)
397 delete_all_groups(self.controller)
398
399 if len(config["port_map"]) <2:
400 logging.info("Port count less than 2, can't run this case")
401 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500402
Flavio Castro05d20bc2015-11-16 15:06:14 -0500403 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
404 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
405 dip=0xc0a80001
Flavio Castroa8233862015-12-02 14:41:11 -0500406 ports = config["port_map"].keys()
407 for port in ports:
Flavio Castro05d20bc2015-11-16 15:06:14 -0500408 #add l2 interface group
Flavio Castroa8233862015-12-02 14:41:11 -0500409 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500410 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 -0500411 dst_mac[5]=vlan_id
412 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
413 #add vlan flow table
Flavio Castro34352e72015-12-07 20:01:51 -0500414 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500415 #add termination flow
Flavio Castrod8f8af22015-12-02 18:19:26 -0500416 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500417 #add unicast routing flow
Flavio Castrod8f8af22015-12-02 18:19:26 -0500418 dst_ip = dip + (vlan_id<<8)
Flavio Castro6efe1862015-11-18 16:28:06 -0500419 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
Flavio Castro6efe1862015-11-18 16:28:06 -0500420 #add entries in the Bridging table to avoid packet-in from mac learning
421 group_id = encode_l2_interface_group_id(vlan_id, port)
422 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500423
424 do_barrier(self.controller)
425
Flavio Castro05d20bc2015-11-16 15:06:14 -0500426 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
Flavio Castroa8233862015-12-02 14:41:11 -0500427 for in_port in ports:
428 mac_src='00:00:00:22:22:%02X' % in_port
429 ip_src='192.168.%02d.1' % in_port
430 for out_port in ports:
431 if in_port == out_port:
432 continue
433 ip_dst='192.168.%02d.1' % out_port
434 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
435 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
Flavio Castrod8f8af22015-12-02 18:19:26 -0500436 ip_dst=ip_dst)
Flavio Castroa8233862015-12-02 14:41:11 -0500437 pkt=str(parsed_pkt)
438 self.dataplane.send(in_port, pkt)
Flavio Castro72a45d52015-12-02 16:37:05 -0500439 #build expected packet
Flavio Castroa8233862015-12-02 14:41:11 -0500440 mac_dst='00:00:00:22:22:%02X' % out_port
Flavio Castrod8f8af22015-12-02 18:19:26 -0500441 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
Flavio Castroa8233862015-12-02 14:41:11 -0500442 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
443 ip_src=ip_src, ip_dst=ip_dst)
444 pkt=str(exp_pkt)
445 verify_packet(self, pkt, out_port)
446 verify_no_other_packets(self)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500447
Flavio Castrod8f8af22015-12-02 18:19:26 -0500448class L3VPNMPLS(base_tests.SimpleDataPlane):
449 """
450 Insert IP packet
451 Receive MPLS packet
452 """
Flavio Castro72a45d52015-12-02 16:37:05 -0500453 def runTest(self):
454 delete_all_flows(self.controller)
455 delete_all_groups(self.controller)
456
457 if len(config["port_map"]) <2:
458 logging.info("Port count less than 2, can't run this case")
459 return
460
461 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
462 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
463 dip=0xc0a80001
464 index=1
465 ports = config["port_map"].keys()
466 for port in ports:
467 #add l2 interface group
468 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500469 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
Flavio Castro72a45d52015-12-02 16:37:05 -0500470 dst_mac[5]=vlan_id
Flavio Castro35e64392015-12-02 16:53:14 -0500471 #add MPLS interface group
Flavio Castro72a45d52015-12-02 16:37:05 -0500472 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 -0500473 #add MPLS L3 VPN group
Flavio Castrod8f8af22015-12-02 18:19:26 -0500474 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 -0500475 index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32)
476 #add vlan flow table
Flavio Castro34352e72015-12-07 20:01:51 -0500477 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 -0500478 #add termination flow
479 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
Flavio Castro35e64392015-12-02 16:53:14 -0500480 #add routing flow
Flavio Castro72a45d52015-12-02 16:37:05 -0500481 dst_ip = dip + (vlan_id<<8)
Flavio Castro34352e72015-12-07 20:01:51 -0500482 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
Flavio Castro72a45d52015-12-02 16:37:05 -0500483 #add entries in the Bridging table to avoid packet-in from mac learning
484 group_id = encode_l2_interface_group_id(vlan_id, port)
485 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
486
487 do_barrier(self.controller)
488
489 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
490 for in_port in ports:
491 mac_src='00:00:00:22:22:%02X' % in_port
492 ip_src='192.168.%02d.1' % in_port
493 for out_port in ports:
494 if in_port == out_port:
495 continue
496 ip_dst='192.168.%02d.1' % out_port
497 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
498 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
499 ip_dst=ip_dst)
500 pkt=str(parsed_pkt)
501 self.dataplane.send(in_port, pkt)
502 #build expect packet
503 mac_dst='00:00:00:22:22:%02X' % out_port
504 label = (out_port, 0, 1, 32)
Flavio Castro34352e72015-12-07 20:01:51 -0500505 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 -0500506 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
507 pkt=str(exp_pkt)
508 verify_packet(self, pkt, out_port)
509 verify_no_other_packets(self)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500510
511class MplsTermination(base_tests.SimpleDataPlane):
Flavio Castro34352e72015-12-07 20:01:51 -0500512 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500513 Insert IP packet
514 Receive MPLS packet
Flavio Castro34352e72015-12-07 20:01:51 -0500515 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500516 def runTest(self):
517 delete_all_flows(self.controller)
518 delete_all_groups(self.controller)
519
520 if len(config["port_map"]) <2:
521 logging.info("Port count less than 2, can't run this case")
522 return
523
524 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
525 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
526 dip=0xc0a80001
527 index=1
528 ports = config["port_map"].keys()
529 for port in ports:
530 #add l2 interface group
531 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500532 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, False)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500533 dst_mac[5]=vlan_id
534 #add L3 Unicast group
535 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 -0500536 #add L3 ecmp group
537 ecmp_msg = add_l3_ecmp_group(self.controller, port, [l3_msg.group_id])
Flavio Castrod8f8af22015-12-02 18:19:26 -0500538 #add vlan flow table
539 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
540 #add termination flow
Flavio Castro167f5bd2015-12-02 19:33:53 -0500541 add_termination_flow(self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500542 #add routing flow
543 dst_ip = dip + (vlan_id<<8)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500544 add_mpls_flow(self.controller, ecmp_msg.group_id, port)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500545 #add entries in the Bridging table to avoid packet-in from mac learning
546 group_id = encode_l2_interface_group_id(vlan_id, port)
547 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
548
549 do_barrier(self.controller)
550
551 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
552 for in_port in ports:
553 mac_src='00:00:00:22:22:%02X' % in_port
554 ip_src='192.168.%02d.1' % in_port
555 for out_port in ports:
556 if in_port == out_port:
557 continue
558 ip_dst='192.168.%02d.1' % out_port
Flavio Castro167f5bd2015-12-02 19:33:53 -0500559
560 label = (out_port, 0, 1, 32)
561 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src,
562 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[label])
Flavio Castrod8f8af22015-12-02 18:19:26 -0500563 pkt=str(parsed_pkt)
564 self.dataplane.send(in_port, pkt)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500565
Flavio Castrod8f8af22015-12-02 18:19:26 -0500566 #build expect packet
567 mac_dst='00:00:00:22:22:%02X' % out_port
Flavio Castro167f5bd2015-12-02 19:33:53 -0500568 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
569 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 -0500570 pkt=str(exp_pkt)
571 verify_packet(self, pkt, out_port)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500572 verify_no_other_packets(self)
573
Flavio Castro34352e72015-12-07 20:01:51 -0500574