Skip to content

Commit

Permalink
Modify pfc and qos counters MIB for Namespace related changes.
Browse files Browse the repository at this point in the history
Revert FDB MIB namespace related changes.

Signed-off-by: SuvarnaMeenakshi <[email protected]>
  • Loading branch information
SuvarnaMeenakshi committed Jul 28, 2020
1 parent 9edee89 commit 4cf3c25
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 50 deletions.
17 changes: 12 additions & 5 deletions src/sonic_ax_impl/mibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def init_namespace_sync_d_interface_tables(dbs):
oid_name_map_ns = init_sync_d_interface_tables(db_conn)
if_name_map.update(if_name_map_ns)
if_alias_map.update(if_alias_map_ns)
if_id_map[inst] = if_id_map_ns
if_id_map.update(if_id_map_ns)
oid_sai_map.update(oid_sai_map_ns)
oid_name_map.update(oid_name_map_ns)

Expand Down Expand Up @@ -634,13 +634,20 @@ def init_namespace_sync_d_queue_tables(dbs):
return port_queues_map, queue_stat_map, port_queue_list_map

@staticmethod
def dbs_get_bridge_port_map(dbs):
def dbs_get_bridge_port_map(dbs, db_name):
"""
get_bridge_port_map from all namespace DBs
"""
if_br_oid_map = {}
for inst in range(Namespace.get_start_idx_of_non_host(dbs), len(dbs)):
if_br_oid_map_ns = port_util.get_bridge_port_map(dbs[inst])
if_br_oid_map[inst] = if_br_oid_map_ns
for db_conn in Namespace.get_non_host_dbs(dbs):
if_br_oid_map_ns = port_util.get_bridge_port_map(db_conn)
if_br_oid_map.update(if_br_oid_map_ns)
return if_br_oid_map

@staticmethod
def dbs_get_vlan_id_from_bvid(dbs, bvid):
for db_conn in Namespace.get_non_host_dbs(dbs):
db_conn.connect('ASIC_DB')
vlan_obj = db_conn.keys('ASIC_DB', "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:" + bvid)
if vlan_obj is not None:
return port_util.get_vlan_id_from_bvid(db_conn, bvid)
57 changes: 26 additions & 31 deletions src/sonic_ax_impl/mibs/ietf/rfc4363.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ def __init__(self):
self.if_bpid_map = {}
self.bvid_vlan_map = {}

def fdb_vlanmac(self, fdb, db_index):
def fdb_vlanmac(self, fdb):
if 'vlan' in fdb:
vlan_id = fdb["vlan"]
elif 'bvid' in fdb:
if fdb["bvid"] in self.bvid_vlan_map:
vlan_id = self.bvid_vlan_map[fdb["bvid"]]
else:
vlan_id = port_util.get_vlan_id_from_bvid(self.db_conn[db_index], fdb["bvid"])
vlan_id = Namespace.dbs_get_vlan_id_from_bvid(self.db_conn, fdb["bvid"])
self.bvid_vlan_map[fdb["bvid"]] = vlan_id
return (int(vlan_id),) + mac_decimals(fdb["mac"])

