blob: 08151148622d493004cf7041df4ce458835f1ddd [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"""
Flavio Castro1c9b1252016-02-04 18:42:58 -050016import Queue
Flavio Castro05d20bc2015-11-16 15:06:14 -050017
Flavio Castro05d20bc2015-11-16 15:06:14 -050018from oftest import config
Flavio Castro67d8bd52016-02-03 14:22:14 -050019import inspect
Flavio Castro167f5bd2015-12-02 19:33:53 -050020import logging
21import oftest.base_tests as base_tests
Flavio Castro05d20bc2015-11-16 15:06:14 -050022import ofp
23from oftest.testutils import *
24from accton_util import *
Flavio Castrod8f8af22015-12-02 18:19:26 -050025
Flavio Castro1c9b1252016-02-04 18:42:58 -050026
Flavio Castro7fb6ca92015-12-16 15:50:14 -050027class PacketInUDP(base_tests.SimpleDataPlane):
Flavio Castro6d498522015-12-15 14:05:04 -050028 """
Flavio Castro1c9b1252016-02-04 18:42:58 -050029 Verify a ACL rule that matches on IP_PROTO 2 will not match a UDP packet.
30 Next it verify a rule that matches on IP_PROTO 17 WILL match a UDP packet.
Flavio Castro6d498522015-12-15 14:05:04 -050031 """
32
33 def runTest(self):
Flavio Castro1c9b1252016-02-04 18:42:58 -050034 parsed_vlan_pkt = simple_udp_packet(pktlen=104,
35 vlan_vid=0x1001,
36 dl_vlan_enable=True)
Flavio Castro6d498522015-12-15 14:05:04 -050037 vlan_pkt = str(parsed_vlan_pkt)
Flavio Castro6d498522015-12-15 14:05:04 -050038 # create match
39 match = ofp.match()
40 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
Flavio Castro1c9b1252016-02-04 18:42:58 -050041 match.oxm_list.append(ofp.oxm.ip_proto(2))
Flavio Castro6d498522015-12-15 14:05:04 -050042 request = ofp.message.flow_add(
Flavio Castro1c9b1252016-02-04 18:42:58 -050043 table_id=60,
44 cookie=42,
45 match=match,
46 instructions=[
47 ofp.instruction.apply_actions(
48 actions=[
49 ofp.action.output(
50 port=ofp.OFPP_CONTROLLER,
51 max_len=ofp.OFPCML_NO_BUFFER)]), ],
52 buffer_id=ofp.OFP_NO_BUFFER,
53 priority=1)
54 logging.info("Inserting packet in flow to controller")
55 self.controller.message_send(request)
56
57 for of_port in config["port_map"].keys():
58 logging.info("PacketInMiss test, port %d", of_port)
59 self.dataplane.send(of_port, vlan_pkt)
60
Flavio Castro6da7e462016-02-04 18:56:29 -050061 verify_no_packet_in(self, vlan_pkt, of_port)
62 delete_all_flows(self.controller)
Flavio Castro6d498522015-12-15 14:05:04 -050063 do_barrier(self.controller)
64
Flavio Castro1c9b1252016-02-04 18:42:58 -050065 match = ofp.match()
66 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
67 match.oxm_list.append(ofp.oxm.ip_proto(17))
68 request = ofp.message.flow_add(
69 table_id=60,
70 cookie=42,
71 match=match,
72 instructions=[
73 ofp.instruction.apply_actions(
74 actions=[
75 ofp.action.output(
76 port=ofp.OFPP_CONTROLLER,
77 max_len=ofp.OFPCML_NO_BUFFER)]), ],
78 buffer_id=ofp.OFP_NO_BUFFER,
79 priority=1)
80 logging.info("Inserting packet in flow to controller")
81 self.controller.message_send(request)
Flavio Castro6da7e462016-02-04 18:56:29 -050082 do_barrier(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -050083
Flavio Castro6d498522015-12-15 14:05:04 -050084 for of_port in config["port_map"].keys():
85 logging.info("PacketInMiss test, port %d", of_port)
86 self.dataplane.send(of_port, vlan_pkt)
87
88 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
89
90 verify_no_other_packets(self)
Flavio Castroaf2b4502016-02-02 17:41:32 -050091
Flavio Castro1c9b1252016-02-04 18:42:58 -050092 delete_all_flows(self.controller)
93
Flavio Castroaf2b4502016-02-02 17:41:32 -050094
Flavio Castro67d8bd52016-02-03 14:22:14 -050095@disabled
Flavio Castro7fb6ca92015-12-16 15:50:14 -050096class ArpNL2(base_tests.SimpleDataPlane):
Flavio Castro1c9b1252016-02-04 18:42:58 -050097 def runTest(self):
Flavio Castro7fb6ca92015-12-16 15:50:14 -050098 delete_all_flows(self.controller)
99 delete_all_groups(self.controller)
100
101 ports = sorted(config["port_map"].keys())
102 match = ofp.match()
103 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
104 request = ofp.message.flow_add(
Flavio Castro1c9b1252016-02-04 18:42:58 -0500105 table_id=60,
106 cookie=42,
107 match=match,
108 instructions=[
109 ofp.instruction.apply_actions(
110 actions=[
111 ofp.action.output(
112 port=ofp.OFPP_CONTROLLER,
113 max_len=ofp.OFPCML_NO_BUFFER)]),
114 ],
115 buffer_id=ofp.OFP_NO_BUFFER,
116 priority=40000)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500117 self.controller.message_send(request)
118 for port in ports:
Flavio Castro932014b2016-01-05 18:29:15 -0500119 add_one_l2_interface_group(self.controller, port, 1, False, False)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500120 add_one_vlan_table_flow(self.controller, port, 1,
121 flag=VLAN_TABLE_FLAG_ONLY_BOTH)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500122 group_id = encode_l2_interface_group_id(1, port)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500123 add_bridge_flow(self.controller,
124 [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id,
125 True)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500126 do_barrier(self.controller)
127 parsed_arp_pkt = simple_arp_packet()
128 arp_pkt = str(parsed_arp_pkt)
129
130 for out_port in ports:
131 self.dataplane.send(out_port, arp_pkt)
132 verify_packet_in(self, arp_pkt, out_port, ofp.OFPR_ACTION)
133 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500134 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500135 for in_port in ports:
136 if in_port == out_port:
137 continue
138 # change source based on port number to avoid packet-ins from learning
Flavio Castro1c9b1252016-02-04 18:42:58 -0500139 mac_src = '00:12:34:56:78:%02X' % in_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500140 parsed_pkt = simple_tcp_packet(eth_dst=mac_dst, eth_src=mac_src)
141 pkt = str(parsed_pkt)
142 self.dataplane.send(in_port, pkt)
143
144 for ofport in ports:
145 if ofport in [out_port]:
146 verify_packet(self, pkt, ofport)
147 else:
148 verify_no_packet(self, pkt, ofport)
149
150 verify_no_other_packets(self)
151
Flavio Castro1c9b1252016-02-04 18:42:58 -0500152
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500153class PacketInArp(base_tests.SimpleDataPlane):
154 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500155 Verify an ACL rule matching on ethertyper 0x806 will result in a packet-in
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500156 """
157
158 def runTest(self):
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500159 parsed_arp_pkt = simple_arp_packet()
160 arp_pkt = str(parsed_arp_pkt)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500161 # create match
162 match = ofp.match()
163 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
164 request = ofp.message.flow_add(
Flavio Castro1c9b1252016-02-04 18:42:58 -0500165 table_id=60,
166 cookie=42,
167 match=match,
168 instructions=[
169 ofp.instruction.apply_actions(
170 actions=[
171 ofp.action.output(
172 port=ofp.OFPP_CONTROLLER,
173 max_len=ofp.OFPCML_NO_BUFFER)]),
174 ],
175 buffer_id=ofp.OFP_NO_BUFFER,
176 priority=1)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500177
178 logging.info("Inserting packet in flow to controller")
179 self.controller.message_send(request)
180 do_barrier(self.controller)
181
182 for of_port in config["port_map"].keys():
183 logging.info("PacketInMiss test, port %d", of_port)
184 self.dataplane.send(of_port, arp_pkt)
185
186 verify_packet_in(self, arp_pkt, of_port, ofp.OFPR_ACTION)
187
188 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500189 delete_all_flows(self.controller)
190
Flavio Castro91d1a552016-05-17 16:59:44 -0700191class PacketInIPTable(base_tests.SimpleDataPlane):
192 """
193 Test packet in function on IPTABLE
194 Send a packet to each dataplane port and verify that a packet
195 in message is received from the controller for each
196 #todo verify you stop receiving after adding rule
197 """
198
199 def runTest(self):
200
201 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
202 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
203 dip=0xc0a80001
204 ports = sorted(config["port_map"].keys())
205 Groups = Queue.LifoQueue()
206
207 for port in ports:
208 #add l2 interface group
209 vlan_id=port
210 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
211 dst_mac[5]=vlan_id
212 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
213 #add vlan flow table
214 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
215 #add termination flow
216 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
217 #add unicast routing flow
218 dst_ip = dip + (vlan_id<<8)
219 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, l3_msg.group_id, send_ctrl=True)
220 Groups.put(l3_msg.group_id)
221
222 do_barrier(self.controller)
223
224 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
225 for in_port in ports:
226 mac_src='00:00:00:22:22:%02X' % in_port
227 ip_src='192.168.%02d.1' % in_port
228 for out_port in ports:
229 if in_port == out_port:
230 continue
231 ip_dst='192.168.%02d.1' % out_port
232 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
233 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
234 ip_dst=ip_dst)
235 pkt=str(parsed_pkt)
236 self.dataplane.send(in_port, pkt)
237 verify_packet_in(self, pkt, in_port, ofp.OFPR_ACTION)
238 #verify_no_other_packets(self)
239 delete_all_flows(self.controller)
240 delete_groups(self.controller, Groups)
241
242
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500243
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500244class L2FloodQinQ(base_tests.SimpleDataPlane):
245 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500246 Verify a tagged frame can be flooded based on its outer vlan
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500247 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500248
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500249 def runTest(self):
250 ports = sorted(config["port_map"].keys())
Flavio Castro1c9b1252016-02-04 18:42:58 -0500251 vlan_id = 1
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500252
Flavio Castro1c9b1252016-02-04 18:42:58 -0500253 Groups = Queue.LifoQueue()
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500254 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500255 L2gid, l2msg = add_one_l2_interface_group(self.controller, port,
256 vlan_id, True, False)
257 add_one_vlan_table_flow(self.controller, port, vlan_id,
258 flag=VLAN_TABLE_FLAG_ONLY_TAG)
259 Groups.put(L2gid)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500260
Flavio Castro1c9b1252016-02-04 18:42:58 -0500261 msg = add_l2_flood_group(self.controller, ports, vlan_id, vlan_id)
Flavio Castro6da7e462016-02-04 18:56:29 -0500262 Groups.put(msg.group_id)
Flavio Castro8628adb2016-02-03 17:30:57 -0500263 add_bridge_flow(self.controller, None, vlan_id, msg.group_id, True)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500264 do_barrier(self.controller)
265
Flavio Castro1c9b1252016-02-04 18:42:58 -0500266 # verify flood
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500267 for ofport in ports:
268 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500269 mac_src = '00:12:34:56:78:%02X' % ofport
270 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108,
271 out_dl_vlan_enable=True,
272 out_vlan_vid=vlan_id,
273 in_dl_vlan_enable=True,
274 in_vlan_vid=10,
275 eth_dst='00:12:34:56:78:9a',
276 eth_src=mac_src)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500277 pkt = str(parsed_pkt)
278 self.dataplane.send(ofport, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500279 # self won't rx packet
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500280 verify_no_packet(self, pkt, ofport)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500281 # others will rx packet
282 tmp_ports = list(ports)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500283 tmp_ports.remove(ofport)
284 verify_packets(self, pkt, tmp_ports)
285
286 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500287 delete_all_flows(self.controller)
288 delete_groups(self.controller, Groups)
289
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500290
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500291@disabled
Flavio Castro184cefe2015-11-19 20:52:49 -0500292class L2FloodTagged(base_tests.SimpleDataPlane):
293 """
294 Test L2 flood to a vlan
295 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 -0500296 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500297
Flavio Castro184cefe2015-11-19 20:52:49 -0500298 def runTest(self):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500299 # Hashes Test Name and uses it as id for installing unique groups
300 vlan_id = abs(hash(inspect.stack()[0][3])) % (256)
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500301 print vlan_id
Flavio Castroaba28ff2016-02-03 16:47:48 -0500302
Flavio Castro184cefe2015-11-19 20:52:49 -0500303 ports = sorted(config["port_map"].keys())
Flavio Castro34352e72015-12-07 20:01:51 -0500304
Flavio Castro184cefe2015-11-19 20:52:49 -0500305 delete_all_flows(self.controller)
306 delete_all_groups(self.controller)
307
Flavio Castro184cefe2015-11-19 20:52:49 -0500308 # Installing flows to avoid packet-in
309 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500310 add_one_l2_interface_group(self.controller, port, vlan_id, True,
311 False)
312 add_one_vlan_table_flow(self.controller, port, vlan_id,
313 flag=VLAN_TABLE_FLAG_ONLY_TAG)
314 msg = add_l2_flood_group(self.controller, ports, vlan_id, vlan_id)
Flavio Castroaba28ff2016-02-03 16:47:48 -0500315 add_bridge_flow(self.controller, None, vlan_id, msg.group_id, True)
Flavio Castro184cefe2015-11-19 20:52:49 -0500316 do_barrier(self.controller)
317
Flavio Castro1c9b1252016-02-04 18:42:58 -0500318 # verify flood
Flavio Castro184cefe2015-11-19 20:52:49 -0500319 for ofport in ports:
320 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500321 pkt = str(simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vlan_id,
322 eth_dst='00:12:34:56:78:9a'))
Flavio Castro184cefe2015-11-19 20:52:49 -0500323 self.dataplane.send(ofport, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500324 # self won't rx packet
Flavio Castro184cefe2015-11-19 20:52:49 -0500325 verify_no_packet(self, pkt, ofport)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500326 # others will rx packet
327 tmp_ports = list(ports)
Flavio Castro184cefe2015-11-19 20:52:49 -0500328 tmp_ports.remove(ofport)
329 verify_packets(self, pkt, tmp_ports)
Flavio Castro184cefe2015-11-19 20:52:49 -0500330 verify_no_other_packets(self)
Flavio Castroaabb5792015-11-18 19:03:50 -0500331
Flavio Castro1c9b1252016-02-04 18:42:58 -0500332
Flavio Castroaabb5792015-11-18 19:03:50 -0500333class L2UnicastTagged(base_tests.SimpleDataPlane):
334 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500335 Verify L2 forwarding works
Flavio Castroaabb5792015-11-18 19:03:50 -0500336 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500337
Flavio Castroaabb5792015-11-18 19:03:50 -0500338 def runTest(self):
339 ports = sorted(config["port_map"].keys())
Flavio Castro1c9b1252016-02-04 18:42:58 -0500340 vlan_id = 1;
341 Groups = Queue.LifoQueue()
Flavio Castroaabb5792015-11-18 19:03:50 -0500342 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500343 L2gid, l2msg = add_one_l2_interface_group(self.controller, port,
344 vlan_id, True, False)
345 add_one_vlan_table_flow(self.controller, port, vlan_id,
346 flag=VLAN_TABLE_FLAG_ONLY_TAG)
347 Groups.put(L2gid)
348 add_bridge_flow(self.controller,
349 [0x00, 0x12, 0x34, 0x56, 0x78, port], vlan_id,
350 L2gid, True)
Flavio Castro6efe1862015-11-18 16:28:06 -0500351 do_barrier(self.controller)
352
Flavio Castroaabb5792015-11-18 19:03:50 -0500353 for out_port in ports:
354 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500355 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castroaabb5792015-11-18 19:03:50 -0500356 for in_port in ports:
357 if in_port == out_port:
358 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -0500359 pkt = str(
360 simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vlan_id,
361 eth_dst=mac_dst))
Flavio Castroaabb5792015-11-18 19:03:50 -0500362 self.dataplane.send(in_port, pkt)
Flavio Castroaabb5792015-11-18 19:03:50 -0500363 for ofport in ports:
364 if ofport in [out_port]:
365 verify_packet(self, pkt, ofport)
366 else:
367 verify_no_packet(self, pkt, ofport)
Flavio Castroaabb5792015-11-18 19:03:50 -0500368 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500369 delete_all_flows(self.controller)
370 delete_groups(self.controller, Groups)
371
Flavio Castro6efe1862015-11-18 16:28:06 -0500372
Flavio Castrob6773032015-11-19 22:49:24 -0500373class Mtu1500(base_tests.SimpleDataPlane):
Flavio Castrob6773032015-11-19 22:49:24 -0500374 def runTest(self):
375 ports = sorted(config["port_map"].keys())
Flavio Castro1c9b1252016-02-04 18:42:58 -0500376 vlan_id = 18
377 Groups = Queue.LifoQueue()
Flavio Castrob6773032015-11-19 22:49:24 -0500378 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500379 L2gid, msg = add_one_l2_interface_group(self.controller, port,
380 vlan_id, True, False)
381 add_one_vlan_table_flow(self.controller, port, vlan_id,
382 flag=VLAN_TABLE_FLAG_ONLY_TAG)
383 Groups.put(L2gid)
384 add_bridge_flow(self.controller,
385 [0x00, 0x12, 0x34, 0x56, 0x78, port], vlan_id,
386 L2gid, True)
Flavio Castrob6773032015-11-19 22:49:24 -0500387 do_barrier(self.controller)
388
389 for out_port in ports:
390 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500391 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castrob6773032015-11-19 22:49:24 -0500392 for in_port in ports:
393 if in_port == out_port:
394 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -0500395 pkt = str(simple_tcp_packet(pktlen=1500, dl_vlan_enable=True,
396 vlan_vid=vlan_id, eth_dst=mac_dst))
Flavio Castrob6773032015-11-19 22:49:24 -0500397 self.dataplane.send(in_port, pkt)
Flavio Castrob6773032015-11-19 22:49:24 -0500398 for ofport in ports:
399 if ofport in [out_port]:
400 verify_packet(self, pkt, ofport)
401 else:
402 verify_no_packet(self, pkt, ofport)
Flavio Castrob6773032015-11-19 22:49:24 -0500403 verify_no_other_packets(self)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500404 delete_all_flows(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500405 delete_groups(self.controller, Groups)
406
407
408class _32UcastTagged(base_tests.SimpleDataPlane):
409 """
410 Verify a IP forwarding works for a /32 rule to L3 Unicast Interface
411 """
412
413 def runTest(self):
414 test_id = 26
415 if len(config["port_map"]) < 2:
Flavio Castro05d20bc2015-11-16 15:06:14 -0500416 logging.info("Port count less than 2, can't run this case")
417 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500418
Flavio Castro1c9b1252016-02-04 18:42:58 -0500419 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
420 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
421 dip = 0xc0a80001
Flavio Castroa8233862015-12-02 14:41:11 -0500422 ports = config["port_map"].keys()
Flavio Castro1c9b1252016-02-04 18:42:58 -0500423 Groups = Queue.LifoQueue()
Flavio Castroa8233862015-12-02 14:41:11 -0500424 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500425 # add l2 interface group
426 vlan_id = port + test_id
427 l2gid, msg = add_one_l2_interface_group(self.controller, port,
428 vlan_id=vlan_id,
429 is_tagged=True,
430 send_barrier=False)
431 dst_mac[5] = vlan_id
432 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
433 id=vlan_id, src_mac=intf_src_mac,
434 dst_mac=dst_mac)
435 # add vlan flow table
436 add_one_vlan_table_flow(self.controller, port, vlan_id,
437 flag=VLAN_TABLE_FLAG_ONLY_TAG)
438 # add termination flow
439 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
440 vlan_id)
441 # add unicast routing flow
442 dst_ip = dip + (vlan_id << 8)
443 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
444 0xffffffff, l3_msg.group_id)
445 Groups.put(l2gid)
446 Groups.put(l3_msg.group_id)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500447 do_barrier(self.controller)
448
Flavio Castro05d20bc2015-11-16 15:06:14 -0500449 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
Flavio Castroa8233862015-12-02 14:41:11 -0500450 for in_port in ports:
Flavio Castro91d1a552016-05-17 16:59:44 -0700451 mac_src = '00:00:00:22:32:%02X' % (test_id + in_port)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500452 ip_src = '192.168.%02d.1' % (test_id + in_port)
Flavio Castroa8233862015-12-02 14:41:11 -0500453 for out_port in ports:
454 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500455 continue
456 ip_dst = '192.168.%02d.1' % (test_id + out_port)
457 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
458 vlan_vid=(test_id + in_port),
459 eth_dst=switch_mac,
460 eth_src=mac_src, ip_ttl=64,
461 ip_src=ip_src,
462 ip_dst=ip_dst)
463 pkt = str(parsed_pkt)
Flavio Castroa8233862015-12-02 14:41:11 -0500464 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500465 # build expected packet
466 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
467 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
468 vlan_vid=(test_id + out_port),
469 eth_dst=mac_dst, eth_src=switch_mac,
470 ip_ttl=63,
471 ip_src=ip_src, ip_dst=ip_dst)
472 pkt = str(exp_pkt)
Flavio Castroa8233862015-12-02 14:41:11 -0500473 verify_packet(self, pkt, out_port)
474 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500475 delete_all_flows(self.controller)
476 delete_groups(self.controller, Groups)
477
Flavio Castro05d20bc2015-11-16 15:06:14 -0500478
Flavio Castro2262fd42016-02-04 19:03:36 -0500479class _32VPN(base_tests.SimpleDataPlane):
480 """
481 Insert IP packet
482 Receive MPLS packet
483 """
484
485 def runTest(self):
486 if len(config["port_map"]) < 2:
487 logging.info("Port count less than 2, can't run this case")
488 return
489
490 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
491 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
492 dip = 0xc0a80001
493 ports = config["port_map"].keys()
494 Groups = Queue.LifoQueue()
495 for port in ports:
496 # add l2 interface group
497 id = port
498 vlan_id = port
499 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
500 vlan_id, True, True)
501 dst_mac[5] = vlan_id
502 # add MPLS interface group
503 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
504 dst_mac, intf_src_mac,
505 vlan_id, id)
506 # add MPLS L3 VPN group
507 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
508 self.controller,
509 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
510 index=id, ref_gid=mpls_gid, push_mpls_header=True,
511 set_mpls_label=port, set_bos=1, set_ttl=32)
512 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
513 do_barrier(self.controller)
514 # add vlan flow table
Flavio Castrobcc3dbc2016-04-06 11:05:03 -0400515 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=2,
Flavio Castro2262fd42016-02-04 19:03:36 -0500516 flag=VLAN_TABLE_FLAG_ONLY_TAG)
517 # add termination flow
518 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
519 vlan_id)
520 # add routing flow
521 dst_ip = dip + (vlan_id << 8)
522 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
Flavio Castrobcc3dbc2016-04-06 11:05:03 -0400523 0xffffffff, mpls_label_gid,vrf=2)
Flavio Castro2262fd42016-02-04 19:03:36 -0500524 Groups._put(l2_gid)
525 Groups._put(mpls_gid)
526 Groups._put(mpls_label_gid)
527 do_barrier(self.controller)
528
529 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
530 for in_port in ports:
531 ip_src = '192.168.%02d.1' % (in_port)
532 for out_port in ports:
533 if in_port == out_port:
534 continue
535 ip_dst = '192.168.%02d.1' % (out_port)
536 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
537 vlan_vid=(in_port),
538 eth_dst=switch_mac, ip_ttl=64,
539 ip_src=ip_src,
540 ip_dst=ip_dst)
541 pkt = str(parsed_pkt)
542 self.dataplane.send(in_port, pkt)
543 # build expect packet
544 mac_dst = '00:00:00:22:22:%02X' % (out_port)
545 label = (out_port, 0, 1, 32)
546 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
547 vlan_vid=(out_port), ip_ttl=63,
548 ip_src=ip_src,
549 ip_dst=ip_dst, eth_dst=mac_dst,
550 eth_src=switch_mac, label=[label])
551 pkt = str(exp_pkt)
552 verify_packet(self, pkt, out_port)
553 verify_no_other_packets(self)
554 delete_all_flows(self.controller)
555 delete_groups(self.controller, Groups)
556
557class _32EcmpVpn(base_tests.SimpleDataPlane):
558 """
559 Insert IP packet
560 Receive MPLS packet
561 """
562
563 def runTest(self):
564 if len(config["port_map"]) < 2:
565 logging.info("Port count less than 2, can't run this case")
566 return
567
568 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
569 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
570 dip = 0xc0a80001
571 ports = config["port_map"].keys()
572 Groups = Queue.LifoQueue()
573 for port in ports:
574 # add l2 interface group
575 id = port
576 vlan_id = port
577 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
578 vlan_id, True, True)
579 dst_mac[5] = vlan_id
580 # add MPLS interface group
581 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
582 dst_mac, intf_src_mac,
583 vlan_id, id)
584 # add MPLS L3 VPN group
585 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
586 self.controller,
587 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
588 index=id, ref_gid=mpls_gid, push_mpls_header=True,
589 set_mpls_label=port, set_bos=1, set_ttl=32)
590 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
591 do_barrier(self.controller)
592 # add vlan flow table
593 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0,
594 flag=VLAN_TABLE_FLAG_ONLY_TAG)
595 # add termination flow
596 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
597 vlan_id)
598 # add routing flow
599 dst_ip = dip + (vlan_id << 8)
600 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
601 0xffffffff, ecmp_msg.group_id)
602 Groups._put(l2_gid)
603 Groups._put(mpls_gid)
604 Groups._put(mpls_label_gid)
605 Groups._put(ecmp_msg.group_id)
606 do_barrier(self.controller)
607
608 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
609 for in_port in ports:
610 ip_src = '192.168.%02d.1' % (in_port)
611 for out_port in ports:
612 if in_port == out_port:
613 continue
614 ip_dst = '192.168.%02d.1' % (out_port)
615 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
616 vlan_vid=(in_port),
617 eth_dst=switch_mac, ip_ttl=64,
618 ip_src=ip_src,
619 ip_dst=ip_dst)
620 pkt = str(parsed_pkt)
621 self.dataplane.send(in_port, pkt)
622 # build expect packet
623 mac_dst = '00:00:00:22:22:%02X' % (out_port)
624 label = (out_port, 0, 1, 32)
625 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
626 vlan_vid=(out_port), ip_ttl=63,
627 ip_src=ip_src,
628 ip_dst=ip_dst, eth_dst=mac_dst,
629 eth_src=switch_mac, label=[label])
630 pkt = str(exp_pkt)
631 verify_packet(self, pkt, out_port)
632 verify_no_other_packets(self)
633 delete_all_flows(self.controller)
634 delete_groups(self.controller, Groups)
635
636class _32ECMPL3(base_tests.SimpleDataPlane):
637 """
638 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
639 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
640 """
641
642 def runTest(self):
643 Groups = Queue.LifoQueue()
644 if len(config["port_map"]) < 2:
645 logging.info("Port count less than 2, can't run this case")
646 return
647
648 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
649 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
650 dip = 0xc0a80001
651 # Hashes Test Name and uses it as id for installing unique groups
652 ports = config["port_map"].keys()
653 for port in ports:
654 vlan_id = port
655 id = port
656 # add l2 interface group
657 l2_gid, msg = add_one_l2_interface_group(self.controller, port,
658 vlan_id=vlan_id,
659 is_tagged=True,
660 send_barrier=False)
661 dst_mac[5] = vlan_id
662 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
663 id=id, src_mac=intf_src_mac,
664 dst_mac=dst_mac)
665 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
666 # add vlan flow table
667 add_one_vlan_table_flow(self.controller, port, vlan_id,
668 flag=VLAN_TABLE_FLAG_ONLY_TAG)
669 # add termination flow
670 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
671 vlan_id)
672 # add unicast routing flow
673 dst_ip = dip + (vlan_id << 8)
674 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
675 0xffffffff, ecmp_msg.group_id)
676 Groups._put(l2_gid)
677 Groups._put(l3_msg.group_id)
678 Groups._put(ecmp_msg.group_id)
679 do_barrier(self.controller)
680
681 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
682 for in_port in ports:
683 mac_src = '00:00:00:22:22:%02X' % in_port
684 ip_src = '192.168.%02d.1' % in_port
685 for out_port in ports:
686 if in_port == out_port:
687 continue
688 ip_dst = '192.168.%02d.1' % out_port
689 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
690 vlan_vid=in_port,
691 eth_dst=switch_mac,
692 eth_src=mac_src, ip_ttl=64,
693 ip_src=ip_src,
694 ip_dst=ip_dst)
695 pkt = str(parsed_pkt)
696 self.dataplane.send(in_port, pkt)
697 # build expected packet
698 mac_dst = '00:00:00:22:22:%02X' % out_port
699 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
700 vlan_vid=out_port,
701 eth_dst=mac_dst, eth_src=switch_mac,
702 ip_ttl=63,
703 ip_src=ip_src, ip_dst=ip_dst)
704 pkt = str(exp_pkt)
705 verify_packet(self, pkt, out_port)
706 verify_no_other_packets(self)
707 delete_all_flows(self.controller)
708 delete_groups(self.controller, Groups)
709
710
711class _24VPN(base_tests.SimpleDataPlane):
712 """
713 Insert IP packet
714 Receive MPLS packet
715 """
716
717 def runTest(self):
718 if len(config["port_map"]) < 2:
719 logging.info("Port count less than 2, can't run this case")
720 return
721
722 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
723 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
724 dip = 0xc0a80001
725 ports = config["port_map"].keys()
726 Groups = Queue.LifoQueue()
727 for port in ports:
728 # add l2 interface group
729 id = port
730 vlan_id = port
Flavio Castro91d1a552016-05-17 16:59:44 -0700731 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
Flavio Castro2262fd42016-02-04 19:03:36 -0500732 dst_mac[5] = vlan_id
733 # add MPLS interface group
Flavio Castro91d1a552016-05-17 16:59:44 -0700734 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, id)
Flavio Castro2262fd42016-02-04 19:03:36 -0500735 # add MPLS L3 VPN group
736 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
737 self.controller,
738 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
739 index=id, ref_gid=mpls_gid, push_mpls_header=True,
740 set_mpls_label=port, set_bos=1, set_ttl=32)
741 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
742 do_barrier(self.controller)
743 # add vlan flow table
744 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0,
745 flag=VLAN_TABLE_FLAG_ONLY_TAG)
746 # add termination flow
747 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
748 vlan_id)
749 # add routing flow
750 dst_ip = dip + (vlan_id << 8)
751 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
752 0xffffff00, mpls_label_gid)
753 Groups._put(l2_gid)
754 Groups._put(mpls_gid)
755 Groups._put(mpls_label_gid)
756 do_barrier(self.controller)
757
758 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
759 for in_port in ports:
760 ip_src = '192.168.%02d.1' % (in_port)
761 for out_port in ports:
762 if in_port == out_port:
763 continue
764 ip_dst = '192.168.%02d.1' % (out_port)
765 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
766 vlan_vid=(in_port),
767 eth_dst=switch_mac, ip_ttl=64,
768 ip_src=ip_src,
769 ip_dst=ip_dst)
770 pkt = str(parsed_pkt)
771 self.dataplane.send(in_port, pkt)
772 # build expect packet
773 mac_dst = '00:00:00:22:22:%02X' % (out_port)
774 label = (out_port, 0, 1, 32)
775 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
776 vlan_vid=(out_port), ip_ttl=63,
777 ip_src=ip_src,
778 ip_dst=ip_dst, eth_dst=mac_dst,
779 eth_src=switch_mac, label=[label])
780 pkt = str(exp_pkt)
781 verify_packet(self, pkt, out_port)
782 verify_no_other_packets(self)
783 delete_all_flows(self.controller)
784 delete_groups(self.controller, Groups)
785
786
787class _24EcmpVpn(base_tests.SimpleDataPlane):
Flavio Castrod8f8af22015-12-02 18:19:26 -0500788 """
789 Insert IP packet
790 Receive MPLS packet
791 """
Flavio Castro72a45d52015-12-02 16:37:05 -0500792
Flavio Castro1c9b1252016-02-04 18:42:58 -0500793 def runTest(self):
794 if len(config["port_map"]) < 2:
Flavio Castro72a45d52015-12-02 16:37:05 -0500795 logging.info("Port count less than 2, can't run this case")
796 return
Flavio Castro1c9b1252016-02-04 18:42:58 -0500797 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
798 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
799 dip = 0xc0a80001
800 Groups = Queue.LifoQueue()
Flavio Castro72a45d52015-12-02 16:37:05 -0500801 ports = config["port_map"].keys()
802 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500803 # add l2 interface group
804 id = port
805 vlan_id = id
806 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
807 vlan_id, True, True)
808 dst_mac[5] = vlan_id
809 # add MPLS interface group
810 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
811 dst_mac, intf_src_mac,
812 vlan_id, id)
813 # add MPLS L3 VPN group
814 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
815 self.controller,
816 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
817 index=id, ref_gid=mpls_gid, push_mpls_header=True,
818 set_mpls_label=port, set_bos=1, set_ttl=32)
819 ecmp_msg = add_l3_ecmp_group(self.controller, id, [mpls_label_gid])
Flavio Castro80730822015-12-11 15:38:47 -0500820 do_barrier(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500821 # add vlan flow table
822 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0,
823 flag=VLAN_TABLE_FLAG_ONLY_TAG)
824 # add termination flow
825 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
826 vlan_id)
827 # add routing flow
828 dst_ip = dip + (vlan_id << 8)
829 # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
830 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
831 0xffffff00, ecmp_msg.group_id, vrf=0)
832 Groups._put(l2_gid)
833 Groups._put(mpls_gid)
834 Groups._put(mpls_label_gid)
835 Groups._put(ecmp_msg.group_id)
Flavio Castro80730822015-12-11 15:38:47 -0500836
837 do_barrier(self.controller)
838
839 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
840 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500841 mac_src = '00:00:00:22:22:%02X' % (in_port)
842 ip_src = '192.168.%02d.1' % (in_port)
Flavio Castro80730822015-12-11 15:38:47 -0500843 for out_port in ports:
844 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500845 continue
846 ip_dst = '192.168.%02d.1' % (out_port)
847 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
848 vlan_vid=(in_port),
849 eth_dst=switch_mac,
850 eth_src=mac_src, ip_ttl=64,
851 ip_src=ip_src,
852 ip_dst=ip_dst)
853 pkt = str(parsed_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500854 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500855 # build expect packet
856 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castro80730822015-12-11 15:38:47 -0500857 label = (out_port, 0, 1, 32)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500858 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
859 vlan_vid=(out_port), ip_ttl=63,
860 ip_src=ip_src,
861 ip_dst=ip_dst, eth_dst=mac_dst,
862 eth_src=switch_mac, label=[label])
863 pkt = str(exp_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500864 verify_packet(self, pkt, out_port)
865 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500866 delete_all_flows(self.controller)
867 delete_groups(self.controller, Groups)
868
castroflavioee294842016-01-06 15:54:28 -0800869
Flavio Castro2262fd42016-02-04 19:03:36 -0500870
871class _24ECMPL3(base_tests.SimpleDataPlane):
Flavio Castro80730822015-12-11 15:38:47 -0500872 """
Flavio Castro2262fd42016-02-04 19:03:36 -0500873 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
874 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
Flavio Castro80730822015-12-11 15:38:47 -0500875 """
Flavio Castro80730822015-12-11 15:38:47 -0500876
Flavio Castro1c9b1252016-02-04 18:42:58 -0500877 def runTest(self):
Flavio Castro2262fd42016-02-04 19:03:36 -0500878 Groups = Queue.LifoQueue()
Flavio Castro1c9b1252016-02-04 18:42:58 -0500879 if len(config["port_map"]) < 2:
Flavio Castro80730822015-12-11 15:38:47 -0500880 logging.info("Port count less than 2, can't run this case")
881 return
882
Flavio Castro1c9b1252016-02-04 18:42:58 -0500883 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
884 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
885 dip = 0xc0a80001
Flavio Castro2262fd42016-02-04 19:03:36 -0500886 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castro80730822015-12-11 15:38:47 -0500887 ports = config["port_map"].keys()
888 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500889 vlan_id = port
Flavio Castro2262fd42016-02-04 19:03:36 -0500890 id = port
891 # add l2 interface group
892 l2_gid, msg = add_one_l2_interface_group(self.controller, port,
893 vlan_id=vlan_id,
894 is_tagged=True,
895 send_barrier=False)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500896 dst_mac[5] = vlan_id
Flavio Castro2262fd42016-02-04 19:03:36 -0500897 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
898 id=id, src_mac=intf_src_mac,
899 dst_mac=dst_mac)
900 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
Flavio Castro1c9b1252016-02-04 18:42:58 -0500901 # add vlan flow table
Flavio Castro2262fd42016-02-04 19:03:36 -0500902 add_one_vlan_table_flow(self.controller, port, vlan_id,
Flavio Castro1c9b1252016-02-04 18:42:58 -0500903 flag=VLAN_TABLE_FLAG_ONLY_TAG)
904 # add termination flow
905 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
906 vlan_id)
Flavio Castro2262fd42016-02-04 19:03:36 -0500907 # add unicast routing flow
Flavio Castro1c9b1252016-02-04 18:42:58 -0500908 dst_ip = dip + (vlan_id << 8)
909 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
Flavio Castro2262fd42016-02-04 19:03:36 -0500910 0xffffff00, ecmp_msg.group_id)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500911 Groups._put(l2_gid)
Flavio Castro2262fd42016-02-04 19:03:36 -0500912 Groups._put(l3_msg.group_id)
913 Groups._put(ecmp_msg.group_id)
Flavio Castro72a45d52015-12-02 16:37:05 -0500914 do_barrier(self.controller)
915
916 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
917 for in_port in ports:
Flavio Castro2262fd42016-02-04 19:03:36 -0500918 mac_src = '00:00:00:22:22:%02X' % in_port
919 ip_src = '192.168.%02d.1' % in_port
Flavio Castro72a45d52015-12-02 16:37:05 -0500920 for out_port in ports:
921 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500922 continue
Flavio Castro2262fd42016-02-04 19:03:36 -0500923 ip_dst = '192.168.%02d.1' % out_port
Flavio Castro1c9b1252016-02-04 18:42:58 -0500924 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
Flavio Castro2262fd42016-02-04 19:03:36 -0500925 vlan_vid=in_port,
926 eth_dst=switch_mac,
927 eth_src=mac_src, ip_ttl=64,
Flavio Castro1c9b1252016-02-04 18:42:58 -0500928 ip_src=ip_src,
929 ip_dst=ip_dst)
930 pkt = str(parsed_pkt)
Flavio Castro72a45d52015-12-02 16:37:05 -0500931 self.dataplane.send(in_port, pkt)
Flavio Castro2262fd42016-02-04 19:03:36 -0500932 # build expected packet
933 mac_dst = '00:00:00:22:22:%02X' % out_port
934 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
935 vlan_vid=out_port,
936 eth_dst=mac_dst, eth_src=switch_mac,
937 ip_ttl=63,
938 ip_src=ip_src, ip_dst=ip_dst)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500939 pkt = str(exp_pkt)
Flavio Castro72a45d52015-12-02 16:37:05 -0500940 verify_packet(self, pkt, out_port)
941 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500942 delete_all_flows(self.controller)
943 delete_groups(self.controller, Groups)
944
Flavio Castroaba28ff2016-02-03 16:47:48 -0500945@disabled
Flavio Castro80730822015-12-11 15:38:47 -0500946class MPLSBUG(base_tests.SimpleDataPlane):
Flavio Castro80730822015-12-11 15:38:47 -0500947 def runTest(self):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500948 if len(config["port_map"]) < 2:
Flavio Castro80730822015-12-11 15:38:47 -0500949 logging.info("Port count less than 2, can't run this case")
950 return
Flavio Castro1c9b1252016-02-04 18:42:58 -0500951 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
952 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
953 dip = 0xc0a80001
954 Groups = Queue.LifoQueue()
Flavio Castro80730822015-12-11 15:38:47 -0500955 ports = config["port_map"].keys()
956 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500957 # add l2 interface group
958 vlan_id = port
959 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
960 vlan_id, True, False)
961 dst_mac[5] = vlan_id
962 # add L3 Unicast group
963 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
964 id=vlan_id, src_mac=intf_src_mac,
965 dst_mac=dst_mac)
966 # add vlan flow table
967 add_one_vlan_table_flow(self.controller, port, vlan_id,
968 flag=VLAN_TABLE_FLAG_ONLY_BOTH)
969 # add termination flow
970 add_termination_flow(self.controller, port, 0x8847, intf_src_mac,
971 vlan_id, goto_table=24)
972 # add mpls flow
Flavio Castro80730822015-12-11 15:38:47 -0500973 add_mpls_flow(self.controller, l3_msg.group_id, port)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500974 # add termination flow
975 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
976 vlan_id)
977 # add unicast routing flow
978 dst_ip = dip + (vlan_id << 8)
979 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
980 0xffffffff, l3_msg.group_id)
981 Groups._put(l2_gid)
982 Groups._put(l3_msg.group_id)
Flavio Castro80730822015-12-11 15:38:47 -0500983 do_barrier(self.controller)
984
985 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
986 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500987 mac_src = '00:00:00:22:22:%02X' % in_port
988 ip_src = '192.168.%02d.1' % in_port
Flavio Castro80730822015-12-11 15:38:47 -0500989 for out_port in ports:
990 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500991 continue
992 ip_dst = '192.168.%02d.1' % out_port
Flavio Castro80730822015-12-11 15:38:47 -0500993 switch_mac = "00:00:00:cc:cc:cc"
994 label = (out_port, 0, 1, 32)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500995 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
996 vlan_vid=in_port, ip_src=ip_src,
997 ip_dst=ip_dst, eth_dst=switch_mac,
998 eth_src=mac_src, label=[label])
999 pkt = str(parsed_pkt)
Flavio Castro80730822015-12-11 15:38:47 -05001000 self.dataplane.send(in_port, pkt)
1001
Flavio Castro1c9b1252016-02-04 18:42:58 -05001002 # build expect packet
1003 mac_dst = '00:00:00:22:22:%02X' % out_port
1004 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1005 vlan_vid=out_port,
1006 eth_dst=mac_dst, eth_src=switch_mac,
1007 ip_ttl=31, ip_src=ip_src,
1008 ip_dst=ip_dst)
1009 pkt = str(exp_pkt)
Flavio Castro80730822015-12-11 15:38:47 -05001010 verify_packet(self, pkt, out_port)
1011 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001012
1013 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1014 vlan_vid=in_port,
1015 eth_dst=switch_mac,
1016 eth_src=mac_src, ip_ttl=64,
1017 ip_src=ip_src,
1018 ip_dst=ip_dst)
1019 pkt = str(parsed_pkt)
Flavio Castro80730822015-12-11 15:38:47 -05001020 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001021 # build expected packet
1022 mac_dst = '00:00:00:22:22:%02X' % out_port
1023 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1024 vlan_vid=out_port,
1025 eth_dst=mac_dst, eth_src=switch_mac,
1026 ip_ttl=63,
1027 ip_src=ip_src, ip_dst=ip_dst)
1028 pkt = str(exp_pkt)
Flavio Castro80730822015-12-11 15:38:47 -05001029 verify_packet(self, pkt, out_port)
1030 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001031 delete_all_flows(self.controller)
1032 delete_groups(self.controller, Groups)
1033
Flavio Castro80730822015-12-11 15:38:47 -05001034
Flavio Castro12296312015-12-15 17:48:26 -05001035class L3McastToL2(base_tests.SimpleDataPlane):
castroflaviocc403a92015-12-15 14:04:19 -05001036 """
Flavio Castro12296312015-12-15 17:48:26 -05001037 Mcast routing to L2
castroflaviocc403a92015-12-15 14:04:19 -05001038 """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001039
castroflaviocc403a92015-12-15 14:04:19 -05001040 def runTest(self):
1041 """
1042 port1 (vlan 300)-> All Ports (vlan 300)
1043 """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001044 if len(config["port_map"]) < 3:
castroflavio4a09c962016-01-05 13:13:41 -08001045 logging.info("Port count less than 3, can't run this case")
Flavio Castro1c9b1252016-02-04 18:42:58 -05001046 assert (False)
castroflaviocc403a92015-12-15 14:04:19 -05001047 return
Flavio Castro1c9b1252016-02-04 18:42:58 -05001048 Groups = Queue.LifoQueue()
1049 vlan_id = 300
1050 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1051 intf_src_mac_str = ':'.join(['%02X' % x for x in intf_src_mac])
1052 dst_mac = [0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
1053 dst_mac_str = ':'.join(['%02X' % x for x in dst_mac])
1054 port1_mac = [0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
1055 port1_mac_str = ':'.join(['%02X' % x for x in port1_mac])
1056 src_ip = 0xc0a80101
1057 src_ip_str = "192.168.1.1"
1058 dst_ip = 0xe0010101
1059 dst_ip_str = "224.1.1.1"
castroflaviocc403a92015-12-15 14:04:19 -05001060
Flavio Castro1c9b1252016-02-04 18:42:58 -05001061 port1 = config["port_map"].keys()[0]
1062 port2 = config["port_map"].keys()[1]
castroflaviocc403a92015-12-15 14:04:19 -05001063
1064 switch_mac = [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00]
1065
Flavio Castro1c9b1252016-02-04 18:42:58 -05001066 # add l2 interface group
1067 l2_intf_group_list = []
castroflaviocc403a92015-12-15 14:04:19 -05001068 for port in config["port_map"].keys():
Flavio Castro1c9b1252016-02-04 18:42:58 -05001069 add_one_vlan_table_flow(self.controller, port, vlan_id,
1070 flag=VLAN_TABLE_FLAG_ONLY_TAG)
castroflaviocc403a92015-12-15 14:04:19 -05001071 if port == port2:
1072 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -05001073 l2_intf_gid, msg = add_one_l2_interface_group(self.controller, port,
1074 vlan_id=vlan_id,
1075 is_tagged=True,
1076 send_barrier=False)
castroflaviocc403a92015-12-15 14:04:19 -05001077 l2_intf_group_list.append(l2_intf_gid)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001078 Groups.put(l2_intf_gid)
castroflaviocc403a92015-12-15 14:04:19 -05001079
Flavio Castro1c9b1252016-02-04 18:42:58 -05001080 # add termination flow
1081 add_termination_flow(self.controller, port1, 0x0800, switch_mac,
1082 vlan_id)
castroflaviocc403a92015-12-15 14:04:19 -05001083
Flavio Castro1c9b1252016-02-04 18:42:58 -05001084 # add l3 interface group
1085 mcat_group_msg = add_l3_mcast_group(self.controller, vlan_id, 2,
1086 l2_intf_group_list)
1087 add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip,
1088 mcat_group_msg.group_id)
1089 Groups._put(mcat_group_msg.group_id)
castroflaviocc403a92015-12-15 14:04:19 -05001090
Flavio Castro1c9b1252016-02-04 18:42:58 -05001091 parsed_pkt = simple_udp_packet(pktlen=100,
Flavio Castro89933f22016-02-03 15:53:16 -05001092 dl_vlan_enable=True,
1093 vlan_vid=vlan_id,
castroflaviocc403a92015-12-15 14:04:19 -05001094 eth_dst=dst_mac_str,
1095 eth_src=port1_mac_str,
1096 ip_ttl=64,
1097 ip_src=src_ip_str,
1098 ip_dst=dst_ip_str)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001099 pkt = str(parsed_pkt)
castroflaviocc403a92015-12-15 14:04:19 -05001100 self.dataplane.send(port1, pkt)
1101 for port in config["port_map"].keys():
Flavio Castro12296312015-12-15 17:48:26 -05001102 if port == port2 or port == port1:
Flavio Castro1c9b1252016-02-04 18:42:58 -05001103 verify_no_packet(self, pkt, port)
1104 continue
castroflaviocc403a92015-12-15 14:04:19 -05001105 verify_packet(self, pkt, port)
1106 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001107 delete_all_flows(self.controller)
1108 delete_groups(self.controller, Groups)
1109
Flavio Castro12296312015-12-15 17:48:26 -05001110class L3McastToL3(base_tests.SimpleDataPlane):
1111 """
1112 Mcast routing
1113 """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001114
1115 def runTest(self):
Flavio Castro12296312015-12-15 17:48:26 -05001116 """
1117 port1 (vlan 1)-> port 2 (vlan 2)
1118 """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001119 Groups = Queue.LifoQueue()
1120 if len(config["port_map"]) < 3:
castroflavio4a09c962016-01-05 13:13:41 -08001121 logging.info("Port count less than 3, can't run this case")
Flavio Castro1c9b1252016-02-04 18:42:58 -05001122 assert (False)
Flavio Castro12296312015-12-15 17:48:26 -05001123 return
1124
Flavio Castro1c9b1252016-02-04 18:42:58 -05001125 vlan_id = 1
1126 port2_out_vlan = 2
1127 port3_out_vlan = 3
1128 in_vlan = 1 # macast group vid shall use input vlan diffe from l3 interface use output vlan
1129 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1130 intf_src_mac_str = ':'.join(['%02X' % x for x in intf_src_mac])
1131 dst_mac = [0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
1132 dst_mac_str = ':'.join(['%02X' % x for x in dst_mac])
1133 port1_mac = [0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
1134 port1_mac_str = ':'.join(['%02X' % x for x in port1_mac])
1135 src_ip = 0xc0a80101
1136 src_ip_str = "192.168.1.1"
1137 dst_ip = 0xe0010101
1138 dst_ip_str = "224.1.1.1"
Flavio Castro12296312015-12-15 17:48:26 -05001139
Flavio Castro1c9b1252016-02-04 18:42:58 -05001140 port1 = config["port_map"].keys()[0]
1141 port2 = config["port_map"].keys()[1]
1142 port3 = config["port_map"].keys()[2]
Flavio Castro12296312015-12-15 17:48:26 -05001143
Flavio Castro1c9b1252016-02-04 18:42:58 -05001144 # add l2 interface group
1145 for port in config["port_map"].keys():
1146 l2gid, msg = add_one_l2_interface_group(self.controller, port,
1147 vlan_id=vlan_id,
1148 is_tagged=False,
1149 send_barrier=False)
1150 # add vlan flow table
1151 add_one_vlan_table_flow(self.controller, port, vlan_id,
1152 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1153 vlan_id += 1
1154 Groups._put(l2gid)
Flavio Castro12296312015-12-15 17:48:26 -05001155
Flavio Castro1c9b1252016-02-04 18:42:58 -05001156 # add termination flow
1157 add_termination_flow(self.controller, port1, 0x0800,
1158 [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
1159
1160 # add l3 interface group
1161 port2_ucast_msg = add_l3_interface_group(self.controller, port2,
1162 port2_out_vlan, 2,
1163 intf_src_mac)
1164 port3_ucast_msg = add_l3_interface_group(self.controller, port3,
1165 port3_out_vlan, 3,
1166 intf_src_mac)
1167 mcat_group_msg = add_l3_mcast_group(self.controller, in_vlan, 2,
1168 [port2_ucast_msg.group_id,
1169 port3_ucast_msg.group_id])
1170 add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip,
1171 mcat_group_msg.group_id)
1172 Groups._put(port2_ucast_msg.group_id)
1173 Groups._put(port3_ucast_msg.group_id)
1174 Groups._put(mcat_group_msg.group_id)
1175 parsed_pkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
1176 vlan_vid=1,
Flavio Castro12296312015-12-15 17:48:26 -05001177 eth_dst=dst_mac_str,
1178 eth_src=port1_mac_str,
1179 ip_ttl=64,
1180 ip_src=src_ip_str,
1181 ip_dst=dst_ip_str)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001182 pkt = str(parsed_pkt)
1183 self.dataplane.send(port1, pkt)
1184 parsed_pkt = simple_udp_packet(pktlen=96,
Flavio Castro12296312015-12-15 17:48:26 -05001185 eth_dst=dst_mac_str,
1186 eth_src=intf_src_mac_str,
1187 ip_ttl=63,
1188 ip_src=src_ip_str,
1189 ip_dst=dst_ip_str)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001190 pkt = str(parsed_pkt)
Flavio Castro12296312015-12-15 17:48:26 -05001191 verify_packet(self, pkt, port2)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001192 verify_packet(self, pkt, port3)
1193 verify_no_other_packets(self)
1194 delete_all_flows(self.controller)
1195 delete_groups(self.controller, Groups)
Flavio Castro54947942016-02-03 16:05:20 -05001196
1197
Flavio Castrob702a2f2016-04-10 22:01:48 -04001198class _MplsFwd(base_tests.SimpleDataPlane):
Flavio Castro12296312015-12-15 17:48:26 -05001199 """
Flavio Castro54947942016-02-03 16:05:20 -05001200 Insert IP packet
1201 Receive MPLS packet
castroflavio30c6cc52016-01-07 15:19:42 -08001202 """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001203 def runTest(self):
1204 Groups = Queue.LifoQueue()
1205 if len(config["port_map"]) < 2:
castroflavio30c6cc52016-01-07 15:19:42 -08001206 logging.info("Port count less than 2, can't run this case")
1207 return
Flavio Castrobcc3dbc2016-04-06 11:05:03 -04001208 dip = 0xc0a80001
Flavio Castro1c9b1252016-02-04 18:42:58 -05001209 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1210 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1211 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
castroflavio30c6cc52016-01-07 15:19:42 -08001212 ports = config["port_map"].keys()
1213 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -05001214 # add l2 interface group
1215 id = port
1216 vlan_id = id
1217 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
1218 vlan_id, True, False)
1219 dst_mac[5] = vlan_id
Flavio Castrob702a2f2016-04-10 22:01:48 -04001220 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
1221 dst_mac, intf_src_mac,
1222 vlan_id, id)
1223 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
1224 self.controller,
1225 subtype=OFDPA_MPLS_GROUP_SUBTYPE_SWAP_LABEL,
1226 index=id, ref_gid=mpls_gid, push_mpls_header=False,
1227 set_mpls_label=port, set_bos=1)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001228 # add vlan flow table
1229 add_one_vlan_table_flow(self.controller, port, vlan_id,
1230 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1231 # add termination flow
1232 add_termination_flow(self.controller, port, 0x8847, intf_src_mac,
1233 vlan_id, goto_table=24)
Flavio Castro8ca52542016-04-11 11:24:49 -04001234 add_mpls_flow(self.controller, mpls_label_gid, port, goto_table=29)
Flavio Castrobcc3dbc2016-04-06 11:05:03 -04001235 dst_ip = dip + (vlan_id << 8)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001236 Groups._put(l2_gid)
Flavio Castrob702a2f2016-04-10 22:01:48 -04001237 Groups._put(mpls_gid)
Flavio Castro8ca52542016-04-11 11:24:49 -04001238 Groups._put(mpls_label_gid)
castroflavio30c6cc52016-01-07 15:19:42 -08001239 do_barrier(self.controller)
1240
1241 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1242 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -05001243 ip_src = '192.168.%02d.1' % (in_port)
castroflavio30c6cc52016-01-07 15:19:42 -08001244 for out_port in ports:
1245 if in_port == out_port:
Flavio Castro54947942016-02-03 16:05:20 -05001246 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -05001247 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castro54947942016-02-03 16:05:20 -05001248
1249 label = (out_port, 0, 1, 32)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001250 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
1251 vlan_vid=(in_port), ip_src=ip_src,
1252 ip_dst=ip_dst, eth_dst=switch_mac,
1253 label=[label])
1254 pkt = str(parsed_pkt)
castroflavio30c6cc52016-01-07 15:19:42 -08001255 self.dataplane.send(in_port, pkt)
Flavio Castro54947942016-02-03 16:05:20 -05001256
Flavio Castro1c9b1252016-02-04 18:42:58 -05001257 # build expect packet
1258 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castrob702a2f2016-04-10 22:01:48 -04001259 label = (out_port, 0, 1, 31)
1260 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
1261 vlan_vid=(out_port), ip_src=ip_src,
1262 ip_dst=ip_dst, eth_src=switch_mac,
1263 eth_dst=mac_dst,label=[label])
1264 pkt = str(exp_pkt)
1265 verify_packet(self, pkt, out_port)
1266 verify_no_other_packets(self)
1267 delete_all_flows(self.controller)
1268 delete_groups(self.controller, Groups)
1269
1270class _MplsTermination(base_tests.SimpleDataPlane):
1271 """
1272 Insert IP packet
1273 Receive MPLS packet
1274 """
1275 def runTest(self):
1276 Groups = Queue.LifoQueue()
1277 if len(config["port_map"]) < 2:
1278 logging.info("Port count less than 2, can't run this case")
1279 return
1280 dip = 0xc0a80001
1281 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1282 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1283 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
1284 ports = config["port_map"].keys()
1285 for port in ports:
1286 # add l2 interface group
1287 vlan_id, id, dst_mac[5] = port, port, port
1288 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
1289 vlan_id, True, False)
1290 # add L3 Unicast group
1291 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
1292 id=id, src_mac=intf_src_mac,dst_mac=dst_mac)
1293 # add L3 ecmp group
1294 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
1295 # add vlan flow table
1296 add_one_vlan_table_flow(self.controller, port, vlan_id,
1297 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1298 # add termination flow
1299 add_termination_flow(self.controller, port, 0x8847, intf_src_mac,
1300 vlan_id, goto_table=24)
1301 #add_mpls_flow(self.controller, ecmp_msg.group_id, port)
1302 add_mpls_flow(self.controller, label=port)
1303 dst_ip = dip + (vlan_id << 8)
1304 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00,
1305 ecmp_msg.group_id, 1)
1306 Groups._put(l2_gid)
1307 Groups._put(l3_msg.group_id)
1308 Groups._put(ecmp_msg.group_id)
1309 do_barrier(self.controller)
1310
1311 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1312 for in_port in ports:
1313 ip_src = '192.168.%02d.1' % (in_port)
1314 for out_port in ports:
1315 if in_port == out_port:
1316 continue
1317 ip_dst = '192.168.%02d.1' % (out_port)
1318 label = (out_port, 0, 1, 32)
1319 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,vlan_vid=(in_port),
1320 ip_src=ip_src,ip_dst=ip_dst, eth_dst=switch_mac,label=[label])
1321 pkt = str(parsed_pkt)
1322 self.dataplane.send(in_port, pkt)
1323 # build expect packet
1324 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001325 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1326 vlan_vid=(out_port),
1327 eth_dst=mac_dst, eth_src=switch_mac,
1328 ip_ttl=31, ip_src=ip_src,
1329 ip_dst=ip_dst)
1330 pkt = str(exp_pkt)
castroflavio30c6cc52016-01-07 15:19:42 -08001331 verify_packet(self, pkt, out_port)
1332 verify_no_other_packets(self)
Flavio Castro76af6482016-04-06 11:42:29 -04001333 delete_all_flows(self.controller)
1334 delete_groups(self.controller, Groups)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001335
1336
1337class _24UcastTagged(base_tests.SimpleDataPlane):
1338 """
1339 Verify a IP forwarding works for a /32 rule to L3 Unicast Interface
1340 """
1341
1342 def runTest(self):
1343 test_id = 26
1344 if len(config["port_map"]) < 2:
1345 logging.info("Port count less than 2, can't run this case")
1346 return
1347
1348 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1349 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1350 dip = 0xc0a80001
1351 ports = config["port_map"].keys()
1352 Groups = Queue.LifoQueue()
1353 for port in ports:
1354 # add l2 interface group
1355 vlan_id = port + test_id
1356 l2gid, msg = add_one_l2_interface_group(self.controller, port,
1357 vlan_id=vlan_id,
1358 is_tagged=True,
1359 send_barrier=False)
1360 dst_mac[5] = vlan_id
1361 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
1362 id=vlan_id, src_mac=intf_src_mac,
1363 dst_mac=dst_mac)
1364 # add vlan flow table
1365 add_one_vlan_table_flow(self.controller, port, vlan_id,
1366 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1367 # add termination flow
1368 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
1369 vlan_id)
1370 # add unicast routing flow
1371 dst_ip = dip + (vlan_id << 8)
1372 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
1373 0xffffff00, l3_msg.group_id)
1374 Groups.put(l2gid)
1375 Groups.put(l3_msg.group_id)
1376 do_barrier(self.controller)
1377
1378 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1379 for in_port in ports:
1380 mac_src = '00:00:00:22:22:%02X' % (test_id + in_port)
1381 ip_src = '192.168.%02d.1' % (test_id + in_port)
1382 for out_port in ports:
1383 if in_port == out_port:
1384 continue
1385 ip_dst = '192.168.%02d.1' % (test_id + out_port)
1386 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1387 vlan_vid=(test_id + in_port),
1388 eth_dst=switch_mac,
1389 eth_src=mac_src, ip_ttl=64,
1390 ip_src=ip_src,
1391 ip_dst=ip_dst)
1392 pkt = str(parsed_pkt)
1393 self.dataplane.send(in_port, pkt)
1394 # build expected packet
1395 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
1396 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1397 vlan_vid=(test_id + out_port),
1398 eth_dst=mac_dst, eth_src=switch_mac,
1399 ip_ttl=63,
1400 ip_src=ip_src, ip_dst=ip_dst)
1401 pkt = str(exp_pkt)
1402 verify_packet(self, pkt, out_port)
1403 verify_no_other_packets(self)
1404 delete_all_flows(self.controller)
1405 delete_groups(self.controller, Groups)
Flavio Castro91d1a552016-05-17 16:59:44 -07001406
1407class _0Ucast(base_tests.SimpleDataPlane):
1408 """
1409 Verify a IP forwarding works for a /0 rule to L3 Unicast Interface
1410 """
1411
1412 def runTest(self):
1413 if len(config["port_map"]) < 2:
1414 logging.info("Port count less than 2, can't run this case")
1415 return
1416
1417 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1418 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1419 dip = 0xc0a80001
1420 ports = config["port_map"].keys()
1421 Groups = Queue.LifoQueue()
1422 for port in ports:
1423 # add l2 interface group
1424 vlan_id = port
1425 l2gid, msg = add_one_l2_interface_group(self.controller, port,
1426 vlan_id=vlan_id,
1427 is_tagged=True,
1428 send_barrier=False)
1429 dst_mac[5] = vlan_id
1430 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
1431 id=vlan_id, src_mac=intf_src_mac,
1432 dst_mac=dst_mac)
1433 # add vlan flow table
1434 add_one_vlan_table_flow(self.controller, port, vlan_id,
1435 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1436 # add termination flow
1437 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
1438 vlan_id)
1439 # add unicast routing flow
1440 dst_ip = dip + (vlan_id << 8)
1441 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
1442 0xffffffff, l3_msg.group_id)
1443 Groups.put(l2gid)
1444 Groups.put(l3_msg.group_id)
1445 l3_gid = encode_l3_unicast_group_id(ports[0])
1446 dst_ip = 0x0
1447 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, l3_gid)
1448 do_barrier(self.controller)
1449
1450 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1451 for in_port in ports:
1452 mac_src = '00:00:00:22:22:%02X' % (in_port)
1453 ip_src = '192.168.%02d.1' % (in_port)
1454 for out_port in ports:
1455 if in_port == out_port:
1456 continue
1457 ip_dst = '192.168.%02d.1' % (out_port)
1458 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1459 vlan_vid=(in_port),
1460 eth_dst=switch_mac,
1461 eth_src=mac_src, ip_ttl=64,
1462 ip_src=ip_src,
1463 ip_dst=ip_dst)
1464 pkt = str(parsed_pkt)
1465 self.dataplane.send(in_port, pkt)
1466 # build expected packet
1467 mac_dst = '00:00:00:22:22:%02X' % (out_port)
1468 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1469 vlan_vid=(out_port),
1470 eth_dst=mac_dst, eth_src=switch_mac,
1471 ip_ttl=63,
1472 ip_src=ip_src, ip_dst=ip_dst)
1473 pkt = str(exp_pkt)
1474 verify_packet(self, pkt, out_port)
1475 verify_no_other_packets(self)
1476 ip_dst='1.168.%02d.1' % ports[0]
1477 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
1478 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst)
1479 pkt=str(parsed_pkt)
1480 self.dataplane.send(in_port, pkt)
1481 #build expect packet
1482 mac_dst='00:00:00:22:22:%02X' % ports[0]
1483 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=ports[0], ip_ttl=63, ip_src=ip_src,
1484 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac)
1485 pkt=str(exp_pkt)
1486 verify_packet(self, pkt, ports[0])
1487 verify_no_other_packets(self)
1488
1489 delete_all_flows(self.controller)
1490 delete_groups(self.controller, Groups)
1491
1492
1493