Skip to content

Commit

Permalink
[intfutil] Display RJ45 port and portchannel speed in 'M' instead of …
Browse files Browse the repository at this point in the history
…'G' when it's <= 1000M (#2110)

* enhance port speed for RJ45 ports

Signed-off-by: Kebo Liu <[email protected]>

* fix speed notation for the speed of LAG port based on RJ45 ports

* on RJ45 ports display speed with unit 'M' when it's <= 1000M

Signed-off-by: Kebo Liu <[email protected]>
  • Loading branch information
keboliu authored Apr 18, 2022
1 parent 781ae9f commit f9dc681
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 17 deletions.
26 changes: 22 additions & 4 deletions scripts/intfutil
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -131,6 +132,19 @@ 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 optics_type == OPTICS_TYPE_RJ45 and 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
Expand All @@ -140,12 +154,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

Expand Down Expand Up @@ -284,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
Expand Down
28 changes: 20 additions & 8 deletions tests/intfutil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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="""\
Expand All @@ -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
Expand Down
46 changes: 46 additions & 0 deletions tests/mock_tables/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -96,7 +96,7 @@
"mtu": "9100",
"tpid": "0x8100",
"pfc_asym": "off",
"speed": "40000"
"speed": "1000"
},
"PORT|Ethernet28": {
"admin_status": "up",
Expand All @@ -107,7 +107,7 @@
"mtu": "9100",
"tpid": "0x8100",
"pfc_asym": "off",
"speed": "40000"
"speed": "1000"
},
"PORT|Ethernet32": {
"admin_status": "up",
Expand All @@ -129,7 +129,7 @@
"mtu": "9100",
"tpid": "0x8100",
"pfc_asym": "off",
"speed": "40000"
"speed": "10"
},
"PORT|Ethernet40": {
"admin_status": "up",
Expand Down
72 changes: 72 additions & 0 deletions tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions tests/tpid_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f9dc681

Please sign in to comment.