updates to allow configuration of installed emane_prefix for default models, requires small tweaks to custom models

This commit is contained in:
bharnden 2019-04-08 09:49:37 -07:00
parent 2825ce423b
commit 6672fd0f7a
10 changed files with 98 additions and 34 deletions

View file

@ -29,6 +29,11 @@ class EmaneBypassModel(emanemodel.EmaneModel):
phy_library = "bypassphylayer" phy_library = "bypassphylayer"
phy_config = [] phy_config = []
@classmethod
def load(cls, emane_prefix):
# ignore default logic
pass
# override config groups # override config groups
@classmethod @classmethod
def config_groups(cls): def config_groups(cls):

View file

@ -37,13 +37,18 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
name = "emane_commeffect" name = "emane_commeffect"
shim_library = "commeffectshim" shim_library = "commeffectshim"
shim_xml = "/usr/share/emane/manifest/commeffectshim.xml" shim_xml = "commeffectshim.xml"
shim_defaults = {} shim_defaults = {}
config_shim = emanemanifest.parse(shim_xml, shim_defaults) config_shim = []
# comm effect does not need the default phy and external configurations # comm effect does not need the default phy and external configurations
phy_config = () phy_config = []
external_config = () external_config = []
@classmethod
def load(cls, emane_prefix):
shim_xml_path = os.path.join(emane_prefix, "share/emane/manifest", cls.shim_xml)
cls.config_shim = emanemanifest.parse(shim_xml_path, cls.shim_defaults)
@classmethod @classmethod
def configurations(cls): def configurations(cls):

View file

@ -51,6 +51,7 @@ EMANE_MODELS = [
EmaneBypassModel, EmaneBypassModel,
EmaneTdmaModel EmaneTdmaModel
] ]
DEFAULT_EMANE_PREFIX = "/usr"
class EmaneManager(ModelManager): class EmaneManager(ModelManager):
@ -212,6 +213,8 @@ class EmaneManager(ModelManager):
""" """
for emane_model in emane_models: for emane_model in emane_models:
logging.info("loading emane model: %s", emane_model.__name__) logging.info("loading emane model: %s", emane_model.__name__)
emane_prefix = self.session.options.get_config("emane_prefix", default=DEFAULT_EMANE_PREFIX)
emane_model.load(emane_prefix)
self.models[emane_model.name] = emane_model self.models[emane_model.name] = emane_model
def add_node(self, emane_node): def add_node(self, emane_node):

View file

