blob: 2dd7cf46b333125cb0dff45721635398aaaba1b1 [file] [log] [blame]
macauley1e26c5b2015-07-16 17:27:32 +08001"""
2Flow Test
3
4Test each flow table can set entry, and packet rx correctly.
5"""
6
7import logging
8
9from oftest import config
10import oftest.base_tests as base_tests
11import ofp
12from oftest.testutils import *
13from accton_util import *
14
15class L2McastFlow(base_tests.SimpleDataPlane):
16 """
17 Test output function for an exact-match flow
18
19 Add some multicast flows
20 Then, for all ports, verifies that sending a matching packet
21 to a multicast match results in an output to all ports.
22 """
23 def runTest(self):
24 ports = sorted(config["port_map"].keys())
25
26 delete_all_flows(self.controller)
27 delete_all_groups(self.controller)
28
29 # table 10: vlan
30 # send to table 20
31 add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
32
33 # group table
34 # set up untag groups for each port
35 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, False)
36
37 # set up multicast group
38 add_l2_mcast_group(self.controller, config["port_map"].keys(), 1, 1)
39
macauley53e64c42015-07-30 14:07:45 +080040 test_macs = [[0x01, 0x00, 0x5e, 0x0f, 0xff, 0xff]]
macauley1e26c5b2015-07-16 17:27:32 +080041
42 for test_mac in test_macs:
43 group_id = encode_l2_mcast_group_id(1, 1)
44 add_bridge_flow(self.controller, test_mac, 1, group_id, True)
45
46 for test_mac in test_macs:
47 mactest = ':'.join(['%02X' % x for x in test_mac])
48
49 for in_port in ports:
50 # change dest based on port number
51 parsed_pkt = simple_tcp_packet(eth_dst=mactest)
52 pkt = str(parsed_pkt)
53 logging.info("OutputExact test, from port %d to mac %s", in_port, mactest)
54 self.dataplane.send(in_port, pkt)
55
56 for ofport in ports:
57 if ofport == in_port: #tx port won't rx packet, unless L3 mcast routing
58 continue
59 verify_packet(self, pkt, ofport)
60 verify_no_other_packets(self)
61
62class L2UnicastFlow(base_tests.SimpleDataPlane):
63 """
64 Test output function for an exact-match flow
65
66 For each port A, adds a flow directing matching packets to that port.
67 Then, for all other ports B != A, verifies that sending a matching packet
68 to B results in an output to A.
69 """
70 def runTest(self):
71 ports = sorted(config["port_map"].keys())
72
73 delete_all_flows(self.controller)
74 delete_all_groups(self.controller)
75 # table 10: vlan
76 # send to table 20
77 add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
78
79 # group table
80 # set up untag groups for each port
81 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, 1)
82
83 for out_port in ports:
84 group_id = encode_l2_interface_group_id(1, out_port)
85 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, out_port], 1, group_id, True)
86
87 for in_port in ports:
88 if in_port == out_port:
89 continue
90 # change dest based on port number
91 parsed_pkt = simple_tcp_packet(eth_dst='00:12:34:56:78:%02X' % out_port)
92 pkt = str(parsed_pkt)
93 logging.info("OutputExact test, ports %d to %d", in_port, out_port)
94 self.dataplane.send(in_port, pkt)
95
96 for ofport in ports:
97 if ofport in [out_port]:
98 verify_packet(self, pkt, ofport)
99 else:
100 verify_no_packet(self, pkt, ofport)
101
102 verify_no_other_packets(self)
103
macauley76cc8d22015-07-27 17:40:36 +0800104class L2Flood(base_tests.SimpleDataPlane):
105 """
106 Test L2 unknown unicast flooding and broadcast flood
107 """
108 def runTest(self):
macauley9a53bf92015-08-03 13:36:00 +0800109 return
macauley76cc8d22015-07-27 17:40:36 +0800110 ports = sorted(config["port_map"].keys())
111
112 delete_all_flows(self.controller)
113 delete_all_groups(self.controller)
114 # table 10: vlan
115 # send to table 20
116 add_vlan_table_flow(self.controller, ports, 1)
117
118 # group table
119 # set up untag groups for each port
120 add_l2_interface_grouop(self.controller, ports, 1, False, 1)
121
122 input_port = ports.pop()
123 flood_ports= ports
macauley53e64c42015-07-30 14:07:45 +0800124
macauley76cc8d22015-07-27 17:40:36 +0800125 #no fllod group create, veriy all drop
126 parsed_pkt = simple_tcp_packet(eth_dst='00:12:34:56:78:9a')
127 pkt = str(parsed_pkt)
128 self.dataplane.send(input_port, pkt)
129 verify_no_other_packets(self)
130 parsed_pkt = simple_tcp_packet(eth_dst='FF:FF:FF:FF:FF:FF')
131 pkt = str(parsed_pkt)
132 self.dataplane.send(input_port, pkt)
133 verify_no_other_packets(self)
134 #add flood groupo
135 msg=add_l2_flood_group(self.controller, flood_ports, 1, 1)
136 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
137 #verify flood
138 parsed_pkt = simple_tcp_packet(eth_dst='00:12:34:56:78:9a')
139 pkt = str(parsed_pkt)
140 self.dataplane.send(input_port, pkt)
141 for ofport in flood_ports:
142 verify_packet(self, pkt, ofport)
143
144 verify_no_other_packets(self)
145
146 for ofport in flood_ports:
147 self.dataplane.send(ofport, pkt)
macauley53e64c42015-07-30 14:07:45 +0800148 #self won't rx packet
macauley76cc8d22015-07-27 17:40:36 +0800149 verify_no_packet(self, pkt, ofport)
macauley53e64c42015-07-30 14:07:45 +0800150 #others will rx packet
151 tmp_ports=[]
152 for tmp in flood_ports:
153 if tmp != ofport:
154 tmp_ports.append(tmp)
155 verify_packets(self, pkt, tmp_ports)
156
macauley76cc8d22015-07-27 17:40:36 +0800157 verify_no_other_packets(self)
158
159 parsed_pkt = simple_tcp_packet(eth_dst='FF:FF:FF:FF:FF:FF')
160 pkt = str(parsed_pkt)
161 self.dataplane.send(input_port, pkt)
162 for ofport in flood_ports:
163 verify_packet(self, pkt, ofport)
164
macauley1e26c5b2015-07-16 17:27:32 +0800165class PacketInMiss(base_tests.SimpleDataPlane):
166 """
167 Test packet in function for a table-miss flow
168
169 Send a packet to each dataplane port and verify that a packet
170 in message is received from the controller for each
macauley52950382015-07-17 15:59:01 +0800171
172 NOTE: Verify This case the oft option shall not use --switch-ip
macauley1e26c5b2015-07-16 17:27:32 +0800173 """
174
175 def runTest(self):
176 delete_all_flows(self.controller)
177 delete_all_groups(self.controller)
178
179 parsed_pkt = simple_tcp_packet(pktlen=100)
180 parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
181 vlan_vid=0x1001, dl_vlan_enable=True)
182 pkt = str(parsed_pkt)
183 vlan_pkt = str(parsed_vlan_pkt)
184 # table 10: vlan
185 # send to table 20
186 add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
187
188 # group table
189 # set up untag groups for each port
190 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, 1)
191
192 # create match
193 match = ofp.match()
194 match.oxm_list.append(ofp.oxm.vlan_vid(0x1001))
195 request = ofp.message.flow_add(
196 table_id=60,
197 cookie=42,
198 match=match,
199 instructions=[
200 ofp.instruction.apply_actions(
201 actions=[
202 ofp.action.output(
203 port=ofp.OFPP_CONTROLLER,
204 max_len=ofp.OFPCML_NO_BUFFER)]),
205 ],
206 buffer_id=ofp.OFP_NO_BUFFER,
207 priority=1)
208
209 logging.info("Inserting packet in flow to controller")
210 self.controller.message_send(request)
211 do_barrier(self.controller)
212
213 for of_port in config["port_map"].keys():
214 logging.info("PacketInMiss test, port %d", of_port)
215 self.dataplane.send(of_port, pkt)
216
217 #AOS current packet in will not have vlan tag
macauley52950382015-07-17 15:59:01 +0800218 if config["cicada_poject"]:
219 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
220 else:
221 verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
222
macauley1e26c5b2015-07-16 17:27:32 +0800223 verify_no_other_packets(self)
224
macauley52950382015-07-17 15:59:01 +0800225class PacketOut(base_tests.SimpleDataPlane):
226 """
227 Verify action Flood, ALL, in port
228 """
229
230 def runTest(self):
231 if config["cicada_poject"]:
232 pass
233
234 delete_all_flows(self.controller)
235 delete_all_groups(self.controller)
236
237 parsed_pkt = simple_tcp_packet(pktlen=100)
238 parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
239 vlan_vid=0x1002, dl_vlan_enable=True)
240
241 pkt = str(parsed_pkt)
242 vlan_pkt = str(parsed_vlan_pkt)
243
244
245 #packet out flood, untag packet
246 self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
247 buffer_id=ofp.OFP_NO_BUFFER,
248 actions=[ofp.action.output(
249 port=ofp.OFPP_FLOOD)],
250 data=pkt))
251
252 for of_port in config["port_map"].keys():
253 verify_packet(self, pkt, of_port)
254
255 verify_no_other_packets(self)
256
257 #packet out flood, tag packet, because it can't identify vlan has which port
258 #so we do as all action.
259 self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
260 buffer_id=ofp.OFP_NO_BUFFER,
261 actions=[ofp.action.output(
262 port=ofp.OFPP_FLOOD)],
263 data=vlan_pkt))
264
265 for of_port in config["port_map"].keys():
266 verify_packet(self, vlan_pkt, of_port)
267
268 verify_no_other_packets(self)
269
270 #packet out all
271 self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
272 buffer_id=ofp.OFP_NO_BUFFER,
273 actions=[ofp.action.output(
274 port=ofp.OFPP_FLOOD)],
275 data=pkt))
276
277 for of_port in config["port_map"].keys():
278 verify_packet(self, pkt, of_port)
279
280 verify_no_other_packets(self)
281
282 #packet out to in port
283 in_port = config["port_map"].keys()[0]
284 self.controller.message_send(ofp.message.packet_out(in_port=in_port,
285 buffer_id=ofp.OFP_NO_BUFFER,
286 actions=[ofp.action.output(
287 port=in_port)],
288 data=pkt))
289
290 verify_packet(self, pkt, in_port)
291 verify_no_other_packets(self)
292
macauleyfa788eb2015-07-23 15:13:54 +0800293class L3UcastRoute(base_tests.SimpleDataPlane):
macauley0c54d3f2015-07-17 18:10:03 +0800294 """
macauley76cc8d22015-07-27 17:40:36 +0800295 Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
296 Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
macauley0c54d3f2015-07-17 18:10:03 +0800297 """
298 def runTest(self):
299 delete_all_flows(self.controller)
300 delete_all_groups(self.controller)
macauleyfa788eb2015-07-23 15:13:54 +0800301
302 if len(config["port_map"]) <2:
303 logging.info("Port count less than 2, can't run this case")
304 return
305
macauley0c54d3f2015-07-17 18:10:03 +0800306 vlan_id=1
307 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
308 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
309 dip=0xc0a80001
310 for port in config["port_map"].keys():
311 #add l2 interface group
312 add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
313 dst_mac[5]=vlan_id
314 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
315 #add vlan flow table
316 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
317 #add termination flow
318 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
319 #add unicast routing flow
320 dst_ip = dip + (vlan_id<<8)
macauleyfa788eb2015-07-23 15:13:54 +0800321 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
macauley0c54d3f2015-07-17 18:10:03 +0800322 vlan_id += 1
323
macauleyfa788eb2015-07-23 15:13:54 +0800324 do_barrier(self.controller)
macauley0c54d3f2015-07-17 18:10:03 +0800325
326 port1=config["port_map"].keys()[0]
327 port2=config["port_map"].keys()[1]
328 #port 1 to port 2
macauleyfa788eb2015-07-23 15:13:54 +0800329 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
macauley0c54d3f2015-07-17 18:10:03 +0800330 dst_mac[5]=1
macauleyfa788eb2015-07-23 15:13:54 +0800331 port1_mac=':'.join(['%02X' % x for x in dst_mac])
macauley0c54d3f2015-07-17 18:10:03 +0800332
333 parsed_pkt = simple_tcp_packet(pktlen=100,
macauleyfa788eb2015-07-23 15:13:54 +0800334 eth_dst=switch_mac,
335 eth_src=port1_mac,
336 ip_ttl=64,
macauley0c54d3f2015-07-17 18:10:03 +0800337 ip_src="192.168.1.1",
338 ip_dst='192.168.2.1')
339 pkt=str(parsed_pkt)
340 self.dataplane.send(port1, pkt)
macauleyfa788eb2015-07-23 15:13:54 +0800341 #build expect packet
342 dst_mac[5]=2
343 port2_mac=':'.join(['%02X' % x for x in dst_mac])
344 exp_pkt = simple_tcp_packet(pktlen=100,
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)
macauley0c54d3f2015-07-17 18:10:03 +0800351 verify_packet(self, pkt, port2)
352 verify_no_other_packets(self)
macauleyfa788eb2015-07-23 15:13:54 +0800353
macauley0c54d3f2015-07-17 18:10:03 +0800354 #port 2 to port 1
macauleyfa788eb2015-07-23 15:13:54 +0800355 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
macauley0c54d3f2015-07-17 18:10:03 +0800356 dst_mac[5]=2
macauleyfa788eb2015-07-23 15:13:54 +0800357 port2_mac=':'.join(['%02X' % x for x in dst_mac])
macauley0c54d3f2015-07-17 18:10:03 +0800358
359 parsed_pkt = simple_tcp_packet(pktlen=100,
macauleyfa788eb2015-07-23 15:13:54 +0800360 eth_dst=switch_mac,
361 eth_src=port2_mac,
362 ip_ttl=64,
macauley0c54d3f2015-07-17 18:10:03 +0800363 ip_src="192.168.2.1",
364 ip_dst='192.168.1.1')
365 pkt=str(parsed_pkt)
366 self.dataplane.send(port2, pkt)
macauleyfa788eb2015-07-23 15:13:54 +0800367 #build expect packet
368 dst_mac[5]=1
369 port1_mac=':'.join(['%02X' % x for x in dst_mac])
370 exp_pkt = simple_tcp_packet(pktlen=100,
371 eth_dst=port1_mac,
372 eth_src=switch_mac,
373 ip_ttl=63,
374 ip_src="192.168.2.1",
375 ip_dst='192.168.1.1')
376 pkt=str(exp_pkt)
377 verify_packet(self, pkt, port1)
378 verify_no_other_packets(self)
macauley76cc8d22015-07-27 17:40:36 +0800379
macauley9a53bf92015-08-03 13:36:00 +0800380class L3UcastRouteOnSamVLANSamPort(base_tests.SimpleDataPlane):
381 """
382 Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
383 Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
384 """
385 def runTest(self):
386 delete_all_flows(self.controller)
387 delete_all_groups(self.controller)
388 port = config["port_map"].keys()[0]
389
390 vlan_id=1
391 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
392 port_mac1=[0x00, 0x00, 0x00, 0x22, 0x22, 0x01]
393 port_mac2=[0x00, 0x00, 0x00, 0x22, 0x22, 0x02]
394 port_ip1=0xc0a80101
395 port_ip1_str=convertIP4toStr(port_ip1)
396 port_ip2=0xc0a80201
397 port_ip2_str=convertIP4toStr(port_ip2)
398 #add l2 interface group
399 add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
400 #add vlan flow table
401 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
402 #add termination flow
403 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
404
405 """192.168.1.1->192.168.2.1"""
406 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=1, src_mac=intf_src_mac, dst_mac=port_mac2)
407 add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id)
408 """192.168.1.1->192.168.2.1"""
409 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=2, src_mac=intf_src_mac, dst_mac=port_mac1)
410 add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id)
411
412 do_barrier(self.controller)
413
414 """send packet to verify"""
415 """192.168.1.1->192.168.2.1"""
416 switch_mac_str = convertMACtoStr(intf_src_mac)
417 port_mac1_str = convertMACtoStr(port_mac1)
418 port_mac2_str = convertMACtoStr(port_mac2)
419 ttl=64
420 #send packet
421 parsed_pkt = simple_tcp_packet(pktlen=100,
422 eth_dst=switch_mac_str,
423 eth_src=port_mac1_str,
424 ip_ttl=ttl,
425 ip_src=port_ip1_str,
426 ip_dst=port_ip2_str)
427 pkt=str(parsed_pkt)
428 self.dataplane.send(port, pkt)
429 #build expect packet
430 exp_pkt = simple_tcp_packet(pktlen=100,
431 eth_dst=port_mac2_str,
432 eth_src=switch_mac_str,
433 ip_ttl=(ttl-1),
434 ip_src=port_ip1_str,
435 ip_dst=port_ip2_str)
436 pkt=str(exp_pkt)
437 verify_packet(self, pkt, port)
438 verify_no_other_packets(self)
439
440 """192.168.2.1->192.168.1.1"""
441 parsed_pkt = simple_tcp_packet(pktlen=100,
442 eth_dst=switch_mac_str,
443 eth_src=port_mac2_str,
444 ip_ttl=ttl,
445 ip_src=port_ip2_str,
446 ip_dst=port_ip1_str)
447 pkt=str(parsed_pkt)
448 self.dataplane.send(port, pkt)
449 #build expect packet
450 exp_pkt = simple_tcp_packet(pktlen=100,
451 eth_dst=port_mac1_str,
452 eth_src=switch_mac_str,
453 ip_ttl=(ttl-1),
454 ip_src=port_ip2_str,
455 ip_dst=port_ip1_str)
456 pkt=str(exp_pkt)
457 verify_packet(self, pkt, port)
458 verify_no_other_packets(self)
459
460class L3UcastRouteOnDiffVLANSamPort(base_tests.SimpleDataPlane):
461 """
462 Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
463 Port1(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
464 """
465 def runTest(self):
466 delete_all_flows(self.controller)
467 delete_all_groups(self.controller)
468 port = config["port_map"].keys()[0]
469
470 port_vlan_id1=1
471 port_vlan_id2=2
472 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
473 port_mac1=[0x00, 0x00, 0x00, 0x22, 0x22, 0x01]
474 port_mac2=[0x00, 0x00, 0x00, 0x22, 0x22, 0x02]
475 port_ip1=0xc0a80101
476 port_ip1_str=convertIP4toStr(port_ip1)
477 port_ip2=0xc0a80201
478 port_ip2_str=convertIP4toStr(port_ip2)
479 #add l2 interface group
480 add_one_l2_interface_grouop(self.controller, port, vlan_id=port_vlan_id1, is_tagged=True, send_barrier=False)
481 add_one_l2_interface_grouop(self.controller, port, vlan_id=port_vlan_id2, is_tagged=True, send_barrier=False)
482 #add vlan flow table
483 add_one_vlan_table_flow(self.controller, port, port_vlan_id1, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
484 add_one_vlan_table_flow(self.controller, port, port_vlan_id2, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
485 #add termination flow
486 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, port_vlan_id1)
487 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, port_vlan_id2)
488
489 """192.168.1.1->192.168.2.1"""
490 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=port_vlan_id2, id=1, src_mac=intf_src_mac, dst_mac=port_mac2)
491 add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id)
492 """192.168.1.1->192.168.2.1"""
493 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=port_vlan_id1, id=2, src_mac=intf_src_mac, dst_mac=port_mac1)
494 add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id)
495
496 do_barrier(self.controller)
497
498 """send packet to verify"""
499 """192.168.1.1->192.168.2.1"""
500 switch_mac_str =convertMACtoStr(intf_src_mac)
501 port_mac1_str= convertMACtoStr(port_mac1)
502 port_mac2_str= convertMACtoStr(port_mac2)
503 ttl=64
504 #send packet
505 parsed_pkt = simple_tcp_packet(pktlen=100,
506 eth_dst=switch_mac_str,
507 eth_src=port_mac1_str,
508 dl_vlan_enable=True,
509 vlan_vid=port_vlan_id1,
510 ip_ttl=ttl,
511 ip_src=port_ip1_str,
512 ip_dst=port_ip2_str)
513 pkt=str(parsed_pkt)
514 self.dataplane.send(port, pkt)
515 #build expect packet
516 exp_pkt = simple_tcp_packet(pktlen=100,
517 eth_dst=port_mac2_str,
518 eth_src=switch_mac_str,
519 dl_vlan_enable=True,
520 vlan_vid=port_vlan_id2,
521 ip_ttl=(ttl-1),
522 ip_src=port_ip1_str,
523 ip_dst=port_ip2_str)
524 pkt=str(exp_pkt)
525 verify_packet(self, pkt, port)
526 verify_no_other_packets(self)
527
528 """192.168.2.1->192.168.1.1"""
529 switch_mac = convertMACtoStr(intf_src_mac)
530 port_mac2_str=convertMACtoStr(port_mac2)
531
532 parsed_pkt = simple_tcp_packet(pktlen=100,
533 eth_dst=switch_mac_str,
534 eth_src=port_mac2_str,
535 dl_vlan_enable=True,
536 vlan_vid=port_vlan_id2,
537 ip_ttl=ttl,
538 ip_src=port_ip2_str,
539 ip_dst=port_ip1_str)
540 pkt=str(parsed_pkt)
541 self.dataplane.send(port, pkt)
542 #build expect packet
543 exp_pkt = simple_tcp_packet(pktlen=100,
544 eth_dst=port_mac1_str,
545 eth_src=switch_mac_str,
546 dl_vlan_enable=True,
547 vlan_vid=port_vlan_id1,
548 ip_ttl=(ttl-1),
549 ip_src=port_ip2_str,
550 ip_dst=port_ip1_str)
551 pkt=str(exp_pkt)
552 verify_packet(self, pkt, port)
553 verify_no_other_packets(self)
554
macauley53d90fe2015-08-04 17:34:22 +0800555class L3UcastVrfRouteOnSamVLANSamPort(base_tests.SimpleDataPlane):
556 """
557 Port1(vlan1, VRF1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
558 Port1(vlan1, VRF1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
559 Port1(vlan2, VRF2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
560 Port1(vlan2, VRF2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
561
562 """
563 def runTest(self):
564 delete_all_flows(self.controller)
565 delete_all_groups(self.controller)
566 port = config["port_map"].keys()[0]
567
568 vrf1=1
569 vrf2=2
570 vrf1_vlan_id=1
571 vrf2_vlan_id=2
572 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
573 port_mac1=[0x00, 0x00, 0x00, 0x22, 0x22, 0x01]
574 port_mac2=[0x00, 0x00, 0x00, 0x22, 0x22, 0x02]
575 port_ip1=0xc0a80101
576 port_ip1_str=convertIP4toStr(port_ip1)
577 port_ip2=0xc0a80201
578 port_ip2_str=convertIP4toStr(port_ip2)
579 #add l2 interface group
580 add_one_l2_interface_grouop(self.controller, port, vlan_id=vrf1_vlan_id, is_tagged=True, send_barrier=False)
581 add_one_l2_interface_grouop(self.controller, port, vlan_id=vrf2_vlan_id, is_tagged=True, send_barrier=False)
582 #add vlan flow table
583 add_one_vlan_table_flow(self.controller, port, vrf1_vlan_id, vrf=vrf1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
584 add_one_vlan_table_flow(self.controller, port, vrf2_vlan_id, vrf=vrf2, flag=VLAN_TABLE_FLAG_ONLY_TAG)
585
586 #add termination flow
587 add_termination_flow(self.controller, 0, 0x0800, intf_src_mac, vrf1_vlan_id)
588 add_termination_flow(self.controller, 0, 0x0800, intf_src_mac, vrf2_vlan_id)
589
590 """192.168.1.1->192.168.2.1"""
591 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf1_vlan_id, id=1, src_mac=intf_src_mac, dst_mac=port_mac2)
592 add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id, vrf1)
593 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf2_vlan_id, id=2, src_mac=intf_src_mac, dst_mac=port_mac2)
594 add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id, vrf2)
595
596 """192.168.1.1->192.168.2.1"""
597 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf1_vlan_id, id=3, src_mac=intf_src_mac, dst_mac=port_mac1)
598 add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id, vrf1)
599 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf2_vlan_id, id=4, src_mac=intf_src_mac, dst_mac=port_mac1)
600 add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id, vrf2)
601
602 do_barrier(self.controller)
603
604 """send packet to verify on VRF vrf1"""
605 """192.168.1.1->192.168.2.1"""
606 switch_mac_str = convertMACtoStr(intf_src_mac)
607 port_mac1_str = convertMACtoStr(port_mac1)
608 port_mac2_str = convertMACtoStr(port_mac2)
609 ttl=64
610 #send packet
611 parsed_pkt = simple_tcp_packet(pktlen=100,
612 eth_dst=switch_mac_str,
613 eth_src=port_mac1_str,
614 dl_vlan_enable=True,
615 vlan_vid=vrf1_vlan_id,
616 ip_ttl=ttl,
617 ip_src=port_ip1_str,
618 ip_dst=port_ip2_str)
619 pkt=str(parsed_pkt)
620 self.dataplane.send(port, pkt)
621 #build expect packet
622 exp_pkt = simple_tcp_packet(pktlen=100,
623 eth_dst=port_mac2_str,
624 eth_src=switch_mac_str,
625 dl_vlan_enable=True,
626 vlan_vid=vrf1_vlan_id,
627 ip_ttl=(ttl-1),
628 ip_src=port_ip1_str,
629 ip_dst=port_ip2_str)
630 pkt=str(exp_pkt)
631 verify_packet(self, pkt, port)
632 verify_no_other_packets(self)
633
634 """192.168.2.1->192.168.1.1"""
635 parsed_pkt = simple_tcp_packet(pktlen=100,
636 eth_dst=switch_mac_str,
637 eth_src=port_mac2_str,
638 dl_vlan_enable=True,
639 vlan_vid=vrf1_vlan_id,
640 ip_ttl=ttl,
641 ip_src=port_ip2_str,
642 ip_dst=port_ip1_str)
643 pkt=str(parsed_pkt)
644 self.dataplane.send(port, pkt)
645 #build expect packet
646 exp_pkt = simple_tcp_packet(pktlen=100,
647 eth_dst=port_mac1_str,
648 eth_src=switch_mac_str,
649 dl_vlan_enable=True,
650 vlan_vid=vrf1_vlan_id,
651 ip_ttl=(ttl-1),
652 ip_src=port_ip2_str,
653 ip_dst=port_ip1_str)
654 pkt=str(exp_pkt)
655 verify_packet(self, pkt, port)
656 verify_no_other_packets(self)
657
658
659 """send packet to verify on VRF vrf2"""
660 """192.168.1.1->192.168.2.1"""
661 switch_mac_str = convertMACtoStr(intf_src_mac)
662 port_mac1_str = convertMACtoStr(port_mac1)
663 port_mac2_str = convertMACtoStr(port_mac2)
664 ttl=64
665 #send packet
666 parsed_pkt = simple_tcp_packet(pktlen=100,
667 eth_dst=switch_mac_str,
668 eth_src=port_mac1_str,
669 dl_vlan_enable=True,
670 vlan_vid=vrf2_vlan_id,
671 ip_ttl=ttl,
672 ip_src=port_ip1_str,
673 ip_dst=port_ip2_str)
674 pkt=str(parsed_pkt)
675 self.dataplane.send(port, pkt)
676 #build expect packet
677 exp_pkt = simple_tcp_packet(pktlen=100,
678 eth_dst=port_mac2_str,
679 eth_src=switch_mac_str,
680 dl_vlan_enable=True,
681 vlan_vid=vrf2_vlan_id,
682 ip_ttl=(ttl-1),
683 ip_src=port_ip1_str,
684 ip_dst=port_ip2_str)
685 pkt=str(exp_pkt)
686 verify_packet(self, pkt, port)
687 verify_no_other_packets(self)
688
689 """192.168.2.1->192.168.1.1"""
690 parsed_pkt = simple_tcp_packet(pktlen=100,
691 eth_dst=switch_mac_str,
692 eth_src=port_mac2_str,
693 dl_vlan_enable=True,
694 vlan_vid=vrf2_vlan_id,
695 ip_ttl=ttl,
696 ip_src=port_ip2_str,
697 ip_dst=port_ip1_str)
698 pkt=str(parsed_pkt)
699 self.dataplane.send(port, pkt)
700 #build expect packet
701 exp_pkt = simple_tcp_packet(pktlen=100,
702 eth_dst=port_mac1_str,
703 eth_src=switch_mac_str,
704 dl_vlan_enable=True,
705 vlan_vid=vrf2_vlan_id,
706 ip_ttl=(ttl-1),
707 ip_src=port_ip2_str,
708 ip_dst=port_ip1_str)
709 pkt=str(exp_pkt)
710 verify_packet(self, pkt, port)
711 verify_no_other_packets(self)
712
713
714
715
macauley76cc8d22015-07-27 17:40:36 +0800716class L3UcastECMP(base_tests.SimpleDataPlane):
717 """
718 Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
719 Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
720 """
macauley0c54d3f2015-07-17 18:10:03 +0800721 def runTest(self):
722 delete_all_flows(self.controller)
723 delete_all_groups(self.controller)
macauley76cc8d22015-07-27 17:40:36 +0800724
725 if len(config["port_map"]) <2:
726 logging.info("Port count less than 2, can't run this case")
727 return
macauley0c54d3f2015-07-17 18:10:03 +0800728
macauley76cc8d22015-07-27 17:40:36 +0800729 vlan_id=1
730 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
731 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
732 dip=0xc0a80001
733 for port in config["port_map"].keys():
734 #add l2 interface group
735 add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
736 dst_mac[5]=vlan_id
737 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
738 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [l3_msg.group_id])
739 #add vlan flow table
740 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
741 #add termination flow
742 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
743 #add unicast routing flow
744 dst_ip = dip + (vlan_id<<8)
745 #ECMP shall have prefix not 32
746 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id)
747 vlan_id += 1
748
749 do_barrier(self.controller)
750
751 port1=config["port_map"].keys()[0]
752 port2=config["port_map"].keys()[1]
753 #port 1 to port 2
754 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
755 dst_mac[5]=1
756 port1_mac=':'.join(['%02X' % x for x in dst_mac])
macauley52950382015-07-17 15:59:01 +0800757
macauley76cc8d22015-07-27 17:40:36 +0800758 parsed_pkt = simple_tcp_packet(pktlen=100,
759 eth_dst=switch_mac,
760 eth_src=port1_mac,
761 ip_ttl=64,
762 ip_src="192.168.1.1",
763 ip_dst='192.168.2.1')
764 pkt=str(parsed_pkt)
765 self.dataplane.send(port1, pkt)
766 #build expect packet
767 dst_mac[5]=2
768 port2_mac=':'.join(['%02X' % x for x in dst_mac])
769 exp_pkt = simple_tcp_packet(pktlen=100,
770 eth_dst=port2_mac,
771 eth_src=switch_mac,
772 ip_ttl=63,
773 ip_src="192.168.1.1",
774 ip_dst='192.168.2.1')
775 pkt=str(exp_pkt)
776 verify_packet(self, pkt, port2)
777 verify_no_other_packets(self)
macauley52950382015-07-17 15:59:01 +0800778
macauley76cc8d22015-07-27 17:40:36 +0800779 #port 2 to port 1
780 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
781 dst_mac[5]=2
782 port2_mac=':'.join(['%02X' % x for x in dst_mac])
783
784 parsed_pkt = simple_tcp_packet(pktlen=100,
785 eth_dst=switch_mac,
786 eth_src=port2_mac,
787 ip_ttl=64,
788 ip_src="192.168.2.1",
789 ip_dst='192.168.1.1')
790 pkt=str(parsed_pkt)
791 self.dataplane.send(port2, pkt)
792 #build expect packet
793 dst_mac[5]=1
794 port1_mac=':'.join(['%02X' % x for x in dst_mac])
795 exp_pkt = simple_tcp_packet(pktlen=100,
796 eth_dst=port1_mac,
797 eth_src=switch_mac,
798 ip_ttl=63,
799 ip_src="192.168.2.1",
800 ip_dst='192.168.1.1')
801 pkt=str(exp_pkt)
802 verify_packet(self, pkt, port1)
803 verify_no_other_packets(self)
macauleyc8edafa2015-07-30 14:26:18 +0800804
macauley76cc8d22015-07-27 17:40:36 +0800805class L3McastRoute1(base_tests.SimpleDataPlane):
806 """
807 Mcast routing, From VLAN 1 to VLAN 2
808 """
809 def runTest(self):
810 """
811 port1 (vlan 1)-> port 2 (vlan 2)
812 """
813 delete_all_flows(self.controller)
814 delete_all_groups(self.controller)
macauleyc8edafa2015-07-30 14:26:18 +0800815
816 if len(config["port_map"]) <3:
macauley76cc8d22015-07-27 17:40:36 +0800817 logging.info("Port count less than 2, can't run this case")
818 return
819
820 vlan_id =1
macauleyc8edafa2015-07-30 14:26:18 +0800821 port2_out_vlan=2
822 port3_out_vlan=3
macauley76cc8d22015-07-27 17:40:36 +0800823 in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan
824 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
825 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
826 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
827 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
828 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
829 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
830 src_ip=0xc0a80101
831 src_ip_str="192.168.1.1"
832 dst_ip=0xe0010101
833 dst_ip_str="224.1.1.1"
834
835 port1=config["port_map"].keys()[0]
836 port2=config["port_map"].keys()[1]
macauleyc8edafa2015-07-30 14:26:18 +0800837 port3=config["port_map"].keys()[2]
838
macauley76cc8d22015-07-27 17:40:36 +0800839 #add l2 interface group
840 for port in config["port_map"].keys():
841 add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
842 #add vlan flow table
843 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
844 vlan_id +=1
845
846 #add termination flow
847 add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
848
849 #add l3 interface group
macauleyc8edafa2015-07-30 14:26:18 +0800850 port2_ucast_msg=add_l3_interface_group(self.controller, port2, port2_out_vlan, 2, intf_src_mac)
851 port3_ucast_msg=add_l3_interface_group(self.controller, port3, port3_out_vlan, 3, intf_src_mac)
852 mcat_group_msg=add_l3_mcast_group(self.controller, in_vlan, 2, [port2_ucast_msg.group_id, port3_ucast_msg.group_id])
macauley76cc8d22015-07-27 17:40:36 +0800853 add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id)
854
855 parsed_pkt = simple_udp_packet(pktlen=100,
856 eth_dst=dst_mac_str,
857 eth_src=port1_mac_str,
858 ip_ttl=64,
859 ip_src=src_ip_str,
860 ip_dst=dst_ip_str)
861 pkt=str(parsed_pkt)
862 self.dataplane.send(port1, pkt)
863 parsed_pkt = simple_udp_packet(pktlen=100,
864 eth_dst=dst_mac_str,
865 eth_src=intf_src_mac_str,
866 ip_ttl=63,
867 ip_src=src_ip_str,
868 ip_dst=dst_ip_str)
869 pkt=str(parsed_pkt)
870 verify_packet(self, pkt, port2)
macauleyc8edafa2015-07-30 14:26:18 +0800871 verify_packet(self, pkt, port3)
macauley76cc8d22015-07-27 17:40:36 +0800872 verify_no_other_packets(self)
873
macauley76cc8d22015-07-27 17:40:36 +0800874class L3McastRoute2(base_tests.SimpleDataPlane):
875 """
macauleyc8edafa2015-07-30 14:26:18 +0800876 Mcast routing, but on same vlan (l2mcast)
macauley76cc8d22015-07-27 17:40:36 +0800877 """
878 def runTest(self):
879 """
880 port1 (vlan 1)-> port 2 (vlan 1)
881 """
882 delete_all_flows(self.controller)
883 delete_all_groups(self.controller)
884
885 if len(config["port_map"]) <2:
886 logging.info("Port count less than 2, can't run this case")
887 return
888
889 vlan_id =1
890 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
891 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
892 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
893 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
894 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
895 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
896 src_ip=0xc0a80101
897 src_ip_str="192.168.1.1"
898 dst_ip=0xe0010101
899 dst_ip_str="224.1.1.1"
900
901 port1=config["port_map"].keys()[0]
902 port2=config["port_map"].keys()[1]
macauleyc8edafa2015-07-30 14:26:18 +0800903
macauley76cc8d22015-07-27 17:40:36 +0800904
905 #add l2 interface group
906 l2_intf_group_list=[]
macauleyc8edafa2015-07-30 14:26:18 +0800907 for port in config["port_map"].keys():
908 if port != port1 and port !=port2:
909 continue
macauley76cc8d22015-07-27 17:40:36 +0800910 l2_intf_gid, msg=add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
911 l2_intf_group_list.append(l2_intf_gid)
912 #add vlan flow table
913 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
914
915 #add termination flow
916 add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
917
918 #add l3 interface group
919 mcat_group_msg=add_l3_mcast_group(self.controller, vlan_id, 2, l2_intf_group_list)
920 add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip, mcat_group_msg.group_id)
921
922 parsed_pkt = simple_udp_packet(pktlen=100,
923 eth_dst=dst_mac_str,
924 eth_src=port1_mac_str,
925 ip_ttl=64,
926 ip_src=src_ip_str,
927 ip_dst=dst_ip_str)
928 pkt=str(parsed_pkt)
929 self.dataplane.send(port1, pkt)
930 verify_packet(self, pkt, port2)
931 verify_no_other_packets(self)
932
933
934