@@ -260,16 +260,22 @@ def update_if_counters(self):
260260 for sai_id_key in self .if_id_map :
261261 namespace , sai_id = mibs .split_sai_id_key (sai_id_key )
262262 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+ }
265269
266270 def update_rif_counters (self ):
267271 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+ }
273279
274280 def get_next (self , sub_id ):
275281 """
@@ -329,7 +335,7 @@ def _get_counter(self, oid, table_name):
329335 try :
330336 counter_value = self .if_counters [oid ][_table_name ]
331337 # truncate to 32-bit counter (database implements 64-bit counters)
332- counter_value = int ( counter_value ) & 0x00000000ffffffff
338+ counter_value = counter_value & 0x00000000ffffffff
333339 # done!
334340 return counter_value
335341 except KeyError as e :
@@ -348,8 +354,8 @@ def aggregate_counters(self):
348354 port_idx = mibs .get_index_from_str (self .if_id_map [port_sai_id ])
349355 for port_counter_name , rif_counter_name in mibs .RIF_DROPS_AGGR_MAP .items ():
350356 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 ]
353359
354360 for vlan_sai_id , vlan_name in self .vlan_name_map .items ():
355361 for port_counter_name , rif_counter_name in mibs .RIF_COUNTERS_AGGR_MAP .items ():
@@ -358,7 +364,7 @@ def aggregate_counters(self):
358364 if rif_counter_name in vlan_rif_counters :
359365 self .if_counters .setdefault (vlan_idx , {})
360366 self .if_counters [vlan_idx ][port_counter_name ] = \
361- int ( vlan_rif_counters [rif_counter_name ])
367+ vlan_rif_counters [rif_counter_name ]
362368
363369
364370 def get_counter (self , sub_id , table_name ):
@@ -386,7 +392,7 @@ def get_counter(self, sub_id, table_name):
386392 table_name = getattr (table_name , 'name' , table_name )
387393 if table_name in mibs .RIF_DROPS_AGGR_MAP :
388394 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 )
390396 # truncate to 32-bit counter
391397 return counter_value & 0x00000000ffffffff
392398 else :
0 commit comments