blob: 5db4ffa3f1a7f617db590fa650d5d22f740e3061 [file] [log] [blame]
"""
Copyright 2020 The Magma Authors.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
# pylint: disable=protected-access
from unittest import TestCase
from data_models.data_model_parameters import ParameterName
from device_config.configuration_init import (
_get_enb_config,
_set_bandwidth,
_set_earfcn_freq_band_mode,
_set_management_server,
_set_misc_static_params,
_set_pci,
_set_perf_mgmt,
_set_plmnids_tac,
_set_s1_connection,
_set_tdd_subframe_config,
)
from device_config.enodeb_configuration import EnodebConfiguration
from devices.baicells import BaicellsTrDataModel
from exceptions import ConfigurationError
from tests.test_utils.config_builder import EnodebConfigBuilder
class EnodebConfigurationFactoryTest(TestCase):
def setUp(self):
self.data_model = BaicellsTrDataModel()
self.cfg = EnodebConfiguration(BaicellsTrDataModel())
self.device_cfg = EnodebConfiguration(BaicellsTrDataModel())
def tearDown(self):
self.data_model = None
self.cfg = None
self.device_cfg = None
def test_set_pci(self):
pci = 3
_set_pci(self.cfg, pci)
self.assertEqual(
self.cfg.get_parameter(ParameterName.PCI), pci,
'PCI value should be same as what was set',
)
with self.assertRaises(ConfigurationError):
_set_pci(self.cfg, 505)
def test_set_bandwidth(self):
mhz = 15
_set_bandwidth(self.cfg, self.data_model, mhz)
self.assertEqual(
self.cfg.get_parameter(ParameterName.DL_BANDWIDTH),
mhz,
'Should have set %s' % ParameterName.DL_BANDWIDTH,
)
self.assertEqual(
self.cfg.get_parameter(ParameterName.UL_BANDWIDTH),
mhz,
'Should have set %s' % ParameterName.UL_BANDWIDTH,
)
def test_set_tdd_subframe_config(self):
# Not TDD mode, should not try to set anything
self.device_cfg.set_parameter(
ParameterName.DUPLEX_MODE_CAPABILITY, 'Not TDDMode',
)
subframe = 0
special_subframe = 0
_set_tdd_subframe_config(
self.device_cfg, self.cfg, subframe,
special_subframe,
)
self.assertTrue(
ParameterName.SUBFRAME_ASSIGNMENT not in
self.cfg.get_parameter_names(),
)
# Invalid subframe assignment
self.device_cfg.set_parameter(
ParameterName.DUPLEX_MODE_CAPABILITY, 'TDDMode',
)
_set_tdd_subframe_config(
self.device_cfg, self.cfg, subframe,
special_subframe,
)
self.assertIn(
ParameterName.SUBFRAME_ASSIGNMENT,
self.cfg.get_parameter_names(),
'Expected a subframe assignment',
)
def test_set_management_server(self):
_set_management_server(self.cfg)
self.assertEqual(
self.cfg.get_parameter(ParameterName.PERIODIC_INFORM_ENABLE),
True, 'Expected periodic inform enable to be true',
)
self.assertTrue(
isinstance(
self.cfg.get_parameter(ParameterName.PERIODIC_INFORM_INTERVAL),
int,
),
'Expected periodic inform interval to ani integer',
)
def test_set_s1_connection(self):
invalid_mme_ip = 1234
invalid_mme_port = '8080'
mme_ip = '192.168.0.1'
mme_port = 8080
# MME IP should be a string
with self.assertRaises(ConfigurationError):
_set_s1_connection(self.cfg, invalid_mme_ip, mme_port)
# MME Port should be an integer
with self.assertRaises(ConfigurationError):
_set_s1_connection(self.cfg, mme_ip, invalid_mme_port)
# Check the ip and port are sort properly
_set_s1_connection(self.cfg, mme_ip, mme_port)
self.assertEqual(
self.cfg.get_parameter(ParameterName.MME_IP), mme_ip,
'Expected mme ip to be set',
)
self.assertEqual(
self.cfg.get_parameter(ParameterName.MME_PORT), mme_port,
'Expected mme port to be set',
)
def test_set_perf_mgmt(self):
mgmt_ip = '192.168.0.1'
mgmt_upload_interval = 300
mgmt_port = 8080
_set_perf_mgmt(self.cfg, mgmt_ip, mgmt_port)
self.assertTrue(
self.cfg.get_parameter(ParameterName.PERF_MGMT_ENABLE),
'Expected perf mgmt to be enabled',
)
self.assertEqual(
self.cfg.get_parameter(ParameterName.PERF_MGMT_UPLOAD_INTERVAL),
mgmt_upload_interval, 'Expected upload interval to be set',
)
expected_url = 'http://192.168.0.1:8080/'
self.assertEqual(
self.cfg.get_parameter(ParameterName.PERF_MGMT_UPLOAD_URL),
expected_url, 'Incorrect Url',
)
def test_set_misc_static_params(self):
# IPSec enable as integer
self.device_cfg.set_parameter(ParameterName.IP_SEC_ENABLE, 0)
self.data_model.set_parameter_presence(ParameterName.GPS_ENABLE, True)
_set_misc_static_params(self.device_cfg, self.cfg, self.data_model)
self.assertTrue(
isinstance(
self.cfg.get_parameter(ParameterName.IP_SEC_ENABLE), int,
),
'Should support an integer IP_SEC_ENABLE parameter',
)
# IPSec enable as boolean
self.device_cfg.set_parameter(ParameterName.IP_SEC_ENABLE, 'False')
_set_misc_static_params(self.device_cfg, self.cfg, self.data_model)
self.assertTrue(
isinstance(
self.cfg.get_parameter(ParameterName.IP_SEC_ENABLE), bool,
),
'Should support a boolean IP_SEC_ENABLE parameter',
)
self.assertEqual(
self.cfg.get_parameter(ParameterName.LOCAL_GATEWAY_ENABLE), 0,
'Should be disabled',
)
self.assertEqual(
self.cfg.get_parameter(ParameterName.CELL_RESERVED), False,
'Should be disabled',
)
self.assertEqual(
self.cfg.get_parameter(ParameterName.MME_POOL_ENABLE), False,
'Should be disabled',
)
def test_set_plmnids_tac(self):
# We only handle a single PLMNID for now
plmnids = '1, 2, 3, 4'
tac = 1
with self.assertRaises(ConfigurationError):
_set_plmnids_tac(self.cfg, plmnids, tac)
# Max PLMNID length is 6 characters
plmnids = '1234567'
with self.assertRaises(ConfigurationError):
_set_plmnids_tac(self.cfg, plmnids, tac)
# Check that only one PLMN element is enabled
plmnids = '1'
_set_plmnids_tac(self.cfg, plmnids, tac)
self.assertTrue(
self.cfg.get_parameter_for_object(
ParameterName.PLMN_N_ENABLE % 1, ParameterName.PLMN_N % 1,
),
'First PLMN should be enabled',
)
self.assertFalse(
self.cfg.has_object(ParameterName.PLMN_N % 2),
'Second PLMN should be disabled',
)
def test_set_earafcn_freq_band_mode(self):
# Invalid earfcndl
with self.assertRaises(ConfigurationError):
invalid_earfcndl = -1
_set_earfcn_freq_band_mode(
self.device_cfg, self.cfg,
self.data_model, invalid_earfcndl,
)
# Duplex_mode is TDD but capability is FDD
with self.assertRaises(ConfigurationError):
self.device_cfg.set_parameter(
ParameterName.DUPLEX_MODE_CAPABILITY, 'FDDMode',
)
earfcndl = 38650 # Corresponds to TDD
_set_earfcn_freq_band_mode(
self.device_cfg, self.cfg,
self.data_model, earfcndl,
)
# Duplex_mode is FDD but capability is TDD
with self.assertRaises(ConfigurationError):
self.device_cfg.set_parameter(
ParameterName.DUPLEX_MODE_CAPABILITY, 'TDDMode',
)
earfcndl = 0 # Corresponds to FDD
_set_earfcn_freq_band_mode(
self.device_cfg, self.cfg,
self.data_model, earfcndl,
)
def test_get_enb_config(self):
mconfig = EnodebConfigBuilder.get_mconfig()
enb_config = _get_enb_config(mconfig, self.device_cfg)
self.assertTrue(
enb_config.earfcndl == 39150,
"Should give earfcndl from default eNB config",
)
mconfig = EnodebConfigBuilder.get_multi_enb_mconfig()
self.device_cfg.set_parameter(
ParameterName.SERIAL_NUMBER,
'120200002618AGP0003',
)
enb_config = _get_enb_config(mconfig, self.device_cfg)
self.assertTrue(
enb_config.earfcndl == 39151,
"Should give earfcndl from specific eNB config",
)