Skip to content

Commit

Permalink
Merge pull request #199 from atlanticwave-sdx/fix/issue_198
Browse files Browse the repository at this point in the history
Add check for existing inter domain link before adding
  • Loading branch information
italovalcy authored Aug 6, 2024
2 parents 69e047d + 76c4c06 commit 5f40e1b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
55 changes: 40 additions & 15 deletions src/sdx_pce/topology/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ def __init__(self):

self._logger = logging.getLogger(__name__)

# mapping attributes for interdomain links
self.status_map = {
("up", "up"): "up",
("up", "error"): "error",
("error", "up"): "error",
("error", "error"): "error",
# defaults to down
}
self.state_map = {
("enabled", "enabled"): "enabled",
("maintenance", "maintenance"): "maintenance",
("maintenance", "enabled"): "maintenance",
("maintenance", "disabled"): "maintenance",
("enabled", "maintenance"): "maintenance",
("disabled", "maintenance"): "maintenance",
# defults to disabled
}

def get_handler(self):
return self.topology_handler

Expand Down Expand Up @@ -286,25 +304,33 @@ def inter_domain_check(self, topology):

return interdomain_ports

def create_inter_domain_link(self, port1, port2):
"""Creates an interdomain link from two ports."""
def create_update_interdomain_link(self, port1, port2):
"""Create or update an interdomain link from two ports."""
if port2.id < port1.id:
port1, port2 = port2, port1

port1_id = port1.id.replace("urn:sdx:port:", "", 1)
port2_id = port2.id.replace("urn:sdx:port:", "", 1)
link_id = f"urn:sdx:link:interdomain:{port1_id}:{port2_id}"

return Link(
id=link_id,
name=f"{port1.name}--{port2.name}",
ports=[port1.id, port2.id],
bandwidth=100,
residual_bandwidth=100,
latency=0,
packet_loss=0,
availability=100,
)
for link in self._topology.links:
if link_id == link.id:
break
else:
link = Link(
id=link_id,
name=f"{port1.name}--{port2.name}",
ports=[port1.id, port2.id],
bandwidth=100,
residual_bandwidth=100,
latency=0,
packet_loss=0,
availability=100,
)
self._topology.add_links([link])

link.status = self.status_map.get((port1.status, port2.status), "down")
link.state = self.state_map.get((port1.state, port2.state), "disabled")

def add_inter_domain_links(self, topology, interdomain_ports):
"""Add inter-domain links (whenever possible)."""
Expand All @@ -316,12 +342,11 @@ def add_inter_domain_links(self, topology, interdomain_ports):
break
else:
self._logger.warning(
"Interdomin link not added now - didnt find other port:"
"Interdomain link not added now - didnt find other port:"
f" port={port.id} other_port={port.nni}"
)
continue
link = self.create_inter_domain_link(port, other_port)
self._topology.add_links([link])
self.create_update_interdomain_link(port, other_port)

# adjacent matrix of the graph, in jason?
def generate_graph(self):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_topology_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ def test_merge_topology_v2(self):
]
self.assertEqual(len(interdomain_links), 4)

# test update topology
for topology_file in self.TOPOLOGY_FILE_LIST_v2:
topology_data = json.loads(pathlib.Path(topology_file).read_text())
topology_data["version"] += 1
self.topology_manager.update_topology(topology_data)

topology = self.topology_manager.get_topology()

self.assertIsInstance(topology.to_dict(), dict)

self.assertEqual(len(topology.nodes), 8)

self.assertEqual(len(topology.links), 10)

interdomain_links = [
link for link in topology.links if "urn:sdx:link:interdomain:" in link.id
]
self.assertEqual(len(interdomain_links), 4)

def test_update_topology(self):
print("Test Topology Update!")

Expand Down

0 comments on commit 5f40e1b

Please sign in to comment.