blob: 5db4ffa3f1a7f617db590fa650d5d22f740e3061 [file] [log] [blame]
Wei-Yu Chen49950b92021-11-08 19:19:18 +08001"""
2Copyright 2020 The Magma Authors.
3
4This source code is licensed under the BSD-style license found in the
5LICENSE file in the root directory of this source tree.
6
7Unless required by applicable law or agreed to in writing, software
8distributed under the License is distributed on an "AS IS" BASIS,
9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10See the License for the specific language governing permissions and
11limitations under the License.
12"""
13
14# pylint: disable=protected-access
15from unittest import TestCase
16
17from data_models.data_model_parameters import ParameterName
18from device_config.configuration_init import (
19 _get_enb_config,
20 _set_bandwidth,
21 _set_earfcn_freq_band_mode,
22 _set_management_server,
23 _set_misc_static_params,
24 _set_pci,
25 _set_perf_mgmt,
26 _set_plmnids_tac,
27 _set_s1_connection,
28 _set_tdd_subframe_config,
29)
30from device_config.enodeb_configuration import EnodebConfiguration
31from devices.baicells import BaicellsTrDataModel
32from exceptions import ConfigurationError
33from tests.test_utils.config_builder import EnodebConfigBuilder
34
35
36class EnodebConfigurationFactoryTest(TestCase):
37
38 def setUp(self):
39 self.data_model = BaicellsTrDataModel()
40 self.cfg = EnodebConfiguration(BaicellsTrDataModel())
41 self.device_cfg = EnodebConfiguration(BaicellsTrDataModel())
42
43 def tearDown(self):
44 self.data_model = None
45 self.cfg = None
46 self.device_cfg = None
47
48 def test_set_pci(self):
49 pci = 3
50 _set_pci(self.cfg, pci)
51 self.assertEqual(
52 self.cfg.get_parameter(ParameterName.PCI), pci,
53 'PCI value should be same as what was set',
54 )
55 with self.assertRaises(ConfigurationError):
56 _set_pci(self.cfg, 505)
57
58 def test_set_bandwidth(self):
59 mhz = 15
60 _set_bandwidth(self.cfg, self.data_model, mhz)
61 self.assertEqual(
62 self.cfg.get_parameter(ParameterName.DL_BANDWIDTH),
63 mhz,
64 'Should have set %s' % ParameterName.DL_BANDWIDTH,
65 )
66 self.assertEqual(
67 self.cfg.get_parameter(ParameterName.UL_BANDWIDTH),
68 mhz,
69 'Should have set %s' % ParameterName.UL_BANDWIDTH,
70 )
71
72 def test_set_tdd_subframe_config(self):
73 # Not TDD mode, should not try to set anything
74 self.device_cfg.set_parameter(
75 ParameterName.DUPLEX_MODE_CAPABILITY, 'Not TDDMode',
76 )
77 subframe = 0
78 special_subframe = 0
79 _set_tdd_subframe_config(
80 self.device_cfg, self.cfg, subframe,
81 special_subframe,
82 )
83 self.assertTrue(
84 ParameterName.SUBFRAME_ASSIGNMENT not in
85 self.cfg.get_parameter_names(),
86 )
87
88 # Invalid subframe assignment
89 self.device_cfg.set_parameter(
90 ParameterName.DUPLEX_MODE_CAPABILITY, 'TDDMode',
91 )
92 _set_tdd_subframe_config(
93 self.device_cfg, self.cfg, subframe,
94 special_subframe,
95 )
96 self.assertIn(
97 ParameterName.SUBFRAME_ASSIGNMENT,
98 self.cfg.get_parameter_names(),
99 'Expected a subframe assignment',
100 )
101
102 def test_set_management_server(self):
103 _set_management_server(self.cfg)
104 self.assertEqual(
105 self.cfg.get_parameter(ParameterName.PERIODIC_INFORM_ENABLE),
106 True, 'Expected periodic inform enable to be true',
107 )
108 self.assertTrue(
109 isinstance(
110 self.cfg.get_parameter(ParameterName.PERIODIC_INFORM_INTERVAL),
111 int,
112 ),
113 'Expected periodic inform interval to ani integer',
114 )
115
116 def test_set_s1_connection(self):
117 invalid_mme_ip = 1234
118 invalid_mme_port = '8080'
119 mme_ip = '192.168.0.1'
120 mme_port = 8080
121
122 # MME IP should be a string
123 with self.assertRaises(ConfigurationError):
124 _set_s1_connection(self.cfg, invalid_mme_ip, mme_port)
125
126 # MME Port should be an integer
127 with self.assertRaises(ConfigurationError):
128 _set_s1_connection(self.cfg, mme_ip, invalid_mme_port)
129
130 # Check the ip and port are sort properly
131 _set_s1_connection(self.cfg, mme_ip, mme_port)
132 self.assertEqual(
133 self.cfg.get_parameter(ParameterName.MME_IP), mme_ip,
134 'Expected mme ip to be set',
135 )
136 self.assertEqual(
137 self.cfg.get_parameter(ParameterName.MME_PORT), mme_port,
138 'Expected mme port to be set',
139 )
140
141 def test_set_perf_mgmt(self):
142 mgmt_ip = '192.168.0.1'
143 mgmt_upload_interval = 300
144 mgmt_port = 8080
145 _set_perf_mgmt(self.cfg, mgmt_ip, mgmt_port)
146 self.assertTrue(
147 self.cfg.get_parameter(ParameterName.PERF_MGMT_ENABLE),
148 'Expected perf mgmt to be enabled',
149 )
150 self.assertEqual(
151 self.cfg.get_parameter(ParameterName.PERF_MGMT_UPLOAD_INTERVAL),
152 mgmt_upload_interval, 'Expected upload interval to be set',
153 )
154 expected_url = 'http://192.168.0.1:8080/'
155 self.assertEqual(
156 self.cfg.get_parameter(ParameterName.PERF_MGMT_UPLOAD_URL),
157 expected_url, 'Incorrect Url',
158 )
159
160 def test_set_misc_static_params(self):
161 # IPSec enable as integer
162 self.device_cfg.set_parameter(ParameterName.IP_SEC_ENABLE, 0)
163 self.data_model.set_parameter_presence(ParameterName.GPS_ENABLE, True)
164 _set_misc_static_params(self.device_cfg, self.cfg, self.data_model)
165 self.assertTrue(
166 isinstance(
167 self.cfg.get_parameter(ParameterName.IP_SEC_ENABLE), int,
168 ),
169 'Should support an integer IP_SEC_ENABLE parameter',
170 )
171
172 # IPSec enable as boolean
173 self.device_cfg.set_parameter(ParameterName.IP_SEC_ENABLE, 'False')
174 _set_misc_static_params(self.device_cfg, self.cfg, self.data_model)
175 self.assertTrue(
176 isinstance(
177 self.cfg.get_parameter(ParameterName.IP_SEC_ENABLE), bool,
178 ),
179 'Should support a boolean IP_SEC_ENABLE parameter',
180 )
181 self.assertEqual(
182 self.cfg.get_parameter(ParameterName.LOCAL_GATEWAY_ENABLE), 0,
183 'Should be disabled',
184 )
185 self.assertEqual(
186 self.cfg.get_parameter(ParameterName.CELL_RESERVED), False,
187 'Should be disabled',
188 )
189 self.assertEqual(
190 self.cfg.get_parameter(ParameterName.MME_POOL_ENABLE), False,
191 'Should be disabled',
192 )
193
194 def test_set_plmnids_tac(self):
195 # We only handle a single PLMNID for now
196 plmnids = '1, 2, 3, 4'
197 tac = 1
198 with self.assertRaises(ConfigurationError):
199 _set_plmnids_tac(self.cfg, plmnids, tac)
200
201 # Max PLMNID length is 6 characters
202 plmnids = '1234567'
203 with self.assertRaises(ConfigurationError):
204 _set_plmnids_tac(self.cfg, plmnids, tac)
205
206 # Check that only one PLMN element is enabled
207 plmnids = '1'
208 _set_plmnids_tac(self.cfg, plmnids, tac)
209 self.assertTrue(
210 self.cfg.get_parameter_for_object(
211 ParameterName.PLMN_N_ENABLE % 1, ParameterName.PLMN_N % 1,
212 ),
213 'First PLMN should be enabled',
214 )
215 self.assertFalse(
216 self.cfg.has_object(ParameterName.PLMN_N % 2),
217 'Second PLMN should be disabled',
218 )
219
220 def test_set_earafcn_freq_band_mode(self):
221 # Invalid earfcndl
222 with self.assertRaises(ConfigurationError):
223 invalid_earfcndl = -1
224 _set_earfcn_freq_band_mode(
225 self.device_cfg, self.cfg,
226 self.data_model, invalid_earfcndl,
227 )
228
229 # Duplex_mode is TDD but capability is FDD
230 with self.assertRaises(ConfigurationError):
231 self.device_cfg.set_parameter(
232 ParameterName.DUPLEX_MODE_CAPABILITY, 'FDDMode',
233 )
234 earfcndl = 38650 # Corresponds to TDD
235 _set_earfcn_freq_band_mode(
236 self.device_cfg, self.cfg,
237 self.data_model, earfcndl,
238 )
239
240 # Duplex_mode is FDD but capability is TDD
241 with self.assertRaises(ConfigurationError):
242 self.device_cfg.set_parameter(
243 ParameterName.DUPLEX_MODE_CAPABILITY, 'TDDMode',
244 )
245 earfcndl = 0 # Corresponds to FDD
246 _set_earfcn_freq_band_mode(
247 self.device_cfg, self.cfg,
248 self.data_model, earfcndl,
249 )
250
251 def test_get_enb_config(self):
252 mconfig = EnodebConfigBuilder.get_mconfig()
253 enb_config = _get_enb_config(mconfig, self.device_cfg)
254 self.assertTrue(
255 enb_config.earfcndl == 39150,
256 "Should give earfcndl from default eNB config",
257 )
258
259 mconfig = EnodebConfigBuilder.get_multi_enb_mconfig()
260 self.device_cfg.set_parameter(
261 ParameterName.SERIAL_NUMBER,
262 '120200002618AGP0003',
263 )
264 enb_config = _get_enb_config(mconfig, self.device_cfg)
265 self.assertTrue(
266 enb_config.earfcndl == 39151,
267 "Should give earfcndl from specific eNB config",
268 )