Merge branch 'develop' into docker-updates

This commit is contained in:
Blake Harnden 2022-05-09 21:11:51 -07:00
commit 33f3eccdcf
10 changed files with 64 additions and 57 deletions

View file

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

View file

@ -1310,7 +1310,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
) -> WlanLinkResponse:
session = self.get_session(request.session_id, context)
wlan = self.get_node(session, request.wlan, context, WlanNode)
if not isinstance(wlan.model, BasicRangeModel):
if not isinstance(wlan.wireless_model, BasicRangeModel):
context.abort(
grpc.StatusCode.NOT_FOUND,
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)
else:
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
return WlanLinkResponse(result=result)

View file

@ -45,8 +45,6 @@ except ImportError:
EventServiceException = None
logger.debug("compatible emane python bindings not installed")
DEFAULT_EMANE_PREFIX = "/usr"
DEFAULT_DEV = "ctrl0"
DEFAULT_LOG_LEVEL: int = 3
@ -223,7 +221,7 @@ class EmaneManager:
:param iface: interface running emane
: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
key = utils.iface_config_id(iface.node.id, iface.id)
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)
# return default config values, when a config is not present
if not config:
config = emane_net.model.default_values()
config = emane_net.wireless_model.default_values()
return config
def config_reset(self, node_id: int = None) -> None:
@ -340,7 +338,7 @@ class EmaneManager:
def get_ifaces(self) -> List[Tuple[EmaneNet, TunTap]]:
ifaces = []
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)
continue
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
)
for iface in emane_net.get_ifaces():
emane_net.model.post_startup(iface)
emane_net.wireless_model.post_startup(iface)
if events_enabled:
iface.setposition()
@ -550,9 +548,11 @@ class EmaneManager:
emane_net = self._emane_nets[node_id]
logger.debug("checking emane model for node: %s", node_id)
# skip nodes that already have a model set
if emane_net.model:
if emane_net.wireless_model:
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
# 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 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.distributed import DistributedServer
@ -19,10 +19,7 @@ logger = logging.getLogger(__name__)
if TYPE_CHECKING:
from core.emane.emanemodel import EmaneModel
from core.emulator.session import Session
from core.location.mobility import WirelessModel, WayPointMobility
OptionalEmaneModel = Optional[EmaneModel]
WirelessModelType = Type[WirelessModel]
from core.location.mobility import WayPointMobility
try:
from emane.events import LocationEvent
@ -158,7 +155,7 @@ class EmaneNet(CoreNetworkBase):
) -> None:
super().__init__(session, _id, name, server)
self.conf: str = ""
self.model: "OptionalEmaneModel" = None
self.wireless_model: Optional["EmaneModel"] = None
self.mobility: Optional[WayPointMobility] = None
def linkconfig(
@ -167,9 +164,9 @@ class EmaneNet(CoreNetworkBase):
"""
The CommEffect model supports link configuration.
"""
if not self.model:
if not self.wireless_model:
return
self.model.linkconfig(iface, options, iface2)
self.wireless_model.linkconfig(iface, options, iface2)
def startup(self) -> None:
self.up = True
@ -190,20 +187,24 @@ class EmaneNet(CoreNetworkBase):
:param config: configuration to update model with
:return: nothing
"""
if not self.model:
if not self.wireless_model:
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)
self.model.update_config(config)
logger.info(
"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
"""
if model.config_type == RegisterTlvs.WIRELESS:
# EmaneModel really uses values from ConfigurableManager
# when buildnemxml() is called, not during init()
self.model = model(session=self.session, _id=self.id)
self.model.update_config(config)
self.wireless_model = model(session=self.session, _id=self.id)
self.wireless_model.update_config(config)
elif model.config_type == RegisterTlvs.MOBILITY:
self.mobility = model(session=self.session, _id=self.id)
self.mobility.update_config(config)

View file

@ -558,7 +558,7 @@ class Session:
# ensure default emane configuration
if isinstance(node, EmaneNet) and 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:
self.emane.add_node(node)
@ -1328,9 +1328,8 @@ class Session:
# use the updown script for control net 0 only.
updown_script = None
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:
logger.debug("controlnet updown script not configured")

View file

@ -627,7 +627,7 @@ class WayPointMobility(WirelessModel):
moved_ifaces.append(iface)
# 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
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
self.setnodeposition(node, x, y, z)
moved_ifaces.append(iface)
self.net.model.update(moved_ifaces)
self.net.wireless_model.update(moved_ifaces)
def addwaypoint(
self,

View file

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

View file

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

View file

@ -162,12 +162,14 @@ def build_platform_xml(
"""
# create top level platform element
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
value = config[configuration.id]
add_param(platform_element, name, value)
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
@ -177,7 +179,7 @@ def build_platform_xml(
)
# 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
if is_external(config):

View file

@ -528,7 +528,7 @@ class TestGrpc:
assert result is True
config = session.mobility.get_model_config(wlan.id, BasicRangeModel.name)
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):
# given