Skip to content

Commit fea1343

Browse files
committed
[autoneg] add support for remote speed advertisement (#2124)
* [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]> * fix test failures in dump_state_test.py Signed-off-by: Dante Su <[email protected]> * address review comments Signed-off-by: Dante Su <[email protected]> * drop PORT_ADV_SPEEDS from state_db_port_status_get() Signed-off-by: Dante Su <[email protected]> * address review comments Signed-off-by: Dante Su <[email protected]>
1 parent 4d734e2 commit fea1343

File tree

4 files changed

+48
-23
lines changed

4 files changed

+48
-23
lines changed

scripts/intfutil

+25-2
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"
@@ -140,8 +141,12 @@ def port_speed_parse(in_speed, optics_type):
140141
speed = int(in_speed)
141142
if optics_type == OPTICS_TYPE_RJ45 and speed <= 1000:
142143
out_speed = '{}M'.format(speed)
144+
elif speed < 1000:
145+
out_speed = '{}M'.format(speed)
146+
elif speed % 1000 >= 100:
147+
out_speed = '{:.1f}G'.format(speed / 1000)
143148
else:
144-
out_speed = '{}G'.format(int(speed/1000))
149+
out_speed = '{:.0f}G'.format(speed / 1000)
145150

146151
return out_speed
147152

@@ -165,6 +170,23 @@ def appl_db_port_status_get(appl_db, intf_name, status_type):
165170
status = ','.join(new_speed_list)
166171
return status
167172

173+
def state_db_port_status_get(db, intf_name, field):
174+
"""
175+
Get the port status
176+
"""
177+
full_table_id = PORT_STATE_TABLE_PREFIX + intf_name
178+
status = db.get(db.STATE_DB, full_table_id, field)
179+
if not status:
180+
return "N/A"
181+
if field in [PORT_RMT_ADV_SPEEDS] and status not in ["N/A", "all"]:
182+
optics_type = state_db_port_optics_get(db, intf_name, PORT_OPTICS_TYPE)
183+
speed_list = status.split(',')
184+
new_speed_list = []
185+
for s in natsorted(speed_list):
186+
new_speed_list.append(port_speed_parse(s, optics_type))
187+
status = ','.join(new_speed_list)
188+
return status
189+
168190
def port_oper_speed_get(db, intf_name):
169191
"""
170192
Get port oper speed
@@ -566,7 +588,7 @@ class IntfDescription(object):
566588

567589

568590
# ========================== interface-autoneg logic ==========================
569-
header_autoneg = ['Interface', 'Auto-Neg Mode', 'Speed', 'Adv Speeds', 'Type', 'Adv Types', 'Oper', 'Admin']
591+
header_autoneg = ['Interface', 'Auto-Neg Mode', 'Speed', 'Adv Speeds', 'Rmt Adv Speeds', 'Type', 'Adv Types', 'Oper', 'Admin']
570592

571593

572594
class IntfAutoNegStatus(object):
@@ -616,6 +638,7 @@ class IntfAutoNegStatus(object):
616638
autoneg_mode,
617639
port_oper_speed_get(self.db, key),
618640
appl_db_port_status_get(self.db, key, PORT_ADV_SPEEDS),
641+
state_db_port_status_get(self.db, key, PORT_RMT_ADV_SPEEDS),
619642
appl_db_port_status_get(self.db, key, PORT_INTERFACE_TYPE),
620643
appl_db_port_status_get(self.db, key, PORT_ADV_INTERFACE_TYPES),
621644
appl_db_port_status_get(self.db, key, PORT_OPER_STATUS),

tests/dump_tests/dump_state_test.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def compare_json_output(exp_json, rec, exclude_paths=None):
3434
| | | | PORT_TABLE|Ethernet0 | +------------------+--------------------------+ | |
3535
| | | | | | field | value | | |
3636
| | | | | |------------------+--------------------------| | |
37+
| | | | | | rmt_adv_speeds | 10,100,1000 | | |
3738
| | | | | | speed | 100000 | | |
3839
| | | | | | supported_speeds | 10000,25000,40000,100000 | | |
3940
| | | | | +------------------+--------------------------+ | |
@@ -120,7 +121,7 @@ def test_identifier_single(self):
120121
expected = {'Ethernet0': {'CONFIG_DB': {'keys': [{'PORT|Ethernet0': {'alias': 'etp1', 'description': 'etp1', 'index': '0', 'lanes': '25,26,27,28', 'mtu': '9100', 'pfc_asym': 'off', 'speed': '40000'}}], 'tables_not_found': []},
121122
'APPL_DB': {'keys': [{'PORT_TABLE:Ethernet0': {'index': '0', 'lanes': '0', 'alias': 'Ethernet0', 'description': 'ARISTA01T2:Ethernet1', 'speed': '25000', 'oper_status': 'down', 'pfc_asym': 'off', 'mtu': '9100', 'fec': 'rs', 'admin_status': 'up'}}], 'tables_not_found': []},
122123
'ASIC_DB': {'keys': [{'ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd00000000056d': {'SAI_HOSTIF_ATTR_NAME': 'Ethernet0', 'SAI_HOSTIF_ATTR_OBJ_ID': 'oid:0x10000000004a4', 'SAI_HOSTIF_ATTR_OPER_STATUS': 'true', 'SAI_HOSTIF_ATTR_TYPE': 'SAI_HOSTIF_TYPE_NETDEV', 'SAI_HOSTIF_ATTR_VLAN_TAG': 'SAI_HOSTIF_VLAN_TAG_STRIP'}}, {'ASIC_STATE:SAI_OBJECT_TYPE_PORT:oid:0x10000000004a4': {'NULL': 'NULL', 'SAI_PORT_ATTR_ADMIN_STATE': 'true', 'SAI_PORT_ATTR_MTU': '9122', 'SAI_PORT_ATTR_SPEED': '100000'}}], 'tables_not_found': [], 'vidtorid': {'oid:0xd00000000056d': 'oid:0xd', 'oid:0x10000000004a4': 'oid:0x1690000000001'}},
123-
'STATE_DB': {'keys': [{'PORT_TABLE|Ethernet0': {'speed': '100000', 'supported_speeds': '10000,25000,40000,100000'}}], 'tables_not_found': []}}}
124+
'STATE_DB': {'keys': [{'PORT_TABLE|Ethernet0': {'rmt_adv_speeds': '10,100,1000', 'speed': '100000', 'supported_speeds': '10000,25000,40000,100000'}}], 'tables_not_found': []}}}
124125

125126
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
126127
# Cause other tests depend and change these paths in the mock_db, this test would fail everytime when a field or a value in changed in this path, creating noise
@@ -137,7 +138,7 @@ def test_identifier_multiple(self):
137138
{"CONFIG_DB": {"keys": [{"PORT|Ethernet0": {"alias": "etp1", "description": "etp1", "index": "0", "lanes": "25,26,27,28", "mtu": "9100", "pfc_asym": "off", "speed": "40000"}}], "tables_not_found": []},
138139
"APPL_DB": {"keys": [{"PORT_TABLE:Ethernet0": {"index": "0", "lanes": "0", "alias": "Ethernet0", "description": "ARISTA01T2:Ethernet1", "speed": "25000", "oper_status": "down", "pfc_asym": "off", "mtu": "9100", "fec": "rs", "admin_status": "up"}}], "tables_not_found": []},
139140
"ASIC_DB": {"keys": [{"ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd00000000056d": {"SAI_HOSTIF_ATTR_NAME": "Ethernet0", "SAI_HOSTIF_ATTR_OBJ_ID": "oid:0x10000000004a4", "SAI_HOSTIF_ATTR_OPER_STATUS": "true", "SAI_HOSTIF_ATTR_TYPE": "SAI_HOSTIF_TYPE_NETDEV", "SAI_HOSTIF_ATTR_VLAN_TAG": "SAI_HOSTIF_VLAN_TAG_STRIP"}}, {"ASIC_STATE:SAI_OBJECT_TYPE_PORT:oid:0x10000000004a4": {"NULL": "NULL", "SAI_PORT_ATTR_ADMIN_STATE": "true", "SAI_PORT_ATTR_MTU": "9122", "SAI_PORT_ATTR_SPEED": "100000"}}], "tables_not_found": [], "vidtorid": {"oid:0xd00000000056d": "oid:0xd", "oid:0x10000000004a4": "oid:0x1690000000001"}},
140-
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"speed": "100000", "supported_speeds": "10000,25000,40000,100000"}}], "tables_not_found": []}},
141+
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"rmt_adv_speeds": "10,100,1000", "speed": "100000", "supported_speeds": "10000,25000,40000,100000"}}], "tables_not_found": []}},
141142
"Ethernet4":
142143
{"CONFIG_DB": {"keys": [{"PORT|Ethernet4": {"admin_status": "up", "alias": "etp2", "description": "Servers0:eth0", "index": "1", "lanes": "29,30,31,32", "mtu": "9100", "pfc_asym": "off", "speed": "40000"}}], "tables_not_found": []},
143144
"APPL_DB": {"keys": [], "tables_not_found": ["PORT_TABLE"]},
@@ -166,7 +167,7 @@ def test_option_db_filtering(self):
166167
result = runner.invoke(dump.state, ["port", "Ethernet0", "--db", "ASIC_DB", "--db", "STATE_DB"])
167168
print(result.output)
168169
expected = {"Ethernet0": {"ASIC_DB": {"keys": [{"ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd00000000056d": {"SAI_HOSTIF_ATTR_NAME": "Ethernet0", "SAI_HOSTIF_ATTR_OBJ_ID": "oid:0x10000000004a4", "SAI_HOSTIF_ATTR_OPER_STATUS": "true", "SAI_HOSTIF_ATTR_TYPE": "SAI_HOSTIF_TYPE_NETDEV", "SAI_HOSTIF_ATTR_VLAN_TAG": "SAI_HOSTIF_VLAN_TAG_STRIP"}}, {"ASIC_STATE:SAI_OBJECT_TYPE_PORT:oid:0x10000000004a4": {"NULL": "NULL", "SAI_PORT_ATTR_ADMIN_STATE": "true", "SAI_PORT_ATTR_MTU": "9122", "SAI_PORT_ATTR_SPEED": "100000"}}], "tables_not_found": [], "vidtorid": {"oid:0xd00000000056d": "oid:0xd", "oid:0x10000000004a4": "oid:0x1690000000001"}},
169-
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"speed": "100000", "supported_speeds": "10000,25000,40000,100000"}}], "tables_not_found": []}}}
170+
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"rmt_adv_speeds": "10,100,1000", "speed": "100000", "supported_speeds": "10000,25000,40000,100000"}}], "tables_not_found": []}}}
170171
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
171172
ddiff = compare_json_output(expected, result.output)
172173
assert not ddiff, ddiff

tests/intfutil_test.py

+18-18
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 10M,100M,1G 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 10M,100M,1G 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

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" : "10,100,1000",
686687
"speed" : "100000",
687688
"supported_speeds": "10000,25000,40000,100000"
688689
},

0 commit comments

Comments
 (0)