daemon: further heavy cleanup to how emane generates and runs xml files

This commit is contained in:
Blake Harnden 2020-07-02 17:49:56 -07:00
parent bd48e14348
commit ce4b61d3b2
5 changed files with 103 additions and 179 deletions

View file

@ -12,7 +12,6 @@ from core.config import ConfigGroup, Configuration
from core.emane import emanemanifest, emanemodel
from core.emane.nodes import EmaneNet
from core.emulator.data import LinkOptions
from core.emulator.enumerations import TransportType
from core.nodes.interface import CoreInterface
from core.xml import emanexml
@ -73,26 +72,16 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
:param iface: interface for the emane node
:return: nothing
"""
# interface node
node = iface.node
# retrieve xml names
nem_name = emanexml.nem_file_name(iface)
shim_name = emanexml.shim_file_name(iface)
# create and write nem document
nem_element = etree.Element("nem", name=f"{self.name} NEM", type="unstructured")
transport_type = TransportType.VIRTUAL
if iface.transport_type == TransportType.RAW:
transport_type = TransportType.RAW
transport_file = emanexml.transport_file_name(iface, transport_type)
etree.SubElement(nem_element, "transport", definition=transport_file)
transport_name = emanexml.transport_file_name(iface)
etree.SubElement(nem_element, "transport", definition=transport_name)
# set shim configuration
nem_name = emanexml.nem_file_name(iface)
shim_name = emanexml.shim_file_name(iface)
etree.SubElement(nem_element, "shim", definition=shim_name)
nem_file = os.path.join(node.nodedir, nem_name)
emanexml.create_file(nem_element, "nem", nem_file)
emanexml.create_iface_file(iface, nem_element, "nem", nem_name)
# create and write shim document
shim_element = etree.Element(
@ -111,9 +100,10 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
ff = config["filterfile"]
if ff.strip() != "":
emanexml.add_param(shim_element, "filterfile", ff)
emanexml.create_iface_file(iface, shim_element, "shim", shim_name)
shim_file = os.path.join(node.nodedir, shim_name)
emanexml.create_file(shim_element, "shim", shim_file)
# create transport xml
emanexml.create_transport_xml(iface, config)
def linkconfig(
self, iface: CoreInterface, options: LinkOptions, iface2: CoreInterface = None

View file

@ -281,8 +281,6 @@ class EmaneManager(ModelManager):
instantiation
"""
logging.debug("emane setup")
# TODO: drive this from the session object
with self.session.nodes_lock:
for node_id in self.session.nodes:
node = self.session.nodes[node_id]
@ -291,7 +289,6 @@ class EmaneManager(ModelManager):
"adding emane node: id(%s) name(%s)", node.id, node.name
)
self.add_node(node)
if not self._emane_nets:
logging.debug("no emane nodes in session")
return EmaneState.NOT_NEEDED
@ -322,7 +319,7 @@ class EmaneManager(ModelManager):
logging.debug("emane event service device index: %s", netidx)
if netidx < 0:
logging.error(
"EMANE cannot start, check core config. invalid event service device: %s",
"emane cannot start due to invalid event service device: %s",
eventdev,
)
return EmaneState.NOT_READY
@ -330,7 +327,6 @@ class EmaneManager(ModelManager):
self.session.add_remove_control_net(
net_index=netidx, remove=False, conf_required=False
)
self.check_node_models()
return EmaneState.SUCCESS
@ -349,10 +345,6 @@ class EmaneManager(ModelManager):
self.starteventmonitor()
self.buildeventservicexml()
with self._emane_node_lock:
# on master, control network bridge added earlier in startup()
control_net = self.session.add_remove_control_net(
0, remove=False, conf_required=False
)
logging.info("emane building xmls...")
for node_id in sorted(self._emane_nets):
emane_net = self._emane_nets[node_id]
@ -360,25 +352,31 @@ class EmaneManager(ModelManager):
logging.error("emane net(%s) has no model", emane_net.name)
continue
for iface in emane_net.get_ifaces():
if not iface.node:
logging.error(
"emane net(%s) connected interface missing node",
emane_net.name,
)
continue
nem_id = self.next_nem_id()
self.nems[nem_id] = iface
self.write_nem(iface, nem_id)
emanexml.build_platform_xml(
self, control_net, emane_net, iface, nem_id
)
emanexml.build_model_xmls(self, emane_net, iface)
self.start_daemon(iface)
self.install_iface(emane_net, iface)
self.start_iface(emane_net, iface)
if self.links_enabled():
self.link_monitor.start()
return EmaneState.SUCCESS
def start_iface(self, emane_net: EmaneNet, iface: CoreInterface) -> None:
if not iface.node:
logging.error(
"emane net(%s) connected interface(%s) missing node",
emane_net.name,
iface.name,
)
return
control_net = self.session.add_remove_control_net(
0, remove=False, conf_required=False
)
nem_id = self.next_nem_id()
self.nems[nem_id] = iface
self.write_nem(iface, nem_id)
emanexml.build_platform_xml(self, control_net, emane_net, iface, nem_id)
config = self.get_iface_config(emane_net, iface)
emane_net.model.build_xml_files(config, iface)
self.start_daemon(iface)
self.install_iface(emane_net, iface)
def write_nem(self, iface: CoreInterface, nem_id: int) -> None:
path = os.path.join(self.session.session_dir, "emane_nems")
try:

View file

@ -9,7 +9,7 @@ from core.config import ConfigGroup, Configuration
from core.emane import emanemanifest
from core.emane.nodes import EmaneNet
from core.emulator.data import LinkOptions
from core.emulator.enumerations import ConfigDataTypes, TransportType
from core.emulator.enumerations import ConfigDataTypes
from core.errors import CoreError
from core.location.mobility import WirelessModel
from core.nodes.base import CoreNode
@ -102,34 +102,14 @@ class EmaneModel(WirelessModel):
both mac.xml and phy.xml definitions.
:param config: emane model configuration for the node and interface
:param iface: interface for the emane node
:param iface: interface to run emane for
:return: nothing
"""
nem_name = emanexml.nem_file_name(iface)
mac_name = emanexml.mac_file_name(iface)
phy_name = emanexml.phy_file_name(iface)
# check if this is external
transport_type = TransportType.VIRTUAL
if iface.transport_type == TransportType.RAW:
transport_type = TransportType.RAW
transport_name = emanexml.transport_file_name(iface, transport_type)
node = iface.node
server = node.server
# create nem xml file
nem_file = os.path.join(node.nodedir, nem_name)
emanexml.create_nem_xml(
self, config, nem_file, transport_name, mac_name, phy_name, server
)
# create mac xml file
mac_file = os.path.join(node.nodedir, mac_name)
emanexml.create_mac_xml(self, config, mac_file, server)
# create phy xml file
phy_file = os.path.join(node.nodedir, phy_name)
emanexml.create_phy_xml(self, config, phy_file, server)
# create nem, mac, and phy xml files
emanexml.create_nem_xml(self, iface, config)
emanexml.create_mac_xml(self, iface, config)
emanexml.create_phy_xml(self, iface, config)
emanexml.create_transport_xml(iface, config)
def post_startup(self) -> None:
"""

View file

@ -96,7 +96,6 @@ class EmaneNet(CoreNetworkBase):
"""
set the EmaneModel associated with this node
"""
logging.info("adding model: %s", model.name)
if model.config_type == RegisterTlvs.WIRELESS:
# EmaneModel really uses values from ConfigurableManager
# when buildnemxml() is called, not during init()