setup a simple default way for dealing with configurable options and added conifg group opbjects as a better way to access the same information formatted within a string

This commit is contained in:
Blake J. Harnden 2018-06-14 08:41:48 -07:00
parent 8e3cd0e013
commit 82c3d57dd3
7 changed files with 107 additions and 75 deletions

View file

@ -29,6 +29,21 @@ class ConfigShim(object):
values[key] = value
return values
@classmethod
def groups_to_str(cls, config_groups):
"""
Converts configuration groups to a TLV formatted string.
:param list[ConfigGroup] config_groups: configuration groups to format
:return: TLV configuration group string
:rtype: str
"""
group_strings = []
for config_group in config_groups:
group_string = "%s:%s-%s" % (config_group.name, config_group.start, config_group.stop)
group_strings.append(group_string)
return "|".join(group_strings)
@classmethod
def config_data(cls, flags, node_id, type_flags, configurable_options, config):
"""
@ -70,6 +85,7 @@ class ConfigShim(object):
else:
key_values += "|%s" % key_value
groups_str = cls.groups_to_str(configurable_options.config_groups())
return ConfigData(
message_type=flags,
node=node_id,
@ -80,7 +96,7 @@ class ConfigShim(object):
captions=captions,
possible_values="|".join(possible_values),
bitmap=configurable_options.bitmap,
groups=configurable_options.config_groups()
groups=groups_str
)
@ -228,12 +244,31 @@ class ConfigurableManager(object):
return self.node_configurations.setdefault(node_id, OrderedDict())
class ConfigGroup(object):
"""
Defines configuration group tabs used for display by ConfigurationOptions.
"""
def __init__(self, name, start, stop):
"""
Creates a ConfigGroup object.
:param str name: configuration group display name
:param int start: configurations start index for this group
:param int stop: configurations stop index for this group
"""
self.name = name
self.start = start
self.stop = stop
class ConfigurableOptions(object):
"""
Provides a base for defining configuration options within CORE.
"""
name = None
bitmap = None
options = []
_default_node = -1
@classmethod
@ -244,7 +279,7 @@ class ConfigurableOptions(object):
:return: configurations
:rtype: list[Configuration]
"""
return []
return cls.options
@classmethod
def config_groups(cls):
@ -252,9 +287,11 @@ class ConfigurableOptions(object):
Defines how configurations are grouped.
:return: configuration group definition
:rtype: str
:rtype: list[ConfigGroup]
"""
return None
return [
ConfigGroup("Options", 1, len(cls.configurations()))
]
@classmethod
def default_values(cls):

View file

@ -3,6 +3,7 @@ commeffect.py: EMANE CommEffect model for CORE
"""
from core import logger
from core.conf import ConfigGroup
from core.emane import emanemanifest
from core.emane import emanemodel
@ -41,7 +42,9 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
@classmethod
def config_groups(cls):
return "CommEffect SHIM Parameters:1-%d" % len(cls.configurations())
return [
ConfigGroup("CommEffect SHIM Parameters", 1, len(cls.configurations()))
]
def build_xml_files(self, emane_manager, interface):
"""

View file

@ -990,7 +990,6 @@ class EmaneGlobalModel(EmaneModel):
_DEFAULT_DEV = "ctrl0"
name = "emane"
configuration_maps = {}
emulator_xml = "/usr/share/emane/manifest/nemmanager.xml"
emulator_defaults = {

View file

@ -3,6 +3,7 @@ Defines Emane Models used within CORE.
"""
from core import logger
from core.conf import ConfigGroup
from core.emane import emanemanifest
from core.misc import utils
from core.mobility import WirelessModel
@ -68,7 +69,10 @@ class EmaneModel(WirelessModel):
def config_groups(cls):
mac_len = len(cls.mac_config)
config_len = len(cls.configurations())
return "MAC Parameters:1-%d|PHY Parameters:%d-%d" % (mac_len, mac_len + 1, config_len)
return [
ConfigGroup("MAC Parameters", 1, mac_len),
ConfigGroup("PHY Parameters", mac_len + 1, config_len)
]
def build_xml_files(self, emane_manager, interface):
"""

View file

@ -9,6 +9,7 @@ import threading
import time
from core import logger
from core.conf import ConfigGroup
from core.conf import ConfigurableOptions
from core.conf import Configuration
from core.conf import ModelManager
@ -314,21 +315,20 @@ class BasicRangeModel(WirelessModel):
the GUI.
"""
name = "basic_range"
@classmethod
def configurations(cls):
return [
Configuration(_id="range", _type=ConfigDataTypes.UINT32, default="275", label="wireless range (pixels)"),
Configuration(_id="bandwidth", _type=ConfigDataTypes.UINT32, default="54000", label="bandwidth (bps)"),
Configuration(_id="jitter", _type=ConfigDataTypes.FLOAT, default="0.0", label="transmission jitter (usec)"),
Configuration(_id="delay", _type=ConfigDataTypes.FLOAT, default="5000.0",
label="transmission delay (usec)"),
Configuration(_id="error", _type=ConfigDataTypes.FLOAT, default="0.0", label="error rate (%)")
]
options = [
Configuration(_id="range", _type=ConfigDataTypes.UINT32, default="275", label="wireless range (pixels)"),
Configuration(_id="bandwidth", _type=ConfigDataTypes.UINT32, default="54000", label="bandwidth (bps)"),
Configuration(_id="jitter", _type=ConfigDataTypes.FLOAT, default="0.0", label="transmission jitter (usec)"),
Configuration(_id="delay", _type=ConfigDataTypes.FLOAT, default="5000.0",
label="transmission delay (usec)"),
Configuration(_id="error", _type=ConfigDataTypes.FLOAT, default="0.0", label="error rate (%)")
]
@classmethod
def config_groups(cls):
return "Basic Range Parameters:1-%d" % len(cls.configurations())
return [
ConfigGroup("Basic Range Parameters", 1, len(cls.configurations()))
]
def __init__(self, session, object_id):
"""
@ -907,23 +907,22 @@ class Ns2ScriptedMobility(WayPointMobility):
BonnMotion.
"""
name = "ns2script"
@classmethod
def configurations(cls):
return [
Configuration(_id="file", _type=ConfigDataTypes.STRING, label="mobility script file"),
Configuration(_id="refresh_ms", _type=ConfigDataTypes.UINT32, default="50", label="mobility script file"),
Configuration(_id="loop", _type=ConfigDataTypes.BOOL, default="1", options=["On", "Off"], label="loop"),
Configuration(_id="autostart", _type=ConfigDataTypes.STRING, label="auto-start seconds (0.0 for runtime)"),
Configuration(_id="map", _type=ConfigDataTypes.STRING, label="node mapping (optional, e.g. 0:1,1:2,2:3)"),
Configuration(_id="script_start", _type=ConfigDataTypes.STRING, label="script file to run upon start"),
Configuration(_id="script_pause", _type=ConfigDataTypes.STRING, label="script file to run upon pause"),
Configuration(_id="script_stop", _type=ConfigDataTypes.STRING, label="script file to run upon stop")
]
options = [
Configuration(_id="file", _type=ConfigDataTypes.STRING, label="mobility script file"),
Configuration(_id="refresh_ms", _type=ConfigDataTypes.UINT32, default="50", label="mobility script file"),
Configuration(_id="loop", _type=ConfigDataTypes.BOOL, default="1", options=["On", "Off"], label="loop"),
Configuration(_id="autostart", _type=ConfigDataTypes.STRING, label="auto-start seconds (0.0 for runtime)"),
Configuration(_id="map", _type=ConfigDataTypes.STRING, label="node mapping (optional, e.g. 0:1,1:2,2:3)"),
Configuration(_id="script_start", _type=ConfigDataTypes.STRING, label="script file to run upon start"),
Configuration(_id="script_pause", _type=ConfigDataTypes.STRING, label="script file to run upon pause"),
Configuration(_id="script_stop", _type=ConfigDataTypes.STRING, label="script file to run upon stop")
]
@classmethod
def config_groups(cls):
return "ns-2 Mobility Script Parameters:1-%d" % len(cls.configurations())
return [
ConfigGroup("ns-2 Mobility Script Parameters", 1, len(cls.configurations()))
]
def __init__(self, session, object_id):
"""

View file

@ -1051,31 +1051,23 @@ class SessionConfig(ConfigurableManager, ConfigurableOptions):
Session configuration object.
"""
name = "session"
configuration_maps = {}
options = [
Configuration(_id="controlnet", _type=ConfigDataTypes.STRING, label="Control Network"),
Configuration(_id="controlnet0", _type=ConfigDataTypes.STRING, label="Control Network 0"),
Configuration(_id="controlnet1", _type=ConfigDataTypes.STRING, label="Control Network 1"),
Configuration(_id="controlnet2", _type=ConfigDataTypes.STRING, label="Control Network 2"),
Configuration(_id="controlnet3", _type=ConfigDataTypes.STRING, label="Control Network 3"),
Configuration(_id="controlnet_updown_script", _type=ConfigDataTypes.STRING, label="Control Network Script"),
Configuration(_id="enablerj45", _type=ConfigDataTypes.BOOL, default="1", options=["On", "Off"],
label="Enable RJ45s"),
Configuration(_id="preservedir", _type=ConfigDataTypes.BOOL, default="0", options=["On", "Off"],
label="Preserve session dir"),
Configuration(_id="enablesdt", _type=ConfigDataTypes.BOOL, default="0", options=["On", "Off"],
label="Enable SDT3D output"),
Configuration(_id="sdturl", _type=ConfigDataTypes.STRING, default=Sdt.DEFAULT_SDT_URL, label="SDT3D URL")
]
config_type = RegisterTlvs.UTILITY.value
@classmethod
def configurations(cls):
return [
Configuration(_id="controlnet", _type=ConfigDataTypes.STRING, label="Control Network"),
Configuration(_id="controlnet0", _type=ConfigDataTypes.STRING, label="Control Network 0"),
Configuration(_id="controlnet1", _type=ConfigDataTypes.STRING, label="Control Network 1"),
Configuration(_id="controlnet2", _type=ConfigDataTypes.STRING, label="Control Network 2"),
Configuration(_id="controlnet3", _type=ConfigDataTypes.STRING, label="Control Network 3"),
Configuration(_id="controlnet_updown_script", _type=ConfigDataTypes.STRING, label="Control Network Script"),
Configuration(_id="enablerj45", _type=ConfigDataTypes.BOOL, default="1", options=["On", "Off"],
label="Enable RJ45s"),
Configuration(_id="preservedir", _type=ConfigDataTypes.BOOL, default="0", options=["On", "Off"],
label="Preserve session dir"),
Configuration(_id="enablesdt", _type=ConfigDataTypes.BOOL, default="0", options=["On", "Off"],
label="Enable SDT3D output"),
Configuration(_id="sdturl", _type=ConfigDataTypes.STRING, default=Sdt.DEFAULT_SDT_URL, label="SDT3D URL")
]
@classmethod
def config_groups(cls):
return "Options:1-%d" % len(cls.configurations())
def __init__(self):
super(SessionConfig, self).__init__()
self.set_configs(self.default_values())
@ -1107,5 +1099,4 @@ class SessionMetaData(ConfigurableManager):
The data is not otherwise interpreted or processed.
"""
name = "metadata"
configuration_maps = {}
config_type = RegisterTlvs.UTILITY.value

View file

@ -1,31 +1,30 @@
import pytest
from core.conf import ConfigurableOptions, ConfigurableManager, ModelManager
from core.conf import ConfigurableManager
from core.conf import ConfigurableOptions
from core.conf import Configuration
from core.conf import ModelManager
from core.emane.ieee80211abg import EmaneIeee80211abgModel
from core.enumerations import ConfigDataTypes, NodeTypes
from core.enumerations import ConfigDataTypes
from core.enumerations import NodeTypes
from core.mobility import BasicRangeModel
class TestConfigurableOptions(ConfigurableOptions):
name_one = "value1"
name_two = "value2"
configuration_maps = {}
@classmethod
def configurations(cls):
return [
Configuration(
_id=TestConfigurableOptions.name_one,
_type=ConfigDataTypes.STRING,
label=TestConfigurableOptions.name_one
),
Configuration(
_id=TestConfigurableOptions.name_two,
_type=ConfigDataTypes.STRING,
label=TestConfigurableOptions.name_two
)
]
options = [
Configuration(
_id=name_one,
_type=ConfigDataTypes.STRING,
label=name_one
),
Configuration(
_id=name_two,
_type=ConfigDataTypes.STRING,
label=name_two
)
]
class TestConf: