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