From 24263d77bd3a39324abc0d1e53cc8336cf11796e Mon Sep 17 00:00:00 2001 From: ahrenholz Date: Thu, 18 Sep 2014 15:50:09 +0000 Subject: [PATCH] initial XML changes for EMANE 0.9.2 for version detection, use 'emane --version' output instead of other tricks (Boeing r1880) --- daemon/core/emane/commeffect.py | 2 +- daemon/core/emane/emane.py | 83 +++++++++++++++++++-------------- daemon/core/emane/nodes.py | 14 +++--- daemon/core/emane/rfpipe.py | 2 +- daemon/core/emane/universal.py | 8 ++-- 5 files changed, 62 insertions(+), 47 deletions(-) diff --git a/daemon/core/emane/commeffect.py b/daemon/core/emane/commeffect.py index 378a14ae..e796ebd2 100755 --- a/daemon/core/emane/commeffect.py +++ b/daemon/core/emane/commeffect.py @@ -103,7 +103,7 @@ class EmaneCommEffectModel(EmaneModel): ''' Generate CommEffect events when a Link Message is received having link parameters. ''' - if self.session.emane.version == self.session.emane.EMANE091: + if self.session.emane.version >= self.session.emane.EMANE091: raise NotImplementedError, \ "CommEffect linkconfig() not implemented for EMANE 0.9.1+" def z(x): diff --git a/daemon/core/emane/emane.py b/daemon/core/emane/emane.py index 5787b1b5..56db4d93 100644 --- a/daemon/core/emane/emane.py +++ b/daemon/core/emane/emane.py @@ -15,7 +15,7 @@ from xml.dom.minidom import parseString, Document from core.constants import * from core.api import coreapi from core.misc.ipaddr import MacAddr -from core.misc.utils import maketuplefromstr +from core.misc.utils import maketuplefromstr, cmdresult from core.misc.xmlutils import addtextelementsfromtuples, addparamlisttoparent from core.conf import ConfigurableManager, Configurable from core.mobility import WirelessModel @@ -45,8 +45,8 @@ class Emane(ConfigurableManager): (SUCCESS, NOT_NEEDED, NOT_READY) = (0, 1, 2) EVENTCFGVAR = 'LIBEMANEEVENTSERVICECONFIG' # possible self.version values - (EMANE074, EMANE081, EMANE091) = (7, 8, 9) - + (EMANEUNK, EMANE074, EMANE081, EMANE091, EMANE092) = (0, 7, 8, 91, 92) + def __init__(self, session): ConfigurableManager.__init__(self, session) self.verbose = self.session.getcfgitembool('verbose', False) @@ -62,27 +62,41 @@ class Emane(ConfigurableManager): 8200) self.doeventloop = False self.eventmonthread = None - # detect between EMANE versions 0.7.4, 0.8.1, and 0.9.1+ - # to be removed as support for older EMANEs is deprecated - self.version = self.EMANE081 - try: - tmp = emaneeventlocation.EventLocation(1) - # check if yaw parameter is supported by Location Events - # if so, we have EMANE 0.8.1; if not, we have EMANE 0.7.4/earlier - tmp.set(0, 1, 2, 2, 2, 3) - except TypeError: - self.version = self.EMANE074 - except Exception: - # e.g. no Python bindings installed - pass - if 'EventService' in globals(): - self.version = self.EMANE091 + self.detectversion() # model for global EMANE configuration options self.emane_config = EmaneGlobalModel(session, None, self.verbose) session.broker.handlers += (self.handledistributed, ) self.loadmodels() self.initeventservice() + def detectversion(self): + ''' Detects the installed EMANE version and sets self.version. + ''' + self.version, self.versionstr = self.detectversionfromcmd() + if self.verbose: + self.info("detected EMANE version: %s" % self.versionstr) + + def detectversionfromcmd(self): + ''' Runs 'emane --version' locally to determine version number. + ''' + # for further study: different EMANE versions on distributed machines + try: + status, result = cmdresult(['emane', '--version']) + except OSError: + status = -1 + result = "" + v = self.EMANEUNK + if status == 0: + if result[:5] == "0.7.4": + v = self.EMANE074 + elif result[:5] == "0.8.1": + v = self.EMANE081 + elif result[:5] == "0.9.1": + v = self.EMANE091 + elif result[:5] == "0.9.2": + v = self.EMANE092 + return v, result.strip() + def initeventservice(self, filename=None): ''' (Re-)initialize the EMANE Event service. The multicast group and/or port may be configured, and can be changed via XML config file and an @@ -92,7 +106,7 @@ class Emane(ConfigurableManager): del self.service self.service = None # EMANE 0.9.1+ does not require event service XML config - if self.version == self.EMANE091: + if self.version >= self.EMANE091: values = self.getconfig(None, "emane", self.emane_config.getdefaultvalues())[1] group, port = self.emane_config.valueof('eventservicegroup', @@ -460,7 +474,7 @@ class Emane(ConfigurableManager): doc = self.xmldoc("platform") plat = doc.getElementsByTagName("platform").pop() platformid = self.emane_config.valueof("platform_id_start", values) - if self.version != self.EMANE091: + if self.version < self.EMANE091: plat.setAttribute("name", "Platform %s" % platformid) plat.setAttribute("id", platformid) @@ -477,21 +491,22 @@ class Emane(ConfigurableManager): for n in sorted(self._objs.keys()): emanenode = self._objs[n] nems = emanenode.buildplatformxmlentry(doc) - for netif in sorted(nems, key=lambda n: n.node.objid): + for netif in sorted(nems, key=lambda n: n.node.objid): # set ID, endpoints here nementry = nems[netif] nementry.setAttribute("id", "%d" % nemid) - # insert nem options (except nem id) to doc - trans_addr = self.emane_config.valueof("transportendpoint", \ - values) - nementry.insertBefore(self.xmlparam(doc, "transportendpoint", \ - "%s:%d" % (trans_addr, self.transformport)), - nementry.firstChild) - platform_addr = self.emane_config.valueof("platformendpoint", \ - values) - nementry.insertBefore(self.xmlparam(doc, "platformendpoint", \ - "%s:%d" % (platform_addr, self.platformport)), - nementry.firstChild) + if self.version < self.EMANE092: + # insert nem options (except nem id) to doc + trans_addr = self.emane_config.valueof("transportendpoint", \ + values) + nementry.insertBefore(self.xmlparam(doc, "transportendpoint", \ + "%s:%d" % (trans_addr, self.transformport)), + nementry.firstChild) + platform_addr = self.emane_config.valueof("platformendpoint", \ + values) + nementry.insertBefore(self.xmlparam(doc, "platformendpoint", \ + "%s:%d" % (platform_addr, self.platformport)), + nementry.firstChild) plat.appendChild(nementry) emanenode.setnemid(netif, nemid) # NOTE: MAC address set before here is incorrect, including the one @@ -693,7 +708,7 @@ class Emane(ConfigurableManager): # reset the service, otherwise nextEvent won't work self.initeventservice() if self.eventmonthread is not None: - if self.version == self.EMANE091: + if self.version >= self.EMANE091: self.eventmonthread._Thread__stop() self.eventmonthread.join() self.eventmonthread = None @@ -706,7 +721,7 @@ class Emane(ConfigurableManager): self.info("Subscribing to EMANE location events (not generating them). " \ "(%s) " % threading.currentThread().getName()) while self.doeventloop is True: - if self.version == self.EMANE091: + if self.version >= self.EMANE091: (uuid, seq, events) = self.service.nextEvent() if not self.doeventloop: break # this occurs with 0.9.1 event service diff --git a/daemon/core/emane/nodes.py b/daemon/core/emane/nodes.py index 33b8b233..3dbe871e 100644 --- a/daemon/core/emane/nodes.py +++ b/daemon/core/emane/nodes.py @@ -249,14 +249,14 @@ class EmaneNode(EmaneNet): self.info("setnemposition %s (%s) x,y,z=(%d,%d,%s)" "(%.6f,%.6f,%.6f)" % \ (ifname, nemid, x, y, z, lat, long, alt)) - if self.session.emane.version == self.session.emane.EMANE091: + if self.session.emane.version >= self.session.emane.EMANE091: event = LocationEvent() else: event = emaneeventlocation.EventLocation(1) # altitude must be an integer or warning is printed # unused: yaw, pitch, roll, azimuth, elevation, velocity alt = int(round(alt)) - if self.session.emane.version == self.session.emane.EMANE091: + if self.session.emane.version >= self.session.emane.EMANE091: event.append(nemid, latitude=lat, longitude=long, altitude=alt) self.session.emane.service.publish(0, event) else: @@ -278,8 +278,8 @@ class EmaneNode(EmaneNet): if self.verbose: self.info("position service not available") return - - if self.session.emane.version == self.session.emane.EMANE091: + + if self.session.emane.version >= self.session.emane.EMANE091: event = LocationEvent() else: event = emaneeventlocation.EventLocation(len(moved_netifs)) @@ -298,13 +298,13 @@ class EmaneNode(EmaneNet): (i, ifname, nemid, x, y, z, lat, long, alt)) # altitude must be an integer or warning is printed alt = int(round(alt)) - if self.session.emane.version == self.session.emane.EMANE091: + if self.session.emane.version >= self.session.emane.EMANE091: event.append(nemid, latitude=lat, longitude=long, altitude=alt) else: event.set(i, nemid, lat, long, alt) i += 1 - - if self.session.emane.version == self.session.emane.EMANE091: + + if self.session.emane.version >= self.session.emane.EMANE091: self.session.emane.service.publish(0, event) else: self.session.emane.service.publish(emaneeventlocation.EVENT_ID, diff --git a/daemon/core/emane/rfpipe.py b/daemon/core/emane/rfpipe.py index 5d383c7a..a85c6220 100644 --- a/daemon/core/emane/rfpipe.py +++ b/daemon/core/emane/rfpipe.py @@ -102,7 +102,7 @@ class EmaneRfPipeModel(EmaneModel): mac = macdoc.getElementsByTagName("mac").pop() mac.setAttribute("name", "RF-PIPE MAC") mac.setAttribute("library", "rfpipemaclayer") - if e.version != e.EMANE091 and \ + if e.version < e.EMANE091 and \ self.valueof("transmissioncontrolmap", values) is "": macnames.remove("transmissioncontrolmap") # EMANE 0.7.4 support diff --git a/daemon/core/emane/universal.py b/daemon/core/emane/universal.py index 45067a20..d0912f25 100644 --- a/daemon/core/emane/universal.py +++ b/daemon/core/emane/universal.py @@ -102,13 +102,13 @@ class EmaneUniversalModel(EmaneModel): "antennaprofilemanifesturi", "frequencyofinterestfilterenable") - + @classmethod def getphydoc(cls, e, mac, values, phynames): phydoc = e.xmldoc("phy") phy = phydoc.getElementsByTagName("phy").pop() phy.setAttribute("name", cls._xmlname) - if e.version != e.EMANE091: + if e.version < e.EMANE091: phy.setAttribute("library", cls._xmllibrary) # EMANE 0.7.4 suppport - to be removed when 0.7.4 support is deprecated if e.version == e.EMANE074: @@ -128,14 +128,14 @@ class EmaneUniversalModel(EmaneModel): phy.appendChild(e.xmlparam(phydoc, old[0], old[2])) frequencies = None - if e.version == e.EMANE091: + if e.version >= e.EMANE091: name = "frequencyofinterest" value = mac.valueof(name, values) frequencies = cls.valuestrtoparamlist(phydoc, name, value) if frequencies: phynames = list(phynames) phynames.remove("frequencyofinterest") - + # append all PHY options to phydoc map( lambda n: phy.appendChild(e.xmlparam(phydoc, n, \ mac.valueof(n, values))), phynames)