adding support to start the tdma schedule after emane startup
This commit is contained in:
parent
e4652f6879
commit
45f041604a
3 changed files with 58 additions and 11 deletions
|
@ -85,6 +85,7 @@ class EmaneManager(ConfigurableManager):
|
|||
self.emane_config = EmaneGlobalModel(session, None)
|
||||
session.broker.handlers.add(self.handledistributed)
|
||||
self.service = None
|
||||
self.event_device = None
|
||||
self._modelclsmap = {
|
||||
self.emane_config.name: self.emane_config
|
||||
}
|
||||
|
@ -104,8 +105,11 @@ class EmaneManager(ConfigurableManager):
|
|||
"""
|
||||
Log the installed EMANE version.
|
||||
"""
|
||||
emane_version = utils.check_cmd(["emane", "--version"])
|
||||
logger.info("using EMANE: %s", emane_version)
|
||||
try:
|
||||
emane_version = utils.check_cmd(["emane", "--version"])
|
||||
logger.info("using EMANE: %s", emane_version)
|
||||
except CoreCommandError:
|
||||
logger.info("emane is not installed")
|
||||
|
||||
def deleteeventservice(self):
|
||||
if self.service:
|
||||
|
@ -116,6 +120,7 @@ class EmaneManager(ConfigurableManager):
|
|||
if f:
|
||||
f.close()
|
||||
self.service = None
|
||||
self.event_device = None
|
||||
|
||||
def initeventservice(self, filename=None, shutdown=False):
|
||||
"""
|
||||
|
@ -130,22 +135,22 @@ class EmaneManager(ConfigurableManager):
|
|||
# Get the control network to be used for events
|
||||
values = self.getconfig(None, "emane", self.emane_config.getdefaultvalues())[1]
|
||||
group, port = self.emane_config.valueof("eventservicegroup", values).split(":")
|
||||
eventdev = self.emane_config.valueof("eventservicedevice", values)
|
||||
eventnetidx = self.session.get_control_net_index(eventdev)
|
||||
self.event_device = self.emane_config.valueof("eventservicedevice", values)
|
||||
eventnetidx = self.session.get_control_net_index(self.event_device)
|
||||
if eventnetidx < 0:
|
||||
logger.error("invalid emane event service device provided: %s", eventdev)
|
||||
logger.error("invalid emane event service device provided: %s", self.event_device)
|
||||
return False
|
||||
|
||||
# make sure the event control network is in place
|
||||
eventnet = self.session.add_remove_control_net(net_index=eventnetidx, remove=False, conf_required=False)
|
||||
if eventnet is not None:
|
||||
# direct EMANE events towards control net bridge
|
||||
eventdev = eventnet.brname
|
||||
eventchannel = (group, int(port), eventdev)
|
||||
self.event_device = eventnet.brname
|
||||
eventchannel = (group, int(port), self.event_device)
|
||||
|
||||
# disabled otachannel for event service
|
||||
# only needed for e.g. antennaprofile events xmit by models
|
||||
logger.info("Using %s for event service traffic", eventdev)
|
||||
logger.info("using %s for event service traffic", self.event_device)
|
||||
try:
|
||||
self.service = EventService(eventchannel=eventchannel, otachannel=None)
|
||||
except EventServiceException:
|
||||
|
@ -339,6 +344,7 @@ class EmaneManager(ConfigurableManager):
|
|||
for netif in emane_node.netifs():
|
||||
x, y, z = netif.node.position.get()
|
||||
emane_node.setnemposition(netif, x, y, z)
|
||||
emane_node.model.post_startup(self, netif)
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
|
|
|
@ -46,6 +46,16 @@ class EmaneModel(WirelessModel):
|
|||
"""
|
||||
return cls.configure(session.emane, config_data)
|
||||
|
||||
def post_startup(self, emane_manager, ifc):
|
||||
"""
|
||||
Logic to execute after the emane manager is finished with startup.
|
||||
|
||||
:param core.emane.emanemanager.EmaneManager emane_manager: emane manager for the session
|
||||
:param ifc: an interface for the emane node this model is tied to
|
||||
:return: nothing
|
||||
"""
|
||||
logger.info("%s has no post setup tasks: interface(%s)", ifc)
|
||||
|
||||
def buildnemxmlfiles(self, e, ifc):
|
||||
"""
|
||||
Build the necessary nem, mac, and phy XMLs in the given path.
|
||||
|
|
|
@ -2,18 +2,26 @@
|
|||
tdma.py: EMANE TDMA model bindings for CORE
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from core import constants
|
||||
from core import logger
|
||||
from core.emane.emanemodel import EmaneModel
|
||||
from core.emane.universal import EmaneUniversalModel
|
||||
from core.enumerations import ConfigDataTypes
|
||||
from core.misc import utils
|
||||
|
||||
|
||||
class EmaneTdmaModel(EmaneModel):
|
||||
# model name
|
||||
name = "emane_tdma"
|
||||
xml_path = "/usr/share/emane/xml/models/mac/tdmaeventscheduler"
|
||||
schedule_name = "schedule"
|
||||
default_schedule = os.path.join(constants.CORE_DATA_DIR, "examples", "tdma", "schedule.xml")
|
||||
|
||||
# MAC parameters
|
||||
_confmatrix_mac = [
|
||||
(schedule_name, ConfigDataTypes.STRING.value, default_schedule, "", "TDMA schedule that will be set"),
|
||||
("enablepromiscuousmode", ConfigDataTypes.BOOL.value, "0", "True,False", "enable promiscuous mode"),
|
||||
("flowcontrolenable", ConfigDataTypes.BOOL.value, "0", "On,Off", "enable traffic flow control"),
|
||||
("flowcontroltokens", ConfigDataTypes.UINT16.value, "10", "", "number of flow control tokens"),
|
||||
|
@ -49,6 +57,24 @@ class EmaneTdmaModel(EmaneModel):
|
|||
def __init__(self, session, object_id=None):
|
||||
EmaneModel.__init__(self, session, object_id)
|
||||
|
||||
def post_startup(self, emane_manager, ifc):
|
||||
"""
|
||||
Logic to execute after the emane manager is finished with startup.
|
||||
|
||||
:param core.emane.emanemanager.EmaneManager emane_manager: emane manager for the session
|
||||
:param ifc: an interface for the emane node this model is tied to
|
||||
:return: nothing
|
||||
"""
|
||||
# get configured schedule
|
||||
values = emane_manager.getifcconfig(self.object_id, self.name, self.getdefaultvalues(), ifc)
|
||||
schedule = self.valueof(EmaneTdmaModel.schedule_name, values)
|
||||
|
||||
event_device = emane_manager.event_device
|
||||
|
||||
# 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])
|
||||
|
||||
def buildnemxmlfiles(self, e, ifc):
|
||||
"""
|
||||
Build the necessary nem, mac, and phy XMLs in the given path.
|
||||
|
@ -75,15 +101,20 @@ class EmaneTdmaModel(EmaneModel):
|
|||
names = list(self.getnames())
|
||||
macnames = names[:len(self._confmatrix_mac)]
|
||||
phynames = names[len(self._confmatrix_mac):]
|
||||
# make any changes to the mac/phy names here to e.g. exclude them from
|
||||
# the XML output
|
||||
|
||||
# make any changes to the mac/phy names here to e.g. exclude them from the XML output
|
||||
macnames.remove(EmaneTdmaModel.schedule_name)
|
||||
|
||||
macdoc = e.xmldoc("mac")
|
||||
mac = macdoc.getElementsByTagName("mac").pop()
|
||||
mac.setAttribute("name", "TDMA MAC")
|
||||
mac.setAttribute("library", "tdmaeventschedulerradiomodel")
|
||||
# append MAC options to macdoc
|
||||
map(lambda n: mac.appendChild(e.xmlparam(macdoc, n, self.valueof(n, values))), macnames)
|
||||
for name in macnames:
|
||||
value = self.valueof(name, values)
|
||||
param = e.xmlparam(macdoc, name, value)
|
||||
mac.appendChild(param)
|
||||
|
||||
e.xmlwrite(macdoc, self.macxmlname(ifc))
|
||||
|
||||
phydoc = EmaneUniversalModel.getphydoc(e, self, values, phynames)
|
||||
|
|
Loading…
Reference in a new issue