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