blob: fe80d9e9cdbb356a44ebfe108e8ca3f1256cb963 [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
macauley76cc8d22015-07-27 17:40:36 +0800555class L3UcastECMP(base_tests.SimpleDataPlane):
556 """
557 Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
558 Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
559 """
macauley0c54d3f2015-07-17 18:10:03 +0800560 def runTest(self):
561 delete_all_flows(self.controller)
562 delete_all_groups(self.controller)
macauley76cc8d22015-07-27 17:40:36 +0800563
564 if len(config["port_map"]) <2:
565 logging.info("Port count less than 2, can't run this case")
566 return
macauley0c54d3f2015-07-17 18:10:03 +0800567
macauley76cc8d22015-07-27 17:40:36 +0800568 vlan_id=1
569 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
570 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
571 dip=0xc0a80001
572 for port in config["port_map"].keys():
573 #add l2 interface group
574 add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
575 dst_mac[5]=vlan_id
576 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
577 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [l3_msg.group_id])
578 #add vlan flow table
579 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
580 #add termination flow
581 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
582 #add unicast routing flow
583 dst_ip = dip + (vlan_id<<8)
584 #ECMP shall have prefix not 32
585 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id)
586 vlan_id += 1
587
588 do_barrier(self.controller)
589
590 port1=config["port_map"].keys()[0]
591 port2=config["port_map"].keys()[1]
592 #port 1 to port 2
593 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
594 dst_mac[5]=1
595 port1_mac=':'.join(['%02X' % x for x in dst_mac])
macauley52950382015-07-17 15:59:01 +0800596
macauley76cc8d22015-07-27 17:40:36 +0800597 parsed_pkt = simple_tcp_packet(pktlen=100,
598 eth_dst=switch_mac,
599 eth_src=port1_mac,
600 ip_ttl=64,
601 ip_src="192.168.1.1",
602 ip_dst='192.168.2.1')
603 pkt=str(parsed_pkt)
604 self.dataplane.send(port1, pkt)
605 #build expect packet
606 dst_mac[5]=2
607 port2_mac=':'.join(['%02X' % x for x in dst_mac])
608 exp_pkt = simple_tcp_packet(pktlen=100,
609 eth_dst=port2_mac,
610 eth_src=switch_mac,
611 ip_ttl=63,
612 ip_src="192.168.1.1",
613 ip_dst='192.168.2.1')
614 pkt=str(exp_pkt)
615 verify_packet(self, pkt, port2)
616 verify_no_other_packets(self)
macauley52950382015-07-17 15:59:01 +0800617
macauley76cc8d22015-07-27 17:40:36 +0800618 #port 2 to port 1
619 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
620 dst_mac[5]=2
621 port2_mac=':'.join(['%02X' % x for x in dst_mac])
622
623 parsed_pkt = simple_tcp_packet(pktlen=100,
624 eth_dst=switch_mac,
625 eth_src=port2_mac,
626 ip_ttl=64,
627 ip_src="192.168.2.1",
628 ip_dst='192.168.1.1')
629 pkt=str(parsed_pkt)
630 self.dataplane.send(port2, pkt)
631 #build expect packet
632 dst_mac[5]=1
633 port1_mac=':'.join(['%02X' % x for x in dst_mac])
634 exp_pkt = simple_tcp_packet(pktlen=100,
635 eth_dst=port1_mac,
636 eth_src=switch_mac,
637 ip_ttl=63,
638 ip_src="192.168.2.1",
639 ip_dst='192.168.1.1')
640 pkt=str(exp_pkt)
641 verify_packet(self, pkt, port1)
642 verify_no_other_packets(self)
macauleyc8edafa2015-07-30 14:26:18 +0800643
macauley76cc8d22015-07-27 17:40:36 +0800644class L3McastRoute1(base_tests.SimpleDataPlane):
645 """
646 Mcast routing, From VLAN 1 to VLAN 2
647 """
648 def runTest(self):
649 """
650 port1 (vlan 1)-> port 2 (vlan 2)
651 """
652 delete_all_flows(self.controller)
653 delete_all_groups(self.controller)
macauleyc8edafa2015-07-30 14:26:18 +0800654
655 if len(config["port_map"]) <3:
macauley76cc8d22015-07-27 17:40:36 +0800656 logging.info("Port count less than 2, can't run this case")
657 return
658
659 vlan_id =1
macauleyc8edafa2015-07-30 14:26:18 +0800660 port2_out_vlan=2
661 port3_out_vlan=3
macauley76cc8d22015-07-27 17:40:36 +0800662 in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan
663 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
664 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
665 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
666 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
667 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
668 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
669 src_ip=0xc0a80101
670 src_ip_str="192.168.1.1"
671 dst_ip=0xe0010101
672 dst_ip_str="224.1.1.1"
673
674 port1=config["port_map"].keys()[0]
675 port2=config["port_map"].keys()[1]
macauleyc8edafa2015-07-30 14:26:18 +0800676 port3=config["port_map"].keys()[2]
677
macauley76cc8d22015-07-27 17:40:36 +0800678 #add l2 interface group
679 for port in config["port_map"].keys():
680 add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
681 #add vlan flow table
682 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
683 vlan_id +=1
684
685 #add termination flow
686 add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
687
688 #add l3 interface group
macauleyc8edafa2015-07-30 14:26:18 +0800689 port2_ucast_msg=add_l3_interface_group(self.controller, port2, port2_out_vlan, 2, intf_src_mac)
690 port3_ucast_msg=add_l3_interface_group(self.controller, port3, port3_out_vlan, 3, intf_src_mac)
691 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 +0800692 add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id)
693
694 parsed_pkt = simple_udp_packet(pktlen=100,
695 eth_dst=dst_mac_str,
696 eth_src=port1_mac_str,
697 ip_ttl=64,
698 ip_src=src_ip_str,
699 ip_dst=dst_ip_str)
700 pkt=str(parsed_pkt)
701 self.dataplane.send(port1, pkt)
702 parsed_pkt = simple_udp_packet(pktlen=100,
703 eth_dst=dst_mac_str,
704 eth_src=intf_src_mac_str,
705 ip_ttl=63,
706 ip_src=src_ip_str,
707 ip_dst=dst_ip_str)
708 pkt=str(parsed_pkt)
709 verify_packet(self, pkt, port2)
macauleyc8edafa2015-07-30 14:26:18 +0800710 verify_packet(self, pkt, port3)
macauley76cc8d22015-07-27 17:40:36 +0800711 verify_no_other_packets(self)
712
macauley76cc8d22015-07-27 17:40:36 +0800713class L3McastRoute2(base_tests.SimpleDataPlane):
714 """
macauleyc8edafa2015-07-30 14:26:18 +0800715 Mcast routing, but on same vlan (l2mcast)
macauley76cc8d22015-07-27 17:40:36 +0800716 """
717 def runTest(self):
718 """
719 port1 (vlan 1)-> port 2 (vlan 1)
720 """
721 delete_all_flows(self.controller)
722 delete_all_groups(self.controller)
723
724 if len(config["port_map"]) <2:
725 logging.info("Port count less than 2, can't run this case")
726 return
727
728 vlan_id =1
729 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
730 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
731 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
732 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
733 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
734 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
735 src_ip=0xc0a80101
736 src_ip_str="192.168.1.1"
737 dst_ip=0xe0010101
738 dst_ip_str="224.1.1.1"
739
740 port1=config["port_map"].keys()[0]
741 port2=config["port_map"].keys()[1]
macauleyc8edafa2015-07-30 14:26:18 +0800742
macauley76cc8d22015-07-27 17:40:36 +0800743
744 #add l2 interface group
745 l2_intf_group_list=[]
macauleyc8edafa2015-07-30 14:26:18 +0800746 for port in config["port_map"].keys():
747 if port != port1 and port !=port2:
748 continue
macauley76cc8d22015-07-27 17:40:36 +0800749 l2_intf_gid, msg=add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
750 l2_intf_group_list.append(l2_intf_gid)
751 #add vlan flow table
752 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
753
754 #add termination flow
755 add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
756
757 #add l3 interface group
758 mcat_group_msg=add_l3_mcast_group(self.controller, vlan_id, 2, l2_intf_group_list)
759 add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip, mcat_group_msg.group_id)
760
761 parsed_pkt = simple_udp_packet(pktlen=100,
762 eth_dst=dst_mac_str,
763 eth_src=port1_mac_str,
764 ip_ttl=64,
765 ip_src=src_ip_str,
766 ip_dst=dst_ip_str)
767 pkt=str(parsed_pkt)
768 self.dataplane.send(port1, pkt)
769 verify_packet(self, pkt, port2)
770 verify_no_other_packets(self)
771
772
773