blob: 9278d0a4fa45a353e0052bb339eed31c9cdb4cef [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 Castro67d8bd52016-02-03 14:22:14 -050018import inspect
Flavio Castro167f5bd2015-12-02 19:33:53 -050019import logging
20import oftest.base_tests as base_tests
Flavio Castro05d20bc2015-11-16 15:06:14 -050021import ofp
22from oftest.testutils import *
23from accton_util import *
Flavio Castrod8f8af22015-12-02 18:19:26 -050024
Flavio Castro7fb6ca92015-12-16 15:50:14 -050025class PacketInUDP(base_tests.SimpleDataPlane):
Flavio Castro6d498522015-12-15 14:05:04 -050026 """
27 Test packet in function for a table-miss flow
28 Send a packet to each dataplane port and verify that a packet
29 in message is received from the controller for each
30
31 NOTE: Verify This case the oft option shall not use --switch-ip
32 """
33
34 def runTest(self):
35 delete_all_flows(self.controller)
36 delete_all_groups(self.controller)
37
38 parsed_vlan_pkt = simple_udp_packet(pktlen=104,
39 vlan_vid=0x1001, dl_vlan_enable=True)
40 vlan_pkt = str(parsed_vlan_pkt)
Flavio Castro6d498522015-12-15 14:05:04 -050041 # create match
42 match = ofp.match()
43 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
castroflavio4a09c962016-01-05 13:13:41 -080044 match.oxm_list.append(ofp.oxm.ip_proto(17))
Flavio Castro6d498522015-12-15 14:05:04 -050045 request = ofp.message.flow_add(
46 table_id=60,
47 cookie=42,
48 match=match,
49 instructions=[
50 ofp.instruction.apply_actions(
51 actions=[
52 ofp.action.output(
53 port=ofp.OFPP_CONTROLLER,
Flavio Castro89933f22016-02-03 15:53:16 -050054 max_len=ofp.OFPCML_NO_BUFFER)]), ],
Flavio Castro6d498522015-12-15 14:05:04 -050055 buffer_id=ofp.OFP_NO_BUFFER,
56 priority=1)
57
58 logging.info("Inserting packet in flow to controller")
59 self.controller.message_send(request)
60 do_barrier(self.controller)
61
62 for of_port in config["port_map"].keys():
63 logging.info("PacketInMiss test, port %d", of_port)
64 self.dataplane.send(of_port, vlan_pkt)
65
66 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
67
68 verify_no_other_packets(self)
Flavio Castroaf2b4502016-02-02 17:41:32 -050069
Flavio Castroaf2b4502016-02-02 17:41:32 -050070
Flavio Castro67d8bd52016-02-03 14:22:14 -050071@disabled
Flavio Castro7fb6ca92015-12-16 15:50:14 -050072class ArpNL2(base_tests.SimpleDataPlane):
73 def runTest(self):
74 delete_all_flows(self.controller)
75 delete_all_groups(self.controller)
76
77 ports = sorted(config["port_map"].keys())
78 match = ofp.match()
79 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
80 request = ofp.message.flow_add(
81 table_id=60,
82 cookie=42,
83 match=match,
84 instructions=[
85 ofp.instruction.apply_actions(
86 actions=[
87 ofp.action.output(
88 port=ofp.OFPP_CONTROLLER,
89 max_len=ofp.OFPCML_NO_BUFFER)]),
90 ],
91 buffer_id=ofp.OFP_NO_BUFFER,
92 priority=40000)
93 self.controller.message_send(request)
94 for port in ports:
Flavio Castro932014b2016-01-05 18:29:15 -050095 add_one_l2_interface_group(self.controller, port, 1, False, False)
Flavio Castro7fb6ca92015-12-16 15:50:14 -050096 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
97 group_id = encode_l2_interface_group_id(1, port)
98 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
99 do_barrier(self.controller)
100 parsed_arp_pkt = simple_arp_packet()
101 arp_pkt = str(parsed_arp_pkt)
102
103 for out_port in ports:
104 self.dataplane.send(out_port, arp_pkt)
105 verify_packet_in(self, arp_pkt, out_port, ofp.OFPR_ACTION)
106 # change dest based on port number
107 mac_dst= '00:12:34:56:78:%02X' % out_port
108 for in_port in ports:
109 if in_port == out_port:
110 continue
111 # change source based on port number to avoid packet-ins from learning
112 mac_src= '00:12:34:56:78:%02X' % in_port
113 parsed_pkt = simple_tcp_packet(eth_dst=mac_dst, eth_src=mac_src)
114 pkt = str(parsed_pkt)
115 self.dataplane.send(in_port, pkt)
116
117 for ofport in ports:
118 if ofport in [out_port]:
119 verify_packet(self, pkt, ofport)
120 else:
121 verify_no_packet(self, pkt, ofport)
122
123 verify_no_other_packets(self)
124
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500125class PacketInArp(base_tests.SimpleDataPlane):
126 """
127 Test packet in function for a table-miss flow
128 Send a packet to each dataplane port and verify that a packet
129 in message is received from the controller for each
130
131 NOTE: Verify This case the oft option shall not use --switch-ip
132 """
133
134 def runTest(self):
135 delete_all_flows(self.controller)
136 delete_all_groups(self.controller)
137
138 parsed_arp_pkt = simple_arp_packet()
139 arp_pkt = str(parsed_arp_pkt)
140 ports = sorted(config["port_map"].keys())
141 #for port in ports:
142 # add_one_l2_interface_group(self.controller, port, 1, True, False)
143 # add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
144
145 # create match
146 match = ofp.match()
147 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
148 request = ofp.message.flow_add(
149 table_id=60,
150 cookie=42,
151 match=match,
152 instructions=[
153 ofp.instruction.apply_actions(
154 actions=[
155 ofp.action.output(
156 port=ofp.OFPP_CONTROLLER,
157 max_len=ofp.OFPCML_NO_BUFFER)]),
158 ],
159 buffer_id=ofp.OFP_NO_BUFFER,
160 priority=1)
161
162 logging.info("Inserting packet in flow to controller")
163 self.controller.message_send(request)
164 do_barrier(self.controller)
165
166 for of_port in config["port_map"].keys():
167 logging.info("PacketInMiss test, port %d", of_port)
168 self.dataplane.send(of_port, arp_pkt)
169
170 verify_packet_in(self, arp_pkt, of_port, ofp.OFPR_ACTION)
171
172 verify_no_other_packets(self)
173
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500174class L2FloodQinQ(base_tests.SimpleDataPlane):
175 """
Flavio Castroc36621e2015-12-08 12:57:07 -0500176 Test L2 flood of double tagged vlan packets (802.1Q)
177 Sends a double tagged packet and verifies flooding behavior according to outer vlan
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500178 """
179 def runTest(self):
180 ports = sorted(config["port_map"].keys())
181
182 delete_all_flows(self.controller)
183 delete_all_groups(self.controller)
184
185 # Installing flows to avoid packet-in
186 for port in ports:
castroflaviodd171472015-12-08 13:55:58 -0500187 add_one_l2_interface_group(self.controller, port, 1, True, False)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500188 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
189
190 group_id = encode_l2_interface_group_id(1, port)
191 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
192 msg=add_l2_flood_group(self.controller, ports, 1, 1)
193 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
194 do_barrier(self.controller)
195
196 #verify flood
197 for ofport in ports:
198 # change dest based on port number
199 mac_src= '00:12:34:56:78:%02X' % ofport
200 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108, out_dl_vlan_enable=True, out_vlan_vid=1,
201 in_dl_vlan_enable=True, in_vlan_vid=10, eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
202 pkt = str(parsed_pkt)
203 self.dataplane.send(ofport, pkt)
204 #self won't rx packet
205 verify_no_packet(self, pkt, ofport)
206 #others will rx packet
207 tmp_ports=list(ports)
208 tmp_ports.remove(ofport)
209 verify_packets(self, pkt, tmp_ports)
210
211 verify_no_other_packets(self)
212
Flavio Castro184cefe2015-11-19 20:52:49 -0500213class L2FloodTagged(base_tests.SimpleDataPlane):
214 """
215 Test L2 flood to a vlan
216 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
Flavio Castro184cefe2015-11-19 20:52:49 -0500217 """
218 def runTest(self):
Flavio Castroaba28ff2016-02-03 16:47:48 -0500219 #Hashes Test Name and uses it as id for installing unique groups
220 vlan_id=abs(hash(inspect.stack()[0][3])) % (256)
221
Flavio Castro184cefe2015-11-19 20:52:49 -0500222 ports = sorted(config["port_map"].keys())
Flavio Castro34352e72015-12-07 20:01:51 -0500223
Flavio Castro184cefe2015-11-19 20:52:49 -0500224 delete_all_flows(self.controller)
225 delete_all_groups(self.controller)
226
Flavio Castro184cefe2015-11-19 20:52:49 -0500227 # Installing flows to avoid packet-in
228 for port in ports:
Flavio Castroaba28ff2016-02-03 16:47:48 -0500229 add_one_l2_interface_group(self.controller, port, vlan_id, True, False)
230 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
231 msg=add_l2_flood_group(self.controller, ports, vlan_id, 1)
232 add_bridge_flow(self.controller, None, vlan_id, msg.group_id, True)
Flavio Castro184cefe2015-11-19 20:52:49 -0500233 do_barrier(self.controller)
234
235 #verify flood
236 for ofport in ports:
237 # change dest based on port number
Flavio Castroaba28ff2016-02-03 16:47:48 -0500238 pkt = str( simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, eth_dst='00:12:34:56:78:9a') )
Flavio Castro184cefe2015-11-19 20:52:49 -0500239 self.dataplane.send(ofport, pkt)
240 #self won't rx packet
241 verify_no_packet(self, pkt, ofport)
242 #others will rx packet
243 tmp_ports=list(ports)
244 tmp_ports.remove(ofport)
245 verify_packets(self, pkt, tmp_ports)
Flavio Castro184cefe2015-11-19 20:52:49 -0500246 verify_no_other_packets(self)
Flavio Castroaabb5792015-11-18 19:03:50 -0500247
Flavio Castroaabb5792015-11-18 19:03:50 -0500248class L2UnicastTagged(base_tests.SimpleDataPlane):
249 """
250 Test output function for an exact-match flow
251
252 For each port A, adds a flow directing matching packets to that port.
253 Then, for all other ports B != A, verifies that sending a matching packet
254 to B results in an output to A.
255 """
256 def runTest(self):
257 ports = sorted(config["port_map"].keys())
Flavio Castroaba28ff2016-02-03 16:47:48 -0500258 #Hashes Test Name and uses it as id for installing unique groups
259 vlan_id=abs(hash(inspect.stack()[0][3])) % (256)
Flavio Castroaabb5792015-11-18 19:03:50 -0500260 delete_all_flows(self.controller)
261 delete_all_groups(self.controller)
262
Flavio Castroaabb5792015-11-18 19:03:50 -0500263 for port in ports:
Flavio Castroaba28ff2016-02-03 16:47:48 -0500264 add_one_l2_interface_group(self.controller, port, vlan_id, True, False)
265 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
266 group_id = encode_l2_interface_group_id(vlan_id, port)
267 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], vlan_id, group_id, True)
Flavio Castro6efe1862015-11-18 16:28:06 -0500268 do_barrier(self.controller)
269
Flavio Castroaabb5792015-11-18 19:03:50 -0500270 for out_port in ports:
271 # change dest based on port number
272 mac_dst= '00:12:34:56:78:%02X' % out_port
273 for in_port in ports:
274 if in_port == out_port:
275 continue
Flavio Castroaba28ff2016-02-03 16:47:48 -0500276 pkt = str( simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vlan_id, eth_dst=mac_dst))
Flavio Castroaabb5792015-11-18 19:03:50 -0500277 self.dataplane.send(in_port, pkt)
Flavio Castroaabb5792015-11-18 19:03:50 -0500278 for ofport in ports:
279 if ofport in [out_port]:
280 verify_packet(self, pkt, ofport)
281 else:
282 verify_no_packet(self, pkt, ofport)
Flavio Castroaabb5792015-11-18 19:03:50 -0500283 verify_no_other_packets(self)
Flavio Castro6efe1862015-11-18 16:28:06 -0500284
Flavio Castrob6773032015-11-19 22:49:24 -0500285class Mtu1500(base_tests.SimpleDataPlane):
286
287 def runTest(self):
288 ports = sorted(config["port_map"].keys())
Flavio Castroaba28ff2016-02-03 16:47:48 -0500289 #Hashes Test Name and uses it as id for installing unique groups
290 vlan_id=abs(hash(inspect.stack()[0][3])) % (256)
Flavio Castrob6773032015-11-19 22:49:24 -0500291 delete_all_flows(self.controller)
292 delete_all_groups(self.controller)
293
Flavio Castrob6773032015-11-19 22:49:24 -0500294 for port in ports:
Flavio Castroaba28ff2016-02-03 16:47:48 -0500295 add_one_l2_interface_group(self.controller, port, vlan_id, True, False)
296 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
297 group_id = encode_l2_interface_group_id(vlan_id, port)
298 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], vlan_id, group_id, True)
Flavio Castrob6773032015-11-19 22:49:24 -0500299 do_barrier(self.controller)
300
301 for out_port in ports:
302 # change dest based on port number
303 mac_dst= '00:12:34:56:78:%02X' % out_port
304 for in_port in ports:
305 if in_port == out_port:
306 continue
Flavio Castroaba28ff2016-02-03 16:47:48 -0500307 pkt = str(simple_tcp_packet(pktlen=1500,dl_vlan_enable=True, vlan_vid=vlan_id, eth_dst=mac_dst))
Flavio Castrob6773032015-11-19 22:49:24 -0500308 self.dataplane.send(in_port, pkt)
Flavio Castrob6773032015-11-19 22:49:24 -0500309 for ofport in ports:
310 if ofport in [out_port]:
311 verify_packet(self, pkt, ofport)
312 else:
313 verify_no_packet(self, pkt, ofport)
Flavio Castrob6773032015-11-19 22:49:24 -0500314 verify_no_other_packets(self)
315
Flavio Castroaabb5792015-11-18 19:03:50 -0500316class L3UcastTagged(base_tests.SimpleDataPlane):
Flavio Castro05d20bc2015-11-16 15:06:14 -0500317 """
Flavio Castro35e64392015-12-02 16:53:14 -0500318 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
319 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500320 """
Flavio Castrod8f8af22015-12-02 18:19:26 -0500321 def runTest(self):
Flavio Castro05d20bc2015-11-16 15:06:14 -0500322 delete_all_flows(self.controller)
323 delete_all_groups(self.controller)
Flavio Castroaba28ff2016-02-03 16:47:48 -0500324 #Hashes Test Name and uses it as id for installing unique groups
325 class_id=abs(hash(inspect.stack()[0][3])) % (256)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500326 if len(config["port_map"]) <2:
327 logging.info("Port count less than 2, can't run this case")
328 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500329
Flavio Castro05d20bc2015-11-16 15:06:14 -0500330 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
331 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
332 dip=0xc0a80001
Flavio Castroa8233862015-12-02 14:41:11 -0500333 ports = config["port_map"].keys()
334 for port in ports:
Flavio Castro05d20bc2015-11-16 15:06:14 -0500335 #add l2 interface group
Flavio Castroaba28ff2016-02-03 16:47:48 -0500336 vlan_id=port+class_id
castroflaviodd171472015-12-08 13:55:58 -0500337 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 -0500338 dst_mac[5]=vlan_id
339 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
340 #add vlan flow table
Flavio Castro34352e72015-12-07 20:01:51 -0500341 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500342 #add termination flow
Flavio Castrod8f8af22015-12-02 18:19:26 -0500343 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500344 #add unicast routing flow
Flavio Castrod8f8af22015-12-02 18:19:26 -0500345 dst_ip = dip + (vlan_id<<8)
Flavio Castroaf2b4502016-02-02 17:41:32 -0500346 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id)
Flavio Castro6efe1862015-11-18 16:28:06 -0500347 #add entries in the Bridging table to avoid packet-in from mac learning
348 group_id = encode_l2_interface_group_id(vlan_id, port)
349 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500350
351 do_barrier(self.controller)
352
Flavio Castro05d20bc2015-11-16 15:06:14 -0500353 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
Flavio Castroa8233862015-12-02 14:41:11 -0500354 for in_port in ports:
355 mac_src='00:00:00:22:22:%02X' % in_port
356 ip_src='192.168.%02d.1' % in_port
357 for out_port in ports:
358 if in_port == out_port:
359 continue
360 ip_dst='192.168.%02d.1' % out_port
Flavio Castroaba28ff2016-02-03 16:47:48 -0500361 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=(class_id+in_port),
Flavio Castroa8233862015-12-02 14:41:11 -0500362 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
Flavio Castrod8f8af22015-12-02 18:19:26 -0500363 ip_dst=ip_dst)
Flavio Castroa8233862015-12-02 14:41:11 -0500364 pkt=str(parsed_pkt)
365 self.dataplane.send(in_port, pkt)
Flavio Castro72a45d52015-12-02 16:37:05 -0500366 #build expected packet
Flavio Castroa8233862015-12-02 14:41:11 -0500367 mac_dst='00:00:00:22:22:%02X' % out_port
Flavio Castroaba28ff2016-02-03 16:47:48 -0500368 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=(class_id+out_port),
Flavio Castroa8233862015-12-02 14:41:11 -0500369 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
370 ip_src=ip_src, ip_dst=ip_dst)
371 pkt=str(exp_pkt)
372 verify_packet(self, pkt, out_port)
373 verify_no_other_packets(self)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500374
Flavio Castrod8f8af22015-12-02 18:19:26 -0500375class L3VPNMPLS(base_tests.SimpleDataPlane):
376 """
377 Insert IP packet
378 Receive MPLS packet
379 """
Flavio Castro72a45d52015-12-02 16:37:05 -0500380 def runTest(self):
381 delete_all_flows(self.controller)
382 delete_all_groups(self.controller)
383
384 if len(config["port_map"]) <2:
385 logging.info("Port count less than 2, can't run this case")
386 return
387
388 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
389 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
390 dip=0xc0a80001
Flavio Castro17327782016-02-03 15:20:15 -0500391 #Hashes Test Name and uses it as id for installing unique groups
392 class_id=abs(hash(inspect.stack()[0][3])) % (256)
Flavio Castro72a45d52015-12-02 16:37:05 -0500393 ports = config["port_map"].keys()
394 for port in ports:
395 #add l2 interface group
Flavio Castro17327782016-02-03 15:20:15 -0500396 id=port+class_id<<8
Flavio Castroaba28ff2016-02-03 16:47:48 -0500397 vlan_id=port+class_id
castroflaviodd171472015-12-08 13:55:58 -0500398 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
Flavio Castro72a45d52015-12-02 16:37:05 -0500399 dst_mac[5]=vlan_id
Flavio Castro35e64392015-12-02 16:53:14 -0500400 #add MPLS interface group
Flavio Castro17327782016-02-03 15:20:15 -0500401 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, id)
Flavio Castro35e64392015-12-02 16:53:14 -0500402 #add MPLS L3 VPN group
Flavio Castrod8f8af22015-12-02 18:19:26 -0500403 mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
Flavio Castro17327782016-02-03 15:20:15 -0500404 index=id, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32)
405 ecmp_msg=add_l3_ecmp_group(self.controller, id, [mpls_label_gid])
Flavio Castro80730822015-12-11 15:38:47 -0500406 do_barrier(self.controller)
Flavio Castro72a45d52015-12-02 16:37:05 -0500407 #add vlan flow table
Flavio Castro17327782016-02-03 15:20:15 -0500408 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castro72a45d52015-12-02 16:37:05 -0500409 #add termination flow
410 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
Flavio Castro35e64392015-12-02 16:53:14 -0500411 #add routing flow
Flavio Castroaf2b4502016-02-02 17:41:32 -0500412 dst_ip = dip + (vlan_id<<8)
Flavio Castro5edf3132016-01-27 15:45:08 -0500413 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
Flavio Castro17327782016-02-03 15:20:15 -0500414 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id, vrf=0)
Flavio Castro80730822015-12-11 15:38:47 -0500415
416 do_barrier(self.controller)
417
418 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
419 for in_port in ports:
420 mac_src='00:00:00:22:22:%02X' % in_port
421 ip_src='192.168.%02d.1' % in_port
422 for out_port in ports:
423 if in_port == out_port:
424 continue
425 ip_dst='192.168.%02d.1' % out_port
Flavio Castroaba28ff2016-02-03 16:47:48 -0500426 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=(class_id+in_port),
Flavio Castro80730822015-12-11 15:38:47 -0500427 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
428 ip_dst=ip_dst)
429 pkt=str(parsed_pkt)
430 self.dataplane.send(in_port, pkt)
431 #build expect packet
432 mac_dst='00:00:00:22:22:%02X' % out_port
433 label = (out_port, 0, 1, 32)
Flavio Castroaba28ff2016-02-03 16:47:48 -0500434 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=(out_port+class_id), ip_ttl=63, ip_src=ip_src,
Flavio Castro80730822015-12-11 15:38:47 -0500435 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
436 pkt=str(exp_pkt)
437 verify_packet(self, pkt, out_port)
438 verify_no_other_packets(self)
castroflavioee294842016-01-06 15:54:28 -0800439
Flavio Castro67d8bd52016-02-03 14:22:14 -0500440class _32VPN(base_tests.SimpleDataPlane):
Flavio Castro80730822015-12-11 15:38:47 -0500441 """
442 Insert IP packet
443 Receive MPLS packet
444 """
445 def runTest(self):
446 delete_all_flows(self.controller)
447 delete_all_groups(self.controller)
448
449 if len(config["port_map"]) <2:
450 logging.info("Port count less than 2, can't run this case")
451 return
452
453 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
454 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
455 dip=0xc0a80001
Flavio Castro67d8bd52016-02-03 14:22:14 -0500456 #Hashes Test Name and uses it as id for installing unique groups
Flavio Castro443c95e2016-02-03 15:05:28 -0500457 class_id=abs(hash(inspect.stack()[0][3])) % (256)
Flavio Castro80730822015-12-11 15:38:47 -0500458 ports = config["port_map"].keys()
459 for port in ports:
460 #add l2 interface group
Flavio Castro443c95e2016-02-03 15:05:28 -0500461 id=port+class_id<<8
Flavio Castroaba28ff2016-02-03 16:47:48 -0500462 vlan_id=port+class_id
Flavio Castro80730822015-12-11 15:38:47 -0500463 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
464 dst_mac[5]=vlan_id
465 #add MPLS interface group
Flavio Castro67d8bd52016-02-03 14:22:14 -0500466 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, id)
Flavio Castro80730822015-12-11 15:38:47 -0500467 #add MPLS L3 VPN group
468 mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
Flavio Castro67d8bd52016-02-03 14:22:14 -0500469 index=id, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32)
Flavio Castro80730822015-12-11 15:38:47 -0500470 #ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
471 do_barrier(self.controller)
472 #add vlan flow table
Flavio Castro67d8bd52016-02-03 14:22:14 -0500473 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castro80730822015-12-11 15:38:47 -0500474 #add termination flow
475 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
476 #add routing flow
477 dst_ip = dip + (vlan_id<<8)
Flavio Castro67d8bd52016-02-03 14:22:14 -0500478 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffffff, mpls_label_gid)
Flavio Castro72a45d52015-12-02 16:37:05 -0500479
480 do_barrier(self.controller)
481
482 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
483 for in_port in ports:
Flavio Castro72a45d52015-12-02 16:37:05 -0500484 ip_src='192.168.%02d.1' % in_port
485 for out_port in ports:
486 if in_port == out_port:
487 continue
488 ip_dst='192.168.%02d.1' % out_port
Flavio Castroaba28ff2016-02-03 16:47:48 -0500489 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=(class_id+in_port),
Flavio Castro67d8bd52016-02-03 14:22:14 -0500490 eth_dst=switch_mac, ip_ttl=64, ip_src=ip_src,
Flavio Castro72a45d52015-12-02 16:37:05 -0500491 ip_dst=ip_dst)
492 pkt=str(parsed_pkt)
493 self.dataplane.send(in_port, pkt)
494 #build expect packet
495 mac_dst='00:00:00:22:22:%02X' % out_port
496 label = (out_port, 0, 1, 32)
Flavio Castroaba28ff2016-02-03 16:47:48 -0500497 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=(class_id+out_port), ip_ttl=63, ip_src=ip_src,
Flavio Castro72a45d52015-12-02 16:37:05 -0500498 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
499 pkt=str(exp_pkt)
500 verify_packet(self, pkt, out_port)
501 verify_no_other_packets(self)
Flavio Castroaba28ff2016-02-03 16:47:48 -0500502@disabled
Flavio Castro80730822015-12-11 15:38:47 -0500503class MPLSBUG(base_tests.SimpleDataPlane):
504
505 def runTest(self):
506 delete_all_flows(self.controller)
507 delete_all_groups(self.controller)
508
509 if len(config["port_map"]) <2:
510 logging.info("Port count less than 2, can't run this case")
511 return
512
513 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
514 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
515 dip=0xc0a80001
516 index=1
517 ports = config["port_map"].keys()
518 for port in ports:
519 #add l2 interface group
520 vlan_id=port
521 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, False)
522 dst_mac[5]=vlan_id
523 #add L3 Unicast group
524 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
525 #add vlan flow table
526 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
527 #add termination flow
528 add_termination_flow(self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24)
529 #add mpls flow
530 add_mpls_flow(self.controller, l3_msg.group_id, port)
531 #add termination flow
532 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
533 #add unicast routing flow
534 dst_ip = dip + (vlan_id<<8)
Flavio Castroaf2b4502016-02-02 17:41:32 -0500535 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id)
Flavio Castro80730822015-12-11 15:38:47 -0500536
537 #add entries in the Bridging table to avoid packet-in from mac learning
538 group_id = encode_l2_interface_group_id(vlan_id, port)
539 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
540
541 do_barrier(self.controller)
542
543 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
544 for in_port in ports:
545 mac_src='00:00:00:22:22:%02X' % in_port
546 ip_src='192.168.%02d.1' % in_port
547 for out_port in ports:
548 if in_port == out_port:
549 continue
550 ip_dst='192.168.%02d.1' % out_port
551 switch_mac = "00:00:00:cc:cc:cc"
552 label = (out_port, 0, 1, 32)
553 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=in_port, ip_src=ip_src,
554 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=mac_src, label=[label])
555 pkt=str(parsed_pkt)
556 self.dataplane.send(in_port, pkt)
557
558 #build expect packet
559 mac_dst='00:00:00:22:22:%02X' % out_port
560 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
561 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst)
562 pkt=str(exp_pkt)
563 verify_packet(self, pkt, out_port)
564 verify_no_other_packets(self)
565
566 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
567 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
568 ip_dst=ip_dst)
569 pkt=str(parsed_pkt)
570 self.dataplane.send(in_port, pkt)
571 #build expected packet
572 mac_dst='00:00:00:22:22:%02X' % out_port
573 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
574 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
575 ip_src=ip_src, ip_dst=ip_dst)
576 pkt=str(exp_pkt)
577 verify_packet(self, pkt, out_port)
578 verify_no_other_packets(self)
579
Flavio Castro12296312015-12-15 17:48:26 -0500580class L3McastToL2(base_tests.SimpleDataPlane):
castroflaviocc403a92015-12-15 14:04:19 -0500581 """
Flavio Castro12296312015-12-15 17:48:26 -0500582 Mcast routing to L2
castroflaviocc403a92015-12-15 14:04:19 -0500583 """
584 def runTest(self):
585 """
586 port1 (vlan 300)-> All Ports (vlan 300)
587 """
Flavio Castro932014b2016-01-05 18:29:15 -0500588 #delete_all_flows(self.controller)
589 #delete_all_groups(self.controller)
castroflaviocc403a92015-12-15 14:04:19 -0500590
castroflavio4a09c962016-01-05 13:13:41 -0800591 if len(config["port_map"]) <3:
592 logging.info("Port count less than 3, can't run this case")
593 assert(False)
castroflaviocc403a92015-12-15 14:04:19 -0500594 return
595
596 vlan_id =300
597 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
598 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
599 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
600 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
601 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
602 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
603 src_ip=0xc0a80101
604 src_ip_str="192.168.1.1"
605 dst_ip=0xe0010101
606 dst_ip_str="224.1.1.1"
607
608 port1=config["port_map"].keys()[0]
609 port2=config["port_map"].keys()[1]
610
611 switch_mac = [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00]
612
613
614 #add l2 interface group
615 l2_intf_group_list=[]
616 for port in config["port_map"].keys():
Flavio Castro89933f22016-02-03 15:53:16 -0500617 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
castroflaviocc403a92015-12-15 14:04:19 -0500618 if port == port2:
619 continue
Flavio Castro12296312015-12-15 17:48:26 -0500620 l2_intf_gid, msg=add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
castroflaviocc403a92015-12-15 14:04:19 -0500621 l2_intf_group_list.append(l2_intf_gid)
castroflaviocc403a92015-12-15 14:04:19 -0500622
623 #add termination flow
624 add_termination_flow(self.controller, port1, 0x0800, switch_mac, vlan_id)
625
626 #add l3 interface group
627 mcat_group_msg=add_l3_mcast_group(self.controller, vlan_id, 2, l2_intf_group_list)
628 add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip, mcat_group_msg.group_id)
629
Flavio Castro932014b2016-01-05 18:29:15 -0500630 parsed_pkt = simple_udp_packet(pktlen=100,
Flavio Castro89933f22016-02-03 15:53:16 -0500631 dl_vlan_enable=True,
632 vlan_vid=vlan_id,
castroflaviocc403a92015-12-15 14:04:19 -0500633 eth_dst=dst_mac_str,
634 eth_src=port1_mac_str,
635 ip_ttl=64,
636 ip_src=src_ip_str,
637 ip_dst=dst_ip_str)
638 pkt=str(parsed_pkt)
639 self.dataplane.send(port1, pkt)
640 for port in config["port_map"].keys():
Flavio Castro12296312015-12-15 17:48:26 -0500641 if port == port2 or port == port1:
castroflaviocc403a92015-12-15 14:04:19 -0500642 verify_no_packet(self, pkt, port)
Flavio Castro12296312015-12-15 17:48:26 -0500643 continue
castroflaviocc403a92015-12-15 14:04:19 -0500644 verify_packet(self, pkt, port)
645 verify_no_other_packets(self)
646
Flavio Castro12296312015-12-15 17:48:26 -0500647class L3McastToL3(base_tests.SimpleDataPlane):
648 """
649 Mcast routing
650 """
651 def runTest(self):
652 """
653 port1 (vlan 1)-> port 2 (vlan 2)
654 """
655 delete_all_flows(self.controller)
656 delete_all_groups(self.controller)
657
658 if len(config["port_map"]) <3:
castroflavio4a09c962016-01-05 13:13:41 -0800659 logging.info("Port count less than 3, can't run this case")
660 assert(False)
Flavio Castro12296312015-12-15 17:48:26 -0500661 return
662
663 vlan_id =1
664 port2_out_vlan=2
665 port3_out_vlan=3
666 in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan
667 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
668 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
669 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
670 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
671 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
672 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
673 src_ip=0xc0a80101
674 src_ip_str="192.168.1.1"
675 dst_ip=0xe0010101
676 dst_ip_str="224.1.1.1"
677
678 port1=config["port_map"].keys()[0]
679 port2=config["port_map"].keys()[1]
680 port3=config["port_map"].keys()[2]
681
682 #add l2 interface group
683 for port in config["port_map"].keys():
684 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
685 #add vlan flow table
686 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
687 vlan_id +=1
688
689 #add termination flow
690 add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
691
692 #add l3 interface group
693 port2_ucast_msg=add_l3_interface_group(self.controller, port2, port2_out_vlan, 2, intf_src_mac)
694 port3_ucast_msg=add_l3_interface_group(self.controller, port3, port3_out_vlan, 3, intf_src_mac)
695 mcat_group_msg=add_l3_mcast_group(self.controller, in_vlan, 2, [port2_ucast_msg.group_id, port3_ucast_msg.group_id])
696 add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id)
697
698 parsed_pkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=1,
699 eth_dst=dst_mac_str,
700 eth_src=port1_mac_str,
701 ip_ttl=64,
702 ip_src=src_ip_str,
703 ip_dst=dst_ip_str)
704 pkt=str(parsed_pkt)
705 self.dataplane.send(port1, pkt)
706 parsed_pkt = simple_udp_packet(pktlen=96,
707 eth_dst=dst_mac_str,
708 eth_src=intf_src_mac_str,
709 ip_ttl=63,
710 ip_src=src_ip_str,
711 ip_dst=dst_ip_str)
712 pkt=str(parsed_pkt)
713 verify_packet(self, pkt, port2)
714 verify_packet(self, pkt, port3)
715 verify_no_other_packets(self)
Flavio Castro54947942016-02-03 16:05:20 -0500716
717
718
Flavio Castrof54be492016-02-03 16:26:22 -0500719class _MplsTermination(base_tests.SimpleDataPlane):
Flavio Castro12296312015-12-15 17:48:26 -0500720 """
Flavio Castro54947942016-02-03 16:05:20 -0500721 Insert IP packet
722 Receive MPLS packet
castroflavio30c6cc52016-01-07 15:19:42 -0800723 """
724 def runTest(self):
725 delete_all_flows(self.controller)
726 delete_all_groups(self.controller)
727
728 if len(config["port_map"]) <2:
729 logging.info("Port count less than 2, can't run this case")
730 return
731
732 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
733 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
Flavio Castro54947942016-02-03 16:05:20 -0500734 #Hashes Test Name and uses it as id for installing unique groups
735 class_id=abs(hash(inspect.stack()[0][3])) % (256)
castroflavio30c6cc52016-01-07 15:19:42 -0800736 ports = config["port_map"].keys()
737 for port in ports:
738 #add l2 interface group
Flavio Castro54947942016-02-03 16:05:20 -0500739 id = port + class_id<<8
Flavio Castroaba28ff2016-02-03 16:47:48 -0500740 vlan_id=port+class_id
Flavio Castro54947942016-02-03 16:05:20 -0500741 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, False)
castroflavio30c6cc52016-01-07 15:19:42 -0800742 dst_mac[5]=vlan_id
Flavio Castro54947942016-02-03 16:05:20 -0500743 #add L3 Unicast group
744 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=id, src_mac=intf_src_mac, dst_mac=dst_mac)
745 #add L3 ecmp group
746 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
castroflavio30c6cc52016-01-07 15:19:42 -0800747 #add vlan flow table
Flavio Castro54947942016-02-03 16:05:20 -0500748 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
castroflavio30c6cc52016-01-07 15:19:42 -0800749 #add termination flow
Flavio Castro54947942016-02-03 16:05:20 -0500750 add_termination_flow(self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24)
751 add_mpls_flow(self.controller, ecmp_msg.group_id, port)
castroflavio30c6cc52016-01-07 15:19:42 -0800752
753 do_barrier(self.controller)
754
755 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
756 for in_port in ports:
castroflavio30c6cc52016-01-07 15:19:42 -0800757 ip_src='192.168.%02d.1' % in_port
758 for out_port in ports:
759 if in_port == out_port:
Flavio Castro54947942016-02-03 16:05:20 -0500760 continue
castroflavio30c6cc52016-01-07 15:19:42 -0800761 ip_dst='192.168.%02d.1' % out_port
Flavio Castro54947942016-02-03 16:05:20 -0500762
763 label = (out_port, 0, 1, 32)
Flavio Castroaba28ff2016-02-03 16:47:48 -0500764 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=(in_port+class_id), ip_src=ip_src,
Flavio Castro54947942016-02-03 16:05:20 -0500765 ip_dst=ip_dst, eth_dst=switch_mac, label=[label])
castroflavio30c6cc52016-01-07 15:19:42 -0800766 pkt=str(parsed_pkt)
767 self.dataplane.send(in_port, pkt)
Flavio Castro54947942016-02-03 16:05:20 -0500768
castroflavio30c6cc52016-01-07 15:19:42 -0800769 #build expect packet
770 mac_dst='00:00:00:22:22:%02X' % out_port
Flavio Castroaba28ff2016-02-03 16:47:48 -0500771 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=(class_id+out_port),
Flavio Castro54947942016-02-03 16:05:20 -0500772 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst)
castroflavio30c6cc52016-01-07 15:19:42 -0800773 pkt=str(exp_pkt)
774 verify_packet(self, pkt, out_port)
775 verify_no_other_packets(self)