From 15212106c1416175cfeee3ea3963ef8bac4c5abb Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 13 Sep 2024 22:28:01 -0500 Subject: [PATCH 01/17] Use datamodel PR branch while testing --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7e51d402..5f7f265f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ dependencies = [ "prtpy", "pydot", "dataclasses-json", - "sdx-datamodel @ git+https://github.com/atlanticwave-sdx/datamodel@3.0.0.dev0", + "sdx-datamodel @ git+https://github.com/atlanticwave-sdx/datamodel@148.pydantic-connection-requests", ] [project.urls] From c91a5b0cd90ea38ce1737cb63aab594ce52172e9 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 13 Sep 2024 22:28:26 -0500 Subject: [PATCH 02/17] Use correct request file --- tests/__init__.py | 4 ++-- tests/test_te_manager.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 1c56a228..e670bbf0 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -23,8 +23,8 @@ 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" + CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_V1 = ( + REQUESTS_DIR / "v1.0" / "test-request-amlight-zaoxi-p2p.json" ) # Write test output files in OS temporary directory. diff --git a/tests/test_te_manager.py b/tests/test_te_manager.py index e2f44e71..5ad4a285 100644 --- a/tests/test_te_manager.py +++ b/tests/test_te_manager.py @@ -1080,7 +1080,7 @@ def test_connection_amlight_to_zaoxi_user_port_v2(self): graph = temanager.generate_graph_te() connection_request = json.loads( - TestData.CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_v2.read_text() + TestData.CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_V1.read_text() ) # Modify the connection request for this test so that we have @@ -1205,7 +1205,7 @@ def test_connection_amlight_to_zaoxi_user_port_any(self): graph = temanager.generate_graph_te() connection_request = json.loads( - TestData.CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_v2.read_text() + TestData.CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_V1.read_text() ) # Rewrite the request to have VLAN of "any". From 7d2e67641c1dec996af0ee2fb8242157c202da79 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 13 Sep 2024 22:30:25 -0500 Subject: [PATCH 03/17] Remove workaround --- tests/test_te_manager.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/test_te_manager.py b/tests/test_te_manager.py index 5ad4a285..1a11d263 100644 --- a/tests/test_te_manager.py +++ b/tests/test_te_manager.py @@ -1083,15 +1083,6 @@ def test_connection_amlight_to_zaoxi_user_port_v2(self): TestData.CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_V1.read_text() ) - # Modify the connection request for this test so that we have - # a solvable one. The original one asks for (1) a VLAN that is - # not present on the ingress port (777), and (2) a range - # ("55:90") on the egress port. This is an unsolvable request - # because of (1), and an invalid one because of (2) since both - # ports have to use a range. - connection_request["endpoints"][0]["vlan"] = "100" - connection_request["endpoints"][1]["vlan"] = "100" - print(f"connection_request: {connection_request}") traffic_matrix = temanager.generate_traffic_matrix(connection_request) From 0b1370eb3d36acbebec7f49c6d636e61d906ee9d Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Thu, 19 Sep 2024 08:37:22 -0500 Subject: [PATCH 04/17] Use correct connection request format One VLAN in ingress must correspond to one VLAN on egress, not a range. --- tests/test_te_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_te_manager.py b/tests/test_te_manager.py index 1a11d263..35b5a6d9 100644 --- a/tests/test_te_manager.py +++ b/tests/test_te_manager.py @@ -1291,7 +1291,7 @@ def test_disallowed_vlan(self): }, { "port_id": "urn:sdx:port:amlight:B1:1", - "vlan": "55:90" + "vlan": "777" } ] } From 182cdeea9ed44cd4b60182ef5ccd4d7e744258df Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Thu, 19 Sep 2024 08:38:07 -0500 Subject: [PATCH 05/17] Attempt to use Pydantic connection requests Unfortunately things fail as of now --- src/sdx_pce/topology/temanager.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/sdx_pce/topology/temanager.py b/src/sdx_pce/topology/temanager.py index 4afa387f..868acdee 100644 --- a/src/sdx_pce/topology/temanager.py +++ b/src/sdx_pce/topology/temanager.py @@ -3,10 +3,16 @@ from itertools import chain from typing import List, Optional +from pydantic import ValidationError + import networkx as nx from networkx.algorithms import approximation as approx from sdx_datamodel.models.port import Port from sdx_datamodel.parsing.connectionhandler import ConnectionHandler +from sdx_datamodel.models.connection_request import ( + ConnectionRequestV0, + ConnectionRequestV1, +) from sdx_pce.models import ( ConnectionPath, @@ -204,7 +210,16 @@ def generate_traffic_matrix(self, connection_request: dict) -> TrafficMatrix: f"generate_traffic_matrix: connection_request: {connection_request}" ) - request = ConnectionHandler().import_connection_data(connection_request) + try: + # request = ConnectionRequestV0(**connection_request) + # except ValidationError: + print("TRYING V1") + request = ConnectionRequestV1(**connection_request) + except Exception as e: + print(f"COULD NOT USE {connection_request}: {e}") + return None + + # request = ConnectionHandler().import_connection_data(connection_request) self._logger.info(f"generate_traffic_matrix: decoded request: {request}") From abfb07fe4b26aee41844ffae1393b9b83bcf9238 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Wed, 19 Mar 2025 12:03:14 -0500 Subject: [PATCH 06/17] Remove old Python versions from tox env list --- tox.ini | 2 -- 1 file changed, 2 deletions(-) diff --git a/tox.ini b/tox.ini index 3ecdb2e2..2ebbeac4 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,5 @@ [tox] env_list = - py39 - py310 py311 py312 From b6019b445a744de51bf831d1bd0117cd10a4ab07 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Wed, 19 Mar 2025 19:04:21 -0500 Subject: [PATCH 07/17] Update test data path --- tests/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/__init__.py b/tests/__init__.py index fb10c547..13724952 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -16,7 +16,7 @@ class TestData: TOPOLOGY_FILE_AMLIGHT_USER_PORT = TOPOLOGY_DIR / "amlight_user_port.json" REQUESTS_DIR = files("sdx_datamodel") / "data" / "requests" - CONNECTION_REQ = REQUESTS_DIR / "test_request.json" + CONNECTION_REQ = REQUESTS_DIR / "v0" / "test_request.json" CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_V1 = ( REQUESTS_DIR / "v1.0" / "test-request-amlight-zaoxi-p2p.json" ) From a57e13d127fd9edc20c8114c8e62d0685a949711 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Thu, 20 Mar 2025 13:39:51 -0500 Subject: [PATCH 08/17] Run black and isort --- src/sdx_pce/topology/temanager.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/sdx_pce/topology/temanager.py b/src/sdx_pce/topology/temanager.py index fef2418e..c0f33313 100644 --- a/src/sdx_pce/topology/temanager.py +++ b/src/sdx_pce/topology/temanager.py @@ -5,20 +5,18 @@ from itertools import chain from typing import List, Optional -from pydantic import ValidationError - import networkx as nx from networkx.algorithms import approximation as approx -from sdx_datamodel.models.port import Port -from sdx_datamodel.parsing.connectionhandler import ConnectionHandler - +from pydantic import ValidationError +from sdx_datamodel.models.connection_request import ( + ConnectionRequest as DmConnectionRequest, +) from sdx_datamodel.models.connection_request import ( ConnectionRequestV0, ConnectionRequestV1, ) - -from sdx_datamodel.models.connection_request import ConnectionRequest as DmConnectionRequest - +from sdx_datamodel.models.port import Port +from sdx_datamodel.parsing.connectionhandler import ConnectionHandler from sdx_datamodel.parsing.exceptions import ( MissingAttributeException, ServiceNotSupportedException, From b5f5fd0d2185002b085a63af5dde48dd52a84ae5 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Thu, 20 Mar 2025 13:44:36 -0500 Subject: [PATCH 09/17] Disable unused imports for now --- src/sdx_pce/topology/temanager.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/sdx_pce/topology/temanager.py b/src/sdx_pce/topology/temanager.py index c0f33313..4019e3cb 100644 --- a/src/sdx_pce/topology/temanager.py +++ b/src/sdx_pce/topology/temanager.py @@ -1,27 +1,31 @@ import logging import re import threading -import traceback + +# import traceback from itertools import chain from typing import List, Optional import networkx as nx from networkx.algorithms import approximation as approx -from pydantic import ValidationError + +# from pydantic import ValidationError from sdx_datamodel.models.connection_request import ( ConnectionRequest as DmConnectionRequest, ) -from sdx_datamodel.models.connection_request import ( - ConnectionRequestV0, - ConnectionRequestV1, -) + +# from sdx_datamodel.models.connection_request import ( +# ConnectionRequestV0, +# ConnectionRequestV1, +# ) from sdx_datamodel.models.port import Port from sdx_datamodel.parsing.connectionhandler import ConnectionHandler -from sdx_datamodel.parsing.exceptions import ( - MissingAttributeException, - ServiceNotSupportedException, -) -from sdx_datamodel.validation.connectionvalidator import ConnectionValidator + +# from sdx_datamodel.parsing.exceptions import ( +# MissingAttributeException, +# ServiceNotSupportedException, +# ) +# from sdx_datamodel.validation.connectionvalidator import ConnectionValidator from sdx_pce.models import ( ConnectionPath, @@ -36,7 +40,7 @@ from sdx_pce.topology.manager import TopologyManager from sdx_pce.utils.constants import Constants from sdx_pce.utils.exceptions import ( - RequestValidationError, + # RequestValidationError, TEError, UnknownRequestError, ValidationError, From 5f9668fec828e79b636cd3ca08b88eb1e78dff72 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 21 Mar 2025 20:07:54 -0500 Subject: [PATCH 10/17] Construct the request object the right way --- src/sdx_pce/topology/temanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdx_pce/topology/temanager.py b/src/sdx_pce/topology/temanager.py index 4019e3cb..b3d9e0d2 100644 --- a/src/sdx_pce/topology/temanager.py +++ b/src/sdx_pce/topology/temanager.py @@ -380,7 +380,7 @@ def generate_traffic_matrix(self, connection_request: dict) -> TrafficMatrix: ) try: - request = DmConnectionRequest.parse_obj(connection_request) + request = DmConnectionRequest(**connection_request) except Exception as e: print(f"Exception: could not validate {connection_request}: {e}") raise e From 9500fdd717315ac70bc3184b47e6aa0dc762fe2f Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 21 Mar 2025 20:08:16 -0500 Subject: [PATCH 11/17] Use the right assertion --- tests/test_te_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_te_manager.py b/tests/test_te_manager.py index 587702fe..6071494d 100644 --- a/tests/test_te_manager.py +++ b/tests/test_te_manager.py @@ -1534,7 +1534,7 @@ def test_identical_vlan_ranges(self): print(f"ex = {ex}") self.assertIsNotNone(graph) - self.assertIsNone(traffic_matrix) + self.assertIsNotNone(traffic_matrix) def test_disallowed_vlan(self): """ From f6e6077a843b7865742b3883562bd3cfb4fb0bab Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 21 Mar 2025 20:48:48 -0500 Subject: [PATCH 12/17] Use model_validate() rather --- src/sdx_pce/topology/temanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdx_pce/topology/temanager.py b/src/sdx_pce/topology/temanager.py index ead4b2b8..ede7a44e 100644 --- a/src/sdx_pce/topology/temanager.py +++ b/src/sdx_pce/topology/temanager.py @@ -381,7 +381,7 @@ def generate_traffic_matrix(self, connection_request: dict) -> TrafficMatrix: ) try: - request = DmConnectionRequest(**connection_request) + request = DmConnectionRequest.model_validate(connection_request) except Exception as e: print(f"Exception: could not validate {connection_request}: {e}") raise e From b130a18faadaeb49179463d586e47ff2eb87fff7 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Sat, 22 Mar 2025 12:09:25 -0500 Subject: [PATCH 13/17] Use version suffixes consistently with test request files --- tests/__init__.py | 6 +++--- tests/test_te_manager.py | 22 +++++++++++----------- tests/test_te_solver_static.py | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 13724952..24739d44 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -16,11 +16,11 @@ class TestData: TOPOLOGY_FILE_AMLIGHT_USER_PORT = TOPOLOGY_DIR / "amlight_user_port.json" REQUESTS_DIR = files("sdx_datamodel") / "data" / "requests" - CONNECTION_REQ = REQUESTS_DIR / "v0" / "test_request.json" - CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_V1 = ( + CONNECTION_REQ_v0 = REQUESTS_DIR / "v0" / "test_request.json" + CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_v1 = ( REQUESTS_DIR / "v1.0" / "test-request-amlight-zaoxi-p2p.json" ) - CONNECTION_REQ_AMLIGHT_SAX_v2 = ( + CONNECTION_REQ_AMLIGHT_SAX_v1 = ( REQUESTS_DIR / "v1.0" / "test-request-amlight_sax-p2p-v2.json" ) diff --git a/tests/test_te_manager.py b/tests/test_te_manager.py index f8c5b7f4..79576974 100644 --- a/tests/test_te_manager.py +++ b/tests/test_te_manager.py @@ -555,7 +555,7 @@ def test_connection_amlight_to_zaoxi(self): graph = temanager.generate_graph_te() - connection_request = json.loads(TestData.CONNECTION_REQ.read_text()) + connection_request = json.loads(TestData.CONNECTION_REQ_v0.read_text()) print(f"connection_request: {connection_request}") traffic_matrix = temanager.generate_traffic_matrix(connection_request) @@ -748,7 +748,7 @@ def test_delete_connection(self): # Create a connection request connection_request = json.loads( - TestData.CONNECTION_REQ_AMLIGHT_SAX_v2.read_text() + TestData.CONNECTION_REQ_AMLIGHT_SAX_v1.read_text() ) traffic_matrix = temanager.generate_traffic_matrix(connection_request) self.assertIsInstance(traffic_matrix, TrafficMatrix) @@ -788,7 +788,7 @@ def test_connection_amlight_to_sax_v2(self): graph = temanager.generate_graph_te() connection_request = json.loads( - TestData.CONNECTION_REQ_AMLIGHT_SAX_v2.read_text() + TestData.CONNECTION_REQ_AMLIGHT_SAX_v1.read_text() ) print(f"connection_request: {connection_request}") traffic_matrix = temanager.generate_traffic_matrix(connection_request) @@ -860,7 +860,7 @@ def test_connection_amlight_to_zaoxi_two_identical_requests(self): graph = temanager.generate_graph_te() - connection_request = json.loads(TestData.CONNECTION_REQ.read_text()) + connection_request = json.loads(TestData.CONNECTION_REQ_v0.read_text()) print(f"connection_request: {connection_request}") traffic_matrix = temanager.generate_traffic_matrix(connection_request) @@ -935,7 +935,7 @@ def test_connection_amlight_to_zaoxi_many_identical_requests(self): graph = temanager.generate_graph_te() - connection_request = json.loads(TestData.CONNECTION_REQ.read_text()) + connection_request = json.loads(TestData.CONNECTION_REQ_v0.read_text()) init_vlan = connection_request["ingress_port"]["label_range"] breakdowns = set() num_requests = 10 @@ -999,7 +999,7 @@ def test_connection_amlight_to_zaoxi_two_distinct_requests(self): self.assertIsInstance(graph, nx.Graph) # Use a connection request that should span all three domains. - connection_request1 = json.loads(TestData.CONNECTION_REQ.read_text()) + connection_request1 = json.loads(TestData.CONNECTION_REQ_v0.read_text()) print(f"Connection request #1: {connection_request1}") traffic_matrix1 = temanager.generate_traffic_matrix(connection_request1) @@ -1072,7 +1072,7 @@ def test_connection_amlight_to_zaoxi_two_distinct_requests_concurrent(self): # Step 2: connections connection_object_map = {} # Use a connection request that should span all three domains. - connection_request1 = json.loads(TestData.CONNECTION_REQ.read_text()) + connection_request1 = json.loads(TestData.CONNECTION_REQ_v0.read_text()) print(f"Connection request #1: {connection_request1}") traffic_matrix = temanager.generate_traffic_matrix(connection_request1) @@ -1137,7 +1137,7 @@ def test_connection_amlight_to_zaoxi_unreserve(self): graph = temanager.generate_graph_te() - connection_request = json.loads(TestData.CONNECTION_REQ.read_text()) + connection_request = json.loads(TestData.CONNECTION_REQ_v0.read_text()) print(f"connection_request: {connection_request}") traffic_matrix = temanager.generate_traffic_matrix(connection_request) @@ -1198,7 +1198,7 @@ def test_connection_amlight_to_zaoxi_with_merged_topology(self): graph = temanager.generate_graph_te() - connection_request = json.loads(TestData.CONNECTION_REQ.read_text()) + connection_request = json.loads(TestData.CONNECTION_REQ_v0.read_text()) print(f"connection_request: {connection_request}") traffic_matrix = temanager.generate_traffic_matrix(connection_request) @@ -1364,7 +1364,7 @@ def test_connection_amlight_to_zaoxi_user_port_v2(self): graph = temanager.generate_graph_te() connection_request = json.loads( - TestData.CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_V1.read_text() + TestData.CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_v1.read_text() ) print(f"connection_request: {connection_request}") @@ -1480,7 +1480,7 @@ def test_connection_amlight_to_zaoxi_user_port_any(self): graph = temanager.generate_graph_te() connection_request = json.loads( - TestData.CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_V1.read_text() + TestData.CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_v1.read_text() ) # Rewrite the request to have VLAN of "any". diff --git a/tests/test_te_solver_static.py b/tests/test_te_solver_static.py index 553e4562..9eb7af09 100644 --- a/tests/test_te_solver_static.py +++ b/tests/test_te_solver_static.py @@ -33,7 +33,7 @@ def setUp(self): topology_data = json.loads(TestData.TOPOLOGY_FILE_SDX.read_text()) self.temanager = TEManager(topology_data) - self.connection_request = json.loads(TestData.CONNECTION_REQ.read_text()) + self.connection_request = json.loads(TestData.CONNECTION_REQ_v0.read_text()) def test_computation_breakdown(self): graph = self.temanager.generate_graph_te() From 3a5dc7152784bd21060c3887d421be194099770d Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Sat, 22 Mar 2025 12:36:34 -0500 Subject: [PATCH 14/17] Add version suffixes to more test request files --- tests/__init__.py | 10 +++++----- tests/test_te_manager.py | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 24739d44..94cce1cd 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -33,14 +33,14 @@ class TestData: # Other test data files. TEST_DATA_DIR = pathlib.Path(__file__).parent / "data" - CONNECTION_REQ_AMLIGHT = TEST_DATA_DIR / "test_request_amlight.json" - CONNECTION_REQ_AMLIGHT_USER_PORT = ( + CONNECTION_REQ_AMLIGHT_v0 = TEST_DATA_DIR / "test_request_amlight.json" + CONNECTION_REQ_AMLIGHT_USER_PORT_v0 = ( TEST_DATA_DIR / "test_request_amlight_user_port.json" ) - CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT = ( + CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_v0 = ( TEST_DATA_DIR / "test_request_amlight_zaoxi_user_port.json" ) TOPOLOGY_FILE_SAX_2 = TEST_DATA_DIR / "sax-2.json" - CONNECTION_REQ_FILE_SAX_2_INVALID = TEST_DATA_DIR / "sax-2-request-invalid.json" - CONNECTION_REQ_FILE_SAX_2_VALID = TEST_DATA_DIR / "sax-2-request-valid.json" + CONNECTION_REQ_FILE_SAX_2_INVALID_v0 = TEST_DATA_DIR / "sax-2-request-invalid.json" + CONNECTION_REQ_FILE_SAX_2_VALID_v0 = TEST_DATA_DIR / "sax-2-request-valid.json" diff --git a/tests/test_te_manager.py b/tests/test_te_manager.py index 79576974..01c56657 100644 --- a/tests/test_te_manager.py +++ b/tests/test_te_manager.py @@ -113,7 +113,7 @@ def test_find_common_vlan_on_link(self): def test_generate_solver_input(self): print("Test Convert Connection To Topology") - request = json.loads(TestData.CONNECTION_REQ_AMLIGHT.read_text()) + request = json.loads(TestData.CONNECTION_REQ_AMLIGHT_v0.read_text()) temanager = TEManager( topology_data=json.loads(TestData.TOPOLOGY_FILE_AMLIGHT.read_text()) @@ -334,7 +334,7 @@ def test_generate_graph_and_connection_with_sax_2_invalid(self): # Expect None because the connection_data contains # unresolvable port IDs, which are not present in the given # topology. - request = json.loads(TestData.CONNECTION_REQ_FILE_SAX_2_INVALID.read_text()) + request = json.loads(TestData.CONNECTION_REQ_FILE_SAX_2_INVALID_v0.read_text()) tm = None with self.assertRaises(RequestValidationError) as ctx: tm = temanager.generate_traffic_matrix(request) @@ -359,7 +359,7 @@ def test_generate_graph_and_connection_with_sax_2_valid(self): self.assertIsNotNone(graph) self.assertIsInstance(graph, nx.Graph) - request = json.loads(TestData.CONNECTION_REQ_FILE_SAX_2_VALID.read_text()) + request = json.loads(TestData.CONNECTION_REQ_FILE_SAX_2_VALID_v0.read_text()) tm = temanager.generate_traffic_matrix(request) print(f"traffic matrix: {tm}") self.assertIsInstance(tm, TrafficMatrix) @@ -393,7 +393,7 @@ def test_connection_amlight(self): self.assertIsInstance(graph, nx.Graph) - request = json.loads(TestData.CONNECTION_REQ_AMLIGHT.read_text()) + request = json.loads(TestData.CONNECTION_REQ_AMLIGHT_v0.read_text()) print(f"connection request: {request}") traffic_matrix = temanager.generate_traffic_matrix(request) @@ -515,7 +515,7 @@ def test_connection_amlight_user_port(self): self.assertIsInstance(graph, nx.Graph) connection_request = json.loads( - TestData.CONNECTION_REQ_AMLIGHT_USER_PORT.read_text() + TestData.CONNECTION_REQ_AMLIGHT_USER_PORT_v0.read_text() ) print(f"connection request: {connection_request}") @@ -653,7 +653,7 @@ def test_connection_amlight_to_zaoxi_user_port(self): graph = temanager.generate_graph_te() connection_request = json.loads( - TestData.CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT.read_text() + TestData.CONNECTION_REQ_AMLIGHT_ZAOXI_USER_PORT_v0.read_text() ) print(f"connection_request: {connection_request}") traffic_matrix = temanager.generate_traffic_matrix(connection_request) @@ -1020,7 +1020,7 @@ def test_connection_amlight_to_zaoxi_two_distinct_requests(self): graph = TESolver(graph, traffic_matrix1).update_graph(graph, solution1) # Use another connection request that spans just one domain. - connection_request2 = json.loads(TestData.CONNECTION_REQ_AMLIGHT.read_text()) + connection_request2 = json.loads(TestData.CONNECTION_REQ_AMLIGHT_v0.read_text()) print(f"Connection request #2: {connection_request2}") traffic_matrix2 = temanager.generate_traffic_matrix(connection_request2) @@ -1083,7 +1083,7 @@ def test_connection_amlight_to_zaoxi_two_distinct_requests_concurrent(self): ) # Use another connection request that spans just one domain. - connection_request2 = json.loads(TestData.CONNECTION_REQ_AMLIGHT.read_text()) + connection_request2 = json.loads(TestData.CONNECTION_REQ_AMLIGHT_v0.read_text()) print(f"Connection request #2: {connection_request2}") traffic_matrix2 = temanager.generate_traffic_matrix(connection_request2) @@ -1236,7 +1236,7 @@ def test_generate_graph_and_connection(self): self.assertIsNotNone(graph) self.assertIsInstance(graph, nx.Graph) - request = json.loads(TestData.CONNECTION_REQ_AMLIGHT.read_text()) + request = json.loads(TestData.CONNECTION_REQ_AMLIGHT_v0.read_text()) tm = temanager.generate_traffic_matrix(request) print(f"tm: {tm}") From 02ed02d2a268dea9186ffb1917e95f03a306fc07 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Sat, 22 Mar 2025 12:37:56 -0500 Subject: [PATCH 15/17] Run isort --- src/sdx_pce/topology/temanager.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/sdx_pce/topology/temanager.py b/src/sdx_pce/topology/temanager.py index ede7a44e..3d4981f4 100644 --- a/src/sdx_pce/topology/temanager.py +++ b/src/sdx_pce/topology/temanager.py @@ -21,12 +21,6 @@ from sdx_datamodel.models.port import Port from sdx_datamodel.parsing.connectionhandler import ConnectionHandler -# from sdx_datamodel.parsing.exceptions import ( -# MissingAttributeException, -# ServiceNotSupportedException, -# ) -# from sdx_datamodel.validation.connectionvalidator import ConnectionValidator - from sdx_pce.models import ( ConnectionPath, ConnectionRequest, @@ -47,6 +41,13 @@ ValidationError, ) +# from sdx_datamodel.parsing.exceptions import ( +# MissingAttributeException, +# ServiceNotSupportedException, +# ) +# from sdx_datamodel.validation.connectionvalidator import ConnectionValidator + + UNUSED_VLAN = None From 08c081b6d204dd96a09f14de46a88d3660e1a754 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Sat, 22 Mar 2025 22:35:33 -0500 Subject: [PATCH 16/17] Rename sdx_pce.models.ConnectionRequest to sdx_pce.models.PceConnectionRequest To avoid confusing it with sdx_datamodel.models.ConnectionRequest --- src/sdx_pce/heuristic/heur.py | 4 ++-- src/sdx_pce/models.py | 6 +++--- src/sdx_pce/topology/temanager.py | 6 +++--- src/sdx_pce/utils/random_connection_generator.py | 6 +++--- tests/test_te_manager.py | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/sdx_pce/heuristic/heur.py b/src/sdx_pce/heuristic/heur.py index 5207606d..d79389a4 100644 --- a/src/sdx_pce/heuristic/heur.py +++ b/src/sdx_pce/heuristic/heur.py @@ -7,7 +7,7 @@ import prtpy from sdx_pce.load_balancing.te_solver import TESolver -from sdx_pce.models import ConnectionRequest, TrafficMatrix +from sdx_pce.models import PceConnectionRequest, TrafficMatrix from sdx_pce.utils.random_connection_generator import RandomConnectionGenerator from sdx_pce.utils.random_topology_generator import RandomTopologyGenerator @@ -41,7 +41,7 @@ def matrix_to_connection(matrix): """ traffic_matrix = TrafficMatrix(connection_requests=[]) for rq in matrix: - request = ConnectionRequest( + request = PceConnectionRequest( source=rq[0], destination=rq[1], required_bandwidth=rq[2], diff --git a/src/sdx_pce/models.py b/src/sdx_pce/models.py index 6a9440cc..24792515 100644 --- a/src/sdx_pce/models.py +++ b/src/sdx_pce/models.py @@ -6,7 +6,7 @@ @dataclass_json @dataclass(frozen=True) -class ConnectionRequest: +class PceConnectionRequest: """ A connection request. @@ -34,7 +34,7 @@ class TrafficMatrix: Traffic matrix is input to TE Solver. """ - connection_requests: List[ConnectionRequest] + connection_requests: List[PceConnectionRequest] request_id: str @@ -58,7 +58,7 @@ class ConnectionSolution: TE Solver's result is represented as a ConnectionSolution. """ - connection_map: Mapping[ConnectionRequest, List[ConnectionPath]] + connection_map: Mapping[PceConnectionRequest, List[ConnectionPath]] cost: float request_id: str diff --git a/src/sdx_pce/topology/temanager.py b/src/sdx_pce/topology/temanager.py index 3d4981f4..3f5e7f79 100644 --- a/src/sdx_pce/topology/temanager.py +++ b/src/sdx_pce/topology/temanager.py @@ -23,8 +23,8 @@ from sdx_pce.models import ( ConnectionPath, - ConnectionRequest, ConnectionSolution, + PceConnectionRequest, TrafficMatrix, VlanTag, VlanTaggedBreakdown, @@ -170,7 +170,7 @@ def get_failed_links(self) -> List[dict]: """Get failed links on the topology (ie., Links not up and enabled).""" return self.topology_manager.get_failed_links() - def get_connections(self) -> List[ConnectionRequest]: + def get_connections(self) -> List[PceConnectionRequest]: """Get all the connections in the _connectionSolution_list.""" connections = [] for solution in self._connectionSolution_list: @@ -506,7 +506,7 @@ def generate_traffic_matrix(self, connection_request: dict) -> TrafficMatrix: f"required_bandwidth: {required_bandwidth}" ) - request = ConnectionRequest( + request = PceConnectionRequest( source=ingress_nodes[0], destination=egress_nodes[0], required_bandwidth=required_bandwidth, diff --git a/src/sdx_pce/utils/random_connection_generator.py b/src/sdx_pce/utils/random_connection_generator.py index 3b89d123..7c0a0b8b 100644 --- a/src/sdx_pce/utils/random_connection_generator.py +++ b/src/sdx_pce/utils/random_connection_generator.py @@ -1,6 +1,6 @@ import numpy as np -from sdx_pce.models import ConnectionRequest, TrafficMatrix +from sdx_pce.models import PceConnectionRequest, TrafficMatrix class RandomConnectionGenerator: @@ -34,7 +34,7 @@ def generate(self, querynum, l_bw, u_bw, l_lat, u_lat, seed=2022) -> TrafficMatr required_bandwidth = bw[i] required_latency = np.random.randint(l_lat, u_lat) - request = ConnectionRequest( + request = PceConnectionRequest( source=source, destination=destination, required_bandwidth=required_bandwidth, @@ -52,7 +52,7 @@ def generate(self, querynum, l_bw, u_bw, l_lat, u_lat, seed=2022) -> TrafficMatr required_bandwidth = bw[i] required_latency = np.random.randint(l_lat, u_lat) - request = ConnectionRequest( + request = PceConnectionRequest( source=source, destination=destination, required_bandwidth=required_bandwidth, diff --git a/tests/test_te_manager.py b/tests/test_te_manager.py index 01c56657..4b47ad73 100644 --- a/tests/test_te_manager.py +++ b/tests/test_te_manager.py @@ -5,7 +5,7 @@ import networkx as nx from sdx_pce.load_balancing.te_solver import TESolver -from sdx_pce.models import ConnectionRequest, ConnectionSolution, TrafficMatrix +from sdx_pce.models import ConnectionSolution, PceConnectionRequest, TrafficMatrix from sdx_pce.topology.temanager import TEManager from sdx_pce.utils.exceptions import ( RequestValidationError, @@ -1307,7 +1307,7 @@ def _make_traffic_matrix_from_list(self, old_style_request: list) -> TrafficMatr cost = old_style_request[1] print(f"cost: {cost}") - new_requests: list(ConnectionRequest) = [] + new_requests: list(PceConnectionRequest) = [] print(f"type of request: {type(requests_map)}") assert isinstance(requests_map, dict) @@ -1337,7 +1337,7 @@ def _make_traffic_matrix_from_list(self, old_style_request: list) -> TrafficMatr assert len(request) == 2 new_requests.append( - ConnectionRequest( + PceConnectionRequest( source=source, destination=destination, required_bandwidth=required_bandwidth, From 7e36b689f5369cbc00e1bcb32fc2f8d11f7a22ea Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Mon, 24 Mar 2025 09:02:21 -0500 Subject: [PATCH 17/17] Re-throw request validation error --- src/sdx_pce/topology/temanager.py | 54 +++---------------------------- 1 file changed, 5 insertions(+), 49 deletions(-) diff --git a/src/sdx_pce/topology/temanager.py b/src/sdx_pce/topology/temanager.py index 3f5e7f79..44a2cfae 100644 --- a/src/sdx_pce/topology/temanager.py +++ b/src/sdx_pce/topology/temanager.py @@ -8,16 +8,7 @@ import networkx as nx from networkx.algorithms import approximation as approx - -# from pydantic import ValidationError -from sdx_datamodel.models.connection_request import ( - ConnectionRequest as DmConnectionRequest, -) - -# from sdx_datamodel.models.connection_request import ( -# ConnectionRequestV0, -# ConnectionRequestV1, -# ) +from sdx_datamodel.models.connection_request import ConnectionRequest from sdx_datamodel.models.port import Port from sdx_datamodel.parsing.connectionhandler import ConnectionHandler @@ -382,46 +373,11 @@ def generate_traffic_matrix(self, connection_request: dict) -> TrafficMatrix: ) try: - request = DmConnectionRequest.model_validate(connection_request) + request = ConnectionRequest.model_validate(connection_request) except Exception as e: - print(f"Exception: could not validate {connection_request}: {e}") - raise e - # return None - - # try: - # request = ConnectionHandler().import_connection_data(connection_request) - # except MissingAttributeException as e: - # self._logger.error(f"Missing attribute: {e} for {connection_request}") - # raise RequestValidationError( - # f"Validation error: {e} for {connection_request}", 400 - # ) - # except ServiceNotSupportedException as e: - # self._logger.error(f"Service not supported: {e} for {connection_request}") - # raise RequestValidationError( - # f"Validation error: {e} for {connection_request}", 402 - # ) - - # try: - # ConnectionValidator(request).is_valid() - # except ValueError as request_err: - # err = traceback.format_exc().replace("\n", ", ") - # self._logger.error( - # f"Validation error: {request_err} for {connection_request}: {request_err} - {err}" - # ) - # raise RequestValidationError( - # f"Validation error: {request_err} for {connection_request}", 400 - # ) - # except ServiceNotSupportedException as e: - # self._logger.error(f"Service not supported: {e} for {connection_request}") - # raise RequestValidationError( - # f"Validation error: {e} for {connection_request}", 402 - # ) - # except Exception as e: - # err = traceback.format_exc().replace("\n", ", ") - # self._logger.error(f"Error when validating connection request: {e} - {err}") - # raise RequestValidationError( - # f"Validation error: {e} for {connection_request}", 400 - # ) + message = f"Validation error: for {connection_request}: {e}" + self._logger.error(message) + raise RequestValidationError(message, 400) self._logger.info(f"generate_traffic_matrix: decoded request: {request}")