blob: b2a11be807b8b13f739adbf13d551c462831a29a [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 Castro8c37e1c2016-07-19 18:26:33 -070022 try:
23 parsed_vlan_pkt = simple_udp_packet(pktlen=104,
24 vlan_vid=0x1001,
25 dl_vlan_enable=True)
26 vlan_pkt = str(parsed_vlan_pkt)
27 # create match
28 match = ofp.match()
29 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
30 match.oxm_list.append(ofp.oxm.ip_proto(2))
31 request = ofp.message.flow_add(
32 table_id=60,
33 cookie=42,
34 match=match,
35 instructions=[
36 ofp.instruction.apply_actions(
37 actions=[
38 ofp.action.output(
39 port=ofp.OFPP_CONTROLLER,
40 max_len=ofp.OFPCML_NO_BUFFER)]), ],
41 buffer_id=ofp.OFP_NO_BUFFER,
42 priority=1)
43 logging.info("Inserting packet in flow to controller")
44 self.controller.message_send(request)
Flavio Castro1c9b1252016-02-04 18:42:58 -050045
Flavio Castro8c37e1c2016-07-19 18:26:33 -070046 for of_port in config["port_map"].keys():
47 logging.info("PacketInMiss test, port %d", of_port)
48 self.dataplane.send(of_port, vlan_pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -050049
Flavio Castro8c37e1c2016-07-19 18:26:33 -070050 verify_no_packet_in(self, vlan_pkt, of_port)
51 delete_all_flows(self.controller)
52 do_barrier(self.controller)
Flavio Castro6d498522015-12-15 14:05:04 -050053
Flavio Castro8c37e1c2016-07-19 18:26:33 -070054 match = ofp.match()
55 match.oxm_list.append(ofp.oxm.eth_type(0x0800))
56 match.oxm_list.append(ofp.oxm.ip_proto(17))
57 request = ofp.message.flow_add(
58 table_id=60,
59 cookie=42,
60 match=match,
61 instructions=[
62 ofp.instruction.apply_actions(
63 actions=[
64 ofp.action.output(
65 port=ofp.OFPP_CONTROLLER,
66 max_len=ofp.OFPCML_NO_BUFFER)]), ],
67 buffer_id=ofp.OFP_NO_BUFFER,
68 priority=1)
69 logging.info("Inserting packet in flow to controller")
70 self.controller.message_send(request)
71 do_barrier(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -050072
Flavio Castro8c37e1c2016-07-19 18:26:33 -070073 for of_port in config["port_map"].keys():
74 logging.info("PacketInMiss test, port %d", of_port)
75 self.dataplane.send(of_port, vlan_pkt)
Flavio Castro6d498522015-12-15 14:05:04 -050076
Flavio Castro8c37e1c2016-07-19 18:26:33 -070077 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
Flavio Castro6d498522015-12-15 14:05:04 -050078
Flavio Castro8c37e1c2016-07-19 18:26:33 -070079 verify_no_other_packets(self)
80 finally:
81 delete_all_flows(self.controller)
82 delete_all_groups(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -050083
Flavio Castroaf2b4502016-02-02 17:41:32 -050084
Flavio Castro67d8bd52016-02-03 14:22:14 -050085@disabled
Flavio Castro7fb6ca92015-12-16 15:50:14 -050086class ArpNL2(base_tests.SimpleDataPlane):
Flavio Castro1c9b1252016-02-04 18:42:58 -050087 def runTest(self):
Flavio Castro7fb6ca92015-12-16 15:50:14 -050088 delete_all_flows(self.controller)
89 delete_all_groups(self.controller)
90
91 ports = sorted(config["port_map"].keys())
92 match = ofp.match()
93 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
94 request = ofp.message.flow_add(
Flavio Castro1c9b1252016-02-04 18:42:58 -050095 table_id=60,
96 cookie=42,
97 match=match,
98 instructions=[
99 ofp.instruction.apply_actions(
100 actions=[
101 ofp.action.output(
102 port=ofp.OFPP_CONTROLLER,
103 max_len=ofp.OFPCML_NO_BUFFER)]),
104 ],
105 buffer_id=ofp.OFP_NO_BUFFER,
106 priority=40000)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500107 self.controller.message_send(request)
108 for port in ports:
Flavio Castro932014b2016-01-05 18:29:15 -0500109 add_one_l2_interface_group(self.controller, port, 1, False, False)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500110 add_one_vlan_table_flow(self.controller, port, 1,
111 flag=VLAN_TABLE_FLAG_ONLY_BOTH)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500112 group_id = encode_l2_interface_group_id(1, port)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500113 add_bridge_flow(self.controller,
114 [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id,
115 True)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500116 do_barrier(self.controller)
117 parsed_arp_pkt = simple_arp_packet()
118 arp_pkt = str(parsed_arp_pkt)
119
120 for out_port in ports:
121 self.dataplane.send(out_port, arp_pkt)
122 verify_packet_in(self, arp_pkt, out_port, ofp.OFPR_ACTION)
123 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500124 mac_dst = '00:12:34:56:78:%02X' % out_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500125 for in_port in ports:
126 if in_port == out_port:
127 continue
128 # change source based on port number to avoid packet-ins from learning
Flavio Castro1c9b1252016-02-04 18:42:58 -0500129 mac_src = '00:12:34:56:78:%02X' % in_port
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500130 parsed_pkt = simple_tcp_packet(eth_dst=mac_dst, eth_src=mac_src)
131 pkt = str(parsed_pkt)
132 self.dataplane.send(in_port, pkt)
133
134 for ofport in ports:
135 if ofport in [out_port]:
136 verify_packet(self, pkt, ofport)
137 else:
138 verify_no_packet(self, pkt, ofport)
139
140 verify_no_other_packets(self)
141
Flavio Castro1c9b1252016-02-04 18:42:58 -0500142
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500143class PacketInArp(base_tests.SimpleDataPlane):
144 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500145 Verify an ACL rule matching on ethertyper 0x806 will result in a packet-in
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500146 """
147
148 def runTest(self):
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700149 try:
150 parsed_arp_pkt = simple_arp_packet()
151 arp_pkt = str(parsed_arp_pkt)
152 # create match
153 match = ofp.match()
154 match.oxm_list.append(ofp.oxm.eth_type(0x0806))
155 request = ofp.message.flow_add(
156 table_id=60,
157 cookie=42,
158 match=match,
159 instructions=[
160 ofp.instruction.apply_actions(
161 actions=[
162 ofp.action.output(
163 port=ofp.OFPP_CONTROLLER,
164 max_len=ofp.OFPCML_NO_BUFFER)]),
165 ],
166 buffer_id=ofp.OFP_NO_BUFFER,
167 priority=1)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500168
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700169 logging.info("Inserting packet in flow to controller")
170 self.controller.message_send(request)
171 do_barrier(self.controller)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500172
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700173 for of_port in config["port_map"].keys():
174 logging.info("PacketInMiss test, port %d", of_port)
175 self.dataplane.send(of_port, arp_pkt)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500176
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700177 verify_packet_in(self, arp_pkt, of_port, ofp.OFPR_ACTION)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500178
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700179 verify_no_other_packets(self)
180 finally:
181 delete_all_flows(self.controller)
182 delete_all_groups(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500183
Flavio Castro91d1a552016-05-17 16:59:44 -0700184class PacketInIPTable(base_tests.SimpleDataPlane):
185 """
186 Test packet in function on IPTABLE
187 Send a packet to each dataplane port and verify that a packet
188 in message is received from the controller for each
189 #todo verify you stop receiving after adding rule
190 """
191
192 def runTest(self):
Flavio Castrob01d0aa2016-07-20 16:14:48 -0700193 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700194 try:
195 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
196 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
197 dip=0xc0a80001
198 ports = sorted(config["port_map"].keys())
Flavio Castro91d1a552016-05-17 16:59:44 -0700199
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700200 for port in ports:
201 #add l2 interface group
202 vlan_id=port
203 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
204 dst_mac[5]=vlan_id
205 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
206 #add vlan flow table
207 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
208 #add termination flow
209 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
210 #add unicast routing flow
211 dst_ip = dip + (vlan_id<<8)
212 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, l3_msg.group_id, send_ctrl=True)
213 Groups.put(l3_msg.group_id)
Flavio Castro91d1a552016-05-17 16:59:44 -0700214
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700215 do_barrier(self.controller)
Flavio Castro91d1a552016-05-17 16:59:44 -0700216
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700217 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
218 for in_port in ports:
219 mac_src='00:00:00:22:22:%02X' % in_port
220 ip_src='192.168.%02d.1' % in_port
221 for out_port in ports:
222 if in_port == out_port:
223 continue
224 ip_dst='192.168.%02d.1' % out_port
225 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
226 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
227 ip_dst=ip_dst)
228 pkt=str(parsed_pkt)
229 self.dataplane.send(in_port, pkt)
230 verify_packet_in(self, pkt, in_port, ofp.OFPR_ACTION)
231 #verify_no_other_packets(self)
232 finally:
233 delete_all_flows(self.controller)
234 delete_groups(self.controller, Groups)
235 delete_all_groups(self.controller)
Flavio Castro91d1a552016-05-17 16:59:44 -0700236
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500237class L2FloodQinQ(base_tests.SimpleDataPlane):
238 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500239 Verify a tagged frame can be flooded based on its outer vlan
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500240 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500241
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500242 def runTest(self):
Flavio Castrob01d0aa2016-07-20 16:14:48 -0700243 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700244 try:
245 ports = sorted(config["port_map"].keys())
246 vlan_id = 1
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500247
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700248 for port in ports:
249 L2gid, l2msg = add_one_l2_interface_group(self.controller, port,
250 vlan_id, True, False)
251 add_one_vlan_table_flow(self.controller, port, vlan_id,
252 flag=VLAN_TABLE_FLAG_ONLY_TAG)
253 Groups.put(L2gid)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500254
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700255 msg = add_l2_flood_group(self.controller, ports, vlan_id, vlan_id)
256 Groups.put(msg.group_id)
257 add_bridge_flow(self.controller, None, vlan_id, msg.group_id, True)
258 do_barrier(self.controller)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500259
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700260 # verify flood
261 for ofport in ports:
262 # change dest based on port number
263 mac_src = '00:12:34:56:78:%02X' % ofport
264 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108,
265 out_dl_vlan_enable=True,
266 out_vlan_vid=vlan_id,
267 in_dl_vlan_enable=True,
268 in_vlan_vid=10,
269 eth_dst='00:12:34:56:78:9a',
270 eth_src=mac_src)
271 pkt = str(parsed_pkt)
272 self.dataplane.send(ofport, pkt)
273 # self won't rx packet
274 verify_no_packet(self, pkt, ofport)
275 # others will rx packet
276 tmp_ports = list(ports)
277 tmp_ports.remove(ofport)
278 verify_packets(self, pkt, tmp_ports)
Flavio Castro1b5c21d2015-12-08 12:41:56 -0500279
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700280 verify_no_other_packets(self)
281 finally:
282 delete_all_flows(self.controller)
283 delete_groups(self.controller, Groups)
284 delete_all_groups(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500285
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500286@disabled
Flavio Castro184cefe2015-11-19 20:52:49 -0500287class L2FloodTagged(base_tests.SimpleDataPlane):
288 """
289 Test L2 flood to a vlan
290 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 -0500291 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500292
Flavio Castro184cefe2015-11-19 20:52:49 -0500293 def runTest(self):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500294 # Hashes Test Name and uses it as id for installing unique groups
295 vlan_id = abs(hash(inspect.stack()[0][3])) % (256)
Flavio Castroce3bfeb2016-02-04 14:06:55 -0500296 print vlan_id
Flavio Castroaba28ff2016-02-03 16:47:48 -0500297
Flavio Castro184cefe2015-11-19 20:52:49 -0500298 ports = sorted(config["port_map"].keys())
Flavio Castro34352e72015-12-07 20:01:51 -0500299
Flavio Castro184cefe2015-11-19 20:52:49 -0500300 delete_all_flows(self.controller)
301 delete_all_groups(self.controller)
302
Flavio Castro184cefe2015-11-19 20:52:49 -0500303 # Installing flows to avoid packet-in
304 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500305 add_one_l2_interface_group(self.controller, port, vlan_id, True,
306 False)
307 add_one_vlan_table_flow(self.controller, port, vlan_id,
308 flag=VLAN_TABLE_FLAG_ONLY_TAG)
309 msg = add_l2_flood_group(self.controller, ports, vlan_id, vlan_id)
Flavio Castroaba28ff2016-02-03 16:47:48 -0500310 add_bridge_flow(self.controller, None, vlan_id, msg.group_id, True)
Flavio Castro184cefe2015-11-19 20:52:49 -0500311 do_barrier(self.controller)
312
Flavio Castro1c9b1252016-02-04 18:42:58 -0500313 # verify flood
Flavio Castro184cefe2015-11-19 20:52:49 -0500314 for ofport in ports:
315 # change dest based on port number
Flavio Castro1c9b1252016-02-04 18:42:58 -0500316 pkt = str(simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vlan_id,
317 eth_dst='00:12:34:56:78:9a'))
Flavio Castro184cefe2015-11-19 20:52:49 -0500318 self.dataplane.send(ofport, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500319 # self won't rx packet
Flavio Castro184cefe2015-11-19 20:52:49 -0500320 verify_no_packet(self, pkt, ofport)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500321 # others will rx packet
322 tmp_ports = list(ports)
Flavio Castro184cefe2015-11-19 20:52:49 -0500323 tmp_ports.remove(ofport)
324 verify_packets(self, pkt, tmp_ports)
Flavio Castro184cefe2015-11-19 20:52:49 -0500325 verify_no_other_packets(self)
Flavio Castroaabb5792015-11-18 19:03:50 -0500326
Flavio Castro1c9b1252016-02-04 18:42:58 -0500327
Flavio Castroaabb5792015-11-18 19:03:50 -0500328class L2UnicastTagged(base_tests.SimpleDataPlane):
329 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500330 Verify L2 forwarding works
Flavio Castroaabb5792015-11-18 19:03:50 -0500331 """
Flavio Castro1c9b1252016-02-04 18:42:58 -0500332
Flavio Castroaabb5792015-11-18 19:03:50 -0500333 def runTest(self):
Flavio Castrob01d0aa2016-07-20 16:14:48 -0700334
335 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700336 try:
337 ports = sorted(config["port_map"].keys())
338 vlan_id = 1;
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700339 for port in ports:
340 L2gid, l2msg = add_one_l2_interface_group(self.controller, port,
341 vlan_id, True, False)
342 add_one_vlan_table_flow(self.controller, port, vlan_id,
343 flag=VLAN_TABLE_FLAG_ONLY_TAG)
344 Groups.put(L2gid)
345 add_bridge_flow(self.controller,
346 [0x00, 0x12, 0x34, 0x56, 0x78, port], vlan_id,
347 L2gid, True)
348 do_barrier(self.controller)
Flavio Castro6efe1862015-11-18 16:28:06 -0500349
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700350 for out_port in ports:
351 # change dest based on port number
352 mac_dst = '00:12:34:56:78:%02X' % out_port
353 for in_port in ports:
354 if in_port == out_port:
355 continue
356 pkt = str(
357 simple_tcp_packet(dl_vlan_enable=True, vlan_vid=vlan_id,
358 eth_dst=mac_dst))
359 self.dataplane.send(in_port, pkt)
360 for ofport in ports:
361 if ofport in [out_port]:
362 verify_packet(self, pkt, ofport)
363 else:
364 verify_no_packet(self, pkt, ofport)
365 verify_no_other_packets(self)
366 finally:
367 delete_all_flows(self.controller)
368 delete_groups(self.controller, Groups)
369 delete_all_groups(self.controller)
Flavio Castro6efe1862015-11-18 16:28:06 -0500370
Flavio Castrob6773032015-11-19 22:49:24 -0500371class Mtu1500(base_tests.SimpleDataPlane):
Flavio Castrob6773032015-11-19 22:49:24 -0500372 def runTest(self):
Flavio Castrob01d0aa2016-07-20 16:14:48 -0700373 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700374 try:
375 ports = sorted(config["port_map"].keys())
376 vlan_id = 18
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700377 for port in ports:
378 L2gid, msg = add_one_l2_interface_group(self.controller, port,
379 vlan_id, True, False)
380 add_one_vlan_table_flow(self.controller, port, vlan_id,
381 flag=VLAN_TABLE_FLAG_ONLY_TAG)
382 Groups.put(L2gid)
383 add_bridge_flow(self.controller,
384 [0x00, 0x12, 0x34, 0x56, 0x78, port], vlan_id,
385 L2gid, True)
386 do_barrier(self.controller)
Flavio Castrob6773032015-11-19 22:49:24 -0500387
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700388 for out_port in ports:
389 # change dest based on port number
390 mac_dst = '00:12:34:56:78:%02X' % out_port
391 for in_port in ports:
392 if in_port == out_port:
393 continue
394 pkt = str(simple_tcp_packet(pktlen=1500, dl_vlan_enable=True,
395 vlan_vid=vlan_id, eth_dst=mac_dst))
396 self.dataplane.send(in_port, pkt)
397 for ofport in ports:
398 if ofport in [out_port]:
399 verify_packet(self, pkt, ofport)
400 else:
401 verify_no_packet(self, pkt, ofport)
402 verify_no_other_packets(self)
403 finally:
404 delete_all_flows(self.controller)
405 delete_groups(self.controller, Groups)
406 delete_all_groups(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500407
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):
Flavio Castrob01d0aa2016-07-20 16:14:48 -0700414 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700415 try:
416 test_id = 26
417 if len(config["port_map"]) < 2:
418 logging.info("Port count less than 2, can't run this case")
419 return
Flavio Castrod8f8af22015-12-02 18:19:26 -0500420
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700421 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
422 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
423 dip = 0xc0a80001
424 ports = config["port_map"].keys()
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700425 for port in ports:
426 # add l2 interface group
427 vlan_id = port + test_id
428 l2gid, msg = add_one_l2_interface_group(self.controller, port,
429 vlan_id=vlan_id,
430 is_tagged=True,
431 send_barrier=False)
432 dst_mac[5] = vlan_id
433 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
434 id=vlan_id, src_mac=intf_src_mac,
435 dst_mac=dst_mac)
436 # add vlan flow table
437 add_one_vlan_table_flow(self.controller, port, vlan_id,
438 flag=VLAN_TABLE_FLAG_ONLY_TAG)
439 # add termination flow
440 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
441 vlan_id)
442 # add unicast routing flow
443 dst_ip = dip + (vlan_id << 8)
444 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
445 0xffffffff, l3_msg.group_id)
446 Groups.put(l2gid)
447 Groups.put(l3_msg.group_id)
448 do_barrier(self.controller)
Flavio Castrod8f8af22015-12-02 18:19:26 -0500449
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700450 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
451 for in_port in ports:
452 mac_src = '00:00:00:22:32:%02X' % (test_id + in_port)
453 ip_src = '192.168.%02d.1' % (test_id + in_port)
454 for out_port in ports:
455 if in_port == out_port:
456 continue
457 ip_dst = '192.168.%02d.1' % (test_id + out_port)
458 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
459 vlan_vid=(test_id + in_port),
460 eth_dst=switch_mac,
461 eth_src=mac_src, ip_ttl=64,
462 ip_src=ip_src,
463 ip_dst=ip_dst)
464 pkt = str(parsed_pkt)
465 self.dataplane.send(in_port, pkt)
466 # build expected packet
467 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
468 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
469 vlan_vid=(test_id + out_port),
470 eth_dst=mac_dst, eth_src=switch_mac,
471 ip_ttl=63,
472 ip_src=ip_src, ip_dst=ip_dst)
473 pkt = str(exp_pkt)
474 verify_packet(self, pkt, out_port)
475 verify_no_other_packets(self)
476 finally:
477 delete_all_flows(self.controller)
478 delete_groups(self.controller, Groups)
479 delete_all_groups(self.controller)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500480
Flavio Castro2262fd42016-02-04 19:03:36 -0500481class _32VPN(base_tests.SimpleDataPlane):
482 """
483 Insert IP packet
484 Receive MPLS packet
485 """
486
487 def runTest(self):
Flavio Castrob01d0aa2016-07-20 16:14:48 -0700488 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700489 try:
490 if len(config["port_map"]) < 2:
491 logging.info("Port count less than 2, can't run this case")
492 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500493
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700494 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
495 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
496 dip = 0xc0a80001
497 ports = config["port_map"].keys()
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700498 for port in ports:
499 # add l2 interface group
500 id = port
501 vlan_id = port
502 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
503 vlan_id, True, True)
504 dst_mac[5] = vlan_id
505 # add MPLS interface group
506 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
507 dst_mac, intf_src_mac,
508 vlan_id, id)
509 # add MPLS L3 VPN group
510 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
511 self.controller,
512 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
513 index=id, ref_gid=mpls_gid, push_mpls_header=True,
514 set_mpls_label=port, set_bos=1, set_ttl=32)
515 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
516 do_barrier(self.controller)
517 # add vlan flow table
518 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=2,
519 flag=VLAN_TABLE_FLAG_ONLY_TAG)
520 # add termination flow
521 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
522 vlan_id)
523 # add routing flow
524 dst_ip = dip + (vlan_id << 8)
525 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
526 0xffffffff, mpls_label_gid,vrf=2)
527 Groups._put(l2_gid)
528 Groups._put(mpls_gid)
529 Groups._put(mpls_label_gid)
Flavio Castro2262fd42016-02-04 19:03:36 -0500530 do_barrier(self.controller)
Flavio Castro2262fd42016-02-04 19:03:36 -0500531
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700532 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
533 for in_port in ports:
534 ip_src = '192.168.%02d.1' % (in_port)
535 for out_port in ports:
536 if in_port == out_port:
537 continue
538 ip_dst = '192.168.%02d.1' % (out_port)
539 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
540 vlan_vid=(in_port),
541 eth_dst=switch_mac, ip_ttl=64,
542 ip_src=ip_src,
543 ip_dst=ip_dst)
544 pkt = str(parsed_pkt)
545 self.dataplane.send(in_port, pkt)
546 # build expect packet
547 mac_dst = '00:00:00:22:22:%02X' % (out_port)
548 label = (out_port, 0, 1, 32)
549 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
550 vlan_vid=(out_port), ip_ttl=63,
551 ip_src=ip_src,
552 ip_dst=ip_dst, eth_dst=mac_dst,
553 eth_src=switch_mac, label=[label])
554 pkt = str(exp_pkt)
555 verify_packet(self, pkt, out_port)
556 verify_no_other_packets(self)
557 finally:
558 delete_all_flows(self.controller)
559 delete_groups(self.controller, Groups)
560 delete_all_groups(self.controller)
Flavio Castro2262fd42016-02-04 19:03:36 -0500561
562class _32EcmpVpn(base_tests.SimpleDataPlane):
563 """
564 Insert IP packet
565 Receive MPLS packet
566 """
567
568 def runTest(self):
Flavio Castrob01d0aa2016-07-20 16:14:48 -0700569 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700570 try:
571 if len(config["port_map"]) < 2:
572 logging.info("Port count less than 2, can't run this case")
573 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500574
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700575 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
576 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
577 dip = 0xc0a80001
578 ports = config["port_map"].keys()
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700579 for port in ports:
580 # add l2 interface group
581 id = port
582 vlan_id = port
583 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
584 vlan_id, True, True)
585 dst_mac[5] = vlan_id
586 # add MPLS interface group
587 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
588 dst_mac, intf_src_mac,
589 vlan_id, id)
590 # add MPLS L3 VPN group
591 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
592 self.controller,
593 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
594 index=id, ref_gid=mpls_gid, push_mpls_header=True,
595 set_mpls_label=port, set_bos=1, set_ttl=32)
596 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
597 do_barrier(self.controller)
598 # add vlan flow table
599 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0,
600 flag=VLAN_TABLE_FLAG_ONLY_TAG)
601 # add termination flow
602 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
603 vlan_id)
604 # add routing flow
605 dst_ip = dip + (vlan_id << 8)
606 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
607 0xffffffff, ecmp_msg.group_id)
608 Groups._put(l2_gid)
609 Groups._put(mpls_gid)
610 Groups._put(mpls_label_gid)
611 Groups._put(ecmp_msg.group_id)
Flavio Castro2262fd42016-02-04 19:03:36 -0500612 do_barrier(self.controller)
Flavio Castro2262fd42016-02-04 19:03:36 -0500613
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700614 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
615 for in_port in ports:
616 ip_src = '192.168.%02d.1' % (in_port)
617 for out_port in ports:
618 if in_port == out_port:
619 continue
620 ip_dst = '192.168.%02d.1' % (out_port)
621 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
622 vlan_vid=(in_port),
623 eth_dst=switch_mac, ip_ttl=64,
624 ip_src=ip_src,
625 ip_dst=ip_dst)
626 pkt = str(parsed_pkt)
627 self.dataplane.send(in_port, pkt)
628 # build expect packet
629 mac_dst = '00:00:00:22:22:%02X' % (out_port)
630 label = (out_port, 0, 1, 32)
631 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
632 vlan_vid=(out_port), ip_ttl=63,
633 ip_src=ip_src,
634 ip_dst=ip_dst, eth_dst=mac_dst,
635 eth_src=switch_mac, label=[label])
636 pkt = str(exp_pkt)
637 verify_packet(self, pkt, out_port)
638 verify_no_other_packets(self)
639 finally:
640 delete_all_flows(self.controller)
641 delete_groups(self.controller, Groups)
642 delete_all_groups(self.controller)
Flavio Castro2262fd42016-02-04 19:03:36 -0500643
644class _32ECMPL3(base_tests.SimpleDataPlane):
645 """
646 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
647 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
648 """
649
650 def runTest(self):
Flavio Castrob01d0aa2016-07-20 16:14:48 -0700651 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700652 try:
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700653 if len(config["port_map"]) < 2:
654 logging.info("Port count less than 2, can't run this case")
655 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500656
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700657 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
658 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
659 dip = 0xc0a80001
660 # Hashes Test Name and uses it as id for installing unique groups
661 ports = config["port_map"].keys()
662 for port in ports:
663 vlan_id = port
664 id = port
665 # add l2 interface group
666 l2_gid, msg = add_one_l2_interface_group(self.controller, port,
667 vlan_id=vlan_id,
668 is_tagged=True,
669 send_barrier=False)
670 dst_mac[5] = vlan_id
671 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
672 id=id, src_mac=intf_src_mac,
673 dst_mac=dst_mac)
674 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
675 # add vlan flow table
676 add_one_vlan_table_flow(self.controller, port, vlan_id,
677 flag=VLAN_TABLE_FLAG_ONLY_TAG)
678 # add termination flow
679 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
680 vlan_id)
681 # add unicast routing flow
682 dst_ip = dip + (vlan_id << 8)
683 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
684 0xffffffff, ecmp_msg.group_id)
685 Groups._put(l2_gid)
686 Groups._put(l3_msg.group_id)
687 Groups._put(ecmp_msg.group_id)
688 do_barrier(self.controller)
Flavio Castro2262fd42016-02-04 19:03:36 -0500689
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700690 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
691 for in_port in ports:
692 mac_src = '00:00:00:22:22:%02X' % in_port
693 ip_src = '192.168.%02d.1' % in_port
694 for out_port in ports:
695 if in_port == out_port:
696 continue
697 ip_dst = '192.168.%02d.1' % out_port
698 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
699 vlan_vid=in_port,
700 eth_dst=switch_mac,
701 eth_src=mac_src, ip_ttl=64,
702 ip_src=ip_src,
703 ip_dst=ip_dst)
704 pkt = str(parsed_pkt)
705 self.dataplane.send(in_port, pkt)
706 # build expected packet
707 mac_dst = '00:00:00:22:22:%02X' % out_port
708 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
709 vlan_vid=out_port,
710 eth_dst=mac_dst, eth_src=switch_mac,
711 ip_ttl=63,
712 ip_src=ip_src, ip_dst=ip_dst)
713 pkt = str(exp_pkt)
714 verify_packet(self, pkt, out_port)
715 verify_no_other_packets(self)
716 finally:
717 delete_all_flows(self.controller)
718 delete_groups(self.controller, Groups)
719 delete_all_groups(self.controller)
Flavio Castro2262fd42016-02-04 19:03:36 -0500720
Flavio Castro2262fd42016-02-04 19:03:36 -0500721class _24VPN(base_tests.SimpleDataPlane):
722 """
723 Insert IP packet
724 Receive MPLS packet
725 """
726
727 def runTest(self):
Flavio Castrob01d0aa2016-07-20 16:14:48 -0700728 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700729 try:
730 if len(config["port_map"]) < 2:
731 logging.info("Port count less than 2, can't run this case")
732 return
Flavio Castro2262fd42016-02-04 19:03:36 -0500733
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700734 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
735 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
736 dip = 0xc0a80001
737 ports = config["port_map"].keys()
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700738 for port in ports:
739 # add l2 interface group
740 id = port
741 vlan_id = port
742 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
743 dst_mac[5] = vlan_id
744 # add MPLS interface group
745 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, id)
746 # add MPLS L3 VPN group
747 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
748 self.controller,
749 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
750 index=id, ref_gid=mpls_gid, push_mpls_header=True,
751 set_mpls_label=port, set_bos=1, set_ttl=32)
752 # ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
753 do_barrier(self.controller)
754 # add vlan flow table
755 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0,
756 flag=VLAN_TABLE_FLAG_ONLY_TAG)
757 # add termination flow
758 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
759 vlan_id)
760 # add routing flow
761 dst_ip = dip + (vlan_id << 8)
762 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
763 0xffffff00, mpls_label_gid)
764 Groups._put(l2_gid)
765 Groups._put(mpls_gid)
766 Groups._put(mpls_label_gid)
Flavio Castro2262fd42016-02-04 19:03:36 -0500767 do_barrier(self.controller)
Flavio Castro2262fd42016-02-04 19:03:36 -0500768
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700769 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
770 for in_port in ports:
771 ip_src = '192.168.%02d.1' % (in_port)
772 for out_port in ports:
773 if in_port == out_port:
774 continue
775 ip_dst = '192.168.%02d.1' % (out_port)
776 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
777 vlan_vid=(in_port),
778 eth_dst=switch_mac, ip_ttl=64,
779 ip_src=ip_src,
780 ip_dst=ip_dst)
781 pkt = str(parsed_pkt)
782 self.dataplane.send(in_port, pkt)
783 # build expect packet
784 mac_dst = '00:00:00:22:22:%02X' % (out_port)
785 label = (out_port, 0, 1, 32)
786 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
787 vlan_vid=(out_port), ip_ttl=63,
788 ip_src=ip_src,
789 ip_dst=ip_dst, eth_dst=mac_dst,
790 eth_src=switch_mac, label=[label])
791 pkt = str(exp_pkt)
792 verify_packet(self, pkt, out_port)
793 verify_no_other_packets(self)
794 finally:
795 delete_all_flows(self.controller)
796 delete_groups(self.controller, Groups)
797 delete_all_groups(self.controller)
Flavio Castro2262fd42016-02-04 19:03:36 -0500798
Flavio Castro2262fd42016-02-04 19:03:36 -0500799class _24EcmpVpn(base_tests.SimpleDataPlane):
Flavio Castrod8f8af22015-12-02 18:19:26 -0500800 """
801 Insert IP packet
802 Receive MPLS packet
803 """
Flavio Castro72a45d52015-12-02 16:37:05 -0500804
Flavio Castro1c9b1252016-02-04 18:42:58 -0500805 def runTest(self):
Flavio Castrob01d0aa2016-07-20 16:14:48 -0700806 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700807 try:
808 if len(config["port_map"]) < 2:
809 logging.info("Port count less than 2, can't run this case")
810 return
811 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
812 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
813 dip = 0xc0a80001
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700814 ports = config["port_map"].keys()
815 for port in ports:
816 # add l2 interface group
817 id = port
818 vlan_id = id
819 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
820 vlan_id, True, True)
821 dst_mac[5] = vlan_id
822 # add MPLS interface group
823 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
824 dst_mac, intf_src_mac,
825 vlan_id, id)
826 # add MPLS L3 VPN group
827 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
828 self.controller,
829 subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
830 index=id, ref_gid=mpls_gid, push_mpls_header=True,
831 set_mpls_label=port, set_bos=1, set_ttl=32)
832 ecmp_msg = add_l3_ecmp_group(self.controller, id, [mpls_label_gid])
833 do_barrier(self.controller)
834 # add vlan flow table
835 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0,
836 flag=VLAN_TABLE_FLAG_ONLY_TAG)
837 # add termination flow
838 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
839 vlan_id)
840 # add routing flow
841 dst_ip = dip + (vlan_id << 8)
842 # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, mpls_label_gid, vrf=2)
843 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
844 0xffffff00, ecmp_msg.group_id, vrf=0)
845 Groups._put(l2_gid)
846 Groups._put(mpls_gid)
847 Groups._put(mpls_label_gid)
848 Groups._put(ecmp_msg.group_id)
849
Flavio Castro80730822015-12-11 15:38:47 -0500850 do_barrier(self.controller)
Flavio Castro80730822015-12-11 15:38:47 -0500851
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700852 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
853 for in_port in ports:
854 mac_src = '00:00:00:22:22:%02X' % (in_port)
855 ip_src = '192.168.%02d.1' % (in_port)
856 for out_port in ports:
857 if in_port == out_port:
858 continue
859 ip_dst = '192.168.%02d.1' % (out_port)
860 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
861 vlan_vid=(in_port),
862 eth_dst=switch_mac,
863 eth_src=mac_src, ip_ttl=64,
864 ip_src=ip_src,
865 ip_dst=ip_dst)
866 pkt = str(parsed_pkt)
867 self.dataplane.send(in_port, pkt)
868 # build expect packet
869 mac_dst = '00:00:00:22:22:%02X' % out_port
870 label = (out_port, 0, 1, 32)
871 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
872 vlan_vid=(out_port), ip_ttl=63,
873 ip_src=ip_src,
874 ip_dst=ip_dst, eth_dst=mac_dst,
875 eth_src=switch_mac, label=[label])
876 pkt = str(exp_pkt)
877 verify_packet(self, pkt, out_port)
878 verify_no_other_packets(self)
879 finally:
880 delete_all_flows(self.controller)
881 delete_groups(self.controller, Groups)
882 delete_all_groups(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500883
Flavio Castro2262fd42016-02-04 19:03:36 -0500884class _24ECMPL3(base_tests.SimpleDataPlane):
Flavio Castro80730822015-12-11 15:38:47 -0500885 """
Flavio Castro2262fd42016-02-04 19:03:36 -0500886 Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) ,
887 Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
Flavio Castro80730822015-12-11 15:38:47 -0500888 """
Flavio Castro80730822015-12-11 15:38:47 -0500889
Flavio Castro1c9b1252016-02-04 18:42:58 -0500890 def runTest(self):
Flavio Castrob01d0aa2016-07-20 16:14:48 -0700891 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700892 try:
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700893 if len(config["port_map"]) < 2:
894 logging.info("Port count less than 2, can't run this case")
895 return
Flavio Castro80730822015-12-11 15:38:47 -0500896
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700897 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
898 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
899 dip = 0xc0a80001
900 # Hashes Test Name and uses it as id for installing unique groups
901 ports = config["port_map"].keys()
902 for port in ports:
903 vlan_id = port
904 id = port
905 # add l2 interface group
906 l2_gid, msg = add_one_l2_interface_group(self.controller, port,
907 vlan_id=vlan_id,
908 is_tagged=True,
909 send_barrier=False)
910 dst_mac[5] = vlan_id
911 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
912 id=id, src_mac=intf_src_mac,
913 dst_mac=dst_mac)
914 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
915 # add vlan flow table
916 add_one_vlan_table_flow(self.controller, port, vlan_id,
917 flag=VLAN_TABLE_FLAG_ONLY_TAG)
918 # add termination flow
919 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
920 vlan_id)
921 # add unicast routing flow
922 dst_ip = dip + (vlan_id << 8)
923 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
924 0xffffff00, ecmp_msg.group_id)
925 Groups._put(l2_gid)
926 Groups._put(l3_msg.group_id)
927 Groups._put(ecmp_msg.group_id)
928 do_barrier(self.controller)
Flavio Castro72a45d52015-12-02 16:37:05 -0500929
Flavio Castro8c37e1c2016-07-19 18:26:33 -0700930 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
931 for in_port in ports:
932 mac_src = '00:00:00:22:22:%02X' % in_port
933 ip_src = '192.168.%02d.1' % in_port
934 for out_port in ports:
935 if in_port == out_port:
936 continue
937 ip_dst = '192.168.%02d.1' % out_port
938 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
939 vlan_vid=in_port,
940 eth_dst=switch_mac,
941 eth_src=mac_src, ip_ttl=64,
942 ip_src=ip_src,
943 ip_dst=ip_dst)
944 pkt = str(parsed_pkt)
945 self.dataplane.send(in_port, pkt)
946 # build expected packet
947 mac_dst = '00:00:00:22:22:%02X' % out_port
948 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
949 vlan_vid=out_port,
950 eth_dst=mac_dst, eth_src=switch_mac,
951 ip_ttl=63,
952 ip_src=ip_src, ip_dst=ip_dst)
953 pkt = str(exp_pkt)
954 verify_packet(self, pkt, out_port)
955 verify_no_other_packets(self)
956 finally:
957 delete_all_flows(self.controller)
958 delete_groups(self.controller, Groups)
959 delete_all_groups(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500960
Flavio Castroaba28ff2016-02-03 16:47:48 -0500961@disabled
Flavio Castro80730822015-12-11 15:38:47 -0500962class MPLSBUG(base_tests.SimpleDataPlane):
Flavio Castro80730822015-12-11 15:38:47 -0500963 def runTest(self):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500964 if len(config["port_map"]) < 2:
Flavio Castro80730822015-12-11 15:38:47 -0500965 logging.info("Port count less than 2, can't run this case")
966 return
Flavio Castro1c9b1252016-02-04 18:42:58 -0500967 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
968 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
969 dip = 0xc0a80001
970 Groups = Queue.LifoQueue()
Flavio Castro80730822015-12-11 15:38:47 -0500971 ports = config["port_map"].keys()
972 for port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -0500973 # add l2 interface group
974 vlan_id = port
975 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
976 vlan_id, True, False)
977 dst_mac[5] = vlan_id
978 # add L3 Unicast group
979 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
980 id=vlan_id, src_mac=intf_src_mac,
981 dst_mac=dst_mac)
982 # add vlan flow table
983 add_one_vlan_table_flow(self.controller, port, vlan_id,
984 flag=VLAN_TABLE_FLAG_ONLY_BOTH)
985 # add termination flow
986 add_termination_flow(self.controller, port, 0x8847, intf_src_mac,
987 vlan_id, goto_table=24)
988 # add mpls flow
Flavio Castro80730822015-12-11 15:38:47 -0500989 add_mpls_flow(self.controller, l3_msg.group_id, port)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500990 # add termination flow
991 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
992 vlan_id)
993 # add unicast routing flow
994 dst_ip = dip + (vlan_id << 8)
995 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
996 0xffffffff, l3_msg.group_id)
997 Groups._put(l2_gid)
998 Groups._put(l3_msg.group_id)
Flavio Castro80730822015-12-11 15:38:47 -0500999 do_barrier(self.controller)
1000
1001 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1002 for in_port in ports:
Flavio Castro1c9b1252016-02-04 18:42:58 -05001003 mac_src = '00:00:00:22:22:%02X' % in_port
1004 ip_src = '192.168.%02d.1' % in_port
Flavio Castro80730822015-12-11 15:38:47 -05001005 for out_port in ports:
1006 if in_port == out_port:
Flavio Castro1c9b1252016-02-04 18:42:58 -05001007 continue
1008 ip_dst = '192.168.%02d.1' % out_port
Flavio Castro80730822015-12-11 15:38:47 -05001009 switch_mac = "00:00:00:cc:cc:cc"
1010 label = (out_port, 0, 1, 32)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001011 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
1012 vlan_vid=in_port, ip_src=ip_src,
1013 ip_dst=ip_dst, eth_dst=switch_mac,
1014 eth_src=mac_src, label=[label])
1015 pkt = str(parsed_pkt)
Flavio Castro80730822015-12-11 15:38:47 -05001016 self.dataplane.send(in_port, pkt)
1017
Flavio Castro1c9b1252016-02-04 18:42:58 -05001018 # build expect packet
1019 mac_dst = '00:00:00:22:22:%02X' % out_port
1020 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1021 vlan_vid=out_port,
1022 eth_dst=mac_dst, eth_src=switch_mac,
1023 ip_ttl=31, ip_src=ip_src,
1024 ip_dst=ip_dst)
1025 pkt = str(exp_pkt)
Flavio Castro80730822015-12-11 15:38:47 -05001026 verify_packet(self, pkt, out_port)
1027 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001028
1029 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1030 vlan_vid=in_port,
1031 eth_dst=switch_mac,
1032 eth_src=mac_src, ip_ttl=64,
1033 ip_src=ip_src,
1034 ip_dst=ip_dst)
1035 pkt = str(parsed_pkt)
Flavio Castro80730822015-12-11 15:38:47 -05001036 self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001037 # build expected packet
1038 mac_dst = '00:00:00:22:22:%02X' % out_port
1039 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1040 vlan_vid=out_port,
1041 eth_dst=mac_dst, eth_src=switch_mac,
1042 ip_ttl=63,
1043 ip_src=ip_src, ip_dst=ip_dst)
1044 pkt = str(exp_pkt)
Flavio Castro80730822015-12-11 15:38:47 -05001045 verify_packet(self, pkt, out_port)
1046 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001047 delete_all_flows(self.controller)
1048 delete_groups(self.controller, Groups)
1049
Flavio Castro12296312015-12-15 17:48:26 -05001050class L3McastToL2(base_tests.SimpleDataPlane):
castroflaviocc403a92015-12-15 14:04:19 -05001051 """
Flavio Castro12296312015-12-15 17:48:26 -05001052 Mcast routing to L2
castroflaviocc403a92015-12-15 14:04:19 -05001053 """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001054
castroflaviocc403a92015-12-15 14:04:19 -05001055 def runTest(self):
1056 """
1057 port1 (vlan 300)-> All Ports (vlan 300)
1058 """
Flavio Castrob01d0aa2016-07-20 16:14:48 -07001059 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001060 try:
1061 if len(config["port_map"]) < 3:
1062 logging.info("Port count less than 3, can't run this case")
1063 assert (False)
1064 return
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001065 vlan_id = 300
1066 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1067 intf_src_mac_str = ':'.join(['%02X' % x for x in intf_src_mac])
1068 dst_mac = [0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
1069 dst_mac_str = ':'.join(['%02X' % x for x in dst_mac])
1070 port1_mac = [0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
1071 port1_mac_str = ':'.join(['%02X' % x for x in port1_mac])
1072 src_ip = 0xc0a80101
1073 src_ip_str = "192.168.1.1"
1074 dst_ip = 0xe0010101
1075 dst_ip_str = "224.1.1.1"
castroflaviocc403a92015-12-15 14:04:19 -05001076
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001077 port1 = config["port_map"].keys()[0]
1078 port2 = config["port_map"].keys()[1]
castroflaviocc403a92015-12-15 14:04:19 -05001079
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001080 switch_mac = [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00]
castroflaviocc403a92015-12-15 14:04:19 -05001081
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001082 # add l2 interface group
1083 l2_intf_group_list = []
1084 for port in config["port_map"].keys():
1085 add_one_vlan_table_flow(self.controller, port, vlan_id,
1086 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1087 if port == port2:
1088 continue
1089 l2_intf_gid, msg = add_one_l2_interface_group(self.controller, port,
1090 vlan_id=vlan_id,
1091 is_tagged=True,
1092 send_barrier=False)
1093 l2_intf_group_list.append(l2_intf_gid)
1094 Groups.put(l2_intf_gid)
castroflaviocc403a92015-12-15 14:04:19 -05001095
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001096 # add termination flow
1097 add_termination_flow(self.controller, port1, 0x0800, switch_mac,
1098 vlan_id)
castroflaviocc403a92015-12-15 14:04:19 -05001099
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001100 # add l3 interface group
1101 mcat_group_msg = add_l3_mcast_group(self.controller, vlan_id, 2,
1102 l2_intf_group_list)
1103 add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip,
1104 mcat_group_msg.group_id)
1105 Groups._put(mcat_group_msg.group_id)
castroflaviocc403a92015-12-15 14:04:19 -05001106
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001107 parsed_pkt = simple_udp_packet(pktlen=100,
1108 dl_vlan_enable=True,
1109 vlan_vid=vlan_id,
1110 eth_dst=dst_mac_str,
1111 eth_src=port1_mac_str,
1112 ip_ttl=64,
1113 ip_src=src_ip_str,
1114 ip_dst=dst_ip_str)
1115 pkt = str(parsed_pkt)
1116 self.dataplane.send(port1, pkt)
1117 for port in config["port_map"].keys():
1118 if port == port2 or port == port1:
1119 verify_no_packet(self, pkt, port)
1120 continue
1121 verify_packet(self, pkt, port)
1122 verify_no_other_packets(self)
1123 finally:
1124 delete_all_flows(self.controller)
1125 delete_groups(self.controller, Groups)
1126 delete_all_groups(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001127
Flavio Castro12296312015-12-15 17:48:26 -05001128class L3McastToL3(base_tests.SimpleDataPlane):
1129 """
1130 Mcast routing
1131 """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001132
1133 def runTest(self):
Flavio Castro12296312015-12-15 17:48:26 -05001134 """
1135 port1 (vlan 1)-> port 2 (vlan 2)
1136 """
Flavio Castrob01d0aa2016-07-20 16:14:48 -07001137 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001138 try:
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001139 if len(config["port_map"]) < 3:
1140 logging.info("Port count less than 3, can't run this case")
1141 assert (False)
1142 return
Flavio Castro12296312015-12-15 17:48:26 -05001143
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001144 vlan_id = 1
1145 port2_out_vlan = 2
1146 port3_out_vlan = 3
1147 in_vlan = 1 # macast group vid shall use input vlan diffe from l3 interface use output vlan
1148 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1149 intf_src_mac_str = ':'.join(['%02X' % x for x in intf_src_mac])
1150 dst_mac = [0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
1151 dst_mac_str = ':'.join(['%02X' % x for x in dst_mac])
1152 port1_mac = [0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
1153 port1_mac_str = ':'.join(['%02X' % x for x in port1_mac])
1154 src_ip = 0xc0a80101
1155 src_ip_str = "192.168.1.1"
1156 dst_ip = 0xe0010101
1157 dst_ip_str = "224.1.1.1"
Flavio Castro12296312015-12-15 17:48:26 -05001158
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001159 port1 = config["port_map"].keys()[0]
1160 port2 = config["port_map"].keys()[1]
1161 port3 = config["port_map"].keys()[2]
Flavio Castro12296312015-12-15 17:48:26 -05001162
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001163 # add l2 interface group
1164 for port in config["port_map"].keys():
1165 l2gid, msg = add_one_l2_interface_group(self.controller, port,
1166 vlan_id=vlan_id,
1167 is_tagged=False,
1168 send_barrier=False)
1169 # add vlan flow table
1170 add_one_vlan_table_flow(self.controller, port, vlan_id,
1171 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1172 vlan_id += 1
1173 Groups._put(l2gid)
Flavio Castro12296312015-12-15 17:48:26 -05001174
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001175 # add termination flow
1176 add_termination_flow(self.controller, port1, 0x0800,
1177 [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001178
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001179 # add l3 interface group
1180 port2_ucast_msg = add_l3_interface_group(self.controller, port2,
1181 port2_out_vlan, 2,
1182 intf_src_mac)
1183 port3_ucast_msg = add_l3_interface_group(self.controller, port3,
1184 port3_out_vlan, 3,
1185 intf_src_mac)
1186 mcat_group_msg = add_l3_mcast_group(self.controller, in_vlan, 2,
1187 [port2_ucast_msg.group_id,
1188 port3_ucast_msg.group_id])
1189 add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip,
1190 mcat_group_msg.group_id)
1191 Groups._put(port2_ucast_msg.group_id)
1192 Groups._put(port3_ucast_msg.group_id)
1193 Groups._put(mcat_group_msg.group_id)
1194 parsed_pkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True,
1195 vlan_vid=1,
1196 eth_dst=dst_mac_str,
1197 eth_src=port1_mac_str,
1198 ip_ttl=64,
1199 ip_src=src_ip_str,
1200 ip_dst=dst_ip_str)
1201 pkt = str(parsed_pkt)
1202 self.dataplane.send(port1, pkt)
1203 parsed_pkt = simple_udp_packet(pktlen=96,
1204 eth_dst=dst_mac_str,
1205 eth_src=intf_src_mac_str,
1206 ip_ttl=63,
1207 ip_src=src_ip_str,
1208 ip_dst=dst_ip_str)
1209 pkt = str(parsed_pkt)
1210 verify_packet(self, pkt, port2)
1211 verify_packet(self, pkt, port3)
1212 verify_no_other_packets(self)
1213 finally:
1214 delete_all_flows(self.controller)
1215 delete_groups(self.controller, Groups)
1216 delete_all_groups(self.controller)
Flavio Castro54947942016-02-03 16:05:20 -05001217
Flavio Castrob702a2f2016-04-10 22:01:48 -04001218class _MplsFwd(base_tests.SimpleDataPlane):
Flavio Castro12296312015-12-15 17:48:26 -05001219 """
Flavio Castro54947942016-02-03 16:05:20 -05001220 Insert IP packet
1221 Receive MPLS packet
castroflavio30c6cc52016-01-07 15:19:42 -08001222 """
Flavio Castro1c9b1252016-02-04 18:42:58 -05001223 def runTest(self):
Flavio Castrob01d0aa2016-07-20 16:14:48 -07001224 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001225 try:
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001226 if len(config["port_map"]) < 2:
1227 logging.info("Port count less than 2, can't run this case")
1228 return
1229 dip = 0xc0a80001
1230 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1231 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1232 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
1233 ports = config["port_map"].keys()
1234 for port in ports:
1235 # add l2 interface group
1236 id = port
1237 vlan_id = id
1238 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
1239 vlan_id, True, False)
1240 dst_mac[5] = vlan_id
1241 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
1242 dst_mac, intf_src_mac,
1243 vlan_id, id)
1244 mpls_label_gid, mpls_label_msg = add_mpls_label_group(
1245 self.controller,
1246 subtype=OFDPA_MPLS_GROUP_SUBTYPE_SWAP_LABEL,
1247 index=id, ref_gid=mpls_gid, push_mpls_header=False,
1248 set_mpls_label=port, set_bos=1)
1249 # add vlan flow table
1250 add_one_vlan_table_flow(self.controller, port, vlan_id,
1251 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1252 # add termination flow
1253 add_termination_flow(self.controller, port, 0x8847, intf_src_mac,
1254 vlan_id, goto_table=24)
1255 add_mpls_flow(self.controller, mpls_label_gid, port, goto_table=29)
1256 dst_ip = dip + (vlan_id << 8)
1257 Groups._put(l2_gid)
1258 Groups._put(mpls_gid)
1259 Groups._put(mpls_label_gid)
1260 do_barrier(self.controller)
castroflavio30c6cc52016-01-07 15:19:42 -08001261
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001262 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1263 for in_port in ports:
1264 ip_src = '192.168.%02d.1' % (in_port)
1265 for out_port in ports:
1266 if in_port == out_port:
1267 continue
1268 ip_dst = '192.168.%02d.1' % (out_port)
Flavio Castro54947942016-02-03 16:05:20 -05001269
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001270 label = (out_port, 0, 1, 32)
1271 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
1272 vlan_vid=(in_port), ip_src=ip_src,
1273 ip_dst=ip_dst, eth_dst=switch_mac,
1274 label=[label])
1275 pkt = str(parsed_pkt)
1276 self.dataplane.send(in_port, pkt)
Flavio Castro54947942016-02-03 16:05:20 -05001277
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001278 # build expect packet
1279 mac_dst = '00:00:00:22:22:%02X' % (out_port)
1280 label = (out_port, 0, 1, 31)
1281 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
1282 vlan_vid=(out_port), ip_src=ip_src,
1283 ip_dst=ip_dst, eth_src=switch_mac,
1284 eth_dst=mac_dst,label=[label])
1285 pkt = str(exp_pkt)
1286 verify_packet(self, pkt, out_port)
1287 verify_no_other_packets(self)
1288 finally:
1289 delete_all_flows(self.controller)
1290 delete_groups(self.controller, Groups)
1291 delete_all_groups(self.controller)
Flavio Castrob702a2f2016-04-10 22:01:48 -04001292
1293class _MplsTermination(base_tests.SimpleDataPlane):
1294 """
1295 Insert IP packet
1296 Receive MPLS packet
1297 """
1298 def runTest(self):
Flavio Castrob01d0aa2016-07-20 16:14:48 -07001299 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001300 try:
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001301 if len(config["port_map"]) < 2:
1302 logging.info("Port count less than 2, can't run this case")
1303 return
1304 dip = 0xc0a80001
1305 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1306 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1307 # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
1308 ports = config["port_map"].keys()
1309 for port in ports:
1310 # add l2 interface group
1311 vlan_id, id, dst_mac[5] = port, port, port
1312 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
1313 vlan_id, True, False)
1314 # add L3 Unicast group
1315 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
1316 id=id, src_mac=intf_src_mac,dst_mac=dst_mac)
1317 # add L3 ecmp group
1318 ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
1319 # add vlan flow table
1320 add_one_vlan_table_flow(self.controller, port, vlan_id,
1321 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1322 # add termination flow
1323 add_termination_flow(self.controller, port, 0x8847, intf_src_mac,
1324 vlan_id, goto_table=24)
1325 #add_mpls_flow(self.controller, ecmp_msg.group_id, port)
1326 add_mpls_flow(self.controller, label=port)
1327 dst_ip = dip + (vlan_id << 8)
1328 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00,
1329 ecmp_msg.group_id, 1)
1330 Groups._put(l2_gid)
1331 Groups._put(l3_msg.group_id)
1332 Groups._put(ecmp_msg.group_id)
1333 do_barrier(self.controller)
Flavio Castrob702a2f2016-04-10 22:01:48 -04001334
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001335 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1336 for in_port in ports:
1337 ip_src = '192.168.%02d.1' % (in_port)
1338 for out_port in ports:
1339 if in_port == out_port:
1340 continue
1341 ip_dst = '192.168.%02d.1' % (out_port)
1342 label = (out_port, 0, 1, 32)
1343 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,vlan_vid=(in_port),
1344 ip_src=ip_src,ip_dst=ip_dst, eth_dst=switch_mac,label=[label])
1345 pkt = str(parsed_pkt)
1346 self.dataplane.send(in_port, pkt)
1347 # build expect packet
1348 mac_dst = '00:00:00:22:22:%02X' % (out_port)
1349 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1350 vlan_vid=(out_port),
1351 eth_dst=mac_dst, eth_src=switch_mac,
1352 ip_ttl=31, ip_src=ip_src,
1353 ip_dst=ip_dst)
1354 pkt = str(exp_pkt)
1355 verify_packet(self, pkt, out_port)
1356 verify_no_other_packets(self)
1357 finally:
1358 delete_all_flows(self.controller)
1359 delete_groups(self.controller, Groups)
1360 delete_all_groups(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001361
Flavio Castro1c9b1252016-02-04 18:42:58 -05001362class _24UcastTagged(base_tests.SimpleDataPlane):
1363 """
1364 Verify a IP forwarding works for a /32 rule to L3 Unicast Interface
1365 """
1366
1367 def runTest(self):
Flavio Castrob01d0aa2016-07-20 16:14:48 -07001368 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001369 try:
1370 test_id = 26
1371 if len(config["port_map"]) < 2:
1372 logging.info("Port count less than 2, can't run this case")
1373 return
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001374 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1375 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1376 dip = 0xc0a80001
1377 ports = config["port_map"].keys()
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001378 for port in ports:
1379 # add l2 interface group
1380 vlan_id = port + test_id
1381 l2gid, msg = add_one_l2_interface_group(self.controller, port,
1382 vlan_id=vlan_id,
1383 is_tagged=True,
1384 send_barrier=False)
1385 dst_mac[5] = vlan_id
1386 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
1387 id=vlan_id, src_mac=intf_src_mac,
1388 dst_mac=dst_mac)
1389 # add vlan flow table
1390 add_one_vlan_table_flow(self.controller, port, vlan_id,
1391 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1392 # add termination flow
1393 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
1394 vlan_id)
1395 # add unicast routing flow
1396 dst_ip = dip + (vlan_id << 8)
1397 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
1398 0xffffff00, l3_msg.group_id)
1399 Groups.put(l2gid)
1400 Groups.put(l3_msg.group_id)
1401 do_barrier(self.controller)
Flavio Castro1c9b1252016-02-04 18:42:58 -05001402
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001403 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1404 for in_port in ports:
1405 mac_src = '00:00:00:22:22:%02X' % (test_id + in_port)
1406 ip_src = '192.168.%02d.1' % (test_id + in_port)
1407 for out_port in ports:
1408 if in_port == out_port:
1409 continue
1410 ip_dst = '192.168.%02d.1' % (test_id + out_port)
1411 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1412 vlan_vid=(test_id + in_port),
1413 eth_dst=switch_mac,
1414 eth_src=mac_src, ip_ttl=64,
1415 ip_src=ip_src,
1416 ip_dst=ip_dst)
1417 pkt = str(parsed_pkt)
1418 self.dataplane.send(in_port, pkt)
1419 # build expected packet
1420 mac_dst = '00:00:00:22:22:%02X' % (test_id + out_port)
1421 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1422 vlan_vid=(test_id + out_port),
1423 eth_dst=mac_dst, eth_src=switch_mac,
1424 ip_ttl=63,
1425 ip_src=ip_src, ip_dst=ip_dst)
1426 pkt = str(exp_pkt)
1427 verify_packet(self, pkt, out_port)
1428 verify_no_other_packets(self)
1429 finally:
1430 delete_all_flows(self.controller)
1431 delete_groups(self.controller, Groups)
1432 delete_all_groups(self.controller)
Flavio Castro91d1a552016-05-17 16:59:44 -07001433
1434class _0Ucast(base_tests.SimpleDataPlane):
1435 """
1436 Verify a IP forwarding works for a /0 rule to L3 Unicast Interface
1437 """
1438
1439 def runTest(self):
Flavio Castrob01d0aa2016-07-20 16:14:48 -07001440 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001441 try:
1442 if len(config["port_map"]) < 2:
1443 logging.info("Port count less than 2, can't run this case")
1444 return
Flavio Castro91d1a552016-05-17 16:59:44 -07001445
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001446 intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1447 dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
1448 dip = 0xc0a80001
1449 ports = config["port_map"].keys()
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001450 for port in ports:
1451 # add l2 interface group
1452 vlan_id = port
1453 l2gid, msg = add_one_l2_interface_group(self.controller, port,
1454 vlan_id=vlan_id+1,
1455 is_tagged=True,
1456 send_barrier=False)
1457 dst_mac[5] = vlan_id
1458 l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id+1,
1459 id=vlan_id, src_mac=intf_src_mac,
1460 dst_mac=dst_mac)
1461 # add vlan flow table
1462 add_one_vlan_table_flow(self.controller, port, vlan_id,
1463 flag=VLAN_TABLE_FLAG_ONLY_TAG)
1464 # add termination flow
1465 add_termination_flow(self.controller, port, 0x0800, intf_src_mac,
1466 vlan_id)
1467 # add unicast routing flow
1468 dst_ip = dip + (vlan_id << 8)
1469 add_unicast_routing_flow(self.controller, 0x0800, dst_ip,
1470 0xffffffff, l3_msg.group_id)
1471 Groups.put(l2gid)
1472 Groups.put(l3_msg.group_id)
1473 l3_gid = encode_l3_unicast_group_id(ports[0])
1474 dst_ip = 0x0
1475 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, l3_gid)
1476 do_barrier(self.controller)
Flavio Castro91d1a552016-05-17 16:59:44 -07001477
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001478 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
1479 for in_port in ports:
1480 mac_src = '00:00:00:22:22:%02X' % (in_port)
1481 ip_src = '192.168.%02d.1' % (in_port)
1482 for out_port in ports:
1483 if in_port == out_port:
1484 continue
1485 ip_dst = '192.168.%02d.1' % (out_port)
1486 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1487 vlan_vid=(in_port),
1488 eth_dst=switch_mac,
1489 eth_src=mac_src, ip_ttl=64,
1490 ip_src=ip_src,
1491 ip_dst=ip_dst)
1492 pkt = str(parsed_pkt)
1493 self.dataplane.send(in_port, pkt)
1494 # build expected packet
1495 mac_dst = '00:00:00:22:22:%02X' % (out_port)
1496 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
1497 vlan_vid=(out_port+1),
1498 eth_dst=mac_dst, eth_src=switch_mac,
1499 ip_ttl=63,
1500 ip_src=ip_src, ip_dst=ip_dst)
1501 pkt = str(exp_pkt)
1502 verify_packet(self, pkt, out_port)
1503 verify_no_other_packets(self)
1504 ip_dst='1.168.%02d.1' % ports[0]
1505 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
1506 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst)
1507 pkt=str(parsed_pkt)
1508 self.dataplane.send(in_port, pkt)
1509 #build expect packet
1510 mac_dst='00:00:00:22:22:%02X' % ports[0]
1511 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=ports[0]+1, ip_ttl=63, ip_src=ip_src,
1512 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac)
1513 pkt=str(exp_pkt)
1514 verify_packet(self, pkt, ports[0])
1515 verify_no_other_packets(self)
1516 finally:
1517 delete_all_flows(self.controller)
1518 delete_groups(self.controller, Groups)
1519 delete_all_groups(self.controller)
Flavio Castro91d1a552016-05-17 16:59:44 -07001520
Flavio Castro423df652016-05-17 20:14:08 -04001521class Unfiltered(base_tests.SimpleDataPlane):
1522 """
1523 Testing addition of unfiltered groups
1524 """
Flavio Castro91d1a552016-05-17 16:59:44 -07001525
Flavio Castro423df652016-05-17 20:14:08 -04001526 def runTest(self):
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001527 try:
1528 ports = sorted(config["port_map"].keys())
1529 vlan_id = 1;
1530 for port in ports:
1531 add_l2_unfiltered_group(self.controller, [port], False)
1532 do_barrier(self.controller)
1533 finally:
1534 delete_all_flows(self.controller)
1535 delete_all_groups(self.controller)
Flavio Castro91d1a552016-05-17 16:59:44 -07001536
Flavio Castro423df652016-05-17 20:14:08 -04001537class L3McastToVPN(base_tests.SimpleDataPlane):
1538 """
1539 Mcast routing
1540 """
1541 def runTest(self):
1542 """
1543 port1 (vlan 1)-> port 2 (vlan 2)
1544 """
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001545 try:
1546 delete_all_flows(self.controller)
1547 delete_all_groups(self.controller)
Flavio Castro423df652016-05-17 20:14:08 -04001548
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001549 if len(config["port_map"]) <3:
1550 logging.info("Port count less than 3, can't run this case")
1551 assert(False)
1552 return
Flavio Castro423df652016-05-17 20:14:08 -04001553
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001554 vlan_id =1
1555 port2_out_vlan=2
1556 port3_out_vlan=3
1557 in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan
1558 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
1559 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
1560 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
1561 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
1562 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
1563 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
1564 src_ip=0xc0a80101
1565 src_ip_str="192.168.1.1"
1566 dst_ip=0xe0010101
1567 dst_ip_str="224.1.1.1"
Flavio Castro423df652016-05-17 20:14:08 -04001568
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001569 port1=config["port_map"].keys()[0]
1570 port2=config["port_map"].keys()[1]
1571 #port3=config["port_map"].keys()[2]
Flavio Castro423df652016-05-17 20:14:08 -04001572
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001573 #add l2 interface group
1574 for port in config["port_map"].keys():
1575 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
1576 #add vlan flow table
1577 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
1578 vlan_id +=1
Flavio Castro423df652016-05-17 20:14:08 -04001579
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001580 #add termination flow
1581 add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
Flavio Castro423df652016-05-17 20:14:08 -04001582
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001583 #add MPLS interface group
1584 l2_gid = encode_l2_interface_group_id(port2_out_vlan, port2)
1585 mpls_gid2, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, port2_out_vlan, port2)
1586 #l2_gid3 = encode_l2_interface_group_id(port3_out_vlan, port3)
1587 #mpls_gid3, mpls_msg = add_mpls_intf_group(self.controller, l2_gid3, dst_mac, intf_src_mac, port3_out_vlan, port3)
1588 #add L3VPN groups
1589 mpls_label_gid2, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
1590 index=(0x20000+port2), ref_gid= mpls_gid2, push_mpls_header=True, set_mpls_label=port2, set_bos=1, cpy_ttl_outward=True)
1591 #mpls_label_gid3, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
1592 # index=(0x10000+port3), ref_gid= mpls_gid3, push_mpls_header=True, set_mpls_label=port3, set_bos=1, cpy_ttl_outward=True)
Flavio Castro423df652016-05-17 20:14:08 -04001593
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001594 mcat_group_msg=add_l3_mcast_group(self.controller, in_vlan, 2, [mpls_label_gid2])
1595 add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id)
Flavio Castro423df652016-05-17 20:14:08 -04001596
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001597 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=1,
1598 eth_dst=dst_mac_str,
1599 eth_src=port1_mac_str,
1600 ip_ttl=64,
1601 ip_src=src_ip_str,
1602 ip_dst=dst_ip_str)
1603 pkt=str(parsed_pkt)
1604 self.dataplane.send(port1, pkt)
1605 label = (12, 0, 1, 63)
1606 exp_pkt = mpls_packet(pktlen=100,
1607 eth_dst=dst_mac_str,
1608 eth_src=intf_src_mac_str,
1609 ip_ttl=64,
1610 ip_src=src_ip_str, label= [label],
1611 ip_dst=dst_ip_str)
1612 pkt=str(exp_pkt)
1613 verify_packet(self, pkt, port2)
1614 #verify_packet(self, pkt, port3)
1615 verify_no_other_packets(self)
1616 delete_all_groups(self.controller)
1617 finally:
1618 delete_all_flows(self.controller)
1619 delete_all_groups(self.controller)
1620
Flavio Castro423df652016-05-17 20:14:08 -04001621
1622class PacketInSrcMacMiss(base_tests.SimpleDataPlane):
1623 """
1624 Test packet in function on a src-mac miss
1625 Send a packet to each dataplane port and verify that a packet
1626 in message is received from the controller for each
1627 #todo verify you stop receiving after adding rule
1628 """
1629
1630 def runTest(self):
Flavio Castrob01d0aa2016-07-20 16:14:48 -07001631 Groups = Queue.LifoQueue()
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001632 try:
1633 ports = sorted(config["port_map"].keys())
Flavio Castro423df652016-05-17 20:14:08 -04001634
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001635 Groups = Queue.LifoQueue()
1636 for port in ports:
1637 L2gid, l2msg = add_one_l2_interface_group(self.controller, port, 1, True, False)
1638 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
1639 Groups.put(L2gid)
1640 parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
1641 vlan_vid=0x1001, dl_vlan_enable=True)
1642 vlan_pkt = str(parsed_vlan_pkt)
1643 for of_port in config["port_map"].keys():
1644 logging.info("PacketInMiss test, port %d", of_port)
1645 self.dataplane.send(of_port, vlan_pkt)
1646 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH)
1647 verify_no_other_packets(self)
1648 finally:
1649 delete_all_flows(self.controller)
Flavio Castro8c37e1c2016-07-19 18:26:33 -07001650 delete_all_groups(self.controller)