daemon: updates to provide config types for configurable values, without the need to specify the enumerated type

This commit is contained in:
Blake Harnden 2021-11-15 16:40:30 -08:00
parent bd3e2f5d0e
commit 22e92111d0
10 changed files with 115 additions and 240 deletions

View file

@ -36,7 +36,7 @@ class ConfigGroup:
@dataclass
class Configuration:
"""
Represents a configuration options.
Represents a configuration option.
"""
id: str
@ -71,6 +71,42 @@ class Configuration:
)
@dataclass
class ConfigBool(Configuration):
"""
Represents a boolean configuration option.
"""
type: ConfigDataTypes = ConfigDataTypes.BOOL
@dataclass
class ConfigFloat(Configuration):
"""
Represents a float configuration option.
"""
type: ConfigDataTypes = ConfigDataTypes.FLOAT
@dataclass
class ConfigInt(Configuration):
"""
Represents an integer configuration option.
"""
type: ConfigDataTypes = ConfigDataTypes.INT32
@dataclass
class ConfigString(Configuration):
"""
Represents a string configuration option.
"""
type: ConfigDataTypes = ConfigDataTypes.STRING
class ConfigurableOptions:
"""
Provides a base for defining configuration options within CORE.

View file

@ -1,8 +1,7 @@
from typing import Any, Dict, List
from core.config import Configuration
from core.config import ConfigString, Configuration
from core.configservice.base import ConfigService, ConfigServiceMode
from core.emulator.enumerations import ConfigDataTypes
GROUP_NAME: str = "Security"
@ -19,24 +18,9 @@ class VpnClient(ConfigService):
shutdown: List[str] = ["killall openvpn"]
validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING
default_configs: List[Configuration] = [
Configuration(
id="keydir",
type=ConfigDataTypes.STRING,
label="Key Dir",
default="/etc/core/keys",
),
Configuration(
id="keyname",
type=ConfigDataTypes.STRING,
label="Key Name",
default="client1",
),
Configuration(
id="server",
type=ConfigDataTypes.STRING,
label="Server",
default="10.0.2.10",
),
ConfigString(id="keydir", label="Key Dir", default="/etc/core/keys"),
ConfigString(id="keyname", label="Key Name", default="client1"),
ConfigString(id="server", label="Server", default="10.0.2.10"),
]
modes: Dict[str, Dict[str, str]] = {}
@ -53,24 +37,9 @@ class VpnServer(ConfigService):
shutdown: List[str] = ["killall openvpn"]
validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING
default_configs: List[Configuration] = [
Configuration(
id="keydir",
type=ConfigDataTypes.STRING,
label="Key Dir",
default="/etc/core/keys",
),
Configuration(
id="keyname",
type=ConfigDataTypes.STRING,
label="Key Name",
default="server",
),
Configuration(
id="subnet",
type=ConfigDataTypes.STRING,
label="Subnet",
default="10.0.200.0",
),
ConfigString(id="keydir", label="Key Dir", default="/etc/core/keys"),
ConfigString(id="keyname", label="Key Name", default="server"),
ConfigString(id="subnet", label="Subnet", default="10.0.200.0"),
]
modes: Dict[str, Dict[str, str]] = {}

View file

@ -5,10 +5,9 @@ import logging
from pathlib import Path
from typing import Dict, List, Optional, Set
from core.config import ConfigGroup, Configuration
from core.config import ConfigBool, ConfigGroup, ConfigString, Configuration
from core.emane import emanemanifest
from core.emulator.data import LinkOptions
from core.emulator.enumerations import ConfigDataTypes
from core.errors import CoreError
from core.location.mobility import WirelessModel
from core.nodes.interface import CoreInterface
@ -55,13 +54,9 @@ class EmaneModel(WirelessModel):
# support for external configurations
external_config: List[Configuration] = [
Configuration("external", ConfigDataTypes.BOOL, default="0"),
Configuration(
"platformendpoint", ConfigDataTypes.STRING, default="127.0.0.1:40001"
),
Configuration(
"transportendpoint", ConfigDataTypes.STRING, default="127.0.0.1:50002"
),
ConfigBool(id="external", default="0"),
ConfigString(id="platformendpoint", default="127.0.0.1:40001"),
ConfigString(id="transportendpoint", default="127.0.0.1:50002"),
]
config_ignore: Set[str] = set()

View file

@ -4,9 +4,8 @@ EMANE Bypass model for CORE
from pathlib import Path
from typing import List, Set
from core.config import Configuration
from core.config import ConfigBool, Configuration
from core.emane import emanemodel
from core.emulator.enumerations import ConfigDataTypes
class EmaneBypassModel(emanemodel.EmaneModel):
@ -18,9 +17,8 @@ class EmaneBypassModel(emanemodel.EmaneModel):
# mac definitions
mac_library: str = "bypassmaclayer"
mac_config: List[Configuration] = [
Configuration(
ConfigBool(
id="none",
type=ConfigDataTypes.BOOL,
default="0",
label="There are no parameters for the bypass model.",
)

View file

@ -7,10 +7,9 @@ from pathlib import Path
from typing import Set
from core import constants, utils
from core.config import Configuration
from core.config import ConfigString
from core.emane import emanemodel
from core.emane.nodes import EmaneNet
from core.emulator.enumerations import ConfigDataTypes
from core.nodes.interface import CoreInterface
logger = logging.getLogger(__name__)
@ -38,9 +37,8 @@ class EmaneTdmaModel(emanemodel.EmaneModel):
/ "share/emane/xml/models/mac/tdmaeventscheduler/tdmabasemodelpcr.xml"
)
super().load(emane_prefix)
config_item = Configuration(
config_item = ConfigString(
id=cls.schedule_name,
type=ConfigDataTypes.STRING,
default=str(cls.default_schedule),
label="TDMA schedule file (core)",
)

View file

@ -1,7 +1,14 @@
from typing import Any, List
from core.config import ConfigurableManager, ConfigurableOptions, Configuration
from core.emulator.enumerations import ConfigDataTypes, RegisterTlvs
from core.config import (
ConfigBool,
ConfigInt,
ConfigString,
ConfigurableManager,
ConfigurableOptions,
Configuration,
)
from core.emulator.enumerations import RegisterTlvs
from core.plugins.sdt import Sdt
@ -12,89 +19,27 @@ class SessionConfig(ConfigurableManager, ConfigurableOptions):
name: str = "session"
options: List[Configuration] = [
Configuration(
id="controlnet", type=ConfigDataTypes.STRING, label="Control Network"
ConfigString(id="controlnet", label="Control Network"),
ConfigString(id="controlnet0", label="Control Network 0"),
ConfigString(id="controlnet1", label="Control Network 1"),
ConfigString(id="controlnet2", label="Control Network 2"),
ConfigString(id="controlnet3", label="Control Network 3"),
ConfigString(id="controlnet_updown_script", label="Control Network Script"),
ConfigBool(id="enablerj45", default="1", label="Enable RJ45s"),
ConfigBool(id="preservedir", default="0", label="Preserve session dir"),
ConfigBool(id="enablesdt", default="0", label="Enable SDT3D output"),
ConfigString(id="sdturl", default=Sdt.DEFAULT_SDT_URL, label="SDT3D URL"),
ConfigBool(id="ovs", default="0", label="Enable OVS"),
ConfigInt(id="platform_id_start", default="1", label="EMANE Platform ID Start"),
ConfigInt(id="nem_id_start", default="1", label="EMANE NEM ID Start"),
ConfigBool(id="link_enabled", default="1", label="EMANE Links?"),
ConfigInt(
id="loss_threshold", default="30", label="EMANE Link Loss Threshold (%)"
),
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",
label="Enable RJ45s",
),
Configuration(
id="preservedir",
type=ConfigDataTypes.BOOL,
default="0",
label="Preserve session dir",
),
Configuration(
id="enablesdt",
type=ConfigDataTypes.BOOL,
default="0",
label="Enable SDT3D output",
),
Configuration(
id="sdturl",
type=ConfigDataTypes.STRING,
default=Sdt.DEFAULT_SDT_URL,
label="SDT3D URL",
),
Configuration(
id="ovs", type=ConfigDataTypes.BOOL, default="0", label="Enable OVS"
),
Configuration(
id="platform_id_start",
type=ConfigDataTypes.INT32,
default="1",
label="EMANE Platform ID Start",
),
Configuration(
id="nem_id_start",
type=ConfigDataTypes.INT32,
default="1",
label="EMANE NEM ID Start",
),
Configuration(
id="link_enabled",
type=ConfigDataTypes.BOOL,
default="1",
label="EMANE Links?",
),
Configuration(
id="loss_threshold",
type=ConfigDataTypes.INT32,
default="30",
label="EMANE Link Loss Threshold (%)",
),
Configuration(
id="link_interval",
type=ConfigDataTypes.INT32,
default="1",
label="EMANE Link Check Interval (sec)",
),
Configuration(
id="link_timeout",
type=ConfigDataTypes.INT32,
default="4",
label="EMANE Link Timeout (sec)",
ConfigInt(
id="link_interval", default="1", label="EMANE Link Check Interval (sec)"
),
ConfigInt(id="link_timeout", default="4", label="EMANE Link Timeout (sec)"),
]
config_type: RegisterTlvs = RegisterTlvs.UTILITY

View file

@ -12,16 +12,18 @@ from pathlib import Path
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Tuple, Union
from core import utils
from core.config import ConfigGroup, ConfigurableOptions, Configuration, ModelManager
from core.config import (
ConfigBool,
ConfigGroup,
ConfigInt,
ConfigString,
ConfigurableOptions,
Configuration,
ModelManager,
)
from core.emane.nodes import EmaneNet
from core.emulator.data import EventData, LinkData, LinkOptions
from core.emulator.enumerations import (
ConfigDataTypes,
EventTypes,
LinkTypes,
MessageFlags,
RegisterTlvs,
)
from core.emulator.enumerations import EventTypes, LinkTypes, MessageFlags, RegisterTlvs
from core.errors import CoreError
from core.executables import BASH
from core.nodes.base import CoreNode
@ -274,39 +276,12 @@ class BasicRangeModel(WirelessModel):
name: str = "basic_range"
options: List[Configuration] = [
Configuration(
id="range",
type=ConfigDataTypes.UINT32,
default="275",
label="wireless range (pixels)",
),
Configuration(
id="bandwidth",
type=ConfigDataTypes.UINT64,
default="54000000",
label="bandwidth (bps)",
),
Configuration(
id="jitter",
type=ConfigDataTypes.UINT64,
default="0",
label="transmission jitter (usec)",
),
Configuration(
id="delay",
type=ConfigDataTypes.UINT64,
default="5000",
label="transmission delay (usec)",
),
Configuration(
id="error", type=ConfigDataTypes.STRING, default="0", label="loss (%)"
),
Configuration(
id="promiscuous",
type=ConfigDataTypes.BOOL,
default="0",
label="promiscuous mode",
),
ConfigInt(id="range", default="275", label="wireless range (pixels)"),
ConfigInt(id="bandwidth", default="54000000", label="bandwidth (bps)"),
ConfigInt(id="jitter", default="0", label="transmission jitter (usec)"),
ConfigInt(id="delay", default="5000", label="transmission delay (usec)"),
ConfigString(id="error", default="0", label="loss (%)"),
ConfigBool(id="promiscuous", default="0", label="promiscuous mode"),
]
@classmethod
@ -887,41 +862,14 @@ class Ns2ScriptedMobility(WayPointMobility):
name: str = "ns2script"
options: List[Configuration] = [
Configuration(
id="file", type=ConfigDataTypes.STRING, label="mobility script file"
),
Configuration(
id="refresh_ms",
type=ConfigDataTypes.UINT32,
default="50",
label="refresh time (ms)",
),
Configuration(id="loop", type=ConfigDataTypes.BOOL, default="1", 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",
),
ConfigString(id="file", label="mobility script file"),
ConfigInt(id="refresh_ms", default="50", label="refresh time (ms)"),
ConfigBool(id="loop", default="1", label="loop"),
ConfigString(id="autostart", label="auto-start seconds (0.0 for runtime)"),
ConfigString(id="map", label="node mapping (optional, e.g. 0:1,1:2,2:3)"),
ConfigString(id="script_start", label="script file to run upon start"),
ConfigString(id="script_pause", label="script file to run upon pause"),
ConfigString(id="script_stop", label="script file to run upon stop"),
]
@classmethod

View file

@ -1,13 +1,12 @@
import pytest
from core.config import (
ConfigString,
ConfigurableManager,
ConfigurableOptions,
Configuration,
ModelManager,
)
from core.emane.models.ieee80211abg import EmaneIeee80211abgModel
from core.emulator.enumerations import ConfigDataTypes
from core.emulator.session import Session
from core.location.mobility import BasicRangeModel
from core.nodes.network import WlanNode
@ -16,10 +15,7 @@ from core.nodes.network import WlanNode
class TestConfigurableOptions(ConfigurableOptions):
name1 = "value1"
name2 = "value2"
options = [
Configuration(id=name1, type=ConfigDataTypes.STRING, label=name1),
Configuration(id=name2, type=ConfigDataTypes.STRING, label=name2),
]
options = [ConfigString(id=name1, label=name1), ConfigString(id=name2, label=name2)]
class TestConf:

View file

@ -3,13 +3,12 @@ from unittest import mock
import pytest
from core.config import Configuration
from core.config import ConfigBool, ConfigString
from core.configservice.base import (
ConfigService,
ConfigServiceBootError,
ConfigServiceMode,
)
from core.emulator.enumerations import ConfigDataTypes
from core.errors import CoreCommandError, CoreError
TEMPLATE_TEXT = "echo hello"
@ -27,13 +26,10 @@ class MyService(ConfigService):
shutdown = [f"pkill {files[0]}"]
validation_mode = ConfigServiceMode.BLOCKING
default_configs = [
Configuration(id="value1", type=ConfigDataTypes.STRING, label="Text"),
Configuration(id="value2", type=ConfigDataTypes.BOOL, label="Boolean"),
Configuration(
id="value3",
type=ConfigDataTypes.STRING,
label="Multiple Choice",
options=["value1", "value2", "value3"],
ConfigString(id="value1", label="Text"),
ConfigBool(id="value2", label="Boolean"),
ConfigString(
id="value3", label="Multiple Choice", options=["value1", "value2", "value3"]
),
]
modes = {

View file

@ -118,9 +118,8 @@ running the shell files generated.
```python
from typing import Dict, List
from core.config import Configuration
from core.config import ConfigString, ConfigBool, Configuration
from core.configservice.base import ConfigService, ConfigServiceMode, ShadowDir
from core.emulator.enumerations import ConfigDataTypes
# class that subclasses ConfigService
class ExampleService(ConfigService):
@ -152,14 +151,9 @@ class ExampleService(ConfigService):
validation_mode: ConfigServiceMode = ConfigServiceMode.BLOCKING
# configurable values that this service can use, for file generation
default_configs: List[Configuration] = [
Configuration(id="value1", type=ConfigDataTypes.STRING, label="Text"),
Configuration(id="value2", type=ConfigDataTypes.BOOL, label="Boolean"),
Configuration(
id="value3",
type=ConfigDataTypes.STRING,
label="Multiple Choice",
options=["value1", "value2", "value3"],
),
ConfigString(id="value1", label="Text"),
ConfigBool(id="value2", label="Boolean"),
ConfigString(id="value3", label="Multiple Choice", options=["value1", "value2", "value3"]),
]
# sets of values to set for the configuration defined above, can be used to
# provide convenient sets of values to typically use