blob: 1bedd5a30cfdaa276e802c03f570b7f20e98f06a [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
Roman Bubyr8c385572019-04-25 11:45:13 +030016
17"""
18Check README file
19"""
20import logging
21import os
22import time
23import json
24
25import Queue
26import ofp
27import oftest.base_tests as base_tests
28from accton_util import *
29from oftest import config
30from oftest.ofdpa_utils import *
31from oftest.testutils import *
32from oftest.utils import *
33
34#### Global variables ####
35req_onos = "no" # to identify weather a test case require ONOS controller or not; default value is "no" for all the test cases without ONOS server
36
37### Read config parameters from JSON file 'global_vars.json'
38ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
39with open(ROOT_DIR + '/' + 'global_vars.json') as f:
40 data = json.load(f)
41
42switch_ip = data['switch_ip']
43switch_user = data['switch_user']
44switch_passwd = data['switch_passwd']
45controller_ip = data['controller_ip']
46controller_port = data['controller_port']
47onos_server_ip = data['onos_server_ip']
48onos_user = data['onos_user']
49onos_passwd = data['onos_passwd']
50onos_port = data['onos_port']
51
52
53class FabricSW_OP_TC_0005(base_tests.SimpleDataPlane):
54 """
55 To verify packet flooding when ports associated with L2 Interface groups are flapped administratively (disable/enable) - single interface pair.
56 """
57 controller_port = controller_port
58 onos_port = onos_port
59 switch_user = switch_user
60 switch_passwd = switch_passwd
61 switch_ip = switch_ip
62 controller_ip = controller_ip
63 onos_server_ip = onos_server_ip
64 onos_user = onos_user
65 onos_passwd = onos_passwd
66
67 def runTest(self):
68 groups = Queue.LifoQueue()
69 vlan_id101 = 101
70 vlan_id201 = 201
71 global req_onos
72
73 try:
74 if len( config[ "port_map" ] ) < 2:
75 logging.info( "Port count less than 2, can't run this case" )
76 assert False, "Port count less than 2, can't run this case"
77 return
78
79 if req_onos == "yes":
80 req_onos = "no"
81 ofagent_reconfig(self, arg="no")
82 ofagent_restart(self)
83 time.sleep(90)
84
85 of_ports = config["port_map"].keys()
86
87 create_flows(self, groups, vlan_id101, 1, 2)
88 logging.info("Admin down interfaces")
89 port_admin(self, of_ports[0], admin_state="disable")
90 port_admin(self, of_ports[1], admin_state="disable")
91 time.sleep(2)
92 logging.info("Admin up interfaces")
93 port_admin(self, of_ports[0], admin_state="enable")
94 port_admin(self, of_ports[1], admin_state="enable")
95 time.sleep(7)
96
97 # Verify flood VLAN101 from port1 to port2
98 transmit_and_verify_packets(self, vlan_id101, 1, 2, True)
99 transmit_and_verify_packets(self, vlan_id201, 1, 2, False)
100
101 finally:
102 delete_all_flows(self.controller)
103 delete_groups(self.controller, groups)
104 delete_all_groups(self.controller)
105 logging.info("End of Test")
106
107
108class FabricSW_OP_TC_0010(base_tests.SimpleDataPlane):
109 """
110 To verify packet forwarding when ports associated with L2 Interface groups are flapped administratively (disable/enable) - multiple interface pairs.
111 """
112
113 controller_port = controller_port
114 onos_port = onos_port
115 switch_user = switch_user
116 switch_passwd = switch_passwd
117 switch_ip = switch_ip
118 controller_ip = controller_ip
119 onos_server_ip = onos_server_ip
120 onos_user = onos_user
121 onos_passwd = onos_passwd
122
123 def runTest(self):
124 groups = Queue.LifoQueue()
125 global req_onos
126 try:
127 if len( config[ "port_map" ] ) < 3:
128 logging.info("Port count less than 3, can't run this case")
129 assert False, "Port count less than 3, can't run this case"
130 return
131
132 if req_onos == "yes":
133 req_onos = "no"
134 ofagent_reconfig(self, arg="no")
135 ofagent_restart(self)
136 time.sleep(90)
137
138 ports = (config["port_map"].keys())
139 vlan_id101 = 101
140 vlan_id151 = 151
141
142 # Create flows between two pairs of ports
143 create_flows(self, groups, vlan_id101, 1, 2)
144 create_flows(self, groups, vlan_id151, 1, 3)
145
146 logging.info("Admin down interface " + str(ports[2]))
147 port_admin(self, ports[2], admin_state="disable")
148 time.sleep(5)
149
150 # Send VLAN 101 to port1 and verify packet on port2
151 transmit_and_verify_packets(self, vlan_id101, 1, 2, True)
152
153 # Send VLAN 101 to port2 and verify packet on port1
154 transmit_and_verify_packets(self, vlan_id101, 2, 1, True)
155
156 logging.info("Admin up interface " + str(ports[2]))
157 port_admin(self, ports[2], admin_state="enable")
158 time.sleep(7)
159
160 # Send VLAN 151 to port1 and verify packet on port3
161 transmit_and_verify_packets(self,vlan_id151, 1, 3, True)
162
163 # Send VLAN 151 to port3 and verify packet on port1
164 transmit_and_verify_packets(self, vlan_id151, 3, 1, True)
165
166 logging.info("Admin down interface " + str(ports[0]))
167 port_admin(self, ports[0], admin_state="disable")
168 time.sleep(3)
169
170 logging.info("Admin up interface " + str(ports[0]))
171 port_admin(self, ports[0], admin_state="enable")
172 time.sleep(5)
173
174 # Send VLAN 101 to port1 and verify packet on port2
175 transmit_and_verify_packets(self, vlan_id101, 2, 1, True)
176
177 # Send VLAN 151 to port1 and verify packet on port3
178 transmit_and_verify_packets(self, vlan_id151, 1, 3, True)
179
180 finally:
181 delete_all_flows(self.controller)
182 delete_groups(self.controller, groups)
183 delete_all_groups(self.controller)
184 logging.info("End of Test")
185
186
187class FabricSW_OP_TC_0015(base_tests.SimpleDataPlane):
188 """
189 To verify control channels are re-established and flows are re-configuration after fabric switch is rebooted.
190 """
191 controller_port = controller_port
192 onos_port = onos_port
193 switch_user = switch_user
194 switch_passwd = switch_passwd
195 switch_ip = switch_ip
196 controller_ip = controller_ip
197 onos_server_ip = onos_server_ip
198 onos_user = onos_user
199 onos_passwd = onos_passwd
200
201 def runTest(self):
202 groups = Queue.LifoQueue()
203 global req_onos
204 vlan_id101 = 101
205 try:
206 datapathid = get_datapathid(self)
207
208 if len( config[ "port_map" ] ) < 2:
209 logging.info( "Port count less than 2, can't run this case" )
210 assert False, "Port count less than 2, can't run this case"
211 return
212
213 if req_onos == "no":
214 req_onos = "yes"
215 ofagent_reconfig(self, arg="yes")
216 ofagent_restart(self)
217 time.sleep(90)
218
219 ports = (config["port_map"].keys())
220
221 # Create flows between two pairs of ports
222 add_onos_xconnect(self, datapathid, vlan_id101, ports[0], ports[1])
223 time.sleep(10)
224
225 #Reboot switch
226 switch_restart(self)
227 time.sleep(120)
228
229 # Send VLAN 101 to port1 and verify packet on port2
230 transmit_and_verify_packets(self, vlan_id101, 1, 2, True)
231
232 # Send VLAN 101 to port2 and verify packet on port1
233 transmit_and_verify_packets(self, vlan_id101, 2, 1, True)
234
235 finally:
236 # Remove vlan-cross connection
237 # send_command_to_onos_cli(self.log_path, "clear_xconnection1", "sr-xconnect-remove of:" + datapathid + " " + str(vlan_id101),
238 # self.onos_server_ip, self.onos_user, self.onos_passwd, regexp='onos>')
239 remove_onos_xconnect(self, datapathid, vlan_id101)
240 time.sleep(3)
241 logging.info("End of Test")
242
243
244class FabricSW_OP_TC_0020(base_tests.SimpleDataPlane):
245 """
246 To verify control channels are re-established and flows are re-configuration after of-agent restart.
247 """
248 controller_port = controller_port
249 onos_port = onos_port
250 switch_user = switch_user
251 switch_passwd = switch_passwd
252 switch_ip = switch_ip
253 controller_ip = controller_ip
254 onos_server_ip = onos_server_ip
255 onos_user = onos_user
256 onos_passwd = onos_passwd
257
258 def runTest(self):
259 groups = Queue.LifoQueue()
260 global req_onos
261 vlan_id101 = 101
262 try:
263 datapathid = get_datapathid(self)
264
265 if len( config[ "port_map" ] ) < 2:
266 logging.info( "Port count less than 2, can't run this case" )
267 assert False, "Port count less than 2, can't run this case"
268 return
269
270 if req_onos == "no":
271 req_onos = "yes"
272 ofagent_reconfig(self, arg="yes")
273 ofagent_restart(self)
274 time.sleep(60)
275
276 ports = (config["port_map"].keys())
277 # Create flows between two pairs of ports
278 add_onos_xconnect(self, datapathid, vlan_id101, ports[0], ports[1])
279 time.sleep(2)
280
281 # Agent restart
282 ofagent_restart(self)
283 time.sleep(90)
284
285 # Send VLAN 101 to port1 and verify packet on port2
286 transmit_and_verify_packets(self, vlan_id101, 1, 2, True)
287
288 # Send VLAN 101 to port2 and verify packet on port1
289 transmit_and_verify_packets(self, vlan_id101, 2, 1, True)
290
291 finally:
292 # Remove vlan-cross connection
293 remove_onos_xconnect(self, datapathid, vlan_id101)
294 time.sleep(3)
295 logging.info("End of Test")
296
297
298class FabricSW_OP_TC_0025(base_tests.SimpleDataPlane):
299 """
300 To verify packet forwarding when ports associated with L2 Interface groups are flapped physically.
301 """
302 controller_port = controller_port
303 onos_port = onos_port
304 switch_user = switch_user
305 switch_passwd = switch_passwd
306 switch_ip = switch_ip
307 controller_ip = controller_ip
308 onos_server_ip = onos_server_ip
309 onos_user = onos_user
310 onos_passwd = onos_passwd
311
312 def runTest(self):
313 groups = Queue.LifoQueue()
314 global req_onos
315 try:
316 if len( config[ "port_map" ] ) < 2:
317 logging.info( "Port count less than 2, can't run this case" )
318 assert False, "Port count less than 2, can't run this case"
319 return
320
321 if req_onos == "yes":
322 req_onos = "no"
323 ofagent_reconfig(self, arg="no")
324 ofagent_restart(self)
325 time.sleep(90)
326
327 vlan_id101 = 101
328 vlan_id201 = 201
329 ports = (config["port_map"].keys())
330
331 # Create flows between two pairs of ports
332 create_flows(self, groups, vlan_id101, 1, 2)
333
334 logging.info("Simulate plug-out and Plug-in the physical cable on port1 (through bcm port state commands)")
335 switch_port_enable(self, ports[0], False)
336 time.sleep(2)
337 switch_port_enable(self, ports[0], True)
338 time.sleep(5)
339
340 # Send VLAN 101 to port1 and verify packet on port2
341 transmit_and_verify_packets(self, vlan_id101, 1, 2, True)
342
343 # Send VLAN 101 to port2 and verify packet on port1
344 transmit_and_verify_packets(self, vlan_id101, 2, 1, True)
345
346 # Send VLAN 201 to port1 and verify no packet on port2
347 transmit_and_verify_packets(self, vlan_id201, 1, 2, False)
348
349 finally:
350 delete_all_flows(self.controller)
351 delete_groups(self.controller, groups)
352 delete_all_groups(self.controller)
353 logging.info("End of Test")
354
355
356class FabricSW_OP_TC_0030(base_tests.SimpleDataPlane):
357 """
358 To verify switch owners the flow rules when vlan-cross-connect pair is configured on operationally down interface and then interfaces are enabled.
359 """
360 controller_port = controller_port
361 onos_port = onos_port
362 switch_user = switch_user
363 switch_passwd = switch_passwd
364 switch_ip = switch_ip
365 controller_ip = controller_ip
366 onos_server_ip = onos_server_ip
367 onos_user = onos_user
368 onos_passwd = onos_passwd
369
370 def runTest(self):
371 groups = Queue.LifoQueue()
372 global req_onos
373 try:
374 if len( config[ "port_map" ] ) < 2:
375 logging.info( "Port count less than 2, can't run this case" )
376 assert False, "Port count less than 2, can't run this case"
377 return
378
379 if req_onos == "yes":
380 req_onos = "no"
381 ofagent_reconfig(self, arg="no")
382 ofagent_restart(self)
383 time.sleep(60)
384
385 ports = (config["port_map"].keys())
386 vlan_id101 = 101
387 vlan_id201 = 201
388
389 logging.info("Plug-out the physical cable on port1 (through bcm port state commands)")
390 switch_port_enable(self, ports[0], False)
391 time.sleep(2)
392
393 # Create flows between two pairs of ports
394 create_flows(self, groups, vlan_id101, 1, 2)
395
396 logging.info("Plug-in the physical cable on port1 (through bcm port state commands)")
397 switch_port_enable(self, ports[0], True)
398 time.sleep(5)
399
400 # Send VLAN 101 to port2 and verify packet on port1
401 transmit_and_verify_packets(self, vlan_id101, 2, 1, True)
402
403 # Send VLAN 101 to port1 and verify packet on port2
404 transmit_and_verify_packets(self, vlan_id101, 1, 2, True)
405
406 # Send VLAN 201 to port1 and verify no packet on port2
407 transmit_and_verify_packets(self, vlan_id201, 1, 2, False)
408
409 finally:
410 delete_all_flows(self.controller)
411 delete_groups(self.controller, groups)
412 delete_all_groups(self.controller)
413 logging.info("End of Test")
414
415
416class FabricSW_OP_TC_0035(base_tests.SimpleDataPlane):
417 """
418 To verify flows are successfully modified when ports associated with vlan-cross-connect pair is changed.
419 """
420 controller_port = controller_port
421 onos_port = onos_port
422 switch_user = switch_user
423 switch_passwd = switch_passwd
424 switch_ip = switch_ip
425 controller_ip = controller_ip
426 onos_server_ip = onos_server_ip
427 onos_user = onos_user
428 onos_passwd = onos_passwd
429
430 def runTest(self):
431 groups = Queue.LifoQueue()
432 global req_onos
433 vlan_id101 = 101
434 try:
435 datapathid = get_datapathid(self)
436 if len( config[ "port_map" ] ) < 3:
437 logging.info( "Port count less than 3, can't run this case" )
438 assert False, "Port count less than 3, can't run this case"
439 return
440
441 if req_onos == "no":
442 req_onos = "yes"
443 ofagent_reconfig(self, arg="yes")
444
445 ofagent_restart(self)
446 time.sleep(90)
447
448 ports = (config["port_map"].keys())
449
450 # Create flows between two pairs of ports
451 add_onos_xconnect(self, datapathid, vlan_id101, ports[0], ports[1])
452 time.sleep(10)
453
454 #Send VLAN 101 to port1 and verify packet on port2
455 transmit_and_verify_packets(self, vlan_id101, 1, 2, True)
456
457 #Send VLAN 101 to port2 and verify packet on port1
458 transmit_and_verify_packets(self, vlan_id101, 2, 1, True)
459
460 # Modify vlan-cross connect with port3 instead of port2
461 add_onos_xconnect(self, datapathid, vlan_id101, ports[0], ports[2])
462 time.sleep(10)
463 #
464 # #Send VLAN 101 to port1 and verify packet on port3
465 transmit_and_verify_packets(self, vlan_id101, 1, 3, True)
466 #
467 # #Send VLAN 101 to port3 and verify packet on port1
468 transmit_and_verify_packets(self, vlan_id101, 3, 1, True)
469 #
470 # #Send VLAN 101 to port2 and verify no packets on port1
471 transmit_and_verify_packets(self, vlan_id101, 2, 1, False)
472
473 finally:
474 #Remove vlan-cross connection
475 remove_onos_xconnect(self, datapathid, vlan_id101)
476 time.sleep(5)
477 logging.info("End of Test")
478
479
480class FabricSW_OP_TC_0040(base_tests.SimpleDataPlane):
481 """
482 To verify flows are removed when vlan-cross-connect pair is removed.
483 """
484
485 switch_user = switch_user
486 switch_passwd = switch_passwd
487 switch_ip = switch_ip
488 controller_ip = controller_ip
489 controller_port = controller_port
490 onos_server_ip = onos_server_ip
491 onos_port = onos_port
492 onos_user = onos_user
493 onos_passwd = onos_passwd
494
495 def runTest(self):
496 groups = Queue.LifoQueue()
497 global req_onos
498 vlan_id101 = 101
499 try:
500 datapathid = get_datapathid(self)
501
502 if len( config[ "port_map" ] ) < 2:
503 logging.info( "Port count less than 2, can't run this case" )
504 assert False, "Port count less than 2, can't run this case"
505 return
506
507 if req_onos == "no":
508 req_onos = "yes"
509 ofagent_reconfig(self, arg="yes")
510 ofagent_restart(self)
511 time.sleep(90)
512
513 ports = (config["port_map"].keys())
514
515 # Create flows between two pairs of ports
516 add_onos_xconnect(self, datapathid, vlan_id101, ports[0], ports[1])
517 time.sleep(10)
518
519 # Send VLAN 101 to port1 and verify packet on port2
520 transmit_and_verify_packets(self, vlan_id101, 1, 2, True)
521
522 # Send VLAN 101 to port2 and verify packet on port1
523 transmit_and_verify_packets(self, vlan_id101, 2, 1, True)
524
525 # Remove vlan-cross connection
526 remove_onos_xconnect(self, datapathid, vlan_id101)
527 time.sleep(10)
528
529 # Send VLAN 101 to port1 and verify packet on port2
530 transmit_and_verify_packets(self, vlan_id101, 1, 2, False)
531
532 # Send VLAN 101 to port2 and verify packet on port1
533 transmit_and_verify_packets(self, vlan_id101, 2, 1, False)
534
535 finally:
536 # Remove vlan-cross connection
537 remove_onos_xconnect(self, datapathid, vlan_id101)
538 logging.info("End of Test")
539
540
541def create_flows(self, groups, vid, port1, port2):
542 ports = (config["port_map"].keys())
543 pair = [ports[(port1-1)], ports[(port2-1)]]
544
545 for port in pair:
546 L2gid, l2msg = add_one_l2_interface_group(self.controller, port, vid, True, False)
547 add_one_vlan_table_flow(self.controller, port, vlan_id=vid, flag=VLAN_TABLE_FLAG_ONLY_TAG)
548 groups.put(L2gid)
549
550 msg = add_l2_flood_group(self.controller, pair, vid, vid)
551 groups.put(msg.group_id)
552 add_bridge_flow(self.controller, None, vid, msg.group_id, True)
553
554 logging.info(
555 "Add a flow to TABLE-60 to match vlan {} and action Send to Controller".format(vid))
556 add_acl_rule(self.controller, vlan_id=vid)
557
558 match = ofp.match()
559 match.oxm_list.append(ofp.oxm.vlan_vid(vid))
560
561
562def transmit_and_verify_packets(self, vid, port1, port2, recv):
563 # @parameters:
564 # vid - VLAN ID to create a flow
565 # port1 - a port where to send packets
566 # port2 - a port where to verify packets
567 # recv = True or False: True - we expect receive packets on port2; False - we don't expect recive packets on port2
568
569 ports = (config["port_map"].keys())
570 pair = [ports[(port1-1)], ports[(port2-1)]]
571
572 # verify flood
573 logging.info("Creating a double tagged vlan packet with outer vlan id {}".format(vid))
574 # change dest based on port number
575 mac_src = '00:12:34:56:78:%02X' % pair[0]
576 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108, out_dl_vlan_enable=True,
577 out_vlan_vid=vid, in_dl_vlan_enable=True, in_vlan_vid=10,
578 eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
579
580 pkt = str(parsed_pkt)
581 self.dataplane.send(pair[0], pkt)
582 # self won't rx packet
583 verify_no_packet(self, pkt, pair[0])
584 if recv == True:
585 # verify rx packet
586 tmp_ports = list(pair)
587 tmp_ports.remove(pair[0])
588 verify_packets(self, pkt, tmp_ports)
589 else:
590 #Verify the packet is not flooded
591 verify_no_packet(self, pkt, ports[(port2-1)])
592
593
594
595def port_admin(self, port, admin_state):
596 # @parameters:
597 # port - number of port to set admin state disable or enable
598 # admin_state for port = enable | disable
599
600 # Retrieve Port Configuration
601 logging.info("Sends Features Request and retrieve Port Configuration from reply")
602 (hw_addr, port_config, advert) = \
603 port_config_get(self.controller, port)
604 self.assertTrue(port_config is not None, "Did not get port config")
605
606 logging.debug("Admin state bit of port " + str(port) + " is now " +
607 str(port_config & ofp.OFPPC_PORT_DOWN))
608
609 # Modify Port Configuration
610 logging.info("Modify Port Configuration using Port Modification Message:OFPT_PORT_MOD")
611
612 if admin_state == "disable":
613
614 rv = port_config_set(self.controller, port,
615 port_config ^ ofp.OFPPC_PORT_DOWN, ofp.OFPPC_PORT_DOWN)
616 self.assertTrue(rv != -1, "Error sending port mod")
617 do_barrier(self.controller)
618
619 # Verify change took place with features request
620 logging.info("Verify the change")
621 (hw_addr, port_config2, advert) = port_config_get(self.controller, port)
622
623 logging.debug("Admin state bit " + str(port) + " is now " +
624 str(port_config2 & ofp.OFPPC_PORT_DOWN))
625 self.assertTrue(port_config2 is not None, "Did not get port config2")
626 self.assertTrue(port_config2 & ofp.OFPPC_PORT_DOWN !=
627 port_config & ofp.OFPPC_PORT_DOWN,
628 "Bit change did not take")
629
630 if admin_state == "enable":
631 rv = port_config_set(self.controller, port, port_config ^ ofp.OFPPC_PORT_DOWN, 0)
632 self.assertTrue(rv != -1, "Error sending port mod")
633 do_barrier(self.controller)
634
635 # Verify change took place with features request
636 logging.info("Verify the change")
637 (hw_addr, port_config2, advert) = port_config_get(self.controller, port)
638
639 logging.debug("Admin state bit " + str(port) + " is now " + str(port_config2 & ofp.OFPPC_PORT_DOWN))
640 self.assertTrue(port_config2 is not None, "Did not get port config2")
641 self.assertTrue(port_config2 & ofp.OFPPC_PORT_DOWN != port_config & ofp.OFPPC_PORT_DOWN, "Bit change did not take")
642
643
644def get_datapathid(self):
645 feature_reply = get_featureReplay(self)
646 str_datapath_id_f = "{:016x}".format(feature_reply.datapath_id)
647 return str_datapath_id_f