Skip to content

Commit f9dc681

Browse files
authored
[intfutil] Display RJ45 port and portchannel speed in 'M' instead of '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]>
1 parent 781ae9f commit f9dc681

File tree

6 files changed

+169
-17
lines changed

6 files changed

+169
-17
lines changed

scripts/intfutil

+22-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ PORT_ADV_SPEEDS = 'adv_speeds'
4848
PORT_INTERFACE_TYPE = 'interface_type'
4949
PORT_ADV_INTERFACE_TYPES = 'adv_interface_types'
5050
PORT_TPID = "tpid"
51+
OPTICS_TYPE_RJ45 = 'RJ45'
5152

5253
VLAN_SUB_INTERFACE_SEPARATOR = "."
5354
VLAN_SUB_INTERFACE_TYPE = "802.1q-encapsulation"
@@ -131,6 +132,19 @@ def appl_db_sub_intf_keys_get(appl_db, sub_intf_list, sub_intf_name):
131132
return appl_db_sub_intf_keys
132133

133134

135+
def appl_db_port_speed_parse(in_speed, optics_type):
136+
"""
137+
Parse the speed received from application DB
138+
"""
139+
# fetched speed is in megabits per second
140+
speed = int(in_speed)
141+
if optics_type == OPTICS_TYPE_RJ45 and speed <= 1000:
142+
out_speed = '{}M'.format(speed)
143+
else:
144+
out_speed = '{}G'.format(int(speed/1000))
145+
146+
return out_speed
147+
134148
def appl_db_port_status_get(appl_db, intf_name, status_type):
135149
"""
136150
Get the port status
@@ -140,12 +154,14 @@ def appl_db_port_status_get(appl_db, intf_name, status_type):
140154
if status is None:
141155
return "N/A"
142156
if status_type == PORT_SPEED and status != "N/A":
143-
status = '{}G'.format(status[:-3])
157+
optics_type = state_db_port_optics_get(appl_db, intf_name, PORT_OPTICS_TYPE)
158+
status = appl_db_port_speed_parse(status, optics_type)
144159
elif status_type == PORT_ADV_SPEEDS and status != "N/A" and status != "all":
160+
optics_type = state_db_port_optics_get(appl_db, intf_name, PORT_OPTICS_TYPE)
145161
speed_list = status.split(',')
146162
new_speed_list = []
147163
for s in natsorted(speed_list):
148-
new_speed_list.append('{}G'.format(s[:-3]))
164+
new_speed_list.append(appl_db_port_speed_parse(s, optics_type))
149165
status = ','.join(new_speed_list)
150166
return status
151167

@@ -284,16 +300,18 @@ def po_speed_dict(po_int_dict, appl_db):
284300
# If no speed was returned, append None without format
285301
po_list.append(None)
286302
else:
287-
interface_speed = '{}G'.format(interface_speed[:-3])
303+
optics_type = state_db_port_optics_get(appl_db, value[0], PORT_OPTICS_TYPE)
304+
interface_speed = appl_db_port_speed_parse(interface_speed, optics_type)
288305
po_list.append(interface_speed)
289306
elif len(value) > 1:
290307
for intf in value:
291308
temp_speed = port_oper_speed_get_raw(appl_db, intf)
309+
optics_type = state_db_port_optics_get(appl_db, intf, PORT_OPTICS_TYPE)
292310
temp_speed = int(temp_speed) if temp_speed else 0
293311
agg_speed_list.append(temp_speed)
294312
interface_speed = sum(agg_speed_list)
295313
interface_speed = str(interface_speed)
296-
interface_speed = '{}G'.format(interface_speed[:-3])
314+
interface_speed = appl_db_port_speed_parse(interface_speed, optics_type)
297315
po_list.append(interface_speed)
298316
po_speed_dict = dict(po_list[i:i+2] for i in range(0, len(po_list), 2))
299317
return po_speed_dict

tests/intfutil_test.py

+20-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC
1515
--------------- --------------- ------- ----- ----- --------- --------------- ------ ------- --------------- ----------
1616
Ethernet0 0 25G 9100 rs Ethernet0 routed down up QSFP28 or later off
17+
Ethernet16 16 100M 9100 N/A etp5 trunk up up RJ45 off
18+
Ethernet24 24 1G 9100 N/A etp6 trunk up up QSFP28 or later off
19+
Ethernet28 28 1000M 9100 N/A etp8 trunk up up RJ45 off
1720
Ethernet32 13,14,15,16 40G 9100 rs etp9 PortChannel1001 up up N/A off
21+
Ethernet36 9,10,11,12 10M 9100 N/A etp10 routed up up RJ45 off
1822
Ethernet112 93,94,95,96 40G 9100 rs etp29 PortChannel0001 up up N/A off
1923
Ethernet116 89,90,91,92 40G 9100 rs etp30 PortChannel0002 up up N/A off
2024
Ethernet120 101,102,103,104 40G 9100 rs etp31 PortChannel0003 up up N/A off
@@ -33,14 +37,18 @@
3337
"""
3438

