Beispiel #1
0
def packetloss(db, action, port):
    """config muxcable packetloss reset"""

    port = platform_sfputil_helper.get_interface_name(port, db)

    port_table_keys = {}
    mux_cable_table_keys = {}
    pck_loss_table_keys = {}
    per_npu_configdb = {}
    per_npu_statedb = {}

    # Getting all front asic namespace and correspding config and state DB connector

    namespaces = multi_asic.get_front_end_namespaces()
    for namespace in namespaces:
        asic_id = multi_asic.get_asic_index_from_namespace(namespace)
        # replace these with correct macros
        per_npu_configdb[asic_id] = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
        per_npu_configdb[asic_id].connect()
        per_npu_statedb[asic_id] = swsscommon.SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
        per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB)

        port_table_keys[asic_id] = per_npu_statedb[asic_id].keys(
            per_npu_statedb[asic_id].STATE_DB, 'LINK_PROBE_STATS|*')
        mux_cable_table_keys[asic_id] = per_npu_configdb[asic_id].get_table("MUX_CABLE").keys() # keys here are port names
    if port is not None and port != "all":

        asic_index = None
        if platform_sfputil is not None:
            asic_index = platform_sfputil.get_asic_id_for_logical_port(port)
        if asic_index is None:
            # TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
            # is fully mocked
            import sonic_platform_base.sonic_sfp.sfputilhelper
            asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper().get_asic_id_for_logical_port(port)
            if asic_index is None:
                click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port))
                sys.exit(CONFIG_FAIL)

        if per_npu_statedb[asic_index] is not None:
            pck_loss_table_keys = port_table_keys[asic_index]
            logical_key = "LINK_PROBE_STATS|{}".format(port)
            if logical_key in pck_loss_table_keys:
                update_configdb_pck_loss_data(per_npu_configdb[asic_index], port, "reset")
                sys.exit(CONFIG_SUCCESSFUL)
            else:
                click.echo("this is not a valid port present on pck_loss_stats".format(port))
                sys.exit(CONFIG_FAIL)
        else:
            click.echo("there is not a valid asic table for this asic_index".format(asic_index))
            sys.exit(CONFIG_FAIL)

    elif port == "all" and port is not None:

        for namespace in namespaces:
            asic_id = multi_asic.get_asic_index_from_namespace(namespace)
            for key in port_table_keys[asic_id]:
                logical_port = key.split("|")[1]
                if logical_port in mux_cable_table_keys[asic_id]:
                    update_configdb_pck_loss_data(per_npu_configdb[asic_id], logical_port, "reset")

        sys.exit(CONFIG_SUCCESSFUL)
