cleaned up broadcast_node to use nodes directly
This commit is contained in:
parent
fd7db64f6d
commit
33bcc24d88
8 changed files with 39 additions and 84 deletions
|
@ -721,8 +721,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
if request.source:
|
if request.source:
|
||||||
source = request.source
|
source = request.source
|
||||||
if not has_geo:
|
if not has_geo:
|
||||||
node_data = node.data(source=source)
|
session.broadcast_node(node, source=source)
|
||||||
session.broadcast_node(node_data)
|
|
||||||
except CoreError:
|
except CoreError:
|
||||||
result = False
|
result = False
|
||||||
return core_pb2.EditNodeResponse(result=result)
|
return core_pb2.EditNodeResponse(result=result)
|
||||||
|
|
|
@ -1836,24 +1836,16 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
||||||
Return API messages that describe the current session.
|
Return API messages that describe the current session.
|
||||||
"""
|
"""
|
||||||
# find all nodes and links
|
# find all nodes and links
|
||||||
|
|
||||||
nodes_data = []
|
|
||||||
links_data = []
|
links_data = []
|
||||||
with self.session._nodes_lock:
|
with self.session._nodes_lock:
|
||||||
for node_id in self.session.nodes:
|
for node_id in self.session.nodes:
|
||||||
node = self.session.nodes[node_id]
|
node = self.session.nodes[node_id]
|
||||||
node_data = node.data(message_type=MessageFlags.ADD)
|
self.session.broadcast_node(node, MessageFlags.ADD)
|
||||||
if node_data:
|
|
||||||
nodes_data.append(node_data)
|
|
||||||
|
|
||||||
node_links = node.all_link_data(flags=MessageFlags.ADD)
|
node_links = node.all_link_data(flags=MessageFlags.ADD)
|
||||||
for link_data in node_links:
|
for link_data in node_links:
|
||||||
links_data.append(link_data)
|
links_data.append(link_data)
|
||||||
|
|
||||||
# send all nodes first, so that they will exist for any links
|
|
||||||
for node_data in nodes_data:
|
|
||||||
self.session.broadcast_node(node_data)
|
|
||||||
|
|
||||||
for link_data in links_data:
|
for link_data in links_data:
|
||||||
self.session.broadcast_link(link_data)
|
self.session.broadcast_link(link_data)
|
||||||
|
|
||||||
|
@ -1960,8 +1952,9 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
||||||
)
|
)
|
||||||
self.session.broadcast_config(config_data)
|
self.session.broadcast_config(config_data)
|
||||||
|
|
||||||
|
node_count = self.session.get_node_count()
|
||||||
logging.info(
|
logging.info(
|
||||||
"informed GUI about %d nodes and %d links", len(nodes_data), len(links_data)
|
"informed GUI about %d nodes and %d links", node_count, len(links_data)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -806,8 +806,7 @@ class EmaneManager(ModelManager):
|
||||||
# don"t use node.setposition(x,y,z) which generates an event
|
# don"t use node.setposition(x,y,z) which generates an event
|
||||||
node.position.set(x, y, z)
|
node.position.set(x, y, z)
|
||||||
node.position.set_geo(lon, lat, alt)
|
node.position.set_geo(lon, lat, alt)
|
||||||
node_data = node.data(lat=lat, lon=lon, alt=alt)
|
self.session.broadcast_node(node)
|
||||||
self.session.broadcast_node(node_data)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def emanerunning(self, node: CoreNode) -> bool:
|
def emanerunning(self, node: CoreNode) -> bool:
|
||||||
|
|
|
@ -17,14 +17,7 @@ from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type
|
||||||
from core import constants, utils
|
from core import constants, utils
|
||||||
from core.emane.emanemanager import EmaneManager
|
from core.emane.emanemanager import EmaneManager
|
||||||
from core.emane.nodes import EmaneNet
|
from core.emane.nodes import EmaneNet
|
||||||
from core.emulator.data import (
|
from core.emulator.data import ConfigData, EventData, ExceptionData, FileData, LinkData
|
||||||
ConfigData,
|
|
||||||
EventData,
|
|
||||||
ExceptionData,
|
|
||||||
FileData,
|
|
||||||
LinkData,
|
|
||||||
NodeData,
|
|
||||||
)
|
|
||||||
from core.emulator.distributed import DistributedController
|
from core.emulator.distributed import DistributedController
|
||||||
from core.emulator.emudata import (
|
from core.emulator.emudata import (
|
||||||
IdGen,
|
IdGen,
|
||||||
|
@ -34,7 +27,13 @@ from core.emulator.emudata import (
|
||||||
create_interface,
|
create_interface,
|
||||||
link_config,
|
link_config,
|
||||||
)
|
)
|
||||||
from core.emulator.enumerations import EventTypes, ExceptionLevels, LinkTypes, NodeTypes
|
from core.emulator.enumerations import (
|
||||||
|
EventTypes,
|
||||||
|
ExceptionLevels,
|
||||||
|
LinkTypes,
|
||||||
|
MessageFlags,
|
||||||
|
NodeTypes,
|
||||||
|
)
|
||||||
from core.emulator.sessionconfig import SessionConfig
|
from core.emulator.sessionconfig import SessionConfig
|
||||||
from core.errors import CoreError
|
from core.errors import CoreError
|
||||||
from core.location.event import EventLoop
|
from core.location.event import EventLoop
|
||||||
|
@ -805,35 +804,13 @@ class Session:
|
||||||
using_lat_lon_alt = has_empty_position and has_lat_lon_alt
|
using_lat_lon_alt = has_empty_position and has_lat_lon_alt
|
||||||
if using_lat_lon_alt:
|
if using_lat_lon_alt:
|
||||||
x, y, _ = self.location.getxyz(lat, lon, alt)
|
x, y, _ = self.location.getxyz(lat, lon, alt)
|
||||||
node.position.set_geo(lon, lat, alt)
|
|
||||||
|
|
||||||
# set position and broadcast
|
|
||||||
if None not in [x, y]:
|
|
||||||
node.setposition(x, y, None)
|
node.setposition(x, y, None)
|
||||||
|
node.position.set_geo(lon, lat, alt)
|
||||||
# broadcast updated location when using lat/lon/alt
|
self.broadcast_node(node)
|
||||||
if using_lat_lon_alt:
|
else:
|
||||||
self.broadcast_node_location(node, lon, lat, alt)
|
if has_empty_position:
|
||||||
|
x, y = 0, 0
|
||||||
def broadcast_node_location(
|
node.setposition(x, y, None)
|
||||||
self, node: NodeBase, lon: float, lat: float, alt: float
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
Broadcast node location to all listeners.
|
|
||||||
|
|
||||||
:param node: node to broadcast location for
|
|
||||||
:return: nothing
|
|
||||||
"""
|
|
||||||
node_data = NodeData(
|
|
||||||
message_type=0,
|
|
||||||
id=node.id,
|
|
||||||
x_position=node.position.x,
|
|
||||||
y_position=node.position.y,
|
|
||||||
latitude=lat,
|
|
||||||
longitude=lon,
|
|
||||||
altitude=alt,
|
|
||||||
)
|
|
||||||
self.broadcast_node(node_data)
|
|
||||||
|
|
||||||
def start_mobility(self, node_ids: List[int] = None) -> None:
|
def start_mobility(self, node_ids: List[int] = None) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -1026,14 +1003,23 @@ class Session:
|
||||||
for handler in self.exception_handlers:
|
for handler in self.exception_handlers:
|
||||||
handler(exception_data)
|
handler(exception_data)
|
||||||
|
|
||||||
def broadcast_node(self, node_data: NodeData) -> None:
|
def broadcast_node(
|
||||||
|
self,
|
||||||
|
node: NodeBase,
|
||||||
|
message_type: MessageFlags = MessageFlags.NONE,
|
||||||
|
source: str = None,
|
||||||
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Handle node data that should be provided to node handlers.
|
Handle node data that should be provided to node handlers.
|
||||||
|
|
||||||
:param node_data: node data to send out
|
:param node: node to broadcast
|
||||||
|
:param message_type: type of message to broadcast, None by default
|
||||||
|
:param source: source of broadcast, None by default
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
|
node_data = node.data(message_type, source)
|
||||||
|
if not node_data:
|
||||||
|
return
|
||||||
for handler in self.node_handlers:
|
for handler in self.node_handlers:
|
||||||
handler(node_data)
|
handler(node_data)
|
||||||
|
|
||||||
|
|
|
@ -812,8 +812,7 @@ class WayPointMobility(WirelessModel):
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
node.position.set(x, y, z)
|
node.position.set(x, y, z)
|
||||||
node_data = node.data()
|
self.session.broadcast_node(node)
|
||||||
self.session.broadcast_node(node_data)
|
|
||||||
|
|
||||||
def setendtime(self) -> None:
|
def setendtime(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -192,20 +192,12 @@ class NodeBase:
|
||||||
return ifindex
|
return ifindex
|
||||||
|
|
||||||
def data(
|
def data(
|
||||||
self,
|
self, message_type: MessageFlags = MessageFlags.NONE, source: str = None
|
||||||
message_type: MessageFlags = MessageFlags.NONE,
|
|
||||||
lat: float = None,
|
|
||||||
lon: float = None,
|
|
||||||
alt: float = None,
|
|
||||||
source: str = None,
|
|
||||||
) -> NodeData:
|
) -> NodeData:
|
||||||
"""
|
"""
|
||||||
Build a data object for this node.
|
Build a data object for this node.
|
||||||
|
|
||||||
:param message_type: purpose for the data object we are creating
|
:param message_type: purpose for the data object we are creating
|
||||||
:param lat: latitude
|
|
||||||
:param lon: longitude
|
|
||||||
:param alt: altitude
|
|
||||||
:param source: source of node data
|
:param source: source of node data
|
||||||
:return: node data object
|
:return: node data object
|
||||||
"""
|
"""
|
||||||
|
@ -217,12 +209,10 @@ class NodeBase:
|
||||||
server = None
|
server = None
|
||||||
if self.server is not None:
|
if self.server is not None:
|
||||||
server = self.server.name
|
server = self.server.name
|
||||||
|
|
||||||
services = self.services
|
services = self.services
|
||||||
if services is not None:
|
if services is not None:
|
||||||
services = "|".join([service.name for service in services])
|
services = "|".join([service.name for service in services])
|
||||||
|
return NodeData(
|
||||||
node_data = NodeData(
|
|
||||||
message_type=message_type,
|
message_type=message_type,
|
||||||
id=self.id,
|
id=self.id,
|
||||||
node_type=self.apitype,
|
node_type=self.apitype,
|
||||||
|
@ -233,17 +223,15 @@ class NodeBase:
|
||||||
opaque=self.opaque,
|
opaque=self.opaque,
|
||||||
x_position=x,
|
x_position=x,
|
||||||
y_position=y,
|
y_position=y,
|
||||||
latitude=lat,
|
latitude=self.position.lat,
|
||||||
longitude=lon,
|
longitude=self.position.lon,
|
||||||
altitude=alt,
|
altitude=self.position.alt,
|
||||||
model=model,
|
model=model,
|
||||||
server=server,
|
server=server,
|
||||||
services=services,
|
services=services,
|
||||||
source=source,
|
source=source,
|
||||||
)
|
)
|
||||||
|
|
||||||
return node_data
|
|
||||||
|
|
||||||
def all_link_data(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]:
|
def all_link_data(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]:
|
||||||
"""
|
"""
|
||||||
Build CORE Link data for this object. There is no default
|
Build CORE Link data for this object. There is no default
|
||||||
|
|
|
@ -879,21 +879,13 @@ class PtpNet(CoreNetwork):
|
||||||
super().attach(netif)
|
super().attach(netif)
|
||||||
|
|
||||||
def data(
|
def data(
|
||||||
self,
|
self, message_type: MessageFlags = MessageFlags.NONE, source: str = None
|
||||||
message_type: int,
|
|
||||||
lat: float = None,
|
|
||||||
lon: float = None,
|
|
||||||
alt: float = None,
|
|
||||||
source: str = None,
|
|
||||||
) -> NodeData:
|
) -> NodeData:
|
||||||
"""
|
"""
|
||||||
Do not generate a Node Message for point-to-point links. They are
|
Do not generate a Node Message for point-to-point links. They are
|
||||||
built using a link message instead.
|
built using a link message instead.
|
||||||
|
|
||||||
:param message_type: purpose for the data object we are creating
|
:param message_type: purpose for the data object we are creating
|
||||||
:param lat: latitude
|
|
||||||
:param lon: longitude
|
|
||||||
:param alt: altitude
|
|
||||||
:param source: source of node data
|
:param source: source of node data
|
||||||
:return: node data object
|
:return: node data object
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -982,7 +982,6 @@ class TestGrpc:
|
||||||
client = CoreGrpcClient()
|
client = CoreGrpcClient()
|
||||||
session = grpc_server.coreemu.create_session()
|
session = grpc_server.coreemu.create_session()
|
||||||
node = session.add_node()
|
node = session.add_node()
|
||||||
node_data = node.data()
|
|
||||||
queue = Queue()
|
queue = Queue()
|
||||||
|
|
||||||
def handle_event(event_data):
|
def handle_event(event_data):
|
||||||
|
@ -994,7 +993,7 @@ class TestGrpc:
|
||||||
with client.context_connect():
|
with client.context_connect():
|
||||||
client.events(session.id, handle_event)
|
client.events(session.id, handle_event)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
session.broadcast_node(node_data)
|
session.broadcast_node(node)
|
||||||
|
|
||||||
# then
|
# then
|
||||||
queue.get(timeout=5)
|
queue.get(timeout=5)
|
||||||
|
|
Loading…
Add table
Reference in a new issue