pass over emane code to cleanup methods and some documentation

This commit is contained in:
Blake J. Harnden 2018-03-28 13:58:49 -07:00
parent ef48052d41
commit b7327a5798
9 changed files with 356 additions and 267 deletions

View file

@ -1,5 +1,5 @@
"""
bypass.py: EMANE Bypass model for CORE
EMANE Bypass model for CORE
"""
from core.emane.emanemodel import EmaneModel
@ -9,8 +9,8 @@ from core.enumerations import ConfigDataTypes
class EmaneBypassModel(EmaneModel):
name = "emane_bypass"
config_matrix = [
("none", ConfigDataTypes.BOOL.value, "0",
"True,False", "There are no parameters for the bypass model."),
("none", ConfigDataTypes.BOOL.value, "0", "True,False",
"There are no parameters for the bypass model."),
]
# value groupings
@ -19,36 +19,55 @@ class EmaneBypassModel(EmaneModel):
def __init__(self, session, object_id=None):
EmaneModel.__init__(self, session, object_id)
def buildnemxmlfiles(self, e, ifc):
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_bypassnem.xml,
nXXemane_bypassmac.xml, nXXemane_bypassphy.xml are used.
:param core.emane.emanemanager.EmaneManager emane_manager: core emane manager
:param interface: interface for the emane node
:return: nothing
"""
values = e.getifcconfig(self.object_id, self.name, self.getdefaultvalues(), ifc)
values = emane_manager.getifcconfig(self.object_id, self.name, self.getdefaultvalues(), interface)
if values is None:
return
nemdoc = e.xmldoc("nem")
nem = nemdoc.getElementsByTagName("nem").pop()
nem.setAttribute("name", "BYPASS NEM")
e.appendtransporttonem(nemdoc, nem, self.object_id, ifc)
mactag = nemdoc.createElement("mac")
mactag.setAttribute("definition", self.macxmlname(ifc))
nem.appendChild(mactag)
phytag = nemdoc.createElement("phy")
phytag.setAttribute("definition", self.phyxmlname(ifc))
nem.appendChild(phytag)
e.xmlwrite(nemdoc, self.nemxmlname(ifc))
macdoc = e.xmldoc("mac")
mac = macdoc.getElementsByTagName("mac").pop()
mac.setAttribute("name", "BYPASS MAC")
mac.setAttribute("library", "bypassmaclayer")
e.xmlwrite(macdoc, self.macxmlname(ifc))
# retrieve xml names
nem_name = self.nem_name(interface)
mac_name = self.mac_name(interface)
phy_name = self.phy_name(interface)
phydoc = e.xmldoc("phy")
phy = phydoc.getElementsByTagName("phy").pop()
phy.setAttribute("name", "BYPASS PHY")
phy.setAttribute("library", "bypassphylayer")
e.xmlwrite(phydoc, self.phyxmlname(ifc))
# create nem document
nem_document = emane_manager.xmldoc("nem")
nem_element = nem_document.getElementsByTagName("nem").pop()
nem_element.setAttribute("name", "BYPASS NEM")
emane_manager.appendtransporttonem(nem_document, nem_element, self.object_id, interface)
# create link to mac definition
mac_element = nem_document.createElement("mac")
mac_element.setAttribute("definition", mac_name)
nem_element.appendChild(mac_element)
# create link to phy definition
phy_element = nem_document.createElement("phy")
phy_element.setAttribute("definition", phy_name)
nem_element.appendChild(phy_element)
# write nem document
emane_manager.xmlwrite(nem_document, nem_name)
# create and write mac document
mac_document = emane_manager.xmldoc("mac")
mac_element = mac_document.getElementsByTagName("mac").pop()
mac_element.setAttribute("name", "BYPASS MAC")
mac_element.setAttribute("library", "bypassmaclayer")
emane_manager.xmlwrite(mac_document, mac_name)
# create and write phy document
phy_document = emane_manager.xmldoc("phy")
phy_element = phy_document.getElementsByTagName("phy").pop()
phy_element.setAttribute("name", "BYPASS PHY")
phy_element.setAttribute("library", "bypassphylayer")
emane_manager.xmlwrite(phy_document, phy_name)