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
20 sys.path.append('transportpce_tests/common/')
21 import test_utils # nopep8
24 class TransportGNPYtesting(unittest.TestCase):
26 topo_cllinet_data = None
27 topo_ordnet_data = None
28 topo_ordtopo_data = None
29 port_mapping_data = None
34 # pylint: disable=bare-except
36 sample_files_parsed = False
37 TOPO_CLLINET_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
38 "..", "..", "sample_configs", "gnpy", "clliNetwork.json")
39 with open(TOPO_CLLINET_FILE, 'r') as topo_cllinet:
40 cls.topo_cllinet_data = topo_cllinet.read()
42 TOPO_ORDNET_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
43 "..", "..", "sample_configs", "gnpy", "openroadmNetwork.json")
44 with open(TOPO_ORDNET_FILE, 'r') as topo_ordnet:
45 cls.topo_ordnet_data = topo_ordnet.read()
47 TOPO_ORDTOPO_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
48 "..", "..", "sample_configs", "gnpy", "openroadmTopology.json")
49 with open(TOPO_ORDTOPO_FILE, 'r') as topo_ordtopo:
50 cls.topo_ordtopo_data = topo_ordtopo.read()
51 PORT_MAPPING_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
52 "..", "..", "sample_configs", "gnpy", "gnpy_portmapping_121.json")
53 with open(PORT_MAPPING_FILE, 'r') as port_mapping:
54 cls.port_mapping_data = port_mapping.read()
55 sample_files_parsed = True
56 except PermissionError as err:
57 print("Permission Error when trying to read sample files\n", err)
59 except FileNotFoundError as err:
60 print("File Not found Error when trying to read sample files\n", err)
63 print("Unexpected error when trying to read sample files\n", sys.exc_info()[0])
66 if sample_files_parsed:
67 print("sample files content loaded")
69 cls.processes = test_utils.start_tpce()
72 def tearDownClass(cls):
73 # pylint: disable=not-an-iterable
74 for process in cls.processes:
75 test_utils.shutdown_process(process)
76 print("all processes killed")
82 def test_00_load_port_mapping(self):
83 response = test_utils.rawpost_request(test_utils.URL_FULL_PORTMAPPING, self.port_mapping_data)
84 self.assertEqual(response.status_code, requests.codes.no_content)
87 # Mount the different topologies
88 def test_01_connect_clliNetwork(self):
89 response = test_utils.rawput_request(test_utils.URL_CONFIG_CLLI_NET, self.topo_cllinet_data)
90 self.assertEqual(response.status_code, requests.codes.ok)
93 def test_02_connect_openroadmNetwork(self):
94 response = test_utils.rawput_request(test_utils.URL_CONFIG_ORDM_NET, self.topo_ordnet_data)
95 self.assertEqual(response.status_code, requests.codes.ok)
98 def test_03_connect_openroadmTopology(self):
99 response = test_utils.rawput_request(test_utils.URL_CONFIG_ORDM_TOPO, self.topo_ordtopo_data)
100 self.assertEqual(response.status_code, requests.codes.ok)
103 # Path computed by PCE is feasible according to Gnpy
104 def test_04_path_computation_FeasibleWithPCE(self):
105 response = test_utils.path_computation_request("request-1", "service-1",
106 {"node-id": "XPONDER-1", "service-rate": "100",
107 "service-format": "Ethernet", "clli": "Node1"},
108 {"node-id": "XPONDER-5", "service-rate": "100",
109 "service-format": "Ethernet", "clli": "Node5"})
110 self.assertEqual(response.status_code, requests.codes.ok)
111 res = response.json()
112 self.assertEqual(res['output']['configuration-response-common'][
113 'response-code'], '200')
114 self.assertEqual(res['output']['configuration-response-common'][
116 'Path is calculated by PCE')
117 self.assertIn('A-to-Z',
118 [res['output']['gnpy-response'][0]['path-dir'],
119 res['output']['gnpy-response'][1]['path-dir']])
120 self.assertIn('Z-to-A',
121 [res['output']['gnpy-response'][0]['path-dir'],
122 res['output']['gnpy-response'][1]['path-dir']])
123 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
124 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
127 # Path computed by PCE is not feasible by GNPy and GNPy cannot find
128 # another one (low SNR)
129 def test_05_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
130 response = test_utils.path_computation_request("request-2", "service-2",
131 {"node-id": "XPONDER-1", "service-rate": "100",
132 "service-format": "Ethernet", "clli": "Node1"},
133 {"node-id": "XPONDER-5", "service-rate": "100",
134 "service-format": "Ethernet", "clli": "Node5"},
135 {"include_": {"ordered-hops": [
136 {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
137 {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}},
138 {"hop-number": "2", "hop-type": {"node-id": "OpenROADM-4"}}]}
140 self.assertEqual(response.status_code, requests.codes.ok)
141 res = response.json()
142 self.assertEqual(res['output']['configuration-response-common'][
143 'response-code'], '500')
144 self.assertEqual(res['output']['configuration-response-common'][
146 'No path available by PCE and GNPy ')
147 self.assertIn('A-to-Z',
148 [res['output']['gnpy-response'][0]['path-dir'],
149 res['output']['gnpy-response'][1]['path-dir']])
150 self.assertIn('Z-to-A',
151 [res['output']['gnpy-response'][0]['path-dir'],
152 res['output']['gnpy-response'][1]['path-dir']])
153 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'],
155 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'],
159 # #PCE cannot find a path while GNPy finds a feasible one
160 def test_06_path_computation_NotFoundByPCE_FoundByGNPy(self):
161 response = test_utils.path_computation_request("request-3", "service-3",
162 {"node-id": "XPONDER-1", "service-rate": "100",
163 "service-format": "Ethernet", "clli": "Node1"},
164 {"node-id": "XPONDER-4", "service-rate": "100",
165 "service-format": "Ethernet", "clli": "Node5"},
166 {"include_": {"ordered-hops": [
167 {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
168 {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}}]}
170 self.assertEqual(response.status_code, requests.codes.ok)
171 res = response.json()
172 self.assertEqual(res['output']['configuration-response-common'][
173 'response-code'], '200')
174 self.assertEqual(res['output']['configuration-response-common'][
176 'Path is calculated by GNPy')
177 self.assertIn('A-to-Z',
178 [res['output']['gnpy-response'][0]['path-dir'],
179 res['output']['gnpy-response'][1]['path-dir']])
180 self.assertIn('Z-to-A',
181 [res['output']['gnpy-response'][0]['path-dir'],
182 res['output']['gnpy-response'][1]['path-dir']])
183 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
184 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
187 # Not found path by PCE and GNPy cannot find another one
188 def test_07_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
189 response = test_utils.path_computation_request("request-4", "service-4",
190 {"node-id": "XPONDER-1", "service-rate": "100",
191 "service-format": "Ethernet", "clli": "Node1"},
192 {"node-id": "XPONDER-4", "service-rate": "100",
193 "service-format": "Ethernet", "clli": "Node5"},
194 {"include_": {"ordered-hops": [
195 {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
196 {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}},
197 {"hop-number": "2", "hop-type": {"node-id": "OpenROADM-4"}},
198 {"hop-number": "3", "hop-type": {"node-id": "OpenROADM-3"}}]}
200 self.assertEqual(response.status_code, requests.codes.ok)
201 res = response.json()
202 self.assertEqual(res['output']['configuration-response-common'][
203 'response-code'], '500')
204 self.assertEqual(res['output']['configuration-response-common'][
206 'No path available by PCE and GNPy ')
209 # Disconnect the different topologies
210 def test_08_disconnect_openroadmTopology(self):
211 response = test_utils.delete_request(test_utils.URL_CONFIG_ORDM_TOPO)
212 self.assertEqual(response.status_code, requests.codes.ok)
215 def test_09_disconnect_openroadmNetwork(self):
216 response = test_utils.delete_request(test_utils.URL_CONFIG_ORDM_NET)
217 self.assertEqual(response.status_code, requests.codes.ok)
220 def test_10_disconnect_clliNetwork(self):
221 response = test_utils.delete_request(test_utils.URL_CONFIG_CLLI_NET)
222 self.assertEqual(response.status_code, requests.codes.ok)
226 def test_11_delete_port_mapping(self):
227 response = test_utils.delete_request(test_utils.URL_FULL_PORTMAPPING)
228 self.assertEqual(response.status_code, requests.codes.ok)
232 if __name__ == "__main__":
233 # logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
234 unittest.main(verbosity=2)