@@ -48,6 +48,7 @@ PORT_ADV_SPEEDS = 'adv_speeds'
48
48
PORT_INTERFACE_TYPE = 'interface_type'
49
49
PORT_ADV_INTERFACE_TYPES = 'adv_interface_types'
50
50
PORT_TPID = "tpid"
51
+ OPTICS_TYPE_RJ45 = 'RJ45'
51
52
52
53
VLAN_SUB_INTERFACE_SEPARATOR = "."
53
54
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):
131
132
return appl_db_sub_intf_keys
132
133
133
134
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
+
134
148
def appl_db_port_status_get (appl_db , intf_name , status_type ):
135
149
"""
136
150
Get the port status
@@ -140,12 +154,14 @@ def appl_db_port_status_get(appl_db, intf_name, status_type):
140
154
if status is None :
141
155
return "N/A"
142
156
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 )
144
159
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 )
145
161
speed_list = status .split (',' )
146
162
new_speed_list = []
147
163
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 ))
149
165
status = ',' .join (new_speed_list )
150
166
return status
151
167
@@ -284,16 +300,18 @@ def po_speed_dict(po_int_dict, appl_db):
284
300
# If no speed was returned, append None without format
285
301
po_list .append (None )
286
302
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 )
288
305
po_list .append (interface_speed )
289
306
elif len (value ) > 1 :
290
307
for intf in value :
291
308
temp_speed = port_oper_speed_get_raw (appl_db , intf )
309
+ optics_type = state_db_port_optics_get (appl_db , intf , PORT_OPTICS_TYPE )
292
310
temp_speed = int (temp_speed ) if temp_speed else 0
293
311
agg_speed_list .append (temp_speed )
294
312
interface_speed = sum (agg_speed_list )
295
313
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 )
297
315
po_list .append (interface_speed )
298
316
po_speed_dict = dict (po_list [i :i + 2 ] for i in range (0 , len (po_list ), 2 ))
299
317
return po_speed_dict
0 commit comments