Skip to content

Commit

Permalink
[201911] Fix interface counters in RFC1213 (sonic-net#144)
Browse files Browse the repository at this point in the history
* Fix interface counters in RFC1213.

Signed-off-by: SuvarnaMeenakshi <[email protected]>

* Added comment.

Signed-off-by: SuvarnaMeenakshi <[email protected]>

* Remove test comment.

Signed-off-by: SuvarnaMeenakshi <[email protected]>
  • Loading branch information
SuvarnaMeenakshi authored Jul 15, 2020
1 parent 6429835 commit 2ba72d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/sonic_ax_impl/mibs/ietf/rfc1213.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ax_interface.mib import MIBMeta, ValueType, MIBUpdater, MIBEntry, SubtreeMIBEntry, OverlayAdpaterMIBEntry, OidMIBEntry
from ax_interface.encodings import ObjectIdentifier
from ax_interface.util import mac_decimals, ip2tuple_v4
from swsssdk.port_util import get_index_from_str

@unique
class DbTables(int, Enum):
Expand Down Expand Up @@ -168,6 +169,7 @@ def __init__(self):
self.if_id_map = {}
self.oid_sai_map = {}
self.oid_name_map = {}
self.namespace_db_map = Namespace.get_namespace_db_map(self.db_conn)

def reinit_data(self):
"""
Expand All @@ -191,9 +193,11 @@ def update_data(self):
Update redis (caches config)
Pulls the table references for each interface.
"""
self.if_counters = \
{sai_id: Namespace.dbs_get_all(self.db_conn, mibs.COUNTERS_DB, mibs.counter_table(sai_id), blocking=True)
for sai_id in self.if_id_map}
for sai_id_key in self.if_id_map:
namespace, sai_id = mibs.split_sai_id_key(sai_id_key)
if_idx = get_index_from_str(self.if_id_map[sai_id_key].decode())
self.if_counters[if_idx] = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB, \
mibs.counter_table(sai_id), blocking=True)

self.lag_name_if_name_map, \
self.if_name_lag_name_map, \
Expand Down Expand Up @@ -254,12 +258,10 @@ def _get_counter(self, oid, table_name):
:param table_name: the redis table (either IntEnum or string literal) to query.
:return: the counter for the respective sub_id/table.
"""
sai_id = self.oid_sai_map[oid]
# Enum.name or table_name = 'name_of_the_table'
_table_name = bytes(getattr(table_name, 'name', table_name), 'utf-8')

try:
counter_value = self.if_counters[sai_id][_table_name]
counter_value = self.if_counters[oid][_table_name]
# truncate to 32-bit counter (database implements 64-bit counters)
counter_value = int(counter_value) & 0x00000000ffffffff
# done!
Expand Down
2 changes: 0 additions & 2 deletions tests/namespace/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
class TestGetNextPDU(TestCase):
@classmethod
def setUpClass(cls):
cls.skipTest(cls, "TODO: Need to update corresponding MIB implementation \
in the Snmp Agent for multiple namespaces/multi-asic")
tests.mock_tables.dbconnector.load_namespace_config()
importlib.reload(rfc1213)
cls.lut = MIBTable(rfc1213.InterfacesMIB)
Expand Down

0 comments on commit 2ba72d8

Please sign in to comment.