@@ -260,16 +260,22 @@ def update_if_counters(self):
260
260
for sai_id_key in self .if_id_map :
261
261
namespace , sai_id = mibs .split_sai_id_key (sai_id_key )
262
262
if_idx = mibs .get_index_from_str (self .if_id_map [sai_id_key ])
263
- self .if_counters [if_idx ] = self .namespace_db_map [namespace ].get_all (mibs .COUNTERS_DB , \
264
- mibs .counter_table (sai_id ), blocking = True )
263
+ counters_db_data = self .namespace_db_map [namespace ].get_all (mibs .COUNTERS_DB ,
264
+ mibs .counter_table (sai_id ),
265
+ blocking = True )
266
+ self .if_counters [if_idx ] = {
267
+ counter : int (value ) for counter , value in counters_db_data .items ()
268
+ }
265
269
266
270
def update_rif_counters (self ):
267
271
rif_sai_ids = list (self .rif_port_map ) + list (self .vlan_name_map )
268
- self .rif_counters = \
269
- {sai_id : Namespace .dbs_get_all (self .db_conn , mibs .COUNTERS_DB ,
270
- mibs .counter_table (mibs .split_sai_id_key (sai_id )[1 ]),
271
- blocking = False )
272
- for sai_id in rif_sai_ids }
272
+ for sai_id in rif_sai_ids :
273
+ counters_db_data = Namespace .dbs_get_all (self .db_conn , mibs .COUNTERS_DB ,
274
+ mibs .counter_table (mibs .split_sai_id_key (sai_id )[1 ]),
275
+ blocking = False )
276
+ self .rif_counters [sai_id ] = {
277
+ counter : int (value ) for counter , value in counters_db_data .items ()
278
+ }
273
279
274
280
def get_next (self , sub_id ):
275
281
"""
@@ -329,7 +335,7 @@ def _get_counter(self, oid, table_name):
329
335
try :
330
336
counter_value = self .if_counters [oid ][_table_name ]
331
337
# truncate to 32-bit counter (database implements 64-bit counters)
332
- counter_value = int ( counter_value ) & 0x00000000ffffffff
338
+ counter_value = counter_value & 0x00000000ffffffff
333
339
# done!
334
340
return counter_value
335
341
except KeyError as e :
@@ -348,8 +354,8 @@ def aggregate_counters(self):
348
354
port_idx = mibs .get_index_from_str (self .if_id_map [port_sai_id ])
349
355
for port_counter_name , rif_counter_name in mibs .RIF_DROPS_AGGR_MAP .items ():
350
356
self .if_counters [port_idx ][port_counter_name ] = \
351
- int ( self .if_counters [port_idx ][port_counter_name ]) + \
352
- int ( self .rif_counters [rif_sai_id ][rif_counter_name ])
357
+ self .if_counters [port_idx ][port_counter_name ] + \
358
+ self .rif_counters [rif_sai_id ][rif_counter_name ]
353
359
354
360
for vlan_sai_id , vlan_name in self .vlan_name_map .items ():
355
361
for port_counter_name , rif_counter_name in mibs .RIF_COUNTERS_AGGR_MAP .items ():
@@ -358,7 +364,7 @@ def aggregate_counters(self):
358
364
if rif_counter_name in vlan_rif_counters :
359
365
self .if_counters .setdefault (vlan_idx , {})
360
366
self .if_counters [vlan_idx ][port_counter_name ] = \
361
- int ( vlan_rif_counters [rif_counter_name ])
367
+ vlan_rif_counters [rif_counter_name ]
362
368
363
369
364
370
def get_counter (self , sub_id , table_name ):
@@ -386,7 +392,7 @@ def get_counter(self, sub_id, table_name):
386
392
table_name = getattr (table_name , 'name' , table_name )
387
393
if table_name in mibs .RIF_DROPS_AGGR_MAP :
388
394
rif_table_name = mibs .RIF_DROPS_AGGR_MAP [table_name ]
389
- counter_value += int ( self .rif_counters [sai_lag_rif_id ].get (rif_table_name , 0 ) )
395
+ counter_value += self .rif_counters [sai_lag_rif_id ].get (rif_table_name , 0 )
390
396
# truncate to 32-bit counter
391
397
return counter_value & 0x00000000ffffffff
392
398
else :
0 commit comments