Skip to content

Commit

Permalink
Merge pull request #195 from atlanticwave-sdx/194-test-against-the-ne…
Browse files Browse the repository at this point in the history
…w-request-connection-spec-20

confirming to request spec v2
  • Loading branch information
sajith authored Jul 5, 2024
2 parents 9c7e535 + 5878dba commit 85705d9
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = [
"prtpy",
"pydot",
"dataclasses-json",
"sdx-datamodel @ git+https://github.com/atlanticwave-sdx/datamodel@2.0.6.rc2"
"sdx-datamodel @ git+https://github.com/atlanticwave-sdx/datamodel@2.0.6.rc4",
]

[project.urls]
Expand Down
3 changes: 3 additions & 0 deletions src/sdx_pce/topology/temanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,9 @@ def generate_connection_breakdown(
)
same_domain_port_flag = False
if not request_format_is_tm:
connection_request = (
ConnectionHandler().import_connection_data(connection_request).to_dict()
)
self._logger.info(
f'connection_requst ingress_port: {connection_request["ingress_port"]["id"]}'
)
Expand Down
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class TestData:

REQUESTS_DIR = files("sdx_datamodel") / "data" / "requests"
CONNECTION_REQ = REQUESTS_DIR / "test_request.json"
CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_v2 = (
REQUESTS_DIR / "test_request-amlight_zaoxi-p2p-v2.json"
)

# Write test output files in OS temporary directory.
TEST_OUTPUT_DIR = pathlib.Path(tempfile.gettempdir())
Expand Down
91 changes: 91 additions & 0 deletions tests/test_te_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,3 +943,94 @@ def _make_traffic_matrix_from_list(self, old_style_request: list) -> TrafficMatr
)

return TrafficMatrix(connection_requests=new_requests, request_id=self.id())

def test_connection_amlight_to_zaoxi_user_port_v2(self):
"""
Exercise a connection request between Amlight and Zaoxi.
"""
temanager = TEManager(topology_data=None)

for path in (
TestData.TOPOLOGY_FILE_AMLIGHT_USER_PORT,
TestData.TOPOLOGY_FILE_SAX,
TestData.TOPOLOGY_FILE_ZAOXI,
):
topology = json.loads(path.read_text())
temanager.add_topology(topology)

graph = temanager.generate_graph_te()

connection_request = json.loads(
TestData.CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_v2.read_text()
)
print(f"connection_request: {connection_request}")
traffic_matrix = temanager.generate_traffic_matrix(connection_request)

print(f"Generated graph: '{graph}', traffic matrix: '{traffic_matrix}'")

self.assertIsNotNone(graph)
self.assertIsNotNone(traffic_matrix)

conn = temanager.requests_connectivity(traffic_matrix)
print(f"Graph connectivity: {conn}")

solution = TESolver(graph, traffic_matrix).solve()
print(f"TESolver result: {solution}")

self.assertIsNotNone(solution.connection_map)

links = temanager.get_links_on_path(solution)
print(f"Links on path: {links}")

# Make a flat list of links in connection solution dict, and
# check that we have the same number of links.
values = sum([v for v in solution.connection_map.values()], [])
self.assertEqual(len(links), len(values))

breakdown = temanager.generate_connection_breakdown(
solution, connection_request
)
print(f"breakdown: {json.dumps(breakdown)}")

# Note that the "domain" key is correct in the breakdown
# result when we initialize TEManager with None for topology,
# and later add individual topologies with add_topology().
zaoxi = breakdown.get("urn:sdx:topology:zaoxi.net")
sax = breakdown.get("urn:sdx:topology:sax.net")
amlight = breakdown.get("urn:sdx:topology:amlight.net")

# Per https://github.com/atlanticwave-sdx/pce/issues/101, each
# breakdown should be of the below form:
#
# {
# "name": "TENET_vlan_201_203_Ampath_Tenet",
# "dynamic_backup_path": true,
# "uni_a": {
# "tag": {
# "value": 203,
# "tag_type": 1
# },
# "interface_id": "cc:00:00:00:00:00:00:07:41"
# },
# "uni_z": {
# "tag": {
# "value": 201,
# "tag_type": 1
# },
# "interface_id": "cc:00:00:00:00:00:00:08:50"
# }
# }
for segment in [zaoxi, sax, amlight]:
self.assertIsInstance(segment, dict)
self.assertIsInstance(segment.get("name"), str)
self.assertIsInstance(segment.get("dynamic_backup_path"), bool)
self.assertIsInstance(segment.get("uni_a"), dict)
self.assertIsInstance(segment.get("uni_a").get("tag"), dict)
self.assertIsInstance(segment.get("uni_a").get("tag").get("value"), int)
self.assertIsInstance(segment.get("uni_a").get("tag").get("tag_type"), int)
self.assertIsInstance(segment.get("uni_a").get("port_id"), str)
self.assertIsInstance(segment.get("uni_z"), dict)
self.assertIsInstance(segment.get("uni_z").get("tag"), dict)
self.assertIsInstance(segment.get("uni_z").get("tag").get("value"), int)
self.assertIsInstance(segment.get("uni_z").get("tag").get("tag_type"), int)
self.assertIsInstance(segment.get("uni_z").get("port_id"), str)

0 comments on commit 85705d9

Please sign in to comment.