blob: 3c26ef7ca219b6006cb15e9295506b43f1dab0fe [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
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:
castroflaviodd171472015-12-08 13:55:58 -050035 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -050036 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):
Flavio Castroc36621e2015-12-08 12:57:07 -050051 """
52 Test L2 forwarding of both, untagged and tagged packets
53 Sends a packet and expects the same packet on the other port
54 Repeats for tagged
55 """
Flavio Castro1b5c21d2015-12-08 12:41:56 -050056 def runTest(self):
57 delete_all_flows(self.controller)
58 delete_all_groups(self.controller)
59 ports = sorted(config["port_map"].keys())
60 # group table
61 # set up untag groups for each port
62 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 4093, False, 1)
63 #set up tagged groups
64 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 300, True, 1)
65 for port in ports:
66 add_one_vlan_table_flow(self.controller, port, 4093, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
67 group_id = encode_l2_interface_group_id(4093, port)
68 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 4093, group_id, True)
69 #add flow match for vlan 300
70 add_one_vlan_table_flow(self.controller, port, 300, flag=VLAN_TABLE_FLAG_ONLY_TAG)
71 group_id = encode_l2_interface_group_id(300, port)
72 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 300, group_id, True)
73 do_barrier(self.controller)
74
75 for out_port in ports:
76 # change dest based on port number
77 mac_dst= '00:12:34:56:78:%02X' % out_port
78
79 for in_port in ports:
80 if in_port == out_port:
81 continue
82 # change source based on port number to avoid packet-ins from learning
83 mac_src= '00:12:34:56:78:%02X' % in_port
Flavio Castroc36621e2015-12-08 12:57:07 -050084 #sends an untagged packet
Flavio Castro1b5c21d2015-12-08 12:41:56 -050085 parsed_pkt = simple_tcp_packet(dl_vlan_enable=False, vlan_vid=4093, eth_dst=mac_dst, eth_src=mac_src)
86 pkt = str(parsed_pkt)
87 logging.info("OutputExact test, ports %d to %d", in_port, out_port)
88 self.dataplane.send(in_port, pkt)
89
90 for ofport in ports:
91 if ofport in [out_port]:
92 verify_packet(self, pkt, ofport)
93 else:
94 verify_no_packet(self, pkt, ofport)
95
96 verify_no_other_packets(self)
Flavio Castroc36621e2015-12-08 12:57:07 -050097 # sends a tagged packet
Flavio Castro1b5c21d2015-12-08 12:41:56 -050098 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=300, eth_dst=mac_dst, eth_src=mac_src)
99 pkt = str(parsed_pkt)
100 logging.info("OutputExact test, ports %d to %d", in_port, out_port)
101 self.dataplane.send(in_port, pkt)
102
103 for ofport in ports:
104 if ofport in [out_port]:
105 verify_packet(self, pkt, ofport)
106 else:
107 verify_no_packet(self, pkt, ofport)
108
109 verify_no_other_packets(self)
110
111class L2FloodQinQ(base_tests.SimpleDataPlane):
112 """
Flavio Castroc36621e2015-12-08 12:57:07 -0500113 Test L2 flood of double tagged vlan packets (802.1Q)
114 Sends a double tagged packet and verifies flooding behavior according to outer vlan
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500115 """
116 def runTest(self):
117 ports = sorted(config["port_map"].keys())
118
119 delete_all_flows(self.controller)
120 delete_all_groups(self.controller)
121
122 # Installing flows to avoid packet-in
123 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500124 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500125 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
126
127 group_id = encode_l2_interface_group_id(1, port)
128 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
129 msg=add_l2_flood_group(self.controller, ports, 1, 1)
130 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
131 do_barrier(self.controller)
132
133 #verify flood
134 for ofport in ports:
135 # change dest based on port number
136 mac_src= '00:12:34:56:78:%02X' % ofport
137 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108, out_dl_vlan_enable=True, out_vlan_vid=1,
138 in_dl_vlan_enable=True, in_vlan_vid=10, eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
139 pkt = str(parsed_pkt)
140 self.dataplane.send(ofport, pkt)
141 #self won't rx packet
142 verify_no_packet(self, pkt, ofport)
143 #others will rx packet
144 tmp_ports=list(ports)
145 tmp_ports.remove(ofport)
146 verify_packets(self, pkt, tmp_ports)
147
148 verify_no_other_packets(self)
149
150
Flavio Castro184cefe2015-11-19 20:52:49 -0500151class L2FloodTagged(base_tests.SimpleDataPlane):
152 """
153 Test L2 flood to a vlan
154 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
155 #todo take in account unknown src
156 """
157 def runTest(self):
158 ports = sorted(config["port_map"].keys())
Flavio Castro34352e72015-12-07 20:01:51 -0500159
Flavio Castro184cefe2015-11-19 20:52:49 -0500160 delete_all_flows(self.controller)
161 delete_all_groups(self.controller)
162
Flavio Castro184cefe2015-11-19 20:52:49 -0500163 # Installing flows to avoid packet-in
164 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500165 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500166 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
167
Flavio Castro184cefe2015-11-19 20:52:49 -0500168 group_id = encode_l2_interface_group_id(1, port)
169 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
Flavio Castro34352e72015-12-07 20:01:51 -0500170 msg=add_l2_flood_group(self.controller, ports, 1, 1)
171 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
Flavio Castro184cefe2015-11-19 20:52:49 -0500172 do_barrier(self.controller)
173
174 #verify flood
175 for ofport in ports:
176 # change dest based on port number
177 mac_src= '00:12:34:56:78:%02X' % ofport
178 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
179 pkt = str(parsed_pkt)
180 self.dataplane.send(ofport, pkt)
181 #self won't rx packet
182 verify_no_packet(self, pkt, ofport)
183 #others will rx packet
184 tmp_ports=list(ports)
185 tmp_ports.remove(ofport)
186 verify_packets(self, pkt, tmp_ports)
187
188 verify_no_other_packets(self)
189
Flavio Castroaabb5792015-11-18 19:03:50 -0500190class L2FloodTaggedUnknownSrc(base_tests.SimpleDataPlane):
191 """
192 Test L2 flood to a vlan
193 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
194 #todo take in account unknown src
195 """
196 def runTest(self):
Flavio Castroaabb5792015-11-18 19:03:50 -0500197 delete_all_flows(self.controller)
198 delete_all_groups(self.controller)
199
Flavio Castro34352e72015-12-07 20:01:51 -0500200 ports = sorted(config["port_map"].keys())
201 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500202 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500203 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castroaabb5792015-11-18 19:03:50 -0500204
205 msg=add_l2_flood_group(self.controller, ports, 1, 1)
206 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
207
208 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a')
209 pkt = str(parsed_pkt)
210 #verify flood
211 for ofport in ports:
212 self.dataplane.send(ofport, pkt)
213 #self won't rx packet
214 verify_no_packet(self, pkt, ofport)
215 #others will rx packet
216 tmp_ports=list(ports)
217 tmp_ports.remove(ofport)
218 verify_packets(self, pkt, tmp_ports)
219
220 verify_no_other_packets(self)
221
Flavio Castroaabb5792015-11-18 19:03:50 -0500222class L2UnicastTagged(base_tests.SimpleDataPlane):
223 """
224 Test output function for an exact-match flow
225
226 For each port A, adds a flow directing matching packets to that port.
227 Then, for all other ports B != A, verifies that sending a matching packet
228 to B results in an output to A.
229 """
230 def runTest(self):
231 ports = sorted(config["port_map"].keys())
232
233 delete_all_flows(self.controller)
234 delete_all_groups(self.controller)
235
Flavio Castroaabb5792015-11-18 19:03:50 -0500236 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500237 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500238 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castroaabb5792015-11-18 19:03:50 -0500239 group_id = encode_l2_interface_group_id(1, port)
240 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
Flavio Castro6efe1862015-11-18 16:28:06 -0500241 do_barrier(self.controller)
242
Flavio Castroaabb5792015-11-18 19:03:50 -0500243 for out_port in ports:
244 # change dest based on port number
245 mac_dst= '00:12:34:56:78:%02X' % out_port
246 for in_port in ports:
247 if in_port == out_port:
248 continue
249 # change source based on port number to avoid packet-ins from learning
250 mac_src= '00:12:34:56:78:%02X' % in_port
251 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
252 pkt = str(parsed_pkt)
253 self.dataplane.send(in_port, pkt)
254
255 for ofport in ports:
256 if ofport in [out_port]:
257 verify_packet(self, pkt, ofport)
258 else:
259 verify_no_packet(self, pkt, ofport)
260
261 verify_no_other_packets(self)
Flavio Castro6efe1862015-11-18 16:28:06 -0500262
263
Flavio Castrob6773032015-11-19 22:49:24 -0500264class Mtu4500(base_tests.SimpleDataPlane):
265
266 def runTest(self):
267 ports = sorted(config["port_map"].keys())
268
269 delete_all_flows(self.controller)
270 delete_all_groups(self.controller)
271
Flavio Castrob6773032015-11-19 22:49:24 -0500272 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500273 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500274 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrob6773032015-11-19 22:49:24 -0500275 group_id = encode_l2_interface_group_id(1, port)
276 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
277 do_barrier(self.controller)
278
279 for out_port in ports:
280 # change dest based on port number
281 mac_dst= '00:12:34:56:78:%02X' % out_port
282 for in_port in ports:
283 if in_port == out_port:
284 continue
285 # change source based on port number to avoid packet-ins from learning
286 mac_src= '00:12:34:56:78:%02X' % in_port
287 parsed_pkt = simple_tcp_packet(pktlen=4500,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
288 pkt = str(parsed_pkt)
289 self.dataplane.send(in_port, pkt)
290
291 for ofport in ports:
292 if ofport in [out_port]:
293 verify_packet(self, pkt, ofport)
294 else:
295 verify_no_packet(self, pkt, ofport)
296
297 verify_no_other_packets(self)
298
299
300class Mtu1500(base_tests.SimpleDataPlane):
301
302 def runTest(self):
303 ports = sorted(config["port_map"].keys())
304
305 delete_all_flows(self.controller)
306 delete_all_groups(self.controller)
307
Flavio Castro34352e72015-12-07 20:01:51 -0500308 # set up tag groups for each port
309 add_l2_interface_grouop(self.controller, ports, 1, True, 1)
Flavio Castrob6773032015-11-19 22:49:24 -0500310
Flavio Castro34352e72015-12-07 20:01:51 -0500311 add_vlan_table_flow(self.controller, ports)
Flavio Castrob6773032015-11-19 22:49:24 -0500312
313 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500314 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500315 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrob6773032015-11-19 22:49:24 -0500316 group_id = encode_l2_interface_group_id(1, port)
317 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
318 do_barrier(self.controller)
319
320 for out_port in ports:
321 # change dest based on port number
322 mac_dst= '00:12:34:56:78:%02X' % out_port
323 for in_port in ports:
324 if in_port == out_port:
325 continue
326 # change source based on port number to avoid packet-ins from learning
327 mac_src= '00:12:34:56:78:%02X' % in_port
328 parsed_pkt = simple_tcp_packet(pktlen=1500,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
329 pkt = str(parsed_pkt)
330 self.dataplane.send(in_port, pkt)
331
332 for ofport in ports:
333 if ofport in [out_port]:
334 verify_packet(self, pkt, ofport)
335 else:
336 verify_no_packet(self, pkt, ofport)
337
338 verify_no_other_packets(self)
339
340
341class Mtu4000(base_tests.SimpleDataPlane):
342 """
343 Test output function for an exact-match flow
344 For each port A, adds a flow directing matching packets to that port.
345 Then, for all other ports B != A, verifies that sending a matching packet
346 to B results in an output to A.
347 """
348 def runTest(self):
349 ports = sorted(config["port_map"].keys())
350
351 delete_all_flows(self.controller)
352 delete_all_groups(self.controller)
353
354 add_vlan_table_flow(self.controller, config["port_map"].keys())
355
356 # set up tag groups for each port
357 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1)
358
359 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500360 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro34352e72015-12-07 20:01:51 -0500361 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castrob6773032015-11-19 22:49:24 -0500362 group_id = encode_l2_interface_group_id(1, port)
363 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
364 do_barrier(self.controller)
365
366 for out_port in ports:
367 # change dest based on port number
368 mac_dst= '00:12:34:56:78:%02X' % out_port
369 for in_port in ports:
370 if in_port == out_port:
371 continue
372 # change source based on port number to avoid packet-ins from learning
373 mac_src= '00:12:34:56:78:%02X' % in_port
374 parsed_pkt = simple_tcp_packet(pktlen=4000,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
375 pkt = str(parsed_pkt)
376 self.dataplane.send(in_port, pkt)
377
378 for ofport in ports:
379 if ofport in [out_port]:
380 verify_packet(self, pkt, ofport)
381 else:
382 verify_no_packet(self, pkt, ofport)
383
384 verify_no_other_packets(self)
Flavio Castroaabb5792015-11-18 19:03:50 -0500385
386class L3UcastTagged(base_tests.SimpleDataPlane):
Flavio Castro05d20bc2015-11-16 15:06:14 -0500387 """
Flavio Castro35e64392015-12-02 16:53:14 -0500388 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
389 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500390 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500391 def runTest(self):
Flavio Castro05d20bc2015-11-16 15:06:14 -0500392 delete_all_flows(self.controller)
393 delete_all_groups(self.controller)
394
395 if len(config["port_map"]) <2:
396 logging.info("Port count less than 2, can't run this case")
397 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500398
Flavio Castro05d20bc2015-11-16 15:06:14 -0500399 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
400 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
401 dip=0xc0a80001
Flavio Castroa8233862015-12-02 14:41:11 -0500402 ports = config["port_map"].keys()
403 for port in ports:
Flavio Castro05d20bc2015-11-16 15:06:14 -0500404 #add l2 interface group
Flavio Castroa8233862015-12-02 14:41:11 -0500405 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500406 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 -0500407 dst_mac[5]=vlan_id
408 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
409 #add vlan flow table
Flavio Castro34352e72015-12-07 20:01:51 -0500410 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500411 #add termination flow
Flavio Castrod8f8af22015-12-02 18:19:26 -0500412 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500413 #add unicast routing flow
Flavio Castrod8f8af22015-12-02 18:19:26 -0500414 dst_ip = dip + (vlan_id<<8)
Flavio Castro6efe1862015-11-18 16:28:06 -0500415 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
Flavio Castro6efe1862015-11-18 16:28:06 -0500416 #add entries in the Bridging table to avoid packet-in from mac learning
417 group_id = encode_l2_interface_group_id(vlan_id, port)
418 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500419
420 do_barrier(self.controller)
421
Flavio Castro05d20bc2015-11-16 15:06:14 -0500422 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
Flavio Castroa8233862015-12-02 14:41:11 -0500423 for in_port in ports:
424 mac_src='00:00:00:22:22:%02X' % in_port
425 ip_src='192.168.%02d.1' % in_port
426 for out_port in ports:
427 if in_port == out_port:
428 continue
429 ip_dst='192.168.%02d.1' % out_port
430 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
431 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
Flavio Castrod8f8af22015-12-02 18:19:26 -0500432 ip_dst=ip_dst)
Flavio Castroa8233862015-12-02 14:41:11 -0500433 pkt=str(parsed_pkt)
434 self.dataplane.send(in_port, pkt)
Flavio Castro72a45d52015-12-02 16:37:05 -0500435 #build expected packet
Flavio Castroa8233862015-12-02 14:41:11 -0500436 mac_dst='00:00:00:22:22:%02X' % out_port
Flavio Castrod8f8af22015-12-02 18:19:26 -0500437 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
Flavio Castroa8233862015-12-02 14:41:11 -0500438 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
439 ip_src=ip_src, ip_dst=ip_dst)
440 pkt=str(exp_pkt)
441 verify_packet(self, pkt, out_port)
442 verify_no_other_packets(self)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500443
Flavio Castrod8f8af22015-12-02 18:19:26 -0500444class L3VPNMPLS(base_tests.SimpleDataPlane):
445 """
446 Insert IP packet
447 Receive MPLS packet
448 """
Flavio Castro72a45d52015-12-02 16:37:05 -0500449 def runTest(self):
450 delete_all_flows(self.controller)
451 delete_all_groups(self.controller)
452
453 if len(config["port_map"]) <2:
454 logging.info("Port count less than 2, can't run this case")
455 return
456
457 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
458 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
459 dip=0xc0a80001
460 index=1
461 ports = config["port_map"].keys()
462 for port in ports:
463 #add l2 interface group
464 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500465 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
Flavio Castro72a45d52015-12-02 16:37:05 -0500466 dst_mac[5]=vlan_id
Flavio Castro35e64392015-12-02 16:53:14 -0500467 #add MPLS interface group
Flavio Castro72a45d52015-12-02 16:37:05 -0500468 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 -0500469 #add MPLS L3 VPN group
Flavio Castrod8f8af22015-12-02 18:19:26 -0500470 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 -0500471 index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32)
472 #add vlan flow table
Flavio Castro34352e72015-12-07 20:01:51 -0500473 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 -0500474 #add termination flow
475 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
Flavio Castro35e64392015-12-02 16:53:14 -0500476 #add routing flow
Flavio Castro72a45d52015-12-02 16:37:05 -0500477 dst_ip = dip + (vlan_id<<8)
Flavio Castro34352e72015-12-07 20:01:51 -0500478 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
Flavio Castro72a45d52015-12-02 16:37:05 -0500479 #add entries in the Bridging table to avoid packet-in from mac learning
480 group_id = encode_l2_interface_group_id(vlan_id, port)
481 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
482
483 do_barrier(self.controller)
484
485 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
486 for in_port in ports:
487 mac_src='00:00:00:22:22:%02X' % in_port
488 ip_src='192.168.%02d.1' % in_port
489 for out_port in ports:
490 if in_port == out_port:
491 continue
492 ip_dst='192.168.%02d.1' % out_port
493 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
494 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
495 ip_dst=ip_dst)
496 pkt=str(parsed_pkt)
497 self.dataplane.send(in_port, pkt)
498 #build expect packet
499 mac_dst='00:00:00:22:22:%02X' % out_port
500 label = (out_port, 0, 1, 32)
Flavio Castro34352e72015-12-07 20:01:51 -0500501 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 -0500502 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
503 pkt=str(exp_pkt)
504 verify_packet(self, pkt, out_port)
505 verify_no_other_packets(self)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500506
507class MplsTermination(base_tests.SimpleDataPlane):
Flavio Castro34352e72015-12-07 20:01:51 -0500508 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500509 Insert IP packet
510 Receive MPLS packet
Flavio Castro34352e72015-12-07 20:01:51 -0500511 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500512 def runTest(self):
513 delete_all_flows(self.controller)
514 delete_all_groups(self.controller)
515
516 if len(config["port_map"]) <2:
517 logging.info("Port count less than 2, can't run this case")
518 return
519
520 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
521 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
522 dip=0xc0a80001
523 index=1
524 ports = config["port_map"].keys()
525 for port in ports:
526 #add l2 interface group
527 vlan_id=port
castroflaviodd171472015-12-08 13:55:58 -0500528 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, False)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500529 dst_mac[5]=vlan_id
530 #add L3 Unicast group
531 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 -0500532 #add L3 ecmp group
533 ecmp_msg = add_l3_ecmp_group(self.controller, port, [l3_msg.group_id])
Flavio Castrod8f8af22015-12-02 18:19:26 -0500534 #add vlan flow table
535 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
536 #add termination flow
Flavio Castro167f5bd2015-12-02 19:33:53 -0500537 add_termination_flow(self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500538 #add routing flow
539 dst_ip = dip + (vlan_id<<8)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500540 add_mpls_flow(self.controller, ecmp_msg.group_id, port)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500541 #add entries in the Bridging table to avoid packet-in from mac learning
542 group_id = encode_l2_interface_group_id(vlan_id, port)
543 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
544
545 do_barrier(self.controller)
546
547 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
548 for in_port in ports:
549 mac_src='00:00:00:22:22:%02X' % in_port
550 ip_src='192.168.%02d.1' % in_port
551 for out_port in ports:
552 if in_port == out_port:
553 continue
554 ip_dst='192.168.%02d.1' % out_port
Flavio Castro167f5bd2015-12-02 19:33:53 -0500555
556 label = (out_port, 0, 1, 32)
557 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src,
558 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[label])
Flavio Castrod8f8af22015-12-02 18:19:26 -0500559 pkt=str(parsed_pkt)
560 self.dataplane.send(in_port, pkt)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500561
Flavio Castrod8f8af22015-12-02 18:19:26 -0500562 #build expect packet
563 mac_dst='00:00:00:22:22:%02X' % out_port
Flavio Castro167f5bd2015-12-02 19:33:53 -0500564 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
565 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 -0500566 pkt=str(exp_pkt)
567 verify_packet(self, pkt, out_port)
Flavio Castro167f5bd2015-12-02 19:33:53 -0500568 verify_no_other_packets(self)
569
Flavio Castro34352e72015-12-07 20:01:51 -0500570