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/')
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.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
119 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
120 self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
122 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
125 # Path computed by PCE is not feasible by GNPy and GNPy cannot find
126 # another one (low SNR)
127 def test_05_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
128 response = test_utils.path_computation_request("request-2", "service-2",
129 {"node-id": "XPONDER-1", "service-rate": "100",
130 "service-format": "Ethernet", "clli": "Node1"},
131 {"node-id": "XPONDER-5", "service-rate": "100",
132 "service-format": "Ethernet", "clli": "Node5"},
133 {"include_": {"ordered-hops": [
134 {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
135 {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}},
136 {"hop-number": "2", "hop-type": {"node-id": "OpenROADM-4"}}]}
138 self.assertEqual(response.status_code, requests.codes.ok)
139 res = response.json()
140 self.assertEqual(res['output']['configuration-response-common'][
141 'response-code'], '500')
142 self.assertEqual(res['output']['configuration-response-common'][
144 'No path available by PCE and GNPy ')
145 self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
147 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'],
149 self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
151 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'],
155 # #PCE cannot find a path while GNPy finds a feasible one
156 def test_06_path_computation_NotFoundByPCE_FoundByGNPy(self):
157 response = test_utils.path_computation_request("request-3", "service-3",
158 {"node-id": "XPONDER-1", "service-rate": "100",
159 "service-format": "Ethernet", "clli": "Node1"},
160 {"node-id": "XPONDER-4", "service-rate": "100",
161 "service-format": "Ethernet", "clli": "Node5"},
162 {"include_": {"ordered-hops": [
163 {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
164 {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}}]}
166 self.assertEqual(response.status_code, requests.codes.ok)
167 res = response.json()
168 self.assertEqual(res['output']['configuration-response-common'][
169 'response-code'], '200')
170 self.assertEqual(res['output']['configuration-response-common'][
172 'Path is calculated by GNPy')
173 self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
175 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
176 self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
178 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
181 # Not found path by PCE and GNPy cannot find another one
182 def test_07_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
183 response = test_utils.path_computation_request("request-4", "service-4",
184 {"node-id": "XPONDER-1", "service-rate": "100",
185 "service-format": "Ethernet", "clli": "Node1"},
186 {"node-id": "XPONDER-4", "service-rate": "100",
187 "service-format": "Ethernet", "clli": "Node5"},
188 {"include_": {"ordered-hops": [
189 {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
190 {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}},
191 {"hop-number": "2", "hop-type": {"node-id": "OpenROADM-4"}},
192 {"hop-number": "3", "hop-type": {"node-id": "OpenROADM-3"}}]}
194 self.assertEqual(response.status_code, requests.codes.ok)
195 res = response.json()
196 self.assertEqual(res['output']['configuration-response-common'][
197 'response-code'], '500')
198 self.assertEqual(res['output']['configuration-response-common'][
200 'No path available by PCE and GNPy ')
203 # Disconnect the different topologies
204 def test_08_disconnect_openroadmTopology(self):
205 response = test_utils.delete_request(test_utils.URL_CONFIG_ORDM_TOPO)
206 self.assertEqual(response.status_code, requests.codes.ok)
209 def test_09_disconnect_openroadmNetwork(self):
210 response = test_utils.delete_request(test_utils.URL_CONFIG_ORDM_NET)
211 self.assertEqual(response.status_code, requests.codes.ok)
214 def test_10_disconnect_clliNetwork(self):
215 response = test_utils.delete_request(test_utils.URL_CONFIG_CLLI_NET)
216 self.assertEqual(response.status_code, requests.codes.ok)
220 def test_11_delete_port_mapping(self):
221 response = test_utils.delete_request(test_utils.URL_FULL_PORTMAPPING)
222 self.assertEqual(response.status_code, requests.codes.ok)
225 if __name__ == "__main__":
226 # logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
227 unittest.main(verbosity=2)