blob: 348d8ab8631c5bc0b0493db59d29557324da3dec [file] [log] [blame]
Sreeju Sreedhare3fefd92019-04-02 15:57:15 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
17"""
18Flow Test
19
20Test each flow table can set entry, and packet rx correctly.
21"""
22
23import logging
24
25from oftest import config
26import oftest.base_tests as base_tests
27import ofp
28from oftest.testutils import *
29from accton_util import *
30
31class L2McastFlow(base_tests.SimpleDataPlane):
32 """
33 Test output function for an exact-match flow
34
35 Add some multicast flows
36 Then, for all ports, verifies that sending a matching packet
37 to a multicast match results in an output to all ports.
38 """
39 def runTest(self):
40 ports = sorted(config["port_map"].keys())
41
42 delete_all_flows(self.controller)
43 delete_all_groups(self.controller)
44
45 # table 10: vlan
46 # send to table 20
47 add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
48
49 # group table
50 # set up untag groups for each port
51 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, False)
52
53 # set up multicast group
54 add_l2_mcast_group(self.controller, config["port_map"].keys(), 1, 1)
55
56 test_macs = [[0x01, 0x00, 0x5e, 0x0f, 0xff, 0xff]]
57
58 for test_mac in test_macs:
59 group_id = encode_l2_mcast_group_id(1, 1)
60 add_bridge_flow(self.controller, test_mac, 1, group_id, True)
61
62 for test_mac in test_macs:
63 mactest = ':'.join(['%02X' % x for x in test_mac])
64
65 for in_port in ports:
66 # change dest based on port number
67 parsed_pkt = simple_tcp_packet(eth_dst=mactest)
68 pkt = str(parsed_pkt)
69 logging.info("OutputExact test, from port %d to mac %s", in_port, mactest)
70 self.dataplane.send(in_port, pkt)
71
72 for ofport in ports:
73 if ofport == in_port: #tx port won't rx packet, unless L3 mcast routing
74 continue
75 verify_packet(self, pkt, ofport)
76 verify_no_other_packets(self)
77
78class L2UnicastFlow(base_tests.SimpleDataPlane):
79 """
80 Test output function for an exact-match flow
81
82 For each port A, adds a flow directing matching packets to that port.
83 Then, for all other ports B != A, verifies that sending a matching packet
84 to B results in an output to A.
85 """
86 def runTest(self):
87 ports = sorted(config["port_map"].keys())
88
89 delete_all_flows(self.controller)
90 delete_all_groups(self.controller)
91 # table 10: vlan
92 # send to table 20
93 #add_vlan_table_flow(self.controller, config["port_map"].keys(),1)
94
95 # group table
96 # set up tag groups for each port
97 add_l2_interface_group(self.controller, config["port_map"].keys(), 1, True, 1)
98
99 for port in ports:
100 add_one_vlan_table_flow(self.controller, port, 1)
101 group_id = encode_l2_interface_group_id(1, port)
102 add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
103 do_barrier(self.controller)
104
105 for out_port in ports:
106 # change dest based on port number
107 mac_dst= '00:12:34:56:78:%02X' % out_port
108
109 for in_port in ports:
110 if in_port == out_port:
111 continue
112 # change source based on port number to avoid packet-ins from learning
113 mac_src= '00:12:34:56:79:%02X' % in_port
114 parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
115 pkt = str(parsed_pkt)
116 logging.info("OutputExact test, ports %d to %d", in_port, out_port)
117 self.dataplane.send(in_port, pkt)
118
119 for ofport in ports:
120 if ofport in [out_port]:
121 verify_packet(self, pkt, ofport)
122 else:
123 verify_no_packet(self, pkt, ofport)
124
125 verify_no_other_packets(self)
126
127class L2Flood(base_tests.SimpleDataPlane):
128 """
129 Test L2 unknown unicast flooding and broadcast flood
130 """
131 def runTest(self):
132 ports = sorted(config["port_map"].keys())
133
134 delete_all_flows(self.controller)
135 delete_all_groups(self.controller)
136 # table 10: vlan
137 # send to table 20
138 add_vlan_table_flow(self.controller, ports, 1)
139
140 # group table
141 # set up untag groups for each port
142 add_l2_interface_grouop(self.controller, ports, 1, False, 1)
143
144 input_port = ports.pop()
145 flood_ports= ports
146
147 #no fllod group create, veriy all drop
148 parsed_pkt = simple_tcp_packet(eth_dst='00:12:34:56:78:9a')
149 pkt = str(parsed_pkt)
150 self.dataplane.send(input_port, pkt)
151 verify_no_other_packets(self)
152 parsed_pkt = simple_tcp_packet(eth_dst='FF:FF:FF:FF:FF:FF')
153 pkt = str(parsed_pkt)
154 self.dataplane.send(input_port, pkt)
155 verify_no_other_packets(self)
156 #add flood groupo
157 msg=add_l2_flood_group(self.controller, flood_ports, 1, 1)
158 add_bridge_flow(self.controller, None, 1, msg.group_id, True)
159 #verify flood
160 parsed_pkt = simple_tcp_packet(eth_dst='00:12:34:56:78:9a')
161 pkt = str(parsed_pkt)
162 self.dataplane.send(input_port, pkt)
163 for ofport in flood_ports:
164 verify_packet(self, pkt, ofport)
165
166 verify_no_other_packets(self)
167
168 for ofport in flood_ports:
169 self.dataplane.send(ofport, pkt)
170 #self won't rx packet
171 verify_no_packet(self, pkt, ofport)
172 #others will rx packet
173 tmp_ports=[]
174 for tmp in flood_ports:
175 if tmp != ofport:
176 tmp_ports.append(tmp)
177 verify_packets(self, pkt, tmp_ports)
178
179 verify_no_other_packets(self)
180
181 parsed_pkt = simple_tcp_packet(eth_dst='FF:FF:FF:FF:FF:FF')
182 pkt = str(parsed_pkt)
183 self.dataplane.send(input_port, pkt)
184 for ofport in flood_ports:
185 verify_packet(self, pkt, ofport)
186
187class PacketInMiss(base_tests.SimpleDataPlane):
188 """
189 Test packet in function for a table-miss flow
190
191 Send a packet to each dataplane port and verify that a packet
192 in message is received from the controller for each
193
194 NOTE: Verify This case the oft option shall not use --switch-ip
195 """
196
197 def runTest(self):
198 delete_all_flows(self.controller)
199 delete_all_groups(self.controller)
200
201 parsed_pkt = simple_tcp_packet(pktlen=100)
202 parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
203 vlan_vid=0x1001, dl_vlan_enable=True)
204 pkt = str(parsed_pkt)
205 vlan_pkt = str(parsed_vlan_pkt)
206 # table 10: vlan
207 # send to table 20
208 add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
209
210 # group table
211 # set up untag groups for each port
212 add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, 1)
213
214 # create match
215 match = ofp.match()
216 match.oxm_list.append(ofp.oxm.vlan_vid(0x1001))
217 request = ofp.message.flow_add(
218 table_id=60,
219 cookie=42,
220 match=match,
221 instructions=[
222 ofp.instruction.apply_actions(
223 actions=[
224 ofp.action.output(
225 port=ofp.OFPP_CONTROLLER,
226 max_len=ofp.OFPCML_NO_BUFFER)]),
227 ],
228 buffer_id=ofp.OFP_NO_BUFFER,
229 priority=1)
230
231 logging.info("Inserting packet in flow to controller")
232 self.controller.message_send(request)
233 do_barrier(self.controller)
234
235 for of_port in config["port_map"].keys():
236 logging.info("PacketInMiss test, port %d", of_port)
237 self.dataplane.send(of_port, pkt)
238
239 #AOS current packet in will not have vlan tag
240 if config["cicada_poject"]:
241 verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
242 else:
243 verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
244
245 verify_no_other_packets(self)
246
247class PacketOut(base_tests.SimpleDataPlane):
248 """
249 Verify action Flood, ALL, in port
250 """
251
252 def runTest(self):
253 if config["cicada_poject"]:
254 pass
255
256 delete_all_flows(self.controller)
257 delete_all_groups(self.controller)
258
259 parsed_pkt = simple_tcp_packet(pktlen=100)
260 parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
261 vlan_vid=0x1002, dl_vlan_enable=True)
262
263 pkt = str(parsed_pkt)
264 vlan_pkt = str(parsed_vlan_pkt)
265
266
267 #packet out flood, untag packet
268 self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
269 buffer_id=ofp.OFP_NO_BUFFER,
270 actions=[ofp.action.output(
271 port=ofp.OFPP_FLOOD)],
272 data=pkt))
273
274 for of_port in config["port_map"].keys():
275 verify_packet(self, pkt, of_port)
276
277 verify_no_other_packets(self)
278
279 #packet out flood, tag packet, because it can't identify vlan has which port
280 #so we do as all action.
281 self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
282 buffer_id=ofp.OFP_NO_BUFFER,
283 actions=[ofp.action.output(
284 port=ofp.OFPP_FLOOD)],
285 data=vlan_pkt))
286
287 for of_port in config["port_map"].keys():
288 verify_packet(self, vlan_pkt, of_port)
289
290 verify_no_other_packets(self)
291
292 #packet out all
293 self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
294 buffer_id=ofp.OFP_NO_BUFFER,
295 actions=[ofp.action.output(
296 port=ofp.OFPP_FLOOD)],
297 data=pkt))
298
299 for of_port in config["port_map"].keys():
300 verify_packet(self, pkt, of_port)
301
302 verify_no_other_packets(self)
303
304 #packet out to in port
305 in_port = config["port_map"].keys()[0]
306 self.controller.message_send(ofp.message.packet_out(in_port=in_port,
307 buffer_id=ofp.OFP_NO_BUFFER,
308 actions=[ofp.action.output(
309 port=in_port)],
310 data=pkt))
311
312 verify_packet(self, pkt, in_port)
313 verify_no_other_packets(self)
314
315class L3UcastRoute(base_tests.SimpleDataPlane):
316 """
317 Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
318 Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
319 """
320 def runTest(self):
321 delete_all_flows(self.controller)
322 delete_all_groups(self.controller)
323
324 if len(config["port_map"]) <2:
325 logging.info("Port count less than 2, can't run this case")
326 return
327
328 vlan_id=1
329 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
330 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
331 dip=0xc0a80001
332 for port in config["port_map"].keys():
333 #add l2 interface group
334 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
335 dst_mac[5]=vlan_id
336 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
337 #add vlan flow table
338 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
339 #add termination flow
340 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
341 #add unicast routing flow
342 dst_ip = dip + (vlan_id<<8)
343 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
344 vlan_id += 1
345
346 do_barrier(self.controller)
347
348 port1=config["port_map"].keys()[0]
349 port2=config["port_map"].keys()[1]
350 #port 1 to port 2
351 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
352 dst_mac[5]=1
353 port1_mac=':'.join(['%02X' % x for x in dst_mac])
354
355 parsed_pkt = simple_tcp_packet(pktlen=100,
356 eth_dst=switch_mac,
357 eth_src=port1_mac,
358 ip_ttl=64,
359 ip_src="192.168.1.1",
360 ip_dst='192.168.2.1')
361 pkt=str(parsed_pkt)
362 self.dataplane.send(port1, pkt)
363 #build expect packet
364 dst_mac[5]=2
365 port2_mac=':'.join(['%02X' % x for x in dst_mac])
366 exp_pkt = simple_tcp_packet(pktlen=100,
367 eth_dst=port2_mac,
368 eth_src=switch_mac,
369 ip_ttl=63,
370 ip_src="192.168.1.1",
371 ip_dst='192.168.2.1')
372 pkt=str(exp_pkt)
373 verify_packet(self, pkt, port2)
374 verify_no_other_packets(self)
375
376 #port 2 to port 1
377 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
378 dst_mac[5]=2
379 port2_mac=':'.join(['%02X' % x for x in dst_mac])
380
381 parsed_pkt = simple_tcp_packet(pktlen=100,
382 eth_dst=switch_mac,
383 eth_src=port2_mac,
384 ip_ttl=64,
385 ip_src="192.168.2.1",
386 ip_dst='192.168.1.1')
387 pkt=str(parsed_pkt)
388 self.dataplane.send(port2, pkt)
389 #build expect packet
390 dst_mac[5]=1
391 port1_mac=':'.join(['%02X' % x for x in dst_mac])
392 exp_pkt = simple_tcp_packet(pktlen=100,
393 eth_dst=port1_mac,
394 eth_src=switch_mac,
395 ip_ttl=63,
396 ip_src="192.168.2.1",
397 ip_dst='192.168.1.1')
398 pkt=str(exp_pkt)
399 verify_packet(self, pkt, port1)
400 verify_no_other_packets(self)
401
402class L3UcastRouteOnSamVLANSamPort(base_tests.SimpleDataPlane):
403 """
404 Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
405 Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
406 """
407 def runTest(self):
408 delete_all_flows(self.controller)
409 delete_all_groups(self.controller)
410 port = config["port_map"].keys()[0]
411
412 vlan_id=1
413 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
414 port_mac1=[0x00, 0x00, 0x00, 0x22, 0x22, 0x01]
415 port_mac2=[0x00, 0x00, 0x00, 0x22, 0x22, 0x02]
416 port_ip1=0xc0a80101
417 port_ip1_str=convertIP4toStr(port_ip1)
418 port_ip2=0xc0a80201
419 port_ip2_str=convertIP4toStr(port_ip2)
420 #add l2 interface group
421 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
422 #add vlan flow table
423 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
424 #add termination flow
425 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
426
427 """192.168.1.1->192.168.2.1"""
428 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=1, src_mac=intf_src_mac, dst_mac=port_mac2)
429 add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id)
430 """192.168.1.1->192.168.2.1"""
431 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=2, src_mac=intf_src_mac, dst_mac=port_mac1)
432 add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id)
433
434 do_barrier(self.controller)
435
436 """send packet to verify"""
437 """192.168.1.1->192.168.2.1"""
438 switch_mac_str = convertMACtoStr(intf_src_mac)
439 port_mac1_str = convertMACtoStr(port_mac1)
440 port_mac2_str = convertMACtoStr(port_mac2)
441 ttl=64
442 #send packet
443 parsed_pkt = simple_tcp_packet(pktlen=100,
444 eth_dst=switch_mac_str,
445 eth_src=port_mac1_str,
446 ip_ttl=ttl,
447 ip_src=port_ip1_str,
448 ip_dst=port_ip2_str)
449 pkt=str(parsed_pkt)
450 self.dataplane.send(port, pkt)
451 #build expect packet
452 exp_pkt = simple_tcp_packet(pktlen=100,
453 eth_dst=port_mac2_str,
454 eth_src=switch_mac_str,
455 ip_ttl=(ttl-1),
456 ip_src=port_ip1_str,
457 ip_dst=port_ip2_str)
458 pkt=str(exp_pkt)
459 verify_packet(self, pkt, port)
460 verify_no_other_packets(self)
461
462 """192.168.2.1->192.168.1.1"""
463 parsed_pkt = simple_tcp_packet(pktlen=100,
464 eth_dst=switch_mac_str,
465 eth_src=port_mac2_str,
466 ip_ttl=ttl,
467 ip_src=port_ip2_str,
468 ip_dst=port_ip1_str)
469 pkt=str(parsed_pkt)
470 self.dataplane.send(port, pkt)
471 #build expect packet
472 exp_pkt = simple_tcp_packet(pktlen=100,
473 eth_dst=port_mac1_str,
474 eth_src=switch_mac_str,
475 ip_ttl=(ttl-1),
476 ip_src=port_ip2_str,
477 ip_dst=port_ip1_str)
478 pkt=str(exp_pkt)
479 verify_packet(self, pkt, port)
480 verify_no_other_packets(self)
481
482class L3UcastRouteOnDiffVLANSamPort(base_tests.SimpleDataPlane):
483 """
484 Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
485 Port1(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
486 """
487 def runTest(self):
488 delete_all_flows(self.controller)
489 delete_all_groups(self.controller)
490 port = config["port_map"].keys()[0]
491
492 port_vlan_id1=1
493 port_vlan_id2=2
494 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
495 port_mac1=[0x00, 0x00, 0x00, 0x22, 0x22, 0x01]
496 port_mac2=[0x00, 0x00, 0x00, 0x22, 0x22, 0x02]
497 port_ip1=0xc0a80101
498 port_ip1_str=convertIP4toStr(port_ip1)
499 port_ip2=0xc0a80201
500 port_ip2_str=convertIP4toStr(port_ip2)
501 #add l2 interface group
502 add_one_l2_interface_group(self.controller, port, vlan_id=port_vlan_id1, is_tagged=True, send_barrier=False)
503 add_one_l2_interface_group(self.controller, port, vlan_id=port_vlan_id2, is_tagged=True, send_barrier=False)
504 #add vlan flow table
505 add_one_vlan_table_flow(self.controller, port, port_vlan_id1, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
506 add_one_vlan_table_flow(self.controller, port, port_vlan_id2, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
507 #add termination flow
508 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, port_vlan_id1)
509 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, port_vlan_id2)
510
511 """192.168.1.1->192.168.2.1"""
512 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=port_vlan_id2, id=1, src_mac=intf_src_mac, dst_mac=port_mac2)
513 add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id)
514 """192.168.1.1->192.168.2.1"""
515 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=port_vlan_id1, id=2, src_mac=intf_src_mac, dst_mac=port_mac1)
516 add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id)
517
518 do_barrier(self.controller)
519
520 """send packet to verify"""
521 """192.168.1.1->192.168.2.1"""
522 switch_mac_str =convertMACtoStr(intf_src_mac)
523 port_mac1_str= convertMACtoStr(port_mac1)
524 port_mac2_str= convertMACtoStr(port_mac2)
525 ttl=64
526 #send packet
527 parsed_pkt = simple_tcp_packet(pktlen=100,
528 eth_dst=switch_mac_str,
529 eth_src=port_mac1_str,
530 dl_vlan_enable=True,
531 vlan_vid=port_vlan_id1,
532 ip_ttl=ttl,
533 ip_src=port_ip1_str,
534 ip_dst=port_ip2_str)
535 pkt=str(parsed_pkt)
536 self.dataplane.send(port, pkt)
537 #build expect packet
538 exp_pkt = simple_tcp_packet(pktlen=100,
539 eth_dst=port_mac2_str,
540 eth_src=switch_mac_str,
541 dl_vlan_enable=True,
542 vlan_vid=port_vlan_id2,
543 ip_ttl=(ttl-1),
544 ip_src=port_ip1_str,
545 ip_dst=port_ip2_str)
546 pkt=str(exp_pkt)
547 verify_packet(self, pkt, port)
548 verify_no_other_packets(self)
549
550 """192.168.2.1->192.168.1.1"""
551 switch_mac = convertMACtoStr(intf_src_mac)
552 port_mac2_str=convertMACtoStr(port_mac2)
553
554 parsed_pkt = simple_tcp_packet(pktlen=100,
555 eth_dst=switch_mac_str,
556 eth_src=port_mac2_str,
557 dl_vlan_enable=True,
558 vlan_vid=port_vlan_id2,
559 ip_ttl=ttl,
560 ip_src=port_ip2_str,
561 ip_dst=port_ip1_str)
562 pkt=str(parsed_pkt)
563 self.dataplane.send(port, pkt)
564 #build expect packet
565 exp_pkt = simple_tcp_packet(pktlen=100,
566 eth_dst=port_mac1_str,
567 eth_src=switch_mac_str,
568 dl_vlan_enable=True,
569 vlan_vid=port_vlan_id1,
570 ip_ttl=(ttl-1),
571 ip_src=port_ip2_str,
572 ip_dst=port_ip1_str)
573 pkt=str(exp_pkt)
574 verify_packet(self, pkt, port)
575 verify_no_other_packets(self)
576
577class L3UcastVrfRouteOnSamVLANSamPort(base_tests.SimpleDataPlane):
578 """
579 Port1(vlan1, VRF1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
580 Port1(vlan1, VRF1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
581 Port1(vlan2, VRF2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
582 Port1(vlan2, VRF2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
583
584 """
585 def runTest(self):
586 delete_all_flows(self.controller)
587 delete_all_groups(self.controller)
588 port = config["port_map"].keys()[0]
589
590 vrf1=1
591 vrf2=2
592 vrf1_vlan_id=1
593 vrf2_vlan_id=2
594 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
595 port_mac1=[0x00, 0x00, 0x00, 0x22, 0x22, 0x01]
596 port_mac2=[0x00, 0x00, 0x00, 0x22, 0x22, 0x02]
597 port_ip1=0xc0a80101
598 port_ip1_str=convertIP4toStr(port_ip1)
599 port_ip2=0xc0a80201
600 port_ip2_str=convertIP4toStr(port_ip2)
601 #add l2 interface group
602 add_one_l2_interface_group(self.controller, port, vlan_id=vrf1_vlan_id, is_tagged=True, send_barrier=False)
603 add_one_l2_interface_group(self.controller, port, vlan_id=vrf2_vlan_id, is_tagged=True, send_barrier=False)
604 #add vlan flow table
605 add_one_vlan_table_flow(self.controller, port, vrf1_vlan_id, vrf=vrf1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
606 add_one_vlan_table_flow(self.controller, port, vrf2_vlan_id, vrf=vrf2, flag=VLAN_TABLE_FLAG_ONLY_TAG)
607
608 #add termination flow
609 add_termination_flow(self.controller, 0, 0x0800, intf_src_mac, vrf1_vlan_id)
610 add_termination_flow(self.controller, 0, 0x0800, intf_src_mac, vrf2_vlan_id)
611
612 """192.168.1.1->192.168.2.1"""
613 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf1_vlan_id, id=1, src_mac=intf_src_mac, dst_mac=port_mac2)
614 add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id, vrf1)
615 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf2_vlan_id, id=2, src_mac=intf_src_mac, dst_mac=port_mac2)
616 add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id, vrf2)
617
618 """192.168.1.1->192.168.2.1"""
619 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf1_vlan_id, id=3, src_mac=intf_src_mac, dst_mac=port_mac1)
620 add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id, vrf1)
621 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf2_vlan_id, id=4, src_mac=intf_src_mac, dst_mac=port_mac1)
622 add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id, vrf2)
623
624 do_barrier(self.controller)
625
626 """send packet to verify on VRF vrf1"""
627 """192.168.1.1->192.168.2.1"""
628 switch_mac_str = convertMACtoStr(intf_src_mac)
629 port_mac1_str = convertMACtoStr(port_mac1)
630 port_mac2_str = convertMACtoStr(port_mac2)
631 ttl=64
632 #send packet
633 parsed_pkt = simple_tcp_packet(pktlen=100,
634 eth_dst=switch_mac_str,
635 eth_src=port_mac1_str,
636 dl_vlan_enable=True,
637 vlan_vid=vrf1_vlan_id,
638 ip_ttl=ttl,
639 ip_src=port_ip1_str,
640 ip_dst=port_ip2_str)
641 pkt=str(parsed_pkt)
642 self.dataplane.send(port, pkt)
643 #build expect packet
644 exp_pkt = simple_tcp_packet(pktlen=100,
645 eth_dst=port_mac2_str,
646 eth_src=switch_mac_str,
647 dl_vlan_enable=True,
648 vlan_vid=vrf1_vlan_id,
649 ip_ttl=(ttl-1),
650 ip_src=port_ip1_str,
651 ip_dst=port_ip2_str)
652 pkt=str(exp_pkt)
653 verify_packet(self, pkt, port)
654 verify_no_other_packets(self)
655
656 """192.168.2.1->192.168.1.1"""
657 parsed_pkt = simple_tcp_packet(pktlen=100,
658 eth_dst=switch_mac_str,
659 eth_src=port_mac2_str,
660 dl_vlan_enable=True,
661 vlan_vid=vrf1_vlan_id,
662 ip_ttl=ttl,
663 ip_src=port_ip2_str,
664 ip_dst=port_ip1_str)
665 pkt=str(parsed_pkt)
666 self.dataplane.send(port, pkt)
667 #build expect packet
668 exp_pkt = simple_tcp_packet(pktlen=100,
669 eth_dst=port_mac1_str,
670 eth_src=switch_mac_str,
671 dl_vlan_enable=True,
672 vlan_vid=vrf1_vlan_id,
673 ip_ttl=(ttl-1),
674 ip_src=port_ip2_str,
675 ip_dst=port_ip1_str)
676 pkt=str(exp_pkt)
677 verify_packet(self, pkt, port)
678 verify_no_other_packets(self)
679
680
681 """send packet to verify on VRF vrf2"""
682 """192.168.1.1->192.168.2.1"""
683 switch_mac_str = convertMACtoStr(intf_src_mac)
684 port_mac1_str = convertMACtoStr(port_mac1)
685 port_mac2_str = convertMACtoStr(port_mac2)
686 ttl=64
687 #send packet
688 parsed_pkt = simple_tcp_packet(pktlen=100,
689 eth_dst=switch_mac_str,
690 eth_src=port_mac1_str,
691 dl_vlan_enable=True,
692 vlan_vid=vrf2_vlan_id,
693 ip_ttl=ttl,
694 ip_src=port_ip1_str,
695 ip_dst=port_ip2_str)
696 pkt=str(parsed_pkt)
697 self.dataplane.send(port, pkt)
698 #build expect packet
699 exp_pkt = simple_tcp_packet(pktlen=100,
700 eth_dst=port_mac2_str,
701 eth_src=switch_mac_str,
702 dl_vlan_enable=True,
703 vlan_vid=vrf2_vlan_id,
704 ip_ttl=(ttl-1),
705 ip_src=port_ip1_str,
706 ip_dst=port_ip2_str)
707 pkt=str(exp_pkt)
708 verify_packet(self, pkt, port)
709 verify_no_other_packets(self)
710
711 """192.168.2.1->192.168.1.1"""
712 parsed_pkt = simple_tcp_packet(pktlen=100,
713 eth_dst=switch_mac_str,
714 eth_src=port_mac2_str,
715 dl_vlan_enable=True,
716 vlan_vid=vrf2_vlan_id,
717 ip_ttl=ttl,
718 ip_src=port_ip2_str,
719 ip_dst=port_ip1_str)
720 pkt=str(parsed_pkt)
721 self.dataplane.send(port, pkt)
722 #build expect packet
723 exp_pkt = simple_tcp_packet(pktlen=100,
724 eth_dst=port_mac1_str,
725 eth_src=switch_mac_str,
726 dl_vlan_enable=True,
727 vlan_vid=vrf2_vlan_id,
728 ip_ttl=(ttl-1),
729 ip_src=port_ip2_str,
730 ip_dst=port_ip1_str)
731 pkt=str(exp_pkt)
732 verify_packet(self, pkt, port)
733 verify_no_other_packets(self)
734
735
736
737
738class L3UcastECMP(base_tests.SimpleDataPlane):
739 """
740 Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
741 Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
742 """
743 def runTest(self):
744 delete_all_flows(self.controller)
745 delete_all_groups(self.controller)
746
747 if len(config["port_map"]) <2:
748 logging.info("Port count less than 2, can't run this case")
749 return
750
751 vlan_id=1
752 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
753 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
754 dip=0xc0a80001
755 for port in config["port_map"].keys():
756 #add l2 interface group
757 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
758 dst_mac[5]=vlan_id
759 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
760 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [l3_msg.group_id])
761 #add vlan flow table
762 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
763 #add termination flow
764 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
765 #add unicast routing flow
766 dst_ip = dip + (vlan_id<<8)
767 #ECMP shall have prefix not 32
768 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id)
769 vlan_id += 1
770
771 do_barrier(self.controller)
772
773 port1=config["port_map"].keys()[0]
774 port2=config["port_map"].keys()[1]
775 #port 1 to port 2
776 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
777 dst_mac[5]=1
778 port1_mac=':'.join(['%02X' % x for x in dst_mac])
779
780 parsed_pkt = simple_tcp_packet(pktlen=100,
781 eth_dst=switch_mac,
782 eth_src=port1_mac,
783 ip_ttl=64,
784 ip_src="192.168.1.1",
785 ip_dst='192.168.2.1')
786 pkt=str(parsed_pkt)
787 self.dataplane.send(port1, pkt)
788 #build expect packet
789 dst_mac[5]=2
790 port2_mac=':'.join(['%02X' % x for x in dst_mac])
791 exp_pkt = simple_tcp_packet(pktlen=100,
792 eth_dst=port2_mac,
793 eth_src=switch_mac,
794 ip_ttl=63,
795 ip_src="192.168.1.1",
796 ip_dst='192.168.2.1')
797 pkt=str(exp_pkt)
798 verify_packet(self, pkt, port2)
799 verify_no_other_packets(self)
800
801 #port 2 to port 1
802 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
803 dst_mac[5]=2
804 port2_mac=':'.join(['%02X' % x for x in dst_mac])
805
806 parsed_pkt = simple_tcp_packet(pktlen=100,
807 eth_dst=switch_mac,
808 eth_src=port2_mac,
809 ip_ttl=64,
810 ip_src="192.168.2.1",
811 ip_dst='192.168.1.1')
812 pkt=str(parsed_pkt)
813 self.dataplane.send(port2, pkt)
814 #build expect packet
815 dst_mac[5]=1
816 port1_mac=':'.join(['%02X' % x for x in dst_mac])
817 exp_pkt = simple_tcp_packet(pktlen=100,
818 eth_dst=port1_mac,
819 eth_src=switch_mac,
820 ip_ttl=63,
821 ip_src="192.168.2.1",
822 ip_dst='192.168.1.1')
823 pkt=str(exp_pkt)
824 verify_packet(self, pkt, port1)
825 verify_no_other_packets(self)
826
827
828class L3UcastECMP2(base_tests.SimpleDataPlane):
829 """
830 Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
831 Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
832 Portn(vlann, 0x00, 0x00, 0x00, 0x22, 0x22, 0x0n, 19.168.n.1)
833 """
834
835 def runTest(self):
836 delete_all_flows(self.controller)
837 delete_all_groups(self.controller)
838
839 if len(config["port_map"]) <3:
840 logging.info("Port count less than 3, can't run this case")
841 return
842
843 vlan_id=1
844 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
845 same_dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x22]
846
847 l3_ucast_gips=[]
848 tx_port = config["port_map"].keys()[0]
849 for port in config["port_map"].keys():
850 #add l2 interface group
851 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
852 if tx_port != port:
853 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=same_dst_mac)
854 l3_ucast_gips.append(l3_msg.group_id)
855 #add vlan flow table
856 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
857 #add termination flow
858 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
859 vlan_id += 1
860
861 tx_dip=0x0a0a0a0a
862 tx_sip=0x0b0a0a0a
863 ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, l3_ucast_gips)
864 #ECMP shall have prefix not 32
865 add_unicast_routing_flow(self.controller, 0x0800, tx_dip, 0xffffff00, ecmp_msg.group_id)
866
867 do_barrier(self.controller)
868
869 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
870 packet_src_mac="00:00:33:44:55:66"
871 #from unknown src ip to unknown dst ip, to verify ecmp
872 parsed_pkt = simple_tcp_packet(pktlen=100,
873 eth_dst=switch_mac,
874 eth_src=packet_src_mac,
875 ip_ttl=64,
876 ip_src=convertIP4toStr(tx_sip),
877 ip_dst=convertIP4toStr(tx_dip))
878 self.dataplane.send(tx_port, str(parsed_pkt))
879 #build expect packet
880 dst_mac=':'.join(['%02X' % x for x in same_dst_mac])
881 exp_pkt = simple_tcp_packet(pktlen=100,
882 eth_dst=dst_mac,
883 eth_src=switch_mac,
884 ip_ttl=63,
885 ip_src=convertIP4toStr(tx_sip),
886 ip_dst=convertIP4toStr(tx_dip))
887
888 verify_packet(self, exp_pkt, config["port_map"].keys()[2])
889 verify_no_other_packets(self)
890 tx_sip=tx_sip+0x01000000
891 #from unknown scr ip to unknown dst ip, to verify ecmp
892 parsed_pkt = simple_tcp_packet(pktlen=100,
893 eth_dst=switch_mac,
894 eth_src=packet_src_mac,
895 ip_ttl=64,
896 ip_src=convertIP4toStr(tx_sip),
897 ip_dst=convertIP4toStr(tx_dip))
898 self.dataplane.send(tx_port, str(parsed_pkt))
899 #build expect packet
900 dst_mac=':'.join(['%02X' % x for x in same_dst_mac])
901 exp_pkt = simple_tcp_packet(pktlen=100,
902 eth_dst=dst_mac,
903 eth_src=switch_mac,
904 ip_ttl=63,
905 ip_src=convertIP4toStr(tx_sip),
906 ip_dst=convertIP4toStr(tx_dip))
907
908 verify_packet(self, exp_pkt, config["port_map"].keys()[1])
909 verify_no_other_packets(self)
910
911class L3McastRoute1(base_tests.SimpleDataPlane):
912 """
913 Mcast routing, From VLAN 1 to VLAN 2
914 """
915 def runTest(self):
916 """
917 port1 (vlan 1)-> port 2 (vlan 2)
918 """
919 delete_all_flows(self.controller)
920 delete_all_groups(self.controller)
921
922 if len(config["port_map"]) <3:
923 logging.info("Port count less than 2, can't run this case")
924 return
925
926 vlan_id =1
927 port2_out_vlan=2
928 port3_out_vlan=3
929 in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan
930 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
931 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
932 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
933 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
934 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
935 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
936 src_ip=0xc0a80101
937 src_ip_str="192.168.1.1"
938 dst_ip=0xe0010101
939 dst_ip_str="224.1.1.1"
940
941 port1=config["port_map"].keys()[0]
942 port2=config["port_map"].keys()[1]
943 port3=config["port_map"].keys()[2]
944
945 #add l2 interface group
946 for port in config["port_map"].keys():
947 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
948 #add vlan flow table
949 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
950 vlan_id +=1
951
952 #add termination flow
953 add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
954
955 #add l3 interface group
956 port2_ucast_msg=add_l3_interface_group(self.controller, port2, port2_out_vlan, 2, intf_src_mac)
957 port3_ucast_msg=add_l3_interface_group(self.controller, port3, port3_out_vlan, 3, intf_src_mac)
958 mcat_group_msg=add_l3_mcast_group(self.controller, in_vlan, 2, [port2_ucast_msg.group_id, port3_ucast_msg.group_id])
959 add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id)
960
961 parsed_pkt = simple_udp_packet(pktlen=100,
962 eth_dst=dst_mac_str,
963 eth_src=port1_mac_str,
964 ip_ttl=64,
965 ip_src=src_ip_str,
966 ip_dst=dst_ip_str)
967 pkt=str(parsed_pkt)
968 self.dataplane.send(port1, pkt)
969 parsed_pkt = simple_udp_packet(pktlen=100,
970 eth_dst=dst_mac_str,
971 eth_src=intf_src_mac_str,
972 ip_ttl=63,
973 ip_src=src_ip_str,
974 ip_dst=dst_ip_str)
975 pkt=str(parsed_pkt)
976 verify_packet(self, pkt, port2)
977 verify_packet(self, pkt, port3)
978 verify_no_other_packets(self)
979
980class L3McastRoute2(base_tests.SimpleDataPlane):
981 """
982 Mcast routing, but on same vlan (l2mcast)
983 """
984 def runTest(self):
985 """
986 port1 (vlan 1)-> port 2 (vlan 1)
987 """
988 delete_all_flows(self.controller)
989 delete_all_groups(self.controller)
990
991 if len(config["port_map"]) <2:
992 logging.info("Port count less than 2, can't run this case")
993 return
994
995 vlan_id =1
996 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
997 intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
998 dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
999 dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
1000 port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
1001 port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
1002 src_ip=0xc0a80101
1003 src_ip_str="192.168.1.1"
1004 dst_ip=0xe0010101
1005 dst_ip_str="224.1.1.1"
1006
1007 port1=config["port_map"].keys()[0]
1008 port2=config["port_map"].keys()[1]
1009
1010
1011 #add l2 interface group
1012 l2_intf_group_list=[]
1013 for port in config["port_map"].keys():
1014 if port != port1 and port !=port2:
1015 continue
1016 l2_intf_gid, msg=add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
1017 l2_intf_group_list.append(l2_intf_gid)
1018 #add vlan flow table
1019 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
1020
1021 #add termination flow
1022 add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
1023
1024 #add l3 interface group
1025 mcat_group_msg=add_l3_mcast_group(self.controller, vlan_id, 2, l2_intf_group_list)
1026 add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip, mcat_group_msg.group_id)
1027
1028 parsed_pkt = simple_udp_packet(pktlen=100,
1029 eth_dst=dst_mac_str,
1030 eth_src=port1_mac_str,
1031 ip_ttl=64,
1032 ip_src=src_ip_str,
1033 ip_dst=dst_ip_str)
1034 pkt=str(parsed_pkt)
1035 self.dataplane.send(port1, pkt)
1036 verify_packet(self, pkt, port2)
1037 verify_no_other_packets(self)
1038
1039
1040