@ -26,13 +26,13 @@ class EmaneModel(WirelessModel):
# default phy configuration settings, using the universal model # default phy configuration settings, using the universal model
phy_library = None phy_library = None
phy_xml = "/usr/share/emane/manifest/emanephy.xml" phy_xml = "emanephy.xml"
phy_defaults = { phy_defaults = {
"subid": "1", "subid": "1",
"propagationmodel": "2ray", "propagationmodel": "2ray",
"noisemode": "none" "noisemode": "none"
} }
phy_config = emanemanifest.parse(phy_xml, phy_defaults) phy_config = []
# support for external configurations # support for external configurations
external_config = [ external_config = [
@ -43,12 +43,42 @@ class EmaneModel(WirelessModel):
config_ignore = set() config_ignore = set()
@classmethod
def load(cls, emane_prefix):
"""
Called after being loaded within the EmaneManager. Provides configured emane_prefix for
parsing xml files.
:param str emane_prefix: configured emane prefix path
:return: nothing
"""
manifest_path = "share/emane/manifest"
# load mac configuration
mac_xml_path = os.path.join(emane_prefix, manifest_path, cls.mac_xml)
cls.mac_config = emanemanifest.parse(mac_xml_path, cls.mac_defaults)
# load phy configuration
phy_xml_path = os.path.join(emane_prefix, manifest_path, cls.phy_xml)
cls.phy_config = emanemanifest.parse(phy_xml_path, cls.phy_defaults)
@classmethod @classmethod
def configurations(cls): def configurations(cls):
"""
Returns the combination all all configurations (mac, phy, and external).
:return: all configurations
:rtype: list[Configuration]
"""
return cls.mac_config + cls.phy_config + cls.external_config return cls.mac_config + cls.phy_config + cls.external_config
@classmethod @classmethod
def config_groups(cls): def config_groups(cls):
"""
Returns the defined configuration groups.
:return: list of configuration groups.
:rtype: list[ConfigGroup]
"""
mac_len = len(cls.mac_config) mac_len = len(cls.mac_config)
phy_len = len(cls.phy_config) + mac_len phy_len = len(cls.phy_config) + mac_len
config_len = len(cls.configurations()) config_len = len(cls.configurations())

View file

@ -1,8 +1,8 @@
""" """
ieee80211abg.py: EMANE IEEE 802.11abg model for CORE ieee80211abg.py: EMANE IEEE 802.11abg model for CORE
""" """
import os
from core.emane import emanemanifest
from core.emane import emanemodel from core.emane import emanemodel
@ -12,8 +12,12 @@ class EmaneIeee80211abgModel(emanemodel.EmaneModel):
# mac configuration # mac configuration
mac_library = "ieee80211abgmaclayer" mac_library = "ieee80211abgmaclayer"
mac_xml = "/usr/share/emane/manifest/ieee80211abgmaclayer.xml" mac_xml = "ieee80211abgmaclayer.xml"
mac_defaults = {
"pcrcurveuri": "/usr/share/emane/xml/models/mac/ieee80211abg/ieee80211pcr.xml", @classmethod
} def load(cls, emane_prefix):
mac_config = emanemanifest.parse(mac_xml, mac_defaults) cls.mac_defaults["pcrcurveuri"] = os.path.join(
emane_prefix,
"share/emane/xml/models/mac/ieee80211abg/ieee80211pcr.xml"
)
super(EmaneIeee80211abgModel, cls).load(emane_prefix)

View file

@ -1,8 +1,8 @@
""" """
rfpipe.py: EMANE RF-PIPE model for CORE rfpipe.py: EMANE RF-PIPE model for CORE
""" """
import os
from core.emane import emanemanifest
from core.emane import emanemodel from core.emane import emanemodel
@ -12,8 +12,12 @@ class EmaneRfPipeModel(emanemodel.EmaneModel):
# mac configuration # mac configuration
mac_library = "rfpipemaclayer" mac_library = "rfpipemaclayer"
mac_xml = "/usr/share/emane/manifest/rfpipemaclayer.xml" mac_xml = "rfpipemaclayer.xml"
mac_defaults = {
"pcrcurveuri": "/usr/share/emane/xml/models/mac/rfpipe/rfpipepcr.xml", @classmethod
} def load(cls, emane_prefix):
mac_config = emanemanifest.parse(mac_xml, mac_defaults) cls.mac_defaults["pcrcurveuri"] = os.path.join(
emane_prefix,
"share/emane/xml/models/mac/rfpipe/rfpipepcr.xml"
)
super(EmaneRfPipeModel, cls).load(emane_prefix)

View file

@ -7,7 +7,6 @@ import os
from core import constants from core import constants
from core.conf import Configuration from core.conf import Configuration
from core.emane import emanemanifest
from core.emane import emanemodel from core.emane import emanemodel
from core.enumerations import ConfigDataTypes from core.enumerations import ConfigDataTypes
from core.misc import utils from core.misc import utils
@ -19,26 +18,30 @@ class EmaneTdmaModel(emanemodel.EmaneModel):
# mac configuration # mac configuration
mac_library = "tdmaeventschedulerradiomodel" mac_library = "tdmaeventschedulerradiomodel"
mac_xml = "/usr/share/emane/manifest/tdmaeventschedulerradiomodel.xml" mac_xml = "tdmaeventschedulerradiomodel.xml"
mac_defaults = {
"pcrcurveuri": "/usr/share/emane/xml/models/mac/tdmaeventscheduler/tdmabasemodelpcr.xml",
}
mac_config = emanemanifest.parse(mac_xml, mac_defaults)
# add custom schedule options and ignore it when writing emane xml # add custom schedule options and ignore it when writing emane xml
schedule_name = "schedule" schedule_name = "schedule"
default_schedule = os.path.join(constants.CORE_DATA_DIR, "examples", "tdma", "schedule.xml") default_schedule = os.path.join(constants.CORE_DATA_DIR, "examples", "tdma", "schedule.xml")
mac_config.insert(
0,
Configuration(
_id=schedule_name,
_type=ConfigDataTypes.STRING,
default=default_schedule,
label="TDMA schedule file (core)"
)
)
config_ignore = {schedule_name} config_ignore = {schedule_name}
@classmethod
def load(cls, emane_prefix):
cls.mac_defaults["pcrcurveuri"] = os.path.join(
emane_prefix,
"share/emane/xml/models/mac/tdmaeventscheduler/tdmabasemodelpcr.xml"
)
super(EmaneTdmaModel, cls).load(emane_prefix)
cls.mac_config.insert(
0,
Configuration(
_id=cls.schedule_name,
_type=ConfigDataTypes.STRING,
default=cls.default_schedule,
label="TDMA schedule file (core)"
)
)
def post_startup(self): def post_startup(self):
""" """
Logic to execute after the emane manager is finished with startup. Logic to execute after the emane manager is finished with startup.

View file

@ -55,3 +55,5 @@ emane_event_monitor = False
# EMANE log level range [0,4] default: 2 # EMANE log level range [0,4] default: 2
#emane_log_level = 2 #emane_log_level = 2
emane_realtime = True emane_realtime = True
# prefix used for emane installation
# emane_prefix = /usr

View file

@ -224,7 +224,7 @@ def grpc_server():
@pytest.fixture @pytest.fixture
def session(): def session():
# use coreemu and create a session # use coreemu and create a session
coreemu = CoreEmu() coreemu = CoreEmu(config={"emane_prefix": "/usr"})
session_fixture = coreemu.create_session() session_fixture = coreemu.create_session()
session_fixture.set_state(EventTypes.CONFIGURATION_STATE) session_fixture.set_state(EventTypes.CONFIGURATION_STATE)
assert os.path.exists(session_fixture.session_dir) assert os.path.exists(session_fixture.session_dir)

View file

@ -1,6 +1,7 @@
""" """
Unit tests for testing CORE EMANE networks. Unit tests for testing CORE EMANE networks.
""" """
import os
import pytest import pytest
@ -19,6 +20,7 @@ _EMANE_MODELS = [
EmaneCommEffectModel, EmaneCommEffectModel,
EmaneTdmaModel, EmaneTdmaModel,
] ]
_DIR = os.path.dirname(os.path.abspath(__file__))
class TestEmane: class TestEmane:
@ -39,6 +41,12 @@ class TestEmane:
) )
emane_network.setposition(x=80, y=50) emane_network.setposition(x=80, y=50)
# configure tdma
if model == EmaneTdmaModel:
session.emane.set_model_config(emane_network.objid, EmaneTdmaModel.name, {
"schedule": os.path.join(_DIR, "../examples/tdma/schedule.xml")
})
# create nodes # create nodes
node_options = NodeOptions() node_options = NodeOptions()
node_options.set_position(150, 150) node_options.set_position(150, 150)