Skip to content

Commit

Permalink
[autoneg] add support for remote speed advertisement
Browse files Browse the repository at this point in the history
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 <dante.su@broadcom.com>
  • Loading branch information
ds952811 committed Apr 22, 2022
1 parent cb3a047 commit e41dc94
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
22 changes: 21 additions & 1 deletion scripts/intfutil
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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),
Expand Down
38 changes: 19 additions & 19 deletions tests/intfutil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""


Expand Down Expand 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"
Expand Down
1 change: 1 addition & 0 deletions tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@
"access": "False"
},
"PORT_TABLE|Ethernet0": {
"rmt_adv_speeds" : "40000",
"speed" : "100000",
"supported_speeds": "10000,25000,40000,100000"
},
Expand Down

0 comments on commit e41dc94

Please sign in to comment.