diff --git a/config/muxcable.py b/config/muxcable.py index f6b5a6a39d..29375feb7a 100644 --- a/config/muxcable.py +++ b/config/muxcable.py @@ -11,6 +11,7 @@ from swsscommon import swsscommon from tabulate import tabulate from utilities_common import platform_sfputil_helper +from utilities_common.general import get_optional_value_for_key_in_config_tbl platform_sfputil = None @@ -203,7 +204,6 @@ def update_and_get_response_for_xcvr_cmd(cmd_name, rsp_name, exp_rsp, cmd_table_ return res_dict - def get_value_for_key_in_config_tbl(config_db, port, key, table): info_dict = {} info_dict = config_db.get_entry(table, port) @@ -244,6 +244,8 @@ def lookup_statedb_and_update_configdb(db, per_npu_statedb, config_db, port, sta 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") + soc_ipv4_value = get_optional_value_for_key_in_config_tbl(config_db, port, "soc_ipv4", "MUX_CABLE") + cable_type = get_optional_value_for_key_in_config_tbl(config_db, port, "cable_type", "MUX_CABLE") state = get_value_for_key_in_dict(muxcable_statedb_dict, port, "state", "MUX_CABLE_TABLE") @@ -252,8 +254,16 @@ def lookup_statedb_and_update_configdb(db, per_npu_statedb, config_db, port, sta 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 cable_type is not None and soc_ipv4_value is not None: + config_db.set_entry("MUX_CABLE", port, {"state": state_cfg_val, + "server_ipv4": ipv4_value, + "server_ipv6": ipv6_value, + "soc_ipv4":soc_ipv4_value, + "cable_type": cable_type}) + 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: diff --git a/show/muxcable.py b/show/muxcable.py index a6cd008c2a..6d01727868 100644 --- a/show/muxcable.py +++ b/show/muxcable.py @@ -13,6 +13,7 @@ from swsscommon import swsscommon from tabulate import tabulate from utilities_common import platform_sfputil_helper +from utilities_common.general import get_optional_value_for_key_in_config_tbl platform_sfputil = None @@ -460,7 +461,7 @@ def create_table_dump_per_port_status(db, print_data, muxcable_info_dict, muxcab print_data.append(print_port_data) -def create_table_dump_per_port_config(db ,print_data, per_npu_configdb, asic_id, port): +def create_table_dump_per_port_config(db ,print_data, per_npu_configdb, asic_id, port, is_dualtor_active_active): port_list = [] port_name = platform_sfputil_helper.get_interface_alias(port, db) @@ -471,6 +472,13 @@ def create_table_dump_per_port_config(db ,print_data, per_npu_configdb, asic_id, 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) + cable_type = get_optional_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "cable_type", "MUX_CABLE") + if cable_type is not None: + port_list.append(cable_type) + soc_ipv4_value = get_optional_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "soc_ipv4", "MUX_CABLE") + if soc_ipv4_value is not None: + port_list.append(soc_ipv4_value) + is_dualtor_active_active[0] = True print_data.append(port_list) @@ -484,6 +492,12 @@ def create_json_dump_per_port_config(db, port_status_dict, per_npu_configdb, asi 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 + cable_type = get_optional_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "cable_type", "MUX_CABLE") + if cable_type is not None: + port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"]["cable_type"] = cable_type + soc_ipv4_value = get_optional_value_for_key_in_config_tbl(per_npu_configdb[asic_id], port, "soc_ipv4", "MUX_CABLE") + if soc_ipv4_value is not None: + port_status_dict["MUX_CABLE"]["PORTS"][port_name]["SERVER"]["soc_ipv4"] = soc_ipv4_value @muxcable.command() @@ -688,8 +702,10 @@ def config(db, port, json_output): else: print_data = [] print_peer_tor = [] + is_dualtor_active_active = [False] - create_table_dump_per_port_config(db, print_data, per_npu_configdb, asic_id, port) + + create_table_dump_per_port_config(db, print_data, per_npu_configdb, asic_id, port, is_dualtor_active_active) headers = ['SWITCH_NAME', 'PEER_TOR'] peer_tor_data = [] @@ -697,7 +713,10 @@ def config(db, port, json_output): 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'] + if is_dualtor_active_active[0]: + headers = ['port', 'state', 'ipv4', 'ipv6', 'cable_type', 'soc_ipv4'] + else: + headers = ['port', 'state', 'ipv4', 'ipv6'] click.echo(tabulate(print_data, headers=headers)) sys.exit(CONFIG_SUCCESSFUL) @@ -733,10 +752,12 @@ def config(db, port, json_output): else: print_data = [] print_peer_tor = [] + is_dualtor_active_active = [False] + 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) + create_table_dump_per_port_config(db, print_data, per_npu_configdb, asic_id, port, is_dualtor_active_active) headers = ['SWITCH_NAME', 'PEER_TOR'] peer_tor_data = [] @@ -744,7 +765,10 @@ def config(db, port, json_output): 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'] + if is_dualtor_active_active[0]: + headers = ['port', 'state', 'ipv4', 'ipv6', 'cable_type', 'soc_ipv4'] + else: + headers = ['port', 'state', 'ipv4', 'ipv6'] click.echo(tabulate(print_data, headers=headers)) sys.exit(CONFIG_SUCCESSFUL) diff --git a/tests/mock_tables/config_db.json b/tests/mock_tables/config_db.json index e546f48e7d..3314fef9e9 100644 --- a/tests/mock_tables/config_db.json +++ b/tests/mock_tables/config_db.json @@ -1740,11 +1740,14 @@ "MUX_CABLE|Ethernet32": { "state": "auto", "server_ipv4": "10.1.1.1", + "cable_type": "active-active", + "soc_ipv4": "10.1.1.2", "server_ipv6": "fc00::75" }, "MUX_CABLE|Ethernet16": { "state": "standby", "server_ipv4": "10.1.1.1", + "cable_type": "active-standby", "server_ipv6": "fc00::75" }, "MUX_CABLE|Ethernet28": { diff --git a/tests/muxcable_test.py b/tests/muxcable_test.py index 30798e3915..d79606e3dc 100644 --- a/tests/muxcable_test.py +++ b/tests/muxcable_test.py @@ -138,30 +138,30 @@ SWITCH_NAME PEER_TOR ------------- ---------- sonic-switch 10.2.2.2 -port state ipv4 ipv6 ----------- ------- -------- -------- +port state ipv4 ipv6 cable_type soc_ipv4 +---------- ------- -------- -------- -------------- ---------- Ethernet0 active 10.2.1.1 e800::46 Ethernet4 auto 10.3.1.1 e801::46 Ethernet8 active 10.4.1.1 e802::46 Ethernet12 active 10.4.1.1 e802::46 -Ethernet16 standby 10.1.1.1 fc00::75 +Ethernet16 standby 10.1.1.1 fc00::75 active-standby Ethernet28 manual 10.1.1.1 fc00::75 -Ethernet32 auto 10.1.1.1 fc00::75 +Ethernet32 auto 10.1.1.1 fc00::75 active-active 10.1.1.2 """ tabular_data_config_output_expected_alias = """\ SWITCH_NAME PEER_TOR ------------- ---------- sonic-switch 10.2.2.2 -port state ipv4 ipv6 ------- ------- -------- -------- +port state ipv4 ipv6 cable_type soc_ipv4 +------ ------- -------- -------- -------------- ---------- etp1 active 10.2.1.1 e800::46 etp2 auto 10.3.1.1 e801::46 etp3 active 10.4.1.1 e802::46 etp4 active 10.4.1.1 e802::46 -etp5 standby 10.1.1.1 fc00::75 +etp5 standby 10.1.1.1 fc00::75 active-standby etp8 manual 10.1.1.1 fc00::75 -etp9 auto 10.1.1.1 fc00::75 +etp9 auto 10.1.1.1 fc00::75 active-active 10.1.1.2 """ json_data_status_config_output_expected = """\ @@ -201,7 +201,8 @@ "STATE": "standby", "SERVER": { "IPv4": "10.1.1.1", - "IPv6": "fc00::75" + "IPv6": "fc00::75", + "cable_type": "active-standby" } }, "Ethernet28": { @@ -215,7 +216,9 @@ "STATE": "auto", "SERVER": { "IPv4": "10.1.1.1", - "IPv6": "fc00::75" + "IPv6": "fc00::75", + "cable_type": "active-active", + "soc_ipv4": "10.1.1.2" } } } @@ -260,7 +263,8 @@ "STATE": "standby", "SERVER": { "IPv4": "10.1.1.1", - "IPv6": "fc00::75" + "IPv6": "fc00::75", + "cable_type": "active-standby" } }, "etp8": { @@ -274,7 +278,9 @@ "STATE": "auto", "SERVER": { "IPv4": "10.1.1.1", - "IPv6": "fc00::75" + "IPv6": "fc00::75", + "cable_type": "active-active", + "soc_ipv4": "10.1.1.2" } } } diff --git a/utilities_common/general.py b/utilities_common/general.py index a2f9eaf2a9..6ed70a46a1 100644 --- a/utilities_common/general.py +++ b/utilities_common/general.py @@ -30,4 +30,15 @@ def load_db_config(): swsscommon.SonicDBConfig.load_sonic_global_db_config() else: if not swsscommon.SonicDBConfig.isInit(): - swsscommon.SonicDBConfig.load_sonic_db_config() \ No newline at end of file + swsscommon.SonicDBConfig.load_sonic_db_config() + +def get_optional_value_for_key_in_config_tbl(config_db, port, key, table): + info_dict = {} + info_dict = config_db.get_entry(table, port) + if info_dict is None: + return None + + value = info_dict.get(key, None) + + return value +