2017-04-25 16:45:34 +01:00
|
|
|
"""
|
2016-09-15 01:15:43 +01:00
|
|
|
tdma.py: EMANE TDMA model bindings for CORE
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
|
|
|
|
2018-03-26 18:27:39 +01:00
|
|
|
import os
|
|
|
|
|
|
|
|
from core import constants
|
|
|
|
from core import logger
|
2018-06-06 22:51:45 +01:00
|
|
|
from core.conf import Configuration
|
2018-03-30 20:08:33 +01:00
|
|
|
from core.emane import emanemanifest
|
2018-03-29 22:38:32 +01:00
|
|
|
from core.emane import emanemodel
|
2017-04-25 16:45:34 +01:00
|
|
|
from core.enumerations import ConfigDataTypes
|
2018-03-26 18:27:39 +01:00
|
|
|
from core.misc import utils
|
2016-09-15 01:15:43 +01:00
|
|
|
|
|
|
|
|
2018-03-29 22:38:32 +01:00
|
|
|
class EmaneTdmaModel(emanemodel.EmaneModel):
|
2016-09-15 01:15:43 +01:00
|
|
|
# model name
|
2017-04-25 16:45:34 +01:00
|
|
|
name = "emane_tdma"
|
2018-03-29 21:32:06 +01:00
|
|
|
|
|
|
|
# mac configuration
|
2018-03-30 20:08:33 +01:00
|
|
|
mac_library = "tdmaeventschedulerradiomodel"
|
|
|
|
mac_xml = "/usr/share/emane/manifest/tdmaeventschedulerradiomodel.xml"
|
|
|
|
mac_defaults = {
|
|
|
|
"pcrcurveuri": "/usr/share/emane/xml/models/mac/tdmaeventscheduler/tdmabasemodelpcr.xml",
|
|
|
|
}
|
2018-03-30 20:52:10 +01:00
|
|
|
mac_config = emanemanifest.parse(mac_xml, mac_defaults)
|
2018-03-30 20:08:33 +01:00
|
|
|
|
|
|
|
# add custom schedule options and ignore it when writing emane xml
|
2018-03-26 18:27:39 +01:00
|
|
|
schedule_name = "schedule"
|
|
|
|
default_schedule = os.path.join(constants.CORE_DATA_DIR, "examples", "tdma", "schedule.xml")
|
2018-04-02 22:00:28 +01:00
|
|
|
mac_config.insert(
|
|
|
|
0,
|
2018-06-06 22:51:45 +01:00
|
|
|
Configuration(
|
|
|
|
_id=schedule_name,
|
|
|
|
_type=ConfigDataTypes.STRING,
|
|
|
|
default=default_schedule,
|
|
|
|
label="TDMA schedule file (core)"
|
|
|
|
)
|
2018-04-02 22:00:28 +01:00
|
|
|
)
|
2018-03-29 21:32:06 +01:00
|
|
|
config_ignore = {schedule_name}
|
2016-09-15 01:15:43 +01:00
|
|
|
|
2018-06-11 20:26:51 +01:00
|
|
|
def post_startup(self):
|
2018-03-26 18:27:39 +01:00
|
|
|
"""
|
|
|
|
Logic to execute after the emane manager is finished with startup.
|
|
|
|
|
|
|
|
:return: nothing
|
|
|
|
"""
|
|
|
|
# get configured schedule
|
2018-06-13 19:59:50 +01:00
|
|
|
config = self.session.emane.get_configs(node_id=self.object_id, config_type=self.name)
|
2018-06-06 22:51:45 +01:00
|
|
|
if not config:
|
2018-03-26 06:08:22 +01:00
|
|
|
return
|
2018-06-06 22:51:45 +01:00
|
|
|
schedule = config[self.schedule_name]
|
2018-03-28 21:58:49 +01:00
|
|
|
|
2018-06-11 20:26:51 +01:00
|
|
|
# get the set event device
|
|
|
|
event_device = self.session.emane.event_device
|
2018-03-26 18:27:39 +01:00
|
|
|
|
|
|
|
# initiate tdma schedule
|
|
|
|
logger.info("setting up tdma schedule: schedule(%s) device(%s)", schedule, event_device)
|
|
|
|
utils.check_cmd(["emaneevent-tdmaschedule", "-i", event_device, schedule])
|