Change way to start simulators
[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 sys.path.append('transportpce_tests/common/')
21 import test_utils
22
23
24 class TransportGNPYtesting(unittest.TestCase):
25
26     topo_cllinet_data = None
27     topo_ordnet_data = None
28     topo_ordtopo_data = None
29     port_mapping_data = None
30     processes = None
31
32     @classmethod
33     def setUpClass(cls):
34         # pylint: disable=bare-except
35         try:
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()
41
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()
46
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)
58             sys.exit(2)
59         except FileNotFoundError as err:
60             print("File Not found Error when trying to read sample files\n", err)
61             sys.exit(2)
62         except:
63             print("Unexpected error when trying to read sample files\n", sys.exc_info()[0])
64             sys.exit(2)
65         finally:
66             if sample_files_parsed:
67                 print("sample files content loaded")
68
69         cls.processes = test_utils.start_tpce()
70
71     @classmethod
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")
77
78     def setUp(self):
79         time.sleep(2)
80
81      # Load port mapping
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)
85         time.sleep(2)
86
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)
91         time.sleep(3)
92
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)
96         time.sleep(3)
97
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)
101         time.sleep(3)
102
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'][
115             'response-message'],
116             'Path is calculated by PCE')
117         self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
118                          'A-to-Z')
119         self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
120         self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
121                          'Z-to-A')
122         self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
123         time.sleep(5)
124
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"}}]}
137                                                         })
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'][
143             'response-message'],
144             'No path available by PCE and GNPy ')
145         self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
146                          'A-to-Z')
147         self.assertEqual(res['output']['gnpy-response'][1]['feasibility'],
148                          False)
149         self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
150                          'Z-to-A')
151         self.assertEqual(res['output']['gnpy-response'][0]['feasibility'],
152                          False)
153         time.sleep(5)
154
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"}}]}
165                                                         })
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'][
171             'response-message'],
172             'Path is calculated by GNPy')
173         self.assertEqual(res['output']['gnpy-response'][1]['path-dir'],
174                          'A-to-Z')
175         self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
176         self.assertEqual(res['output']['gnpy-response'][0]['path-dir'],
177                          'Z-to-A')
178         self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
179         time.sleep(5)
180
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"}}]}
193                                                         })
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'][
199             'response-message'],
200             'No path available by PCE and GNPy ')
201         time.sleep(5)
202
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)
207         time.sleep(3)
208
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)
212         time.sleep(3)
213
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)
217         time.sleep(3)
218
219     # Delete portmapping
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)
223         time.sleep(2)
224
225 if __name__ == "__main__":
226     # logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
227     unittest.main(verbosity=2)