blob: 172b094599187a97226e2bad587d760558e9072c [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
Roman Bubyr8c385572019-04-25 11:45:13 +0300237 remove_onos_xconnect(self, datapathid, vlan_id101)
238 time.sleep(3)
239 logging.info("End of Test")
240
241
242class FabricSW_OP_TC_0020(base_tests.SimpleDataPlane):
243 """
244 To verify control channels are re-established and flows are re-configuration after of-agent restart.
245 """
246 controller_port = controller_port
247 onos_port = onos_port
248 switch_user = switch_user
249 switch_passwd = switch_passwd
250 switch_ip = switch_ip
251 controller_ip = controller_ip
252 onos_server_ip = onos_server_ip
253 onos_user = onos_user
254 onos_passwd = onos_passwd
255
256 def runTest(self):
257 groups = Queue.LifoQueue()
258 global req_onos
259 vlan_id101 = 101
260 try:
261 datapathid = get_datapathid(self)
262
263 if len( config[ "port_map" ] ) < 2:
264 logging.info( "Port count less than 2, can't run this case" )
265 assert False, "Port count less than 2, can't run this case"
266 return
267
268 if req_onos == "no":
269 req_onos = "yes"
270 ofagent_reconfig(self, arg="yes")
271 ofagent_restart(self)
272 time.sleep(60)
273
274 ports = (config["port_map"].keys())
275 # Create flows between two pairs of ports
276 add_onos_xconnect(self, datapathid, vlan_id101, ports[0], ports[1])
277 time.sleep(2)
278
279 # Agent restart
280 ofagent_restart(self)
281 time.sleep(90)
282
283 # Send VLAN 101 to port1 and verify packet on port2
284 transmit_and_verify_packets(self, vlan_id101, 1, 2, True)
285
286 # Send VLAN 101 to port2 and verify packet on port1
287 transmit_and_verify_packets(self, vlan_id101, 2, 1, True)
288
289 finally:
290 # Remove vlan-cross connection
291 remove_onos_xconnect(self, datapathid, vlan_id101)
292 time.sleep(3)
293 logging.info("End of Test")
294
295
296class FabricSW_OP_TC_0025(base_tests.SimpleDataPlane):
297 """
298 To verify packet forwarding when ports associated with L2 Interface groups are flapped physically.
299 """
300 controller_port = controller_port
301 onos_port = onos_port
302 switch_user = switch_user
303 switch_passwd = switch_passwd
304 switch_ip = switch_ip
305 controller_ip = controller_ip
306 onos_server_ip = onos_server_ip
307 onos_user = onos_user
308 onos_passwd = onos_passwd
309
310 def runTest(self):
311 groups = Queue.LifoQueue()
312 global req_onos
313 try:
314 if len( config[ "port_map" ] ) < 2:
315 logging.info( "Port count less than 2, can't run this case" )
316 assert False, "Port count less than 2, can't run this case"
317 return
318
319 if req_onos == "yes":
320 req_onos = "no"
321 ofagent_reconfig(self, arg="no")
322 ofagent_restart(self)
323 time.sleep(90)
324
325 vlan_id101 = 101
326 vlan_id201 = 201
327 ports = (config["port_map"].keys())
328
329 # Create flows between two pairs of ports
330 create_flows(self, groups, vlan_id101, 1, 2)
331
332 logging.info("Simulate plug-out and Plug-in the physical cable on port1 (through bcm port state commands)")
333 switch_port_enable(self, ports[0], False)
334 time.sleep(2)
335 switch_port_enable(self, ports[0], True)
336 time.sleep(5)
337
338 # Send VLAN 101 to port1 and verify packet on port2
339 transmit_and_verify_packets(self, vlan_id101, 1, 2, True)
340
341 # Send VLAN 101 to port2 and verify packet on port1
342 transmit_and_verify_packets(self, vlan_id101, 2, 1, True)
343
344 # Send VLAN 201 to port1 and verify no packet on port2
345 transmit_and_verify_packets(self, vlan_id201, 1, 2, False)
346
347 finally:
348 delete_all_flows(self.controller)
349 delete_groups(self.controller, groups)
350 delete_all_groups(self.controller)
351 logging.info("End of Test")
352
353
354class FabricSW_OP_TC_0030(base_tests.SimpleDataPlane):
355 """
356 To verify switch owners the flow rules when vlan-cross-connect pair is configured on operationally down interface and then interfaces are enabled.
357 """
358 controller_port = controller_port
359 onos_port = onos_port
360 switch_user = switch_user
361 switch_passwd = switch_passwd
362 switch_ip = switch_ip
363 controller_ip = controller_ip
364 onos_server_ip = onos_server_ip
365 onos_user = onos_user
366 onos_passwd = onos_passwd
367
368 def runTest(self):
369 groups = Queue.LifoQueue()
370 global req_onos
371 try:
372 if len( config[ "port_map" ] ) < 2:
373 logging.info( "Port count less than 2, can't run this case" )
374 assert False, "Port count less than 2, can't run this case"
375 return
376
377 if req_onos == "yes":
378 req_onos = "no"
379 ofagent_reconfig(self, arg="no")
380 ofagent_restart(self)
381 time.sleep(60)
382
383 ports = (config["port_map"].keys())
384 vlan_id101 = 101
385 vlan_id201 = 201
386
387 logging.info("Plug-out the physical cable on port1 (through bcm port state commands)")
388 switch_port_enable(self, ports[0], False)
389 time.sleep(2)
390
391 # Create flows between two pairs of ports
392 create_flows(self, groups, vlan_id101, 1, 2)
393
394 logging.info("Plug-in the physical cable on port1 (through bcm port state commands)")
395 switch_port_enable(self, ports[0], True)
396 time.sleep(5)
397
398 # Send VLAN 101 to port2 and verify packet on port1
399 transmit_and_verify_packets(self, vlan_id101, 2, 1, True)
400
401 # Send VLAN 101 to port1 and verify packet on port2
402 transmit_and_verify_packets(self, vlan_id101, 1, 2, True)
403
404 # Send VLAN 201 to port1 and verify no packet on port2
405 transmit_and_verify_packets(self, vlan_id201, 1, 2, False)
406
407 finally:
408 delete_all_flows(self.controller)
409 delete_groups(self.controller, groups)
410 delete_all_groups(self.controller)
411 logging.info("End of Test")
412
413
414class FabricSW_OP_TC_0035(base_tests.SimpleDataPlane):
415 """
416 To verify flows are successfully modified when ports associated with vlan-cross-connect pair is changed.
417 """
418 controller_port = controller_port
419 onos_port = onos_port
420 switch_user = switch_user
421 switch_passwd = switch_passwd
422 switch_ip = switch_ip
423 controller_ip = controller_ip
424 onos_server_ip = onos_server_ip
425 onos_user = onos_user
426 onos_passwd = onos_passwd
427
428 def runTest(self):
429 groups = Queue.LifoQueue()
430 global req_onos
431 vlan_id101 = 101
432 try:
433 datapathid = get_datapathid(self)
434 if len( config[ "port_map" ] ) < 3:
435 logging.info( "Port count less than 3, can't run this case" )
436 assert False, "Port count less than 3, can't run this case"
437 return
438
439 if req_onos == "no":
440 req_onos = "yes"
441 ofagent_reconfig(self, arg="yes")
442
443 ofagent_restart(self)
444 time.sleep(90)
445
446 ports = (config["port_map"].keys())
447
448 # Create flows between two pairs of ports
449 add_onos_xconnect(self, datapathid, vlan_id101, ports[0], ports[1])
450 time.sleep(10)
451
452 #Send VLAN 101 to port1 and verify packet on port2
453 transmit_and_verify_packets(self, vlan_id101, 1, 2, True)
454
455 #Send VLAN 101 to port2 and verify packet on port1
456 transmit_and_verify_packets(self, vlan_id101, 2, 1, True)
457
458 # Modify vlan-cross connect with port3 instead of port2
459 add_onos_xconnect(self, datapathid, vlan_id101, ports[0], ports[2])
460 time.sleep(10)
461 #
462 # #Send VLAN 101 to port1 and verify packet on port3
463 transmit_and_verify_packets(self, vlan_id101, 1, 3, True)
464 #
465 # #Send VLAN 101 to port3 and verify packet on port1
466 transmit_and_verify_packets(self, vlan_id101, 3, 1, True)
467 #
468 # #Send VLAN 101 to port2 and verify no packets on port1
469 transmit_and_verify_packets(self, vlan_id101, 2, 1, False)
470
471 finally:
472 #Remove vlan-cross connection
473 remove_onos_xconnect(self, datapathid, vlan_id101)
474 time.sleep(5)
475 logging.info("End of Test")
476
477
478class FabricSW_OP_TC_0040(base_tests.SimpleDataPlane):
479 """
480 To verify flows are removed when vlan-cross-connect pair is removed.
481 """
482
483 switch_user = switch_user
484 switch_passwd = switch_passwd
485 switch_ip = switch_ip
486 controller_ip = controller_ip
487 controller_port = controller_port
488 onos_server_ip = onos_server_ip
489 onos_port = onos_port
490 onos_user = onos_user
491 onos_passwd = onos_passwd
492
493 def runTest(self):
494 groups = Queue.LifoQueue()
495 global req_onos
496 vlan_id101 = 101
497 try:
498 datapathid = get_datapathid(self)
499
500 if len( config[ "port_map" ] ) < 2:
501 logging.info( "Port count less than 2, can't run this case" )
502 assert False, "Port count less than 2, can't run this case"
503 return
504
505 if req_onos == "no":
506 req_onos = "yes"
507 ofagent_reconfig(self, arg="yes")
508 ofagent_restart(self)
509 time.sleep(90)
510
511 ports = (config["port_map"].keys())
512
513 # Create flows between two pairs of ports
514 add_onos_xconnect(self, datapathid, vlan_id101, ports[0], ports[1])
515 time.sleep(10)
516
517 # Send VLAN 101 to port1 and verify packet on port2
518 transmit_and_verify_packets(self, vlan_id101, 1, 2, True)
519
520 # Send VLAN 101 to port2 and verify packet on port1
521 transmit_and_verify_packets(self, vlan_id101, 2, 1, True)
522
523 # Remove vlan-cross connection
524 remove_onos_xconnect(self, datapathid, vlan_id101)
525 time.sleep(10)
526
527 # Send VLAN 101 to port1 and verify packet on port2
528 transmit_and_verify_packets(self, vlan_id101, 1, 2, False)
529
530 # Send VLAN 101 to port2 and verify packet on port1
531 transmit_and_verify_packets(self, vlan_id101, 2, 1, False)
532
533 finally:
534 # Remove vlan-cross connection
535 remove_onos_xconnect(self, datapathid, vlan_id101)
536 logging.info("End of Test")
537
538
539def create_flows(self, groups, vid, port1, port2):
540 ports = (config["port_map"].keys())
541 pair = [ports[(port1-1)], ports[(port2-1)]]
542
543 for port in pair:
544 L2gid, l2msg = add_one_l2_interface_group(self.controller, port, vid, True, False)
545 add_one_vlan_table_flow(self.controller, port, vlan_id=vid, flag=VLAN_TABLE_FLAG_ONLY_TAG)
546 groups.put(L2gid)
547
548 msg = add_l2_flood_group(self.controller, pair, vid, vid)
549 groups.put(msg.group_id)
550 add_bridge_flow(self.controller, None, vid, msg.group_id, True)
551
552 logging.info(
553 "Add a flow to TABLE-60 to match vlan {} and action Send to Controller".format(vid))
554 add_acl_rule(self.controller, vlan_id=vid)
555
556 match = ofp.match()
557 match.oxm_list.append(ofp.oxm.vlan_vid(vid))
558
559
560def transmit_and_verify_packets(self, vid, port1, port2, recv):
561 # @parameters:
562 # vid - VLAN ID to create a flow
563 # port1 - a port where to send packets
564 # port2 - a port where to verify packets
565 # recv = True or False: True - we expect receive packets on port2; False - we don't expect recive packets on port2
566
567 ports = (config["port_map"].keys())
568 pair = [ports[(port1-1)], ports[(port2-1)]]
569
570 # verify flood
571 logging.info("Creating a double tagged vlan packet with outer vlan id {}".format(vid))
572 # change dest based on port number
573 mac_src = '00:12:34:56:78:%02X' % pair[0]
574 parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108, out_dl_vlan_enable=True,
575 out_vlan_vid=vid, in_dl_vlan_enable=True, in_vlan_vid=10,
576 eth_dst='00:12:34:56:78:9a', eth_src=mac_src)
577
578 pkt = str(parsed_pkt)
579 self.dataplane.send(pair[0], pkt)
580 # self won't rx packet
581 verify_no_packet(self, pkt, pair[0])
582 if recv == True:
583 # verify rx packet
584 tmp_ports = list(pair)
585 tmp_ports.remove(pair[0])
586 verify_packets(self, pkt, tmp_ports)
587 else:
588 #Verify the packet is not flooded
589 verify_no_packet(self, pkt, ports[(port2-1)])
590
591
592
593def port_admin(self, port, admin_state):
594 # @parameters:
595 # port - number of port to set admin state disable or enable
596 # admin_state for port = enable | disable
597
598 # Retrieve Port Configuration
599 logging.info("Sends Features Request and retrieve Port Configuration from reply")
600 (hw_addr, port_config, advert) = \
601 port_config_get(self.controller, port)
602 self.assertTrue(port_config is not None, "Did not get port config")
603
604 logging.debug("Admin state bit of port " + str(port) + " is now " +
605 str(port_config & ofp.OFPPC_PORT_DOWN))
606
607 # Modify Port Configuration
608 logging.info("Modify Port Configuration using Port Modification Message:OFPT_PORT_MOD")
609
610 if admin_state == "disable":
611
612 rv = port_config_set(self.controller, port,
613 port_config ^ ofp.OFPPC_PORT_DOWN, ofp.OFPPC_PORT_DOWN)
614 self.assertTrue(rv != -1, "Error sending port mod")
615 do_barrier(self.controller)
616
617 # Verify change took place with features request
618 logging.info("Verify the change")
619 (hw_addr, port_config2, advert) = port_config_get(self.controller, port)
620
621 logging.debug("Admin state bit " + str(port) + " is now " +
622 str(port_config2 & ofp.OFPPC_PORT_DOWN))
623 self.assertTrue(port_config2 is not None, "Did not get port config2")
624 self.assertTrue(port_config2 & ofp.OFPPC_PORT_DOWN !=
625 port_config & ofp.OFPPC_PORT_DOWN,
626 "Bit change did not take")
627
628 if admin_state == "enable":
629 rv = port_config_set(self.controller, port, port_config ^ ofp.OFPPC_PORT_DOWN, 0)
630 self.assertTrue(rv != -1, "Error sending port mod")
631 do_barrier(self.controller)
632
633 # Verify change took place with features request
634 logging.info("Verify the change")
635 (hw_addr, port_config2, advert) = port_config_get(self.controller, port)
636
637 logging.debug("Admin state bit " + str(port) + " is now " + str(port_config2 & ofp.OFPPC_PORT_DOWN))
638 self.assertTrue(port_config2 is not None, "Did not get port config2")
639 self.assertTrue(port_config2 & ofp.OFPPC_PORT_DOWN != port_config & ofp.OFPPC_PORT_DOWN, "Bit change did not take")
640
641
642def get_datapathid(self):
643 feature_reply = get_featureReplay(self)
644 str_datapath_id_f = "{:016x}".format(feature_reply.datapath_id)
645 return str_datapath_id_f