blob: cf9796ffbc06bd1f25614a08f001827ed8e23c6b [file] [log] [blame]
Flavio Castro05d20bc2015-11-16 15:06:14 -05001"""
2Flow Test
Flavio Castro3aec8902015-11-20 10:51:38 -050031) PacketInSrcMacMiss
42) L2FloodTagged
53) L2Flood Tagged Unknown Src
64) L2 Unicast Tagged
75) L3 Unicast Tagged
86) MTU 1500
97) MTU 4100
108) MTU 4500
Flavio Castro05d20bc2015-11-16 15:06:14 -050011"""
12
13import logging
14
15from oftest import config
16import oftest.base_tests as base_tests
17import ofp
18from oftest.testutils import *
19from accton_util import *
20
Flavio Castroaabb5792015-11-18 19:03:50 -050021class PacketInSrcMacMiss(base_tests.SimpleDataPlane):
22 """
23 Test packet in function on a src-mac miss
24 Send a packet to each dataplane port and verify that a packet
25 in message is received from the controller for each
26 #todo verify you stop receiving after adding rule
27 """
28
Flavio Castro6efe1862015-11-18 16:28:06 -050029 def runTest(self):
30 delete_all_flows(self.controller)
31 delete_all_groups(self.controller)
32
Flavio Castroaabb5792015-11-18 19:03:50 -050033 parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
34 vlan_vid=0x1001, dl_vlan_enable=True)
35 vlan_pkt = str(parsed_vlan_pkt)
Flavio Castro6efe1862015-11-18 16:28:06 -050036
Flavio Castroaabb5792015-11-18 19:03:50 -050037 add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
Flavio Castro6efe1862015-11-18 16:28:06 -050038
Flavio Castroaabb5792015-11-18 19:03:50 -050039 # group table
40 # set up untag groups for each port
41 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1)
42
43 for of_port in config["port_map"].keys():
44 logging.info("PacketInMiss test, port %d", of_port)
45 self.dataplane.send(of_port, vlan_pkt)
46
47 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH)
48
49 verify_no_other_packets(self)
50
Flavio Castro184cefe2015-11-19 20:52:49 -050051class L2FloodTagged(base_tests.SimpleDataPlane):
52 """
53 Test L2 flood to a vlan
54 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
55 #todo take in account unknown src
56 """
57 def runTest(self):
58 ports = sorted(config["port_map"].keys())
59 delete_all_flows(self.controller)
60 delete_all_groups(self.controller)
61
62 add_vlan_table_flow(self.controller, ports, 1)
63
64 # set up tagged groups for each port
65 add_l2_interface_grouop(self.controller, ports, 1, True, 1)
66
67 msg=add_l2_flood_group(self.controller, ports, 1, 1)
68 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
69 # Installing flows to avoid packet-in
70 for port in ports:
71 group_id = encode_l2_interface_group_id(1, port)
72 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
73 do_barrier(self.controller)
74
75 #verify flood
76 for ofport in ports:
77 # change dest based on port number
78 mac_src= '00:12:34:56:78:%02X' % ofport
79 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
80 pkt = str(parsed_pkt)
81 self.dataplane.send(ofport, pkt)
82 #self won't rx packet
83 verify_no_packet(self, pkt, ofport)
84 #others will rx packet
85 tmp_ports=list(ports)
86 tmp_ports.remove(ofport)
87 verify_packets(self, pkt, tmp_ports)
88
89 verify_no_other_packets(self)
90
Flavio Castroaabb5792015-11-18 19:03:50 -050091class L2FloodTaggedUnknownSrc(base_tests.SimpleDataPlane):
92 """
93 Test L2 flood to a vlan
94 Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport
95 #todo take in account unknown src
96 """
97 def runTest(self):
98 ports = sorted(config["port_map"].keys())
99 delete_all_flows(self.controller)
100 delete_all_groups(self.controller)
101
102 add_vlan_table_flow(self.controller, ports, 1)
103
104 # set up tagged groups for each port
105 add_l2_interface_grouop(self.controller, ports, 1, True, 1)
106
107 msg=add_l2_flood_group(self.controller, ports, 1, 1)
108 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
109
110 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a')
111 pkt = str(parsed_pkt)
112 #verify flood
113 for ofport in ports:
114 self.dataplane.send(ofport, pkt)
115 #self won't rx packet
116 verify_no_packet(self, pkt, ofport)
117 #others will rx packet
118 tmp_ports=list(ports)
119 tmp_ports.remove(ofport)
120 verify_packets(self, pkt, tmp_ports)
121
122 verify_no_other_packets(self)
123
Flavio Castroaabb5792015-11-18 19:03:50 -0500124class L2UnicastTagged(base_tests.SimpleDataPlane):
125 """
126 Test output function for an exact-match flow
127
128 For each port A, adds a flow directing matching packets to that port.
129 Then, for all other ports B != A, verifies that sending a matching packet
130 to B results in an output to A.
131 """
132 def runTest(self):
133 ports = sorted(config["port_map"].keys())
134
135 delete_all_flows(self.controller)
136 delete_all_groups(self.controller)
137
138 add_vlan_table_flow(self.controller, config["port_map"].keys())
139
140 # set up tag groups for each port
141 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1)
142
143 for port in ports:
144 group_id = encode_l2_interface_group_id(1, port)
145 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
Flavio Castro6efe1862015-11-18 16:28:06 -0500146 do_barrier(self.controller)
147
Flavio Castroaabb5792015-11-18 19:03:50 -0500148 for out_port in ports:
149 # change dest based on port number
150 mac_dst= '00:12:34:56:78:%02X' % out_port
151 for in_port in ports:
152 if in_port == out_port:
153 continue
154 # change source based on port number to avoid packet-ins from learning
155 mac_src= '00:12:34:56:78:%02X' % in_port
156 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
157 pkt = str(parsed_pkt)
158 self.dataplane.send(in_port, pkt)
159
160 for ofport in ports:
161 if ofport in [out_port]:
162 verify_packet(self, pkt, ofport)
163 else:
164 verify_no_packet(self, pkt, ofport)
165
166 verify_no_other_packets(self)
Flavio Castro6efe1862015-11-18 16:28:06 -0500167
168
Flavio Castrob6773032015-11-19 22:49:24 -0500169class Mtu4500(base_tests.SimpleDataPlane):
170
171 def runTest(self):
172 ports = sorted(config["port_map"].keys())
173
174 delete_all_flows(self.controller)
175 delete_all_groups(self.controller)
176
177 add_vlan_table_flow(self.controller, config["port_map"].keys())
178
179 # set up tag groups for each port
180 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1)
181
182 for port in ports:
183 group_id = encode_l2_interface_group_id(1, port)
184 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
185 do_barrier(self.controller)
186
187 for out_port in ports:
188 # change dest based on port number
189 mac_dst= '00:12:34:56:78:%02X' % out_port
190 for in_port in ports:
191 if in_port == out_port:
192 continue
193 # change source based on port number to avoid packet-ins from learning
194 mac_src= '00:12:34:56:78:%02X' % in_port
195 parsed_pkt = simple_tcp_packet(pktlen=4500,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
196 pkt = str(parsed_pkt)
197 self.dataplane.send(in_port, pkt)
198
199 for ofport in ports:
200 if ofport in [out_port]:
201 verify_packet(self, pkt, ofport)
202 else:
203 verify_no_packet(self, pkt, ofport)
204
205 verify_no_other_packets(self)
206
207
208class Mtu1500(base_tests.SimpleDataPlane):
209
210 def runTest(self):
211 ports = sorted(config["port_map"].keys())
212
213 delete_all_flows(self.controller)
214 delete_all_groups(self.controller)
215
216 add_vlan_table_flow(self.controller, config["port_map"].keys())
217
218 # set up tag groups for each port
219 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1)
220
221 for port in ports:
222 group_id = encode_l2_interface_group_id(1, port)
223 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
224 do_barrier(self.controller)
225
226 for out_port in ports:
227 # change dest based on port number
228 mac_dst= '00:12:34:56:78:%02X' % out_port
229 for in_port in ports:
230 if in_port == out_port:
231 continue
232 # change source based on port number to avoid packet-ins from learning
233 mac_src= '00:12:34:56:78:%02X' % in_port
234 parsed_pkt = simple_tcp_packet(pktlen=1500,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
235 pkt = str(parsed_pkt)
236 self.dataplane.send(in_port, pkt)
237
238 for ofport in ports:
239 if ofport in [out_port]:
240 verify_packet(self, pkt, ofport)
241 else:
242 verify_no_packet(self, pkt, ofport)
243
244 verify_no_other_packets(self)
245
246
247class Mtu4000(base_tests.SimpleDataPlane):
248 """
249 Test output function for an exact-match flow
250 For each port A, adds a flow directing matching packets to that port.
251 Then, for all other ports B != A, verifies that sending a matching packet
252 to B results in an output to A.
253 """
254 def runTest(self):
255 ports = sorted(config["port_map"].keys())
256
257 delete_all_flows(self.controller)
258 delete_all_groups(self.controller)
259
260 add_vlan_table_flow(self.controller, config["port_map"].keys())
261
262 # set up tag groups for each port
263 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1)
264
265 for port in ports:
266 group_id = encode_l2_interface_group_id(1, port)
267 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
268 do_barrier(self.controller)
269
270 for out_port in ports:
271 # change dest based on port number
272 mac_dst= '00:12:34:56:78:%02X' % out_port
273 for in_port in ports:
274 if in_port == out_port:
275 continue
276 # change source based on port number to avoid packet-ins from learning
277 mac_src= '00:12:34:56:78:%02X' % in_port
278 parsed_pkt = simple_tcp_packet(pktlen=4000,dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
279 pkt = str(parsed_pkt)
280 self.dataplane.send(in_port, pkt)
281
282 for ofport in ports:
283 if ofport in [out_port]:
284 verify_packet(self, pkt, ofport)
285 else:
286 verify_no_packet(self, pkt, ofport)
287
288 verify_no_other_packets(self)
Flavio Castroaabb5792015-11-18 19:03:50 -0500289
290class L3UcastTagged(base_tests.SimpleDataPlane):
Flavio Castro05d20bc2015-11-16 15:06:14 -0500291 """
292 Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
293 Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
294 """
295 def runTest(self):
296 delete_all_flows(self.controller)
297 delete_all_groups(self.controller)
298
299 if len(config["port_map"]) <2:
300 logging.info("Port count less than 2, can't run this case")
301 return
302
Flavio Castro05d20bc2015-11-16 15:06:14 -0500303 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
304 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
305 dip=0xc0a80001
Flavio Castroa8233862015-12-02 14:41:11 -0500306 ports = config["port_map"].keys()
307 for port in ports:
Flavio Castro05d20bc2015-11-16 15:06:14 -0500308 #add l2 interface group
Flavio Castroa8233862015-12-02 14:41:11 -0500309 vlan_id=port
Flavio Castro05d20bc2015-11-16 15:06:14 -0500310 add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
311 dst_mac[5]=vlan_id
312 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
313 #add vlan flow table
314 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
315 #add termination flow
316 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
317 #add unicast routing flow
318 dst_ip = dip + (vlan_id<<8)
Flavio Castro6efe1862015-11-18 16:28:06 -0500319 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
320
321 #add entries in the Bridging table to avoid packet-in from mac learning
322 group_id = encode_l2_interface_group_id(vlan_id, port)
323 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500324
325 do_barrier(self.controller)
326
Flavio Castro05d20bc2015-11-16 15:06:14 -0500327 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
Flavio Castroa8233862015-12-02 14:41:11 -0500328 for in_port in ports:
329 mac_src='00:00:00:22:22:%02X' % in_port
330 ip_src='192.168.%02d.1' % in_port
331 for out_port in ports:
332 if in_port == out_port:
333 continue
334 ip_dst='192.168.%02d.1' % out_port
335 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
336 eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
337 ip_dst=ip_dst)
338 pkt=str(parsed_pkt)
339 self.dataplane.send(in_port, pkt)
340 #build expect packet
341 mac_dst='00:00:00:22:22:%02X' % out_port
342 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
343 eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
344 ip_src=ip_src, ip_dst=ip_dst)
345 pkt=str(exp_pkt)
346 verify_packet(self, pkt, out_port)
347 verify_no_other_packets(self)
Flavio Castro05d20bc2015-11-16 15:06:14 -0500348