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

Remove old breakdown method #151

Merged
merged 5 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 2 additions & 109 deletions src/sdx_pce/topology/temanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,9 @@ def requests_connectivity(self, tm: TrafficMatrix) -> bool:

return True

def generate_connection_breakdown(self, connection) -> dict:
def generate_connection_breakdown(self, connection: ConnectionSolution) -> dict:
"""
A "router" method for backward compatibility.
"""
if isinstance(connection, ConnectionSolution):
return self._generate_connection_breakdown_tm(connection)
return self._generate_connection_breakdown_old(connection)

def _generate_connection_breakdown_tm(self, connection: ConnectionSolution) -> dict:
"""
Take a connection and generate a breakdown.
Take a connection solution and generate a breakdown.

This is an alternative to generate_connection_breakdown()
below which uses the newly defined types from sdx_pce.models.
Expand All @@ -282,9 +274,6 @@ def _generate_connection_breakdown_tm(self, connection: ConnectionSolution) -> d
breakdown = {}
paths = connection.connection_map # p2p for now

# i_port = None
# e_port = None

for domain, links in paths.items():
print(f"domain: {domain}, links: {links}")

Expand Down Expand Up @@ -371,102 +360,6 @@ def _generate_connection_breakdown_tm(self, connection: ConnectionSolution) -> d
# expected format.
return tagged_breakdown.to_dict().get("breakdowns")

def _generate_connection_breakdown_old(self, connection):
"""
Take a connection and generate a breakdown.

TODO: remove this when convenient.
https://github.com/atlanticwave-sdx_pce/issues/125
"""
assert connection is not None

breakdown = {}
paths = connection[0] # p2p for now
# cost = connection[1]
i_port = None
e_port = None

print(f"Domain breakdown with graph: {self.graph}")
print(f"Graph nodes: {self.graph.nodes}")
print(f"Graph edges: {self.graph.edges}")

print(f"Paths: {paths}")

for i, j in paths.items():
print(f"i: {i}, j: {j}")
current_link_set = []
for count, link in enumerate(j):
print(f"count: {count}, link: {link}")
assert len(link) == 2

node_1 = self.graph.nodes.get(link[0])
assert node_1 is not None

node_2 = self.graph.nodes.get(link[1])
assert node_2 is not None

print(f"node_1: {node_1}, node_2: {node_2}")

domain_1 = self.topology_manager.get_domain_name(node_1["id"])
domain_2 = self.topology_manager.get_domain_name(node_2["id"])

# # TODO: handle the cases where a domain was not found.
# if domain_1 is None:
# domain_1 = f"domain_{i}"
# if domain_2 is None:
# domain_2 = f"domain_{i}"

print(f"domain_1: {domain_1}, domain_2: {domain_2}")

current_link_set.append(link)
current_domain = domain_1
if domain_1 == domain_2:
# current_domain = domain_1
if count == len(j) - 1:
breakdown[current_domain] = current_link_set.copy()
else:
breakdown[current_domain] = current_link_set.copy()
current_domain = None
current_link_set = []

print(f"[intermediate] breakdown: {breakdown}")

# now starting with the ingress_port
first = True
i = 0
domain_breakdown = {}

for domain, links in breakdown.items():
print(f"Creating domain_breakdown: domain: {domain}, links: {links}")
segment = {}
if first:
first = False
last_link = links[-1]
n1 = self.graph.nodes[last_link[0]]["id"]
n2 = self.graph.nodes[last_link[1]]["id"]
n1, p1, n2, p2 = self.topology_manager.topology.get_port_by_link(n1, n2)
i_port = self.connection.ingress_port.to_dict()
e_port = p1
next_i = p2
elif i == len(breakdown) - 1:
i_port = next_i
e_port = self.connection.egress_port.to_dict()
else:
last_link = links[-1]
n1 = self.graph.nodes[last_link[0]]["id"]
n2 = self.graph.nodes[last_link[1]]["id"]
n1, p1, n2, p2 = self.topology_manager.topology.get_port_by_link(n1, n2)
i_port = next_i
e_port = p1
next_i = p2
segment["ingress_port"] = i_port
segment["egress_port"] = e_port
domain_breakdown[domain] = segment.copy()
i = i + 1

print(f"generate_connection_breakdown(): domain_breakdown: {domain_breakdown}")
return domain_breakdown

"""
functions for vlan reservation.

Expand Down
20 changes: 2 additions & 18 deletions tests/test_te_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,8 @@ def test_generate_solver_input(self):
self.assertIsNotNone(connection)

def test_connection_breakdown_none_input(self):
# Expect an error to be raised.
self.assertRaises(
AssertionError, self.temanager.generate_connection_breakdown, None
)

def test_connection_breakdown_simple(self):
# Test that the old way, which had plain old dicts and arrays
# representing connection requests, still works.
request = [
{
"1": [[0, 1], [1, 2]],
},
1.0,
]

breakdown = self.temanager.generate_connection_breakdown(request)
print(f"Breakdown: {breakdown}")
self.assertIsNotNone(breakdown)
# Expect no breakdown when input is None.
self.assertIsNone(self.temanager.generate_connection_breakdown(None))

def test_connection_breakdown_tm(self):
# Breaking down a traffic matrix.
Expand Down