Skip to content
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

Use pce 2.0.6 #198

Merged
merged 12 commits into from
Jan 18, 2024
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ pika >= 1.2.0
dataset
pymongo > 3.0

sdx-pce @ git+https://github.com/atlanticwave-sdx/[email protected].3
sdx-pce @ git+https://github.com/atlanticwave-sdx/[email protected].6.dev2
5 changes: 3 additions & 2 deletions swagger_server/controllers/connection_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def place_connection(body):
db_instance.add_key_value_pair_to_db("connection_data", json.dumps(body))
logger.info("Saving to database complete.")

connection_handler.place_connection(body)
reason, code = connection_handler.place_connection(body)
logger.info(f"place_connection result: reason='{reason}', code={code}")

return "Connection published"
return reason, code
36 changes: 26 additions & 10 deletions swagger_server/handlers/connection_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
from typing import Tuple

from sdx_pce.load_balancing.te_solver import TESolver
from sdx_pce.topology.temanager import TEManager
Expand All @@ -21,8 +22,7 @@ def remove_connection(self, connection):
# call pce to remove connection
pass

def _send_breakdown_to_lc(self, temanager, connection, solution):
breakdown = temanager.generate_connection_breakdown(solution)
def _send_breakdown_to_lc(self, breakdown, connection_request):
logger.debug(f"-- BREAKDOWN: {json.dumps(breakdown)}")

if breakdown is None:
Expand Down Expand Up @@ -53,8 +53,8 @@ def _send_breakdown_to_lc(self, temanager, connection, solution):
if simple_link not in link_connections_dict:
link_connections_dict[simple_link] = []

if connection not in link_connections_dict[simple_link]:
link_connections_dict[simple_link].append(connection)
if connection_request not in link_connections_dict[simple_link]:
link_connections_dict[simple_link].append(connection_request)

self.db_instance.add_key_value_pair_to_db(
"link_connections_dict", json.dumps(link_connections_dict)
Expand All @@ -81,8 +81,21 @@ def _send_breakdown_to_lc(self, temanager, connection, solution):
producer.call(json.dumps(link))
producer.stop_keep_alive()

def place_connection(self, connection):
# call pce to generate breakdown, and place connection
# We will get to this point only if all the previous steps
# leading up to this point were successful.
return "Connection published", 200

def place_connection(self, connection_request: dict) -> Tuple[str, int]:
"""
Do the actual work of creating a connection.

This method will call pce library to generate a breakdown
across relevant domains, and then send individual connection
requests to each of those domains.

Note that we can return early if things fail. Return value is
a tuple of the form (reason, HTTP code).
"""
num_domain_topos = 0

if self.db_instance.read_from_db("num_domain_topos"):
Expand All @@ -93,7 +106,7 @@ def place_connection(self, connection):
# Initializing TEManager with `None` topology data is a
# work-around for
# https://github.com/atlanticwave-sdx/sdx-controller/issues/145
temanager = TEManager(topology_data=None, connection_data=connection)
temanager = TEManager(topology_data=None)
lc_domain_topo_dict = {}

# Read LC-1, LC-2, LC-3, and LC-4 topologies because of
Expand All @@ -120,14 +133,16 @@ def place_connection(self, connection):
)
temanager.add_topology(curr_topo_json)

for num, val in enumerate(temanager.topology_manager.topology_list):
for num, val in enumerate(temanager.get_topology_map().values()):
logger.info(f"TE topology #{num}: {val}")

graph = temanager.generate_graph_te()
if graph is None:
return "Could not generate a graph", 400

traffic_matrix = temanager.generate_connection_te()
traffic_matrix = temanager.generate_traffic_matrix(
connection_request=connection_request
)
if traffic_matrix is None:
return "Could not generate a traffic matrix", 400

Expand All @@ -140,7 +155,8 @@ def place_connection(self, connection):
if solution is None or solution.connection_map is None:
return "Could not solve the request", 400

self._send_breakdown_to_lc(temanager, connection, solution)
breakdown = temanager.generate_connection_breakdown(solution)
self._send_breakdown_to_lc(breakdown, connection_request)

def handle_link_failure(self, msg_json):
logger.debug("---Handling connections that contain failed link.---")
Expand Down