def rollback(db, port, fwfile):
    """Config muxcable firmware rollback"""

    port = platform_sfputil_helper.get_interface_name(port, db)

    delete_all_keys_in_db_table("STATE_DB", "XCVRD_ROLL_FW_RSP")
    delete_all_keys_in_db_table("APPL_DB", "XCVRD_ROLL_FW_CMD")

    if port is not None and port != "all":

        res_dict = {}
        res_dict[0] = CONFIG_FAIL
        res_dict[1] = "unknown"
        res_dict = update_and_get_response_for_xcvr_cmd(
            "rollback_firmware", "status", "0", "XCVRD_ROLL_FW_CMD",
            "XCVRD_ROLL_FW_RSP", port, 60, fwfile)

        delete_all_keys_in_db_table("STATE_DB", "XCVRD_ROLL_FW_RSP")
        delete_all_keys_in_db_table("APPL_DB", "XCVRD_ROLL_FW_CMD")

        rc = res_dict[0]

        port = platform_sfputil_helper.get_interface_alias(port, db)

        if rc == 0:
            click.echo("Success in rollback firmware port {} fwfile {}".format(
                port, fwfile))
        else:
            click.echo(
                "ERR: Unable to rollback firmware port {} fwfile {}".format(
                    port, fwfile))
            sys.exit(CONFIG_FAIL)

    elif port == "all":

        logical_port_list = platform_sfputil_helper.get_logical_list()

        rc_exit = True

        for port in logical_port_list:

            if platform_sfputil is not None:
                physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list(
                    port)

            if not isinstance(physical_port_list, list):
                continue
            if len(physical_port_list) != 1:
                continue

            physical_port = physical_port_list[0]
            logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical(
            )

            logical_port_list_per_port = logical_port_list_for_physical_port.get(
                physical_port, None)
            """ This check is required for checking whether or not this logical port is the one which is
            actually mapped to physical port and by convention it is always the first port.
            TODO: this should be removed with more logic to check which logical port maps to actual physical port
            being used"""

            if port != logical_port_list_per_port[0]:
                continue

            res_dict = {}

            res_dict[0] = CONFIG_FAIL
            res_dict[1] = "unknown"
            res_dict = update_and_get_response_for_xcvr_cmd(
                "rollback_firmware", "status", "0", "XCVRD_ROLL_FW_CMD",
                "XCVRD_ROLL_FW_RSP", port, 60, fwfile)

            delete_all_keys_in_db_table("STATE_DB", "XCVRD_ROLL_FW_RSP")
            delete_all_keys_in_db_table("APPL_DB", "XCVRD_ROLL_FW_CMD")

            rc = res_dict[0]

            port = platform_sfputil_helper.get_interface_alias(port, db)

            if rc == 0:
                click.echo(
                    "Success in rollback firmware port {} fwfile {}".format(
                        port, fwfile))
            else:
                click.echo(
                    "ERR: Unable to rollback firmware port {} fwfile {}".
                    format(port, fwfile))
                rc_exit = CONFIG_FAIL

        sys.exit(rc_exit)
Beispiel #3
0
def mode(db, state, port, json_output):
    """Config muxcable mode"""

    port = platform_sfputil_helper.get_interface_name(port, db)

    port_table_keys = {}
    y_cable_asic_table_keys = {}
    per_npu_configdb = {}
    per_npu_statedb = {}
    mux_tbl_cfg_db = {}

    # Getting all front asic namespace and correspding config and state DB connector

    namespaces = multi_asic.get_front_end_namespaces()
    for namespace in namespaces:
        asic_id = multi_asic.get_asic_index_from_namespace(namespace)
        # replace these with correct macros
        per_npu_configdb[asic_id] = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
        per_npu_configdb[asic_id].connect()
        per_npu_statedb[asic_id] = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
        per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB)

        mux_tbl_cfg_db[asic_id] = per_npu_configdb[asic_id].get_table("MUX_CABLE")

        port_table_keys[asic_id] = per_npu_statedb[asic_id].keys(
            per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|*')

    if port is not None and port != "all":

        asic_index = None
        if platform_sfputil is not None:
            asic_index = platform_sfputil.get_asic_id_for_logical_port(port)
        if asic_index is None:
            # TODO this import is only for unit test purposes, and should be removed once sonic_platform_base
            # is fully mocked
            import sonic_platform_base.sonic_sfp.sfputilhelper
            asic_index = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper().get_asic_id_for_logical_port(port)
            if asic_index is None:
                click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port))
                sys.exit(CONFIG_FAIL)

        if per_npu_statedb[asic_index] is not None:
            y_cable_asic_table_keys = port_table_keys[asic_index]
            logical_key = "MUX_CABLE_TABLE|{}".format(port)
            if logical_key in y_cable_asic_table_keys:
                port_status_dict = {}
                lookup_statedb_and_update_configdb(
                    db, per_npu_statedb[asic_index], per_npu_configdb[asic_index], port, state, port_status_dict)

                if json_output:
                    click.echo("{}".format(json.dumps(port_status_dict, indent=4)))
                else:
                    headers = ['port', 'state']
                    data = sorted([(k, v) for k, v in port_status_dict.items()])
                    click.echo(tabulate(data, headers=headers))

                sys.exit(CONFIG_SUCCESSFUL)

            else:
                click.echo("this is not a valid port present on mux_cable".format(port))
                sys.exit(CONFIG_FAIL)
        else:
            click.echo("there is not a valid asic table for this asic_index".format(asic_index))
            sys.exit(CONFIG_FAIL)

    elif port == "all" and port is not None:

        port_status_dict = {}
        for namespace in namespaces:
            asic_id = multi_asic.get_asic_index_from_namespace(namespace)
            for key in port_table_keys[asic_id]:
                logical_port = key.split("|")[1]
                lookup_statedb_and_update_configdb(
                    db, per_npu_statedb[asic_id], per_npu_configdb[asic_id], logical_port, state, port_status_dict)

            if json_output:
                click.echo("{}".format(json.dumps(port_status_dict, indent=4)))
            else:
                data = sorted([(k, v) for k, v in port_status_dict.items()])

                headers = ['port', 'state']
                click.echo(tabulate(data, headers=headers))

        sys.exit(CONFIG_SUCCESSFUL)
