blob: 388cf96a32e96d9334c38c4d2765abff3c108567 [file] [log] [blame]
Flavio Castro05d20bc2015-11-16 15:06:14 -05001"""
2Flow Test
Flavio Castro3aec8902015-11-20 10:51:38 -050031) PacketInSrcMacMiss
42) L2FloodTagged
53) L2Flood Tagged Unknown Src
64) L2 Unicast Tagged
75) L3 Unicast Tagged
86) MTU 1500
97) MTU 4100
108) MTU 4500
Flavio Castro05d20bc2015-11-16 15:06:14 -050011"""
12
Flavio Castro05d20bc2015-11-16 15:06:14 -050013from oftest import config
Flavio Castro167f5bd2015-12-02 19:33:53 -050014import logging
15import oftest.base_tests as base_tests
Flavio Castro05d20bc2015-11-16 15:06:14 -050016import ofp
17from oftest.testutils import *
18from accton_util import *
Flavio Castrod8f8af22015-12-02 18:19:26 -050019
Flavio Castro05d20bc2015-11-16 15:06:14 -050020
Flavio Castroaabb5792015-11-18 19:03:50 -050021class PacketInSrcMacMiss(base_tests.SimpleDataPlane):
22 """
23 Test packet in function on a src-mac miss
24 Send a packet to each dataplane port and verify that a packet
25 in message is received from the controller for each
26 #todo verify you stop receiving after adding rule
27 """
28
Flavio Castro6efe1862015-11-18 16:28:06 -050029 def runTest(self):
30 delete_all_flows(self.controller)
31 delete_all_groups(self.controller)
32
Flavio Castro34352e72015-12-07 20:01:51 -050033 ports = sorted(config["port_map"].keys())
34 for port in ports:
35 add_one_l2_interface_grouop(self.controller, port, 1, True, False)
36 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
37
Flavio Castroaabb5792015-11-18 19:03:50 -050038 parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
39 vlan_vid=0x1001, dl_vlan_enable=True)
40 vlan_pkt = str(parsed_vlan_pkt)
Flavio Castro6efe1862015-11-18 16:28:06 -050041
Flavio Castroaabb5792015-11-18 19:03:50 -050042 for of_port in config["port_map"].keys():
43 logging.info("PacketInMiss test, port %d", of_port)
44 self.dataplane.send(of_port, vlan_pkt)
45
46 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH)
47
48 verify_no_other_packets(self)
49
Flavio Castro1b5c21d2015-12-08 12:41:56 -050050class VlanSupport(base_tests.SimpleDataPlane):
51 def runTest(self):
52 delete_all_flows(self.controller)
53 delete_all_groups(self.controller)
54 ports = sorted(config["port_map"].keys())
55 # group table
56 # set up untag groups for each port
57 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 4093, False, 1)
58 #set up tagged groups
59 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 300, True, 1)
60 for port in ports:
61 add_one_vlan_table_flow(self.controller, port, 4093, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
62 group_id = encode_l2_interface_group_id(4093, port)
63 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 4093, group_id, True)
64 #add flow match for vlan 300
65 add_one_vlan_table_flow(self.controller, port, 300, flag=VLAN_TABLE_FLAG_ONLY_TAG)
66 group_id = encode_l2_interface_group_id(300, port)
67 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 300, group_id, True)
68 do_barrier(self.controller)
69
70 for out_port in ports:
71 # change dest based on port number
72 mac_dst= '00:12:34:56:78:%02X' % out_port
73
74 for in_port in ports:
75 if in_port == out_port:
76 continue
77 # change source based on port number to avoid packet-ins from learning
78 mac_src= '00:12:34:56:78:%02X' % in_port
79 parsed_pkt = simple_tcp_packet(dl_vlan_enable=False, vlan_vid=4093, eth_dst=mac_dst, eth_src=mac_src)
80 pkt = str(parsed_pkt)
81 logging.info("OutputExact test, ports %d to %d", in_port, out_port)
82 self.dataplane.send(in_port, pkt)
83
84 for ofport in ports:
85 if ofport in [out_port]:
86 verify_packet(self, pkt, ofport)
87 else:
88 verify_no_packet(self, pkt, ofport)
89
90 verify_no_other_packets(self)
91 mac_src= '00:12:34:56:78:%02X' % in_port
92 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=300, eth_dst=mac_dst, eth_src=mac_src)
93 pkt = str(parsed_pkt)
94 logging.info("OutputExact test, ports %d to %d", in_port, out_port)
95 self.dataplane.send(in_port, pkt)
96
97 for ofport in ports:
98 if ofport in [out_port]:
99 verify_packet(self, pkt, ofport)
100 else:
101 verify_no_packet(self, pkt, ofport)
102
103 verify_no_other_packets(self)
104
105class L2FloodQinQ(base_tests.SimpleDataPlane):
106 """
107 Test L2 flood to a vlan
108 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
109 #todo take in account unknown src
110 """
111 def runTest(self):
112 ports = sorted(config["port_map"].keys())
113
114 delete_all_flows(self.controller)
115 delete_all_groups(self.controller)
116
117 # Installing flows to avoid packet-in
118 for port in ports:
119 add_one_l2_interface_grouop(self.controller, port, 1, True, False)
120 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
121
122 group_id = encode_l2_interface_group_id(1, port)
123 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
124 msg=add_l2_flood_group(self.controller, ports, 1, 1)
125 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
126 do_barrier(self.controller)
127
128 #verify flood
129 for ofport in ports:
130 # change dest based on port number
131 mac_src= '00:12:34:56:78:%02X' % ofport
132 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108, out_dl_vlan_enable=True, out_vlan_vid=1,
133 in_dl_vlan_enable=True, in_vlan_vid=10, eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
134 pkt = str(parsed_pkt)
135 self.dataplane.send(ofport, pkt)
136 #self won't rx packet
137 verify_no_packet(self, pkt, ofport)
138 #others will rx packet
139 tmp_ports=list(ports)
140 tmp_ports.remove(ofport)
141 verify_packets(self, pkt, tmp_ports)
142
143 verify_no_other_packets(self)
144
145
Flavio Castro184cefe2015-11-19 20:52:49 -0500146class L2FloodTagged(base_tests.SimpleDataPlane):
147 """
148 Test L2 flood to a vlan
149 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
150 #todo take in account unknown src
151 """
152 def runTest(self):
153 ports = sorted(config["port_map"].keys())
Flavio Castro34352e72015-12-07 20:01:51 -0500154
Flavio Castro184cefe2015-11-19 20:52:49 -0500155 delete_all_flows(self.controller)
156 delete_all_groups(self.controller)
157
Flavio Castro184cefe2015-11-19 20:52:49 -0500158 # Installing flows to avoid packet-in
159 for port in ports:
Flavio Castro34352e72015-12-07 20:01:51 -0500160 add_one_l2_interface_grouop(self.controller, port, 1, True, False)
161 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
162
Flavio Castro184cefe2015-11-19 20:52:49 -0500163 group_id = encode_l2_interface_group_id(1, port)
164 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
Flavio Castro34352e72015-12-07 20:01:51 -0500165 msg=add_l2_flood_group(self.controller, ports, 1, 1)
166 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
Flavio Castro184cefe2015-11-19 20:52:49 -0500167 do_barrier(self.controller)
168
169 #verify flood
170 for ofport in ports:
171 # change dest based on port number
172 mac_src= '00:12:34:56:78:%02X' % ofport
173 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
174 pkt = str(parsed_pkt)
175 self.dataplane.send(ofport, pkt)
176 #self won't rx packet
177 verify_no_packet(self, pkt, ofport)
178 #others will rx packet
179 tmp_ports=list(ports)
180 tmp_ports.remove(ofport)
181 verify_packets(self, pkt, tmp_ports)
182
183 verify_no_other_packets(self)
184
Flavio Castroaabb5792015-11-18 19:03:50 -0500185class L2FloodTaggedUnknownSrc(base_tests.SimpleDataPlane):
186 """
187 Test L2 flood to a vlan
188 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
189 #todo take in account unknown src
190 """
191 def runTest(self):
Flavio Castroaabb5792015-11-18 19:03:50 -0500192 delete_all_flows(self.controller)
193 delete_all_groups(self.controller)
194
Flavio Castro34352e72015-12-07 20:01:51 -0500195 ports = sorted(config["port_map"].keys())
196 for port in ports:
197 add_one_l2_interface_grouop(self.controller, port, 1, True, False)
198 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castroaabb5792015-11-18 19:03:50 -0500199
200 msg=add_l2_flood_group(self.controller, ports, 1, 1)
201 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
202
203 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a')
204 pkt = str(parsed_pkt)
205 #verify flood
206 for ofport in ports:
207 self.dataplane.send(ofport, pkt)
208 #self won't rx packet
209 verify_no_packet(self, pkt, ofport)
210 #others will rx packet
211 tmp_ports=list(ports)
212 tmp_ports.remove(ofport)
213 verify_packets(self, pkt, tmp_ports)
214
215 verify_no_other_packets(self)
216
Flavio Castroaabb5792015-11-18 19:03:50 -0500217class L2UnicastTagged(base_tests.SimpleDataPlane):
218 """
219 Test output function for an exact-match flow
220
221 For each port A, adds a flow directing matching packets to that port.
222 Then, for all other ports B != A, verifies that sending a matching packet
223 to B results in an output to A.
224 """
225 def runTest(self):
226 ports = sorted(config["port_map"].keys())
227
228 delete_all_flows(self.controller)
229 delete_all_groups(self.controller)
230
Flavio Castroaabb5792015-11-18 19:03:50 -0500231 for port in ports:
Flavio Castro34352e72015-12-07 20:01:51 -0500232 add_one_l2_interface_grouop(self.controller, port, 1, True, False)
233 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castroaabb5792015-11-18 19:03:50 -0500234 group_id = encode_l2_interface_group_id(1, port)
235 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
Flavio Castro6efe1862015-11-18 16:28:06 -0500236 do_barrier(self.controller)
237
Flavio Castroaabb5792015-11-18 19:03:50 -0500238 for out_port in ports:
239 # change dest based on port number
240 mac_dst= '00:12:34:56:78:%02X' % out_port
241 for in_port in ports:
242 if in_port == out_port:
243 continue
244 # change source based on port number to avoid packet-ins from learning
245 mac_src= '00:12:34:56:78:%02X' % in_port
246 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
247 pkt = str(parsed_pkt)
248 self.dataplane.send(in_port, pkt)
249
250 for ofport in ports:
251 if ofport in [out_port]:
252 verify_packet(self, pkt, ofport)
253 else:
254 verify_no_packet(self, pkt, ofport)
255
256 verify_no_other_packets(self)
Flavio Castro6efe1862015-11-18 16:28:06 -0500257
258
Flavio Castrob6773032015-11-19 22:49:24 -0500259class Mtu4500(base_tests.SimpleDataPlane):
260
261 def runTest(self):
262 ports = sorted(config["port_map"].keys())
263
264 delete_all_flows(self.controller)
265 delete_all_groups(self.controller)
266
Flavio Castrob6773032015-11-19 22:49:24 -0500267 for port in ports:
Flavio Castro34352e72015-12-07 20:01:51 -0500268 add_one_l2_interface_grouop(self.controller, port, 1, True, False)
269 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrob6773032015-11-19 22:49:24 -0500270 group_id = encode_l2_interface_group_id(1, port)
271 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
272 do_barrier(self.controller)
273
274 for out_port in ports:
275 # change dest based on port number
276 mac_dst= '00:12:34:56:78:%02X' % out_port
277 for in_port in ports:
278 if in_port == out_port:
279 continue
280 # change source based on port number to avoid packet-ins from learning
281 mac_src= '00:12:34:56:78:%02X' % in_port
282 parsed_pkt = simple_tcp_packet(pktlen=4500,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
283 pkt = str(parsed_pkt)
284 self.dataplane.send(in_port, pkt)
285
286 for ofport in ports:
287 if ofport in [out_port]:
288 verify_packet(self, pkt, ofport)
289 else:
290 verify_no_packet(self, pkt, ofport)
291
292 verify_no_other_packets(self)
293
294
295class Mtu1500(base_tests.SimpleDataPlane):
296
297 def runTest(self):
298 ports = sorted(config["port_map"].keys())
299
300 delete_all_flows(self.controller)
301 delete_all_groups(self.controller)
302
Flavio Castro34352e72015-12-07 20:01:51 -0500303 # set up tag groups for each port
304 add_l2_interface_grouop(self.controller, ports, 1, True, 1)
Flavio Castrob6773032015-11-19 22:49:24 -0500305
Flavio Castro34352e72015-12-07 20:01:51 -0500306 add_vlan_table_flow(self.controller, ports)
Flavio Castrob6773032015-11-19 22:49:24 -0500307
308 for port in ports:
Flavio Castro34352e72015-12-07 20:01:51 -0500309 add_one_l2_interface_grouop(self.controller, port, 1, True, False)
310 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrob6773032015-11-19 22:49:24 -0500311 group_id = encode_l2_interface_group_id(1, port)
312 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
313 do_barrier(self.controller)
314
315 for out_port in ports:
316 # change dest based on port number
317 mac_dst= '00:12:34:56:78:%02X' % out_port
318 for in_port in ports:
319 if in_port == out_port:
320 continue
321 # change source based on port number to avoid packet-ins from learning
322 mac_src= '00:12:34:56:78:%02X' % in_port
323 parsed_pkt = simple_tcp_packet(pktlen=1500,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
324 pkt = str(parsed_pkt)
325 self.dataplane.send(in_port, pkt)
326
327 for ofport in ports:
328 if ofport in [out_port]:
329 verify_packet(self, pkt, ofport)
330 else:
331 verify_no_packet(self, pkt, ofport)
332
333 verify_no_other_packets(self)
334
335
336class Mtu4000(base_tests.SimpleDataPlane):
337 """
338 Test output function for an exact-match flow
339 For each port A, adds a flow directing matching packets to that port.
340 Then, for all other ports B != A, verifies that sending a matching packet
341 to B results in an output to A.
342 """
343 def runTest(self):
344 ports = sorted(config["port_map"].keys())
345
346 delete_all_flows(self.controller)
347 delete_all_groups(self.controller)
348
349 add_vlan_table_flow(self.controller, config["port_map"].keys())
350
351 # set up tag groups for each port
352 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1)
353
354 for port in ports:
Flavio Castro34352e72015-12-07 20:01:51 -0500355 add_one_l2_interface_grouop(self.controller, port, 1, True, False)
356 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrob6773032015-11-19 22:49:24 -0500357 group_id = encode_l2_interface_group_id(1, port)
358 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
359 do_barrier(self.controller)
360
361 for out_port in ports:
362 # change dest based on port number
363 mac_dst= '00:12:34:56:78:%02X' % out_port
364 for in_port in ports:
365 if in_port == out_port:
366 continue
367 # change source based on port number to avoid packet-ins from learning
368 mac_src= '00:12:34:56:78:%02X' % in_port
369 parsed_pkt = simple_tcp_packet(pktlen=4000,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
370 pkt = str(parsed_pkt)
371 self.dataplane.send(in_port, pkt)
372
373 for ofport in ports:
374 if ofport in [out_port]:
375 verify_packet(self, pkt, ofport)
376 else:
377 verify_no_packet(self, pkt, ofport)
378
379 verify_no_other_packets(self)
Flavio Castroaabb5792015-11-18 19:03:50 -0500380
381class L3UcastTagged(base_tests.SimpleDataPlane):
Flavio Castro05d20bc2015-11-16 15:06:14 -0500382 """
Flavio Castro35e64392015-12-02 16:53:14 -0500383 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
384 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500385 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500386 def runTest(self):
Flavio Castro05d20bc2015-11-16 15:06:14 -0500387 delete_all_flows(self.controller)
388 delete_all_groups(self.controller)
389
390 if len(config["port_map"]) <2:
391 logging.info("Port count less than 2, can't run this case")
392 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500393
Flavio Castro05d20bc2015-11-16 15:06:14 -0500394 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
395 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
396 dip=0xc0a80001
Flavio Castroa8233862015-12-02 14:41:11 -0500397 ports = config["port_map"].keys()
398 for port in ports:
Flavio Castro05d20bc2015-11-16 15:06:14 -0500399 #add l2 interface group
Flavio Castroa8233862015-12-02 14:41:11 -0500400 vlan_id=port
Flavio Castro05d20bc2015-11-16 15:06:14 -0500401 add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
402 dst_mac[5]=vlan_id
403 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
404 #add vlan flow table
Flavio Castro34352e72015-12-07 20:01:51 -0500405 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500406 #add termination flow
Flavio Castrod8f8af22015-12-02 18:19:26 -0500407 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500408 #add unicast routing flow
Flavio Castrod8f8af22015-12-02 18:19:26 -0500409 dst_ip = dip + (vlan_id<<8)
Flavio Castro6efe1862015-11-18 16:28:06 -0500410 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
Flavio Castro6efe1862015-11-18 16:28:06 -0500411 #add entries in the Bridging table to avoid packet-in from mac learning
412 group_id = encode_l2_interface_group_id(vlan_id, port)
413 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500414
415 do_barrier(self.controller)
416
Flavio Castro05d20bc2015-11-16 15:06:14 -0500417 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
Flavio Castroa8233862015-12-02 14:41:11 -0500418 for in_port in ports:
419 mac_src='00:00:00:22:22:%02X' % in_port
420 ip_src='192.168.%02d.1' % in_port
421 for out_port in ports:
422 if in_port == out_port:
423 continue
424 ip_dst='192.168.%02d.1' % out_port
425 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
426 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
Flavio Castrod8f8af22015-12-02 18:19:26 -0500427 ip_dst=ip_dst)
Flavio Castroa8233862015-12-02 14:41:11 -0500428 pkt=str(parsed_pkt)
429 self.dataplane.send(in_port, pkt)
Flavio Castro72a45d52015-12-02 16:37:05 -0500430 #build expected packet
Flavio Castroa8233862015-12-02 14:41:11 -0500431 mac_dst='00:00:00:22:22:%02X' % out_port
Flavio Castrod8f8af22015-12-02 18:19:26 -0500432 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
Flavio Castroa8233862015-12-02 14:41:11 -0500433 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
434 ip_src=ip_src, ip_dst=ip_dst)
435 pkt=str(exp_pkt)
436 verify_packet(self, pkt, out_port)
437 verify_no_other_packets(self)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500438
Flavio Castrod8f8af22015-12-02 18:19:26 -0500439class L3VPNMPLS(base_tests.SimpleDataPlane):
440 """
441 Insert IP packet
442 Receive MPLS packet
443 """
Flavio Castro72a45d52015-12-02 16:37:05 -0500444 def runTest(self):
445 delete_all_flows(self.controller)
446 delete_all_groups(self.controller)
447
448 if len(config["port_map"]) <2:
449 logging.info("Port count less than 2, can't run this case")
450 return
451
452 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
453 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
454 dip=0xc0a80001
455 index=1
456 ports = config["port_map"].keys()
457 for port in ports:
458 #add l2 interface group
459 vlan_id=port
Flavio Castro34352e72015-12-07 20:01:51 -0500460 l2_gid, l2_msg = add_one_l2_interface_grouop(self.controller, port, vlan_id, True, True)
Flavio Castro72a45d52015-12-02 16:37:05 -0500461 dst_mac[5]=vlan_id
Flavio Castro35e64392015-12-02 16:53:14 -0500462 #add MPLS interface group
Flavio Castro72a45d52015-12-02 16:37:05 -0500463 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 -0500464 #add MPLS L3 VPN group
Flavio Castrod8f8af22015-12-02 18:19:26 -0500465 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 -0500466 index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32)
467 #add vlan flow table
Flavio Castro34352e72015-12-07 20:01:51 -0500468 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 -0500469 #add termination flow
470 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
Flavio Castro35e64392015-12-02 16:53:14 -0500471 #add routing flow
Flavio Castro72a45d52015-12-02 16:37:05 -0500472 dst_ip = dip + (vlan_id<<8)
Flavio Castro34352e72015-12-07 20:01:51 -0500473 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
Flavio Castro72a45d52015-12-02 16:37:05 -0500474 #add entries in the Bridging table to avoid packet-in from mac learning
475 group_id = encode_l2_interface_group_id(vlan_id, port)
476 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
477
478 do_barrier(self.controller)
479
480 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
481 for in_port in ports:
482 mac_src='00:00:00:22:22:%02X' % in_port
483 ip_src='192.168.%02d.1' % in_port
484 for out_port in ports:
485 if in_port == out_port:
486 continue
487 ip_dst='192.168.%02d.1' % out_port
488 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
489 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
490 ip_dst=ip_dst)
491 pkt=str(parsed_pkt)
492 self.dataplane.send(in_port, pkt)
493 #build expect packet
494 mac_dst='00:00:00:22:22:%02X' % out_port
495 label = (out_port, 0, 1, 32)
Flavio Castro34352e72015-12-07 20:01:51 -0500496 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 -0500497 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
498 pkt=str(exp_pkt)
499 verify_packet(self, pkt, out_port)
500 verify_no_other_packets(self)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500501
502class MplsTermination(base_tests.SimpleDataPlane):
Flavio Castro34352e72015-12-07 20:01:51 -0500503 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500504 Insert IP packet
505 Receive MPLS packet
Flavio Castro34352e72015-12-07 20:01:51 -0500506 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500507 def runTest(self):
508 delete_all_flows(self.controller)
509 delete_all_groups(self.controller)
510
511 if len(config["port_map"]) <2:
512 logging.info("Port count less than 2, can't run this case")
513 return
514
515 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
516 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
517 dip=0xc0a80001
518 index=1
519 ports = config["port_map"].keys()
520 for port in ports:
521 #add l2 interface group
522 vlan_id=port
523 l2_gid, l2_msg = add_one_l2_interface_grouop(self.controller, port, vlan_id, True, False)
524 dst_mac[5]=vlan_id
525 #add L3 Unicast group
526 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 -0500527 #add L3 ecmp group
528 ecmp_msg = add_l3_ecmp_group(self.controller, port, [l3_msg.group_id])
Flavio Castrod8f8af22015-12-02 18:19:26 -0500529 #add vlan flow table
530 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
531 #add termination flow
Flavio Castro167f5bd2015-12-02 19:33:53 -0500532 add_termination_flow(self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500533 #add routing flow
534 dst_ip = dip + (vlan_id<<8)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500535 add_mpls_flow(self.controller, ecmp_msg.group_id, port)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500536 #add entries in the Bridging table to avoid packet-in from mac learning
537 group_id = encode_l2_interface_group_id(vlan_id, port)
538 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
539
540 do_barrier(self.controller)
541
542 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
543 for in_port in ports:
544 mac_src='00:00:00:22:22:%02X' % in_port
545 ip_src='192.168.%02d.1' % in_port
546 for out_port in ports:
547 if in_port == out_port:
548 continue
549 ip_dst='192.168.%02d.1' % out_port
Flavio Castro167f5bd2015-12-02 19:33:53 -0500550
551 label = (out_port, 0, 1, 32)
552 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src,
553 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[label])
Flavio Castrod8f8af22015-12-02 18:19:26 -0500554 pkt=str(parsed_pkt)
555 self.dataplane.send(in_port, pkt)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500556
Flavio Castrod8f8af22015-12-02 18:19:26 -0500557 #build expect packet
558 mac_dst='00:00:00:22:22:%02X' % out_port
Flavio Castro167f5bd2015-12-02 19:33:53 -0500559 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
560 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 -0500561 pkt=str(exp_pkt)
562 verify_packet(self, pkt, out_port)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500563 verify_no_other_packets(self)
564
Flavio Castro34352e72015-12-07 20:01:51 -0500565