3539
show_interface_description_output="""\
36-
Interface Oper Admin Alias Description
37-
----------- ------ ------- --------- --------------------
38-
Ethernet0 down up Ethernet0 ARISTA01T2:Ethernet1
39-
Ethernet32 up up etp9 Servers7:eth0
40-
Ethernet112 up up etp29 ARISTA01T1:Ethernet1
41-
Ethernet116 up up etp30 ARISTA02T1:Ethernet1
42-
Ethernet120 up up etp31 ARISTA03T1:Ethernet1
43-
Ethernet124 up up etp32 ARISTA04T1:Ethernet1
40+
Interface Oper Admin Alias Description
41+
----------- ------ ------- --------- ---------------------
42+
Ethernet0 down up Ethernet0 ARISTA01T2:Ethernet1
43+
Ethernet16 up up etp5 ARISTA04T1:Ethernet16
44+
Ethernet24 up up etp6 ARISTA02T1:Ethernet24
45+
Ethernet28 up up etp8 ARISTA03T1:Ethernet28
46+
Ethernet32 up up etp9 Servers7:eth0
47+
Ethernet36 up up etp10 Servers8:eth0
48+
Ethernet112 up up etp29 ARISTA01T1:Ethernet1
49+
Ethernet116 up up etp30 ARISTA02T1:Ethernet1
50+
Ethernet120 up up etp31 ARISTA03T1:Ethernet1
51+
Ethernet124 up up etp32 ARISTA04T1:Ethernet1
4452
"""
4553

