blob: df54f7d28639409db328d18b864bf0847537ff3e [file] [log] [blame]
castroflaviobd48e302015-12-15 17:57:38 -05001"""
castroflaviobd48e302015-12-15 17:57:38 -05002"""
Flavio Castro1c9b1252016-02-04 18:42:58 -05003import Queue
castroflaviobd48e302015-12-15 17:57:38 -05004
5from oftest import config
6import logging
7import oftest.base_tests as base_tests
8import ofp
9from oftest.testutils import *
10from accton_util import *
Flavio Castro54947942016-02-03 16:05:20 -050011import inspect
12
13@disabled
14class Mtu4000(base_tests.SimpleDataPlane):
15 """
16 Test output function for an exact-match flow
17 For each port A, adds a flow directing matching packets to that port.
18 Then, for all other ports B != A, verifies that sending a matching packet
19 to B results in an output to A.
20 """
21 def runTest(self):
22 ports = sorted(config["port_map"].keys())
23
24 delete_all_flows(self.controller)
25 delete_all_groups(self.controller)
26
27 add_vlan_table_flow(self.controller, config["port_map"].keys())
28
29 # set up tag groups for each port
30 add_l2_interface_group(self.controller, config["port_map"].keys(), 1, True, 1)
31
32 for port in ports:
33 add_one_l2_interface_group(self.controller, port, 1, True, False)
34 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
35 group_id = encode_l2_interface_group_id(1, port)
36 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
37 do_barrier(self.controller)
38
39 for out_port in ports:
40 # change dest based on port number
41 mac_dst= '00:12:34:56:78:%02X' % out_port
42 for in_port in ports:
43 if in_port == out_port:
44 continue
45 # change source based on port number to avoid packet-ins from learning
46 mac_src= '00:12:34:56:78:%02X' % in_port
47 parsed_pkt = simple_tcp_packet(pktlen=4000,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
48 pkt = str(parsed_pkt)
49 self.dataplane.send(in_port, pkt)
50
51 for ofport in ports:
52 if ofport in [out_port]:
53 verify_packet(self, pkt, ofport)
54 else:
55 verify_no_packet(self, pkt, ofport)
56
57 verify_no_other_packets(self)
Flavio Castro91d1a552016-05-17 16:59:44 -070058
castroflaviobd48e302015-12-15 17:57:38 -050059
Flavio Castro1c9b1252016-02-04 18:42:58 -050060
61class LPMDirect(base_tests.SimpleDataPlane):
62 """
63 Insert IP packet
64 Receive MPLS packet
65 """
66 def runTest(self):
67 Groups=Queue.LifoQueue()
68 if len(config["port_map"]) <2:
69 logging.info("Port count less than 2, can't run this case")
70 return
71 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
72 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
73 dip=0xc0a80001
74 index=1
75 ports = config["port_map"].keys()
76 for port in ports:
77 #add l2 interface group
78 vlan_id=port
79 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
80 dst_mac[5]=vlan_id
81 #add MPLS interface group
82 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, port)
83 #add MPLS L3 VPN group
84 mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
Flavio Castro91d1a552016-05-17 16:59:44 -070085 index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32)
Flavio Castro1c9b1252016-02-04 18:42:58 -050086 #ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
87 Groups._put(l2_gid)
88 Groups._put(mpls_gid)
89 Groups._put(mpls_label_gid)
90 do_barrier(self.controller)
91 #add vlan flow table
Flavio Castro91d1a552016-05-17 16:59:44 -070092 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castro1c9b1252016-02-04 18:42:58 -050093 #add termination flow
94 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
95 #add routing flow
96 dst_ip = dip + (vlan_id<<8)
Flavio Castro91d1a552016-05-17 16:59:44 -070097 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, mpls_label_gid)
Flavio Castro1c9b1252016-02-04 18:42:58 -050098 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id)
99 port = ports[0]
100 #add l2 interface group
101 vlan_id=port
102 l2_gid = encode_l2_interface_group_id(vlan_id, port)
103 dst_mac[5]=vlan_id
104 #add MPLS interface group
105 mpls_gid = encode_mpls_interface_group_id(0, port)
106 #add MPLS L3 VPN group
107 mpls_label_gid = encode_mpls_label_group_id(OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=port)
108 #ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
109 do_barrier(self.controller)
110 #add routing flow
111 dst_ip = 0x0
Flavio Castro91d1a552016-05-17 16:59:44 -0700112 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, mpls_label_gid)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500113 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, ecmp_msg.group_id)
114
115 do_barrier(self.controller)
116
117 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
118 for in_port in ports:
119 mac_src='00:00:00:22:22:%02X' % in_port
120 ip_src='192.168.%02d.1' % in_port
121 for out_port in ports:
122 if in_port == out_port:
123 continue
124 ip_dst='192.168.%02d.1' % out_port
125 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
126 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
127 ip_dst=ip_dst)
128 pkt=str(parsed_pkt)
129 self.dataplane.send(in_port, pkt)
130 #build expect packet
131 mac_dst='00:00:00:22:22:%02X' % out_port
132 label = (out_port, 0, 1, 32)
133 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=63, ip_src=ip_src,
134 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
135 pkt=str(exp_pkt)
136 verify_packet(self, pkt, out_port)
137 verify_no_other_packets(self)
138 ip_dst='1.168.%02d.1' % ports[0]
139 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
140 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst)
141 pkt=str(parsed_pkt)
Flavio Castro91d1a552016-05-17 16:59:44 -0700142 #self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500143 #build expect packet
144 mac_dst='00:00:00:22:22:%02X' % ports[0]
145 label = (ports[0], 0, 1, 32)
146 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=ports[0], ip_ttl=63, ip_src=ip_src,
147 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
148 pkt=str(exp_pkt)
Flavio Castro91d1a552016-05-17 16:59:44 -0700149 #verify_packet(self, pkt, ports[0])
150 #verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500151 delete_all_flows(self.controller)
152 delete_groups(self.controller,Groups)
153
Flavio Castro54947942016-02-03 16:05:20 -0500154class LPM(base_tests.SimpleDataPlane):
155 """
156 Insert IP packet
157 Receive MPLS packet
158 """
159 def runTest(self):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500160 Groups=Queue.LifoQueue()
Flavio Castro54947942016-02-03 16:05:20 -0500161 if len(config["port_map"]) <2:
162 logging.info("Port count less than 2, can't run this case")
163 return
Flavio Castro54947942016-02-03 16:05:20 -0500164 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
165 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
166 dip=0xc0a80001
167 index=1
168 ports = config["port_map"].keys()
169 for port in ports:
170 #add l2 interface group
171 vlan_id=port
172 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
173 dst_mac[5]=vlan_id
174 #add MPLS interface group
175 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, port)
176 #add MPLS L3 VPN group
177 mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
178 index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32)
179 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castro1c9b1252016-02-04 18:42:58 -0500180 Groups._put(l2_gid)
181 Groups._put(mpls_gid)
182 Groups._put(mpls_label_gid)
183 Groups._put(ecmp_msg.group_id)
Flavio Castro54947942016-02-03 16:05:20 -0500184 do_barrier(self.controller)
185 #add vlan flow table
186 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG)
187 #add termination flow
188 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
189 #add routing flow
190 dst_ip = dip + (vlan_id<<8)
191 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, mpls_label_gid, vrf=2)
192 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id)
193 #add entries in the Bridging table to avoid packet-in from mac learning
194 group_id = encode_l2_interface_group_id(vlan_id, port)
195 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
196 port = ports[0]
197 #add l2 interface group
198 vlan_id=port
199 l2_gid = encode_l2_interface_group_id(vlan_id, port)
200 dst_mac[5]=vlan_id
201 #add MPLS interface group
202 mpls_gid = encode_mpls_interface_group_id(0, port)
203 #add MPLS L3 VPN group
204 mpls_label_gid = encode_mpls_label_group_id(OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=port)
205 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castro6da7e462016-02-04 18:56:29 -0500206 Groups._put(ecmp_msg.group_id)
Flavio Castro54947942016-02-03 16:05:20 -0500207 do_barrier(self.controller)
208 #add routing flow
209 dst_ip = 0x0
210 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, mpls_label_gid, vrf=2)
211 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, ecmp_msg.group_id)
212
213 do_barrier(self.controller)
214
215 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
216 for in_port in ports:
217 mac_src='00:00:00:22:22:%02X' % in_port
218 ip_src='192.168.%02d.1' % in_port
219 for out_port in ports:
220 if in_port == out_port:
221 continue
222 ip_dst='192.168.%02d.1' % out_port
223 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
224 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
225 ip_dst=ip_dst)
226 pkt=str(parsed_pkt)
227 self.dataplane.send(in_port, pkt)
228 #build expect packet
229 mac_dst='00:00:00:22:22:%02X' % out_port
230 label = (out_port, 0, 1, 32)
231 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=63, ip_src=ip_src,
232 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
233 pkt=str(exp_pkt)
234 verify_packet(self, pkt, out_port)
235 verify_no_other_packets(self)
236 ip_dst='1.168.%02d.1' % ports[0]
237 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
238 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst)
239 pkt=str(parsed_pkt)
240 self.dataplane.send(in_port, pkt)
241 #build expect packet
242 mac_dst='00:00:00:22:22:%02X' % ports[0]
243 label = (ports[0], 0, 1, 32)
244 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=ports[0], ip_ttl=63, ip_src=ip_src,
245 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
246 pkt=str(exp_pkt)
247 verify_packet(self, pkt, ports[0])
248 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500249 delete_all_flows(self.controller)
250 delete_groups(self.controller,Groups)
Flavio Castro54947942016-02-03 16:05:20 -0500251
252@disabled
253class L2FloodTaggedUnknownSrc(base_tests.SimpleDataPlane):
254 """
255 Test L2 flood to a vlan
256 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
257 #todo take in account unknown src
258 """
259 def runTest(self):
260 delete_all_flows(self.controller)
261 delete_all_groups(self.controller)
262
263 ports = sorted(config["port_map"].keys())
264 for port in ports:
265 add_one_l2_interface_group(self.controller, port, 1, True, False)
266 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
267
268 msg=add_l2_flood_group(self.controller, ports, 1, 1)
269 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
270
271 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a')
272 pkt = str(parsed_pkt)
273 #verify flood
274 for ofport in ports:
275 self.dataplane.send(ofport, pkt)
276 #self won't rx packet
277 verify_no_packet(self, pkt, ofport)
278 #others will rx packet
279 tmp_ports=list(ports)
280 tmp_ports.remove(ofport)
281 verify_packets(self, pkt, tmp_ports)
282
283 verify_no_other_packets(self)
284
Flavio Castro91d1a552016-05-17 16:59:44 -0700285@disabled
Flavio Castro54947942016-02-03 16:05:20 -0500286class PacketInIPTable(base_tests.SimpleDataPlane):
287 """
288 Test packet in function on IPTABLE
289 Send a packet to each dataplane port and verify that a packet
290 in message is received from the controller for each
291 #todo verify you stop receiving after adding rule
292 """
293
294 def runTest(self):
Flavio Castro54947942016-02-03 16:05:20 -0500295
296 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
297 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
298 dip=0xc0a80001
299 ports = sorted(config["port_map"].keys())
Flavio Castro8ef7b5b2016-05-10 15:29:51 -0700300 Groups = Queue.LifoQueue()
301
Flavio Castro54947942016-02-03 16:05:20 -0500302 for port in ports:
303 #add l2 interface group
304 vlan_id=port
305 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
306 dst_mac[5]=vlan_id
307 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
308 #add vlan flow table
309 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
310 #add termination flow
311 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
312 #add unicast routing flow
313 dst_ip = dip + (vlan_id<<8)
Flavio Castro8ef7b5b2016-05-10 15:29:51 -0700314 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, l3_msg.group_id, send_ctrl=True)
315 Groups.put(l3_msg.group_id)
Flavio Castro54947942016-02-03 16:05:20 -0500316
317 do_barrier(self.controller)
318
319 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
320 for in_port in ports:
321 mac_src='00:00:00:22:22:%02X' % in_port
322 ip_src='192.168.%02d.1' % in_port
323 for out_port in ports:
324 if in_port == out_port:
325 continue
326 ip_dst='192.168.%02d.1' % out_port
327 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
328 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
329 ip_dst=ip_dst)
330 pkt=str(parsed_pkt)
331 self.dataplane.send(in_port, pkt)
332 verify_packet_in(self, pkt, in_port, ofp.OFPR_ACTION)
333 #verify_no_other_packets(self)
Flavio Castro91d1a552016-05-17 16:59:44 -0700334 delete_all_flows(self.controller)
335 delete_groups(self.controller, Groups)
Flavio Castro54947942016-02-03 16:05:20 -0500336
Flavio Castro54947942016-02-03 16:05:20 -0500337class PacketInSrcMacMiss(base_tests.SimpleDataPlane):
338 """
339 Test packet in function on a src-mac miss
340 Send a packet to each dataplane port and verify that a packet
341 in message is received from the controller for each
342 #todo verify you stop receiving after adding rule
343 """
344
345 def runTest(self):
346 delete_all_flows(self.controller)
347 delete_all_groups(self.controller)
348
349 ports = sorted(config["port_map"].keys())
350 for port in ports:
351 add_one_l2_interface_group(self.controller, port, 1, True, False)
352 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
353
354 parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
355 vlan_vid=0x1001, dl_vlan_enable=True)
356 vlan_pkt = str(parsed_vlan_pkt)
357
358 for of_port in config["port_map"].keys():
359 logging.info("PacketInMiss test, port %d", of_port)
360 self.dataplane.send(of_port, vlan_pkt)
361
362 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH)
363
Flavio Castro6da7e462016-02-04 18:56:29 -0500364 verify_no_other_packets(self)