Skip to content

Commit 89b7b2c

Browse files
[Multi-asic]: Namespace support for LLDP and Sensor tables (#131)
* Changes in below MIB tables implementation to support multi-asic platform: LLDPRemManAddrTable PhysicalTableMIB PhysicalSensorTableMIB QBridgeMIBObjects * Fix LGTM errors. * Fix merge conflicts and fix function names as per review comment.
1 parent fcb8955 commit 89b7b2c

File tree

9 files changed

+635
-66
lines changed

9 files changed

+635
-66
lines changed

src/sonic_ax_impl/mibs/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,3 +571,22 @@ def init_namespace_sync_d_queue_tables(dbs):
571571
port_queue_list_map.update(port_queue_list_map_ns)
572572

573573
return port_queues_map, queue_stat_map, port_queue_list_map
574+
575+
@staticmethod
576+
def dbs_get_bridge_port_map(dbs, db_name):
577+
"""
578+
get_bridge_port_map from all namespace DBs
579+
"""
580+
if_br_oid_map = {}
581+
for db_conn in Namespace.get_non_host_dbs(dbs):
582+
if_br_oid_map_ns = port_util.get_bridge_port_map(db_conn)
583+
if_br_oid_map.update(if_br_oid_map_ns)
584+
return if_br_oid_map
585+
586+
@staticmethod
587+
def dbs_get_vlan_id_from_bvid(dbs, bvid):
588+
for db_conn in Namespace.get_non_host_dbs(dbs):
589+
db_conn.connect('ASIC_DB')
590+
vlan_obj = db.keys('ASIC_DB', "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:" + bvid)
591+
if vlan_obj is not None:
592+
return port_util.get_vlan_id_from_bvid(db_conn, bvid)

src/sonic_ax_impl/mibs/ieee802_1ab.py

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from swsssdk import port_util
99
from sonic_ax_impl import mibs, logger
10+
from sonic_ax_impl.mibs import Namespace
1011
from ax_interface import MIBMeta, SubtreeMIBEntry, MIBEntry, MIBUpdater, ValueType
1112

1213

@@ -102,16 +103,16 @@ class LLDPLocalSystemDataUpdater(MIBUpdater):
102103
def __init__(self):
103104
super().__init__()
104105

105-
self.db_conn = mibs.init_db()
106+
self.db_conn = Namespace.init_namespace_dbs()
106107
self.loc_chassis_data = {}
107108

108109
def reinit_data(self):
109110
"""
110111
Subclass update data routine.
111112
"""
112113
# establish connection to application database.
113-
self.db_conn.connect(mibs.APPL_DB)
114-
self.loc_chassis_data = self.db_conn.get_all(mibs.APPL_DB, mibs.LOC_CHASSIS_TABLE)
114+
Namespace.connect_all_dbs(self.db_conn, mibs.APPL_DB)
115+
self.loc_chassis_data = Namespace.dbs_get_all(self.db_conn, mibs.APPL_DB, mibs.LOC_CHASSIS_TABLE)
115116
self.loc_chassis_data[b'lldp_loc_sys_cap_supported'] = parse_sys_capability(self.loc_chassis_data[b'lldp_loc_sys_cap_supported'])
116117
self.loc_chassis_data[b'lldp_loc_sys_cap_enabled'] = parse_sys_capability(self.loc_chassis_data[b'lldp_loc_sys_cap_enabled'])
117118
def update_data(self):
@@ -139,9 +140,9 @@ class LocPortUpdater(MIBUpdater):
139140
def __init__(self):
140141
super().__init__()
141142

142-
self.db_conn = mibs.init_db()
143+
self.db_conn = Namespace.init_namespace_dbs()
143144
# establish connection to application database.
144-
self.db_conn.connect(mibs.APPL_DB)
145+
Namespace.connect_all_dbs(self.db_conn, mibs.APPL_DB)
145146
self.if_name_map = {}
146147
self.if_alias_map = {}
147148
self.if_id_map = {}
@@ -156,7 +157,7 @@ def __init__(self):
156157
# cache of port data
157158
# { if_name -> { 'key': 'value' } }
158159
self.loc_port_data = {}
159-
self.pubsub = None
160+
self.pubsub = [None] * len(self.db_conn)
160161

161162
def reinit_data(self):
162163
"""
@@ -166,10 +167,10 @@ def reinit_data(self):
166167
self.if_alias_map, \
167168
self.if_id_map, \
168169
self.oid_sai_map, \
169-
self.oid_name_map = mibs.init_sync_d_interface_tables(self.db_conn)
170+
self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn)
170171

171172
self.mgmt_oid_name_map, \
172-
self.mgmt_alias_map = mibs.init_mgmt_interface_tables(self.db_conn)
173+
self.mgmt_alias_map = mibs.init_mgmt_interface_tables(self.db_conn[0])
173174

174175
# merge dataplane and mgmt ports
175176
self.oid_name_map.update(self.mgmt_oid_name_map)
@@ -199,7 +200,7 @@ def _get_if_entry(self, if_name):
199200
else:
200201
return None
201202

202-
return self.db_conn.get_all(db, if_table, blocking=True)
203+
return Namespace.dbs_get_all(self.db_conn, db, if_table, blocking=True)
203204

204205
def update_interface_data(self, if_name):
205206
"""
@@ -221,25 +222,29 @@ def get_next(self, sub_id):
221222
return None
222223
return self.if_range[right]
223224

224-
def update_data(self):
225+
def _update_per_namespace_data(self, db_conn, pubsub):
225226
"""
226227
Listen to updates in APP DB, update local cache
227228
"""
228-
if not self.pubsub:
229-
redis_client = self.db_conn.get_redis_client(self.db_conn.APPL_DB)
230-
db = self.db_conn.get_dbid(self.db_conn.APPL_DB)
231-
self.pubsub = redis_client.pubsub()
232-
self.pubsub.psubscribe("__keyspace@{}__:{}".format(db, mibs.lldp_entry_table(b'*')))
229+
if not pubsub:
230+
redis_client = db_conn.get_redis_client(db_conn.APPL_DB)
231+
db = db_conn.get_dbid(db_conn.APPL_DB)
232+
pubsub = redis_client.pubsub()
233+
pubsub.psubscribe("__keyspace@{}__:{}".format(db, mibs.lldp_entry_table(b'*')))
233234

234235
while True:
235-
data, interface, if_id = poll_lldp_entry_updates(self.pubsub)
236+
data, interface, if_id = poll_lldp_entry_updates(pubsub)
236237

237238
if not data:
238239
break
239240

240241
if b"set" in data:
241242
self.update_interface_data(interface.encode())
242243

244+
def update_data(self):
245+
for i in range(len(self.db_conn)):
246+
self._update_per_namespace_data(self.db_conn[i], self.pubsub[i])
247+
243248
def local_port_num(self, sub_id):
244249
if len(sub_id) == 0:
245250
return None
@@ -302,7 +307,7 @@ def reinit_data(self):
302307
self.mgmt_ip_str = None
303308

304309
# establish connection to application database.
305-
self.db_conn.connect(mibs.APPL_DB)
310+
self.db_conn.connect(mibs.APPL_DB)
306311
mgmt_ip_bytes = self.db_conn.get(mibs.APPL_DB, mibs.LOC_CHASSIS_TABLE, b'lldp_loc_man_addr')
307312

308313
if not mgmt_ip_bytes:
@@ -377,7 +382,7 @@ class LLDPRemTableUpdater(MIBUpdater):
377382
def __init__(self):
378383
super().__init__()
379384

380-
self.db_conn = mibs.init_db()
385+
self.db_conn = Namespace.init_namespace_dbs()
381386
self.if_name_map = {}
382387
self.if_alias_map = {}
383388
self.if_id_map = {}
@@ -400,9 +405,9 @@ def reinit_data(self):
400405
self.if_alias_map, \
401406
self.if_id_map, \
402407
self.oid_sai_map, \
403-
self.oid_name_map = mibs.init_sync_d_interface_tables(self.db_conn)
408+
self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn)
404409

