def lookup_statedb_and_update_configdb(db, per_npu_statedb, config_db, port, state_cfg_val, port_status_dict): muxcable_statedb_dict = per_npu_statedb.get_all( per_npu_statedb.STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port)) configdb_state = get_value_for_key_in_config_tbl(config_db, port, "state", "MUX_CABLE") ipv4_value = get_value_for_key_in_config_tbl(config_db, port, "server_ipv4", "MUX_CABLE") ipv6_value = get_value_for_key_in_config_tbl(config_db, port, "server_ipv6", "MUX_CABLE") state = get_value_for_key_in_dict(muxcable_statedb_dict, port, "state", "MUX_CABLE_TABLE") port_name = platform_sfputil_helper.get_interface_alias(port, db) if str(state_cfg_val) == str(configdb_state): port_status_dict[port_name] = 'OK' else: config_db.set_entry( "MUX_CABLE", port, { "state": state_cfg_val, "server_ipv4": ipv4_value, "server_ipv6": ipv6_value }) if (str(state_cfg_val) == 'active' and str(state) != 'active') or (str(state_cfg_val) == 'standby' and str(state) != 'standby'): port_status_dict[port_name] = 'INPROGRESS' else: port_status_dict[port_name] = 'OK'
def disable(db, port, target): """Disable loopback mode on a port""" port = platform_sfputil_helper.get_interface_name(port, db) delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD") delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD_ARG") delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_LOOP_RSP") if port is not None: click.confirm(('Muxcable at port {} will be changed to disable LOOP mode {} state; disable traffic Continue?'.format( port, target)), abort=True) res_dict = {} res_dict[0] = CONFIG_FAIL res_dict[1] = "unknown" param_dict = {} target = parse_target(target) param_dict["target"] = target res_dict = update_and_get_response_for_xcvr_cmd( "config_loop", "status", "True", "XCVRD_CONFIG_LOOP_CMD", "XCVRD_CONFIG_LOOP_CMD_ARG", "XCVRD_CONFIG_LOOP_RSP", port, 30, param_dict, "disable") rc = res_dict[0] delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD") delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_LOOP_CMD_ARG") delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_LOOP_RSP") port = platform_sfputil_helper.get_interface_alias(port, db) if rc == 0: click.echo("Success in disable LOOP mode port {} to {}".format(port, target)) else: click.echo("ERR: Unable to set disable LOOP mode port {} to {}".format(port, target)) sys.exit(CONFIG_FAIL)
def cableinfo(db, port): """Show muxcable cable information""" port = platform_sfputil_helper.get_interface_alias(port, db) 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): click.echo("ERR: Unable to get a port on muxcable port") sys.exit(EXIT_FAIL) if len(physical_port_list) != 1: click.echo("ERR: Unable to get a single port on muxcable") sys.exit(EXIT_FAIL) physical_port = physical_port_list[0] import sonic_y_cable.y_cable part_num = sonic_y_cable.y_cable.get_part_number(physical_port) if part_num == False or part_num == -1: click.echo("ERR: Unable to get cable info part number") sys.exit(EXIT_FAIL) vendor = sonic_y_cable.y_cable.get_vendor(physical_port) if vendor == False or vendor == -1: click.echo("ERR: Unable to get cable info vendor name") sys.exit(EXIT_FAIL) headers = ['Vendor', 'Model'] body = [[vendor, part_num]] click.echo(tabulate(body, headers=headers))
def reset(db, port, target): """reset a target on the cable NIC TORA TORB Local """ port = platform_sfputil_helper.get_interface_name(port, db) delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD") delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG") delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP") if port is not None: click.confirm(('Muxcable at port {} will be reset; CAUTION: disable traffic Continue?'.format(port)), abort=True) res_dict = {} res_dict[0] = CONFIG_FAIL res_dict[1] = "unknown" param_dict = {} target = parse_target(target) param_dict["target"] = target res_dict = update_and_get_response_for_xcvr_cmd( "config_prbs", "status", "True", "XCVRD_CONFIG_PRBS_CMD", "XCVRD_CONFIG_PRBS_CMD_ARG", "XCVRD_CONFIG_PRBS_RSP", port, 30, param_dict, "reset") rc = res_dict[0] delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD") delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG") delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP") port = platform_sfputil_helper.get_interface_alias(port, db) if rc == 0: click.echo("Success in reset port {}".format(port)) else: click.echo("ERR: Unable to reset port {}".format(port)) sys.exit(CONFIG_FAIL)
def create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict, muxcable_health_dict, asic_index, port): status_value = get_value_for_key_in_dict(muxcable_info_dict[asic_index], port, "state", "MUX_CABLE_TABLE") port_name = platform_sfputil_helper.get_interface_alias(port, db) port_status_dict["MUX_CABLE"][port_name] = {} port_status_dict["MUX_CABLE"][port_name]["STATUS"] = status_value health_value = get_value_for_key_in_dict(muxcable_health_dict[asic_index], port, "state", "MUX_LINKMGR_TABLE") port_status_dict["MUX_CABLE"][port_name]["HEALTH"] = health_value
def create_json_dump_per_port_config(db, port_status_dict, per_npu_configdb, asic_id, port): state_value = get_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "state", "MUX_CABLE") port_name = platform_sfputil_helper.get_interface_alias(port, db) port_status_dict["MUX_CABLE"]["PORTS"][port_name] = {"STATE": state_value} port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"] = {} ipv4_value = get_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "server_ipv4", "MUX_CABLE") port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"]["IPv4"] = ipv4_value ipv6_value = get_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "server_ipv6", "MUX_CABLE") port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"]["IPv6"] = ipv6_value
def create_table_dump_per_port_status(db, print_data, muxcable_info_dict, muxcable_health_dict, asic_index, port): print_port_data = [] status_value = get_value_for_key_in_dict(muxcable_info_dict[asic_index], port, "state", "MUX_CABLE_TABLE") #status_value = get_value_for_key_in_tbl(y_cable_asic_table, port, "status") health_value = get_value_for_key_in_dict(muxcable_health_dict[asic_index], port, "state", "MUX_LINKMGR_TABLE") port_name = platform_sfputil_helper.get_interface_alias(port, db) print_port_data.append(port_name) print_port_data.append(status_value) print_port_data.append(health_value) print_data.append(print_port_data)
def create_table_dump_per_port_config(db ,print_data, per_npu_configdb, asic_id, port): port_list = [] port_name = platform_sfputil_helper.get_interface_alias(port, db) port_list.append(port_name) state_value = get_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "state", "MUX_CABLE") port_list.append(state_value) ipv4_value = get_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "server_ipv4", "MUX_CABLE") port_list.append(ipv4_value) ipv6_value = get_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "server_ipv6", "MUX_CABLE") port_list.append(ipv6_value) print_data.append(port_list)
def download(db, fwfile, port): """Config muxcable firmware download""" port = platform_sfputil_helper.get_interface_alias(port, db) per_npu_statedb = {} y_cable_asic_table_keys = {} port_table_keys = {} get_per_npu_statedb(per_npu_statedb, port_table_keys) if port is not None and port != "all": physical_port_list = [] physical_port_list, asic_index = get_physical_port_list(port) physical_port = physical_port_list[0] 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: perform_download_firmware(physical_port, fwfile, port) 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: rc = CONFIG_SUCCESSFUL for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) for key in port_table_keys[asic_id]: port = key.split("|")[1] physical_port_list = [] (physical_port_list, asic_index) = get_physical_port_list(port) physical_port = physical_port_list[0] status = perform_download_firmware(physical_port, fwfile, port) if status is not True: rc = CONFIG_FAIL sys.exit(rc)
def version(db, port, active): """Show muxcable firmware version""" port = platform_sfputil_helper.get_interface_alias(port, db) delete_all_keys_in_db_table("APPL_DB", "XCVRD_DOWN_FW_CMD") delete_all_keys_in_db_table("STATE_DB", "XCVRD_DOWN_FW_RSP") delete_all_keys_in_db_table("APPL_DB", "XCVRD_SHOW_FW_CMD") delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_FW_RSP") delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_FW_RES") if port is not None: res_dict = {} mux_info_dict, mux_info_active_dict = {}, {} res_dict[0] = CONFIG_FAIL res_dict[1] = "unknown" mux_info_dict["version_nic_active"] = "N/A" mux_info_dict["version_nic_inactive"] = "N/A" mux_info_dict["version_nic_next"] = "N/A" mux_info_dict["version_peer_active"] = "N/A" mux_info_dict["version_peer_inactive"] = "N/A" mux_info_dict["version_peer_next"] = "N/A" mux_info_dict["version_self_active"] = "N/A" mux_info_dict["version_self_inactive"] = "N/A" mux_info_dict["version_self_next"] = "N/A" res_dict = update_and_get_response_for_xcvr_cmd( "firmware_version", "status", "True", "XCVRD_SHOW_FW_CMD", "XCVRD_SHOW_FW_RSP", port, 20, "probe") if res_dict[1] == "True": mux_info_dict = get_response_for_version(port, mux_info_dict) delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_FW_RSP") delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_FW_RES") if active is True: for key in mux_info_dict: if key.endswith("_active"): mux_info_active_dict[key] = mux_info_dict[key] click.echo("{}".format(json.dumps(mux_info_active_dict, indent=4))) else: click.echo("{}".format(json.dumps(mux_info_dict, indent=4))) else: click.echo( "Did not get a valid Port for mux firmware version".format(port)) sys.exit(CONFIG_FAIL)
def enable(db, port, target, mode_value, lane_mask, prbs_direction): """Enable PRBS mode on a port args port target mode_value lane_mask prbs_direction example sudo config mux prbs enable Ethernet48 0 3 3 0 """ port = platform_sfputil_helper.get_interface_name(port, db) delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD") delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG") delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP") if port is not None: click.confirm(('Muxcable at port {} will be changed to PRBS mode {} state; disable traffic Continue?'.format( port, mode_value)), abort=True) res_dict = {} res_dict[0] = CONFIG_FAIL res_dict[1] = "unknown" param_dict = {} target = parse_target(target) param_dict["target"] = target param_dict["mode_value"] = mode_value param_dict["lane_mask"] = lane_mask param_dict["direction"] = prbs_direction res_dict = update_and_get_response_for_xcvr_cmd( "config_prbs", "status", "True", "XCVRD_CONFIG_PRBS_CMD", "XCVRD_CONFIG_PRBS_CMD_ARG", "XCVRD_CONFIG_PRBS_RSP", port, 30, param_dict, "enable") rc = res_dict[0] port = platform_sfputil_helper.get_interface_alias(port, db) delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD") delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG") delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP") if rc == 0: click.echo("Success in PRBS mode port {} to {}".format(port, mode_value)) else: click.echo("ERR: Unable to set PRBS mode port {} to {}".format(port, mode_value)) sys.exit(CONFIG_FAIL)
def set_fec(db, port, target, mode): """Enable fec mode on a port args port <target> NIC TORA TORB LOCAL <mode_value> FEC_MODE_NONE 0 FEC_MODE_RS 1 FEC_MODE_FC 2 """ port = platform_sfputil_helper.get_interface_name(port, db) delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD") delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG") delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP") if port is not None: click.confirm( ('Muxcable at port {} will be changed to enable/disable fec mode {} state; disable traffic Continue?'.format(port, mode)), abort=True) res_dict = {} res_dict[0] = CONFIG_FAIL res_dict[1] = "unknown" param_dict = {} target = parse_target(target) param_dict["target"] = target param_dict["mode"] = mode res_dict = update_and_get_response_for_xcvr_cmd( "config_prbs", "status", "True", "XCVRD_CONFIG_PRBS_CMD", "XCVRD_CONFIG_PRBS_CMD_ARG", "XCVRD_CONFIG_PRBS_RSP", port, 30, param_dict, "fec") rc = res_dict[0] delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD") delete_all_keys_in_db_table("APPL_DB", "XCVRD_CONFIG_PRBS_CMD_ARG") delete_all_keys_in_db_table("STATE_DB", "XCVRD_CONFIG_PRBS_RSP") port = platform_sfputil_helper.get_interface_alias(port, db) if rc == 0: click.echo("Success in fec enable/disable port {} to {}".format(port, mode)) else: click.echo("ERR: Unable to set fec enable/disable port {} to {}".format(port, mode)) sys.exit(CONFIG_FAIL)
def rollback(db, port, fwfile): """Config muxcable firmware rollback""" port = platform_sfputil_helper.get_interface_alias(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] 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] 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)
def setswitchmode(db, state, port): """Configure the muxcable mux switching mode {auto/manual}""" port = platform_sfputil_helper.get_interface_alias(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") 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") 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)
def mode(db, state, port, json_output): """Config muxcable mode""" port = platform_sfputil_helper.get_interface_alias(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( 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(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_alias(port, db) per_npu_statedb = {} transceiver_dict = {} # 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) per_npu_statedb[asic_id] = SonicV2Connector(use_unix_socket_path=False, namespace=namespace) per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB) 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) logical_port_list = platform_sfputil_helper.get_logical_list() if port not in logical_port_list: click.echo("ERR: This is not a valid port, valid ports ({})".format(", ".join(logical_port_list))) sys.exit(CONFIG_FAIL) asic_index = None if platform_sfputil is not None: asic_index = platform_sfputil_helper.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 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): click.echo(("ERR: Unable to locate physical port information for {}".format(port))) sys.exit(CONFIG_FAIL) if len(physical_port_list) != 1: click.echo("ERR: Found multiple physical ports ({}) associated with {}".format( ", ".join(physical_port_list), port)) sys.exit(CONFIG_FAIL) transceiver_dict[asic_index] = per_npu_statedb[asic_index].get_all( per_npu_statedb[asic_index].STATE_DB, 'TRANSCEIVER_INFO|{}'.format(port)) vendor_value = get_value_for_key_in_dict(transceiver_dict[asic_index], port, "manufacturer", "TRANSCEIVER_INFO") model_value = get_value_for_key_in_dict(transceiver_dict[asic_index], port, "model", "TRANSCEIVER_INFO") """ This check is required for checking whether or not this port is connected to a Y cable or not. The check gives a way to differentiate between non Y cable ports and Y cable ports. TODO: this should be removed once their is support for multiple vendors on Y cable""" if vendor_value != VENDOR_NAME or not re.match(VENDOR_MODEL_REGEX, model_value): click.echo("ERR: Got invalid vendor value and model for port {}".format(port)) sys.exit(CONFIG_FAIL) 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]: click.echo("ERR: This logical Port {} is not on a muxcable".format(port)) sys.exit(CONFIG_FAIL) if state == "auto": mode = sonic_y_cable.y_cable.SWITCHING_MODE_AUTO elif state == "manual": mode = sonic_y_cable.y_cable.SWITCHING_MODE_MANUAL import sonic_y_cable.y_cable result = sonic_y_cable.y_cable.set_switching_mode(physical_port, mode) if result == False: click.echo(("ERR: Unable to set switching mode for the cable port {}".format(port))) sys.exit(CONFIG_FAIL) click.echo("Success in switching mode on port {} to {}".format(port, state)) elif port == "all" and port is not None: click.confirm(('Muxcable at port {} will be changed to {} switching mode. Continue?'.format(port, state)), abort=True) logical_port_list = platform_sfputil_helper.get_logical_list() rc = 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) asic_index = None if platform_sfputil is not None: asic_index = platform_sfputil_helper.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)) if not isinstance(physical_port_list, list): click.echo(("ERR: Unable to locate physical port information for {}".format(port))) continue if len(physical_port_list) != 1: click.echo("ERR: Found multiple physical ports ({}) associated with {}".format( ", ".join(physical_port_list), port)) continue transceiver_dict[asic_index] = per_npu_statedb[asic_index].get_all( per_npu_statedb[asic_index].STATE_DB, 'TRANSCEIVER_INFO|{}'.format(port)) vendor_value = transceiver_dict[asic_index].get("manufacturer", None) model_value = transceiver_dict[asic_index].get("model", None) """ This check is required for checking whether or not this port is connected to a Y cable or not. The check gives a way to differentiate between non Y cable ports and Y cable ports. TODO: this should be removed once their is support for multiple vendors on Y cable""" if vendor_value != VENDOR_NAME or not re.match(VENDOR_MODEL_REGEX, model_value): 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 if state == "auto": mode = sonic_y_cable.y_cable.SWITCHING_MODE_AUTO elif state == "manual": mode = sonic_y_cable.y_cable.SWITCHING_MODE_MANUAL import sonic_y_cable.y_cable result = sonic_y_cable.y_cable.set_switching_mode(physical_port, mode) if result == False: rc = False click.echo("ERR: Unable to set switching mode on port {} to {}".format(port, state)) click.echo("Success in switching mode on port {} to {}".format(port, state)) if rc == False: click.echo("ERR: Unable to set switching mode one or more ports to {}".format(state)) sys.exit(CONFIG_FAIL)
def switchmode(db, port): """Shows the current switching mode of the muxcable {auto/manual}""" port = platform_sfputil_helper.get_interface_name(port, db) delete_all_keys_in_db_table("APPL_DB", "XCVRD_SHOW_HWMODE_SWMODE_CMD") delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_HWMODE_SWMODE_RSP") if port is not None: res_dict = {} res_dict[0] = CONFIG_FAIL res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( "state", "state", "True", "XCVRD_SHOW_HWMODE_SWMODE_CMD", "XCVRD_SHOW_HWMODE_SWMODE_RSP", port, 1, "probe") body = [] temp_list = [] headers = ['Port', 'Switching'] port = platform_sfputil_helper.get_interface_alias(port, db) temp_list.append(port) temp_list.append(res_dict[1]) body.append(temp_list) rc = res_dict[0] click.echo(tabulate(body, headers=headers)) delete_all_keys_in_db_table("APPL_DB", "XCVRD_SHOW_HWMODE_SWMODE_CMD") delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_HWMODE_SWMODE_RSP") return rc else: logical_port_list = platform_sfputil_helper.get_logical_list() rc_exit = True body = [] 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 temp_list = [] res_dict = {} res_dict[0] = CONFIG_FAIL res_dict[1] = "unknown" res_dict = update_and_get_response_for_xcvr_cmd( "state", "state", "True", "XCVRD_SHOW_HWMODE_SWMODE_CMD", "XCVRD_SHOW_HWMODE_SWMODE_RSP", port, 1, "probe") port = platform_sfputil_helper.get_interface_alias(port, db) temp_list.append(port) temp_list.append(res_dict[1]) rc = res_dict[1] if rc != 0: rc_exit = False body.append(temp_list) delete_all_keys_in_db_table("APPL_DB", "XCVRD_SHOW_HWMODE_SWMODE_CMD") delete_all_keys_in_db_table("STATE_DB", "XCVRD_SHOW_HWMODE_SWMODE_RSP") headers = ['Port', 'Switching'] click.echo(tabulate(body, headers=headers)) if rc_exit == False: sys.exit(EXIT_FAIL)
def config(db, port, json_output): """Show muxcable config information""" port = platform_sfputil_helper.get_interface_name(port, db) port_mux_tbl_keys = {} asic_start_idx = None per_npu_configdb = {} mux_tbl_cfg_db = {} peer_switch_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) if asic_start_idx is None: asic_start_idx = asic_id # TO-DO replace the macros with correct swsscommon names #config_db[asic_id] = swsscommon.DBConnector("CONFIG_DB", REDIS_TIMEOUT_MSECS, True, namespace) #mux_tbl_cfg_db[asic_id] = swsscommon.Table(config_db[asic_id], swsscommon.CFG_MUX_CABLE_TABLE_NAME) per_npu_configdb[asic_id] = ConfigDBConnector(use_unix_socket_path=False, namespace=namespace) per_npu_configdb[asic_id].connect() mux_tbl_cfg_db[asic_id] = per_npu_configdb[asic_id].get_table("MUX_CABLE") peer_switch_tbl_cfg_db[asic_id] = per_npu_configdb[asic_id].get_table("PEER_SWITCH") #peer_switch_tbl_cfg_db[asic_id] = swsscommon.Table(config_db[asic_id], swsscommon.CFG_PEER_SWITCH_TABLE_NAME) port_mux_tbl_keys[asic_id] = mux_tbl_cfg_db[asic_id].keys() if port is not None: 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: port_name = platform_sfputil_helper.get_interface_alias(port, db) click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port_name)) sys.exit(CONFIG_FAIL) port_status_dict = {} port_status_dict["MUX_CABLE"] = {} port_status_dict["MUX_CABLE"]["PEER_TOR"] = {} peer_switch_value = None switch_name = get_switch_name(per_npu_configdb[asic_start_idx]) if asic_start_idx is not None: peer_switch_value = get_value_for_key_in_config_tbl( per_npu_configdb[asic_start_idx], switch_name, "address_ipv4", "PEER_SWITCH") port_status_dict["MUX_CABLE"]["PEER_TOR"] = peer_switch_value if port_mux_tbl_keys[asic_id] is not None: if port in port_mux_tbl_keys[asic_id]: if json_output: port_status_dict["MUX_CABLE"] = {} port_status_dict["MUX_CABLE"]["PORTS"] = {} create_json_dump_per_port_config(db, port_status_dict, per_npu_configdb, asic_id, port) click.echo("{}".format(json.dumps(port_status_dict, indent=4))) sys.exit(CONFIG_SUCCESSFUL) else: print_data = [] print_peer_tor = [] create_table_dump_per_port_config(db, print_data, per_npu_configdb, asic_id, port) headers = ['SWITCH_NAME', 'PEER_TOR'] peer_tor_data = [] peer_tor_data.append(switch_name) peer_tor_data.append(peer_switch_value) print_peer_tor.append(peer_tor_data) click.echo(tabulate(print_peer_tor, headers=headers)) headers = ['port', 'state', 'ipv4', 'ipv6'] click.echo(tabulate(print_data, headers=headers)) sys.exit(CONFIG_SUCCESSFUL) else: port_name = platform_sfputil_helper.get_interface_alias(port, db) click.echo("this is not a valid port present on mux_cable".format(port_name)) 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) else: port_status_dict = {} port_status_dict["MUX_CABLE"] = {} port_status_dict["MUX_CABLE"]["PEER_TOR"] = {} peer_switch_value = None switch_name = get_switch_name(per_npu_configdb[asic_start_idx]) if asic_start_idx is not None: peer_switch_value = get_value_for_key_in_config_tbl( per_npu_configdb[asic_start_idx], switch_name, "address_ipv4", "PEER_SWITCH") port_status_dict["MUX_CABLE"]["PEER_TOR"] = peer_switch_value if json_output: port_status_dict["MUX_CABLE"]["PORTS"] = {} for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) for port in natsorted(port_mux_tbl_keys[asic_id]): create_json_dump_per_port_config(db, port_status_dict, per_npu_configdb, asic_id, port) click.echo("{}".format(json.dumps(port_status_dict, indent=4))) else: print_data = [] print_peer_tor = [] for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) for port in natsorted(port_mux_tbl_keys[asic_id]): create_table_dump_per_port_config(db, print_data, per_npu_configdb, asic_id, port) headers = ['SWITCH_NAME', 'PEER_TOR'] peer_tor_data = [] peer_tor_data.append(switch_name) peer_tor_data.append(peer_switch_value) print_peer_tor.append(peer_tor_data) click.echo(tabulate(print_peer_tor, headers=headers)) headers = ['port', 'state', 'ipv4', 'ipv6'] click.echo(tabulate(print_data, headers=headers)) sys.exit(CONFIG_SUCCESSFUL)
def status(db, port, json_output): """Show muxcable status information""" port = platform_sfputil_helper.get_interface_name(port, db) port_table_keys = {} port_health_table_keys = {} per_npu_statedb = {} muxcable_info_dict = {} muxcable_health_dict = {} # 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) per_npu_statedb[asic_id] = SonicV2Connector(use_unix_socket_path=False, 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, 'MUX_CABLE_TABLE|*') port_health_table_keys[asic_id] = per_npu_statedb[asic_id].keys( per_npu_statedb[asic_id].STATE_DB, 'MUX_LINKMGR_TABLE|*') if port is not None: 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: port_name = platform_sfputil_helper.get_interface_alias(port, db) click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port_name)) sys.exit(STATUS_FAIL) muxcable_info_dict[asic_index] = per_npu_statedb[asic_index].get_all( per_npu_statedb[asic_index].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port)) muxcable_health_dict[asic_index] = per_npu_statedb[asic_index].get_all( per_npu_statedb[asic_index].STATE_DB, 'MUX_LINKMGR_TABLE|{}'.format(port)) if muxcable_info_dict[asic_index] is not None: logical_key = "MUX_CABLE_TABLE|{}".format(port) logical_health_key = "MUX_LINKMGR_TABLE|{}".format(port) if logical_key in port_table_keys[asic_index] and logical_health_key in port_health_table_keys[asic_index]: if json_output: port_status_dict = {} port_status_dict["MUX_CABLE"] = {} create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict, muxcable_health_dict, asic_index, port) click.echo("{}".format(json.dumps(port_status_dict, indent=4))) sys.exit(STATUS_SUCCESSFUL) else: print_data = [] create_table_dump_per_port_status(db, print_data, muxcable_info_dict, muxcable_health_dict, asic_index, port) headers = ['PORT', 'STATUS', 'HEALTH'] click.echo(tabulate(print_data, headers=headers)) sys.exit(STATUS_SUCCESSFUL) else: port_name = platform_sfputil_helper.get_interface_alias(port, db) click.echo("this is not a valid port present on mux_cable".format(port_name)) sys.exit(STATUS_FAIL) else: click.echo("there is not a valid asic table for this asic_index".format(asic_index)) sys.exit(STATUS_FAIL) else: if json_output: port_status_dict = {} port_status_dict["MUX_CABLE"] = {} for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) for key in natsorted(port_table_keys[asic_id]): port = key.split("|")[1] muxcable_info_dict[asic_id] = per_npu_statedb[asic_id].get_all( per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port)) muxcable_health_dict[asic_id] = per_npu_statedb[asic_id].get_all( per_npu_statedb[asic_id].STATE_DB, 'MUX_LINKMGR_TABLE|{}'.format(port)) create_json_dump_per_port_status(db, port_status_dict, muxcable_info_dict, muxcable_health_dict, asic_id, port) click.echo("{}".format(json.dumps(port_status_dict, indent=4))) else: print_data = [] for namespace in namespaces: asic_id = multi_asic.get_asic_index_from_namespace(namespace) for key in natsorted(port_table_keys[asic_id]): port = key.split("|")[1] muxcable_health_dict[asic_id] = per_npu_statedb[asic_id].get_all( per_npu_statedb[asic_id].STATE_DB, 'MUX_LINKMGR_TABLE|{}'.format(port)) muxcable_info_dict[asic_id] = per_npu_statedb[asic_id].get_all( per_npu_statedb[asic_id].STATE_DB, 'MUX_CABLE_TABLE|{}'.format(port)) create_table_dump_per_port_status(db, print_data, muxcable_info_dict, muxcable_health_dict, asic_id, port) headers = ['PORT', 'STATUS', 'HEALTH'] click.echo(tabulate(print_data, headers=headers)) sys.exit(STATUS_SUCCESSFUL)
def version(db, port, active): """Show muxcable firmware version""" port = platform_sfputil_helper.get_interface_alias(port, db) port_table_keys = {} y_cable_asic_table_keys = {} per_npu_statedb = {} physical_port_list = [] # 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_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, 'MUX_CABLE_TABLE|*') if port is not None: logical_port_list = platform_sfputil_helper.get_logical_list() if port not in logical_port_list: click.echo( ("ERR: Not a valid logical port for muxcable firmware {}". format(port))) sys.exit(CONFIG_FAIL) asic_index = None if platform_sfputil is not None: asic_index = platform_sfputil_helper.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)) 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): click.echo( ("ERR: Unable to locate physical port information for {}". format(port))) sys.exit(CONFIG_FAIL) if len(physical_port_list) != 1: click.echo( "ERR: Found multiple physical ports ({}) associated with {}". format(", ".join(physical_port_list), port)) sys.exit(CONFIG_FAIL) mux_info_dict = {} mux_info_active_dict = {} physical_port = physical_port_list[0] 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) import sonic_y_cable.y_cable read_side = sonic_y_cable.y_cable.check_read_side(physical_port) if logical_key in y_cable_asic_table_keys: if read_side == 1: get_firmware_dict(physical_port, 1, "self", mux_info_dict) get_firmware_dict(physical_port, 2, "peer", mux_info_dict) get_firmware_dict(physical_port, 0, "nic", mux_info_dict) if active is True: for key in mux_info_dict: if key.endswith("_active"): mux_info_active_dict[key] = mux_info_dict[key] click.echo("{}".format( json.dumps(mux_info_active_dict, indent=4))) else: click.echo("{}".format( json.dumps(mux_info_dict, indent=4))) elif read_side == 2: get_firmware_dict(physical_port, 2, "self", mux_info_dict) get_firmware_dict(physical_port, 1, "peer", mux_info_dict) get_firmware_dict(physical_port, 0, "nic", mux_info_dict) if active is True: for key in mux_info_dict: if key.endswith("_active"): mux_info_active_dict[key] = mux_info_dict[key] click.echo("{}".format( json.dumps(mux_info_active_dict, indent=4))) else: click.echo("{}".format( json.dumps(mux_info_dict, indent=4))) else: click.echo( "Did not get a valid read_side for muxcable".format( port)) sys.exit(CONFIG_FAIL) 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))
def metrics(db, port, json_output): """Show muxcable metrics <port>""" port = platform_sfputil_helper.get_interface_name(port, db) metrics_table_keys = {} per_npu_statedb = {} metrics_dict = {} # 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_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) metrics_table_keys[asic_id] = per_npu_statedb[asic_id].keys( per_npu_statedb[asic_id].STATE_DB, 'MUX_METRICS_TABLE|*') if port is not None: logical_port_list = platform_sfputil_helper.get_logical_list() if port not in logical_port_list: port_name = platform_sfputil_helper.get_interface_alias(port, db) click.echo(("ERR: Not a valid logical port for muxcable firmware {}".format(port_name))) sys.exit(CONFIG_FAIL) asic_index = None if platform_sfputil is not None: asic_index = platform_sfputil_helper.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: port_name = platform_sfputil_helper.get_interface_alias(port, db) click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port_name)) metrics_dict[asic_index] = per_npu_statedb[asic_index].get_all( per_npu_statedb[asic_index].STATE_DB, 'MUX_METRICS_TABLE|{}'.format(port)) ordered_dict = OrderedDict(sorted(metrics_dict[asic_index].items(), key=itemgetter(1))) if json_output: click.echo("{}".format(json.dumps(ordered_dict, indent=4))) else: print_data = [] for key, val in ordered_dict.items(): print_port_data = [] port = platform_sfputil_helper.get_interface_alias(port, db) print_port_data.append(port) print_port_data.append(key) print_port_data.append(val) print_data.append(print_port_data) headers = ['PORT', 'EVENT', 'TIME'] click.echo(tabulate(print_data, headers=headers))
def muxdirection(db, port): """Shows the current direction of the muxcable {active/standy}""" port = platform_sfputil_helper.get_interface_alias(port, db) per_npu_statedb = {} transceiver_table_keys = {} transceiver_dict = {} # 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) per_npu_statedb[asic_id] = SonicV2Connector(use_unix_socket_path=False, namespace=namespace) per_npu_statedb[asic_id].connect(per_npu_statedb[asic_id].STATE_DB) transceiver_table_keys[asic_id] = per_npu_statedb[asic_id].keys( per_npu_statedb[asic_id].STATE_DB, 'TRANSCEIVER_INFO|*') if port is not None: logical_port_list = platform_sfputil_helper.get_logical_list() if port not in logical_port_list: click.echo( "ERR: This is not a valid port, valid ports ({})".format( ", ".join(logical_port_list))) sys.exit(EXIT_FAIL) asic_index = None if platform_sfputil is not None: asic_index = platform_sfputil_helper.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) transceiver_dict[asic_index] = per_npu_statedb[asic_index].get_all( per_npu_statedb[asic_index].STATE_DB, 'TRANSCEIVER_INFO|{}'.format(port)) vendor_value = get_value_for_key_in_dict(transceiver_dict[asic_index], port, "manufacturer", "TRANSCEIVER_INFO") model_value = get_value_for_key_in_dict(transceiver_dict[asic_index], port, "model", "TRANSCEIVER_INFO") """ This check is required for checking whether or not this port is connected to a Y cable or not. The check gives a way to differentiate between non Y cable ports and Y cable ports. TODO: this should be removed once their is support for multiple vendors on Y cable""" if vendor_value != VENDOR_NAME or not re.match(VENDOR_MODEL_REGEX, model_value): click.echo( "ERR: Got invalid vendor value and model for port {}".format( port)) sys.exit(EXIT_FAIL) 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): click.echo( ("ERR: Unable to locate physical port information for {}". format(port))) sys.exit(EXIT_FAIL) if len(physical_port_list) != 1: click.echo( "ERR: Found multiple physical ports ({}) associated with {}". format(", ".join(physical_port_list), port)) sys.exit(EXIT_FAIL) 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]: click.echo( "ERR: This logical Port {} is not on a muxcable".format(port)) sys.exit(EXIT_FAIL) import sonic_y_cable.y_cable read_side = sonic_y_cable.y_cable.check_read_side(physical_port) if read_side == False or read_side == -1: click.echo( ("ERR: Unable to get read_side for the cable port {}".format( port))) sys.exit(EXIT_FAIL) mux_direction = sonic_y_cable.y_cable.check_mux_direction( physical_port) if mux_direction == False or mux_direction == -1: click.echo( ("ERR: Unable to get mux direction for the cable port {}". format(port))) sys.exit(EXIT_FAIL) if int(read_side) == 1: if mux_direction == 1: state = "active" elif mux_direction == 2: state = "standby" elif int(read_side) == 2: if mux_direction == 1: state = "standby" elif mux_direction == 2: state = "active" else: click.echo( ("ERR: Unable to get mux direction, port {}".format(port))) state = "unknown" headers = ['Port', 'Direction'] body = [[port, state]] click.echo(tabulate(body, headers=headers)) else: logical_port_list = platform_sfputil_helper.get_logical_list() rc = True body = [] for port in logical_port_list: temp_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 asic_index = None if platform_sfputil is not None: asic_index = platform_sfputil_helper.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: continue transceiver_dict[asic_index] = per_npu_statedb[asic_index].get_all( per_npu_statedb[asic_index].STATE_DB, 'TRANSCEIVER_INFO|{}'.format(port)) vendor_value = transceiver_dict[asic_index].get( "manufacturer", None) model_value = transceiver_dict[asic_index].get("model", None) """ This check is required for checking whether or not this port is connected to a Y cable or not. The check gives a way to differentiate between non Y cable ports and Y cable ports. TODO: this should be removed once their is support for multiple vendors on Y cable""" if vendor_value != VENDOR_NAME or not re.match( VENDOR_MODEL_REGEX, model_value): 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 import sonic_y_cable.y_cable read_side = sonic_y_cable.y_cable.check_read_side(physical_port) if read_side == False or read_side == -1: rc = False temp_list.append(port) temp_list.append("unknown") body.append(temp_list) continue mux_direction = sonic_y_cable.y_cable.check_mux_direction( physical_port) if mux_direction == False or mux_direction == -1: rc = False temp_list.append(port) temp_list.append("unknown") body.append(temp_list) continue if int(read_side) == 1: if mux_direction == 1: state = "active" elif mux_direction == 2: state = "standby" elif int(read_side) == 2: if mux_direction == 1: state = "standby" elif mux_direction == 2: state = "active" else: rc = False temp_list.append(port) temp_list.append("unknown") body.append(temp_list) continue temp_list.append(port) temp_list.append(state) body.append(temp_list) headers = ['Port', 'Direction'] click.echo(tabulate(body, headers=headers)) if rc == False: sys.exit(EXIT_FAIL)