def reinit_data(self):
"""
Subclass update interface information
Expand All @@ -41,7 +41,7 @@ def reinit_data(self):
self.if_alias_map, \
self.if_id_map, \
self.oid_sai_map, \
self.oid_name_map, _ = Namespace.init_namespace_sync_d_interface_tables(self.db_conn)
self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn)

self.if_bpid_map = Namespace.dbs_get_bridge_port_map(self.db_conn, mibs.ASIC_DB)
self.bvid_vlan_map.clear()
Expand All @@ -54,33 +54,28 @@ def update_data(self):
self.vlanmac_ifindex_map = {}
self.vlanmac_ifindex_list = []

Namespace.connect_all_dbs(self.db_conn, mibs.ASIC_DB)

for db_index in range(Namespace.get_start_idx_of_non_host(self.db_conn), len(self.db_conn)):
fdb_strings = self.db_conn[db_index].keys(mibs.ASIC_DB, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:*")
if not fdb_strings:
continue
for s in fdb_strings:
fdb_str = s.decode()
try:
fdb = json.loads(fdb_str.split(":", maxsplit=2)[-1])
except ValueError as e: # includes simplejson.decoder.JSONDecodeError
mibs.logger.error("SyncD 'ASIC_DB' includes invalid FDB_ENTRY '{}': {}.".format(fdb_str, e))
break

ent = self.db_conn[db_index].get_all(mibs.ASIC_DB, s, blocking=True)
# Example output: oid:0x3a000000000608
bridge_port_id = ent[b"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID"][6:]
#if_bpid_map = self.if_bpid_map[db_index]
if db_index not in self.if_bpid_map or db_index not in self.if_id_map:
continue
if bridge_port_id not in self.if_bpid_map[db_index]:
continue
port_id = self.if_bpid_map[db_index][bridge_port_id]

vlanmac = self.fdb_vlanmac(fdb, db_index)
self.vlanmac_ifindex_map[vlanmac] = mibs.get_index(self.if_id_map[db_index][port_id])
self.vlanmac_ifindex_list.append(vlanmac)
fdb_strings = Namespace.dbs_keys(self.db_conn, mibs.ASIC_DB, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:*")
if not fdb_strings:
return

for s in fdb_strings:
fdb_str = s.decode()
try:
fdb = json.loads(fdb_str.split(":", maxsplit=2)[-1])
except ValueError as e: # includes simplejson.decoder.JSONDecodeError
mibs.logger.error("SyncD 'ASIC_DB' includes invalid FDB_ENTRY '{}': {}.".format(fdb_str, e))
break

ent = Namespace.dbs_get_all(self.db_conn, mibs.ASIC_DB, s, blocking=True)
# Example output: oid:0x3a000000000608
bridge_port_id = ent[b"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID"][6:]
if bridge_port_id not in self.if_bpid_map:
continue
port_id = self.if_bpid_map[bridge_port_id]

vlanmac = self.fdb_vlanmac(fdb)
self.vlanmac_ifindex_map[vlanmac] = mibs.get_index_from_str(self.if_id_map[port_id])
self.vlanmac_ifindex_list.append(vlanmac)
self.vlanmac_ifindex_list.sort()

def fdb_ifindex(self, sub_id):
Expand Down
9 changes: 6 additions & 3 deletions src/sonic_ax_impl/mibs/vendor/cisco/ciscoPfcExtMIB.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self):
# cache of interface counters
self.if_counters = {}
self.if_range = []
self.namespace_db_map = Namespace.get_namespace_db_map(self.db_conn)

def reinit_data(self):
"""
Expand All @@ -45,9 +46,11 @@ def update_data(self):
Update redis (caches config)
Pulls the table references for each interface.
"""
self.if_counters = \
{if_idx: self.db_conn[self.if_oid_namespace[if_idx]].get_all(
mibs.COUNTERS_DB, mibs.counter_table(self.oid_sai_map[if_idx]), blocking=True)
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)

self.lag_name_if_name_map, \
self.if_name_lag_name_map, \
Expand Down
22 changes: 13 additions & 9 deletions src/sonic_ax_impl/mibs/vendor/cisco/ciscoSwitchQosMIB.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(self):
self.mib_oid_list = []

self.queue_type_map = {}
self.if_id_namespace = {}

def reinit_data(self):
"""
Expand All @@ -76,15 +77,15 @@ def reinit_data(self):
self.oid_sai_map, \
self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn)

for sai_id_key, if_name in self.if_id_map.items():
namespace, sai_id = mibs.split_sai_id_key(sai_id_key)
self.if_id_namespace[mibs.get_index_from_str(if_name)] = namespace

self.port_queues_map, self.queue_stat_map, self.port_queue_list_map = \
Namespace.init_namespace_sync_d_queue_tables(self.db_conn)

"""
COUNTERS_QUEUE_TYPE_MAP OID will be the same for all namespaces.
Get OID list from first namespace.
"""
db_start_idx = Namespace.get_start_idx_of_non_host(self.db_conn)
self.queue_type_map = self.db_conn[db_start_idx].get_all(mibs.COUNTERS_DB, "COUNTERS_QUEUE_TYPE_MAP", blocking=False)
for db_conn in Namespace.get_non_host_dbs(self.db_conn):
self.queue_type_map[db_conn.namespace] = db_conn.get_all(mibs.COUNTERS_DB, "COUNTERS_QUEUE_TYPE_MAP", blocking=False)

self.update_data()

Expand All @@ -95,7 +96,8 @@ def update_data(self):
"""
for queue_key, sai_id in self.port_queues_map.items():
queue_stat_name = mibs.queue_table(sai_id)
queue_stat_idx = mibs.queue_key(if_index, queue_stat_table_name)
if_index, _ = queue_key.split(':')
queue_stat_idx = mibs.queue_key(if_index, queue_stat_name)
queue_stat = self.queue_stat_map.get(queue_stat_idx, {})
if queue_stat is not None:
self.queue_stat_map[queue_stat_name] = queue_stat
Expand All @@ -122,6 +124,7 @@ def update_stats(self):
# Port does not has a queues, continue..
continue
if_queues = self.port_queue_list_map[if_index]
namespace = self.if_id_namespace[if_index]

# The first half of queue id is for ucast, and second half is for mcast
# To simulate vendor OID, we wrap queues by half distance
Expand All @@ -131,8 +134,9 @@ def update_stats(self):
# Get queue type and statistics
queue_sai_oid = self.port_queues_map[mibs.queue_key(if_index, queue)]
queue_stat_table_name = mibs.queue_table(queue_sai_oid)
queue_type = self.queue_type_map.get(queue_sai_oid)
queue_stat = self.queue_stat_map.get(queue_stat_table_name, {})
queue_stat_key = mibs.queue_key(if_index, queue_stat_table_name)
queue_type = self.queue_type_map[namespace].get(queue_sai_oid)
queue_stat = self.queue_stat_map.get(queue_stat_key, {})

# Add supported counters to MIBs list and store counters values
for (counter, counter_type), counter_mib_id in CounterMap.items():
Expand Down
2 changes: 0 additions & 2 deletions tests/namespace/test_pfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
class TestPfcPortCounters(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(ciscoPfcExtMIB)

Expand Down

0 comments on commit 4cf3c25

Please sign in to comment.