405-
self.mgmt_oid_name_map, _ = mibs.init_mgmt_interface_tables(self.db_conn)
410+
self.mgmt_oid_name_map, _ = mibs.init_mgmt_interface_tables(self.db_conn[0])
406411

407412
self.oid_name_map.update(self.mgmt_oid_name_map)
408413

@@ -421,12 +426,11 @@ def update_data(self):
421426
Subclass update data routine. Updates available LLDP counters.
422427
"""
423428
# establish connection to application database.
424-
self.db_conn.connect(mibs.APPL_DB)
425429

426430
self.if_range = []
427431
self.lldp_counters = {}
428432
for if_oid, if_name in self.oid_name_map.items():
429-
lldp_kvs = self.db_conn.get_all(mibs.APPL_DB, mibs.lldp_entry_table(if_name))
433+
lldp_kvs = Namespace.dbs_get_all(self.db_conn, mibs.APPL_DB, mibs.lldp_entry_table(if_name))
430434
if not lldp_kvs:
431435
continue
432436
try:
@@ -484,18 +488,18 @@ class LLDPRemManAddrUpdater(MIBUpdater):
484488
def __init__(self):
485489
super().__init__()
486490

487-
self.db_conn = mibs.init_db()
491+
self.db_conn = Namespace.init_namespace_dbs()
488492
# establish connection to application database.
489-
self.db_conn.connect(self.db_conn.APPL_DB)
493+
Namespace.connect_all_dbs(self.db_conn, mibs.APPL_DB)
490494
self.if_range = []
491495
self.mgmt_ips = {}
492496
self.oid_name_map = {}
493497
self.mgmt_oid_name_map = {}
494498
self.mgmt_ip_str = None
495-
self.pubsub = None
499+
self.pubsub = [None] * len(self.db_conn)
496500

497501
def update_rem_if_mgmt(self, if_oid, if_name):
498-
lldp_kvs = self.db_conn.get_all(mibs.APPL_DB, mibs.lldp_entry_table(if_name))
502+
lldp_kvs = Namespace.dbs_get_all(self.db_conn, mibs.APPL_DB, mibs.lldp_entry_table(if_name))
499503
if not lldp_kvs or b'lldp_rem_man_addr' not in lldp_kvs:
500504
# this interfaces doesn't have remote lldp data, or the peer doesn't advertise his mgmt address
501505
return
@@ -532,18 +536,18 @@ def update_rem_if_mgmt(self, if_oid, if_name):
532536
return
533537
self.if_range.sort()
534538

535-
def update_data(self):
539+
def _update_per_namespace_data(self, db_conn, pubsub):
536540
"""
537541
Listen to updates in APP DB, update local cache
538542
"""
539-
if not self.pubsub:
540-
redis_client = self.db_conn.get_redis_client(self.db_conn.APPL_DB)
541-
db = self.db_conn.get_dbid(self.db_conn.APPL_DB)
542-
self.pubsub = redis_client.pubsub()
543-
self.pubsub.psubscribe("__keyspace@{}__:{}".format(db, mibs.lldp_entry_table(b'*')))
543+
if not pubsub:
544+
redis_client = db_conn.get_redis_client(db_conn.APPL_DB)
545+
db = db_conn.get_dbid(db_conn.APPL_DB)
546+
pubsub = redis_client.pubsub()
547+
pubsub.psubscribe("__keyspace@{}__:{}".format(db, mibs.lldp_entry_table(b'*')))
544548

545549
while True:
546-
data, interface, if_index = poll_lldp_entry_updates(self.pubsub)
550+
data, interface, if_index = poll_lldp_entry_updates(pubsub)
547551

548552
if not data:
549553
break
@@ -555,18 +559,23 @@ def update_data(self):
555559
self.if_range = [sub_oid for sub_oid in self.if_range if sub_oid[0] != if_index]
556560
self.update_rem_if_mgmt(if_index, interface.encode())
557561

562+
def update_data(self):
563+
for i in range(len(self.db_conn)):
564+
self._update_per_namespace_data(self.db_conn[i], self.pubsub[i])
565+
566+
558567
def reinit_data(self):
559568
"""
560569
Subclass reinit data routine.
561570
"""
562-
_, _, _, _, self.oid_name_map = mibs.init_sync_d_interface_tables(self.db_conn)
571+
_, _, _, _, self.oid_name_map = Namespace.init_namespace_sync_d_interface_tables(self.db_conn)
563572

564-
self.mgmt_oid_name_map, _ = mibs.init_mgmt_interface_tables(self.db_conn)
573+
self.mgmt_oid_name_map, _ = mibs.init_mgmt_interface_tables(self.db_conn[0])
565574

566575
self.oid_name_map.update(self.mgmt_oid_name_map)
567576

568577
# establish connection to application database.
569-
self.db_conn.connect(mibs.APPL_DB)
578+
Namespace.connect_all_dbs(self.db_conn, mibs.APPL_DB)
570579

571580
self.if_range = []
572581
self.mgmt_ips = {}

src/sonic_ax_impl/mibs/ietf/rfc2737.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
from enum import Enum, unique
66
from bisect import bisect_right, insort_right
77

8-
from swsssdk import SonicV2Connector, port_util
8+
from swsssdk import port_util
99
from ax_interface import MIBMeta, MIBUpdater, ValueType, SubtreeMIBEntry
1010

1111
from sonic_ax_impl import mibs
12-
12+
from sonic_ax_impl.mibs import Namespace
1313

1414
@unique
1515
class PhysicalClass(int, Enum):
@@ -120,8 +120,8 @@ class PhysicalTableMIBUpdater(MIBUpdater):
120120
def __init__(self):
121121
super().__init__()
122122

123-
self.statedb = SonicV2Connector()
124-
self.statedb.connect(self.statedb.STATE_DB)
123+
self.statedb = Namespace.init_namespace_dbs()
124+
Namespace.connect_all_dbs(self.statedb, mibs.STATE_DB)
125125

126126
self.if_alias_map = {}
127127

@@ -136,7 +136,7 @@ def __init__(self):
136136
self.physical_mfg_name_map = {}
137137
self.physical_model_name_map = {}
138138

139-
self.pubsub = None
139+
self.pubsub = [None] * len(self.statedb)
140140

141141
def reinit_data(self):
142142
"""
@@ -153,9 +153,9 @@ def reinit_data(self):
153153