def setswitchmode(db, state, port):
    """Configure the muxcable mux switching mode {auto/manual}"""

    port = platform_sfputil_helper.get_interface_name(port, db)

    delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_HWMODE_SWMODE_CMD")
    delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_HWMODE_SWMODE_RSP")

    if port is not None and port != "all":
        click.confirm((
            'Muxcable at port {} will be changed to {} switching mode. Continue?'
            .format(port, state)),
                      abort=True)

        res_dict = {}
        res_dict[0] = CONFIG_FAIL
        res_dict[1] = "unknown"
        res_dict = update_and_get_response_for_xcvr_cmd(
            "config", "result", "True", "XCVRD_CONFIG_HWMODE_SWMODE_CMD",
            "XCVRD_CONFIG_HWMODE_SWMODE_RSP", port, 1, state)

        rc = res_dict[0]

        delete_all_keys_in_db_table("APPL_DB",
                                    "XCVRD_CONFIG_HWMODE_SWMODE_CMD")
        delete_all_keys_in_db_table("STATE_DB",
                                    "XCVRD_CONFIG_HWMODE_SWMODE_RSP")

        port = platform_sfputil_helper.get_interface_alias(port, db)

        if rc == 0:
            click.echo("Success in switch muxcable mode port {} to {}".format(
                port, state))
        else:
            click.echo(
                "ERR: Unable to switch muxcable mode port {} to {}".format(
                    port, state))
            sys.exit(CONFIG_FAIL)

    elif port == "all":
        click.confirm((
            'Muxcable at all ports will be changed to {} switching mode. Continue?'
            .format(state)),
                      abort=True)

        logical_port_list = platform_sfputil_helper.get_logical_list()

        rc_exit = 0

        for port in logical_port_list:

            if platform_sfputil is not None:
                physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list(
                    port)

            if not isinstance(physical_port_list, list):
                continue
            if len(physical_port_list) != 1:
                continue

            physical_port = physical_port_list[0]
            logical_port_list_for_physical_port = platform_sfputil_helper.get_physical_to_logical(
            )

            logical_port_list_per_port = logical_port_list_for_physical_port.get(
                physical_port, None)
            """ This check is required for checking whether or not this logical port is the one which is
            actually mapped to physical port and by convention it is always the first port.
            TODO: this should be removed with more logic to check which logical port maps to actual physical port
            being used"""

            if port != logical_port_list_per_port[0]:
                continue

            res_dict = {}
            res_dict[0] = CONFIG_FAIL
            res_dict[1] = "unknown"
            res_dict = update_and_get_response_for_xcvr_cmd(
                "config", "result", "True", "XCVRD_CONFIG_HWMODE_SWMODE_CMD",
                "XCVRD_CONFIG_HWMODE_SWMODE_RSP", port, 1, state)

            rc = res_dict[0]

            delete_all_keys_in_db_table("APPL_DB",
                                        "XCVRD_CONFIG_HWMODE_SWMODE_CMD")
            delete_all_keys_in_db_table("STATE_DB",
                                        "XCVRD_CONFIG_HWMODE_SWMODE_RSP")

            port = platform_sfputil_helper.get_interface_alias(port, db)

            if rc == 0:
                click.echo("Success in toggling port {} to {}".format(
                    port, state))
            else:
                click.echo("ERR: Unable to toggle port {} to {}".format(
                    port, state))
                rc_exit = CONFIG_FAIL

        sys.exit(rc_exit)