3 ##############################################################################
4 # Copyright (c) 2017 Orange, Inc. and others. All rights reserved.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
12 # pylint: disable=no-member
13 # pylint: disable=too-many-public-methods
21 from common import test_utils
24 class TransportGNPYtesting(unittest.TestCase):
27 def __init_logfile(cls):
28 GNPY_LOGFILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
29 "..", "..", "transportpce_tests", "gnpy.log")
30 if os.path.isfile(GNPY_LOFGILE):
31 os.remove(GNPY_LOFGILE)
33 topo_cllinet_data = None
34 topo_ordnet_data = None
35 topo_ordtopo_data = None
41 sample_files_parsed = False
42 TOPO_CLLINET_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
43 "..", "..", "sample_configs", "gnpy", "clliNetwork.json")
44 with open(TOPO_CLLINET_FILE, 'r') as topo_cllinet:
45 cls.topo_cllinet_data = topo_cllinet.read()
47 TOPO_ORDNET_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
48 "..", "..", "sample_configs", "gnpy", "openroadmNetwork.json")
49 with open(TOPO_ORDNET_FILE, 'r') as topo_ordnet:
50 cls.topo_ordnet_data = topo_ordnet.read()
52 TOPO_ORDTOPO_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
53 "..", "..", "sample_configs", "gnpy", "openroadmTopology.json")
54 with open(TOPO_ORDTOPO_FILE, 'r') as topo_ordtopo:
55 cls.topo_ordtopo_data = topo_ordtopo.read()
56 sample_files_parsed = True
57 except PermissionError as err:
58 print("Permission Error when trying to read sample files\n", err)
60 except FileNotFoundError as err:
61 print("File Not found Error when trying to read sample files\n", err)
64 print("Unexpected error when trying to read sample files\n", sys.exc_info()[0])
67 if sample_files_parsed:
68 print("sample files content loaded")
70 cls.processes = test_utils.start_tpce()
73 def tearDownClass(cls):
74 for process in cls.processes:
75 test_utils.shutdown_process(process)
76 print("all processes killed")
81 # Mount the different topologies
82 def test_01_connect_clliNetwork(self):
83 response = test_utils.rawput_request(test_utils.URL_CONFIG_CLLI_NET, self.topo_cllinet_data)
84 self.assertEqual(response.status_code, requests.codes.ok)
87 def test_02_connect_openroadmNetwork(self):
88 response = test_utils.rawput_request(test_utils.URL_CONFIG_ORDM_NET, self.topo_ordnet_data)
89 self.assertEqual(response.status_code, requests.codes.ok)
92 def test_03_connect_openroadmTopology(self):
93 response = test_utils.rawput_request(test_utils.URL_CONFIG_ORDM_TOPO, self.topo_ordtopo_data)
94 self.assertEqual(response.status_code, requests.codes.ok)
97 # Path computed by PCE is feasible according to Gnpy
98 def test_04_path_computation_FeasibleWithPCE(self):
99 response = test_utils.path_computation_request("request-1", "service-1",
100 {"node-id": "XPONDER-1", "service-rate": "100",
101 "service-format": "Ethernet", "clli": "Node1"},
102 {"node-id": "XPONDER-5", "service-rate": "100",
103 "service-format": "Ethernet", "clli": "Node5"})
104 self.assertEqual(response.status_code, requests.codes.ok)
105 res = response.json()
106 self.assertEqual(res['output']['configuration-response-common'][
107 'response-code'], '200')
108 self.assertEqual(res['output']['configuration-response-common'][
110 'Path is calculated by PCE')
111 self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
113 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
114 self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
116 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
119 # Path computed by PCE is not feasible by GNPy and GNPy cannot find
120 # another one (low SNR)
121 def test_05_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
122 response = test_utils.path_computation_request("request-2", "service-2",
123 {"node-id": "XPONDER-1", "service-rate": "100",
124 "service-format": "Ethernet", "clli": "Node1"},
125 {"node-id": "XPONDER-5", "service-rate": "100",
126 "service-format": "Ethernet", "clli": "Node5"},
127 {"include_": {"ordered-hops": [
128 {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
129 {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}},
130 {"hop-number": "2", "hop-type": {"node-id": "OpenROADM-4"}}]}})
131 self.assertEqual(response.status_code, requests.codes.ok)
132 res = response.json()
133 self.assertEqual(res['output']['configuration-response-common'][
134 'response-code'], '500')
135 self.assertEqual(res['output']['configuration-response-common'][
137 'No path available by PCE and GNPy ')
138 self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
140 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'],
142 self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
144 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'],
148 # #PCE cannot find a path while GNPy finds a feasible one
149 def test_06_path_computation_NotFoundByPCE_FoundByGNPy(self):
150 response = test_utils.path_computation_request("request-3", "service-3",
151 {"node-id": "XPONDER-1", "service-rate": "100",
152 "service-format": "Ethernet", "clli": "Node1"},
153 {"node-id": "XPONDER-4", "service-rate": "100",
154 "service-format": "Ethernet", "clli": "Node5"},
155 {"include_": {"ordered-hops": [
156 {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
157 {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}}]}})
158 self.assertEqual(response.status_code, requests.codes.ok)
159 res = response.json()
160 self.assertEqual(res['output']['configuration-response-common'][
161 'response-code'], '200')
162 self.assertEqual(res['output']['configuration-response-common'][
164 'Path is calculated by GNPy')
165 self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
167 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
168 self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
170 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
173 # Not found path by PCE and GNPy cannot find another one
174 def test_07_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
175 response = test_utils.path_computation_request("request-4", "service-4",
176 {"node-id": "XPONDER-1", "service-rate": "100",
177 "service-format": "Ethernet", "clli": "Node1"},
178 {"node-id": "XPONDER-4", "service-rate": "100",
179 "service-format": "Ethernet", "clli": "Node5"},
180 {"include_": {"ordered-hops": [
181 {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
182 {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}},
183 {"hop-number": "2", "hop-type": {"node-id": "OpenROADM-4"}},
184 {"hop-number": "3", "hop-type": {"node-id": "OpenROADM-3"}}]}})
185 self.assertEqual(response.status_code, requests.codes.ok)
186 res = response.json()
187 self.assertEqual(res['output']['configuration-response-common'][
188 'response-code'], '500')
189 self.assertEqual(res['output']['configuration-response-common'][
191 'No path available by PCE and GNPy ')
194 # Disconnect the different topologies
195 def test_08_disconnect_openroadmTopology(self):
196 response = test_utils.delete_request(test_utils.URL_CONFIG_ORDM_TOPO)
197 self.assertEqual(response.status_code, requests.codes.ok)
200 def test_09_disconnect_openroadmNetwork(self):
201 response = test_utils.delete_request(test_utils.URL_CONFIG_ORDM_NET)
202 self.assertEqual(response.status_code, requests.codes.ok)
205 def test_10_disconnect_clliNetwork(self):
206 response = test_utils.delete_request(test_utils.URL_CONFIG_CLLI_NET)
207 self.assertEqual(response.status_code, requests.codes.ok)
211 if __name__ == "__main__":
212 # logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
213 unittest.main(verbosity=2)