daemon: fixed naming issues with wireless/emane model attributes, fixed issue with emane controlnet updown script

This commit is contained in:
Blake Harnden 2022-05-09 21:11:14 -07:00
parent 2e4d0e0cea
commit 8ba169c758
10 changed files with 64 additions and 57 deletions

View file

@ -297,7 +297,7 @@ def get_node_proto(
channel = str(node.ctrlchnlname) channel = str(node.ctrlchnlname)
emane_model = None emane_model = None
if isinstance(node, EmaneNet): if isinstance(node, EmaneNet):
emane_model = node.model.name emane_model = node.wireless_model.name
image = None image = None
if isinstance(node, (DockerNode, LxcNode)): if isinstance(node, (DockerNode, LxcNode)):
image = node.image image = node.image

View file

@ -1310,7 +1310,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
) -> WlanLinkResponse: ) -> WlanLinkResponse:
session = self.get_session(request.session_id, context) session = self.get_session(request.session_id, context)
wlan = self.get_node(session, request.wlan, context, WlanNode) wlan = self.get_node(session, request.wlan, context, WlanNode)
if not isinstance(wlan.model, BasicRangeModel): if not isinstance(wlan.wireless_model, BasicRangeModel):
context.abort( context.abort(
grpc.StatusCode.NOT_FOUND, grpc.StatusCode.NOT_FOUND,
f"wlan node {request.wlan} is not using BasicRangeModel", f"wlan node {request.wlan} is not using BasicRangeModel",
@ -1332,7 +1332,9 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
wlan.link(node1_iface, node2_iface) wlan.link(node1_iface, node2_iface)
else: else:
wlan.unlink(node1_iface, node2_iface) wlan.unlink(node1_iface, node2_iface)
wlan.model.sendlinkmsg(node1_iface, node2_iface, unlink=not request.linked) wlan.wireless_model.sendlinkmsg(
node1_iface, node2_iface, unlink=not request.linked
)
result = True result = True
return WlanLinkResponse(result=result) return WlanLinkResponse(result=result)

View file

@ -45,8 +45,6 @@ except ImportError:
EventServiceException = None EventServiceException = None
logger.debug("compatible emane python bindings not installed") logger.debug("compatible emane python bindings not installed")
DEFAULT_EMANE_PREFIX = "/usr"
DEFAULT_DEV = "ctrl0"
DEFAULT_LOG_LEVEL: int = 3 DEFAULT_LOG_LEVEL: int = 3
@ -223,7 +221,7 @@ class EmaneManager:
:param iface: interface running emane :param iface: interface running emane
:return: net, node, or interface model configuration :return: net, node, or interface model configuration
""" """
model_name = emane_net.model.name model_name = emane_net.wireless_model.name
# try to retrieve interface specific configuration # try to retrieve interface specific configuration
key = utils.iface_config_id(iface.node.id, iface.id) key = utils.iface_config_id(iface.node.id, iface.id)
config = self.get_config(key, model_name, default=False) config = self.get_config(key, model_name, default=False)
@ -237,7 +235,7 @@ class EmaneManager:
config = self.get_config(emane_net.id, model_name, default=False) config = self.get_config(emane_net.id, model_name, default=False)
# return default config values, when a config is not present # return default config values, when a config is not present
if not config: if not config:
config = emane_net.model.default_values() config = emane_net.wireless_model.default_values()
return config return config
def config_reset(self, node_id: int = None) -> None: def config_reset(self, node_id: int = None) -> None:
@ -340,7 +338,7 @@ class EmaneManager:
def get_ifaces(self) -> List[Tuple[EmaneNet, TunTap]]: def get_ifaces(self) -> List[Tuple[EmaneNet, TunTap]]:
ifaces = [] ifaces = []
for emane_net in self._emane_nets.values(): for emane_net in self._emane_nets.values():
if not emane_net.model: if not emane_net.wireless_model:
logger.error("emane net(%s) has no model", emane_net.name) logger.error("emane net(%s) has no model", emane_net.name)
continue continue
for iface in emane_net.get_ifaces(): for iface in emane_net.get_ifaces():
@ -498,7 +496,7 @@ class EmaneManager:
"post startup for emane node: %s - %s", emane_net.id, emane_net.name "post startup for emane node: %s - %s", emane_net.id, emane_net.name
) )
for iface in emane_net.get_ifaces(): for iface in emane_net.get_ifaces():
emane_net.model.post_startup(iface) emane_net.wireless_model.post_startup(iface)
if events_enabled: if events_enabled:
iface.setposition() iface.setposition()
@ -550,9 +548,11 @@ class EmaneManager:
emane_net = self._emane_nets[node_id] emane_net = self._emane_nets[node_id]
logger.debug("checking emane model for node: %s", node_id) logger.debug("checking emane model for node: %s", node_id)
# skip nodes that already have a model set # skip nodes that already have a model set
if emane_net.model: if emane_net.wireless_model:
logger.debug( logger.debug(
"node(%s) already has model(%s)", emane_net.id, emane_net.model.name "node(%s) already has model(%s)",
emane_net.id,
emane_net.wireless_model.name,
) )
continue continue
# set model configured for node, due to legacy messaging configuration # set model configured for node, due to legacy messaging configuration

