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 from common import test_utils
23 class TransportGNPYtesting(unittest.TestCase):
25 topo_cllinet_data = None
26 topo_ordnet_data = None
27 topo_ordtopo_data = None
28 port_mapping_data = None
33 # pylint: disable=bare-except
35 sample_files_parsed = False
36 TOPO_CLLINET_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
37 "..", "..", "sample_configs", "gnpy", "clliNetwork.json")
38 with open(TOPO_CLLINET_FILE, 'r') as topo_cllinet:
39 cls.topo_cllinet_data = topo_cllinet.read()
41 TOPO_ORDNET_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
42 "..", "..", "sample_configs", "gnpy", "openroadmNetwork.json")
43 with open(TOPO_ORDNET_FILE, 'r') as topo_ordnet:
44 cls.topo_ordnet_data = topo_ordnet.read()
46 TOPO_ORDTOPO_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
47 "..", "..", "sample_configs", "gnpy", "openroadmTopology.json")
48 with open(TOPO_ORDTOPO_FILE, 'r') as topo_ordtopo:
49 cls.topo_ordtopo_data = topo_ordtopo.read()
50 PORT_MAPPING_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
51 "..", "..", "sample_configs", "gnpy", "gnpy_portmapping_121.json")
52 with open(PORT_MAPPING_FILE, 'r') as port_mapping:
53 cls.port_mapping_data = port_mapping.read()
54 sample_files_parsed = True
55 except PermissionError as err:
56 print("Permission Error when trying to read sample files\n", err)
58 except FileNotFoundError as err:
59 print("File Not found Error when trying to read sample files\n", err)
62 print("Unexpected error when trying to read sample files\n", sys.exc_info()[0])
65 if sample_files_parsed:
66 print("sample files content loaded")
68 cls.processes = test_utils.start_tpce()
71 def tearDownClass(cls):
72 # pylint: disable=not-an-iterable
73 for process in cls.processes:
74 test_utils.shutdown_process(process)
75 print("all processes killed")
81 def test_00_load_port_mapping(self):
82 response = test_utils.rawpost_request(test_utils.URL_FULL_PORTMAPPING, self.port_mapping_data)
83 self.assertEqual(response.status_code, requests.codes.no_content)
86 # Mount the different topologies
87 def test_01_connect_clliNetwork(self):
88 response = test_utils.rawput_request(test_utils.URL_CONFIG_CLLI_NET, self.topo_cllinet_data)
89 self.assertEqual(response.status_code, requests.codes.ok)
92 def test_02_connect_openroadmNetwork(self):
93 response = test_utils.rawput_request(test_utils.URL_CONFIG_ORDM_NET, self.topo_ordnet_data)
94 self.assertEqual(response.status_code, requests.codes.ok)
97 def test_03_connect_openroadmTopology(self):
98 response = test_utils.rawput_request(test_utils.URL_CONFIG_ORDM_TOPO, self.topo_ordtopo_data)
99 self.assertEqual(response.status_code, requests.codes.ok)
102 # Path computed by PCE is feasible according to Gnpy
103 def test_04_path_computation_FeasibleWithPCE(self):
104 response = test_utils.path_computation_request("request-1", "service-1",
105 {"node-id": "XPONDER-1", "service-rate": "100",
106 "service-format": "Ethernet", "clli": "Node1"},
107 {"node-id": "XPONDER-5", "service-rate": "100",
108 "service-format": "Ethernet", "clli": "Node5"})
109 self.assertEqual(response.status_code, requests.codes.ok)
110 res = response.json()
111 self.assertEqual(res['output']['configuration-response-common'][
112 'response-code'], '200')
113 self.assertEqual(res['output']['configuration-response-common'][
115 'Path is calculated by PCE')
116 self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
118 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
119 self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
121 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
124 # Path computed by PCE is not feasible by GNPy and GNPy cannot find
125 # another one (low SNR)
126 def test_05_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
127 response = test_utils.path_computation_request("request-2", "service-2",
128 {"node-id": "XPONDER-1", "service-rate": "100",
129 "service-format": "Ethernet", "clli": "Node1"},
130 {"node-id": "XPONDER-5", "service-rate": "100",
131 "service-format": "Ethernet", "clli": "Node5"},
132 {"include_": {"ordered-hops": [
133 {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
134 {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}},
135 {"hop-number": "2", "hop-type": {"node-id": "OpenROADM-4"}}]}
137 self.assertEqual(response.status_code, requests.codes.ok)
138 res = response.json()
139 self.assertEqual(res['output']['configuration-response-common'][
140 'response-code'], '500')
141 self.assertEqual(res['output']['configuration-response-common'][
143 'No path available by PCE and GNPy ')
144 self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
146 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'],
148 self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
150 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'],
154 # #PCE cannot find a path while GNPy finds a feasible one
155 def test_06_path_computation_NotFoundByPCE_FoundByGNPy(self):
156 response = test_utils.path_computation_request("request-3", "service-3",
157 {"node-id": "XPONDER-1", "service-rate": "100",
158 "service-format": "Ethernet", "clli": "Node1"},
159 {"node-id": "XPONDER-4", "service-rate": "100",
160 "service-format": "Ethernet", "clli": "Node5"},
161 {"include_": {"ordered-hops": [
162 {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
163 {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}}]}
165 self.assertEqual(response.status_code, requests.codes.ok)
166 res = response.json()
167 self.assertEqual(res['output']['configuration-response-common'][
168 'response-code'], '200')
169 self.assertEqual(res['output']['configuration-response-common'][
171 'Path is calculated by GNPy')
172 self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
174 self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
175 self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
177 self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
180 # Not found path by PCE and GNPy cannot find another one
181 def test_07_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
182 response = test_utils.path_computation_request("request-4", "service-4",
183 {"node-id": "XPONDER-1", "service-rate": "100",
184 "service-format": "Ethernet", "clli": "Node1"},
185 {"node-id": "XPONDER-4", "service-rate": "100",
186 "service-format": "Ethernet", "clli": "Node5"},
187 {"include_": {"ordered-hops": [
188 {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
189 {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}},
190 {"hop-number": "2", "hop-type": {"node-id": "OpenROADM-4"}},
191 {"hop-number": "3", "hop-type": {"node-id": "OpenROADM-3"}}]}
193 self.assertEqual(response.status_code, requests.codes.ok)
194 res = response.json()
195 self.assertEqual(res['output']['configuration-response-common'][
196 'response-code'], '500')
197 self.assertEqual(res['output']['configuration-response-common'][
199 'No path available by PCE and GNPy ')
202 # Disconnect the different topologies
203 def test_08_disconnect_openroadmTopology(self):
204 response = test_utils.delete_request(test_utils.URL_CONFIG_ORDM_TOPO)
205 self.assertEqual(response.status_code, requests.codes.ok)
208 def test_09_disconnect_openroadmNetwork(self):
209 response = test_utils.delete_request(test_utils.URL_CONFIG_ORDM_NET)
210 self.assertEqual(response.status_code, requests.codes.ok)
213 def test_10_disconnect_clliNetwork(self):
214 response = test_utils.delete_request(test_utils.URL_CONFIG_CLLI_NET)
215 self.assertEqual(response.status_code, requests.codes.ok)
219 def test_11_delete_port_mapping(self):
220 response = test_utils.delete_request(test_utils.URL_FULL_PORTMAPPING)
221 self.assertEqual(response.status_code, requests.codes.ok)
224 if __name__ == "__main__":
225 # logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
226 unittest.main(verbosity=2)