From 2755366b1f38ce9db9b23cddadc38228eb21a01e Mon Sep 17 00:00:00 2001 From: Cong Wang Date: Tue, 1 Oct 2024 08:31:09 -0400 Subject: [PATCH 1/6] Add topology when initializing TE manager --- sdx_controller/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sdx_controller/__init__.py b/sdx_controller/__init__.py index 70896fc..0f400a4 100644 --- a/sdx_controller/__init__.py +++ b/sdx_controller/__init__.py @@ -64,8 +64,15 @@ def create_app(run_listener: bool = True): app.db_instance = DbUtils() app.db_instance.initialize_db() + topo_val = app.db_instance.read_from_db("topologies", "latest_topo") + print("-----Topo_val-----") + print(topo_val["latest_topo"]) # Get a handle to PCE. - app.te_manager = TEManager(topology_data=None) + app.te_manager = ( + TEManager(topology_data=topo_val["latest_topo"]) + if topo_val + else TEManager(topology_data=None) + ) # TODO: This is a hack, until we find a better way to get a handle # to TEManager from Flask current_app, which are typically From e31e0bd5a6b3503740db699d4e525a30f6ec8588 Mon Sep 17 00:00:00 2001 From: Cong Wang Date: Tue, 1 Oct 2024 08:34:41 -0400 Subject: [PATCH 2/6] Clean up --- sdx_controller/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdx_controller/__init__.py b/sdx_controller/__init__.py index 0f400a4..c165c98 100644 --- a/sdx_controller/__init__.py +++ b/sdx_controller/__init__.py @@ -65,8 +65,7 @@ def create_app(run_listener: bool = True): app.db_instance.initialize_db() topo_val = app.db_instance.read_from_db("topologies", "latest_topo") - print("-----Topo_val-----") - print(topo_val["latest_topo"]) + # Get a handle to PCE. app.te_manager = ( TEManager(topology_data=topo_val["latest_topo"]) From fe808d32437118113ad9a9c96cfb2dc21e5ba144 Mon Sep 17 00:00:00 2001 From: Cong Wang Date: Tue, 1 Oct 2024 10:26:37 -0400 Subject: [PATCH 3/6] Load json string --- sdx_controller/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdx_controller/__init__.py b/sdx_controller/__init__.py index c165c98..882f487 100644 --- a/sdx_controller/__init__.py +++ b/sdx_controller/__init__.py @@ -2,6 +2,7 @@ import os import threading from queue import Queue +import json import connexion from sdx_pce.topology.temanager import TEManager @@ -68,7 +69,7 @@ def create_app(run_listener: bool = True): # Get a handle to PCE. app.te_manager = ( - TEManager(topology_data=topo_val["latest_topo"]) + TEManager(topology_data=json.loads(topo_val["latest_topo"])) if topo_val else TEManager(topology_data=None) ) From e8d3872bb98122afc1c6eedf2c21a3e18d6fc196 Mon Sep 17 00:00:00 2001 From: Cong Wang Date: Tue, 1 Oct 2024 11:40:04 -0400 Subject: [PATCH 4/6] Update LC name calculation --- compose.yml | 1 + sdx_controller/handlers/lc_message_handler.py | 14 +++++++------- sdx_controller/messaging/rpc_queue_consumer.py | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/compose.yml b/compose.yml index 981f6bc..1a740a1 100644 --- a/compose.yml +++ b/compose.yml @@ -23,6 +23,7 @@ services: # MongoDB logs can drown out everything else, so we'll write # them to a file. To watch the log messages, use: `docker exec # -it tail -f /var/log/mongodb/mongod.log`. + - '--quiet' - '--logpath' - '/var/log/mongodb/mongod.log' healthcheck: diff --git a/sdx_controller/handlers/lc_message_handler.py b/sdx_controller/handlers/lc_message_handler.py index cea5f31..58823c0 100644 --- a/sdx_controller/handlers/lc_message_handler.py +++ b/sdx_controller/handlers/lc_message_handler.py @@ -53,7 +53,7 @@ def process_lc_json_msg( "domains", "domain_list", domain_list ) - logger.info("Adding topo") + logger.info("Adding topology to TE manager") self.te_manager.add_topology(msg_json) if self.db_instance.read_from_db("topologies", "num_domain_topos") is None: @@ -63,16 +63,16 @@ def process_lc_json_msg( ) else: 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 ) - logger.info("Adding topo to db.") - db_key = "LC-" + str(num_domain_topos) - self.db_instance.add_key_value_pair_to_db( - "topologies", db_key, json.dumps(msg_json) - ) + logger.info("Adding topology to db.") + db_key = "LC-" + str(num_domain_topos) + + self.db_instance.add_key_value_pair_to_db( + "topologies", db_key, json.dumps(msg_json) + ) # TODO: use TEManager API directly; but TEManager does not # expose a `get_topology()` method yet. diff --git a/sdx_controller/messaging/rpc_queue_consumer.py b/sdx_controller/messaging/rpc_queue_consumer.py index 546623a..3356b72 100644 --- a/sdx_controller/messaging/rpc_queue_consumer.py +++ b/sdx_controller/messaging/rpc_queue_consumer.py @@ -111,7 +111,7 @@ 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 topo in range(1, num_domain_topos + 2): + for topo in range(1, num_domain_topos + 1): db_key = f"LC-{topo}" topology = db_instance.read_from_db("topologies", db_key) From 1672839345300e027d0c5fb262cc1902d17289ae Mon Sep 17 00:00:00 2001 From: Cong Wang Date: Tue, 1 Oct 2024 13:07:18 -0400 Subject: [PATCH 5/6] Use domain name as key to save topology --- sdx_controller/handlers/lc_message_handler.py | 9 ++++----- sdx_controller/messaging/rpc_queue_consumer.py | 10 +++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/sdx_controller/handlers/lc_message_handler.py b/sdx_controller/handlers/lc_message_handler.py index 58823c0..d58e878 100644 --- a/sdx_controller/handlers/lc_message_handler.py +++ b/sdx_controller/handlers/lc_message_handler.py @@ -67,12 +67,11 @@ def process_lc_json_msg( "topologies", "num_domain_topos", num_domain_topos ) - logger.info("Adding topology to db.") - db_key = "LC-" + str(num_domain_topos) + logger.info("Adding topology to db: " + domain_name) - self.db_instance.add_key_value_pair_to_db( - "topologies", db_key, json.dumps(msg_json) - ) + self.db_instance.add_key_value_pair_to_db( + "topologies", domain_name, json.dumps(msg_json) + ) # TODO: use TEManager API directly; but TEManager does not # expose a `get_topology()` method yet. diff --git a/sdx_controller/messaging/rpc_queue_consumer.py b/sdx_controller/messaging/rpc_queue_consumer.py index 3356b72..379cf96 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 topo in range(1, num_domain_topos + 1): - db_key = f"LC-{topo}" - topology = db_instance.read_from_db("topologies", db_key) + + for domain in domain_list: + topology = db_instance.read_from_db("topologies", domain) if topology: # Get the actual thing minus the Mongo ObjectID. - topology = topology[db_key] + topology = topology[domain] topo_json = json.loads(topology) self.te_manager.add_topology(topo_json) - logger.debug(f"Read {db_key}: {topology}") + logger.debug(f"Read {domain}: {topology}") while not self._exit_event.is_set(): # Queue.get() will block until there's an item in the queue. From 7c9b358b8b6229dc552c8c63796ede0aabc0cfeb Mon Sep 17 00:00:00 2001 From: Cong Wang Date: Tue, 1 Oct 2024 13:24:36 -0400 Subject: [PATCH 6/6] isort --- sdx_controller/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdx_controller/__init__.py b/sdx_controller/__init__.py index 882f487..f238e82 100644 --- a/sdx_controller/__init__.py +++ b/sdx_controller/__init__.py @@ -1,8 +1,8 @@ +import json import logging import os import threading from queue import Queue -import json import connexion from sdx_pce.topology.temanager import TEManager