View file

@ -5,7 +5,7 @@ share the same MAC+PHY model.
import logging import logging
import time import time
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Type from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Type, Union
from core.emulator.data import InterfaceData, LinkData, LinkOptions from core.emulator.data import InterfaceData, LinkData, LinkOptions
from core.emulator.distributed import DistributedServer from core.emulator.distributed import DistributedServer
@ -19,10 +19,7 @@ logger = logging.getLogger(__name__)
if TYPE_CHECKING: if TYPE_CHECKING:
from core.emane.emanemodel import EmaneModel from core.emane.emanemodel import EmaneModel
from core.emulator.session import Session from core.emulator.session import Session
from core.location.mobility import WirelessModel, WayPointMobility from core.location.mobility import WayPointMobility
OptionalEmaneModel = Optional[EmaneModel]
WirelessModelType = Type[WirelessModel]
try: try:
from emane.events import LocationEvent from emane.events import LocationEvent
@ -158,7 +155,7 @@ class EmaneNet(CoreNetworkBase):
) -> None: ) -> None:
super().__init__(session, _id, name, server) super().__init__(session, _id, name, server)
self.conf: str = "" self.conf: str = ""
self.model: "OptionalEmaneModel" = None self.wireless_model: Optional["EmaneModel"] = None
self.mobility: Optional[WayPointMobility] = None self.mobility: Optional[WayPointMobility] = None
def linkconfig( def linkconfig(
@ -167,9 +164,9 @@ class EmaneNet(CoreNetworkBase):
""" """
The CommEffect model supports link configuration. The CommEffect model supports link configuration.
""" """
if not self.model: if not self.wireless_model:
return return
self.model.linkconfig(iface, options, iface2) self.wireless_model.linkconfig(iface, options, iface2)
def startup(self) -> None: def startup(self) -> None:
self.up = True self.up = True
@ -190,20 +187,24 @@ class EmaneNet(CoreNetworkBase):
:param config: configuration to update model with :param config: configuration to update model with
:return: nothing :return: nothing
""" """
if not self.model: if not self.wireless_model:
raise CoreError(f"no model set to update for node({self.name})") raise CoreError(f"no model set to update for node({self.name})")
logger.info("node(%s) updating model(%s): %s", self.id, self.model.name, config) logger.info(
self.model.update_config(config) "node(%s) updating model(%s): %s", self.id, self.wireless_model.name, config
)
self.wireless_model.update_config(config)
def setmodel(self, model: "WirelessModelType", config: Dict[str, str]) -> None: def setmodel(
self,
model: Union[Type["EmaneModel"], Type["WayPointMobility"]],
config: Dict[str, str],
) -> None:
""" """
set the EmaneModel associated with this node set the EmaneModel associated with this node
""" """
if model.config_type == RegisterTlvs.WIRELESS: if model.config_type == RegisterTlvs.WIRELESS:
# EmaneModel really uses values from ConfigurableManager self.wireless_model = model(session=self.session, _id=self.id)
# when buildnemxml() is called, not during init() self.wireless_model.update_config(config)
self.model = model(session=self.session, _id=self.id)
self.model.update_config(config)
elif model.config_type == RegisterTlvs.MOBILITY: elif model.config_type == RegisterTlvs.MOBILITY:
self.mobility = model(session=self.session, _id=self.id) self.mobility = model(session=self.session, _id=self.id)
self.mobility.update_config(config) self.mobility.update_config(config)

View file

@ -558,7 +558,7 @@ class Session:
# ensure default emane configuration # ensure default emane configuration
if isinstance(node, EmaneNet) and options.emane: if isinstance(node, EmaneNet) and options.emane:
model_class = self.emane.get_model(options.emane) model_class = self.emane.get_model(options.emane)
node.model = model_class(self, node.id) node.wireless_model = model_class(self, node.id)
if self.state == EventTypes.RUNTIME_STATE: if self.state == EventTypes.RUNTIME_STATE:
self.emane.add_node(node) self.emane.add_node(node)
@ -1328,9 +1328,8 @@ class Session:
# use the updown script for control net 0 only. # use the updown script for control net 0 only.
updown_script = None updown_script = None
if net_index == 0: if net_index == 0:
updown_script = self.options.get("controlnet_updown_script") updown_script = self.options.get("controlnet_updown_script") or None
if not updown_script: if not updown_script:
logger.debug("controlnet updown script not configured") logger.debug("controlnet updown script not configured")

View file

@ -627,7 +627,7 @@ class WayPointMobility(WirelessModel):
moved_ifaces.append(iface) moved_ifaces.append(iface)
# calculate all ranges after moving nodes; this saves calculations # calculate all ranges after moving nodes; this saves calculations
self.net.model.update(moved_ifaces) self.net.wireless_model.update(moved_ifaces)
# TODO: check session state # TODO: check session state
self.session.event_loop.add_event(0.001 * self.refresh_ms, self.runround) self.session.event_loop.add_event(0.001 * self.refresh_ms, self.runround)
@ -705,7 +705,7 @@ class WayPointMobility(WirelessModel):
x, y, z = self.initial[node.id].coords x, y, z = self.initial[node.id].coords
self.setnodeposition(node, x, y, z) self.setnodeposition(node, x, y, z)
moved_ifaces.append(iface) moved_ifaces.append(iface)
self.net.model.update(moved_ifaces) self.net.wireless_model.update(moved_ifaces)
def addwaypoint( def addwaypoint(
self, self,

View file

@ -25,8 +25,6 @@ if TYPE_CHECKING:
from core.emulator.session import Session from core.emulator.session import Session
from core.location.mobility import WirelessModel, WayPointMobility from core.location.mobility import WirelessModel, WayPointMobility
WirelessModelType = Type[WirelessModel]
LEARNING_DISABLED: int = 0 LEARNING_DISABLED: int = 0
@ -685,7 +683,7 @@ class WlanNode(CoreNetwork):
""" """
super().__init__(session, _id, name, server, policy) super().__init__(session, _id, name, server, policy)
# wireless and mobility models (BasicRangeModel, Ns2WaypointMobility) # wireless and mobility models (BasicRangeModel, Ns2WaypointMobility)
self.model: Optional[WirelessModel] = None self.wireless_model: Optional[WirelessModel] = None
self.mobility: Optional[WayPointMobility] = None self.mobility: Optional[WayPointMobility] = None
def startup(self) -> None: def startup(self) -> None:
@ -705,27 +703,27 @@ class WlanNode(CoreNetwork):
:return: nothing :return: nothing
""" """
super().attach(iface) super().attach(iface)
if self.model: if self.wireless_model:
iface.poshook = self.model.position_callback iface.poshook = self.wireless_model.position_callback
iface.setposition() iface.setposition()
def setmodel(self, model: "WirelessModelType", config: Dict[str, str]): def setmodel(self, wireless_model: Type["WirelessModel"], config: Dict[str, str]):
""" """
Sets the mobility and wireless model. Sets the mobility and wireless model.
:param model: wireless model to set to :param wireless_model: wireless model to set to
:param config: configuration for model being set :param config: configuration for model being set
:return: nothing :return: nothing
""" """
logger.debug("node(%s) setting model: %s", self.name, model.name) logger.debug("node(%s) setting model: %s", self.name, wireless_model.name)
if model.config_type == RegisterTlvs.WIRELESS: if wireless_model.config_type == RegisterTlvs.WIRELESS:
self.model = model(session=self.session, _id=self.id) self.wireless_model = wireless_model(session=self.session, _id=self.id)
for iface in self.get_ifaces(): for iface in self.get_ifaces():
iface.poshook = self.model.position_callback iface.poshook = self.wireless_model.position_callback
iface.setposition() iface.setposition()
self.updatemodel(config) self.updatemodel(config)
elif model.config_type == RegisterTlvs.MOBILITY: elif wireless_model.config_type == RegisterTlvs.MOBILITY:
self.mobility = model(session=self.session, _id=self.id) self.mobility = wireless_model(session=self.session, _id=self.id)
self.mobility.update_config(config) self.mobility.update_config(config)
def update_mobility(self, config: Dict[str, str]) -> None: def update_mobility(self, config: Dict[str, str]) -> None:
@ -734,12 +732,12 @@ class WlanNode(CoreNetwork):
self.mobility.update_config(config) self.mobility.update_config(config)
def updatemodel(self, config: Dict[str, str]) -> None: def updatemodel(self, config: Dict[str, str]) -> None:
if not self.model: if not self.wireless_model:
raise CoreError(f"no model set to update for node({self.name})") raise CoreError(f"no model set to update for node({self.name})")
logger.debug( logger.debug(
"node(%s) updating model(%s): %s", self.id, self.model.name, config "node(%s) updating model(%s): %s", self.id, self.wireless_model.name, config
) )
self.model.update_config(config) self.wireless_model.update_config(config)
for iface in self.get_ifaces(): for iface in self.get_ifaces():
iface.setposition() iface.setposition()
@ -750,8 +748,8 @@ class WlanNode(CoreNetwork):
:param flags: message flags :param flags: message flags
:return: list of link data :return: list of link data
""" """
if self.model: if self.wireless_model:
return self.model.links(flags) return self.wireless_model.links(flags)
else: else:
return [] return []

View file

@ -245,9 +245,14 @@ class DeviceElement(NodeElement):
class NetworkElement(NodeElement): class NetworkElement(NodeElement):
def __init__(self, session: "Session", node: NodeBase) -> None: def __init__(self, session: "Session", node: NodeBase) -> None:
super().__init__(session, node, "network") super().__init__(session, node, "network")
if isinstance(self.node, (WlanNode, EmaneNet)): if isinstance(self.node, WlanNode):
if self.node.model: if self.node.wireless_model:
add_attribute(self.element, "model", self.node.model.name) add_attribute(self.element, "model", self.node.wireless_model.name)
if self.node.mobility:
add_attribute(self.element, "mobility", self.node.mobility.name)
if isinstance(self.node, EmaneNet):
if self.node.wireless_model:
add_attribute(self.element, "model", self.node.wireless_model.name)
if self.node.mobility: if self.node.mobility:
add_attribute(self.element, "mobility", self.node.mobility.name) add_attribute(self.element, "mobility", self.node.mobility.name)
if isinstance(self.node, GreTapBridge): if isinstance(self.node, GreTapBridge):

View file

@ -162,12 +162,14 @@ def build_platform_xml(
""" """
# create top level platform element # create top level platform element
platform_element = etree.Element("platform") platform_element = etree.Element("platform")
for configuration in emane_net.model.platform_config: for configuration in emane_net.wireless_model.platform_config:
name = configuration.id name = configuration.id
value = config[configuration.id] value = config[configuration.id]
add_param(platform_element, name, value) add_param(platform_element, name, value)
add_param( add_param(
platform_element, emane_net.model.platform_controlport, f"0.0.0.0:{nem_port}" platform_element,
emane_net.wireless_model.platform_controlport,
f"0.0.0.0:{nem_port}",
) )
# build nem xml # build nem xml
@ -177,7 +179,7 @@ def build_platform_xml(
) )
# create model based xml files # create model based xml files
emane_net.model.build_xml_files(config, iface) emane_net.wireless_model.build_xml_files(config, iface)
# check if this is an external transport # check if this is an external transport
if is_external(config): if is_external(config):

View file

@ -528,7 +528,7 @@ class TestGrpc:
assert result is True assert result is True
config = session.mobility.get_model_config(wlan.id, BasicRangeModel.name) config = session.mobility.get_model_config(wlan.id, BasicRangeModel.name)
assert config[range_key] == range_value assert config[range_key] == range_value
assert wlan.model.range == int(range_value) assert wlan.wireless_model.range == int(range_value)
def test_set_emane_model_config(self, grpc_server: CoreGrpcServer): def test_set_emane_model_config(self, grpc_server: CoreGrpcServer):
# given # given