From e41dc94250b8cfcb925dae5ac7e0126da02c0c35 Mon Sep 17 00:00:00 2001 From: Dante Su Date: Fri, 1 Apr 2022 03:22:24 +0000 Subject: [PATCH] [autoneg] add support for remote speed advertisement Add support for remote speed advertisement, such that users could easily identify the connection issues when autoneg is enabled. HLD: Azure/SONiC#924 - What I did Add support for remote speed advertisement - How I did it Implementation is done according to the AutoNeg HLD Signed-off-by: Dante Su --- scripts/intfutil | 22 ++++++++++++++++++- tests/intfutil_test.py | 38 ++++++++++++++++----------------- tests/mock_tables/state_db.json | 1 + 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/scripts/intfutil b/scripts/intfutil index 784140aced..d1e65701c2 100755 --- a/scripts/intfutil +++ b/scripts/intfutil @@ -45,6 +45,7 @@ PORT_OPTICS_TYPE = "type" PORT_PFC_ASYM_STATUS = "pfc_asym" PORT_AUTONEG = 'autoneg' PORT_ADV_SPEEDS = 'adv_speeds' +PORT_RMT_ADV_SPEEDS = 'rmt_adv_speeds' PORT_INTERFACE_TYPE = 'interface_type' PORT_ADV_INTERFACE_TYPES = 'adv_interface_types' PORT_TPID = "tpid" @@ -165,6 +166,24 @@ def appl_db_port_status_get(appl_db, intf_name, status_type): status = ','.join(new_speed_list) return status +def state_db_port_status_get(db, intf_name, type): + """ + Get the port status + """ + full_table_id = PORT_STATE_TABLE_PREFIX + intf_name + status = db.get(db.STATE_DB, full_table_id, type) + if status in [None, ""]: + return "N/A" + if type == PORT_SPEED and status != "N/A": + status = '{}G'.format(status[:-3]) + elif type in [PORT_ADV_SPEEDS, PORT_RMT_ADV_SPEEDS] and status not in ["N/A", "all"]: + speed_list = status.split(',') + new_speed_list = [] + for s in natsorted(speed_list): + new_speed_list.append('{}G'.format(s[:-3])) + status = ','.join(new_speed_list) + return status + def port_oper_speed_get(db, intf_name): """ Get port oper speed @@ -565,7 +584,7 @@ class IntfDescription(object): # ========================== interface-autoneg logic ========================== -header_autoneg = ['Interface', 'Auto-Neg Mode', 'Speed', 'Adv Speeds', 'Type', 'Adv Types', 'Oper', 'Admin'] +header_autoneg = ['Interface', 'Auto-Neg Mode', 'Speed', 'Adv Speeds', 'Rmt Adv Speeds', 'Type', 'Adv Types', 'Oper', 'Admin'] class IntfAutoNegStatus(object): @@ -615,6 +634,7 @@ class IntfAutoNegStatus(object): autoneg_mode, port_oper_speed_get(self.db, key), appl_db_port_status_get(self.db, key, PORT_ADV_SPEEDS), + state_db_port_status_get(self.db, key, PORT_RMT_ADV_SPEEDS), appl_db_port_status_get(self.db, key, PORT_INTERFACE_TYPE), appl_db_port_status_get(self.db, key, PORT_ADV_INTERFACE_TYPES), appl_db_port_status_get(self.db, key, PORT_OPER_STATUS), diff --git a/tests/intfutil_test.py b/tests/intfutil_test.py index 0129573881..11e0c20188 100644 --- a/tests/intfutil_test.py +++ b/tests/intfutil_test.py @@ -71,30 +71,30 @@ """ show_interface_auto_neg_status_output = """\ - Interface Auto-Neg Mode Speed Adv Speeds Type Adv Types Oper Admin ------------ --------------- ------- ------------ ------ ----------- ------ ------- - Ethernet0 enabled 25G 10G,50G CR4 CR4,CR2 down up - Ethernet16 N/A 100M N/A N/A N/A up up - Ethernet24 N/A 1G N/A N/A N/A up up - Ethernet28 N/A 1000M N/A N/A N/A up up - Ethernet32 disabled 40G all N/A all up up - Ethernet36 N/A 10M N/A N/A N/A up up -Ethernet112 N/A 40G N/A N/A N/A up up -Ethernet116 N/A 40G N/A N/A N/A up up -Ethernet120 N/A 40G N/A N/A N/A up up -Ethernet124 N/A 40G N/A N/A N/A up up + Interface Auto-Neg Mode Speed Adv Speeds Rmt Adv Speeds Type Adv Types Oper Admin +----------- --------------- ------- ------------ ---------------- ------ ----------- ------ ------- + Ethernet0 enabled 25G 10G,50G 40G CR4 CR4,CR2 down up + Ethernet16 N/A 100M N/A N/A N/A N/A up up + Ethernet24 N/A 1G N/A N/A N/A N/A up up + Ethernet28 N/A 1000M N/A N/A N/A N/A up up + Ethernet32 disabled 40G all N/A N/A all up up + Ethernet36 N/A 10M N/A N/A N/A N/A up up +Ethernet112 N/A 40G N/A N/A N/A N/A up up +Ethernet116 N/A 40G N/A N/A N/A N/A up up +Ethernet120 N/A 40G N/A N/A N/A N/A up up +Ethernet124 N/A 40G N/A N/A N/A N/A up up """ show_interface_auto_neg_status_Ethernet0_output = """\ - Interface Auto-Neg Mode Speed Adv Speeds Type Adv Types Oper Admin ------------ --------------- ------- ------------ ------ ----------- ------ ------- - Ethernet0 enabled 25G 10G,50G CR4 CR4,CR2 down up + Interface Auto-Neg Mode Speed Adv Speeds Rmt Adv Speeds Type Adv Types Oper Admin +----------- --------------- ------- ------------ ---------------- ------ ----------- ------ ------- + Ethernet0 enabled 25G 10G,50G 40G CR4 CR4,CR2 down up """ show_interface_auto_neg_status_eth9_output = """\ - Interface Auto-Neg Mode Speed Adv Speeds Type Adv Types Oper Admin ------------ --------------- ------- ------------ ------ ----------- ------ ------- - Ethernet32 disabled 40G all N/A all up up + Interface Auto-Neg Mode Speed Adv Speeds Rmt Adv Speeds Type Adv Types Oper Admin +----------- --------------- ------- ------------ ---------------- ------ ----------- ------ ------- + Ethernet32 disabled 40G all N/A N/A all up up """ @@ -293,7 +293,7 @@ def test_show_interfaces_autoneg_status_Ethernet0(self): assert result.exit_code == 0 assert result.output == show_interface_auto_neg_status_Ethernet0_output - def test_show_interfaces_autoneg_status_etp9_in_alias_mode(self): + def test_show_interfaces_autoneg_status_eth9_in_alias_mode(self): os.environ["SONIC_CLI_IFACE_MODE"] = "alias" result = self.runner.invoke(show.cli.commands["interfaces"].commands["autoneg"].commands["status"], ["etp9"]) os.environ["SONIC_CLI_IFACE_MODE"] = "default" diff --git a/tests/mock_tables/state_db.json b/tests/mock_tables/state_db.json index f9e4c54e2e..038d6a6373 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -683,6 +683,7 @@ "access": "False" }, "PORT_TABLE|Ethernet0": { + "rmt_adv_speeds" : "40000", "speed" : "100000", "supported_speeds": "10000,25000,40000,100000" },