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 cls.odl_process = test_utils.start_tpce()
37 print("opendaylight started")
40 def tearDownClass(cls):
41 for child in psutil.Process(cls.odl_process.pid).children():
42 child.send_signal(signal.SIGINT)
44 cls.odl_process.send_signal(signal.SIGINT)
45 cls.odl_process.wait()
50 # Mount the different topologies
51 def test_01_connect_clliNetwork(self):
52 url = ("{}/config/ietf-network:networks/network/clli-network"
53 .format(self.restconf_baseurl))
54 topo_cllinet_file = "sample_configs/gnpy/clliNetwork.json"
55 if os.path.isfile(topo_cllinet_file):
56 with open(topo_cllinet_file, 'r') as clli_net:
57 body = clli_net.read()
58 headers = {'content-type': 'application/json'}
59 response = requests.request(
60 "PUT", url, data=body, headers=headers,
61 auth=('admin', 'admin'))
62 self.assertEqual(response.status_code, requests.codes.ok)
65 def test_02_connect_openroadmNetwork(self):
66 url = ("{}/config/ietf-network:networks/network/openroadm-network"
67 .format(self.restconf_baseurl))
68 topo_ordnet_file = "sample_configs/gnpy/openroadmNetwork.json"
69 if os.path.isfile(topo_ordnet_file):
70 with open(topo_ordnet_file, 'r') as ord_net:
72 headers = {'content-type': 'application/json'}
73 response = requests.request(
74 "PUT", url, data=body, headers=headers,
75 auth=('admin', 'admin'))
76 self.assertEqual(response.status_code, requests.codes.ok)
79 def test_03_connect_openroadmTopology(self):
80 url = ("{}/config/ietf-network:networks/network/openroadm-topology"
81 .format(self.restconf_baseurl))
82 topo_ordtopo_file = "sample_configs/gnpy/openroadmTopology.json"
83 if os.path.isfile(topo_ordtopo_file):
84 with open(topo_ordtopo_file, 'r') as ord_topo:
85 body = ord_topo.read()
86 headers = {'content-type': 'application/json'}
87 response = requests.request(
88 "PUT", url, data=body, headers=headers,
89 auth=('admin', 'admin'))
90 self.assertEqual(response.status_code, requests.codes.ok)
93 # Path computed by PCE is feasible according to Gnpy
94 def test_04_path_computation_FeasibleWithPCE(self):
95 url = ("{}/operations/transportpce-pce:path-computation-request"
96 .format(self.restconf_baseurl))
99 "service-name": "service-1",
100 "resource-reserve": "true",
101 "pce-metric": "hop-count",
102 "service-handler-header": {
103 "request-id": "request-1"
106 "node-id": "XPONDER-1",
107 "service-rate": "100",
108 "service-format": "Ethernet",
112 "node-id": "XPONDER-5",
113 "service-rate": "100",
114 "service-format": "Ethernet",
119 headers = {'content-type': 'application/json',
120 "Accept": "application/json"}
121 response = requests.request(
122 "POST", url, data=json.dumps(body), headers=headers,
123 auth=('admin', 'admin'))
124 self.assertEqual(response.status_code, requests.codes.ok)
125 res = response.json()
126 self.assertEqual(res['output']['configuration-response-common'][
127 'response-code'], '200')
128 self.assertEqual(res['output']['configuration-response-common'][
130 'Path is calculated by PCE')
131 self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
133 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
134 self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
136 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
139 # Path computed by PCE is not feasible by GNPy and GNPy cannot find
140 # another one (low SNR)
141 def test_05_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
142 url = ("{}/operations/transportpce-pce:path-computation-request"
143 .format(self.restconf_baseurl))
146 "service-name": "service-2",
147 "resource-reserve": "true",
148 "pce-metric": "hop-count",
149 "service-handler-header": {
150 "request-id": "request-2"
153 "node-id": "XPONDER-1",
154 "service-rate": "100",
155 "service-format": "Ethernet",
159 "node-id": "XPONDER-5",
160 "service-rate": "100",
161 "service-format": "Ethernet",
164 "hard-constraints": {
170 "node-id": "OpenROADM-2"
176 "node-id": "OpenROADM-3"
182 "node-id": "OpenROADM-4"
190 headers = {'content-type': 'application/json',
191 "Accept": "application/json"}
192 response = requests.request(
193 "POST", url, data=json.dumps(body), headers=headers,
194 auth=('admin', 'admin'))
195 self.assertEqual(response.status_code, requests.codes.ok)
196 res = response.json()
197 self.assertEqual(res['output']['configuration-response-common'][
198 'response-code'], '500')
199 self.assertEqual(res['output']['configuration-response-common'][
201 'No path available by PCE and GNPy ')
202 self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
204 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'],
206 self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
208 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'],
212 # #PCE cannot find a path while GNPy finds a feasible one
213 def test_06_path_computation_NotFoundByPCE_FoundByGNPy(self):
214 url = ("{}/operations/transportpce-pce:path-computation-request"
215 .format(self.restconf_baseurl))
218 "service-name": "service-3",
219 "resource-reserve": "true",
220 "pce-metric": "hop-count",
221 "service-handler-header": {
222 "request-id": "request-3"
225 "node-id": "XPONDER-1",
226 "service-rate": "100",
227 "service-format": "Ethernet",
231 "node-id": "XPONDER-4",
232 "service-rate": "100",
233 "service-format": "Ethernet",
236 "hard-constraints": {
242 "node-id": "OpenROADM-2"
248 "node-id": "OpenROADM-3"
256 headers = {'content-type': 'application/json',
257 "Accept": "application/json"}
258 response = requests.request(
259 "POST", url, data=json.dumps(body), headers=headers,
260 auth=('admin', 'admin'))
261 self.assertEqual(response.status_code, requests.codes.ok)
262 res = response.json()
263 self.assertEqual(res['output']['configuration-response-common'][
264 'response-code'], '200')
265 self.assertEqual(res['output']['configuration-response-common'][
267 'Path is calculated by GNPy')
268 self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
270 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
271 self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
273 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
276 # Not found path by PCE and GNPy cannot find another one
277 def test_07_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
278 url = ("{}/operations/transportpce-pce:path-computation-request"
279 .format(self.restconf_baseurl))
282 "service-name": "service-4",
283 "resource-reserve": "true",
284 "pce-metric": "hop-count",
285 "service-handler-header": {
286 "request-id": "request-4"
289 "node-id": "XPONDER-1",
290 "service-rate": "100",
291 "service-format": "Ethernet",
295 "node-id": "XPONDER-4",
296 "service-rate": "100",
297 "service-format": "Ethernet",
300 "hard-constraints": {
306 "node-id": "OpenROADM-2"
312 "node-id": "OpenROADM-3"
318 "node-id": "OpenROADM-4"
324 "node-id": "OpenROADM-3"
332 headers = {'content-type': 'application/json',
333 "Accept": "application/json"}
334 response = requests.request(
335 "POST", url, data=json.dumps(body), headers=headers,
336 auth=('admin', 'admin'))
337 self.assertEqual(response.status_code, requests.codes.ok)
338 res = response.json()
339 self.assertEqual(res['output']['configuration-response-common'][
340 'response-code'], '500')
341 self.assertEqual(res['output']['configuration-response-common'][
343 'No path available by PCE and GNPy ')
346 # Disconnect the different topologies
347 def test_08_disconnect_openroadmTopology(self):
348 url = ("{}/config/ietf-network:networks/network/openroadm-topology"
349 .format(self.restconf_baseurl))
351 headers = {'content-type': 'application/json'}
352 response = requests.request(
353 "DELETE", url, data=json.dumps(data), headers=headers,
354 auth=('admin', 'admin'))
355 self.assertEqual(response.status_code, requests.codes.ok)
358 def test_09_disconnect_openroadmNetwork(self):
359 url = ("{}/config/ietf-network:networks/network/openroadm-network"
360 .format(self.restconf_baseurl))
362 headers = {'content-type': 'application/json'}
363 response = requests.request(
364 "DELETE", url, data=json.dumps(data), headers=headers,
365 auth=('admin', 'admin'))
366 self.assertEqual(response.status_code, requests.codes.ok)
369 def test_10_disconnect_clliNetwork(self):
370 url = ("{}/config/ietf-network:networks/network/clli-network"
371 .format(self.restconf_baseurl))
373 headers = {'content-type': 'application/json'}
374 response = requests.request(
375 "DELETE", url, data=json.dumps(data), headers=headers,
376 auth=('admin', 'admin'))
377 self.assertEqual(response.status_code, requests.codes.ok)
381 if __name__ == "__main__":
382 # logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
383 unittest.main(verbosity=2)