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
|
|
|
"""
|
|
|
|
|
2019-02-16 17:50:19 +00:00
|
|
|
import logging
|
2021-03-19 23:54:24 +00:00
|
|
|
from pathlib import Path
|
2018-03-26 18:27:39 +01:00
|
|
|
|
2019-04-30 07:31:47 +01:00
|
|
|
from core import constants, utils
|
2021-11-16 00:40:30 +00:00
|
|
|
from core.config import ConfigString
|
2018-03-29 22:38:32 +01:00
|
|
|
from core.emane import emanemodel
|
2021-05-25 20:14:28 +01:00
|
|
|
from core.emane.nodes import EmaneNet
|
|
|
|
from core.nodes.interface import CoreInterface
|
2016-09-15 01:15:43 +01:00
|
|
|
|
2021-04-22 05:09:35 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
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
|
2020-06-12 17:52:01 +01:00
|
|
|
name: str = "emane_tdma"
|
2018-03-29 21:32:06 +01:00
|
|
|
|
|
|
|
# mac configuration
|
2020-06-12 17:52:01 +01:00
|
|
|
mac_library: str = "tdmaeventschedulerradiomodel"
|
|
|
|
mac_xml: str = "tdmaeventschedulerradiomodel.xml"
|
2018-03-30 20:08:33 +01:00
|
|
|
|
|
|
|
# add custom schedule options and ignore it when writing emane xml
|
2020-06-12 17:52:01 +01:00
|
|
|
schedule_name: str = "schedule"
|
2021-03-19 23:54:24 +00:00
|
|
|
default_schedule: Path = (
|
|
|
|
constants.CORE_DATA_DIR / "examples" / "tdma" / "schedule.xml"
|
2019-09-10 23:10:24 +01:00
|
|
|
)
|
2023-04-13 20:18:24 +01:00
|
|
|
config_ignore: set[str] = {schedule_name}
|
2016-09-15 01:15:43 +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:
|
|
|
|
cls.mac_defaults["pcrcurveuri"] = str(
|
|
|
|
emane_prefix
|
|
|
|
/ "share/emane/xml/models/mac/tdmaeventscheduler/tdmabasemodelpcr.xml"
|
2019-04-08 17:49:37 +01:00
|
|
|
)
|
2019-10-23 17:51:52 +01:00
|
|
|
super().load(emane_prefix)
|
2021-11-16 00:40:30 +00:00
|
|
|
config_item = ConfigString(
|
2021-03-31 19:13:40 +01:00
|
|
|
id=cls.schedule_name,
|
2021-03-19 23:54:24 +00:00
|
|
|
default=str(cls.default_schedule),
|
|
|
|
label="TDMA schedule file (core)",
|
2019-04-08 17:49:37 +01:00
|
|
|
)
|
2021-03-19 23:54:24 +00:00
|
|
|
cls.mac_config.insert(0, config_item)
|
2019-04-08 17:49:37 +01:00
|
|
|
|
2021-05-25 20:14:28 +01:00
|
|
|
def post_startup(self, iface: CoreInterface) -> None:
|
2018-03-26 18:27:39 +01:00
|
|
|
# get configured schedule
|
2021-05-25 20:14:28 +01:00
|
|
|
emane_net = self.session.get_node(self.id, EmaneNet)
|
|
|
|
config = self.session.emane.get_iface_config(emane_net, iface)
|
2021-05-07 18:40:18 +01:00
|
|
|
schedule = Path(config[self.schedule_name])
|
|
|
|
if not schedule.is_file():
|
2021-05-25 20:14:28 +01:00
|
|
|
logger.error("ignoring invalid tdma schedule: %s", schedule)
|
2021-05-07 18:40:18 +01:00
|
|
|
return
|
2018-03-26 18:27:39 +01:00
|
|
|
# initiate tdma schedule
|
2021-05-25 20:14:28 +01:00
|
|
|
nem_id = self.session.emane.get_nem_id(iface)
|
|
|
|
if not nem_id:
|
|
|
|
logger.error("could not find nem for interface")
|
|
|
|
return
|
|
|
|
service = self.session.emane.nem_service.get(nem_id)
|
|
|
|
if service:
|
2021-05-25 05:41:05 +01:00
|
|
|
device = service.device
|
|
|
|
logger.info(
|
|
|
|
"setting up tdma schedule: schedule(%s) device(%s)", schedule, device
|
|
|
|
)
|
|
|
|
utils.cmd(f"emaneevent-tdmaschedule -i {device} {schedule}")
|