effort to consolidate logic for emane models, to avoid redundancy for defining a new model

This commit is contained in:
Blake J. Harnden 2018-03-29 13:32:06 -07:00
parent 81840e501c
commit 9ce8233bc3
7 changed files with 134 additions and 294 deletions

View file

@ -3,18 +3,16 @@ rfpipe.py: EMANE RF-PIPE model for CORE
"""
from core.emane.emanemodel import EmaneModel
from core.emane.universal import EmaneUniversalModel
from core.enumerations import ConfigDataTypes
class EmaneRfPipeModel(EmaneModel):
# model name
name = "emane_rfpipe"
xml_path = "/usr/share/emane/xml/models/mac/rfpipe"
library = "rfpipemaclayer"
# configuration parameters are
# ( "name", "type", "default", "possible-value-list", "caption")
# MAC parameters
# mac configuration
xml_path = "/usr/share/emane/xml/models/mac/rfpipe"
_config_mac = [
("datarate", ConfigDataTypes.UINT64.value, "1M", "", "data rate (bps)"),
("delay", ConfigDataTypes.FLOAT.value, "0.0", "", "transmission delay (sec)"),
@ -29,67 +27,3 @@ class EmaneRfPipeModel(EmaneModel):
("radiometricreportinterval", ConfigDataTypes.FLOAT.value, "1.0", "",
"R2RI radio metric report interval (sec)"),
]
# PHY parameters from Universal PHY
_config_phy = EmaneUniversalModel.config_matrix
config_matrix = _config_mac + _config_phy
# value groupings
config_groups = "RF-PIPE MAC Parameters:1-%d|Universal PHY Parameters:%d-%d" % (
len(_config_mac), len(_config_mac) + 1, len(config_matrix))
def __init__(self, session, object_id=None):
EmaneModel.__init__(self, session, object_id)
def build_xml_files(self, emane_manager, interface):
"""
Build the necessary nem, mac, and phy XMLs in the given path.
If an individual NEM has a nonstandard config, we need to build
that file also. Otherwise the WLAN-wide nXXemane_rfpipenem.xml,
nXXemane_rfpipemac.xml, nXXemane_rfpipephy.xml are used.
:param core.emane.emanemanager.EmaneManager emane_manager: core emane manager
:param interface: interface for the emane node
:return: nothing
"""
values = emane_manager.getifcconfig(self.object_id, self.name, self.getdefaultvalues(), interface)
if values is None:
return
# retrieve xml names
nem_name = self.nem_name(interface)
mac_name = self.mac_name(interface)
phy_name = self.phy_name(interface)
nem_document = emane_manager.xmldoc("nem")
nem_element = nem_document.getElementsByTagName("nem").pop()
nem_element.setAttribute("name", "RF-PIPE NEM")
emane_manager.appendtransporttonem(nem_document, nem_element, self.object_id, interface)
mac_element = nem_document.createElement("mac")
mac_element.setAttribute("definition", mac_name)
nem_element.appendChild(mac_element)
phy_element = nem_document.createElement("phy")
phy_element.setAttribute("definition", phy_name)
nem_element.appendChild(phy_element)
emane_manager.xmlwrite(nem_document, nem_name)
names = list(self.getnames())
mac_names = names[:len(self._config_mac)]
phy_names = names[len(self._config_mac):]
mac_document = emane_manager.xmldoc("mac")
mac_element = mac_document.getElementsByTagName("mac").pop()
mac_element.setAttribute("name", "RF-PIPE MAC")
mac_element.setAttribute("library", "rfpipemaclayer")
for name in mac_names:
value = self.valueof(name, values)
param = emane_manager.xmlparam(mac_document, name, value)
mac_element.appendChild(param)
emane_manager.xmlwrite(mac_document, mac_name)
phy_document = EmaneUniversalModel.get_phy_doc(emane_manager, self, values, phy_names)
emane_manager.xmlwrite(phy_document, phy_name)