PCE modification in order to prepare flexgrid
[transportpce.git] / tests / transportpce_tests / 1.2.1 / test_gnpy.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2017 Orange, Inc. and others.  All rights reserved.
5 #
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 ##############################################################################
11
12 # pylint: disable=no-member
13 # pylint: disable=too-many-public-methods
14
15 import unittest
16 import os
17 import sys
18 import time
19 import requests
20 from common import test_utils
21
22
23 class TransportGNPYtesting(unittest.TestCase):
24
25     topo_cllinet_data = None
26     topo_ordnet_data = None
27     topo_ordtopo_data = None
28     port_mapping_data = None
29     processes = None
30
31     @classmethod
32     def setUpClass(cls):
33         # pylint: disable=bare-except
34         try:
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()
40
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()
45
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)
57             sys.exit(2)
58         except FileNotFoundError as err:
59             print("File Not found Error when trying to read sample files\n", err)
60             sys.exit(2)
61         except:
62             print("Unexpected error when trying to read sample files\n", sys.exc_info()[0])
63             sys.exit(2)
64         finally:
65             if sample_files_parsed:
66                 print("sample files content loaded")
67
68         cls.processes = test_utils.start_tpce()
69
70     @classmethod
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")
76
77     def setUp(self):
78         time.sleep(2)
79
80      # Load port mapping
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)
84         time.sleep(2)
85
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)
90         time.sleep(3)
91
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)
95         time.sleep(3)
96
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)
100         time.sleep(3)
101
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'][
114             'response-message'],
115             'Path is calculated by PCE')
116         self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
117                          'A-to-Z')
118         self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
119         self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
120                          'Z-to-A')
121         self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
122         time.sleep(5)
123
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"}}]}
136                                                         })
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'][
142             'response-message'],
143             'No path available by PCE and GNPy ')
144         self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
145                          'A-to-Z')
146         self.assertEqual(res['output']['gnpy-response'][1]['feasibility'],
147                          False)
148         self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
149                          'Z-to-A')
150         self.assertEqual(res['output']['gnpy-response'][0]['feasibility'],
151                          False)
152         time.sleep(5)
153
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"}}]}
164                                                         })
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'][
170             'response-message'],
171             'Path is calculated by GNPy')
172         self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
173                          'A-to-Z')
174         self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
175         self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
176                          'Z-to-A')
177         self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
178         time.sleep(5)
179
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"}}]}
192                                                         })
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'][
198             'response-message'],
199             'No path available by PCE and GNPy ')
200         time.sleep(5)
201
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)
206         time.sleep(3)
207
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)
211         time.sleep(3)
212
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)
216         time.sleep(3)
217
218     # Delete portmapping
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)
222         time.sleep(2)
223
224 if __name__ == "__main__":
225     # logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
226     unittest.main(verbosity=2)