77
88from swsssdk import port_util
99from sonic_ax_impl import mibs , logger
10+ from sonic_ax_impl .mibs import Namespace
1011from 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 = {}
0 commit comments