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 ##############################################################################
22 class TransportGNPYtesting(unittest.TestCase):
26 restconf_baseurl = "http://localhost:8181/restconf"
29 def __init_logfile(cls):
30 if os.path.isfile("./transportpce_tests/gnpy.log"):
31 os.remove("transportpce_tests/gnpy.log")
35 print("starting opendaylight...")
36 cls.odl_process = test_utils.start_tpce()
38 print("opendaylight started")
41 def tearDownClass(cls):
42 for child in psutil.Process(cls.odl_process.pid).children():
43 child.send_signal(signal.SIGINT)
45 cls.odl_process.send_signal(signal.SIGINT)
46 cls.odl_process.wait()
51 # Mount the different topologies
52 def test_01_connect_clliNetwork(self):
53 url = ("{}/config/ietf-network:networks/network/clli-network"
54 .format(self.restconf_baseurl))
55 topo_cllinet_file = "sample_configs/gnpy/clliNetwork.json"
56 if os.path.isfile(topo_cllinet_file):
57 with open(topo_cllinet_file, 'r') as clli_net:
58 body = clli_net.read()
59 headers = {'content-type': 'application/json'}
60 response = requests.request(
61 "PUT", url, data=body, headers=headers,
62 auth=('admin', 'admin'))
63 self.assertEqual(response.status_code, requests.codes.ok)
66 def test_02_connect_openroadmNetwork(self):
67 url = ("{}/config/ietf-network:networks/network/openroadm-network"
68 .format(self.restconf_baseurl))
69 topo_ordnet_file = "sample_configs/gnpy/openroadmNetwork.json"
70 if os.path.isfile(topo_ordnet_file):
71 with open(topo_ordnet_file, 'r') as ord_net:
73 headers = {'content-type': 'application/json'}
74 response = requests.request(
75 "PUT", url, data=body, headers=headers,
76 auth=('admin', 'admin'))
77 self.assertEqual(response.status_code, requests.codes.ok)
80 def test_03_connect_openroadmTopology(self):
81 url = ("{}/config/ietf-network:networks/network/openroadm-topology"
82 .format(self.restconf_baseurl))
83 topo_ordtopo_file = "sample_configs/gnpy/openroadmTopology.json"
84 if os.path.isfile(topo_ordtopo_file):
85 with open(topo_ordtopo_file, 'r') as ord_topo:
86 body = ord_topo.read()
87 headers = {'content-type': 'application/json'}
88 response = requests.request(
89 "PUT", url, data=body, headers=headers,
90 auth=('admin', 'admin'))
91 self.assertEqual(response.status_code, requests.codes.ok)
94 # Path computed by PCE is feasible according to Gnpy
95 def test_04_path_computation_FeasibleWithPCE(self):
96 url = ("{}/operations/transportpce-pce:path-computation-request"
97 .format(self.restconf_baseurl))
100 "service-name": "service-1",
101 "resource-reserve": "true",
102 "pce-metric": "hop-count",
103 "service-handler-header": {
104 "request-id": "request-1"
107 "node-id": "XPONDER-1",
108 "service-rate": "100",
109 "service-format": "Ethernet",
113 "node-id": "XPONDER-5",
114 "service-rate": "100",
115 "service-format": "Ethernet",
120 headers = {'content-type': 'application/json',
121 "Accept": "application/json"}
122 response = requests.request(
123 "POST", url, data=json.dumps(body), headers=headers,
124 auth=('admin', 'admin'))
125 self.assertEqual(response.status_code, requests.codes.ok)
126 res = response.json()
127 self.assertEqual(res['output']['configuration-response-common'][
128 'response-code'], '200')
129 self.assertEqual(res['output']['configuration-response-common'][
131 'Path is calculated by PCE')
132 self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
134 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
135 self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
137 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
140 # Path computed by PCE is not feasible by GNPy and GNPy cannot find
141 # another one (low SNR)
142 def test_05_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
143 url = ("{}/operations/transportpce-pce:path-computation-request"
144 .format(self.restconf_baseurl))
147 "service-name": "service-2",
148 "resource-reserve": "true",
149 "pce-metric": "hop-count",
150 "service-handler-header": {
151 "request-id": "request-2"
154 "node-id": "XPONDER-1",
155 "service-rate": "100",
156 "service-format": "Ethernet",
160 "node-id": "XPONDER-5",
161 "service-rate": "100",
162 "service-format": "Ethernet",
165 "hard-constraints": {
171 "node-id": "OpenROADM-2"
177 "node-id": "OpenROADM-3"
183 "node-id": "OpenROADM-4"
191 headers = {'content-type': 'application/json',
192 "Accept": "application/json"}
193 response = requests.request(
194 "POST", url, data=json.dumps(body), headers=headers,
195 auth=('admin', 'admin'))
196 self.assertEqual(response.status_code, requests.codes.ok)
197 res = response.json()
198 self.assertEqual(res['output']['configuration-response-common'][
199 'response-code'], '500')
200 self.assertEqual(res['output']['configuration-response-common'][
202 'No path available by PCE and GNPy ')
203 self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
205 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'],
207 self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
209 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'],
213 # #PCE cannot find a path while GNPy finds a feasible one
214 def test_06_path_computation_NotFoundByPCE_FoundByGNPy(self):
215 url = ("{}/operations/transportpce-pce:path-computation-request"
216 .format(self.restconf_baseurl))
219 "service-name": "service-3",
220 "resource-reserve": "true",
221 "pce-metric": "hop-count",
222 "service-handler-header": {
223 "request-id": "request-3"
226 "node-id": "XPONDER-1",
227 "service-rate": "100",
228 "service-format": "Ethernet",
232 "node-id": "XPONDER-4",
233 "service-rate": "100",
234 "service-format": "Ethernet",
237 "hard-constraints": {
243 "node-id": "OpenROADM-2"
249 "node-id": "OpenROADM-3"
257 headers = {'content-type': 'application/json',
258 "Accept": "application/json"}
259 response = requests.request(
260 "POST", url, data=json.dumps(body), headers=headers,
261 auth=('admin', 'admin'))
262 self.assertEqual(response.status_code, requests.codes.ok)
263 res = response.json()
264 self.assertEqual(res['output']['configuration-response-common'][
265 'response-code'], '200')
266 self.assertEqual(res['output']['configuration-response-common'][
268 'Path is calculated by GNPy')
269 self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
271 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
272 self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
274 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
277 # Not found path by PCE and GNPy cannot find another one
278 def test_07_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
279 url = ("{}/operations/transportpce-pce:path-computation-request"
280 .format(self.restconf_baseurl))
283 "service-name": "service-4",
284 "resource-reserve": "true",
285 "pce-metric": "hop-count",
286 "service-handler-header": {
287 "request-id": "request-4"
290 "node-id": "XPONDER-1",
291 "service-rate": "100",
292 "service-format": "Ethernet",
296 "node-id": "XPONDER-4",
297 "service-rate": "100",
298 "service-format": "Ethernet",
301 "hard-constraints": {
307 "node-id": "OpenROADM-2"
313 "node-id": "OpenROADM-3"
319 "node-id": "OpenROADM-4"
325 "node-id": "OpenROADM-3"
333 headers = {'content-type': 'application/json',
334 "Accept": "application/json"}
335 response = requests.request(
336 "POST", url, data=json.dumps(body), headers=headers,
337 auth=('admin', 'admin'))
338 self.assertEqual(response.status_code, requests.codes.ok)
339 res = response.json()
340 self.assertEqual(res['output']['configuration-response-common'][
341 'response-code'], '500')
342 self.assertEqual(res['output']['configuration-response-common'][
344 'No path available by PCE and GNPy ')
347 # Disconnect the different topologies
348 def test_08_disconnect_openroadmTopology(self):
349 url = ("{}/config/ietf-network:networks/network/openroadm-topology"
350 .format(self.restconf_baseurl))
352 headers = {'content-type': 'application/json'}
353 response = requests.request(
354 "DELETE", url, data=json.dumps(data), headers=headers,
355 auth=('admin', 'admin'))
356 self.assertEqual(response.status_code, requests.codes.ok)
359 def test_09_disconnect_openroadmNetwork(self):
360 url = ("{}/config/ietf-network:networks/network/openroadm-network"
361 .format(self.restconf_baseurl))
363 headers = {'content-type': 'application/json'}
364 response = requests.request(
365 "DELETE", url, data=json.dumps(data), headers=headers,
366 auth=('admin', 'admin'))
367 self.assertEqual(response.status_code, requests.codes.ok)
370 def test_10_disconnect_clliNetwork(self):
371 url = ("{}/config/ietf-network:networks/network/clli-network"
372 .format(self.restconf_baseurl))
374 headers = {'content-type': 'application/json'}
375 response = requests.request(
376 "DELETE", url, data=json.dumps(data), headers=headers,
377 auth=('admin', 'admin'))
378 self.assertEqual(response.status_code, requests.codes.ok)
382 if __name__ == "__main__":
383 # logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
384 unittest.main(verbosity=2)