daemon: fixed issue related to updating networks of moved nodes with multiple mobility scripts

This commit is contained in:
Blake Harnden 2020-12-09 15:43:19 -08:00
parent d824fbd1c6
commit 7308dd50ff
2 changed files with 15 additions and 27 deletions

View file

@ -12,7 +12,6 @@ from core.emulator.data import LinkOptions
from core.emulator.enumerations import ConfigDataTypes from core.emulator.enumerations import ConfigDataTypes
from core.errors import CoreError from core.errors import CoreError
from core.location.mobility import WirelessModel from core.location.mobility import WirelessModel
from core.nodes.base import CoreNode
from core.nodes.interface import CoreInterface from core.nodes.interface import CoreInterface
from core.xml import emanexml from core.xml import emanexml
@ -119,13 +118,12 @@ class EmaneModel(WirelessModel):
""" """
logging.debug("emane model(%s) has no post setup tasks", self.name) logging.debug("emane model(%s) has no post setup tasks", self.name)
def update(self, moved: List[CoreNode], moved_ifaces: List[CoreInterface]) -> None: def update(self, moved_ifaces: List[CoreInterface]) -> None:
""" """
Invoked from MobilityModel when nodes are moved; this causes Invoked from MobilityModel when nodes are moved; this causes
emane location events to be generated for the nodes in the moved emane location events to be generated for the nodes in the moved
list, making EmaneModels compatible with Ns2ScriptedMobility. list, making EmaneModels compatible with Ns2ScriptedMobility.
:param moved: moved nodes
:param moved_ifaces: interfaces that were moved :param moved_ifaces: interfaces that were moved
:return: nothing :return: nothing
""" """

View file

@ -173,24 +173,20 @@ class MobilityManager(ModelManager):
self.session.broadcast_event(event_data) self.session.broadcast_event(event_data)
def update_nets( def update_nets(
self, moved: List[CoreNode], moved_ifaces: List[CoreInterface] self, net: Union[WlanNode, EmaneNet], moved_ifaces: List[CoreInterface]
) -> None: ) -> None:
""" """
A mobility script has caused nodes in the 'moved' list to move. A mobility script has caused a set of interfaces to move for a given
Update every mobility network. This saves range calculations if the model mobility network. Update the network of the moved interfaces.
were to recalculate for each individual node movement.
:param moved: moved nodes :param net: network interfaces were moved witin
:param moved_ifaces: moved network interfaces :param moved_ifaces: moved network interfaces
:return: nothing :return: nothing
""" """
for node_id in self.nodes(): if not net.model:
try: logging.error("moved interfaces network has no model: %s", net.name)
node = get_mobility_node(self.session, node_id) return
if node.model: net.model.update(moved_ifaces)
node.model.update(moved, moved_ifaces)
except CoreError:
logging.exception("error updating mobility node")
class WirelessModel(ConfigurableOptions): class WirelessModel(ConfigurableOptions):
@ -223,11 +219,10 @@ class WirelessModel(ConfigurableOptions):
""" """
return [] return []
def update(self, moved: List[CoreNode], moved_ifaces: List[CoreInterface]) -> None: def update(self, moved_ifaces: List[CoreInterface]) -> None:
""" """
Update this wireless model. Update this wireless model.
:param moved: moved nodes
:param moved_ifaces: moved network interfaces :param moved_ifaces: moved network interfaces
:return: nothing :return: nothing
""" """
@ -369,14 +364,13 @@ class BasicRangeModel(WirelessModel):
position_callback = set_position position_callback = set_position
def update(self, moved: List[CoreNode], moved_ifaces: List[CoreInterface]) -> None: def update(self, moved_ifaces: List[CoreInterface]) -> None:
""" """
Node positions have changed without recalc. Update positions from Node positions have changed without recalc. Update positions from
node.position, then re-calculate links for those that have moved. node.position, then re-calculate links for those that have moved.
Assumes bidirectional links, with one calculation per node pair, where Assumes bidirectional links, with one calculation per node pair, where
one of the nodes has moved. one of the nodes has moved.
:param moved: moved nodes
:param moved_ifaces: moved network interfaces :param moved_ifaces: moved network interfaces
:return: nothing :return: nothing
""" """
@ -420,7 +414,6 @@ class BasicRangeModel(WirelessModel):
with self.wlan._linked_lock: with self.wlan._linked_lock:
linked = self.wlan.linked(a, b) linked = self.wlan.linked(a, b)
if d > self.range: if d > self.range:
if linked: if linked:
logging.debug("was linked, unlinking") logging.debug("was linked, unlinking")
@ -638,17 +631,15 @@ class WayPointMobility(WirelessModel):
return return
return self.run() return self.run()
# only move interfaces attached to self.wlan, or all nodenum in script? # TODO: only move interfaces attached to self.wlan, or all nodenum in script?
moved = []
moved_ifaces = [] moved_ifaces = []
for iface in self.net.get_ifaces(): for iface in self.net.get_ifaces():
node = iface.node node = iface.node
if self.movenode(node, dt): if self.movenode(node, dt):
moved.append(node)
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.session.mobility.update_nets(moved, moved_ifaces) self.session.mobility.update_nets(self.net, 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)
@ -719,7 +710,7 @@ class WayPointMobility(WirelessModel):
:return: nothing :return: nothing
""" """
moved = [] # TODO: only move interfaces attached to self.wlan, or all nodenum in script?
moved_ifaces = [] moved_ifaces = []
for iface in self.net.get_ifaces(): for iface in self.net.get_ifaces():
node = iface.node node = iface.node
@ -727,9 +718,8 @@ class WayPointMobility(WirelessModel):
continue continue
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.append(node)
moved_ifaces.append(iface) moved_ifaces.append(iface)
self.session.mobility.update_nets(moved, moved_ifaces) self.session.mobility.update_nets(self.net, moved_ifaces)
def addwaypoint( def addwaypoint(
self, self,