4654
show_interface_description_Ethernet0_output="""\
@@ -66,7 +74,11 @@
6674
Interface Auto-Neg Mode Speed Adv Speeds Type Adv Types Oper Admin
6775
----------- --------------- ------- ------------ ------ ----------- ------ -------
6876
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
6980
Ethernet32 disabled 40G all N/A all up up
81+
Ethernet36 N/A 10M N/A N/A N/A up up
7082
Ethernet112 N/A 40G N/A N/A N/A up up
7183
Ethernet116 N/A 40G N/A N/A N/A up up
7284
Ethernet120 N/A 40G N/A N/A N/A up up

tests/mock_tables/appl_db.json

+46
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,52 @@
4141
"adv_interface_types": "CR4,CR2",
4242
"autoneg": "on"
4343
},
44+
"PORT_TABLE:Ethernet16": {
45+
"index": "4",
46+
"lanes": "16",
47+
"alias": "etp5",
48+
"description": "ARISTA04T1:Ethernet16",
49+
"speed": "100",
50+
"oper_status": "up",
51+
"pfc_asym": "off",
52+
"mtu": "9100",
53+
"admin_status": "up"
54+
},
55+
"PORT_TABLE:Ethernet36": {
56+
"index": "9",
57+
"lanes": "9,10,11,12",
58+
"alias": "etp10",
59+
"description": "Servers8:eth0",
60+
"speed": "10",
61+
"oper_status": "up",
62+
"pfc_asym": "off",
63+
"mtu": "9100",
64+
"tpid": "0x8100",
65+
"admin_status": "up"
66+
},
67+
"PORT_TABLE:Ethernet24": {
68+
"index": "6",
69+
"lanes": "24",
70+
"alias": "etp6",
71+
"description": "ARISTA02T1:Ethernet24",
72+
"speed": "1000",
73+
"oper_status": "up",
74+
"pfc_asym": "off",
75+
"mtu": "9100",
76+
"tpid": "0x8100",
77+
"admin_status": "up"
78+
},
79+
"PORT_TABLE:Ethernet28": {
80+
"index": "7",
81+
"lanes": "28",
82+
"alias": "etp8",
83+
"description": "ARISTA03T1:Ethernet28",
84+
"speed": "1000",
85+
"oper_status": "up",
86+
"pfc_asym": "off",
87+
"mtu": "9100",
88+
"admin_status": "up"
89+
},
4490
"PORT_TABLE:Ethernet32": {
4591
"index": "8",
4692
"lanes": "13,14,15,16",

tests/mock_tables/config_db.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@
7070
"alias": "etp5",
7171
"description": "Servers3:eth0",
7272
"index": "4",
73-
"lanes": "45,46,47,48",
73+
"lanes": "16",
7474
"mtu": "9100",
7575
"tpid": "0x8100",
7676
"pfc_asym": "off",
77-
"speed": "40000"
77+
"speed": "100"
7878
},
7979
"PORT|Ethernet20": {
8080
"admin_status": "up",
@@ -96,7 +96,7 @@
9696
"mtu": "9100",
9797
"tpid": "0x8100",
9898
"pfc_asym": "off",
99-
"speed": "40000"
99+
"speed": "1000"
100100
},
101101
"PORT|Ethernet28": {
102102
"admin_status": "up",
@@ -107,7 +107,7 @@
107107
"mtu": "9100",
108108
"tpid": "0x8100",
109109
"pfc_asym": "off",
110-
"speed": "40000"
110+
"speed": "1000"
111111
},
112112
"PORT|Ethernet32": {
113113
"admin_status": "up",
@@ -129,7 +129,7 @@
129129
"mtu": "9100",
130130
"tpid": "0x8100",
131131
"pfc_asym": "off",
132-
"speed": "40000"
132+
"speed": "10"
133133
},
134134
"PORT|Ethernet40": {
135135
"admin_status": "up",

tests/mock_tables/state_db.json

+72
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,78 @@
133133
"txpowerlowalarm": "-10.5012",
134134
"txpowerlowwarning": "-7.5007"
135135
},
136+
"TRANSCEIVER_INFO|Ethernet16": {
137+
"type": "RJ45",
138+
"hardware_rev": "N/A",
139+
"serial": "N/A",
140+
"manufacturer": "N/A",
141+
"model": "N/A",
142+
"vendor_oui": "N/A",
143+
"vendor_date": "N/A",
144+
"connector": "N/A",
145+
"encoding": "N/A",
146+
"ext_identifier": "N/A",
147+
"ext_rateselect_compliance": "N/A",
148+
"cable_type": "N/A",
149+
"cable_length": "N/A",
150+
"specification_compliance": "N/A",
151+
"nominal_bit_rate": "N/A",
152+
"application_advertisement": "N/A"
153+
},
154+
"TRANSCEIVER_INFO|Ethernet36": {
155+
"type": "RJ45",
156+
"hardware_rev": "N/A",
157+
"serial": "N/A",
158+
"manufacturer": "N/A",
159+
"model": "N/A",
160+
"vendor_oui": "N/A",
161+
"vendor_date": "N/A",
162+
"connector": "N/A",
163+
"encoding": "N/A",
164+
"ext_identifier": "N/A",
165+
"ext_rateselect_compliance": "N/A",
166+
"cable_type": "N/A",
167+
"cable_length": "N/A",
168+
"specification_compliance": "N/A",
169+
"nominal_bit_rate": "N/A",
170+
"application_advertisement": "N/A"
171+
},
172+
"TRANSCEIVER_INFO|Ethernet24": {
173+
"type": "QSFP28 or later",
174+
"hardware_rev": "AC",
175+
"serial": "MT1706FT02066",
176+
"manufacturer": "Mellanox",
177+
"model": "MFA1A00-C003",
178+
"vendor_oui": "00-02-c9",
179+
"vendor_date": "2017-01-13 ",
180+
"connector": "No separable connector",
181+
"encoding": "64B66B",
182+
"ext_identifier": "Power Class 3(2.5W max), CDR present in Rx Tx",
183+
"ext_rateselect_compliance": "QSFP+ Rate Select Version 1",
184+
"cable_type": "Length Cable Assembly(m)",
185+
"cable_length": "3",
186+
"specification_compliance": "{'10/40G Ethernet Compliance Code': '40G Active Cable (XLPPI)'}",
187+
"nominal_bit_rate": "255",
188+
"application_advertisement": "N/A"
189+
},
190+
"TRANSCEIVER_INFO|Ethernet28": {
191+
"type": "RJ45",
192+
"hardware_rev": "N/A",
193+
"serial": "N/A",
194+
"manufacturer": "N/A",
195+
"model": "N/A",
196+
"vendor_oui": "N/A",
197+
"vendor_date": "N/A",
198+
"connector": "N/A",
199+
"encoding": "N/A",
200+
"ext_identifier": "N/A",
201+
"ext_rateselect_compliance": "N/A",
202+
"cable_type": "N/A",
203+
"cable_length": "N/A",
204+
"specification_compliance": "N/A",
205+
"nominal_bit_rate": "N/A",
206+
"application_advertisement": "N/A"
207+
},
136208
"TRANSCEIVER_STATUS|Ethernet0": {
137209
"status": "67",
138210
"error": "Blocking Error|High temperature"

tests/tpid_test.py

+4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@
4848
Interface Alias Oper Admin TPID
4949
--------------- --------- ------ ------- ------
5050
Ethernet0 Ethernet0 down up 0x9200
51+
Ethernet16 etp5 up up N/A
52+
Ethernet24 etp6 up up 0x8100
53+
Ethernet28 etp8 up up N/A
5154
Ethernet32 etp9 up up 0x8100
55+
Ethernet36 etp10 up up 0x8100
5256
Ethernet112 etp29 up up 0x8100
5357
Ethernet116 etp30 up up 0x8100
5458
Ethernet120 etp31 up up 0x8100

0 commit comments

Comments
 (0)