From 181a5b235bb01522a6eb7c663e8f35ba3a3f9eb8 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Wed, 26 Jul 2023 19:59:41 -0500 Subject: [PATCH 1/6] Add test_Solver from sdx-controller here --- tests/test_Solver.py | 115 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 tests/test_Solver.py diff --git a/tests/test_Solver.py b/tests/test_Solver.py new file mode 100644 index 00000000..92d24221 --- /dev/null +++ b/tests/test_Solver.py @@ -0,0 +1,115 @@ +import json +import pathlib +import unittest + +from sdx.datamodel.parsing.exceptions import DataModelException +from sdx.pce.load_balancing.te_solver import TESolver +from sdx.pce.models import ConnectionRequest, ConnectionSolution, TrafficMatrix +from sdx.pce.topology.temanager import TEManager + + +class SolverTests(unittest.TestCase): + """ + Check that the solver from pce does what we expects it to do. + """ + + TEST_DATA_DIR = pathlib.Path(__file__).parent.joinpath("data") + + TOPOLOGY_SDX = TEST_DATA_DIR.joinpath("sdx.json") + CONNECTION_REQ = TEST_DATA_DIR.joinpath("test_request.json") + + TOPOLOGY_AMLIGHT = TEST_DATA_DIR.joinpath("amlight.json") + TOPOLOGY_SAX = TEST_DATA_DIR.joinpath("sax.json") + TOPOLOGY_ZAOXI = TEST_DATA_DIR.joinpath("zaoxi.json") + + TOPOLOGY_FILE_LIST = [TOPOLOGY_AMLIGHT, TOPOLOGY_ZAOXI, TOPOLOGY_SAX] + TOPOLOGY_FILE_LIST_UPDATE = [TOPOLOGY_AMLIGHT, TOPOLOGY_ZAOXI, TOPOLOGY_SAX] + + def setUp(self): + with open(self.TOPOLOGY_SDX, "r", encoding="utf-8") as t: + topology_data = json.load(t) + with open(self.CONNECTION_REQ, "r", encoding="utf-8") as c: + connection_data = json.load(c) + + self.temanager = TEManager(topology_data, connection_data) + + def test_computation_breakdown(self): + graph = self.temanager.generate_graph_te() + connection_request = self.temanager.generate_connection_te() + + print(f"Number of nodes: {graph.number_of_nodes()}") + print(f"Graph edges: {graph.edges}") + print(f"Traffic Matrix: {connection_request}") + + solution = TESolver(graph, connection_request).solve() + print(f"TESolver result: {solution}") + + self.assertIsInstance(solution, ConnectionSolution) + self.assertEqual(solution.cost, 5.0) + + breakdown = self.temanager.generate_connection_breakdown(solution) + print(f"Breakdown: {breakdown}") + self.assertIsNotNone(breakdown) + + def test_computation_breakdown_many_topologies(self): + for topology_file in self.TOPOLOGY_FILE_LIST: + print(f"Adding Topology: {topology_file}") + with open(topology_file, "r", encoding="utf-8") as data_file: + data = json.load(data_file) + self.temanager.topology_manager.add_topology(data) + + graph = self.temanager.generate_graph_te() + print(f"Graph: {graph}") + + connection_request = self.temanager.generate_connection_te() + print(f"Connection Request: {connection_request}") + + conn = self.temanager.requests_connectivity(connection_request) + print(f"Graph connectivity: {conn}") + + solution = TESolver(graph, connection_request).solve() + print(f"TESolver result: {solution}") + + # The reality, for now, is that TE Solver has not been able to + # compute a path. + self.assertIsNone(solution.connection_map, "No path was computed") + self.assertEqual(solution.cost, 0) + + breakdown = self.temanager.generate_connection_breakdown(solution) + print(f"Breakdown: {breakdown}") + self.assertIsNone(breakdown) + + def test_computation_update(self): + for topology_file in self.TOPOLOGY_FILE_LIST: + print(f"Adding Topology: {topology_file}") + with open(topology_file, "r", encoding="utf-8") as data_file: + data = json.load(data_file) + self.temanager.add_topology(data) + + for topology_file in self.TOPOLOGY_FILE_LIST_UPDATE: + print(f"Updating Topology: {topology_file}") + with open(topology_file, "r", encoding="utf-8") as data_file: + data = json.load(data_file) + self.temanager.update_topology(data) + + graph = self.temanager.generate_graph_te() + connection_request = self.temanager.generate_connection_te() + + conn = self.temanager.requests_connectivity(connection_request) + print(f"Graph connectivity: {conn}") + + solution = TESolver(graph, connection_request).solve() + print(f"TESolver result: {solution}") + + # The reality, for now, is that TE Solver has not been able to + # compute a path. + self.assertIsNone(solution.connection_map, "No path was computed") + self.assertEqual(solution.cost, 0) + + breakdown = self.temanager.generate_connection_breakdown(solution) + print(f"Breakdown: {breakdown}") + self.assertIsNone(breakdown) + + +if __name__ == "__main__": + unittest.main() From fd4667eca454d216fb017ff6658bc4527657d57e Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Wed, 26 Jul 2023 20:01:51 -0500 Subject: [PATCH 2/6] Rename test file --- tests/{test_Solver.py => test_te_solver_static.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{test_Solver.py => test_te_solver_static.py} (100%) diff --git a/tests/test_Solver.py b/tests/test_te_solver_static.py similarity index 100% rename from tests/test_Solver.py rename to tests/test_te_solver_static.py From f4b32da00b6cb7532f0504b5451894bae5219d44 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Wed, 26 Jul 2023 20:06:45 -0500 Subject: [PATCH 3/6] Use existing topologies --- tests/test_te_solver_static.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/test_te_solver_static.py b/tests/test_te_solver_static.py index 92d24221..f3f8c219 100644 --- a/tests/test_te_solver_static.py +++ b/tests/test_te_solver_static.py @@ -7,28 +7,29 @@ from sdx.pce.models import ConnectionRequest, ConnectionSolution, TrafficMatrix from sdx.pce.topology.temanager import TEManager +from . import TestData + class SolverTests(unittest.TestCase): """ Check that the solver from pce does what we expects it to do. """ - TEST_DATA_DIR = pathlib.Path(__file__).parent.joinpath("data") - - TOPOLOGY_SDX = TEST_DATA_DIR.joinpath("sdx.json") - CONNECTION_REQ = TEST_DATA_DIR.joinpath("test_request.json") - - TOPOLOGY_AMLIGHT = TEST_DATA_DIR.joinpath("amlight.json") - TOPOLOGY_SAX = TEST_DATA_DIR.joinpath("sax.json") - TOPOLOGY_ZAOXI = TEST_DATA_DIR.joinpath("zaoxi.json") - - TOPOLOGY_FILE_LIST = [TOPOLOGY_AMLIGHT, TOPOLOGY_ZAOXI, TOPOLOGY_SAX] - TOPOLOGY_FILE_LIST_UPDATE = [TOPOLOGY_AMLIGHT, TOPOLOGY_ZAOXI, TOPOLOGY_SAX] + TOPOLOGY_FILE_LIST = [ + TestData.TOPOLOGY_FILE_AMLIGHT, + TestData.TOPOLOGY_FILE_ZAOXI, + TestData.TOPOLOGY_FILE_SAX, + ] + TOPOLOGY_FILE_LIST_UPDATE = [ + TestData.TOPOLOGY_FILE_AMLIGHT, + TestData.TOPOLOGY_FILE_ZAOXI, + TestData.TOPOLOGY_FILE_SAX, + ] def setUp(self): - with open(self.TOPOLOGY_SDX, "r", encoding="utf-8") as t: + with open(TestData.TOPOLOGY_FILE_SDX, "r", encoding="utf-8") as t: topology_data = json.load(t) - with open(self.CONNECTION_REQ, "r", encoding="utf-8") as c: + with open(TestData.CONNECTION_REQ, "r", encoding="utf-8") as c: connection_data = json.load(c) self.temanager = TEManager(topology_data, connection_data) From e3fd32cecc872c4ea9589f6a7a85848e1fb09245 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Wed, 26 Jul 2023 20:09:00 -0500 Subject: [PATCH 4/6] Remove unused imports --- tests/test_te_solver_static.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_te_solver_static.py b/tests/test_te_solver_static.py index f3f8c219..9012f50e 100644 --- a/tests/test_te_solver_static.py +++ b/tests/test_te_solver_static.py @@ -1,10 +1,8 @@ import json -import pathlib import unittest -from sdx.datamodel.parsing.exceptions import DataModelException from sdx.pce.load_balancing.te_solver import TESolver -from sdx.pce.models import ConnectionRequest, ConnectionSolution, TrafficMatrix +from sdx.pce.models import ConnectionSolution from sdx.pce.topology.temanager import TEManager from . import TestData From 4600ef9a97649bc6038c6dff9a622dc49fa68c48 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Wed, 26 Jul 2023 20:11:14 -0500 Subject: [PATCH 5/6] Add a note about where the test came from --- tests/test_te_solver_static.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_te_solver_static.py b/tests/test_te_solver_static.py index 9012f50e..13cf2801 100644 --- a/tests/test_te_solver_static.py +++ b/tests/test_te_solver_static.py @@ -1,3 +1,7 @@ +""" +Solver tests that use some static topology files. These tests used to +be in sdx-controller. +""" import json import unittest From 905fbf23a526845b1eb30217da1e42416b0cdee3 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Wed, 26 Jul 2023 20:17:03 -0500 Subject: [PATCH 6/6] Update tests --- tests/test_te_solver_static.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/test_te_solver_static.py b/tests/test_te_solver_static.py index 13cf2801..9db00174 100644 --- a/tests/test_te_solver_static.py +++ b/tests/test_te_solver_static.py @@ -12,7 +12,7 @@ from . import TestData -class SolverTests(unittest.TestCase): +class TESolverTests(unittest.TestCase): """ Check that the solver from pce does what we expects it to do. """ @@ -73,14 +73,12 @@ def test_computation_breakdown_many_topologies(self): solution = TESolver(graph, connection_request).solve() print(f"TESolver result: {solution}") - # The reality, for now, is that TE Solver has not been able to - # compute a path. - self.assertIsNone(solution.connection_map, "No path was computed") - self.assertEqual(solution.cost, 0) + self.assertIsNotNone(solution.connection_map) + self.assertEqual(solution.cost, 5.0) breakdown = self.temanager.generate_connection_breakdown(solution) print(f"Breakdown: {breakdown}") - self.assertIsNone(breakdown) + self.assertIsNotNone(breakdown) def test_computation_update(self): for topology_file in self.TOPOLOGY_FILE_LIST: @@ -104,14 +102,12 @@ def test_computation_update(self): solution = TESolver(graph, connection_request).solve() print(f"TESolver result: {solution}") - # The reality, for now, is that TE Solver has not been able to - # compute a path. - self.assertIsNone(solution.connection_map, "No path was computed") - self.assertEqual(solution.cost, 0) + self.assertIsNotNone(solution.connection_map) + self.assertEqual(solution.cost, 5.0) breakdown = self.temanager.generate_connection_breakdown(solution) print(f"Breakdown: {breakdown}") - self.assertIsNone(breakdown) + self.assertIsNotNone(breakdown) if __name__ == "__main__":