154154
# update interface maps
155155
_, self.if_alias_map, _, _, _ = \
156-
mibs.init_sync_d_interface_tables(SonicV2Connector())
156+
Namespace.init_namespace_sync_d_interface_tables(Namespace.init_namespace_dbs())
157157

158-
device_metadata = mibs.get_device_metadata(self.statedb)
158+
device_metadata = mibs.get_device_metadata(self.statedb[0])
159159
chassis_sub_id = (self.CHASSIS_ID, )
160160
self.physical_entities = [chassis_sub_id]
161161

@@ -168,7 +168,7 @@ def reinit_data(self):
168168
self.physical_serial_number_map[chassis_sub_id] = chassis_serial_number
169169

170170
# retrieve the initial list of transceivers that are present in the system
171-
transceiver_info = self.statedb.keys(self.statedb.STATE_DB, self.TRANSCEIVER_KEY_PATTERN)
171+
transceiver_info = Namespace.dbs_keys(self.statedb, mibs.STATE_DB, self.TRANSCEIVER_KEY_PATTERN)
172172
if transceiver_info:
173173
self.transceiver_entries = [entry.decode() \
174174
for entry in transceiver_info]
@@ -181,7 +181,7 @@ def reinit_data(self):
181181
interface = transceiver_entry.split(mibs.TABLE_NAME_SEPARATOR_VBAR)[-1]
182182
self._update_transceiver_cache(interface)
183183

