From 08ce7eff4cdd3f229a36665e2a3850196fa7371a Mon Sep 17 00:00:00 2001 From: Cong Wang Date: Wed, 2 Oct 2024 22:25:27 -0400 Subject: [PATCH 1/2] Use LC-X as topology db key --- sdx_controller/handlers/lc_message_handler.py | 15 +++++++++------ sdx_controller/messaging/rpc_queue_consumer.py | 10 +++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/sdx_controller/handlers/lc_message_handler.py b/sdx_controller/handlers/lc_message_handler.py index d58e878..1b9a9b2 100644 --- a/sdx_controller/handlers/lc_message_handler.py +++ b/sdx_controller/handlers/lc_message_handler.py @@ -62,15 +62,18 @@ def process_lc_json_msg( "topologies", "num_domain_topos", num_domain_topos ) else: + # print("----current domain list----") + # print(domain_list) num_domain_topos = len(domain_list) - self.db_instance.add_key_value_pair_to_db( - "topologies", "num_domain_topos", num_domain_topos - ) - - logger.info("Adding topology to db: " + domain_name) + # num_domain_topos = int(num_domain_topos) + 1 + # self.db_instance.add_key_value_pair_to_db( + # "topologies", "num_domain_topos", num_domain_topos + # ) + db_key = "LC-" + str(num_domain_topos) + logger.info(f"Adding topology {db_key} to db.") self.db_instance.add_key_value_pair_to_db( - "topologies", domain_name, json.dumps(msg_json) + "topologies", db_key, json.dumps(msg_json) ) # TODO: use TEManager API directly; but TEManager does not diff --git a/sdx_controller/messaging/rpc_queue_consumer.py b/sdx_controller/messaging/rpc_queue_consumer.py index 379cf96..3356b72 100644 --- a/sdx_controller/messaging/rpc_queue_consumer.py +++ b/sdx_controller/messaging/rpc_queue_consumer.py @@ -111,16 +111,16 @@ def start_sdx_consumer(self, thread_queue, db_instance): num_domain_topos = num_domain_topos_from_db["num_domain_topos"] logger.debug("Read num_domain_topos from db: ") logger.debug(num_domain_topos) - - for domain in domain_list: - topology = db_instance.read_from_db("topologies", domain) + for topo in range(1, num_domain_topos + 1): + db_key = f"LC-{topo}" + topology = db_instance.read_from_db("topologies", db_key) if topology: # Get the actual thing minus the Mongo ObjectID. - topology = topology[domain] + topology = topology[db_key] topo_json = json.loads(topology) self.te_manager.add_topology(topo_json) - logger.debug(f"Read {domain}: {topology}") + logger.debug(f"Read {db_key}: {topology}") while not self._exit_event.is_set(): # Queue.get() will block until there's an item in the queue. From bd483de681e853a5613eca71bd8e62071da1d6eb Mon Sep 17 00:00:00 2001 From: Cong Wang Date: Thu, 3 Oct 2024 11:27:36 -0400 Subject: [PATCH 2/2] Clean up --- sdx_controller/handlers/lc_message_handler.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/sdx_controller/handlers/lc_message_handler.py b/sdx_controller/handlers/lc_message_handler.py index 1b9a9b2..aa69b84 100644 --- a/sdx_controller/handlers/lc_message_handler.py +++ b/sdx_controller/handlers/lc_message_handler.py @@ -62,13 +62,7 @@ def process_lc_json_msg( "topologies", "num_domain_topos", num_domain_topos ) else: - # print("----current domain list----") - # print(domain_list) num_domain_topos = len(domain_list) - # num_domain_topos = int(num_domain_topos) + 1 - # self.db_instance.add_key_value_pair_to_db( - # "topologies", "num_domain_topos", num_domain_topos - # ) db_key = "LC-" + str(num_domain_topos) logger.info(f"Adding topology {db_key} to db.")