2018-06-14 00:17:47 +01:00
|
|
|
import pytest
|
2019-09-11 05:33:35 +01:00
|
|
|
|
2019-09-10 23:10:24 +01:00
|
|
|
from core.config import (
|
2021-11-16 00:40:30 +00:00
|
|
|
ConfigString,
|
2019-09-10 23:10:24 +01:00
|
|
|
ConfigurableManager,
|
|
|
|
ConfigurableOptions,
|
|
|
|
ModelManager,
|
|
|
|
)
|
2021-05-07 18:40:18 +01:00
|
|
|
from core.emane.models.ieee80211abg import EmaneIeee80211abgModel
|
2020-05-25 07:37:38 +01:00
|
|
|
from core.emulator.session import Session
|
2019-04-30 07:31:47 +01:00
|
|
|
from core.location.mobility import BasicRangeModel
|
2020-05-21 06:14:03 +01:00
|
|
|
from core.nodes.network import WlanNode
|
2018-06-08 18:25:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestConfigurableOptions(ConfigurableOptions):
|
2020-06-13 00:52:41 +01:00
|
|
|
name1 = "value1"
|
|
|
|
name2 = "value2"
|
2021-11-16 00:40:30 +00:00
|
|
|
options = [ConfigString(id=name1, label=name1), ConfigString(id=name2, label=name2)]
|
2018-06-08 18:25:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestConf:
|
|
|
|
def test_configurable_options_default(self):
|
|
|
|
# given
|
|
|
|
configurable_options = TestConfigurableOptions()
|
|
|
|
|
|
|
|
# when
|
|
|
|
default_values = TestConfigurableOptions.default_values()
|
|
|
|
instance_default_values = configurable_options.default_values()
|
|
|
|
|
|
|
|
# then
|
|
|
|
assert len(default_values) == 2
|
2020-06-13 00:52:41 +01:00
|
|
|
assert TestConfigurableOptions.name1 in default_values
|
|
|
|
assert TestConfigurableOptions.name2 in default_values
|
2018-06-08 18:25:56 +01:00
|
|
|
assert len(instance_default_values) == 2
|
2020-06-13 00:52:41 +01:00
|
|
|
assert TestConfigurableOptions.name1 in instance_default_values
|
|
|
|
assert TestConfigurableOptions.name2 in instance_default_values
|
2018-06-08 18:25:56 +01:00
|
|
|
|
|
|
|
def test_nodes(self):
|
|
|
|
# given
|
2018-06-13 19:59:50 +01:00
|
|
|
config_manager = ConfigurableManager()
|
2020-05-25 07:37:38 +01:00
|
|
|
test_config = {"1": "2"}
|
2018-06-08 18:25:56 +01:00
|
|
|
node_id = 1
|
|
|
|
config_manager.set_configs(test_config)
|
|
|
|
config_manager.set_configs(test_config, node_id=node_id)
|
|
|
|
|
|
|
|
# when
|
|
|
|
nodes = config_manager.nodes()
|
|
|
|
|
|
|
|
# then
|
|
|
|
assert len(nodes) == 1
|
2018-06-11 20:26:12 +01:00
|
|
|
assert node_id in nodes
|
2018-06-08 18:25:56 +01:00
|
|
|
|
|
|
|
def test_config_reset_all(self):
|
|
|
|
# given
|
2018-06-13 19:59:50 +01:00
|
|
|
config_manager = ConfigurableManager()
|
2020-05-25 07:37:38 +01:00
|
|
|
test_config = {"1": "2"}
|
2018-06-08 18:25:56 +01:00
|
|
|
node_id = 1
|
|
|
|
config_manager.set_configs(test_config)
|
|
|
|
config_manager.set_configs(test_config, node_id=node_id)
|
|
|
|
|
|
|
|
# when
|
|
|
|
config_manager.config_reset()
|
|
|
|
|
|
|
|
# then
|
2018-06-13 20:39:50 +01:00
|
|
|
assert not config_manager.node_configurations
|
2018-06-08 18:25:56 +01:00
|
|
|
|
|
|
|
def test_config_reset_node(self):
|
|
|
|
# given
|
2018-06-13 19:59:50 +01:00
|
|
|
config_manager = ConfigurableManager()
|
2020-05-25 07:37:38 +01:00
|
|
|
test_config = {"1": "2"}
|
2018-06-08 18:25:56 +01:00
|
|
|
node_id = 1
|
|
|
|
config_manager.set_configs(test_config)
|
|
|
|
config_manager.set_configs(test_config, node_id=node_id)
|
|
|
|
|
|
|
|
# when
|
|
|
|
config_manager.config_reset(node_id)
|
|
|
|
|
|
|
|
# then
|
2018-07-12 05:34:21 +01:00
|
|
|
assert not config_manager.get_configs(node_id=node_id)
|
2018-06-11 20:26:12 +01:00
|
|
|
assert config_manager.get_configs()
|
2018-06-08 18:25:56 +01:00
|
|
|
|
|
|
|
def test_configs_setget(self):
|
|
|
|
# given
|
2018-06-13 19:59:50 +01:00
|
|
|
config_manager = ConfigurableManager()
|
2020-05-25 07:37:38 +01:00
|
|
|
test_config = {"1": "2"}
|
2018-06-08 18:25:56 +01:00
|
|
|
node_id = 1
|
|
|
|
config_manager.set_configs(test_config)
|
|
|
|
config_manager.set_configs(test_config, node_id=node_id)
|
|
|
|
|
|
|
|
# when
|
|
|
|
default_config = config_manager.get_configs()
|
|
|
|
node_config = config_manager.get_configs(node_id)
|
|
|
|
|
|
|
|
# then
|
|
|
|
assert default_config
|
|
|
|
assert node_config
|
|
|
|
|
|
|
|
def test_config_setget(self):
|
|
|
|
# given
|
2018-06-13 19:59:50 +01:00
|
|
|
config_manager = ConfigurableManager()
|
2018-06-08 18:25:56 +01:00
|
|
|
name = "test"
|
|
|
|
value = "1"
|
|
|
|
node_id = 1
|
|
|
|
config_manager.set_config(name, value)
|
|
|
|
config_manager.set_config(name, value, node_id=node_id)
|
|
|
|
|
|
|
|
# when
|
|
|
|
defaults_value = config_manager.get_config(name)
|
|
|
|
node_value = config_manager.get_config(name, node_id=node_id)
|
|
|
|
|
|
|
|
# then
|
|
|
|
assert defaults_value == value
|
|
|
|
assert node_value == value
|
2018-06-14 00:17:47 +01:00
|
|
|
|
|
|
|
def test_model_setget_config(self):
|
|
|
|
# given
|
|
|
|
manager = ModelManager()
|
|
|
|
manager.models[BasicRangeModel.name] = BasicRangeModel
|
|
|
|
|
|
|
|
# when
|
|
|
|
manager.set_model_config(1, BasicRangeModel.name)
|
|
|
|
|
|
|
|
# then
|
|
|
|
assert manager.get_model_config(1, BasicRangeModel.name)
|
|
|
|
|
|
|
|
def test_model_set_config_error(self):
|
|
|
|
# given
|
|
|
|
manager = ModelManager()
|
|
|
|
manager.models[BasicRangeModel.name] = BasicRangeModel
|
|
|
|
bad_name = "bad-model"
|
|
|
|
|
|
|
|
# when/then
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
manager.set_model_config(1, bad_name)
|
|
|
|
|
|
|
|
def test_model_get_config_error(self):
|
|
|
|
# given
|
|
|
|
manager = ModelManager()
|
|
|
|
manager.models[BasicRangeModel.name] = BasicRangeModel
|
|
|
|
bad_name = "bad-model"
|
|
|
|
|
|
|
|
# when/then
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
manager.get_model_config(1, bad_name)
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_model_set(self, session: Session):
|
2018-06-14 00:17:47 +01:00
|
|
|
# given
|
2020-05-21 06:14:03 +01:00
|
|
|
wlan_node = session.add_node(WlanNode)
|
2018-06-14 00:17:47 +01:00
|
|
|
|
|
|
|
# when
|
|
|
|
session.mobility.set_model(wlan_node, BasicRangeModel)
|
|
|
|
|
|
|
|
# then
|
2019-04-27 06:07:51 +01:00
|
|
|
assert session.mobility.get_model_config(wlan_node.id, BasicRangeModel.name)
|
2018-06-14 00:17:47 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_model_set_error(self, session: Session):
|
2018-06-14 00:17:47 +01:00
|
|
|
# given
|
2020-05-21 06:14:03 +01:00
|
|
|
wlan_node = session.add_node(WlanNode)
|
2018-06-14 00:17:47 +01:00
|
|
|
|
|
|
|
# when / then
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
session.mobility.set_model(wlan_node, EmaneIeee80211abgModel)
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_get_models(self, session: Session):
|
2018-06-14 00:17:47 +01:00
|
|
|
# given
|
2020-05-21 06:14:03 +01:00
|
|
|
wlan_node = session.add_node(WlanNode)
|
2018-06-14 00:17:47 +01:00
|
|
|
session.mobility.set_model(wlan_node, BasicRangeModel)
|
|
|
|
|
|
|
|
# when
|
2018-06-14 00:23:51 +01:00
|
|
|
models = session.mobility.get_models(wlan_node)
|
2018-06-14 00:17:47 +01:00
|
|
|
|
|
|
|
# then
|
|
|
|
assert models
|
|
|
|
assert len(models) == 1
|