184-
def update_data(self):
184+
def _update_per_namespace_data(self, statedb, pubsub):
185185
"""
186186
Update cache.
187187
Here we listen to changes in STATE_DB TRANSCEIVER_INFO table
@@ -190,14 +190,14 @@ def update_data(self):
190190

191191
# This code is not executed in unit test, since mockredis
192192
# does not support pubsub
193-
if not self.pubsub:
194-
redis_client = self.statedb.get_redis_client(self.statedb.STATE_DB)
195-
db = self.statedb.get_dbid(self.statedb.STATE_DB)
196-
self.pubsub = redis_client.pubsub()
197-
self.pubsub.psubscribe("__keyspace@{}__:{}".format(db, self.TRANSCEIVER_KEY_PATTERN))
193+
if not pubsub:
194+
redis_client = statedb.get_redis_client(statedb.STATE_DB)
195+
db = statedb.get_dbid(statedb.STATE_DB)
196+
pubsub = redis_client.pubsub()
197+
pubsub.psubscribe("__keyspace@{}__:{}".format(db, self.TRANSCEIVER_KEY_PATTERN))
198198

199199
while True:
200-
msg = self.pubsub.get_message()
200+
msg = pubsub.get_message()
201201

202202
if not msg:
203203
break
@@ -232,6 +232,10 @@ def update_data(self):
232232
if sub_id and sub_id in self.physical_entities:
233233
self.physical_entities.remove(sub_id)
234234

235+
def update_data(self):
236+
for i in range(len(self.statedb)):
237+
self._update_per_namespace_data(self.statedb[i], self.pubsub[i])
238+
235239
def _update_transceiver_cache(self, interface):
236240
"""
237241
Update data for single transceiver
@@ -249,7 +253,7 @@ def _update_transceiver_cache(self, interface):
249253
insort_right(self.physical_entities, sub_id)
250254

251255
# get transceiver information from transceiver info entry in STATE DB
252-
transceiver_info = self.statedb.get_all(self.statedb.STATE_DB,
256+
transceiver_info = Namespace.dbs_get_all(self.statedb, mibs.STATE_DB,
253257
mibs.transceiver_info_table(interface))
254258

255259
if not transceiver_info:
@@ -283,7 +287,7 @@ def _update_transceiver_sensor_cache(self, interface):
283287
ifindex = port_util.get_index_from_str(interface)
284288

285289
# get transceiver sensors from transceiver dom entry in STATE DB
286-
transceiver_dom_entry = self.statedb.get_all(self.statedb.STATE_DB,
290+
transceiver_dom_entry = Namespace.dbs_get_all(self.statedb, mibs.STATE_DB,
287291
mibs.transceiver_dom_table(interface))
288292

289293
if not transceiver_dom_entry:

0 commit comments

Comments
 (0)