blob: 1048700d07b337539d6da0102cbe95b54f4f9716 [file] [log] [blame]
Matteo Scandoloa229eca2017-08-08 13:05:28 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
castroflaviobd48e302015-12-15 17:57:38 -050017"""
castroflaviobd48e302015-12-15 17:57:38 -050018"""
Flavio Castro1c9b1252016-02-04 18:42:58 -050019import Queue
castroflaviobd48e302015-12-15 17:57:38 -050020
21from oftest import config
22import logging
23import oftest.base_tests as base_tests
24import ofp
25from oftest.testutils import *
26from accton_util import *
Flavio Castro54947942016-02-03 16:05:20 -050027import inspect
28
29@disabled
30class Mtu4000(base_tests.SimpleDataPlane):
31 """
32 Test output function for an exact-match flow
33 For each port A, adds a flow directing matching packets to that port.
34 Then, for all other ports B != A, verifies that sending a matching packet
35 to B results in an output to A.
36 """
37 def runTest(self):
38 ports = sorted(config["port_map"].keys())
39
40 delete_all_flows(self.controller)
41 delete_all_groups(self.controller)
42
43 add_vlan_table_flow(self.controller, config["port_map"].keys())
44
45 # set up tag groups for each port
46 add_l2_interface_group(self.controller, config["port_map"].keys(), 1, True, 1)
47
48 for port in ports:
49 add_one_l2_interface_group(self.controller, port, 1, True, False)
50 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
51 group_id = encode_l2_interface_group_id(1, port)
52 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
53 do_barrier(self.controller)
54
55 for out_port in ports:
56 # change dest based on port number
57 mac_dst= '00:12:34:56:78:%02X' % out_port
58 for in_port in ports:
59 if in_port == out_port:
60 continue
61 # change source based on port number to avoid packet-ins from learning
62 mac_src= '00:12:34:56:78:%02X' % in_port
63 parsed_pkt = simple_tcp_packet(pktlen=4000,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
64 pkt = str(parsed_pkt)
65 self.dataplane.send(in_port, pkt)
66
67 for ofport in ports:
68 if ofport in [out_port]:
69 verify_packet(self, pkt, ofport)
70 else:
71 verify_no_packet(self, pkt, ofport)
72
73 verify_no_other_packets(self)
Flavio Castro91d1a552016-05-17 16:59:44 -070074
castroflaviobd48e302015-12-15 17:57:38 -050075
Flavio Castro1c9b1252016-02-04 18:42:58 -050076
77class LPMDirect(base_tests.SimpleDataPlane):
78 """
79 Insert IP packet
80 Receive MPLS packet
81 """
82 def runTest(self):
83 Groups=Queue.LifoQueue()
84 if len(config["port_map"]) <2:
85 logging.info("Port count less than 2, can't run this case")
86 return
87 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
88 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
89 dip=0xc0a80001
90 index=1
91 ports = config["port_map"].keys()
92 for port in ports:
93 #add l2 interface group
94 vlan_id=port
95 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
96 dst_mac[5]=vlan_id
97 #add MPLS interface group
98 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, port)
99 #add MPLS L3 VPN group
100 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 -0700101 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 -0500102 #ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
103 Groups._put(l2_gid)
104 Groups._put(mpls_gid)
105 Groups._put(mpls_label_gid)
106 do_barrier(self.controller)
107 #add vlan flow table
Flavio Castro91d1a552016-05-17 16:59:44 -0700108 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500109 #add termination flow
110 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
111 #add routing flow
112 dst_ip = dip + (vlan_id<<8)
Flavio Castro91d1a552016-05-17 16:59:44 -0700113 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, mpls_label_gid)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500114 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id)
115 port = ports[0]
116 #add l2 interface group
117 vlan_id=port
118 l2_gid = encode_l2_interface_group_id(vlan_id, port)
119 dst_mac[5]=vlan_id
120 #add MPLS interface group
121 mpls_gid = encode_mpls_interface_group_id(0, port)
122 #add MPLS L3 VPN group
123 mpls_label_gid = encode_mpls_label_group_id(OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=port)
124 #ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
125 do_barrier(self.controller)
126 #add routing flow
127 dst_ip = 0x0
Flavio Castro91d1a552016-05-17 16:59:44 -0700128 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, mpls_label_gid)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500129 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, ecmp_msg.group_id)
130
131 do_barrier(self.controller)
132
133 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
134 for in_port in ports:
135 mac_src='00:00:00:22:22:%02X' % in_port
136 ip_src='192.168.%02d.1' % in_port
137 for out_port in ports:
138 if in_port == out_port:
139 continue
140 ip_dst='192.168.%02d.1' % out_port
141 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
142 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
143 ip_dst=ip_dst)
144 pkt=str(parsed_pkt)
145 self.dataplane.send(in_port, pkt)
146 #build expect packet
147 mac_dst='00:00:00:22:22:%02X' % out_port
148 label = (out_port, 0, 1, 32)
149 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=63, ip_src=ip_src,
150 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
151 pkt=str(exp_pkt)
152 verify_packet(self, pkt, out_port)
153 verify_no_other_packets(self)
154 ip_dst='1.168.%02d.1' % ports[0]
155 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
156 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst)
157 pkt=str(parsed_pkt)
Flavio Castro91d1a552016-05-17 16:59:44 -0700158 #self.dataplane.send(in_port, pkt)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500159 #build expect packet
160 mac_dst='00:00:00:22:22:%02X' % ports[0]
161 label = (ports[0], 0, 1, 32)
162 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=ports[0], ip_ttl=63, ip_src=ip_src,
163 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
164 pkt=str(exp_pkt)
Flavio Castro91d1a552016-05-17 16:59:44 -0700165 #verify_packet(self, pkt, ports[0])
166 #verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500167 delete_all_flows(self.controller)
168 delete_groups(self.controller,Groups)
169
Flavio Castro54947942016-02-03 16:05:20 -0500170class LPM(base_tests.SimpleDataPlane):
171 """
172 Insert IP packet
173 Receive MPLS packet
174 """
175 def runTest(self):
Flavio Castro1c9b1252016-02-04 18:42:58 -0500176 Groups=Queue.LifoQueue()
Flavio Castro54947942016-02-03 16:05:20 -0500177 if len(config["port_map"]) <2:
178 logging.info("Port count less than 2, can't run this case")
179 return
Flavio Castro54947942016-02-03 16:05:20 -0500180 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
181 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
182 dip=0xc0a80001
183 index=1
184 ports = config["port_map"].keys()
185 for port in ports:
186 #add l2 interface group
187 vlan_id=port
188 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id, True, True)
189 dst_mac[5]=vlan_id
190 #add MPLS interface group
191 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, port)
192 #add MPLS L3 VPN group
193 mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
194 index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32)
195 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castro1c9b1252016-02-04 18:42:58 -0500196 Groups._put(l2_gid)
197 Groups._put(mpls_gid)
198 Groups._put(mpls_label_gid)
199 Groups._put(ecmp_msg.group_id)
Flavio Castro54947942016-02-03 16:05:20 -0500200 do_barrier(self.controller)
201 #add vlan flow table
202 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=0, 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 routing flow
206 dst_ip = dip + (vlan_id<<8)
207 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, mpls_label_gid, vrf=2)
208 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id)
209 #add entries in the Bridging table to avoid packet-in from mac learning
210 group_id = encode_l2_interface_group_id(vlan_id, port)
211 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
212 port = ports[0]
213 #add l2 interface group
214 vlan_id=port
215 l2_gid = encode_l2_interface_group_id(vlan_id, port)
216 dst_mac[5]=vlan_id
217 #add MPLS interface group
218 mpls_gid = encode_mpls_interface_group_id(0, port)
219 #add MPLS L3 VPN group
220 mpls_label_gid = encode_mpls_label_group_id(OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, index=port)
221 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [mpls_label_gid])
Flavio Castro6da7e462016-02-04 18:56:29 -0500222 Groups._put(ecmp_msg.group_id)
Flavio Castro54947942016-02-03 16:05:20 -0500223 do_barrier(self.controller)
224 #add routing flow
225 dst_ip = 0x0
226 #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, mpls_label_gid, vrf=2)
227 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0x0, ecmp_msg.group_id)
228
229 do_barrier(self.controller)
230
231 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
232 for in_port in ports:
233 mac_src='00:00:00:22:22:%02X' % in_port
234 ip_src='192.168.%02d.1' % in_port
235 for out_port in ports:
236 if in_port == out_port:
237 continue
238 ip_dst='192.168.%02d.1' % out_port
239 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
240 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
241 ip_dst=ip_dst)
242 pkt=str(parsed_pkt)
243 self.dataplane.send(in_port, pkt)
244 #build expect packet
245 mac_dst='00:00:00:22:22:%02X' % out_port
246 label = (out_port, 0, 1, 32)
247 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=63, ip_src=ip_src,
248 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
249 pkt=str(exp_pkt)
250 verify_packet(self, pkt, out_port)
251 verify_no_other_packets(self)
252 ip_dst='1.168.%02d.1' % ports[0]
253 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
254 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src, ip_dst=ip_dst)
255 pkt=str(parsed_pkt)
256 self.dataplane.send(in_port, pkt)
257 #build expect packet
258 mac_dst='00:00:00:22:22:%02X' % ports[0]
259 label = (ports[0], 0, 1, 32)
260 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=ports[0], ip_ttl=63, ip_src=ip_src,
261 ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
262 pkt=str(exp_pkt)
263 verify_packet(self, pkt, ports[0])
264 verify_no_other_packets(self)
Flavio Castro1c9b1252016-02-04 18:42:58 -0500265 delete_all_flows(self.controller)
266 delete_groups(self.controller,Groups)
Flavio Castro54947942016-02-03 16:05:20 -0500267
268@disabled
269class L2FloodTaggedUnknownSrc(base_tests.SimpleDataPlane):
270 """
271 Test L2 flood to a vlan
272 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
273 #todo take in account unknown src
274 """
275 def runTest(self):
276 delete_all_flows(self.controller)
277 delete_all_groups(self.controller)
278
279 ports = sorted(config["port_map"].keys())
280 for port in ports:
281 add_one_l2_interface_group(self.controller, port, 1, True, False)
282 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
283
284 msg=add_l2_flood_group(self.controller, ports, 1, 1)
285 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
286
287 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a')
288 pkt = str(parsed_pkt)
289 #verify flood
290 for ofport in ports:
291 self.dataplane.send(ofport, pkt)
292 #self won't rx packet
293 verify_no_packet(self, pkt, ofport)
294 #others will rx packet
295 tmp_ports=list(ports)
296 tmp_ports.remove(ofport)
297 verify_packets(self, pkt, tmp_ports)
298
299 verify_no_other_packets(self)
300
Flavio Castro91d1a552016-05-17 16:59:44 -0700301@disabled
Flavio Castro54947942016-02-03 16:05:20 -0500302class PacketInIPTable(base_tests.SimpleDataPlane):
303 """
304 Test packet in function on IPTABLE
305 Send a packet to each dataplane port and verify that a packet
306 in message is received from the controller for each
307 #todo verify you stop receiving after adding rule
308 """
309
310 def runTest(self):
Flavio Castro54947942016-02-03 16:05:20 -0500311
312 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
313 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
314 dip=0xc0a80001
315 ports = sorted(config["port_map"].keys())
Flavio Castro8ef7b5b2016-05-10 15:29:51 -0700316 Groups = Queue.LifoQueue()
317
Flavio Castro54947942016-02-03 16:05:20 -0500318 for port in ports:
319 #add l2 interface group
320 vlan_id=port
321 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
322 dst_mac[5]=vlan_id
323 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
324 #add vlan flow table
325 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
326 #add termination flow
327 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
328 #add unicast routing flow
329 dst_ip = dip + (vlan_id<<8)
Flavio Castro8ef7b5b2016-05-10 15:29:51 -0700330 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, l3_msg.group_id, send_ctrl=True)
331 Groups.put(l3_msg.group_id)
Flavio Castro54947942016-02-03 16:05:20 -0500332
333 do_barrier(self.controller)
334
335 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
336 for in_port in ports:
337 mac_src='00:00:00:22:22:%02X' % in_port
338 ip_src='192.168.%02d.1' % in_port
339 for out_port in ports:
340 if in_port == out_port:
341 continue
342 ip_dst='192.168.%02d.1' % out_port
343 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
344 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
345 ip_dst=ip_dst)
346 pkt=str(parsed_pkt)
347 self.dataplane.send(in_port, pkt)
348 verify_packet_in(self, pkt, in_port, ofp.OFPR_ACTION)
349 #verify_no_other_packets(self)
Flavio Castro91d1a552016-05-17 16:59:44 -0700350 delete_all_flows(self.controller)
351 delete_groups(self.controller, Groups)
Flavio Castro54947942016-02-03 16:05:20 -0500352
Flavio Castro54947942016-02-03 16:05:20 -0500353class PacketInSrcMacMiss(base_tests.SimpleDataPlane):
354 """
355 Test packet in function on a src-mac miss
356 Send a packet to each dataplane port and verify that a packet
357 in message is received from the controller for each
358 #todo verify you stop receiving after adding rule
359 """
360
361 def runTest(self):
362 delete_all_flows(self.controller)
363 delete_all_groups(self.controller)
364
365 ports = sorted(config["port_map"].keys())
366 for port in ports:
367 add_one_l2_interface_group(self.controller, port, 1, True, False)
368 add_one_vlan_table_flow(self.controller, port, 1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
369
370 parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
371 vlan_vid=0x1001, dl_vlan_enable=True)
372 vlan_pkt = str(parsed_vlan_pkt)
373
374 for of_port in config["port_map"].keys():
375 logging.info("PacketInMiss test, port %d", of_port)
376 self.dataplane.send(of_port, vlan_pkt)
377
378 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH)
379
Flavio Castro6da7e462016-02-04 18:56:29 -0500380 verify_no_other_packets(self)