From 397da40438c9f3f129761245befa1c8647470922 Mon Sep 17 00:00:00 2001 From: Kebo Liu Date: Mon, 27 Dec 2021 23:29:15 +0800 Subject: [PATCH 1/3] enhance port speed for RJ45 ports Signed-off-by: Kebo Liu --- scripts/intfutil | 28 +++++++++++-- tests/intfutil_test.py | 28 +++++++++---- tests/mock_tables/appl_db.json | 46 ++++++++++++++++++++ tests/mock_tables/config_db.json | 10 ++--- tests/mock_tables/state_db.json | 72 ++++++++++++++++++++++++++++++++ tests/tpid_test.py | 4 ++ 6 files changed, 171 insertions(+), 17 deletions(-) diff --git a/scripts/intfutil b/scripts/intfutil index 1a42640529..a055f6ba04 100755 --- a/scripts/intfutil +++ b/scripts/intfutil @@ -48,6 +48,7 @@ PORT_ADV_SPEEDS = 'adv_speeds' PORT_INTERFACE_TYPE = 'interface_type' PORT_ADV_INTERFACE_TYPES = 'adv_interface_types' PORT_TPID = "tpid" +OPTICS_TYPE_RJ45 = 'RJ45' VLAN_SUB_INTERFACE_SEPARATOR = "." VLAN_SUB_INTERFACE_TYPE = "802.1q-encapsulation" @@ -131,6 +132,21 @@ def appl_db_sub_intf_keys_get(appl_db, sub_intf_list, sub_intf_name): return appl_db_sub_intf_keys +def appl_db_port_speed_parse(in_speed, optics_type): + """ + Parse the speed received from application DB + """ + # fetched speed is in megabits per second + speed = int(in_speed) + if speed == 1000 and optics_type == OPTICS_TYPE_RJ45: + out_speed = '{}M'.format(speed) + elif speed < 1000: + out_speed = '{}M'.format(speed) + else: + out_speed = '{}G'.format(int(speed/1000)) + + return out_speed + def appl_db_port_status_get(appl_db, intf_name, status_type): """ Get the port status @@ -140,12 +156,14 @@ def appl_db_port_status_get(appl_db, intf_name, status_type): if status is None: return "N/A" if status_type == PORT_SPEED and status != "N/A": - status = '{}G'.format(status[:-3]) + optics_type = state_db_port_optics_get(appl_db, intf_name, PORT_OPTICS_TYPE) + status = appl_db_port_speed_parse(status, optics_type) elif status_type == PORT_ADV_SPEEDS and status != "N/A" and status != "all": + optics_type = state_db_port_optics_get(appl_db, intf_name, PORT_OPTICS_TYPE) speed_list = status.split(',') new_speed_list = [] for s in natsorted(speed_list): - new_speed_list.append('{}G'.format(s[:-3])) + new_speed_list.append(appl_db_port_speed_parse(s, optics_type)) status = ','.join(new_speed_list) return status @@ -282,16 +300,18 @@ def po_speed_dict(po_int_dict, appl_db): # If no speed was returned, append None without format po_list.append(None) else: - interface_speed = '{}G'.format(interface_speed[:-3]) + optics_type = state_db_port_optics_get(appl_db, value[0], PORT_OPTICS_TYPE) + interface_speed = appl_db_port_speed_parse(interface_speed, optics_type) po_list.append(interface_speed) elif len(value) > 1: for intf in value: temp_speed = port_oper_speed_get_raw(appl_db, intf) + optics_type = state_db_port_optics_get(appl_db, intf, PORT_OPTICS_TYPE) temp_speed = int(temp_speed) if temp_speed else 0 agg_speed_list.append(temp_speed) interface_speed = sum(agg_speed_list) interface_speed = str(interface_speed) - interface_speed = '{}G'.format(interface_speed[:-3]) + interface_speed = appl_db_port_speed_parse(interface_speed, optics_type) po_list.append(interface_speed) po_speed_dict = dict(po_list[i:i+2] for i in range(0, len(po_list), 2)) return po_speed_dict diff --git a/tests/intfutil_test.py b/tests/intfutil_test.py index cfca1dbd6d..0129573881 100644 --- a/tests/intfutil_test.py +++ b/tests/intfutil_test.py @@ -14,7 +14,11 @@ Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC --------------- --------------- ------- ----- ----- --------- --------------- ------ ------- --------------- ---------- Ethernet0 0 25G 9100 rs Ethernet0 routed down up QSFP28 or later off + Ethernet16 16 100M 9100 N/A etp5 trunk up up RJ45 off + Ethernet24 24 1G 9100 N/A etp6 trunk up up QSFP28 or later off + Ethernet28 28 1000M 9100 N/A etp8 trunk up up RJ45 off Ethernet32 13,14,15,16 40G 9100 rs etp9 PortChannel1001 up up N/A off + Ethernet36 9,10,11,12 10M 9100 N/A etp10 routed up up RJ45 off Ethernet112 93,94,95,96 40G 9100 rs etp29 PortChannel0001 up up N/A off Ethernet116 89,90,91,92 40G 9100 rs etp30 PortChannel0002 up up N/A off Ethernet120 101,102,103,104 40G 9100 rs etp31 PortChannel0003 up up N/A off @@ -33,14 +37,18 @@ """ show_interface_description_output="""\ - Interface Oper Admin Alias Description ------------ ------ ------- --------- -------------------- - Ethernet0 down up Ethernet0 ARISTA01T2:Ethernet1 - Ethernet32 up up etp9 Servers7:eth0 -Ethernet112 up up etp29 ARISTA01T1:Ethernet1 -Ethernet116 up up etp30 ARISTA02T1:Ethernet1 -Ethernet120 up up etp31 ARISTA03T1:Ethernet1 -Ethernet124 up up etp32 ARISTA04T1:Ethernet1 + Interface Oper Admin Alias Description +----------- ------ ------- --------- --------------------- + Ethernet0 down up Ethernet0 ARISTA01T2:Ethernet1 + Ethernet16 up up etp5 ARISTA04T1:Ethernet16 + Ethernet24 up up etp6 ARISTA02T1:Ethernet24 + Ethernet28 up up etp8 ARISTA03T1:Ethernet28 + Ethernet32 up up etp9 Servers7:eth0 + Ethernet36 up up etp10 Servers8:eth0 +Ethernet112 up up etp29 ARISTA01T1:Ethernet1 +Ethernet116 up up etp30 ARISTA02T1:Ethernet1 +Ethernet120 up up etp31 ARISTA03T1:Ethernet1 +Ethernet124 up up etp32 ARISTA04T1:Ethernet1 """ show_interface_description_Ethernet0_output="""\ @@ -66,7 +74,11 @@ 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 diff --git a/tests/mock_tables/appl_db.json b/tests/mock_tables/appl_db.json index 0da2ec6c1d..81fa7c7297 100644 --- a/tests/mock_tables/appl_db.json +++ b/tests/mock_tables/appl_db.json @@ -41,6 +41,52 @@ "adv_interface_types": "CR4,CR2", "autoneg": "on" }, + "PORT_TABLE:Ethernet16": { + "index": "4", + "lanes": "16", + "alias": "etp5", + "description": "ARISTA04T1:Ethernet16", + "speed": "100", + "oper_status": "up", + "pfc_asym": "off", + "mtu": "9100", + "admin_status": "up" + }, + "PORT_TABLE:Ethernet36": { + "index": "9", + "lanes": "9,10,11,12", + "alias": "etp10", + "description": "Servers8:eth0", + "speed": "10", + "oper_status": "up", + "pfc_asym": "off", + "mtu": "9100", + "tpid": "0x8100", + "admin_status": "up" + }, + "PORT_TABLE:Ethernet24": { + "index": "6", + "lanes": "24", + "alias": "etp6", + "description": "ARISTA02T1:Ethernet24", + "speed": "1000", + "oper_status": "up", + "pfc_asym": "off", + "mtu": "9100", + "tpid": "0x8100", + "admin_status": "up" + }, + "PORT_TABLE:Ethernet28": { + "index": "7", + "lanes": "28", + "alias": "etp8", + "description": "ARISTA03T1:Ethernet28", + "speed": "1000", + "oper_status": "up", + "pfc_asym": "off", + "mtu": "9100", + "admin_status": "up" + }, "PORT_TABLE:Ethernet32": { "index": "8", "lanes": "13,14,15,16", diff --git a/tests/mock_tables/config_db.json b/tests/mock_tables/config_db.json index 9b618df3b3..23360c4200 100644 --- a/tests/mock_tables/config_db.json +++ b/tests/mock_tables/config_db.json @@ -70,11 +70,11 @@ "alias": "etp5", "description": "Servers3:eth0", "index": "4", - "lanes": "45,46,47,48", + "lanes": "16", "mtu": "9100", "tpid": "0x8100", "pfc_asym": "off", - "speed": "40000" + "speed": "100" }, "PORT|Ethernet20": { "admin_status": "up", @@ -96,7 +96,7 @@ "mtu": "9100", "tpid": "0x8100", "pfc_asym": "off", - "speed": "40000" + "speed": "1000" }, "PORT|Ethernet28": { "admin_status": "up", @@ -107,7 +107,7 @@ "mtu": "9100", "tpid": "0x8100", "pfc_asym": "off", - "speed": "40000" + "speed": "1000" }, "PORT|Ethernet32": { "admin_status": "up", @@ -129,7 +129,7 @@ "mtu": "9100", "tpid": "0x8100", "pfc_asym": "off", - "speed": "40000" + "speed": "10" }, "PORT|Ethernet40": { "admin_status": "up", diff --git a/tests/mock_tables/state_db.json b/tests/mock_tables/state_db.json index 6145868a9b..321e33e68f 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -133,6 +133,78 @@ "txpowerlowalarm": "-10.5012", "txpowerlowwarning": "-7.5007" }, + "TRANSCEIVER_INFO|Ethernet16": { + "type": "RJ45", + "hardware_rev": "N/A", + "serial": "N/A", + "manufacturer": "N/A", + "model": "N/A", + "vendor_oui": "N/A", + "vendor_date": "N/A", + "connector": "N/A", + "encoding": "N/A", + "ext_identifier": "N/A", + "ext_rateselect_compliance": "N/A", + "cable_type": "N/A", + "cable_length": "N/A", + "specification_compliance": "N/A", + "nominal_bit_rate": "N/A", + "application_advertisement": "N/A" + }, + "TRANSCEIVER_INFO|Ethernet36": { + "type": "RJ45", + "hardware_rev": "N/A", + "serial": "N/A", + "manufacturer": "N/A", + "model": "N/A", + "vendor_oui": "N/A", + "vendor_date": "N/A", + "connector": "N/A", + "encoding": "N/A", + "ext_identifier": "N/A", + "ext_rateselect_compliance": "N/A", + "cable_type": "N/A", + "cable_length": "N/A", + "specification_compliance": "N/A", + "nominal_bit_rate": "N/A", + "application_advertisement": "N/A" + }, + "TRANSCEIVER_INFO|Ethernet24": { + "type": "QSFP28 or later", + "hardware_rev": "AC", + "serial": "MT1706FT02066", + "manufacturer": "Mellanox", + "model": "MFA1A00-C003", + "vendor_oui": "00-02-c9", + "vendor_date": "2017-01-13 ", + "connector": "No separable connector", + "encoding": "64B66B", + "ext_identifier": "Power Class 3(2.5W max), CDR present in Rx Tx", + "ext_rateselect_compliance": "QSFP+ Rate Select Version 1", + "cable_type": "Length Cable Assembly(m)", + "cable_length": "3", + "specification_compliance": "{'10/40G Ethernet Compliance Code': '40G Active Cable (XLPPI)'}", + "nominal_bit_rate": "255", + "application_advertisement": "N/A" + }, + "TRANSCEIVER_INFO|Ethernet28": { + "type": "RJ45", + "hardware_rev": "N/A", + "serial": "N/A", + "manufacturer": "N/A", + "model": "N/A", + "vendor_oui": "N/A", + "vendor_date": "N/A", + "connector": "N/A", + "encoding": "N/A", + "ext_identifier": "N/A", + "ext_rateselect_compliance": "N/A", + "cable_type": "N/A", + "cable_length": "N/A", + "specification_compliance": "N/A", + "nominal_bit_rate": "N/A", + "application_advertisement": "N/A" + }, "TRANSCEIVER_STATUS|Ethernet0": { "status": "67", "error": "Blocking Error|High temperature" diff --git a/tests/tpid_test.py b/tests/tpid_test.py index 0c3ca4feee..b4c56ff084 100644 --- a/tests/tpid_test.py +++ b/tests/tpid_test.py @@ -48,7 +48,11 @@ Interface Alias Oper Admin TPID --------------- --------- ------ ------- ------ Ethernet0 Ethernet0 down up 0x9200 + Ethernet16 etp5 up up N/A + Ethernet24 etp6 up up 0x8100 + Ethernet28 etp8 up up N/A Ethernet32 etp9 up up 0x8100 + Ethernet36 etp10 up up 0x8100 Ethernet112 etp29 up up 0x8100 Ethernet116 etp30 up up 0x8100 Ethernet120 etp31 up up 0x8100 From 5786e217309ed101bdc00553578973d3ddb86f7e Mon Sep 17 00:00:00 2001 From: Kebo Liu Date: Tue, 22 Mar 2022 19:08:46 +0800 Subject: [PATCH 2/3] fix speed notation for the speed of LAG port based on RJ45 ports --- scripts/intfutil | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/intfutil b/scripts/intfutil index a055f6ba04..f51412595d 100755 --- a/scripts/intfutil +++ b/scripts/intfutil @@ -138,9 +138,7 @@ def appl_db_port_speed_parse(in_speed, optics_type): """ # fetched speed is in megabits per second speed = int(in_speed) - if speed == 1000 and optics_type == OPTICS_TYPE_RJ45: - out_speed = '{}M'.format(speed) - elif speed < 1000: + if optics_type == OPTICS_TYPE_RJ45: out_speed = '{}M'.format(speed) else: out_speed = '{}G'.format(int(speed/1000)) From af85cc4d6f058b6a0bb7749d65440551d3712d0f Mon Sep 17 00:00:00 2001 From: Kebo Liu Date: Tue, 12 Apr 2022 13:36:30 +0800 Subject: [PATCH 3/3] on RJ45 ports display speed with unit 'M' when it's <= 1000M Signed-off-by: Kebo Liu --- scripts/intfutil | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/intfutil b/scripts/intfutil index f51412595d..6db2b6d1a6 100755 --- a/scripts/intfutil +++ b/scripts/intfutil @@ -138,7 +138,7 @@ def appl_db_port_speed_parse(in_speed, optics_type): """ # fetched speed is in megabits per second speed = int(in_speed) - if optics_type == OPTICS_TYPE_RJ45: + if optics_type == OPTICS_TYPE_RJ45 and speed <= 1000: out_speed = '{}M'.format(speed) else: out_speed = '{}G'.format(int(speed/1000))