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
17 # pylint: disable=wrong-import-order
22 sys.path.append('transportpce_tests/common/')
23 # pylint: disable=wrong-import-position
24 # pylint: disable=import-error
25 import test_utils # nopep8
28 class TransportGNPYtesting(unittest.TestCase):
30 topo_cllinet_data = None
31 topo_ordnet_data = None
32 topo_ordtopo_data = None
33 port_mapping_data = None
38 # pylint: disable=bare-except
40 sample_files_parsed = False
41 TOPO_CLLINET_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
42 "..", "..", "sample_configs", "gnpy", "clliNetwork.json")
43 with open(TOPO_CLLINET_FILE, 'r', encoding='utf-8') as topo_cllinet:
44 cls.topo_cllinet_data = topo_cllinet.read()
46 TOPO_ORDNET_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
47 "..", "..", "sample_configs", "gnpy", "openroadmNetwork.json")
48 with open(TOPO_ORDNET_FILE, 'r', encoding='utf-8') as topo_ordnet:
49 cls.topo_ordnet_data = topo_ordnet.read()
51 TOPO_ORDTOPO_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
52 "..", "..", "sample_configs", "gnpy", "openroadmTopology.json")
53 with open(TOPO_ORDTOPO_FILE, 'r', encoding='utf-8') as topo_ordtopo:
54 cls.topo_ordtopo_data = topo_ordtopo.read()
55 PORT_MAPPING_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
56 "..", "..", "sample_configs", "gnpy", "gnpy_portmapping_121.json")
57 with open(PORT_MAPPING_FILE, 'r', encoding='utf-8') as port_mapping:
58 cls.port_mapping_data = port_mapping.read()
59 sample_files_parsed = True
60 except PermissionError as err:
61 print("Permission Error when trying to read sample files\n", err)
63 except FileNotFoundError as err:
64 print("File Not found Error when trying to read sample files\n", err)
67 print("Unexpected error when trying to read sample files\n", sys.exc_info()[0])
70 if sample_files_parsed:
71 print("sample files content loaded")
73 with open('gnpy.log', 'w', encoding='utf-8') as outfile:
74 print('starting GNPy REST server...')
75 # pylint: disable=consider-using-with
76 test_utils.process_list.append(subprocess.Popen(
77 ['path_requests_run.py', '--rest'], stdout=outfile, stderr=outfile, stdin=None))
78 cls.processes = test_utils.start_tpce()
81 def tearDownClass(cls):
82 # pylint: disable=not-an-iterable
83 for process in cls.processes:
84 test_utils.shutdown_process(process)
85 print("all processes killed")
91 def test_00_load_port_mapping(self):
92 response = test_utils.rawpost_request(test_utils.URL_FULL_PORTMAPPING, self.port_mapping_data)
93 self.assertEqual(response.status_code, requests.codes.no_content)
96 # Mount the different topologies
97 def test_01_connect_clliNetwork(self):
98 response = test_utils.rawput_request(test_utils.URL_CONFIG_CLLI_NET, self.topo_cllinet_data)
99 self.assertEqual(response.status_code, requests.codes.ok)
102 def test_02_connect_openroadmNetwork(self):
103 response = test_utils.rawput_request(test_utils.URL_CONFIG_ORDM_NET, self.topo_ordnet_data)
104 self.assertEqual(response.status_code, requests.codes.ok)
107 def test_03_connect_openroadmTopology(self):
108 response = test_utils.rawput_request(test_utils.URL_CONFIG_ORDM_TOPO, self.topo_ordtopo_data)
109 self.assertEqual(response.status_code, requests.codes.ok)
112 # Path computed by PCE is feasible according to Gnpy
113 def test_04_path_computation_FeasibleWithPCE(self):
114 response = test_utils.path_computation_request("request-1", "service-1",
115 {"node-id": "XPONDER-1", "service-rate": "100",
116 "service-format": "Ethernet", "clli": "Node1"},
117 {"node-id": "XPONDER-5", "service-rate": "100",
118 "service-format": "Ethernet", "clli": "Node5"})
119 self.assertEqual(response.status_code, requests.codes.ok)
120 res = response.json()
121 self.assertEqual(res['output']['configuration-response-common'][
122 'response-code'], '200')
123 self.assertEqual(res['output']['configuration-response-common'][
125 'Path is calculated by PCE')
126 self.assertIn('A-to-Z',
127 [res['output']['gnpy-response'][0]['path-dir'],
128 res['output']['gnpy-response'][1]['path-dir']])
129 self.assertIn('Z-to-A',
130 [res['output']['gnpy-response'][0]['path-dir'],
131 res['output']['gnpy-response'][1]['path-dir']])
132 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
133 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
136 # Path computed by PCE is not feasible by GNPy and GNPy cannot find
137 # another one (low SNR)
138 def test_05_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
139 response = test_utils.path_computation_request("request-2", "service-2",
140 {"node-id": "XPONDER-1", "service-rate": "100",
141 "service-format": "Ethernet", "clli": "Node1"},
142 {"node-id": "XPONDER-5", "service-rate": "100",
143 "service-format": "Ethernet", "clli": "Node5"},
144 {"include_": {"ordered-hops": [
145 {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
146 {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}},
147 {"hop-number": "2", "hop-type": {"node-id": "OpenROADM-4"}}]}
149 self.assertEqual(response.status_code, requests.codes.ok)
150 res = response.json()
151 self.assertEqual(res['output']['configuration-response-common'][
152 'response-code'], '500')
153 self.assertEqual(res['output']['configuration-response-common'][
155 'No path available by PCE and GNPy ')
156 self.assertIn('A-to-Z',
157 [res['output']['gnpy-response'][0]['path-dir'],
158 res['output']['gnpy-response'][1]['path-dir']])
159 self.assertIn('Z-to-A',
160 [res['output']['gnpy-response'][0]['path-dir'],
161 res['output']['gnpy-response'][1]['path-dir']])
162 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'],
164 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'],
168 # #PCE cannot find a path while GNPy finds a feasible one
169 def test_06_path_computation_NotFoundByPCE_FoundByGNPy(self):
170 response = test_utils.path_computation_request("request-3", "service-3",
171 {"node-id": "XPONDER-1", "service-rate": "100",
172 "service-format": "Ethernet", "clli": "Node1"},
173 {"node-id": "XPONDER-4", "service-rate": "100",
174 "service-format": "Ethernet", "clli": "Node5"},
175 {"include_": {"ordered-hops": [
176 {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
177 {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}}]}
179 self.assertEqual(response.status_code, requests.codes.ok)
180 res = response.json()
181 self.assertEqual(res['output']['configuration-response-common'][
182 'response-code'], '200')
183 self.assertEqual(res['output']['configuration-response-common'][
185 'Path is calculated by GNPy')
186 self.assertIn('A-to-Z',
187 [res['output']['gnpy-response'][0]['path-dir'],
188 res['output']['gnpy-response'][1]['path-dir']])
189 self.assertIn('Z-to-A',
190 [res['output']['gnpy-response'][0]['path-dir'],
191 res['output']['gnpy-response'][1]['path-dir']])
192 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
193 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
196 # Not found path by PCE and GNPy cannot find another one
197 def test_07_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
198 response = test_utils.path_computation_request("request-4", "service-4",
199 {"node-id": "XPONDER-1", "service-rate": "100",
200 "service-format": "Ethernet", "clli": "Node1"},
201 {"node-id": "XPONDER-4", "service-rate": "100",
202 "service-format": "Ethernet", "clli": "Node5"},
203 {"include_": {"ordered-hops": [
204 {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
205 {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}},
206 {"hop-number": "2", "hop-type": {"node-id": "OpenROADM-4"}},
207 {"hop-number": "3", "hop-type": {"node-id": "OpenROADM-3"}}]}
209 self.assertEqual(response.status_code, requests.codes.ok)
210 res = response.json()
211 self.assertEqual(res['output']['configuration-response-common'][
212 'response-code'], '500')
213 self.assertEqual(res['output']['configuration-response-common'][
215 'No path available by PCE and GNPy ')
218 # Disconnect the different topologies
219 def test_08_disconnect_openroadmTopology(self):
220 response = test_utils.delete_request(test_utils.URL_CONFIG_ORDM_TOPO)
221 self.assertEqual(response.status_code, requests.codes.ok)
224 def test_09_disconnect_openroadmNetwork(self):
225 response = test_utils.delete_request(test_utils.URL_CONFIG_ORDM_NET)
226 self.assertEqual(response.status_code, requests.codes.ok)
229 def test_10_disconnect_clliNetwork(self):
230 response = test_utils.delete_request(test_utils.URL_CONFIG_CLLI_NET)
231 self.assertEqual(response.status_code, requests.codes.ok)
235 def test_11_delete_port_mapping(self):
236 response = test_utils.delete_request(test_utils.URL_FULL_PORTMAPPING)
237 self.assertEqual(response.status_code, requests.codes.ok)
241 if __name__ == "__main__":
242 # logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
243 unittest.main(verbosity=2)