@@ -631,3 +631,234 @@ def setswitchmode(state, port):
631
631
if rc == False :
632
632
click .echo ("ERR: Unable to set switching mode one or more ports to {}" .format (state ))
633
633
sys .exit (CONFIG_FAIL )
634
+
635
+
636
+ def get_per_npu_statedb (per_npu_statedb , port_table_keys ):
637
+
638
+ # Getting all front asic namespace and correspding config and state DB connector
639
+
640
+ namespaces = multi_asic .get_front_end_namespaces ()
641
+ for namespace in namespaces :
642
+ asic_id = multi_asic .get_asic_index_from_namespace (namespace )
643
+ # replace these with correct macros
644
+ per_npu_statedb [asic_id ] = SonicV2Connector (use_unix_socket_path = True , namespace = namespace )
645
+ per_npu_statedb [asic_id ].connect (per_npu_statedb [asic_id ].STATE_DB )
646
+
647
+ port_table_keys [asic_id ] = per_npu_statedb [asic_id ].keys (
648
+ per_npu_statedb [asic_id ].STATE_DB , 'MUX_CABLE_TABLE|*' )
649
+
650
+
651
+ def get_physical_port_list (port ):
652
+
653
+ physical_port_list = []
654
+ if platform_sfputil is not None :
655
+ physical_port_list = platform_sfputil_helper .logical_port_name_to_physical_port_list (port )
656
+
657
+ asic_index = None
658
+ if platform_sfputil is not None :
659
+ asic_index = platform_sfputil_helper .get_asic_id_for_logical_port (port )
660
+ if asic_index is None :
661
+ # TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
662
+ # is fully mocked
663
+ import sonic_platform_base .sonic_sfp .sfputilhelper
664
+ asic_index = sonic_platform_base .sonic_sfp .sfputilhelper .SfpUtilHelper ().get_asic_id_for_logical_port (port )
665
+ if asic_index is None :
666
+ click .echo ("Got invalid asic index for port {}, cant retreive mux status" .format (port ))
667
+
668
+ if not isinstance (physical_port_list , list ):
669
+ click .echo (("ERR: Unable to locate physical port information for {}" .format (port )))
670
+ sys .exit (CONFIG_FAIL )
671
+
672
+ if len (physical_port_list ) != 1 :
673
+ click .echo ("ERR: Found multiple physical ports ({}) associated with {}" .format (
674
+ ", " .join (physical_port_list ), port ))
675
+ sys .exit (CONFIG_FAIL )
676
+
677
+ return (physical_port_list , asic_index )
678
+
679
+
680
+ def perform_download_firmware (physical_port , fwfile , port ):
681
+ import sonic_y_cable .y_cable
682
+ result = sonic_y_cable .y_cable .download_firmware (physical_port , fwfile )
683
+ if result == sonic_y_cable .y_cable .FIRMWARE_DOWNLOAD_SUCCESS :
684
+ click .echo ("firmware download successful {}" .format (port ))
685
+ return True
686
+ else :
687
+ click .echo ("firmware download failure {}" .format (port ))
688
+ return False
689
+
690
+
691
+ def perform_activate_firmware (physical_port , port ):
692
+ import sonic_y_cable .y_cable
693
+ result = sonic_y_cable .y_cable .activate_firmware (physical_port )
694
+ if result == sonic_y_cable .y_cable .FIRMWARE_ACTIVATE_SUCCESS :
695
+ click .echo ("firmware activate successful for {}" .format (port ))
696
+ return True
697
+ else :
698
+ click .echo ("firmware activate failure for {}" .format (port ))
699
+ return False
700
+
701
+
702
+ def perform_rollback_firmware (physical_port , port ):
703
+ import sonic_y_cable .y_cable
704
+ result = sonic_y_cable .y_cable .rollback_firmware (physical_port )
705
+ if result == sonic_y_cable .y_cable .FIRMWARE_ROLLBACK_SUCCESS :
706
+ click .echo ("firmware rollback successful {}" .format (port ))
707
+ return True
708
+ else :
709
+ click .echo ("firmware rollback failure {}" .format (port ))
710
+ return False
711
+
712
+
713
+ @muxcable .group (cls = clicommon .AbbreviationGroup )
714
+ def firmware ():
715
+ """Configure muxcable firmware command"""
716
+ pass
717
+
718
+
719
+ @firmware .command ()
720
+ @click .argument ('fwfile' , metavar = '<firmware_file>' , required = True )
721
+ @click .argument ('port' , metavar = '<port_name>' , required = True , default = None )
722
+ def download (fwfile , port ):
723
+ """Config muxcable firmware download"""
724
+
725
+ per_npu_statedb = {}
726
+ y_cable_asic_table_keys = {}
727
+ port_table_keys = {}
728
+
729
+ get_per_npu_statedb (per_npu_statedb , port_table_keys )
730
+
731
+ if port is not None and port != "all" :
732
+
733
+ physical_port_list = []
734
+ physical_port_list , asic_index = get_physical_port_list (port )
735
+ physical_port = physical_port_list [0 ]
736
+ if per_npu_statedb [asic_index ] is not None :
737
+ y_cable_asic_table_keys = port_table_keys [asic_index ]
738
+ logical_key = "MUX_CABLE_TABLE|{}" .format (port )
739
+ if logical_key in y_cable_asic_table_keys :
740
+ perform_download_firmware (physical_port , fwfile , port )
741
+
742
+ else :
743
+ click .echo ("this is not a valid port present on mux_cable" .format (port ))
744
+ sys .exit (CONFIG_FAIL )
745
+ else :
746
+ click .echo ("there is not a valid asic table for this asic_index" .format (asic_index ))
747
+ sys .exit (CONFIG_FAIL )
748
+
749
+ elif port == "all" and port is not None :
750
+
751
+ rc = CONFIG_SUCCESSFUL
752
+ for namespace in namespaces :
753
+ asic_id = multi_asic .get_asic_index_from_namespace (namespace )
754
+ for key in port_table_keys [asic_id ]:
755
+ port = key .split ("|" )[1 ]
756
+
757
+ physical_port_list = []
758
+ (physical_port_list , asic_index ) = get_physical_port_list (port )
759
+
760
+ physical_port = physical_port_list [0 ]
761
+
762
+ status = perform_download_firmware (physical_port , fwfile , port )
763
+
764
+ if status is not True :
765
+ rc = CONFIG_FAIL
766
+
767
+ sys .exit (rc )
768
+
769
+
770
+ @firmware .command ()
771
+ @click .argument ('port' , metavar = '<port_name>' , required = True , default = None )
772
+ def activate (port ):
773
+ """Config muxcable firmware activate"""
774
+
775
+ per_npu_statedb = {}
776
+ y_cable_asic_table_keys = {}
777
+ port_table_keys = {}
778
+
779
+ get_per_npu_statedb (per_npu_statedb , port_table_keys )
780
+
781
+ if port is not None and port != "all" :
782
+
783
+ physical_port_list = []
784
+ (physical_port_list , asic_index ) = get_physical_port_list (port )
785
+ physical_port = physical_port_list [0 ]
786
+ if per_npu_statedb [asic_index ] is not None :
787
+ y_cable_asic_table_keys = port_table_keys [asic_index ]
788
+ logical_key = "MUX_CABLE_TABLE|{}" .format (port )
789
+ if logical_key in y_cable_asic_table_keys :
790
+ perform_activate_firmware (physical_port , port )
791
+
792
+ else :
793
+ click .echo ("this is not a valid port present on mux_cable" .format (port ))
794
+ sys .exit (CONFIG_FAIL )
795
+ else :
796
+ click .echo ("there is not a valid asic table for this asic_index" .format (asic_index ))
797
+ sys .exit (CONFIG_FAIL )
798
+
799
+ elif port == "all" and port is not None :
800
+
801
+ rc = CONFIG_SUCCESSFUL
802
+ for namespace in namespaces :
803
+ asic_id = multi_asic .get_asic_index_from_namespace (namespace )
804
+ for key in port_table_keys [asic_id ]:
805
+ port = key .split ("|" )[1 ]
806
+
807
+ physical_port_list = []
808
+
809
+ (physical_port_list , asic_index ) = get_physical_port_list (port )
810
+ physical_port = physical_port_list [0 ]
811
+ status = perform_activate_firmware (physical_port , port )
812
+
813
+ if status is not True :
814
+ rc = CONFIG_FAIL
815
+
816
+ sys .exit (rc )
817
+
818
+
819
+ @firmware .command ()
820
+ @click .argument ('port' , metavar = '<port_name>' , required = True , default = None )
821
+ def rollback (port ):
822
+ """Config muxcable firmware rollback"""
823
+
824
+ port_table_keys = {}
825
+ y_cable_asic_table_keys = {}
826
+ per_npu_statedb = {}
827
+
828
+ get_per_npu_statedb (per_npu_statedb , port_table_keys )
829
+
830
+ if port is not None and port != "all" :
831
+
832
+ physical_port_list = []
833
+ (physical_port_list , asic_index ) = get_physical_port_list (port )
834
+ physical_port = physical_port_list [0 ]
835
+ if per_npu_statedb [asic_index ] is not None :
836
+ y_cable_asic_table_keys = port_table_keys [asic_index ]
837
+ logical_key = "MUX_CABLE_TABLE|{}" .format (port )
838
+ if logical_key in y_cable_asic_table_keys :
839
+ perform_rollback_firmware (physical_port , port )
840
+
841
+ else :
842
+ click .echo ("this is not a valid port present on mux_cable" .format (port ))
843
+ sys .exit (CONFIG_FAIL )
844
+ else :
845
+ click .echo ("there is not a valid asic table for this asic_index" .format (asic_index ))
846
+ sys .exit (CONFIG_FAIL )
847
+
848
+ elif port == "all" and port is not None :
849
+
850
+ rc = CONFIG_SUCCESSFUL
851
+ for namespace in namespaces :
852
+ asic_id = multi_asic .get_asic_index_from_namespace (namespace )
853
+ for key in port_table_keys [asic_id ]:
854
+ port = key .split ("|" )[1 ]
855
+
856
+ physical_port_list = []
857
+ (physical_port_list , asic_index ) = get_physical_port_list (port )
858
+ physical_port = physical_port_list [0 ]
859
+ status = perform_rollback_firmware (physical_port , port )
860
+
861
+ if status is not True :
862
+ rc = CONFIG_FAIL
863
+
864
+ sys .exit (rc )
0 commit comments