blob: 14fa139d8b5ef4d8fbca2fb2648ac7cf80eabda7 [file] [log] [blame]
Flavio Castro05d20bc2015-11-16 15:06:14 -05001"""
Flavio Castro423df652016-05-17 20:14:08 -04002Check README file
Flavio Castro05d20bc2015-11-16 15:06:14 -05003"""
Flavio Castro1c9b1252016-02-04 18:42:58 -05004import Queue
Flavio Castro05d20bc2015-11-16 15:06:14 -05005
Flavio Castro05d20bc2015-11-16 15:06:14 -05006from oftest import config
Flavio Castro67d8bd52016-02-03 14:22:14 -05007import inspect
Flavio Castro167f5bd2015-12-02 19:33:53 -05008import logging
9import oftest.base_tests as base_tests
Flavio Castro05d20bc2015-11-16 15:06:14 -050010import ofp
11from oftest.testutils import *
12from accton_util import *
Flavio Castrod8f8af22015-12-02 18:19:26 -050013
Flavio Castro1c9b1252016-02-04 18:42:58 -050014
Flavio Castro7fb6ca92015-12-16 15:50:14 -050015class PacketInUDP(base_tests.SimpleDataPlane):
Flavio Castro6d498522015-12-15 14:05:04 -050016 """
Flavio Castro1c9b1252016-02-04 18:42:58 -050017 Verify a ACL rule that matches on IP_PROTO 2 will not match a UDP packet.
18 Next it verify a rule that matches on IP_PROTO 17 WILL match a UDP packet.
Flavio Castro6d498522015-12-15 14:05:04 -050019 """
20
21 def runTest(self):
Flavio Castro1c9b1252016-02-04 18:42:58 -050022 parsed_vlan_pkt = simple_udp_packet(pktlen=104,
23 vlan_vid=0x1001,
24 dl_vlan_enable=True)
Flavio Castro6d498522015-12-15 14:05:04 -050025 vlan_pkt = str(parsed_vlan_pkt)
Flavio Castro6d498522015-12-15 14:05:04 -050026 # create match
27 match = ofp.match()
28 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
Flavio Castro1c9b1252016-02-04 18:42:58 -050029 match.oxm_list.append(ofp.oxm.ip_proto(2))
Flavio Castro6d498522015-12-15 14:05:04 -050030 request = ofp.message.flow_add(
Flavio Castro1c9b1252016-02-04 18:42:58 -050031 table_id=60,
32 cookie=42,
33 match=match,
34 instructions=[
35 ofp.instruction.apply_actions(
36 actions=[
37 ofp.action.output(
38 port=ofp.OFPP_CONTROLLER,
39 max_len=ofp.OFPCML_NO_BUFFER)]), ],
40 buffer_id=ofp.OFP_NO_BUFFER,
41 priority=1)
42 logging.info("Inserting packet in flow to controller")
43 self.controller.message_send(request)
44
45 for of_port in config["port_map"].keys():
46 logging.info("PacketInMiss test, port %d", of_port)
47 self.dataplane.send(of_port, vlan_pkt)
48
Flavio Castro6da7e462016-02-04 18:56:29 -050049 verify_no_packet_in(self, vlan_pkt, of_port)
50 delete_all_flows(self.controller)
Flavio Castro6d498522015-12-15 14:05:04 -050051 do_barrier(self.controller)
52
Flavio Castro1c9b1252016-02-04 18:42:58 -050053 match = ofp.match()
54 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
55 match.oxm_list.append(ofp.oxm.ip_proto(17))
56 request = ofp.message.flow_add(
57 table_id=60,
58 cookie=42,
59 match=match,
60 instructions=[
61 ofp.instruction.apply_actions(
62 actions=[
63 ofp.action.output(
64 port=ofp.OFPP_CONTROLLER,
65 max_len=ofp.OFPCML_NO_BUFFER)]), ],
66 buffer_id=ofp.OFP_NO_BUFFER,
67 priority=1)
68 logging.info("Inserting packet in flow to controller")
69 self.controller.message_send(request)
Flavio Castro6da7e462016-02-04 18:56:29 -050070 do_barrier(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -050071
Flavio Castro6d498522015-12-15 14:05:04 -050072 for of_port in config["port_map"].keys():
73 logging.info("PacketInMiss test, port %d", of_port)
74 self.dataplane.send(of_port, vlan_pkt)
75
76 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
77
78 verify_no_other_packets(self)
Flavio Castroaf2b4502016-02-02 17:41:32 -050079
Flavio Castro1c9b1252016-02-04 18:42:58 -050080 delete_all_flows(self.controller)
81
Flavio Castroaf2b4502016-02-02 17:41:32 -050082
Flavio Castro67d8bd52016-02-03 14:22:14 -050083@disabled
Flavio Castro7fb6ca92015-12-16 15:50:14 -050084class ArpNL2(base_tests.SimpleDataPlane):
Flavio Castro1c9b1252016-02-04 18:42:58 -050085 def runTest(self):
Flavio Castro7fb6ca92015-12-16 15:50:14 -050086 delete_all_flows(self.controller)
87 delete_all_groups(self.controller)
88
89 ports = sorted(config["port_map"].keys())
90 match = ofp.match()
91 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
92 request = ofp.message.flow_add(
Flavio Castro1c9b1252016-02-04 18:42:58 -050093 table_id=60,
94 cookie=42,
95 match=match,
96 instructions=[
97 ofp.instruction.apply_actions(
98 actions=[
99 ofp.action.output(
100 port=ofp.OFPP_CONTROLLER,
101 max_len=ofp.OFPCML_NO_BUFFER)]),
102 ],
103 buffer_id=ofp.OFP_NO_BUFFER,
104 priority=40000)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500105 self.controller.message_send(request)
106 for port in ports:
Flavio Castro932014b2016-01-05 18:29:15 -0500107 add_one_l2_interface_group(self.controller, port, 1, False, False)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500108 add_one_vlan_table_flow(self.controller, port, 1,
109 flag=VLAN_TABLE_FLAG_ONLY_BOTH)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500110 group_id = encode_l2_interface_group_id(1, port)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500111 add_bridge_flow(self.controller,
112 [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id,
113 True)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500114 do_barrier(self.controller)
115 parsed_arp_pkt = simple_arp_packet()
116 arp_pkt = str(parsed_arp_pkt)
117
118 for out_port in ports:
119 self.dataplane.send(out_port, arp_pkt)
120 verify_packet_in(self, arp_pkt, out_port, ofp.OFPR_ACTION)
121 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500122 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500123 for in_port in ports:
124 if in_port == out_port:
125 continue
126 # change source based on port number to avoid packet-ins from learning
Flavio Castro1c9b1252016-02-04 18:42:58 -0500127 mac_src = '00:12:34:56:78:%02X' % in_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500128 parsed_pkt = simple_tcp_packet(eth_dst=mac_dst, eth_src=mac_src)
129 pkt = str(parsed_pkt)
130 self.dataplane.send(in_port, pkt)
131
132 for ofport in ports:
133 if ofport in [out_port]:
134 verify_packet(self, pkt, ofport)
135 else:
136 verify_no_packet(self, pkt, ofport)
137
138 verify_no_other_packets(self)
139
Flavio Castro1c9b1252016-02-04 18:42:58 -0500140
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500141class PacketInArp(base_tests.SimpleDataPlane):
142 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500143 Verify an ACL rule matching on ethertyper 0x806 will result in a packet-in
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500144 """
145
146 def runTest(self):
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500147 parsed_arp_pkt = simple_arp_packet()
148 arp_pkt = str(parsed_arp_pkt)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500149 # create match
150 match = ofp.match()
151 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
152 request = ofp.message.flow_add(
Flavio Castro1c9b1252016-02-04 18:42:58 -0500153 table_id=60,
154 cookie=42,
155 match=match,
156 instructions=[
157 ofp.instruction.apply_actions(
158 actions=[
159 ofp.action.output(
160 port=ofp.OFPP_CONTROLLER,
161 max_len=ofp.OFPCML_NO_BUFFER)]),
162 ],
163 buffer_id=ofp.OFP_NO_BUFFER,
164 priority=1)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500165
166 logging.info("Inserting packet in flow to controller")
167 self.controller.message_send(request)
168 do_barrier(self.controller)
169
170 for of_port in config["port_map"].keys():
171 logging.info("PacketInMiss test, port %d", of_port)
172 self.dataplane.send(of_port, arp_pkt)
173
174 verify_packet_in(self, arp_pkt, of_port, ofp.OFPR_ACTION)
175
176 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500177 delete_all_flows(self.controller)
178
Flavio Castro91d1a552016-05-17 16:59:44 -0700179class PacketInIPTable(base_tests.SimpleDataPlane):
180 """
181 Test packet in function on IPTABLE
182 Send a packet to each dataplane port and verify that a packet
183 in message is received from the controller for each
184 #todo verify you stop receiving after adding rule
185 """
186
187 def runTest(self):
188
189 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
190 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
191 dip=0xc0a80001
192 ports = sorted(config["port_map"].keys())
193 Groups = Queue.LifoQueue()
194
195 for port in ports:
196 #add l2 interface group
197 vlan_id=port
198 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
199 dst_mac[5]=vlan_id
200 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
201 #add vlan flow table
202 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
203 #add termination flow
204 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
205 #add unicast routing flow
206 dst_ip = dip + (vlan_id<<8)
207 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, l3_msg.group_id, send_ctrl=True)
208 Groups.put(l3_msg.group_id)
209
210 do_barrier(self.controller)
211
212 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
213 for in_port in ports:
214 mac_src='00:00:00:22:22:%02X' % in_port
215 ip_src='192.168.%02d.1' % in_port
216 for out_port in ports:
217 if in_port == out_port:
218 continue
219 ip_dst='192.168.%02d.1' % out_port
220 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
221 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
222 ip_dst=ip_dst)
223 pkt=str(parsed_pkt)
224 self.dataplane.send(in_port, pkt)
225 verify_packet_in(self, pkt, in_port, ofp.OFPR_ACTION)
226 #verify_no_other_packets(self)
227 delete_all_flows(self.controller)
228 delete_groups(self.controller, Groups)
229
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500230class L2FloodQinQ(base_tests.SimpleDataPlane):
231 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500232 Verify a tagged frame can be flooded based on its outer vlan
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500233 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500234
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500235 def runTest(self):
236 ports = sorted(config["port_map"].keys())
Flavio Castro1c9b1252016-02-04 18:42:58 -0500237 vlan_id = 1
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500238
Flavio Castro1c9b1252016-02-04 18:42:58 -0500239 Groups = Queue.LifoQueue()
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500240 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500241 L2gid, l2msg = add_one_l2_interface_group(self.controller, port,
242 vlan_id, True, False)
243 add_one_vlan_table_flow(self.controller, port, vlan_id,
244 flag=VLAN_TABLE_FLAG_ONLY_TAG)
245 Groups.put(L2gid)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500246
Flavio Castro1c9b1252016-02-04 18:42:58 -0500247 msg = add_l2_flood_group(self.controller, ports, vlan_id, vlan_id)
Flavio Castro6da7e462016-02-04 18:56:29 -0500248 Groups.put(msg.group_id)
Flavio Castro8628adb2016-02-03 17:30:57 -0500249 add_bridge_flow(self.controller, None, vlan_id, msg.group_id, True)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500250 do_barrier(self.controller)
251
Flavio Castro1c9b1252016-02-04 18:42:58 -0500252 # verify flood
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500253 for ofport in ports:
254 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500255 mac_src = '00:12:34:56:78:%02X' % ofport
256 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108,
257 out_dl_vlan_enable=True,
258 out_vlan_vid=vlan_id,
259 in_dl_vlan_enable=True,
260 in_vlan_vid=10,
261 eth_dst='00:12:34:56:78:9a',
262 eth_src=mac_src)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500263 pkt = str(parsed_pkt)
264 self.dataplane.send(ofport, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500265 # self won't rx packet
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500266 verify_no_packet(self, pkt, ofport)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500267 # others will rx packet
268 tmp_ports = list(ports)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500269 tmp_ports.remove(ofport)
270 verify_packets(self, pkt, tmp_ports)
271
272 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500273 delete_all_flows(self.controller)
274 delete_groups(self.controller, Groups)
275
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500276@disabled
Flavio Castro184cefe2015-11-19 20:52:49 -0500277class L2FloodTagged(base_tests.SimpleDataPlane):
278 """
279 Test L2 flood to a vlan
280 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 -0500281 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500282
Flavio Castro184cefe2015-11-19 20:52:49 -0500283 def runTest(self):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500284 # Hashes Test Name and uses it as id for installing unique groups
285 vlan_id = abs(hash(inspect.stack()[0][3])) % (256)
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500286 print vlan_id
Flavio Castroaba28ff2016-02-03 16:47:48 -0500287
Flavio Castro184cefe2015-11-19 20:52:49 -0500288 ports = sorted(config["port_map"].keys())
Flavio Castro34352e72015-12-07 20:01:51 -0500289
Flavio Castro184cefe2015-11-19 20:52:49 -0500290 delete_all_flows(self.controller)
291 delete_all_groups(self.controller)
292
Flavio Castro184cefe2015-11-19 20:52:49 -0500293 # Installing flows to avoid packet-in
294 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500295 add_one_l2_interface_group(self.controller, port, vlan_id, True,
296 False)
297 add_one_vlan_table_flow(self.controller, port, vlan_id,
298 flag=VLAN_TABLE_FLAG_ONLY_TAG)
299 msg = add_l2_flood_group(self.controller, ports, vlan_id, vlan_id)
Flavio Castroaba28ff2016-02-03 16:47:48 -0500300 add_bridge_flow(self.controller, None, vlan_id, msg.group_id, True)
Flavio Castro184cefe2015-11-19 20:52:49 -0500301 do_barrier(self.controller)
302
Flavio Castro1c9b1252016-02-04 18:42:58 -0500303 # verify flood
Flavio Castro184cefe2015-11-19 20:52:49 -0500304 for ofport in ports:
305 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500306 pkt = str(simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vlan_id,
307 eth_dst='00:12:34:56:78:9a'))
Flavio Castro184cefe2015-11-19 20:52:49 -0500308 self.dataplane.send(ofport, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500309 # self won't rx packet
Flavio Castro184cefe2015-11-19 20:52:49 -0500310 verify_no_packet(self, pkt, ofport)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500311 # others will rx packet
312 tmp_ports = list(ports)
Flavio Castro184cefe2015-11-19 20:52:49 -0500313 tmp_ports.remove(ofport)
314 verify_packets(self, pkt, tmp_ports)
Flavio Castro184cefe2015-11-19 20:52:49 -0500315 verify_no_other_packets(self)
Flavio Castroaabb5792015-11-18 19:03:50 -0500316
Flavio Castro1c9b1252016-02-04 18:42:58 -0500317
Flavio Castroaabb5792015-11-18 19:03:50 -0500318class L2UnicastTagged(base_tests.SimpleDataPlane):
319 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500320 Verify L2 forwarding works
Flavio Castroaabb5792015-11-18 19:03:50 -0500321 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500322
Flavio Castroaabb5792015-11-18 19:03:50 -0500323 def runTest(self):
324 ports = sorted(config["port_map"].keys())
Flavio Castro1c9b1252016-02-04 18:42:58 -0500325 vlan_id = 1;
326 Groups = Queue.LifoQueue()
Flavio Castroaabb5792015-11-18 19:03:50 -0500327 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500328 L2gid, l2msg = add_one_l2_interface_group(self.controller, port,
329 vlan_id, True, False)
330 add_one_vlan_table_flow(self.controller, port, vlan_id,
331 flag=VLAN_TABLE_FLAG_ONLY_TAG)
332 Groups.put(L2gid)
333 add_bridge_flow(self.controller,
334 [0x00, 0x12, 0x34, 0x56, 0x78, port], vlan_id,
335 L2gid, True)
Flavio Castro6efe1862015-11-18 16:28:06 -0500336 do_barrier(self.controller)
337
Flavio Castroaabb5792015-11-18 19:03:50 -0500338 for out_port in ports:
339 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500340 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castroaabb5792015-11-18 19:03:50 -0500341 for in_port in ports:
342 if in_port == out_port:
343 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -0500344 pkt = str(
345 simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vlan_id,
346 eth_dst=mac_dst))
Flavio Castroaabb5792015-11-18 19:03:50 -0500347 self.dataplane.send(in_port, pkt)
Flavio Castroaabb5792015-11-18 19:03:50 -0500348 for ofport in ports:
349 if ofport in [out_port]:
350 verify_packet(self, pkt, ofport)
351 else:
352 verify_no_packet(self, pkt, ofport)
Flavio Castroaabb5792015-11-18 19:03:50 -0500353 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500354 delete_all_flows(self.controller)
355 delete_groups(self.controller, Groups)
356
Flavio Castro6efe1862015-11-18 16:28:06 -0500357
Flavio Castrob6773032015-11-19 22:49:24 -0500358class Mtu1500(base_tests.SimpleDataPlane):
Flavio Castrob6773032015-11-19 22:49:24 -0500359 def runTest(self):
360 ports = sorted(config["port_map"].keys())
Flavio Castro1c9b1252016-02-04 18:42:58 -0500361 vlan_id = 18
362 Groups = Queue.LifoQueue()
Flavio Castrob6773032015-11-19 22:49:24 -0500363 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500364 L2gid, msg = add_one_l2_interface_group(self.controller, port,
365 vlan_id, True, False)
366 add_one_vlan_table_flow(self.controller, port, vlan_id,
367 flag=VLAN_TABLE_FLAG_ONLY_TAG)
368 Groups.put(L2gid)
369 add_bridge_flow(self.controller,
370 [0x00, 0x12, 0x34, 0x56, 0x78, port], vlan_id,
371 L2gid, True)
Flavio Castrob6773032015-11-19 22:49:24 -0500372 do_barrier(self.controller)
373
374 for out_port in ports:
375 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500376 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castrob6773032015-11-19 22:49:24 -0500377 for in_port in ports:
378 if in_port == out_port:
379 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -0500380 pkt = str(simple_tcp_packet(pktlen=1500, dl_vlan_enable=True,
381 vlan_vid=vlan_id, eth_dst=mac_dst))
Flavio Castrob6773032015-11-19 22:49:24 -0500382 self.dataplane.send(in_port, pkt)
Flavio Castrob6773032015-11-19 22:49:24 -0500383 for ofport in ports:
384 if ofport in [out_port]:
385 verify_packet(self, pkt, ofport)
386 else:
387 verify_no_packet(self, pkt, ofport)
Flavio Castrob6773032015-11-19 22:49:24 -0500388 verify_no_other_packets(self)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500389 delete_all_flows(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500390 delete_groups(self.controller, Groups)
391
392
393class _32UcastTagged(base_tests.SimpleDataPlane):
394 """
395 Verify a IP forwarding works for a /32 rule to L3 Unicast Interface
396 """
397
398 def runTest(self):
399 test_id = 26
400 if len(config["port_map"]) < 2:
Flavio Castro05d20bc2015-11-16 15:06:14 -0500401 logging.info("Port count less than 2, can't run this case")
402 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500403
Flavio Castro1c9b1252016-02-04 18:42:58 -0500404 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
405 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
406 dip = 0xc0a80001
Flavio Castroa8233862015-12-02 14:41:11 -0500407 ports = config["port_map"].keys()
Flavio Castro1c9b1252016-02-04 18:42:58 -0500408 Groups = Queue.LifoQueue()
Flavio Castroa8233862015-12-02 14:41:11 -0500409 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500410 # add l2 interface group
411 vlan_id = port + test_id
412 l2gid, msg = add_one_l2_interface_group(self.controller, port,
413 vlan_id=vlan_id,
414 is_tagged=True,
415 send_barrier=False)
416 dst_mac[5] = vlan_id
417 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
418 id=vlan_id, src_mac=intf_src_mac,
419 dst_mac=dst_mac)
420 # add vlan flow table
421 add_one_vlan_table_flow(self.controller, port, vlan_id,
422 flag=VLAN_TABLE_FLAG_ONLY_TAG)
423 # add termination flow
424 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
425 vlan_id)
426 # add unicast routing flow
427 dst_ip = dip + (vlan_id << 8)
428 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
429 0xffffffff, l3_msg.group_id)
430 Groups.put(l2gid)
431 Groups.put(l3_msg.group_id)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500432 do_barrier(self.controller)
433
Flavio Castro05d20bc2015-11-16 15:06:14 -0500434 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
Flavio Castroa8233862015-12-02 14:41:11 -0500435 for in_port in ports:
Flavio Castro91d1a552016-05-17 16:59:44 -0700436 mac_src = '00:00:00:22:32:%02X' % (test_id + in_port)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500437 ip_src = '192.168.%02d.1' % (test_id + in_port)
Flavio Castroa8233862015-12-02 14:41:11 -0500438 for out_port in ports:
439 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500440 continue
441 ip_dst = '192.168.%02d.1' % (test_id + out_port)
442 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
443 vlan_vid=(test_id + in_port),
444 eth_dst=switch_mac,
445 eth_src=mac_src, ip_ttl=64,
446 ip_src=ip_src,
447 ip_dst=ip_dst)
448 pkt = str(parsed_pkt)
Flavio Castroa8233862015-12-02 14:41:11 -0500449 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500450 # build expected packet
451 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
452 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
453 vlan_vid=(test_id + out_port),
454 eth_dst=mac_dst, eth_src=switch_mac,
455 ip_ttl=63,
456 ip_src=ip_src, ip_dst=ip_dst)
457 pkt = str(exp_pkt)
Flavio Castroa8233862015-12-02 14:41:11 -0500458 verify_packet(self, pkt, out_port)
459 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500460 delete_all_flows(self.controller)
461 delete_groups(self.controller, Groups)
462
Flavio Castro05d20bc2015-11-16 15:06:14 -0500463
Flavio Castro2262fd42016-02-04 19:03:36 -0500464class _32VPN(base_tests.SimpleDataPlane):
465 """
466 Insert IP packet
467 Receive MPLS packet
468 """
469
470 def runTest(self):
471 if len(config["port_map"]) < 2:
472 logging.info("Port count less than 2, can't run this case")
473 return
474
475 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
476 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
477 dip = 0xc0a80001
478 ports = config["port_map"].keys()
479 Groups = Queue.LifoQueue()
480 for port in ports:
481 # add l2 interface group
482 id = port
483 vlan_id = port
484 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
485 vlan_id, True, True)
486 dst_mac[5] = vlan_id
487 # add MPLS interface group
488 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
489 dst_mac, intf_src_mac,
490 vlan_id, id)
491 # add MPLS L3 VPN group
492 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
493 self.controller,
494 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
495 index=id, ref_gid=mpls_gid, push_mpls_header=True,
496 set_mpls_label=port, set_bos=1, set_ttl=32)
497 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
498 do_barrier(self.controller)
499 # add vlan flow table
Flavio Castrobcc3dbc2016-04-06 11:05:03 -0400500 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=2,
Flavio Castro2262fd42016-02-04 19:03:36 -0500501 flag=VLAN_TABLE_FLAG_ONLY_TAG)
502 # add termination flow
503 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
504 vlan_id)
505 # add routing flow
506 dst_ip = dip + (vlan_id << 8)
507 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
Flavio Castrobcc3dbc2016-04-06 11:05:03 -0400508 0xffffffff, mpls_label_gid,vrf=2)
Flavio Castro2262fd42016-02-04 19:03:36 -0500509 Groups._put(l2_gid)
510 Groups._put(mpls_gid)
511 Groups._put(mpls_label_gid)
512 do_barrier(self.controller)
513
514 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
515 for in_port in ports:
516 ip_src = '192.168.%02d.1' % (in_port)
517 for out_port in ports:
518 if in_port == out_port:
519 continue
520 ip_dst = '192.168.%02d.1' % (out_port)
521 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
522 vlan_vid=(in_port),
523 eth_dst=switch_mac, ip_ttl=64,
524 ip_src=ip_src,
525 ip_dst=ip_dst)
526 pkt = str(parsed_pkt)
527 self.dataplane.send(in_port, pkt)
528 # build expect packet
529 mac_dst = '00:00:00:22:22:%02X' % (out_port)
530 label = (out_port, 0, 1, 32)
531 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
532 vlan_vid=(out_port), ip_ttl=63,
533 ip_src=ip_src,
534 ip_dst=ip_dst, eth_dst=mac_dst,
535 eth_src=switch_mac, label=[label])
536 pkt = str(exp_pkt)
537 verify_packet(self, pkt, out_port)
538 verify_no_other_packets(self)
539 delete_all_flows(self.controller)
540 delete_groups(self.controller, Groups)
541
542class _32EcmpVpn(base_tests.SimpleDataPlane):
543 """
544 Insert IP packet
545 Receive MPLS packet
546 """
547
548 def runTest(self):
549 if len(config["port_map"]) < 2:
550 logging.info("Port count less than 2, can't run this case")
551 return
552
553 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
554 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
555 dip = 0xc0a80001
556 ports = config["port_map"].keys()
557 Groups = Queue.LifoQueue()
558 for port in ports:
559 # add l2 interface group
560 id = port
561 vlan_id = port
562 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
563 vlan_id, True, True)
564 dst_mac[5] = vlan_id
565 # add MPLS interface group
566 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
567 dst_mac, intf_src_mac,
568 vlan_id, id)
569 # add MPLS L3 VPN group
570 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
571 self.controller,
572 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
573 index=id, ref_gid=mpls_gid, push_mpls_header=True,
574 set_mpls_label=port, set_bos=1, set_ttl=32)
575 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
576 do_barrier(self.controller)
577 # add vlan flow table
578 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0,
579 flag=VLAN_TABLE_FLAG_ONLY_TAG)
580 # add termination flow
581 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
582 vlan_id)
583 # add routing flow
584 dst_ip = dip + (vlan_id << 8)
585 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
586 0xffffffff, ecmp_msg.group_id)
587 Groups._put(l2_gid)
588 Groups._put(mpls_gid)
589 Groups._put(mpls_label_gid)
590 Groups._put(ecmp_msg.group_id)
591 do_barrier(self.controller)
592
593 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
594 for in_port in ports:
595 ip_src = '192.168.%02d.1' % (in_port)
596 for out_port in ports:
597 if in_port == out_port:
598 continue
599 ip_dst = '192.168.%02d.1' % (out_port)
600 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
601 vlan_vid=(in_port),
602 eth_dst=switch_mac, ip_ttl=64,
603 ip_src=ip_src,
604 ip_dst=ip_dst)
605 pkt = str(parsed_pkt)
606 self.dataplane.send(in_port, pkt)
607 # build expect packet
608 mac_dst = '00:00:00:22:22:%02X' % (out_port)
609 label = (out_port, 0, 1, 32)
610 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
611 vlan_vid=(out_port), ip_ttl=63,
612 ip_src=ip_src,
613 ip_dst=ip_dst, eth_dst=mac_dst,
614 eth_src=switch_mac, label=[label])
615 pkt = str(exp_pkt)
616 verify_packet(self, pkt, out_port)
617 verify_no_other_packets(self)
618 delete_all_flows(self.controller)
619 delete_groups(self.controller, Groups)
620
621class _32ECMPL3(base_tests.SimpleDataPlane):
622 """
623 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
624 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
625 """
626
627 def runTest(self):
628 Groups = Queue.LifoQueue()
629 if len(config["port_map"]) < 2:
630 logging.info("Port count less than 2, can't run this case")
631 return
632
633 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
634 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
635 dip = 0xc0a80001
636 # Hashes Test Name and uses it as id for installing unique groups
637 ports = config["port_map"].keys()
638 for port in ports:
639 vlan_id = port
640 id = port
641 # add l2 interface group
642 l2_gid, msg = add_one_l2_interface_group(self.controller, port,
643 vlan_id=vlan_id,
644 is_tagged=True,
645 send_barrier=False)
646 dst_mac[5] = vlan_id
647 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
648 id=id, src_mac=intf_src_mac,
649 dst_mac=dst_mac)
650 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
651 # add vlan flow table
652 add_one_vlan_table_flow(self.controller, port, vlan_id,
653 flag=VLAN_TABLE_FLAG_ONLY_TAG)
654 # add termination flow
655 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
656 vlan_id)
657 # add unicast routing flow
658 dst_ip = dip + (vlan_id << 8)
659 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
660 0xffffffff, ecmp_msg.group_id)
661 Groups._put(l2_gid)
662 Groups._put(l3_msg.group_id)
663 Groups._put(ecmp_msg.group_id)
664 do_barrier(self.controller)
665
666 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
667 for in_port in ports:
668 mac_src = '00:00:00:22:22:%02X' % in_port
669 ip_src = '192.168.%02d.1' % in_port
670 for out_port in ports:
671 if in_port == out_port:
672 continue
673 ip_dst = '192.168.%02d.1' % out_port
674 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
675 vlan_vid=in_port,
676 eth_dst=switch_mac,
677 eth_src=mac_src, ip_ttl=64,
678 ip_src=ip_src,
679 ip_dst=ip_dst)
680 pkt = str(parsed_pkt)
681 self.dataplane.send(in_port, pkt)
682 # build expected packet
683 mac_dst = '00:00:00:22:22:%02X' % out_port
684 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
685 vlan_vid=out_port,
686 eth_dst=mac_dst, eth_src=switch_mac,
687 ip_ttl=63,
688 ip_src=ip_src, ip_dst=ip_dst)
689 pkt = str(exp_pkt)
690 verify_packet(self, pkt, out_port)
691 verify_no_other_packets(self)
692 delete_all_flows(self.controller)
693 delete_groups(self.controller, Groups)
694
Flavio Castro2262fd42016-02-04 19:03:36 -0500695class _24VPN(base_tests.SimpleDataPlane):
696 """
697 Insert IP packet
698 Receive MPLS packet
699 """
700
701 def runTest(self):
702 if len(config["port_map"]) < 2:
703 logging.info("Port count less than 2, can't run this case")
704 return
705
706 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
707 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
708 dip = 0xc0a80001
709 ports = config["port_map"].keys()
710 Groups = Queue.LifoQueue()
711 for port in ports:
712 # add l2 interface group
713 id = port
714 vlan_id = port
Flavio Castro91d1a552016-05-17 16:59:44 -0700715 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
Flavio Castro2262fd42016-02-04 19:03:36 -0500716 dst_mac[5] = vlan_id
717 # add MPLS interface group
Flavio Castro91d1a552016-05-17 16:59:44 -0700718 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 -0500719 # add MPLS L3 VPN group
720 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
721 self.controller,
722 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
723 index=id, ref_gid=mpls_gid, push_mpls_header=True,
724 set_mpls_label=port, set_bos=1, set_ttl=32)
725 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
726 do_barrier(self.controller)
727 # add vlan flow table
728 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0,
729 flag=VLAN_TABLE_FLAG_ONLY_TAG)
730 # add termination flow
731 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
732 vlan_id)
733 # add routing flow
734 dst_ip = dip + (vlan_id << 8)
735 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
736 0xffffff00, mpls_label_gid)
737 Groups._put(l2_gid)
738 Groups._put(mpls_gid)
739 Groups._put(mpls_label_gid)
740 do_barrier(self.controller)
741
742 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
743 for in_port in ports:
744 ip_src = '192.168.%02d.1' % (in_port)
745 for out_port in ports:
746 if in_port == out_port:
747 continue
748 ip_dst = '192.168.%02d.1' % (out_port)
749 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
750 vlan_vid=(in_port),
751 eth_dst=switch_mac, ip_ttl=64,
752 ip_src=ip_src,
753 ip_dst=ip_dst)
754 pkt = str(parsed_pkt)
755 self.dataplane.send(in_port, pkt)
756 # build expect packet
757 mac_dst = '00:00:00:22:22:%02X' % (out_port)
758 label = (out_port, 0, 1, 32)
759 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
760 vlan_vid=(out_port), ip_ttl=63,
761 ip_src=ip_src,
762 ip_dst=ip_dst, eth_dst=mac_dst,
763 eth_src=switch_mac, label=[label])
764 pkt = str(exp_pkt)
765 verify_packet(self, pkt, out_port)
766 verify_no_other_packets(self)
767 delete_all_flows(self.controller)
768 delete_groups(self.controller, Groups)
769
Flavio Castro2262fd42016-02-04 19:03:36 -0500770class _24EcmpVpn(base_tests.SimpleDataPlane):
Flavio Castrod8f8af22015-12-02 18:19:26 -0500771 """
772 Insert IP packet
773 Receive MPLS packet
774 """
Flavio Castro72a45d52015-12-02 16:37:05 -0500775
Flavio Castro1c9b1252016-02-04 18:42:58 -0500776 def runTest(self):
777 if len(config["port_map"]) < 2:
Flavio Castro72a45d52015-12-02 16:37:05 -0500778 logging.info("Port count less than 2, can't run this case")
779 return
Flavio Castro1c9b1252016-02-04 18:42:58 -0500780 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
781 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
782 dip = 0xc0a80001
783 Groups = Queue.LifoQueue()
Flavio Castro72a45d52015-12-02 16:37:05 -0500784 ports = config["port_map"].keys()
785 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500786 # add l2 interface group
787 id = port
788 vlan_id = id
789 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
790 vlan_id, True, True)
791 dst_mac[5] = vlan_id
792 # add MPLS interface group
793 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
794 dst_mac, intf_src_mac,
795 vlan_id, id)
796 # add MPLS L3 VPN group
797 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
798 self.controller,
799 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
800 index=id, ref_gid=mpls_gid, push_mpls_header=True,
801 set_mpls_label=port, set_bos=1, set_ttl=32)
802 ecmp_msg = add_l3_ecmp_group(self.controller, id, [mpls_label_gid])
Flavio Castro80730822015-12-11 15:38:47 -0500803 do_barrier(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500804 # add vlan flow table
805 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0,
806 flag=VLAN_TABLE_FLAG_ONLY_TAG)
807 # add termination flow
808 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
809 vlan_id)
810 # add routing flow
811 dst_ip = dip + (vlan_id << 8)
812 # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
813 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
814 0xffffff00, ecmp_msg.group_id, vrf=0)
815 Groups._put(l2_gid)
816 Groups._put(mpls_gid)
817 Groups._put(mpls_label_gid)
818 Groups._put(ecmp_msg.group_id)
Flavio Castro80730822015-12-11 15:38:47 -0500819
820 do_barrier(self.controller)
821
822 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
823 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500824 mac_src = '00:00:00:22:22:%02X' % (in_port)
825 ip_src = '192.168.%02d.1' % (in_port)
Flavio Castro80730822015-12-11 15:38:47 -0500826 for out_port in ports:
827 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500828 continue
829 ip_dst = '192.168.%02d.1' % (out_port)
830 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
831 vlan_vid=(in_port),
832 eth_dst=switch_mac,
833 eth_src=mac_src, ip_ttl=64,
834 ip_src=ip_src,
835 ip_dst=ip_dst)
836 pkt = str(parsed_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500837 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500838 # build expect packet
839 mac_dst = '00:00:00:22:22:%02X' % out_port
Flavio Castro80730822015-12-11 15:38:47 -0500840 label = (out_port, 0, 1, 32)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500841 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
842 vlan_vid=(out_port), ip_ttl=63,
843 ip_src=ip_src,
844 ip_dst=ip_dst, eth_dst=mac_dst,
845 eth_src=switch_mac, label=[label])
846 pkt = str(exp_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500847 verify_packet(self, pkt, out_port)
848 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500849 delete_all_flows(self.controller)
850 delete_groups(self.controller, Groups)
851
Flavio Castro2262fd42016-02-04 19:03:36 -0500852class _24ECMPL3(base_tests.SimpleDataPlane):
Flavio Castro80730822015-12-11 15:38:47 -0500853 """
Flavio Castro2262fd42016-02-04 19:03:36 -0500854 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
855 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
Flavio Castro80730822015-12-11 15:38:47 -0500856 """
Flavio Castro80730822015-12-11 15:38:47 -0500857
Flavio Castro1c9b1252016-02-04 18:42:58 -0500858 def runTest(self):
Flavio Castro2262fd42016-02-04 19:03:36 -0500859 Groups = Queue.LifoQueue()
Flavio Castro1c9b1252016-02-04 18:42:58 -0500860 if len(config["port_map"]) < 2:
Flavio Castro80730822015-12-11 15:38:47 -0500861 logging.info("Port count less than 2, can't run this case")
862 return
863
Flavio Castro1c9b1252016-02-04 18:42:58 -0500864 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
865 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
866 dip = 0xc0a80001
Flavio Castro2262fd42016-02-04 19:03:36 -0500867 # Hashes Test Name and uses it as id for installing unique groups
Flavio Castro80730822015-12-11 15:38:47 -0500868 ports = config["port_map"].keys()
869 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500870 vlan_id = port
Flavio Castro2262fd42016-02-04 19:03:36 -0500871 id = port
872 # add l2 interface group
873 l2_gid, msg = add_one_l2_interface_group(self.controller, port,
874 vlan_id=vlan_id,
875 is_tagged=True,
876 send_barrier=False)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500877 dst_mac[5] = vlan_id
Flavio Castro2262fd42016-02-04 19:03:36 -0500878 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
879 id=id, src_mac=intf_src_mac,
880 dst_mac=dst_mac)
881 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
Flavio Castro1c9b1252016-02-04 18:42:58 -0500882 # add vlan flow table
Flavio Castro2262fd42016-02-04 19:03:36 -0500883 add_one_vlan_table_flow(self.controller, port, vlan_id,
Flavio Castro1c9b1252016-02-04 18:42:58 -0500884 flag=VLAN_TABLE_FLAG_ONLY_TAG)
885 # add termination flow
886 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
887 vlan_id)
Flavio Castro2262fd42016-02-04 19:03:36 -0500888 # add unicast routing flow
Flavio Castro1c9b1252016-02-04 18:42:58 -0500889 dst_ip = dip + (vlan_id << 8)
890 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
Flavio Castro2262fd42016-02-04 19:03:36 -0500891 0xffffff00, ecmp_msg.group_id)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500892 Groups._put(l2_gid)
Flavio Castro2262fd42016-02-04 19:03:36 -0500893 Groups._put(l3_msg.group_id)
894 Groups._put(ecmp_msg.group_id)
Flavio Castro72a45d52015-12-02 16:37:05 -0500895 do_barrier(self.controller)
896
897 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
898 for in_port in ports:
Flavio Castro2262fd42016-02-04 19:03:36 -0500899 mac_src = '00:00:00:22:22:%02X' % in_port
900 ip_src = '192.168.%02d.1' % in_port
Flavio Castro72a45d52015-12-02 16:37:05 -0500901 for out_port in ports:
902 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500903 continue
Flavio Castro2262fd42016-02-04 19:03:36 -0500904 ip_dst = '192.168.%02d.1' % out_port
Flavio Castro1c9b1252016-02-04 18:42:58 -0500905 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
Flavio Castro2262fd42016-02-04 19:03:36 -0500906 vlan_vid=in_port,
907 eth_dst=switch_mac,
908 eth_src=mac_src, ip_ttl=64,
Flavio Castro1c9b1252016-02-04 18:42:58 -0500909 ip_src=ip_src,
910 ip_dst=ip_dst)
911 pkt = str(parsed_pkt)
Flavio Castro72a45d52015-12-02 16:37:05 -0500912 self.dataplane.send(in_port, pkt)
Flavio Castro2262fd42016-02-04 19:03:36 -0500913 # build expected packet
914 mac_dst = '00:00:00:22:22:%02X' % out_port
915 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
916 vlan_vid=out_port,
917 eth_dst=mac_dst, eth_src=switch_mac,
918 ip_ttl=63,
919 ip_src=ip_src, ip_dst=ip_dst)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500920 pkt = str(exp_pkt)
Flavio Castro72a45d52015-12-02 16:37:05 -0500921 verify_packet(self, pkt, out_port)
922 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500923 delete_all_flows(self.controller)
924 delete_groups(self.controller, Groups)
925
Flavio Castroaba28ff2016-02-03 16:47:48 -0500926@disabled
Flavio Castro80730822015-12-11 15:38:47 -0500927class MPLSBUG(base_tests.SimpleDataPlane):
Flavio Castro80730822015-12-11 15:38:47 -0500928 def runTest(self):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500929 if len(config["port_map"]) < 2:
Flavio Castro80730822015-12-11 15:38:47 -0500930 logging.info("Port count less than 2, can't run this case")
931 return
Flavio Castro1c9b1252016-02-04 18:42:58 -0500932 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
933 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
934 dip = 0xc0a80001
935 Groups = Queue.LifoQueue()
Flavio Castro80730822015-12-11 15:38:47 -0500936 ports = config["port_map"].keys()
937 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500938 # add l2 interface group
939 vlan_id = port
940 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
941 vlan_id, True, False)
942 dst_mac[5] = vlan_id
943 # add L3 Unicast group
944 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
945 id=vlan_id, src_mac=intf_src_mac,
946 dst_mac=dst_mac)
947 # add vlan flow table
948 add_one_vlan_table_flow(self.controller, port, vlan_id,
949 flag=VLAN_TABLE_FLAG_ONLY_BOTH)
950 # add termination flow
951 add_termination_flow(self.controller, port, 0x8847, intf_src_mac,
952 vlan_id, goto_table=24)
953 # add mpls flow
Flavio Castro80730822015-12-11 15:38:47 -0500954 add_mpls_flow(self.controller, l3_msg.group_id, port)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500955 # add termination flow
956 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
957 vlan_id)
958 # add unicast routing flow
959 dst_ip = dip + (vlan_id << 8)
960 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
961 0xffffffff, l3_msg.group_id)
962 Groups._put(l2_gid)
963 Groups._put(l3_msg.group_id)
Flavio Castro80730822015-12-11 15:38:47 -0500964 do_barrier(self.controller)
965
966 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
967 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500968 mac_src = '00:00:00:22:22:%02X' % in_port
969 ip_src = '192.168.%02d.1' % in_port
Flavio Castro80730822015-12-11 15:38:47 -0500970 for out_port in ports:
971 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500972 continue
973 ip_dst = '192.168.%02d.1' % out_port
Flavio Castro80730822015-12-11 15:38:47 -0500974 switch_mac = "00:00:00:cc:cc:cc"
975 label = (out_port, 0, 1, 32)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500976 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
977 vlan_vid=in_port, ip_src=ip_src,
978 ip_dst=ip_dst, eth_dst=switch_mac,
979 eth_src=mac_src, label=[label])
980 pkt = str(parsed_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500981 self.dataplane.send(in_port, pkt)
982
Flavio Castro1c9b1252016-02-04 18:42:58 -0500983 # build expect packet
984 mac_dst = '00:00:00:22:22:%02X' % out_port
985 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
986 vlan_vid=out_port,
987 eth_dst=mac_dst, eth_src=switch_mac,
988 ip_ttl=31, ip_src=ip_src,
989 ip_dst=ip_dst)
990 pkt = str(exp_pkt)
Flavio Castro80730822015-12-11 15:38:47 -0500991 verify_packet(self, pkt, out_port)
992 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500993
994 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
995 vlan_vid=in_port,
996 eth_dst=switch_mac,
997 eth_src=mac_src, ip_ttl=64,
998 ip_src=ip_src,
999 ip_dst=ip_dst)
1000 pkt = str(parsed_pkt)
Flavio Castro80730822015-12-11 15:38:47 -05001001 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001002 # build expected 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=63,
1008 ip_src=ip_src, 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 delete_all_flows(self.controller)
1013 delete_groups(self.controller, Groups)
1014
Flavio Castro12296312015-12-15 17:48:26 -05001015class L3McastToL2(base_tests.SimpleDataPlane):
castroflaviocc403a92015-12-15 14:04:19 -05001016 """
Flavio Castro12296312015-12-15 17:48:26 -05001017 Mcast routing to L2
castroflaviocc403a92015-12-15 14:04:19 -05001018 """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001019
castroflaviocc403a92015-12-15 14:04:19 -05001020 def runTest(self):
1021 """
1022 port1 (vlan 300)-> All Ports (vlan 300)
1023 """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001024 if len(config["port_map"]) < 3:
castroflavio4a09c962016-01-05 13:13:41 -08001025 logging.info("Port count less than 3, can't run this case")
Flavio Castro1c9b1252016-02-04 18:42:58 -05001026 assert (False)
castroflaviocc403a92015-12-15 14:04:19 -05001027 return
Flavio Castro1c9b1252016-02-04 18:42:58 -05001028 Groups = Queue.LifoQueue()
1029 vlan_id = 300
1030 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1031 intf_src_mac_str = ':'.join(['%02X' % x for x in intf_src_mac])
1032 dst_mac = [0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
1033 dst_mac_str = ':'.join(['%02X' % x for x in dst_mac])
1034 port1_mac = [0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
1035 port1_mac_str = ':'.join(['%02X' % x for x in port1_mac])
1036 src_ip = 0xc0a80101
1037 src_ip_str = "192.168.1.1"
1038 dst_ip = 0xe0010101
1039 dst_ip_str = "224.1.1.1"
castroflaviocc403a92015-12-15 14:04:19 -05001040
Flavio Castro1c9b1252016-02-04 18:42:58 -05001041 port1 = config["port_map"].keys()[0]
1042 port2 = config["port_map"].keys()[1]
castroflaviocc403a92015-12-15 14:04:19 -05001043
1044 switch_mac = [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00]
1045
Flavio Castro1c9b1252016-02-04 18:42:58 -05001046 # add l2 interface group
1047 l2_intf_group_list = []
castroflaviocc403a92015-12-15 14:04:19 -05001048 for port in config["port_map"].keys():
Flavio Castro1c9b1252016-02-04 18:42:58 -05001049 add_one_vlan_table_flow(self.controller, port, vlan_id,
1050 flag=VLAN_TABLE_FLAG_ONLY_TAG)
castroflaviocc403a92015-12-15 14:04:19 -05001051 if port == port2:
1052 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -05001053 l2_intf_gid, msg = add_one_l2_interface_group(self.controller, port,
1054 vlan_id=vlan_id,
1055 is_tagged=True,
1056 send_barrier=False)
castroflaviocc403a92015-12-15 14:04:19 -05001057 l2_intf_group_list.append(l2_intf_gid)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001058 Groups.put(l2_intf_gid)
castroflaviocc403a92015-12-15 14:04:19 -05001059
Flavio Castro1c9b1252016-02-04 18:42:58 -05001060 # add termination flow
1061 add_termination_flow(self.controller, port1, 0x0800, switch_mac,
1062 vlan_id)
castroflaviocc403a92015-12-15 14:04:19 -05001063
Flavio Castro1c9b1252016-02-04 18:42:58 -05001064 # add l3 interface group
1065 mcat_group_msg = add_l3_mcast_group(self.controller, vlan_id, 2,
1066 l2_intf_group_list)
1067 add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip,
1068 mcat_group_msg.group_id)
1069 Groups._put(mcat_group_msg.group_id)
castroflaviocc403a92015-12-15 14:04:19 -05001070
Flavio Castro1c9b1252016-02-04 18:42:58 -05001071 parsed_pkt = simple_udp_packet(pktlen=100,
Flavio Castro89933f22016-02-03 15:53:16 -05001072 dl_vlan_enable=True,
1073 vlan_vid=vlan_id,
castroflaviocc403a92015-12-15 14:04:19 -05001074 eth_dst=dst_mac_str,
1075 eth_src=port1_mac_str,
1076 ip_ttl=64,
1077 ip_src=src_ip_str,
1078 ip_dst=dst_ip_str)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001079 pkt = str(parsed_pkt)
castroflaviocc403a92015-12-15 14:04:19 -05001080 self.dataplane.send(port1, pkt)
1081 for port in config["port_map"].keys():
Flavio Castro12296312015-12-15 17:48:26 -05001082 if port == port2 or port == port1:
Flavio Castro1c9b1252016-02-04 18:42:58 -05001083 verify_no_packet(self, pkt, port)
1084 continue
castroflaviocc403a92015-12-15 14:04:19 -05001085 verify_packet(self, pkt, port)
1086 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001087 delete_all_flows(self.controller)
1088 delete_groups(self.controller, Groups)
1089
Flavio Castro12296312015-12-15 17:48:26 -05001090class L3McastToL3(base_tests.SimpleDataPlane):
1091 """
1092 Mcast routing
1093 """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001094
1095 def runTest(self):
Flavio Castro12296312015-12-15 17:48:26 -05001096 """
1097 port1 (vlan 1)-> port 2 (vlan 2)
1098 """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001099 Groups = Queue.LifoQueue()
1100 if len(config["port_map"]) < 3:
castroflavio4a09c962016-01-05 13:13:41 -08001101 logging.info("Port count less than 3, can't run this case")
Flavio Castro1c9b1252016-02-04 18:42:58 -05001102 assert (False)
Flavio Castro12296312015-12-15 17:48:26 -05001103 return
1104
Flavio Castro1c9b1252016-02-04 18:42:58 -05001105 vlan_id = 1
1106 port2_out_vlan = 2
1107 port3_out_vlan = 3
1108 in_vlan = 1 # macast group vid shall use input vlan diffe from l3 interface use output vlan
1109 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1110 intf_src_mac_str = ':'.join(['%02X' % x for x in intf_src_mac])
1111 dst_mac = [0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
1112 dst_mac_str = ':'.join(['%02X' % x for x in dst_mac])
1113 port1_mac = [0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
1114 port1_mac_str = ':'.join(['%02X' % x for x in port1_mac])
1115 src_ip = 0xc0a80101
1116 src_ip_str = "192.168.1.1"
1117 dst_ip = 0xe0010101
1118 dst_ip_str = "224.1.1.1"
Flavio Castro12296312015-12-15 17:48:26 -05001119
Flavio Castro1c9b1252016-02-04 18:42:58 -05001120 port1 = config["port_map"].keys()[0]
1121 port2 = config["port_map"].keys()[1]
1122 port3 = config["port_map"].keys()[2]
Flavio Castro12296312015-12-15 17:48:26 -05001123
Flavio Castro1c9b1252016-02-04 18:42:58 -05001124 # add l2 interface group
1125 for port in config["port_map"].keys():
1126 l2gid, msg = add_one_l2_interface_group(self.controller, port,
1127 vlan_id=vlan_id,
1128 is_tagged=False,
1129 send_barrier=False)
1130 # add vlan flow table
1131 add_one_vlan_table_flow(self.controller, port, vlan_id,
1132 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1133 vlan_id += 1
1134 Groups._put(l2gid)
Flavio Castro12296312015-12-15 17:48:26 -05001135
Flavio Castro1c9b1252016-02-04 18:42:58 -05001136 # add termination flow
1137 add_termination_flow(self.controller, port1, 0x0800,
1138 [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
1139
1140 # add l3 interface group
1141 port2_ucast_msg = add_l3_interface_group(self.controller, port2,
1142 port2_out_vlan, 2,
1143 intf_src_mac)
1144 port3_ucast_msg = add_l3_interface_group(self.controller, port3,
1145 port3_out_vlan, 3,
1146 intf_src_mac)
1147 mcat_group_msg = add_l3_mcast_group(self.controller, in_vlan, 2,
1148 [port2_ucast_msg.group_id,
1149 port3_ucast_msg.group_id])
1150 add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip,
1151 mcat_group_msg.group_id)
1152 Groups._put(port2_ucast_msg.group_id)
1153 Groups._put(port3_ucast_msg.group_id)
1154 Groups._put(mcat_group_msg.group_id)
1155 parsed_pkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
1156 vlan_vid=1,
Flavio Castro12296312015-12-15 17:48:26 -05001157 eth_dst=dst_mac_str,
1158 eth_src=port1_mac_str,
1159 ip_ttl=64,
1160 ip_src=src_ip_str,
1161 ip_dst=dst_ip_str)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001162 pkt = str(parsed_pkt)
1163 self.dataplane.send(port1, pkt)
1164 parsed_pkt = simple_udp_packet(pktlen=96,
Flavio Castro12296312015-12-15 17:48:26 -05001165 eth_dst=dst_mac_str,
1166 eth_src=intf_src_mac_str,
1167 ip_ttl=63,
1168 ip_src=src_ip_str,
1169 ip_dst=dst_ip_str)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001170 pkt = str(parsed_pkt)
Flavio Castro12296312015-12-15 17:48:26 -05001171 verify_packet(self, pkt, port2)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001172 verify_packet(self, pkt, port3)
1173 verify_no_other_packets(self)
1174 delete_all_flows(self.controller)
1175 delete_groups(self.controller, Groups)
Flavio Castro54947942016-02-03 16:05:20 -05001176
Flavio Castrob702a2f2016-04-10 22:01:48 -04001177class _MplsFwd(base_tests.SimpleDataPlane):
Flavio Castro12296312015-12-15 17:48:26 -05001178 """
Flavio Castro54947942016-02-03 16:05:20 -05001179 Insert IP packet
1180 Receive MPLS packet
castroflavio30c6cc52016-01-07 15:19:42 -08001181 """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001182 def runTest(self):
1183 Groups = Queue.LifoQueue()
1184 if len(config["port_map"]) < 2:
castroflavio30c6cc52016-01-07 15:19:42 -08001185 logging.info("Port count less than 2, can't run this case")
1186 return
Flavio Castrobcc3dbc2016-04-06 11:05:03 -04001187 dip = 0xc0a80001
Flavio Castro1c9b1252016-02-04 18:42:58 -05001188 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1189 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1190 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
castroflavio30c6cc52016-01-07 15:19:42 -08001191 ports = config["port_map"].keys()
1192 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -05001193 # add l2 interface group
1194 id = port
1195 vlan_id = id
1196 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
1197 vlan_id, True, False)
1198 dst_mac[5] = vlan_id
Flavio Castrob702a2f2016-04-10 22:01:48 -04001199 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
1200 dst_mac, intf_src_mac,
1201 vlan_id, id)
1202 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
1203 self.controller,
1204 subtype=OFDPA_MPLS_GROUP_SUBTYPE_SWAP_LABEL,
1205 index=id, ref_gid=mpls_gid, push_mpls_header=False,
1206 set_mpls_label=port, set_bos=1)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001207 # add vlan flow table
1208 add_one_vlan_table_flow(self.controller, port, vlan_id,
1209 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1210 # add termination flow
1211 add_termination_flow(self.controller, port, 0x8847, intf_src_mac,
1212 vlan_id, goto_table=24)
Flavio Castro8ca52542016-04-11 11:24:49 -04001213 add_mpls_flow(self.controller, mpls_label_gid, port, goto_table=29)
Flavio Castrobcc3dbc2016-04-06 11:05:03 -04001214 dst_ip = dip + (vlan_id << 8)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001215 Groups._put(l2_gid)
Flavio Castrob702a2f2016-04-10 22:01:48 -04001216 Groups._put(mpls_gid)
Flavio Castro8ca52542016-04-11 11:24:49 -04001217 Groups._put(mpls_label_gid)
castroflavio30c6cc52016-01-07 15:19:42 -08001218 do_barrier(self.controller)
1219
1220 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1221 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -05001222 ip_src = '192.168.%02d.1' % (in_port)
castroflavio30c6cc52016-01-07 15:19:42 -08001223 for out_port in ports:
1224 if in_port == out_port:
Flavio Castro54947942016-02-03 16:05:20 -05001225 continue
Flavio Castro1c9b1252016-02-04 18:42:58 -05001226 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castro54947942016-02-03 16:05:20 -05001227
1228 label = (out_port, 0, 1, 32)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001229 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
1230 vlan_vid=(in_port), ip_src=ip_src,
1231 ip_dst=ip_dst, eth_dst=switch_mac,
1232 label=[label])
1233 pkt = str(parsed_pkt)
castroflavio30c6cc52016-01-07 15:19:42 -08001234 self.dataplane.send(in_port, pkt)
Flavio Castro54947942016-02-03 16:05:20 -05001235
Flavio Castro1c9b1252016-02-04 18:42:58 -05001236 # build expect packet
1237 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castrob702a2f2016-04-10 22:01:48 -04001238 label = (out_port, 0, 1, 31)
1239 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
1240 vlan_vid=(out_port), ip_src=ip_src,
1241 ip_dst=ip_dst, eth_src=switch_mac,
1242 eth_dst=mac_dst,label=[label])
1243 pkt = str(exp_pkt)
1244 verify_packet(self, pkt, out_port)
1245 verify_no_other_packets(self)
1246 delete_all_flows(self.controller)
1247 delete_groups(self.controller, Groups)
1248
1249class _MplsTermination(base_tests.SimpleDataPlane):
1250 """
1251 Insert IP packet
1252 Receive MPLS packet
1253 """
1254 def runTest(self):
1255 Groups = Queue.LifoQueue()
1256 if len(config["port_map"]) < 2:
1257 logging.info("Port count less than 2, can't run this case")
1258 return
1259 dip = 0xc0a80001
1260 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1261 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1262 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
1263 ports = config["port_map"].keys()
1264 for port in ports:
1265 # add l2 interface group
1266 vlan_id, id, dst_mac[5] = port, port, port
1267 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
1268 vlan_id, True, False)
1269 # add L3 Unicast group
1270 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
1271 id=id, src_mac=intf_src_mac,dst_mac=dst_mac)
1272 # add L3 ecmp group
1273 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
1274 # add vlan flow table
1275 add_one_vlan_table_flow(self.controller, port, vlan_id,
1276 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1277 # add termination flow
1278 add_termination_flow(self.controller, port, 0x8847, intf_src_mac,
1279 vlan_id, goto_table=24)
1280 #add_mpls_flow(self.controller, ecmp_msg.group_id, port)
1281 add_mpls_flow(self.controller, label=port)
1282 dst_ip = dip + (vlan_id << 8)
1283 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00,
1284 ecmp_msg.group_id, 1)
1285 Groups._put(l2_gid)
1286 Groups._put(l3_msg.group_id)
1287 Groups._put(ecmp_msg.group_id)
1288 do_barrier(self.controller)
1289
1290 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1291 for in_port in ports:
1292 ip_src = '192.168.%02d.1' % (in_port)
1293 for out_port in ports:
1294 if in_port == out_port:
1295 continue
1296 ip_dst = '192.168.%02d.1' % (out_port)
1297 label = (out_port, 0, 1, 32)
1298 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,vlan_vid=(in_port),
1299 ip_src=ip_src,ip_dst=ip_dst, eth_dst=switch_mac,label=[label])
1300 pkt = str(parsed_pkt)
1301 self.dataplane.send(in_port, pkt)
1302 # build expect packet
1303 mac_dst = '00:00:00:22:22:%02X' % (out_port)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001304 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1305 vlan_vid=(out_port),
1306 eth_dst=mac_dst, eth_src=switch_mac,
1307 ip_ttl=31, ip_src=ip_src,
1308 ip_dst=ip_dst)
1309 pkt = str(exp_pkt)
castroflavio30c6cc52016-01-07 15:19:42 -08001310 verify_packet(self, pkt, out_port)
1311 verify_no_other_packets(self)
Flavio Castro76af6482016-04-06 11:42:29 -04001312 delete_all_flows(self.controller)
1313 delete_groups(self.controller, Groups)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001314
Flavio Castro1c9b1252016-02-04 18:42:58 -05001315class _24UcastTagged(base_tests.SimpleDataPlane):
1316 """
1317 Verify a IP forwarding works for a /32 rule to L3 Unicast Interface
1318 """
1319
1320 def runTest(self):
1321 test_id = 26
1322 if len(config["port_map"]) < 2:
1323 logging.info("Port count less than 2, can't run this case")
1324 return
1325
1326 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1327 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1328 dip = 0xc0a80001
1329 ports = config["port_map"].keys()
1330 Groups = Queue.LifoQueue()
1331 for port in ports:
1332 # add l2 interface group
1333 vlan_id = port + test_id
1334 l2gid, msg = add_one_l2_interface_group(self.controller, port,
1335 vlan_id=vlan_id,
1336 is_tagged=True,
1337 send_barrier=False)
1338 dst_mac[5] = vlan_id
1339 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
1340 id=vlan_id, src_mac=intf_src_mac,
1341 dst_mac=dst_mac)
1342 # add vlan flow table
1343 add_one_vlan_table_flow(self.controller, port, vlan_id,
1344 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1345 # add termination flow
1346 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
1347 vlan_id)
1348 # add unicast routing flow
1349 dst_ip = dip + (vlan_id << 8)
1350 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
1351 0xffffff00, l3_msg.group_id)
1352 Groups.put(l2gid)
1353 Groups.put(l3_msg.group_id)
1354 do_barrier(self.controller)
1355
1356 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1357 for in_port in ports:
1358 mac_src = '00:00:00:22:22:%02X' % (test_id + in_port)
1359 ip_src = '192.168.%02d.1' % (test_id + in_port)
1360 for out_port in ports:
1361 if in_port == out_port:
1362 continue
1363 ip_dst = '192.168.%02d.1' % (test_id + out_port)
1364 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1365 vlan_vid=(test_id + in_port),
1366 eth_dst=switch_mac,
1367 eth_src=mac_src, ip_ttl=64,
1368 ip_src=ip_src,
1369 ip_dst=ip_dst)
1370 pkt = str(parsed_pkt)
1371 self.dataplane.send(in_port, pkt)
1372 # build expected packet
1373 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
1374 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1375 vlan_vid=(test_id + out_port),
1376 eth_dst=mac_dst, eth_src=switch_mac,
1377 ip_ttl=63,
1378 ip_src=ip_src, ip_dst=ip_dst)
1379 pkt = str(exp_pkt)
1380 verify_packet(self, pkt, out_port)
1381 verify_no_other_packets(self)
1382 delete_all_flows(self.controller)
1383 delete_groups(self.controller, Groups)
Flavio Castro91d1a552016-05-17 16:59:44 -07001384
1385class _0Ucast(base_tests.SimpleDataPlane):
1386 """
1387 Verify a IP forwarding works for a /0 rule to L3 Unicast Interface
1388 """
1389
1390 def runTest(self):
1391 if len(config["port_map"]) < 2:
1392 logging.info("Port count less than 2, can't run this case")
1393 return
1394
1395 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1396 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1397 dip = 0xc0a80001
1398 ports = config["port_map"].keys()
1399 Groups = Queue.LifoQueue()
1400 for port in ports:
1401 # add l2 interface group
1402 vlan_id = port
1403 l2gid, msg = add_one_l2_interface_group(self.controller, port,
1404 vlan_id=vlan_id,
1405 is_tagged=True,
1406 send_barrier=False)
1407 dst_mac[5] = vlan_id
1408 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
1409 id=vlan_id, src_mac=intf_src_mac,
1410 dst_mac=dst_mac)
1411 # add vlan flow table
1412 add_one_vlan_table_flow(self.controller, port, vlan_id,
1413 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1414 # add termination flow
1415 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
1416 vlan_id)
1417 # add unicast routing flow
1418 dst_ip = dip + (vlan_id << 8)
1419 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
1420 0xffffffff, l3_msg.group_id)
1421 Groups.put(l2gid)
1422 Groups.put(l3_msg.group_id)
1423 l3_gid = encode_l3_unicast_group_id(ports[0])
1424 dst_ip = 0x0
1425 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, l3_gid)
1426 do_barrier(self.controller)
1427
1428 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1429 for in_port in ports:
1430 mac_src = '00:00:00:22:22:%02X' % (in_port)
1431 ip_src = '192.168.%02d.1' % (in_port)
1432 for out_port in ports:
1433 if in_port == out_port:
1434 continue
1435 ip_dst = '192.168.%02d.1' % (out_port)
1436 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1437 vlan_vid=(in_port),
1438 eth_dst=switch_mac,
1439 eth_src=mac_src, ip_ttl=64,
1440 ip_src=ip_src,
1441 ip_dst=ip_dst)
1442 pkt = str(parsed_pkt)
1443 self.dataplane.send(in_port, pkt)
1444 # build expected packet
1445 mac_dst = '00:00:00:22:22:%02X' % (out_port)
1446 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1447 vlan_vid=(out_port),
1448 eth_dst=mac_dst, eth_src=switch_mac,
1449 ip_ttl=63,
1450 ip_src=ip_src, ip_dst=ip_dst)
1451 pkt = str(exp_pkt)
1452 verify_packet(self, pkt, out_port)
1453 verify_no_other_packets(self)
1454 ip_dst='1.168.%02d.1' % ports[0]
1455 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
1456 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst)
1457 pkt=str(parsed_pkt)
1458 self.dataplane.send(in_port, pkt)
1459 #build expect packet
1460 mac_dst='00:00:00:22:22:%02X' % ports[0]
1461 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=ports[0], ip_ttl=63, ip_src=ip_src,
1462 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac)
1463 pkt=str(exp_pkt)
1464 verify_packet(self, pkt, ports[0])
1465 verify_no_other_packets(self)
1466
1467 delete_all_flows(self.controller)
1468 delete_groups(self.controller, Groups)
1469
Flavio Castro423df652016-05-17 20:14:08 -04001470class Unfiltered(base_tests.SimpleDataPlane):
1471 """
1472 Testing addition of unfiltered groups
1473 """
Flavio Castro91d1a552016-05-17 16:59:44 -07001474
Flavio Castro423df652016-05-17 20:14:08 -04001475 def runTest(self):
1476 ports = sorted(config["port_map"].keys())
1477 vlan_id = 1;
1478 Groups = Queue.LifoQueue()
1479 for port in ports:
1480 L2gid, l2msg = add_l2_unfiltered_group(self.controller, [port], False)
1481 Groups.put(L2gid)
1482 do_barrier(self.controller)
1483 #delete_all_flows(self.controller)
1484 #delete_groups(self.controller, Groups)
Flavio Castro91d1a552016-05-17 16:59:44 -07001485
Flavio Castro423df652016-05-17 20:14:08 -04001486class L3McastToVPN(base_tests.SimpleDataPlane):
1487 """
1488 Mcast routing
1489 """
1490 def runTest(self):
1491 """
1492 port1 (vlan 1)-> port 2 (vlan 2)
1493 """
1494 delete_all_flows(self.controller)
1495 delete_all_groups(self.controller)
1496
1497 #if len(config["port_map"]) <3:
1498 #logging.info("Port count less than 3, can't run this case")
1499 #assert(False)
1500 #return
1501
1502 vlan_id =1
1503 port2_out_vlan=2
1504 port3_out_vlan=3
1505 in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan
1506 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1507 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
1508 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
1509 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
1510 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
1511 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
1512 src_ip=0xc0a80101
1513 src_ip_str="192.168.1.1"
1514 dst_ip=0xe0010101
1515 dst_ip_str="224.1.1.1"
1516
1517 port1=config["port_map"].keys()[0]
1518 port2=config["port_map"].keys()[1]
1519 #port3=config["port_map"].keys()[2]
1520
1521 #add l2 interface group
1522 for port in config["port_map"].keys():
1523 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
1524 #add vlan flow table
1525 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
1526 vlan_id +=1
1527
1528 #add termination flow
1529 add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
1530
1531 #add MPLS interface group
1532 l2_gid = encode_l2_interface_group_id(port2_out_vlan, port2)
1533 mpls_gid2, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, port2_out_vlan, port2)
1534 #l2_gid3 = encode_l2_interface_group_id(port3_out_vlan, port3)
1535 #mpls_gid3, mpls_msg = add_mpls_intf_group(self.controller, l2_gid3, dst_mac, intf_src_mac, port3_out_vlan, port3)
1536 #add L3VPN groups
1537 mpls_label_gid2, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
1538 index=(0x20000+port2), ref_gid= mpls_gid2, push_mpls_header=True, set_mpls_label=port2, set_bos=1, cpy_ttl_outward=True)
1539 #mpls_label_gid3, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
1540 # index=(0x10000+port3), ref_gid= mpls_gid3, push_mpls_header=True, set_mpls_label=port3, set_bos=1, cpy_ttl_outward=True)
1541
1542 mcat_group_msg=add_l3_mcast_group(self.controller, in_vlan, 2, [mpls_label_gid2])
1543 add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id)
1544
1545 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=1,
1546 eth_dst=dst_mac_str,
1547 eth_src=port1_mac_str,
1548 ip_ttl=64,
1549 ip_src=src_ip_str,
1550 ip_dst=dst_ip_str)
1551 pkt=str(parsed_pkt)
1552 self.dataplane.send(port1, pkt)
1553 label = (12, 0, 1, 63)
1554 exp_pkt = mpls_packet(pktlen=100,
1555 eth_dst=dst_mac_str,
1556 eth_src=intf_src_mac_str,
1557 ip_ttl=64,
1558 ip_src=src_ip_str, label= [label],
1559 ip_dst=dst_ip_str)
1560 pkt=str(exp_pkt)
1561 verify_packet(self, pkt, port2)
1562 #verify_packet(self, pkt, port3)
1563 verify_no_other_packets(self)
1564
1565class PacketInSrcMacMiss(base_tests.SimpleDataPlane):
1566 """
1567 Test packet in function on a src-mac miss
1568 Send a packet to each dataplane port and verify that a packet
1569 in message is received from the controller for each
1570 #todo verify you stop receiving after adding rule
1571 """
1572
1573 def runTest(self):
1574 delete_all_flows(self.controller)
1575 delete_all_groups(self.controller)
1576
1577 ports = sorted(config["port_map"].keys())
1578 for port in ports:
1579 add_one_l2_interface_group(self.controller, port, 1, True, False)
1580 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
1581
1582 parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
1583 vlan_vid=0x1001, dl_vlan_enable=True)
1584 vlan_pkt = str(parsed_vlan_pkt)
1585
1586 for of_port in config["port_map"].keys():
1587 logging.info("PacketInMiss test, port %d", of_port)
1588 self.dataplane.send(of_port, vlan_pkt)
1589
1590 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH)
1591
1592 verify_no_other_packets(self)