blob: dcbcfa5ea66a62a0e0d27d5790214524fd46fa34 [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
303 vlan_id=1
304 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
305 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
306 dip=0xc0a80001
307 for port in config["port_map"].keys():
308 #add l2 interface group
309 add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
310 dst_mac[5]=vlan_id
311 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
312 #add vlan flow table
313 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
314 #add termination flow
315 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
316 #add unicast routing flow
317 dst_ip = dip + (vlan_id<<8)
Flavio Castro6efe1862015-11-18 16:28:06 -0500318 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
319
320 #add entries in the Bridging table to avoid packet-in from mac learning
321 group_id = encode_l2_interface_group_id(vlan_id, port)
322 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
323
Flavio Castro05d20bc2015-11-16 15:06:14 -0500324 vlan_id += 1
325
326 do_barrier(self.controller)
327
328 port1=config["port_map"].keys()[0]
329 port2=config["port_map"].keys()[1]
330 #port 1 to port 2
331 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
332 dst_mac[5]=1
333 port1_mac=':'.join(['%02X' % x for x in dst_mac])
334
Flavio Castroaabb5792015-11-18 19:03:50 -0500335 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True,
Flavio Castro05d20bc2015-11-16 15:06:14 -0500336 vlan_vid=1,
337 eth_dst=switch_mac,
338 eth_src=port1_mac,
339 ip_ttl=64,
340 ip_src="192.168.1.1",
341 ip_dst='192.168.2.1')
342 pkt=str(parsed_pkt)
343 self.dataplane.send(port1, pkt)
344 #build expect packet
345 dst_mac[5]=2
346 port2_mac=':'.join(['%02X' % x for x in dst_mac])
347 exp_pkt = simple_tcp_packet(pktlen=100,
348 dl_vlan_enable=True,
349 vlan_vid=2,
350 eth_dst=port2_mac,
351 eth_src=switch_mac,
352 ip_ttl=63,
353 ip_src="192.168.1.1",
354 ip_dst='192.168.2.1')
355 pkt=str(exp_pkt)
356 verify_packet(self, pkt, port2)
357 verify_no_other_packets(self)
358
359 #port 2 to port 1
360 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
361 dst_mac[5]=2
362 port2_mac=':'.join(['%02X' % x for x in dst_mac])
363
364 parsed_pkt = simple_tcp_packet(pktlen=100,
365 dl_vlan_enable=True,
366 vlan_vid=2,
367 eth_dst=switch_mac,
368 eth_src=port2_mac,
369 ip_ttl=64,
370 ip_src="192.168.2.1",
371 ip_dst='192.168.1.1')
372 pkt=str(parsed_pkt)
373 self.dataplane.send(port2, pkt)
374 #build expect packet
375 dst_mac[5]=1
376 port1_mac=':'.join(['%02X' % x for x in dst_mac])
377 exp_pkt = simple_tcp_packet(pktlen=100,
378 dl_vlan_enable=True,
379 vlan_vid=1,
380 eth_dst=port1_mac,
381 eth_src=switch_mac,
382 ip_ttl=63,
383 ip_src="192.168.2.1",
384 ip_dst='192.168.1.1')
385 pkt=str(exp_pkt)
386 verify_packet(self, pkt, port1)
387 verify_no_other_packets(self)
388