@@ -429,7 +429,7 @@ def state(state, port):
429
429
430
430
logical_port_list_per_port = logical_port_list_for_physical_port .get (physical_port , None )
431
431
432
- """ This check is required for checking whether or not this logical port is the one which is
432
+ """ This check is required for checking whether or not this logical port is the one which is
433
433
actually mapped to physical port and by convention it is always the first port.
434
434
TODO: this should be removed with more logic to check which logical port maps to actual physical port
435
435
being used"""
@@ -470,3 +470,164 @@ def state(state, port):
470
470
if rc == False :
471
471
click .echo ("ERR: Unable to toggle one or more ports to {}" .format (state ))
472
472
sys .exit (CONFIG_FAIL )
473
+
474
+
475
+ @hwmode .command ()
476
+ @click .argument ('state' , metavar = '<operation_status>' , required = True , type = click .Choice (["auto" , "manual" ]))
477
+ @click .argument ('port' , metavar = '<port_name>' , required = True , default = None )
478
+ def setswitchmode (state , port ):
479
+ """Configure the muxcable mux switching mode {auto/manual}"""
480
+
481
+ per_npu_statedb = {}
482
+ transceiver_dict = {}
483
+
484
+ # Getting all front asic namespace and correspding config and state DB connector
485
+
486
+ namespaces = multi_asic .get_front_end_namespaces ()
487
+ for namespace in namespaces :
488
+ asic_id = multi_asic .get_asic_index_from_namespace (namespace )
489
+ per_npu_statedb [asic_id ] = SonicV2Connector (use_unix_socket_path = False , namespace = namespace )
490
+ per_npu_statedb [asic_id ].connect (per_npu_statedb [asic_id ].STATE_DB )
491
+
492
+ if port is not None and port != "all" :
493
+ click .confirm (('Muxcable at port {} will be changed to {} switching mode. Continue?' .format (port , state )), abort = True )
494
+ logical_port_list = platform_sfputil_helper .get_logical_list ()
495
+ if port not in logical_port_list :
496
+ click .echo ("ERR: This is not a valid port, valid ports ({})" .format (", " .join (logical_port_list )))
497
+ sys .exit (CONFIG_FAIL )
498
+
499
+ asic_index = None
500
+ if platform_sfputil is not None :
501
+ asic_index = platform_sfputil_helper .get_asic_id_for_logical_port (port )
502
+ if asic_index is None :
503
+ # TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
504
+ # is fully mocked
505
+ import sonic_platform_base .sonic_sfp .sfputilhelper
506
+ asic_index = sonic_platform_base .sonic_sfp .sfputilhelper .SfpUtilHelper ().get_asic_id_for_logical_port (port )
507
+ if asic_index is None :
508
+ click .echo ("Got invalid asic index for port {}, cant retreive mux status" .format (port ))
509
+ sys .exit (CONFIG_FAIL )
510
+
511
+ if platform_sfputil is not None :
512
+ physical_port_list = platform_sfputil_helper .logical_port_name_to_physical_port_list (port )
513
+
514
+ if not isinstance (physical_port_list , list ):
515
+ click .echo (("ERR: Unable to locate physical port information for {}" .format (port )))
516
+ sys .exit (CONFIG_FAIL )
517
+ if len (physical_port_list ) != 1 :
518
+ click .echo ("ERR: Found multiple physical ports ({}) associated with {}" .format (
519
+ ", " .join (physical_port_list ), port ))
520
+ sys .exit (CONFIG_FAIL )
521
+
522
+ transceiver_dict [asic_index ] = per_npu_statedb [asic_index ].get_all (
523
+ per_npu_statedb [asic_index ].STATE_DB , 'TRANSCEIVER_INFO|{}' .format (port ))
524
+
525
+ vendor_value = get_value_for_key_in_dict (transceiver_dict [asic_index ], port , "manufacturer" , "TRANSCEIVER_INFO" )
526
+ model_value = get_value_for_key_in_dict (transceiver_dict [asic_index ], port , "model" , "TRANSCEIVER_INFO" )
527
+
528
+ """ This check is required for checking whether or not this port is connected to a Y cable
529
+ or not. The check gives a way to differentiate between non Y cable ports and Y cable ports.
530
+ TODO: this should be removed once their is support for multiple vendors on Y cable"""
531
+
532
+ if vendor_value != VENDOR_NAME or not re .match (VENDOR_MODEL_REGEX , model_value ):
533
+ click .echo ("ERR: Got invalid vendor value and model for port {}" .format (port ))
534
+ sys .exit (CONFIG_FAIL )
535
+
536
+ physical_port = physical_port_list [0 ]
537
+
538
+ logical_port_list_for_physical_port = platform_sfputil_helper .get_physical_to_logical ()
539
+
540
+ logical_port_list_per_port = logical_port_list_for_physical_port .get (physical_port , None )
541
+
542
+ """ This check is required for checking whether or not this logical port is the one which is
543
+ actually mapped to physical port and by convention it is always the first port.
544
+ TODO: this should be removed with more logic to check which logical port maps to actual physical port
545
+ being used"""
546
+
547
+ if port != logical_port_list_per_port [0 ]:
548
+ click .echo ("ERR: This logical Port {} is not on a muxcable" .format (port ))
549
+ sys .exit (CONFIG_FAIL )
550
+
551
+ if state == "auto" :
552
+ mode = sonic_y_cable .y_cable .SWITCHING_MODE_AUTO
553
+ elif state == "manual" :
554
+ mode = sonic_y_cable .y_cable .SWITCHING_MODE_MANUAL
555
+ import sonic_y_cable .y_cable
556
+ result = sonic_y_cable .y_cable .set_switching_mode (physical_port , mode )
557
+ if result == False :
558
+ click .echo (("ERR: Unable to set switching mode for the cable port {}" .format (port )))
559
+ sys .exit (CONFIG_FAIL )
560
+
561
+ click .echo ("Success in switching mode on port {} to {}" .format (port , state ))
562
+
563
+ elif port == "all" and port is not None :
564
+
565
+ click .confirm (('Muxcable at port {} will be changed to {} switching mode. Continue?' .format (port , state )), abort = True )
566
+ logical_port_list = platform_sfputil_helper .get_logical_list ()
567
+
568
+ rc = True
569
+ for port in logical_port_list :
570
+ if platform_sfputil is not None :
571
+ physical_port_list = platform_sfputil_helper .logical_port_name_to_physical_port_list (port )
572
+
573
+ asic_index = None
574
+ if platform_sfputil is not None :
575
+ asic_index = platform_sfputil_helper .get_asic_id_for_logical_port (port )
576
+ if asic_index is None :
577
+ # TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
578
+ # is fully mocked
579
+ import sonic_platform_base .sonic_sfp .sfputilhelper
580
+ asic_index = sonic_platform_base .sonic_sfp .sfputilhelper .SfpUtilHelper ().get_asic_id_for_logical_port (port )
581
+ if asic_index is None :
582
+ click .echo ("Got invalid asic index for port {}, cant retreive mux status" .format (port ))
583
+
584
+ if not isinstance (physical_port_list , list ):
585
+ click .echo (("ERR: Unable to locate physical port information for {}" .format (port )))
586
+ continue
587
+
588
+ if len (physical_port_list ) != 1 :
589
+ click .echo ("ERR: Found multiple physical ports ({}) associated with {}" .format (
590
+ ", " .join (physical_port_list ), port ))
591
+ continue
592
+
593
+ transceiver_dict [asic_index ] = per_npu_statedb [asic_index ].get_all (
594
+ per_npu_statedb [asic_index ].STATE_DB , 'TRANSCEIVER_INFO|{}' .format (port ))
595
+ vendor_value = transceiver_dict [asic_index ].get ("manufacturer" , None )
596
+ model_value = transceiver_dict [asic_index ].get ("model" , None )
597
+
598
+ """ This check is required for checking whether or not this port is connected to a Y cable
599
+ or not. The check gives a way to differentiate between non Y cable ports and Y cable ports.
600
+ TODO: this should be removed once their is support for multiple vendors on Y cable"""
601
+
602
+ if vendor_value != VENDOR_NAME or not re .match (VENDOR_MODEL_REGEX , model_value ):
603
+ continue
604
+
605
+ physical_port = physical_port_list [0 ]
606
+
607
+ logical_port_list_for_physical_port = platform_sfputil_helper .get_physical_to_logical ()
608
+
609
+ logical_port_list_per_port = logical_port_list_for_physical_port .get (physical_port , None )
610
+
611
+ """ This check is required for checking whether or not this logical port is the one which is
612
+ actually mapped to physical port and by convention it is always the first port.
613
+ TODO: this should be removed with more logic to check which logical port maps to actual physical port
614
+ being used"""
615
+
616
+ if port != logical_port_list_per_port [0 ]:
617
+ continue
618
+
619
+ if state == "auto" :
620
+ mode = sonic_y_cable .y_cable .SWITCHING_MODE_AUTO
621
+ elif state == "manual" :
622
+ mode = sonic_y_cable .y_cable .SWITCHING_MODE_MANUAL
623
+ import sonic_y_cable .y_cable
624
+ result = sonic_y_cable .y_cable .set_switching_mode (physical_port , mode )
625
+ if result == False :
626
+ rc = False
627
+ click .echo ("ERR: Unable to set switching mode on port {} to {}" .format (port , state ))
628
+
629
+ click .echo ("Success in switching mode on port {} to {}" .format (port , state ))
630
+
631
+ if rc == False :
632
+ click .echo ("ERR: Unable to set switching mode one or more ports to {}" .format (state ))
633
+ sys .exit (CONFIG_FAIL )
0 commit comments