diff --git a/daemon/core/emane/emane.py b/daemon/core/emane/emane.py index b117cd0f..4fbe8f55 100644 --- a/daemon/core/emane/emane.py +++ b/daemon/core/emane/emane.py @@ -15,7 +15,8 @@ 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.xmlutils import addtextelementsfromtuples +from core.misc.utils import maketuplefromstr +from core.misc.xmlutils import addtextelementsfromtuples, addparamlisttoparent from core.conf import ConfigurableManager, Configurable from core.mobility import WirelessModel from core.emane.nodes import EmaneNode @@ -940,6 +941,20 @@ class EmaneModel(WirelessModel): warntxt = "EMANE model %s does not support link " % self._name warntxt += "configuration, dropping Link Message" self.session.warn(warntxt) + + @staticmethod + def valuestrtoparamlist(dom, name, value): + ''' Helper to convert a parameter to a paramlist. + Returns a an XML paramlist, or None if the value does not expand to + multiple values. + ''' + try: + values = maketuplefromstr(value, str) + except SyntaxError: + return None + if len(values) < 2: + return None + return addparamlisttoparent(dom, parent=None, name=name, values=values) class EmaneGlobalModel(EmaneModel): diff --git a/daemon/core/emane/universal.py b/daemon/core/emane/universal.py index 667b067b..31eea94c 100644 --- a/daemon/core/emane/universal.py +++ b/daemon/core/emane/universal.py @@ -126,10 +126,21 @@ class EmaneUniversalModel(EmaneModel): # insert old options with their default values for old in cls._confmatrix_ver074: phy.appendChild(e.xmlparam(phydoc, old[0], old[2])) + + frequencies = None + 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) + if frequencies: + phy.appendChild(frequencies) return phydoc diff --git a/daemon/core/misc/xmlutils.py b/daemon/core/misc/xmlutils.py index 5ff718c8..4783b738 100644 --- a/daemon/core/misc/xmlutils.py +++ b/daemon/core/misc/xmlutils.py @@ -113,6 +113,26 @@ def addtextparamtoparent(dom, parent, name, value): txt = dom.createTextNode(value) p.appendChild(txt) return p + +def addparamlisttoparent(dom, parent, name, values): + ''' XML helper to return a parameter list and optionally add it to the + parent element: + + + + + ''' + if values is None: + return None + p = dom.createElement("paramlist") + if parent: + parent.appendChild(p) + p.setAttribute("name", name) + for v in values: + item = dom.createElement("item") + item.setAttribute("value", str(v)) + p.appendChild(item) + return p def getoneelement(dom, name): e = dom.getElementsByTagName(name)