Skip to content

Commit

Permalink
Merge pull request #310 from atlanticwave-sdx/fix/issue_161
Browse files Browse the repository at this point in the history
Modify link failure handler to leverage topology update messages
  • Loading branch information
italovalcy authored Aug 12, 2024
2 parents 24a592d + 4ea5ef9 commit 59e776d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 15 deletions.
62 changes: 50 additions & 12 deletions sdx_controller/handlers/connection_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def _send_breakdown_to_lc(self, breakdown, operation, connection_request):
else:
link_connections_dict = {}

interdomain_a, interdomain_b = None, None
for domain, link in breakdown.items():
port_list = []
for key in link.keys():
Expand All @@ -50,13 +51,51 @@ def _send_breakdown_to_lc(self, breakdown, operation, connection_request):
if simple_link not in link_connections_dict:
link_connections_dict[simple_link] = []

if connection_request not in link_connections_dict[simple_link]:
if (
operation == "post"
and connection_request not in link_connections_dict[simple_link]
):
link_connections_dict[simple_link].append(connection_request)

if (
operation == "delete"
and connection_request in link_connections_dict[simple_link]
):
link_connections_dict[simple_link].remove(connection_request)

self.db_instance.add_key_value_pair_to_db(
"links", "link_connections_dict", json.dumps(link_connections_dict)
)

if interdomain_a:
interdomain_b = link.get("uni_a", {}).get("port_id")
else:
interdomain_a = link.get("uni_z", {}).get("port_id")

if interdomain_a and interdomain_b:
simple_link = SimpleLink([interdomain_a, interdomain_b]).to_string()

if simple_link not in link_connections_dict:
link_connections_dict[simple_link] = []

if (
operation == "post"
and connection_request not in link_connections_dict[simple_link]
):
link_connections_dict[simple_link].append(connection_request)

if (
operation == "delete"
and connection_request in link_connections_dict[simple_link]
):
link_connections_dict[simple_link].remove(connection_request)

self.db_instance.add_key_value_pair_to_db(
"links", "link_connections_dict", json.dumps(link_connections_dict)
)

interdomain_a = link.get("uni_z", {}).get("port_id")

logger.debug(f"Attempting to publish domain: {domain}, link: {link}")

# From "urn:ogf:network:sdx:topology:amlight.net", attempt to
Expand Down Expand Up @@ -142,15 +181,15 @@ def remove_connection(self, te_manager, connection_id) -> Tuple[str, int]:

try:
status, code = self._send_breakdown_to_lc(
breakdown, "delete", connection_request
breakdown, "delete", json.loads(connection_request)
)
logger.debug(f"Breakdown sent to LC, status: {status}, code: {code}")
return status, code
except Exception as e:
logger.debug(f"Error when removing breakdown: {e}")
return f"Error: {e}", 400

def handle_link_failure(self, te_manager, msg_json):
def handle_link_failure(self, te_manager, failed_links):
logger.debug("---Handling connections that contain failed link.---")
link_connections_dict_str = self.db_instance.read_from_db(
"links", "link_connections_dict"
Expand All @@ -167,31 +206,30 @@ def handle_link_failure(self, te_manager, msg_json):
link_connections_dict_str["link_connections_dict"]
)

for link in msg_json["link_failure"]:
for link in failed_links:
logger.info(f"Handling link failure on {link['id']} ({link['ports']})")
port_list = []
if "ports" not in link:
continue
for port in link["ports"]:
if "id" not in port:
port_id = port if isinstance(port, str) else port.get("id")
if not port_id:
continue
port_list.append(port["id"])
port_list.append(port_id)

simple_link = SimpleLink(port_list).to_string()

if simple_link in link_connections_dict:
logger.debug("Found failed link record!")
connections = link_connections_dict[simple_link]
for index, connection in enumerate(connections):
logger.info(
f"Connection {connection['id']} affected by link {link['id']}"
)
if "id" not in connection:
continue
self.remove_connection(te_manager, connection["id"])
del link_connections_dict[simple_link][index]
logger.debug("Removed connection:")
logger.debug(connection)
self.place_connection(te_manager, connection)
link_connections_dict[simple_link].append(connection)

self.db_instance.delete_one_entry("links", "link_connections_dict")
self.db_instance.add_key_value_pair_to_db(
"links", "link_connections_dict", json.dumps(link_connections_dict)
)
7 changes: 5 additions & 2 deletions sdx_controller/handlers/lc_message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ def process_lc_json_msg(
logger.info("Updating topo")
logger.debug(msg_json)
self.te_manager.update_topology(msg_json)
if "link_failure" in msg_json:
failed_links = self.te_manager.get_failed_links()
if failed_links:
logger.info("Processing link failure.")
self.connection_handler.handle_link_failure(self.te_manager, msg_json)
self.connection_handler.handle_link_failure(
self.te_manager, failed_links
)
# Add new topology
else:
domain_list.append(domain_name)
Expand Down
2 changes: 1 addition & 1 deletion sdx_controller/models/simple_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class SimpleLink:
def __init__(self, ports: List[str]):
self._ports = ports
self.ports = ports

@property
def ports(self) -> List[str]:
Expand Down

0 comments on commit 59e776d

Please sign in to comment.