fix merge conflict
This commit is contained in:
commit
5c087141bd
86 changed files with 3313 additions and 1832 deletions
|
@ -5,6 +5,7 @@ import json
|
|||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Dict, List
|
||||
|
||||
import grpc
|
||||
|
||||
|
@ -14,11 +15,16 @@ from core.gui.dialogs.mobilityplayer import MobilityPlayer
|
|||
from core.gui.dialogs.sessions import SessionsDialog
|
||||
from core.gui.errors import show_grpc_error
|
||||
from core.gui.graph import tags
|
||||
from core.gui.graph.edges import CanvasEdge
|
||||
from core.gui.graph.node import CanvasNode
|
||||
from core.gui.graph.shape import AnnotationData, Shape
|
||||
from core.gui.graph.shapeutils import ShapeType
|
||||
from core.gui.interface import InterfaceManager
|
||||
from core.gui.nodeutils import NodeDraw, NodeUtils
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
GUI_SOURCE = "gui"
|
||||
OBSERVERS = {
|
||||
"processes": "ps",
|
||||
|
@ -34,20 +40,20 @@ OBSERVERS = {
|
|||
|
||||
|
||||
class CoreServer:
|
||||
def __init__(self, name, address, port):
|
||||
def __init__(self, name: str, address: str, port: int):
|
||||
self.name = name
|
||||
self.address = address
|
||||
self.port = port
|
||||
|
||||
|
||||
class Observer:
|
||||
def __init__(self, name, cmd):
|
||||
def __init__(self, name: str, cmd: str):
|
||||
self.name = name
|
||||
self.cmd = cmd
|
||||
|
||||
|
||||
class CoreClient:
|
||||
def __init__(self, app, proxy):
|
||||
def __init__(self, app: "Application", proxy: bool):
|
||||
"""
|
||||
Create a CoreGrpc instance
|
||||
"""
|
||||
|
@ -110,7 +116,7 @@ class CoreClient:
|
|||
self.handling_events.cancel()
|
||||
self.handling_events = None
|
||||
|
||||
def set_observer(self, value):
|
||||
def set_observer(self, value: str):
|
||||
self.observer = value
|
||||
|
||||
def read_config(self):
|
||||
|
@ -132,7 +138,7 @@ class CoreClient:
|
|||
observer = Observer(config["name"], config["cmd"])
|
||||
self.custom_observers[observer.name] = observer
|
||||
|
||||
def handle_events(self, event):
|
||||
def handle_events(self, event: core_pb2.Event):
|
||||
if event.session_id != self.session_id:
|
||||
logging.warning(
|
||||
"ignoring event session(%s) current(%s)",
|
||||
|
@ -170,7 +176,7 @@ class CoreClient:
|
|||
else:
|
||||
logging.info("unhandled event: %s", event)
|
||||
|
||||
def handle_link_event(self, event):
|
||||
def handle_link_event(self, event: core_pb2.LinkEvent):
|
||||
node_one_id = event.link.node_one_id
|
||||
node_two_id = event.link.node_two_id
|
||||
canvas_node_one = self.canvas_nodes[node_one_id]
|
||||
|
@ -183,7 +189,7 @@ class CoreClient:
|
|||
else:
|
||||
logging.warning("unknown link event: %s", event.message_type)
|
||||
|
||||
def handle_node_event(self, event):
|
||||
def handle_node_event(self, event: core_pb2.NodeEvent):
|
||||
if event.source == GUI_SOURCE:
|
||||
return
|
||||
node_id = event.node.id
|
||||
|
@ -201,7 +207,7 @@ class CoreClient:
|
|||
self.handling_throughputs.cancel()
|
||||
self.handling_throughputs = None
|
||||
|
||||
def handle_throughputs(self, event):
|
||||
def handle_throughputs(self, event: core_pb2.ThroughputsEvent):
|
||||
if event.session_id != self.session_id:
|
||||
logging.warning(
|
||||
"ignoring throughput event session(%s) current(%s)",
|
||||
|
@ -212,11 +218,11 @@ class CoreClient:
|
|||
logging.info("handling throughputs event: %s", event)
|
||||
self.app.canvas.set_throughputs(event)
|
||||
|
||||
def handle_exception_event(self, event):
|
||||
def handle_exception_event(self, event: core_pb2.ExceptionEvent):
|
||||
logging.info("exception event: %s", event)
|
||||
self.app.statusbar.core_alarms.append(event)
|
||||
|
||||
def join_session(self, session_id, query_location=True):
|
||||
def join_session(self, session_id: int, query_location: bool = True):
|
||||
# update session and title
|
||||
self.session_id = session_id
|
||||
self.master.title(f"CORE Session({self.session_id})")
|
||||
|
@ -297,10 +303,10 @@ class CoreClient:
|
|||
# update ui to represent current state
|
||||
self.app.after(0, self.app.joined_session_update)
|
||||
|
||||
def is_runtime(self):
|
||||
def is_runtime(self) -> bool:
|
||||
return self.state == core_pb2.SessionState.RUNTIME
|
||||
|
||||
def parse_metadata(self, config):
|
||||
def parse_metadata(self, config: Dict[str, str]):
|
||||
# canvas setting
|
||||
canvas_config = config.get("canvas")
|
||||
logging.info("canvas metadata: %s", canvas_config)
|
||||
|
@ -364,8 +370,6 @@ class CoreClient:
|
|||
def create_new_session(self):
|
||||
"""
|
||||
Create a new session
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
try:
|
||||
response = self.client.create_session()
|
||||
|
@ -384,7 +388,7 @@ class CoreClient:
|
|||
except grpc.RpcError as e:
|
||||
self.app.after(0, show_grpc_error, e)
|
||||
|
||||
def delete_session(self, session_id=None):
|
||||
def delete_session(self, session_id: int = None):
|
||||
if session_id is None:
|
||||
session_id = self.session_id
|
||||
try:
|
||||
|
@ -396,8 +400,6 @@ class CoreClient:
|
|||
def set_up(self):
|
||||
"""
|
||||
Query sessions, if there exist any, prompt whether to join one
|
||||
|
||||
:return: existing sessions
|
||||
"""
|
||||
try:
|
||||
self.client.connect()
|
||||
|
@ -425,7 +427,7 @@ class CoreClient:
|
|||
self.app.after(0, show_grpc_error, e)
|
||||
self.app.close()
|
||||
|
||||
def edit_node(self, core_node):
|
||||
def edit_node(self, core_node: core_pb2.Node):
|
||||
try:
|
||||
self.client.edit_node(
|
||||
self.session_id, core_node.id, core_node.position, source=GUI_SOURCE
|
||||
|
@ -433,7 +435,7 @@ class CoreClient:
|
|||
except grpc.RpcError as e:
|
||||
self.app.after(0, show_grpc_error, e)
|
||||
|
||||
def start_session(self):
|
||||
def start_session(self) -> core_pb2.StartSessionResponse:
|
||||
nodes = [x.core_node for x in self.canvas_nodes.values()]
|
||||
links = [x.link for x in self.links.values()]
|
||||
wlan_configs = self.get_wlan_configs_proto()
|
||||
|
@ -476,7 +478,7 @@ class CoreClient:
|
|||
self.app.after(0, show_grpc_error, e)
|
||||
return response
|
||||
|
||||
def stop_session(self, session_id=None):
|
||||
def stop_session(self, session_id: int = None) -> core_pb2.StartSessionResponse:
|
||||
if not session_id:
|
||||
session_id = self.session_id
|
||||
response = core_pb2.StopSessionResponse(result=False)
|
||||
|
@ -518,21 +520,19 @@ class CoreClient:
|
|||
response = self.client.set_session_metadata(self.session_id, metadata)
|
||||
logging.info("set session metadata: %s", response)
|
||||
|
||||
def launch_terminal(self, node_id):
|
||||
def launch_terminal(self, node_id: int):
|
||||
try:
|
||||
terminal = self.app.guiconfig["preferences"]["terminal"]
|
||||
response = self.client.get_node_terminal(self.session_id, node_id)
|
||||
logging.info("get terminal %s", response.terminal)
|
||||
os.system(f"{terminal} {response.terminal} &")
|
||||
cmd = f'{terminal} "{response.terminal}" &'
|
||||
logging.info("launching terminal %s", cmd)
|
||||
os.system(cmd)
|
||||
except grpc.RpcError as e:
|
||||
self.app.after(0, show_grpc_error, e)
|
||||
|
||||
def save_xml(self, file_path):
|
||||
def save_xml(self, file_path: str):
|
||||
"""
|
||||
Save core session as to an xml file
|
||||
|
||||
:param str file_path: file path that user pick
|
||||
:return: nothing
|
||||
"""
|
||||
try:
|
||||
if self.state != core_pb2.SessionState.RUNTIME:
|
||||
|
@ -545,12 +545,9 @@ class CoreClient:
|
|||
except grpc.RpcError as e:
|
||||
self.app.after(0, show_grpc_error, e)
|
||||
|
||||
def open_xml(self, file_path):
|
||||
def open_xml(self, file_path: str):
|
||||
"""
|
||||
Open core xml
|
||||
|
||||
:param str file_path: file to open
|
||||
:return: session id
|
||||
"""
|
||||
try:
|
||||
response = self.client.open_xml(file_path)
|
||||
|
@ -559,12 +556,21 @@ class CoreClient:
|
|||
except grpc.RpcError as e:
|
||||
self.app.after(0, show_grpc_error, e)
|
||||
|
||||
def get_node_service(self, node_id, service_name):
|
||||
def get_node_service(
|
||||
self, node_id: int, service_name: str
|
||||
) -> core_pb2.NodeServiceData:
|
||||
response = self.client.get_node_service(self.session_id, node_id, service_name)
|
||||
logging.debug("get node service %s", response)
|
||||
return response.service
|
||||
|
||||
def set_node_service(self, node_id, service_name, startups, validations, shutdowns):
|
||||
def set_node_service(
|
||||
self,
|
||||
node_id: int,
|
||||
service_name: str,
|
||||
startups: List[str],
|
||||
validations: List[str],
|
||||
shutdowns: List[str],
|
||||
) -> core_pb2.NodeServiceData:
|
||||
response = self.client.set_node_service(
|
||||
self.session_id, node_id, service_name, startups, validations, shutdowns
|
||||
)
|
||||
|
@ -573,14 +579,18 @@ class CoreClient:
|
|||
logging.debug("get node service : %s", response)
|
||||
return response.service
|
||||
|
||||
def get_node_service_file(self, node_id, service_name, file_name):
|
||||
def get_node_service_file(
|
||||
self, node_id: int, service_name: str, file_name: str
|
||||
) -> str:
|
||||
response = self.client.get_node_service_file(
|
||||
self.session_id, node_id, service_name, file_name
|
||||
)
|
||||
logging.debug("get service file %s", response)
|
||||
return response.data
|
||||
|
||||
def set_node_service_file(self, node_id, service_name, file_name, data):
|
||||
def set_node_service_file(
|
||||
self, node_id: int, service_name: str, file_name: str, data: bytes
|
||||
):
|
||||
response = self.client.set_node_service_file(
|
||||
self.session_id, node_id, service_name, file_name, data
|
||||
)
|
||||
|
@ -589,8 +599,6 @@ class CoreClient:
|
|||
def create_nodes_and_links(self):
|
||||
"""
|
||||
create nodes and links that have not been created yet
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
node_protos = [x.core_node for x in self.canvas_nodes.values()]
|
||||
link_protos = [x.link for x in self.links.values()]
|
||||
|
@ -617,8 +625,6 @@ class CoreClient:
|
|||
def send_data(self):
|
||||
"""
|
||||
send to daemon all session info, but don't start the session
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
self.create_nodes_and_links()
|
||||
for config_proto in self.get_wlan_configs_proto():
|
||||
|
@ -663,18 +669,13 @@ class CoreClient:
|
|||
def close(self):
|
||||
"""
|
||||
Clean ups when done using grpc
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
logging.debug("close grpc")
|
||||
self.client.close()
|
||||
|
||||
def next_node_id(self):
|
||||
def next_node_id(self) -> int:
|
||||
"""
|
||||
Get the next usable node id.
|
||||
|
||||
:return: the next id to be used
|
||||
:rtype: int
|
||||
"""
|
||||
i = 1
|
||||
while True:
|
||||
|
@ -683,15 +684,11 @@ class CoreClient:
|
|||
i += 1
|
||||
return i
|
||||
|
||||
def create_node(self, x, y, node_type, model):
|
||||
def create_node(
|
||||
self, x: int, y: int, node_type: core_pb2.NodeType, model: str
|
||||
) -> core_pb2.Node:
|
||||
"""
|
||||
Add node, with information filled in, to grpc manager
|
||||
|
||||
:param int x: x coord
|
||||
:param int y: y coord
|
||||
:param core_pb2.NodeType node_type: node type
|
||||
:param str model: node model
|
||||
:return: nothing
|
||||
"""
|
||||
node_id = self.next_node_id()
|
||||
position = core_pb2.Position(x=x, y=y)
|
||||
|
@ -726,13 +723,10 @@ class CoreClient:
|
|||
)
|
||||
return node
|
||||
|
||||
def delete_graph_nodes(self, canvas_nodes):
|
||||
def delete_graph_nodes(self, canvas_nodes: List[core_pb2.Node]):
|
||||
"""
|
||||
remove the nodes selected by the user and anything related to that node
|
||||
such as link, configurations, interfaces
|
||||
|
||||
:param list canvas_nodes: list of nodes to delete
|
||||
:return: nothing
|
||||
"""
|
||||
edges = set()
|
||||
for canvas_node in canvas_nodes:
|
||||
|
@ -754,12 +748,9 @@ class CoreClient:
|
|||
if edge in edges:
|
||||
continue
|
||||
edges.add(edge)
|
||||
#
|
||||
# if edge.token not in self.links:
|
||||
# logging.error("unknown edge: %s", edge.token)
|
||||
self.links.pop(edge.token, None)
|
||||
|
||||
def create_interface(self, canvas_node):
|
||||
def create_interface(self, canvas_node: CanvasNode) -> core_pb2.Interface:
|
||||
node = canvas_node.core_node
|
||||
ip4, ip6, prefix = self.interfaces_manager.get_ips(node.id)
|
||||
interface_id = len(canvas_node.interfaces)
|
||||
|
@ -776,16 +767,12 @@ class CoreClient:
|
|||
)
|
||||
return interface
|
||||
|
||||
def create_link(self, edge, canvas_src_node, canvas_dst_node):
|
||||
def create_link(
|
||||
self, edge: CanvasEdge, canvas_src_node: CanvasNode, canvas_dst_node: CanvasNode
|
||||
):
|
||||
"""
|
||||
Create core link for a pair of canvas nodes, with token referencing
|
||||
the canvas edge.
|
||||
|
||||
:param edge: edge for link
|
||||
:param canvas_src_node: canvas node one
|
||||
:param canvas_dst_node: canvas node two
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
src_node = canvas_src_node.core_node
|
||||
dst_node = canvas_dst_node.core_node
|
||||
|
@ -815,7 +802,7 @@ class CoreClient:
|
|||
edge.set_link(link)
|
||||
self.links[edge.token] = edge
|
||||
|
||||
def get_wlan_configs_proto(self):
|
||||
def get_wlan_configs_proto(self) -> List[core_pb2.WlanConfig]:
|
||||
configs = []
|
||||
for node_id, config in self.wlan_configs.items():
|
||||
config = {x: config[x].value for x in config}
|
||||
|
@ -823,7 +810,7 @@ class CoreClient:
|
|||
configs.append(wlan_config)
|
||||
return configs
|
||||
|
||||
def get_mobility_configs_proto(self):
|
||||
def get_mobility_configs_proto(self) -> List[core_pb2.MobilityConfig]:
|
||||
configs = []
|
||||
for node_id, config in self.mobility_configs.items():
|
||||
config = {x: config[x].value for x in config}
|
||||
|
@ -831,7 +818,7 @@ class CoreClient:
|
|||
configs.append(mobility_config)
|
||||
return configs
|
||||
|
||||
def get_emane_model_configs_proto(self):
|
||||
def get_emane_model_configs_proto(self) -> List[core_pb2.EmaneModelConfig]:
|
||||
configs = []
|
||||
for key, config in self.emane_model_configs.items():
|
||||
node_id, model, interface = key
|
||||
|
@ -844,7 +831,7 @@ class CoreClient:
|
|||
configs.append(config_proto)
|
||||
return configs
|
||||
|
||||
def get_service_configs_proto(self):
|
||||
def get_service_configs_proto(self) -> List[core_pb2.ServiceConfig]:
|
||||
configs = []
|
||||
for node_id, services in self.service_configs.items():
|
||||
for name, config in services.items():
|
||||
|
@ -858,7 +845,7 @@ class CoreClient:
|
|||
configs.append(config_proto)
|
||||
return configs
|
||||
|
||||
def get_service_file_configs_proto(self):
|
||||
def get_service_file_configs_proto(self) -> List[core_pb2.ServiceFileConfig]:
|
||||
configs = []
|
||||
for (node_id, file_configs) in self.file_configs.items():
|
||||
for service, file_config in file_configs.items():
|
||||
|
@ -869,25 +856,27 @@ class CoreClient:
|
|||
configs.append(config_proto)
|
||||
return configs
|
||||
|
||||
def run(self, node_id):
|
||||
def run(self, node_id: int) -> str:
|
||||
logging.info("running node(%s) cmd: %s", node_id, self.observer)
|
||||
return self.client.node_command(self.session_id, node_id, self.observer).output
|
||||
|
||||
def get_wlan_config(self, node_id):
|
||||
def get_wlan_config(self, node_id: int) -> Dict[str, core_pb2.ConfigOption]:
|
||||
config = self.wlan_configs.get(node_id)
|
||||
if not config:
|
||||
response = self.client.get_wlan_config(self.session_id, node_id)
|
||||
config = response.config
|
||||
return config
|
||||
|
||||
def get_mobility_config(self, node_id):
|
||||
def get_mobility_config(self, node_id: int) -> Dict[str, core_pb2.ConfigOption]:
|
||||
config = self.mobility_configs.get(node_id)
|
||||
if not config:
|
||||
response = self.client.get_mobility_config(self.session_id, node_id)
|
||||
config = response.config
|
||||
return config
|
||||
|
||||
def get_emane_model_config(self, node_id, model, interface=None):
|
||||
def get_emane_model_config(
|
||||
self, node_id: int, model: str, interface: int = None
|
||||
) -> Dict[str, core_pb2.ConfigOption]:
|
||||
logging.info("getting emane model config: %s %s %s", node_id, model, interface)
|
||||
config = self.emane_model_configs.get((node_id, model, interface))
|
||||
if not config:
|
||||
|
@ -899,15 +888,21 @@ class CoreClient:
|
|||
config = response.config
|
||||
return config
|
||||
|
||||
def set_emane_model_config(self, node_id, model, config, interface=None):
|
||||
def set_emane_model_config(
|
||||
self,
|
||||
node_id: int,
|
||||
model: str,
|
||||
config: Dict[str, core_pb2.ConfigOption],
|
||||
interface: int = None,
|
||||
):
|
||||
logging.info("setting emane model config: %s %s %s", node_id, model, interface)
|
||||
self.emane_model_configs[(node_id, model, interface)] = config
|
||||
|
||||
def copy_node_service(self, _from, _to):
|
||||
def copy_node_service(self, _from: int, _to: int):
|
||||
services = self.canvas_nodes[_from].core_node.services
|
||||
self.canvas_nodes[_to].core_node.services[:] = services
|
||||
|
||||
def copy_node_config(self, _from, _to):
|
||||
def copy_node_config(self, _from: int, _to: int):
|
||||
node_type = self.canvas_nodes[_from].core_node.type
|
||||
if node_type == core_pb2.NodeType.DEFAULT:
|
||||
services = self.canvas_nodes[_from].core_node.services
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue