-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Multi-asic]: Namespace support for LLDP and Sensor tables #131
Changes from 4 commits
961fc20
3ffba0e
6b55884
01e70be
6ba24bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -419,7 +419,11 @@ def update_data(self): | |
self.oid_list = [] | ||
self.oid_map = {} | ||
|
||
<<<<<<< HEAD | ||
keys = Namespace.get_dbs_keys(self.db_conn, SNMP_OVERLAY_DB, self.prefix_str + '*') | ||
======= | ||
keys = Namespace.dbs_keys(self.db_conn, SNMP_OVERLAY_DB, self.prefix_str + '*') | ||
>>>>>>> remotes/azure/master | ||
# TODO: fix db_conn.keys to return empty list instead of None if there is no match | ||
if keys is None: | ||
keys = [] | ||
|
@@ -428,7 +432,11 @@ def update_data(self): | |
key = key.decode() | ||
oid = oid2tuple(key, dot_prefix=False) | ||
self.oid_list.append(oid) | ||
<<<<<<< HEAD | ||
value = Namespace.get_all_dbs(self.db_conn, SNMP_OVERLAY_DB, key) | ||
======= | ||
value = Namespace.dbs_get_all(self.db_conn, SNMP_OVERLAY_DB, key) | ||
>>>>>>> remotes/azure/master | ||
if value[b'type'] in [b'COUNTER_32', b'COUNTER_64']: | ||
self.oid_map[oid] = int(value[b'data']) | ||
else: | ||
|
@@ -458,7 +466,11 @@ def connect_all_dbs(dbs, db_name): | |
db_conn.connect(db_name) | ||
|
||
@staticmethod | ||
<<<<<<< HEAD | ||
def get_dbs_keys(dbs, db_name, pattern='*'): | ||
======= | ||
def dbs_keys(dbs, db_name, pattern='*'): | ||
>>>>>>> remotes/azure/master | ||
""" | ||
db keys function execute on global and all namespace DBs. | ||
""" | ||
|
@@ -471,6 +483,17 @@ def dbs_keys(dbs, db_name, pattern='*'): | |
return result_keys | ||
|
||
@staticmethod | ||
<<<<<<< HEAD | ||
def get_all_dbs(dbs, db_name, _hash, *args, **kwargs): | ||
""" | ||
db get_all function executed on global and all namespace DBs. | ||
""" | ||
for db_conn in dbs: | ||
db_conn.connect(db_name) | ||
if(db_conn.exists(db_name, _hash)): | ||
return db_conn.get_all(db_name, _hash, *args, **kwargs) | ||
return {} | ||
======= | ||
def dbs_get_all(dbs, db_name, _hash, *args, **kwargs): | ||
""" | ||
db get_all function executed on global and all namespace DBs. | ||
|
@@ -483,6 +506,7 @@ def dbs_get_all(dbs, db_name, _hash, *args, **kwargs): | |
if ns_result is not None: | ||
result.update(ns_result) | ||
return result | ||
>>>>>>> remotes/azure/master | ||
|
||
@staticmethod | ||
def get_non_host_dbs(dbs): | ||
|
@@ -571,3 +595,22 @@ def init_namespace_sync_d_queue_tables(dbs): | |
port_queue_list_map.update(port_queue_list_map_ns) | ||
|
||
return port_queues_map, queue_stat_map, port_queue_list_map | ||
|
||
@staticmethod | ||
def get_bridge_port_map_from_namespace_dbs(dbs, db_name): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
dbs_get_bridge_port_map #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
""" | ||
get_bridge_port_map from all namespace DBs | ||
""" | ||
if_br_oid_map = {} | ||
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 get_vlan_id_from_bvid_from_namespace_dbs(dbs, bvid): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
dbs_get_vlan_id_from_bvid #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
for db_conn in Namespace.get_non_host_dbs(dbs): | ||
db_conn.connect('ASIC_DB') | ||
vlan_obj = db.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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
from swsssdk import port_util | ||
from sonic_ax_impl import mibs, logger | ||
from sonic_ax_impl.mibs import Namespace | ||
from ax_interface import MIBMeta, SubtreeMIBEntry, MIBEntry, MIBUpdater, ValueType | ||
|
||
|
||
|
@@ -102,16 +103,16 @@ class LLDPLocalSystemDataUpdater(MIBUpdater): | |
def __init__(self): | ||
super().__init__() | ||
|
||
self.db_conn = mibs.init_db() | ||
self.db_conn = Namespace.init_namespace_dbs() | ||
self.loc_chassis_data = {} | ||
|
||
def reinit_data(self): | ||
""" | ||
Subclass update data routine. | ||
""" | ||
# establish connection to application database. | ||
self.db_conn.connect(mibs.APPL_DB) | ||
self.loc_chassis_data = self.db_conn.get_all(mibs.APPL_DB, mibs.LOC_CHASSIS_TABLE) | ||
Namespace.connect_all_dbs(self.db_conn, mibs.APPL_DB) | ||
self.loc_chassis_data = Namespace.get_all_dbs(self.db_conn, mibs.APPL_DB, mibs.LOC_CHASSIS_TABLE) | ||
self.loc_chassis_data[b'lldp_loc_sys_cap_supported'] = parse_sys_capability(self.loc_chassis_data[b'lldp_loc_sys_cap_supported']) | ||
self.loc_chassis_data[b'lldp_loc_sys_cap_enabled'] = parse_sys_capability(self.loc_chassis_data[b'lldp_loc_sys_cap_enabled']) | ||
def update_data(self): | ||
|
@@ -139,9 +140,9 @@ class LocPortUpdater(MIBUpdater): | |
def __init__(self): | ||
super().__init__() | ||
|
||
self.db_conn = mibs.init_db() | ||
self.db_conn = Namespace.init_namespace_dbs() | ||
# establish connection to application database. | ||
self.db_conn.connect(mibs.APPL_DB) | ||
Namespace.connect_all_dbs(self.db_conn, mibs.APPL_DB) | ||
self.if_name_map = {} | ||
self.if_alias_map = {} | ||
self.if_id_map = {} | ||
|
@@ -156,7 +157,7 @@ def __init__(self): | |
# cache of port data | ||
# { if_name -> { 'key': 'value' } } | ||
self.loc_port_data = {} | ||
self.pubsub = None | ||
self.pubsub = [None] * len(self.db_conn) | ||
|
||
def reinit_data(self): | ||
""" | ||
|
@@ -166,10 +167,10 @@ def reinit_data(self): | |
self.if_alias_map, \ | ||
self.if_id_map, \ | ||
self.oid_sai_map, \ | ||
self.oid_name_map = mibs.init_sync_d_interface_tables(self.db_conn) | ||
self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn) | ||
|
||
self.mgmt_oid_name_map, \ | ||
self.mgmt_alias_map = mibs.init_mgmt_interface_tables(self.db_conn) | ||
self.mgmt_alias_map = mibs.init_mgmt_interface_tables(self.db_conn[0]) | ||
|
||
# merge dataplane and mgmt ports | ||
self.oid_name_map.update(self.mgmt_oid_name_map) | ||
|
@@ -199,7 +200,7 @@ def _get_if_entry(self, if_name): | |
else: | ||
return None | ||
|
||
return self.db_conn.get_all(db, if_table, blocking=True) | ||
return Namespace.get_all_dbs(self.db_conn, db, if_table, blocking=True) | ||
|
||
def update_interface_data(self, if_name): | ||
""" | ||
|
@@ -221,25 +222,29 @@ def get_next(self, sub_id): | |
return None | ||
return self.if_range[right] | ||
|
||
def update_data(self): | ||
def _update_per_namespace_data(self, db_conn, pubsub): | ||
""" | ||
Listen to updates in APP DB, update local cache | ||
""" | ||
if not self.pubsub: | ||
redis_client = self.db_conn.get_redis_client(self.db_conn.APPL_DB) | ||
db = self.db_conn.get_dbid(self.db_conn.APPL_DB) | ||
self.pubsub = redis_client.pubsub() | ||
self.pubsub.psubscribe("__keyspace@{}__:{}".format(db, mibs.lldp_entry_table(b'*'))) | ||
if not pubsub: | ||
redis_client = db_conn.get_redis_client(db_conn.APPL_DB) | ||
db = db_conn.get_dbid(db_conn.APPL_DB) | ||
pubsub = redis_client.pubsub() | ||
pubsub.psubscribe("__keyspace@{}__:{}".format(db, mibs.lldp_entry_table(b'*'))) | ||
|
||
while True: | ||
data, interface, if_id = poll_lldp_entry_updates(self.pubsub) | ||
data, interface, if_id = poll_lldp_entry_updates(pubsub) | ||
|
||
if not data: | ||
break | ||
|
||
if b"set" in data: | ||
self.update_interface_data(interface.encode()) | ||
|
||
def update_data(self): | ||
for i in range(len(self.db_conn)): | ||
self._update_per_namespace_data(self.db_conn[i], self.pubsub[i]) | ||
|
||
def local_port_num(self, sub_id): | ||
if len(sub_id) == 0: | ||
return None | ||
|
@@ -302,7 +307,7 @@ def reinit_data(self): | |
self.mgmt_ip_str = None | ||
|
||
# establish connection to application database. | ||
self.db_conn.connect(mibs.APPL_DB) | ||
self.db_conn.connect(mibs.APPL_DB) | ||
mgmt_ip_bytes = self.db_conn.get(mibs.APPL_DB, mibs.LOC_CHASSIS_TABLE, b'lldp_loc_man_addr') | ||
|
||
if not mgmt_ip_bytes: | ||
|
@@ -377,7 +382,7 @@ class LLDPRemTableUpdater(MIBUpdater): | |
def __init__(self): | ||
super().__init__() | ||
|
||
self.db_conn = mibs.init_db() | ||
self.db_conn = Namespace.init_namespace_dbs() | ||
self.if_name_map = {} | ||
self.if_alias_map = {} | ||
self.if_id_map = {} | ||
|
@@ -400,9 +405,9 @@ def reinit_data(self): | |
self.if_alias_map, \ | ||
self.if_id_map, \ | ||
self.oid_sai_map, \ | ||
self.oid_name_map = mibs.init_sync_d_interface_tables(self.db_conn) | ||
self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn) | ||
|
||
self.mgmt_oid_name_map, _ = mibs.init_mgmt_interface_tables(self.db_conn) | ||
self.mgmt_oid_name_map, _ = mibs.init_mgmt_interface_tables(self.db_conn[0]) | ||
|
||
self.oid_name_map.update(self.mgmt_oid_name_map) | ||
|
||
|
@@ -421,12 +426,11 @@ def update_data(self): | |
Subclass update data routine. Updates available LLDP counters. | ||
""" | ||
# establish connection to application database. | ||
self.db_conn.connect(mibs.APPL_DB) | ||
|
||
self.if_range = [] | ||
self.lldp_counters = {} | ||
for if_oid, if_name in self.oid_name_map.items(): | ||
lldp_kvs = self.db_conn.get_all(mibs.APPL_DB, mibs.lldp_entry_table(if_name)) | ||
lldp_kvs = Namespace.get_all_dbs(self.db_conn, mibs.APPL_DB, mibs.lldp_entry_table(if_name)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
dbs_get_all #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
if not lldp_kvs: | ||
continue | ||
try: | ||
|
@@ -484,18 +488,18 @@ class LLDPRemManAddrUpdater(MIBUpdater): | |
def __init__(self): | ||
super().__init__() | ||
|
||
self.db_conn = mibs.init_db() | ||
self.db_conn = Namespace.init_namespace_dbs() | ||
# establish connection to application database. | ||
self.db_conn.connect(self.db_conn.APPL_DB) | ||
Namespace.connect_all_dbs(self.db_conn, mibs.APPL_DB) | ||
self.if_range = [] | ||
self.mgmt_ips = {} | ||
self.oid_name_map = {} | ||
self.mgmt_oid_name_map = {} | ||
self.mgmt_ip_str = None | ||
self.pubsub = None | ||
self.pubsub = [None] * len(self.db_conn) | ||
|
||
def update_rem_if_mgmt(self, if_oid, if_name): | ||
lldp_kvs = self.db_conn.get_all(mibs.APPL_DB, mibs.lldp_entry_table(if_name)) | ||
lldp_kvs = Namespace.get_all_dbs(self.db_conn, mibs.APPL_DB, mibs.lldp_entry_table(if_name)) | ||
if not lldp_kvs or b'lldp_rem_man_addr' not in lldp_kvs: | ||
# this interfaces doesn't have remote lldp data, or the peer doesn't advertise his mgmt address | ||
return | ||
|
@@ -532,18 +536,18 @@ def update_rem_if_mgmt(self, if_oid, if_name): | |
return | ||
self.if_range.sort() | ||
|
||
def update_data(self): | ||
def _update_per_namespace_data(self, db_conn, pubsub): | ||
""" | ||
Listen to updates in APP DB, update local cache | ||
""" | ||
if not self.pubsub: | ||
redis_client = self.db_conn.get_redis_client(self.db_conn.APPL_DB) | ||
db = self.db_conn.get_dbid(self.db_conn.APPL_DB) | ||
self.pubsub = redis_client.pubsub() | ||
self.pubsub.psubscribe("__keyspace@{}__:{}".format(db, mibs.lldp_entry_table(b'*'))) | ||
if not pubsub: | ||
redis_client = db_conn.get_redis_client(db_conn.APPL_DB) | ||
db = db_conn.get_dbid(db_conn.APPL_DB) | ||
pubsub = redis_client.pubsub() | ||
pubsub.psubscribe("__keyspace@{}__:{}".format(db, mibs.lldp_entry_table(b'*'))) | ||
|
||
while True: | ||
data, interface, if_index = poll_lldp_entry_updates(self.pubsub) | ||
data, interface, if_index = poll_lldp_entry_updates(pubsub) | ||
|
||
if not data: | ||
break | ||
|
@@ -555,18 +559,23 @@ def update_data(self): | |
self.if_range = [sub_oid for sub_oid in self.if_range if sub_oid[0] != if_index] | ||
self.update_rem_if_mgmt(if_index, interface.encode()) | ||
|
||
def update_data(self): | ||
for i in range(len(self.db_conn)): | ||
self._update_per_namespace_data(self.db_conn[i], self.pubsub[i]) | ||
|
||
|
||
def reinit_data(self): | ||
""" | ||
Subclass reinit data routine. | ||
""" | ||
_, _, _, _, self.oid_name_map = mibs.init_sync_d_interface_tables(self.db_conn) | ||
_, _, _, _, self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn) | ||
|
||
self.mgmt_oid_name_map, _ = mibs.init_mgmt_interface_tables(self.db_conn) | ||
self.mgmt_oid_name_map, _ = mibs.init_mgmt_interface_tables(self.db_conn[0]) | ||
|
||
self.oid_name_map.update(self.mgmt_oid_name_map) | ||
|
||
# establish connection to application database. | ||
self.db_conn.connect(mibs.APPL_DB) | ||
Namespace.connect_all_dbs(self.db_conn, mibs.APPL_DB) | ||
|
||
self.if_range = [] | ||
self.mgmt_ips = {} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please resolve conflicts #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.