2017-04-25 16:45:34 +01:00
|
|
|
"""
|
|
|
|
Defines Emane Models used within CORE.
|
|
|
|
"""
|
2019-02-16 17:50:19 +00:00
|
|
|
import logging
|
2021-03-19 23:54:24 +00:00
|
|
|
from pathlib import Path
|
2020-06-12 17:52:01 +01:00
|
|
|
from typing import Dict, List, Optional, Set
|
2018-07-03 20:48:54 +01:00
|
|
|
|
2019-09-10 22:20:51 +01:00
|
|
|
from core.config import ConfigGroup, Configuration
|
2018-03-30 20:08:33 +01:00
|
|
|
from core.emane import emanemanifest
|
2020-05-20 22:44:34 +01:00
|
|
|
from core.emane.nodes import EmaneNet
|
2020-06-16 20:50:24 +01:00
|
|
|
from core.emulator.data import LinkOptions
|
2020-07-03 01:49:56 +01:00
|
|
|
from core.emulator.enumerations import ConfigDataTypes
|
2019-09-28 07:29:15 +01:00
|
|
|
from core.errors import CoreError
|
2019-04-30 07:31:47 +01:00
|
|
|
from core.location.mobility import WirelessModel
|
2020-01-15 00:27:08 +00:00
|
|
|
from core.nodes.interface import CoreInterface
|
2018-07-04 02:49:36 +01:00
|
|
|
from core.xml import emanexml
|
2018-03-29 22:14:59 +01:00
|
|
|
|
2021-04-22 05:09:35 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
2021-05-19 05:29:38 +01:00
|
|
|
DEFAULT_DEV: str = "ctrl0"
|
|
|
|
MANIFEST_PATH: str = "share/emane/manifest"
|
2021-04-22 05:09:35 +01:00
|
|
|
|
2018-03-29 22:14:59 +01:00
|
|
|
|
2017-04-25 16:45:34 +01:00
|
|
|
class EmaneModel(WirelessModel):
|
|
|
|
"""
|
|
|
|
EMANE models inherit from this parent class, which takes care of
|
2018-03-28 21:58:49 +01:00
|
|
|
handling configuration messages based on the list of
|
2017-04-25 16:45:34 +01:00
|
|
|
configurable parameters. Helper functions also live here.
|
|
|
|
"""
|
2019-09-10 23:10:24 +01:00
|
|
|
|
2021-05-19 05:29:38 +01:00
|
|
|
# default platform configuration settings
|
|
|
|
platform_xml: str = "nemmanager.xml"
|
|
|
|
platform_defaults: Dict[str, str] = {
|
|
|
|
"eventservicedevice": DEFAULT_DEV,
|
|
|
|
"eventservicegroup": "224.1.2.8:45703",
|
|
|
|
"otamanagerdevice": DEFAULT_DEV,
|
|
|
|
"otamanagergroup": "224.1.2.8:45702",
|
|
|
|
}
|
|
|
|
platform_config: List[Configuration] = []
|
|
|
|
|
2018-03-30 20:08:33 +01:00
|
|
|
# default mac configuration settings
|
2020-06-12 17:52:01 +01:00
|
|
|
mac_library: Optional[str] = None
|
|
|
|
mac_xml: Optional[str] = None
|
|
|
|
mac_defaults: Dict[str, str] = {}
|
|
|
|
mac_config: List[Configuration] = []
|
2018-03-30 20:08:33 +01:00
|
|
|
|
|
|
|
# default phy configuration settings, using the universal model
|
2020-06-12 17:52:01 +01:00
|
|
|
phy_library: Optional[str] = None
|
|
|
|
phy_xml: str = "emanephy.xml"
|
|
|
|
phy_defaults: Dict[str, str] = {
|
|
|
|
"subid": "1",
|
|
|
|
"propagationmodel": "2ray",
|
|
|
|
"noisemode": "none",
|
|
|
|
}
|
|
|
|
phy_config: List[Configuration] = []
|
2018-03-30 20:08:33 +01:00
|
|
|
|
2018-07-11 17:19:06 +01:00
|
|
|
# support for external configurations
|
2020-06-12 17:52:01 +01:00
|
|
|
external_config: List[Configuration] = [
|
2018-07-11 17:19:06 +01:00
|
|
|
Configuration("external", ConfigDataTypes.BOOL, default="0"),
|
2019-09-10 23:10:24 +01:00
|
|
|
Configuration(
|
|
|
|
"platformendpoint", ConfigDataTypes.STRING, default="127.0.0.1:40001"
|
|
|
|
),
|
|
|
|
Configuration(
|
|
|
|
"transportendpoint", ConfigDataTypes.STRING, default="127.0.0.1:50002"
|
|
|
|
),
|
2018-07-11 17:19:06 +01:00
|
|
|
]
|
|
|
|
|
2020-06-12 17:52:01 +01:00
|
|
|
config_ignore: Set[str] = set()
|
2018-06-06 22:51:45 +01:00
|
|
|
|
2019-04-08 17:49:37 +01:00
|
|
|
@classmethod
|
2021-03-19 23:54:24 +00:00
|
|
|
def load(cls, emane_prefix: Path) -> None:
|
2019-04-08 17:49:37 +01:00
|
|
|
"""
|
2021-05-19 05:29:38 +01:00
|
|
|
Called after being loaded within the EmaneManager. Provides configured
|
|
|
|
emane_prefix for parsing xml files.
|
2019-04-08 17:49:37 +01:00
|
|
|
|
2020-01-16 19:00:57 +00:00
|
|
|
:param emane_prefix: configured emane prefix path
|
2019-04-08 17:49:37 +01:00
|
|
|
:return: nothing
|
|
|
|
"""
|
2021-05-19 05:29:38 +01:00
|
|
|
cls._load_platform_config(emane_prefix)
|
2019-04-08 17:49:37 +01:00
|
|
|
# load mac configuration
|
2021-05-19 05:29:38 +01:00
|
|
|
mac_xml_path = emane_prefix / MANIFEST_PATH / cls.mac_xml
|
2019-04-08 17:49:37 +01:00
|
|
|
cls.mac_config = emanemanifest.parse(mac_xml_path, cls.mac_defaults)
|
|
|
|
# load phy configuration
|
2021-05-19 05:29:38 +01:00
|
|
|
phy_xml_path = emane_prefix / MANIFEST_PATH / cls.phy_xml
|
2019-04-08 17:49:37 +01:00
|
|
|
cls.phy_config = emanemanifest.parse(phy_xml_path, cls.phy_defaults)
|
|
|
|
|
2021-05-19 05:29:38 +01:00
|
|
|
@classmethod
|
|
|
|
def _load_platform_config(cls, emane_prefix: Path) -> None:
|
|
|
|
platform_xml_path = emane_prefix / MANIFEST_PATH / cls.platform_xml
|
|
|
|
cls.platform_config = emanemanifest.parse(
|
|
|
|
platform_xml_path, cls.platform_defaults
|
|
|
|
)
|
|
|
|
|
2018-06-06 22:51:45 +01:00
|
|
|
@classmethod
|
2020-01-15 00:27:08 +00:00
|
|
|
def configurations(cls) -> List[Configuration]:
|
2019-04-08 17:49:37 +01:00
|
|
|
"""
|
|
|
|
Returns the combination all all configurations (mac, phy, and external).
|
|
|
|
|
|
|
|
:return: all configurations
|
2020-01-17 00:12:01 +00:00
|
|
|
"""
|
2021-05-19 05:29:38 +01:00
|
|
|
return (
|
|
|
|
cls.platform_config + cls.mac_config + cls.phy_config + cls.external_config
|
|
|
|
)
|
2018-06-06 22:51:45 +01:00
|
|
|
|
|
|
|
@classmethod
|
2020-01-15 00:27:08 +00:00
|
|
|
def config_groups(cls) -> List[ConfigGroup]:
|
2019-04-08 17:49:37 +01:00
|
|
|
"""
|
|
|
|
Returns the defined configuration groups.
|
|
|
|
|
|
|
|
:return: list of configuration groups.
|
2020-01-17 00:12:01 +00:00
|
|
|
"""
|
2021-05-19 05:29:38 +01:00
|
|
|
platform_len = len(cls.platform_config)
|
|
|
|
mac_len = len(cls.mac_config) + platform_len
|
2018-07-11 17:19:06 +01:00
|
|
|
phy_len = len(cls.phy_config) + mac_len
|
2018-06-06 22:51:45 +01:00
|
|
|
config_len = len(cls.configurations())
|
2018-06-14 16:41:48 +01:00
|
|
|
return [
|
2021-05-19 05:29:38 +01:00
|
|
|
ConfigGroup("Platform Parameters", 1, platform_len),
|
|
|
|
ConfigGroup("MAC Parameters", platform_len + 1, mac_len),
|
2018-07-11 17:19:06 +01:00
|
|
|
ConfigGroup("PHY Parameters", mac_len + 1, phy_len),
|
2019-09-10 23:10:24 +01:00
|
|
|
ConfigGroup("External Parameters", phy_len + 1, config_len),
|
2018-06-14 16:41:48 +01:00
|
|
|
]
|
2018-03-29 21:32:06 +01:00
|
|
|
|
2020-07-02 23:37:51 +01:00
|
|
|
def build_xml_files(self, config: Dict[str, str], iface: CoreInterface) -> None:
|
2018-03-29 21:32:06 +01:00
|
|
|
"""
|
2020-01-15 00:27:08 +00:00
|
|
|
Builds xml files for this emane model. Creates a nem.xml file that points to
|
|
|
|
both mac.xml and phy.xml definitions.
|
2018-03-29 21:32:06 +01:00
|
|
|
|
2020-01-16 19:00:57 +00:00
|
|
|
:param config: emane model configuration for the node and interface
|
2020-07-03 01:49:56 +01:00
|
|
|
:param iface: interface to run emane for
|
2018-03-29 21:32:06 +01:00
|
|
|
:return: nothing
|
|
|
|
"""
|
2020-07-03 01:49:56 +01:00
|
|
|
# create nem, mac, and phy xml files
|
|
|
|
emanexml.create_nem_xml(self, iface, config)
|
|
|
|
emanexml.create_mac_xml(self, iface, config)
|
|
|
|
emanexml.create_phy_xml(self, iface, config)
|
|
|
|
emanexml.create_transport_xml(iface, config)
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2020-01-15 00:27:08 +00:00
|
|
|
def post_startup(self) -> None:
|
2018-03-26 18:27:39 +01:00
|
|
|
"""
|
|
|
|
Logic to execute after the emane manager is finished with startup.
|
|
|
|
|
|
|
|
:return: nothing
|
|
|
|
"""
|
2021-04-22 05:09:35 +01:00
|
|
|
logger.debug("emane model(%s) has no post setup tasks", self.name)
|
2018-03-26 18:27:39 +01:00
|
|
|
|
2020-12-09 23:43:19 +00:00
|
|
|
def update(self, moved_ifaces: List[CoreInterface]) -> None:
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
2018-03-28 21:58:49 +01:00
|
|
|
Invoked from MobilityModel when nodes are moved; this causes
|
|
|
|
emane location events to be generated for the nodes in the moved
|
|
|
|
list, making EmaneModels compatible with Ns2ScriptedMobility.
|
|
|
|
|
2020-06-16 17:30:16 +01:00
|
|
|
:param moved_ifaces: interfaces that were moved
|
2020-01-15 00:27:08 +00:00
|
|
|
:return: nothing
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
|
|
|
try:
|
2020-07-30 01:08:20 +01:00
|
|
|
emane_net = self.session.get_node(self.id, EmaneNet)
|
|
|
|
emane_net.setnempositions(moved_ifaces)
|
2019-09-12 23:48:09 +01:00
|
|
|
except CoreError:
|
2021-04-22 05:09:35 +01:00
|
|
|
logger.exception("error during update")
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2019-09-10 23:10:24 +01:00
|
|
|
def linkconfig(
|
2020-06-16 17:30:16 +01:00
|
|
|
self, iface: CoreInterface, options: LinkOptions, iface2: CoreInterface = None
|
2020-01-15 00:27:08 +00:00
|
|
|
) -> None:
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
|
|
|
Invoked when a Link Message is received. Default is unimplemented.
|
2018-03-28 21:58:49 +01:00
|
|
|
|
2020-06-16 17:30:16 +01:00
|
|
|
:param iface: interface one
|
2020-06-09 21:41:31 +01:00
|
|
|
:param options: options for configuring link
|
2020-06-16 17:30:16 +01:00
|
|
|
:param iface2: interface two
|
2018-03-28 21:58:49 +01:00
|
|
|
:return: nothing
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
2021-04-22 05:09:35 +01:00
|
|
|
logger.warning("emane model(%s) does not support link config", self.name)
|