Skip to content

Commit

Permalink
[rfc1213] fix counter value type (#189)
Browse files Browse the repository at this point in the history
Counter values were stored as a mix of strings and ints.
This caused swsscommon to fail when there is an attempt
to write integer value where strings value was stored.
  • Loading branch information
stepanblyschak authored Dec 29, 2020
1 parent 025483a commit 8efb4bb
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/sonic_ax_impl/mibs/ietf/rfc1213.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,22 @@ def update_if_counters(self):
for sai_id_key in self.if_id_map:
namespace, sai_id = mibs.split_sai_id_key(sai_id_key)
if_idx = mibs.get_index_from_str(self.if_id_map[sai_id_key])
self.if_counters[if_idx] = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB, \
mibs.counter_table(sai_id), blocking=True)
counters_db_data = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB,
mibs.counter_table(sai_id),
blocking=True)
self.if_counters[if_idx] = {
counter: int(value) for counter, value in counters_db_data.items()
}

def update_rif_counters(self):
rif_sai_ids = list(self.rif_port_map) + list(self.vlan_name_map)
self.rif_counters = \
{sai_id: Namespace.dbs_get_all(self.db_conn, mibs.COUNTERS_DB,
mibs.counter_table(mibs.split_sai_id_key(sai_id)[1]),
blocking=False)
for sai_id in rif_sai_ids}
for sai_id in rif_sai_ids:
counters_db_data = Namespace.dbs_get_all(self.db_conn, mibs.COUNTERS_DB,
mibs.counter_table(mibs.split_sai_id_key(sai_id)[1]),
blocking=False)
self.rif_counters[sai_id] = {
counter: int(value) for counter, value in counters_db_data.items()
}

def get_next(self, sub_id):
"""
Expand Down Expand Up @@ -329,7 +335,7 @@ def _get_counter(self, oid, table_name):
try:
counter_value = self.if_counters[oid][_table_name]
# truncate to 32-bit counter (database implements 64-bit counters)
counter_value = int(counter_value) & 0x00000000ffffffff
counter_value = counter_value & 0x00000000ffffffff
# done!
return counter_value
except KeyError as e:
Expand All @@ -348,8 +354,8 @@ def aggregate_counters(self):
port_idx = mibs.get_index_from_str(self.if_id_map[port_sai_id])
for port_counter_name, rif_counter_name in mibs.RIF_DROPS_AGGR_MAP.items():
self.if_counters[port_idx][port_counter_name] = \
int(self.if_counters[port_idx][port_counter_name]) + \
int(self.rif_counters[rif_sai_id][rif_counter_name])
self.if_counters[port_idx][port_counter_name] + \
self.rif_counters[rif_sai_id][rif_counter_name]

for vlan_sai_id, vlan_name in self.vlan_name_map.items():
for port_counter_name, rif_counter_name in mibs.RIF_COUNTERS_AGGR_MAP.items():
Expand All @@ -358,7 +364,7 @@ def aggregate_counters(self):
if rif_counter_name in vlan_rif_counters:
self.if_counters.setdefault(vlan_idx, {})
self.if_counters[vlan_idx][port_counter_name] = \
int(vlan_rif_counters[rif_counter_name])
vlan_rif_counters[rif_counter_name]


def get_counter(self, sub_id, table_name):
Expand Down Expand Up @@ -386,7 +392,7 @@ def get_counter(self, sub_id, table_name):
table_name = getattr(table_name, 'name', table_name)
if table_name in mibs.RIF_DROPS_AGGR_MAP:
rif_table_name = mibs.RIF_DROPS_AGGR_MAP[table_name]
counter_value += int(self.rif_counters[sai_lag_rif_id].get(rif_table_name, 0))
counter_value += self.rif_counters[sai_lag_rif_id].get(rif_table_name, 0)
# truncate to 32-bit counter
return counter_value & 0x00000000ffffffff
else:
Expand Down

0 comments on commit 8efb4bb

Please sign in to comment.