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