Skip to content

Commit e41dc94

Browse files
committed
[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: sonic-net/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 <[email protected]>
1 parent cb3a047 commit e41dc94

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

scripts/intfutil

+21-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ PORT_OPTICS_TYPE = "type"
4545
PORT_PFC_ASYM_STATUS = "pfc_asym"
4646
PORT_AUTONEG = 'autoneg'
4747
PORT_ADV_SPEEDS = 'adv_speeds'
48+
PORT_RMT_ADV_SPEEDS = 'rmt_adv_speeds'
4849
PORT_INTERFACE_TYPE = 'interface_type'
4950
PORT_ADV_INTERFACE_TYPES = 'adv_interface_types'
5051
PORT_TPID = "tpid"
@@ -165,6 +166,24 @@ def appl_db_port_status_get(appl_db, intf_name, status_type):
165166
status = ','.join(new_speed_list)
166167
return status
167168

169+
def state_db_port_status_get(db, intf_name, type):
170+
"""
171+
Get the port status
172+
"""
173+
full_table_id = PORT_STATE_TABLE_PREFIX + intf_name
174+
status = db.get(db.STATE_DB, full_table_id, type)
175+
if status in [None, ""]:
176+
return "N/A"
177+
if type == PORT_SPEED and status != "N/A":
178+
status = '{}G'.format(status[:-3])
179+
elif type in [PORT_ADV_SPEEDS, PORT_RMT_ADV_SPEEDS] and status not in ["N/A", "all"]:
180+
speed_list = status.split(',')
181+
new_speed_list = []
182+
for s in natsorted(speed_list):
183+
new_speed_list.append('{}G'.format(s[:-3]))
184+
status = ','.join(new_speed_list)
185+
return status
186+
168187
def port_oper_speed_get(db, intf_name):
169188
"""
170189
Get port oper speed
@@ -565,7 +584,7 @@ class IntfDescription(object):
565584

566585

567586
# ========================== interface-autoneg logic ==========================
568-
header_autoneg = ['Interface', 'Auto-Neg Mode', 'Speed', 'Adv Speeds', 'Type', 'Adv Types', 'Oper', 'Admin']
587+
header_autoneg = ['Interface', 'Auto-Neg Mode', 'Speed', 'Adv Speeds', 'Rmt Adv Speeds', 'Type', 'Adv Types', 'Oper', 'Admin']
569588

570589

571590
class IntfAutoNegStatus(object):
@@ -615,6 +634,7 @@ class IntfAutoNegStatus(object):
615634
autoneg_mode,
616635
port_oper_speed_get(self.db, key),
617636
appl_db_port_status_get(self.db, key, PORT_ADV_SPEEDS),
637+
state_db_port_status_get(self.db, key, PORT_RMT_ADV_SPEEDS),
618638
appl_db_port_status_get(self.db, key, PORT_INTERFACE_TYPE),
619639
appl_db_port_status_get(self.db, key, PORT_ADV_INTERFACE_TYPES),
620640
appl_db_port_status_get(self.db, key, PORT_OPER_STATUS),

tests/intfutil_test.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -71,30 +71,30 @@
7171
"""
7272

7373
show_interface_auto_neg_status_output = """\
74-
Interface Auto-Neg Mode Speed Adv Speeds Type Adv Types Oper Admin
75-
----------- --------------- ------- ------------ ------ ----------- ------ -------
76-
Ethernet0 enabled 25G 10G,50G CR4 CR4,CR2 down up
77-
Ethernet16 N/A 100M N/A N/A N/A up up
78-
Ethernet24 N/A 1G N/A N/A N/A up up
79-
Ethernet28 N/A 1000M N/A N/A N/A up up
80-
Ethernet32 disabled 40G all N/A all up up
81-
Ethernet36 N/A 10M N/A N/A N/A up up
82-
Ethernet112 N/A 40G N/A N/A N/A up up
83-
Ethernet116 N/A 40G N/A N/A N/A up up
84-
Ethernet120 N/A 40G N/A N/A N/A up up
85-
Ethernet124 N/A 40G N/A N/A N/A up up
74+
Interface Auto-Neg Mode Speed Adv Speeds Rmt Adv Speeds Type Adv Types Oper Admin
75+
----------- --------------- ------- ------------ ---------------- ------ ----------- ------ -------
76+
Ethernet0 enabled 25G 10G,50G 40G CR4 CR4,CR2 down up
77+
Ethernet16 N/A 100M N/A N/A N/A N/A up up
78+
Ethernet24 N/A 1G N/A N/A N/A N/A up up
79+
Ethernet28 N/A 1000M N/A N/A N/A N/A up up
80+
Ethernet32 disabled 40G all N/A N/A all up up
81+
Ethernet36 N/A 10M N/A N/A N/A N/A up up
82+
Ethernet112 N/A 40G N/A N/A N/A N/A up up
83+
Ethernet116 N/A 40G N/A N/A N/A N/A up up
84+
Ethernet120 N/A 40G N/A N/A N/A N/A up up
85+
Ethernet124 N/A 40G N/A N/A N/A N/A up up
8686
"""
8787

8888
show_interface_auto_neg_status_Ethernet0_output = """\
89-
Interface Auto-Neg Mode Speed Adv Speeds Type Adv Types Oper Admin
90-
----------- --------------- ------- ------------ ------ ----------- ------ -------
91-
Ethernet0 enabled 25G 10G,50G CR4 CR4,CR2 down up
89+
Interface Auto-Neg Mode Speed Adv Speeds Rmt Adv Speeds Type Adv Types Oper Admin
90+
----------- --------------- ------- ------------ ---------------- ------ ----------- ------ -------
91+
Ethernet0 enabled 25G 10G,50G 40G CR4 CR4,CR2 down up
9292
"""
9393

9494
show_interface_auto_neg_status_eth9_output = """\
95-
Interface Auto-Neg Mode Speed Adv Speeds Type Adv Types Oper Admin
96-
----------- --------------- ------- ------------ ------ ----------- ------ -------
97-
Ethernet32 disabled 40G all N/A all up up
95+
Interface Auto-Neg Mode Speed Adv Speeds Rmt Adv Speeds Type Adv Types Oper Admin
96+
----------- --------------- ------- ------------ ---------------- ------ ----------- ------ -------
97+
Ethernet32 disabled 40G all N/A N/A all up up
9898
"""
9999

100100

@@ -293,7 +293,7 @@ def test_show_interfaces_autoneg_status_Ethernet0(self):
293293
assert result.exit_code == 0
294294
assert result.output == show_interface_auto_neg_status_Ethernet0_output
295295

296-
def test_show_interfaces_autoneg_status_etp9_in_alias_mode(self):
296+
def test_show_interfaces_autoneg_status_eth9_in_alias_mode(self):
297297
os.environ["SONIC_CLI_IFACE_MODE"] = "alias"
298298
result = self.runner.invoke(show.cli.commands["interfaces"].commands["autoneg"].commands["status"], ["etp9"])
299299
os.environ["SONIC_CLI_IFACE_MODE"] = "default"

tests/mock_tables/state_db.json

+1
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@
683683
"access": "False"
684684
},
685685
"PORT_TABLE|Ethernet0": {
686+
"rmt_adv_speeds" : "40000",
686687
"speed" : "100000",
687688
"supported_speeds": "10000,25000,40000,100000"
688689
},

0 commit comments

Comments
 (0)