changes to support nodes containing their configurations, starting with emane, making copying easier and reducing code

This commit is contained in:
Blake Harnden 2020-04-21 00:38:36 -07:00
parent 54eab4576d
commit bd30d0d9ff
5 changed files with 60 additions and 68 deletions

View file

@ -92,7 +92,6 @@ class CoreClient:
self.hooks = {} self.hooks = {}
self.wlan_configs = {} self.wlan_configs = {}
self.mobility_configs = {} self.mobility_configs = {}
self.emane_model_configs = {}
self.emane_config = None self.emane_config = None
self.service_configs = {} self.service_configs = {}
self.config_service_configs = {} self.config_service_configs = {}
@ -130,7 +129,6 @@ class CoreClient:
self.hooks.clear() self.hooks.clear()
self.wlan_configs.clear() self.wlan_configs.clear()
self.mobility_configs.clear() self.mobility_configs.clear()
self.emane_model_configs.clear()
self.emane_config = None self.emane_config = None
self.service_configs.clear() self.service_configs.clear()
self.file_configs.clear() self.file_configs.clear()
@ -303,25 +301,29 @@ class CoreClient:
for hook in response.hooks: for hook in response.hooks:
self.hooks[hook.file] = hook self.hooks[hook.file] = hook
# get emane config
response = self.client.get_emane_config(self.session_id)
self.emane_config = response.config
# draw session
self.app.canvas.reset_and_redraw(session)
# get mobility configs # get mobility configs
response = self.client.get_mobility_configs(self.session_id) response = self.client.get_mobility_configs(self.session_id)
for node_id in response.configs: for node_id in response.configs:
node_config = response.configs[node_id].config node_config = response.configs[node_id].config
self.mobility_configs[node_id] = node_config self.mobility_configs[node_id] = node_config
# get emane config
response = self.client.get_emane_config(self.session_id)
self.emane_config = response.config
# get emane model config # get emane model config
response = self.client.get_emane_model_configs(self.session_id) response = self.client.get_emane_model_configs(self.session_id)
for config in response.configs: for config in response.configs:
interface = None interface = None
if config.interface != -1: if config.interface != -1:
interface = config.interface interface = config.interface
self.set_emane_model_config( canvas_node = self.canvas_nodes[config.node_id]
config.node_id, config.model, config.config, interface canvas_node.emane_model_configs[
) (config.model, interface)
] = config.config
# get wlan configurations # get wlan configurations
response = self.client.get_wlan_configs(self.session_id) response = self.client.get_wlan_configs(self.session_id)
@ -353,13 +355,9 @@ class CoreClient:
if config.config: if config.config:
service_config["config"] = config.config service_config["config"] = config.config
# draw session
self.app.canvas.reset_and_redraw(session)
# get metadata # get metadata
response = self.client.get_session_metadata(self.session_id) response = self.client.get_session_metadata(self.session_id)
self.parse_metadata(response.config) self.parse_metadata(response.config)
except grpc.RpcError as e: except grpc.RpcError as e:
self.app.after(0, show_grpc_error, e, self.app, self.app) self.app.after(0, show_grpc_error, e, self.app, self.app)
@ -848,10 +846,6 @@ class CoreClient:
del self.mobility_configs[node_id] del self.mobility_configs[node_id]
if node_id in self.wlan_configs: if node_id in self.wlan_configs:
del self.wlan_configs[node_id] del self.wlan_configs[node_id]
for key in list(self.emane_model_configs):
node_id, _, _ = key
if node_id == node_id:
del self.emane_model_configs[key]
for edge in canvas_node.edges: for edge in canvas_node.edges:
if edge in edges: if edge in edges:
@ -938,15 +932,19 @@ class CoreClient:
def get_emane_model_configs_proto(self) -> List[EmaneModelConfig]: def get_emane_model_configs_proto(self) -> List[EmaneModelConfig]:
configs = [] configs = []
for key, config in self.emane_model_configs.items(): for canvas_node in self.canvas_nodes.values():
node_id, model, interface = key if canvas_node.core_node.type != core_pb2.NodeType.EMANE:
config = {x: config[x].value for x in config} continue
if interface is None: node_id = canvas_node.core_node.id
interface = -1 for key, config in canvas_node.emane_model_configs.items():
config_proto = EmaneModelConfig( model, interface = key
node_id=node_id, interface_id=interface, model=model, config=config config = {x: config[x].value for x in config}
) if interface is None:
configs.append(config_proto) interface = -1
config_proto = EmaneModelConfig(
node_id=node_id, interface_id=interface, model=model, config=config
)
configs.append(config_proto)
return configs return configs
def get_service_configs_proto(self) -> List[ServiceConfig]: def get_service_configs_proto(self) -> List[ServiceConfig]:
@ -1023,14 +1021,12 @@ class CoreClient:
def get_emane_model_config( def get_emane_model_config(
self, node_id: int, model: str, interface: int = None self, node_id: int, model: str, interface: int = None
) -> Dict[str, common_pb2.ConfigOption]: ) -> Dict[str, common_pb2.ConfigOption]:
config = self.emane_model_configs.get((node_id, model, interface)) if interface is None:
if not config: interface = -1
if interface is None: response = self.client.get_emane_model_config(
interface = -1 self.session_id, node_id, model, interface
response = self.client.get_emane_model_config( )
self.session_id, node_id, model, interface config = response.config
)
config = response.config
logging.debug( logging.debug(
"get emane model config: node id: %s, EMANE model: %s, interface: %s, config: %s", "get emane model config: node id: %s, EMANE model: %s, interface: %s, config: %s",
node_id, node_id,
@ -1038,23 +1034,7 @@ class CoreClient:
interface, interface,
config, config,
) )
return config return dict(config)
def set_emane_model_config(
self,
node_id: int,
model: str,
config: Dict[str, common_pb2.ConfigOption],
interface: int = None,
):
logging.info(
"set emane model config: node id: %s, EMANE Model: %s, interface: %s, config: %s",
node_id,
model,
interface,
config,
)
self.emane_model_configs[(node_id, model, interface)] = config
def copy_node_service(self, _from: int, _to: int): def copy_node_service(self, _from: int, _to: int):
services = self.canvas_nodes[_from].core_node.services services = self.canvas_nodes[_from].core_node.services
@ -1083,10 +1063,6 @@ class CoreClient:
config = self.mobility_configs.get(src_node.id) config = self.mobility_configs.get(src_node.id)
if config: if config:
self.mobility_configs[dst_id] = config self.mobility_configs[dst_id] = config
elif node_type == core_pb2.NodeType.EMANE:
config = self.emane_model_configs.get(src_node.id)
if config:
self.emane_model_configs[dst_id] = config
def service_been_modified(self, node_id: int) -> bool: def service_been_modified(self, node_id: int) -> bool:
return node_id in self.modified_service_nodes return node_id in self.modified_service_nodes

View file

@ -8,7 +8,6 @@ from typing import TYPE_CHECKING, Any
import grpc import grpc
from core.api.grpc import core_pb2
from core.gui.dialogs.dialog import Dialog from core.gui.dialogs.dialog import Dialog
from core.gui.errors import show_grpc_error from core.gui.errors import show_grpc_error
from core.gui.images import ImageEnum, Images from core.gui.images import ImageEnum, Images
@ -56,20 +55,30 @@ class EmaneModelDialog(Dialog):
self, self,
master: Any, master: Any,
app: "Application", app: "Application",
node: core_pb2.Node, canvas_node: "CanvasNode",
model: str, model: str,
interface: int = None, interface: int = None,
): ):
super().__init__(master, app, f"{node.name} {model} Configuration", modal=True) super().__init__(
self.node = node master,
app,
f"{canvas_node.core_node.name} {model} Configuration",
modal=True,
)
self.canvas_node = canvas_node
self.node = canvas_node.core_node
self.model = f"emane_{model}" self.model = f"emane_{model}"
self.interface = interface self.interface = interface
self.config_frame = None self.config_frame = None
self.has_error = False self.has_error = False
try: try:
self.config = self.app.core.get_emane_model_config( self.config = self.canvas_node.emane_model_configs.get(
self.node.id, self.model, self.interface (self.model, self.interface)
) )
if not self.config:
self.config = self.app.core.get_emane_model_config(
self.node.id, self.model, self.interface
)
self.draw() self.draw()
except grpc.RpcError as e: except grpc.RpcError as e:
show_grpc_error(e, self.app, self.app) show_grpc_error(e, self.app, self.app)
@ -98,9 +107,8 @@ class EmaneModelDialog(Dialog):
def click_apply(self): def click_apply(self):
self.config_frame.parse_config() self.config_frame.parse_config()
self.app.core.set_emane_model_config( key = (self.model, self.interface)
self.node.id, self.model, self.config, self.interface self.canvas_node.emane_model_configs[key] = dict(self.config)
)
self.destroy() self.destroy()
@ -224,9 +232,7 @@ class EmaneConfigDialog(Dialog):
draw emane model configuration draw emane model configuration
""" """
model_name = self.emane_model.get() model_name = self.emane_model.get()
dialog = EmaneModelDialog( dialog = EmaneModelDialog(self, self.app, self.canvas_node, model_name)
self, self.app, self.canvas_node.core_node, model_name
)
if not dialog.has_error: if not dialog.has_error:
dialog.show() dialog.show()

View file

@ -290,7 +290,9 @@ class NodeConfigDialog(Dialog):
button.grid(row=0, column=1, sticky="ew") button.grid(row=0, column=1, sticky="ew")
def click_emane_config(self, emane_model: str, interface_id: int): def click_emane_config(self, emane_model: str, interface_id: int):
dialog = EmaneModelDialog(self, self.app, self.node, emane_model, interface_id) dialog = EmaneModelDialog(
self, self.app, self.canvas_node, emane_model, interface_id
)
dialog.show() dialog.show()
def click_icon(self): def click_icon(self):

View file

@ -1,5 +1,6 @@
import logging import logging
import tkinter as tk import tkinter as tk
from copy import deepcopy
from tkinter import BooleanVar from tkinter import BooleanVar
from typing import TYPE_CHECKING, Tuple from typing import TYPE_CHECKING, Tuple
@ -922,6 +923,9 @@ class CanvasGraph(tk.Canvas):
) )
node = CanvasNode(self.master, scaled_x, scaled_y, copy, canvas_node.image) node = CanvasNode(self.master, scaled_x, scaled_y, copy, canvas_node.image)
# copy configurations
node.emane_model_configs = deepcopy(canvas_node.emane_model_configs)
# add new node to modified_service_nodes set if that set contains the # add new node to modified_service_nodes set if that set contains the
# to_copy node # to_copy node
if self.core.service_been_modified(core_node.id): if self.core.service_been_modified(core_node.id):

View file

@ -58,6 +58,10 @@ class CanvasNode:
self.wireless_edges = set() self.wireless_edges = set()
self.antennas = [] self.antennas = []
self.antenna_images = {} self.antenna_images = {}
# possible configurations
self.emane_model_configs = {}
self.wlan_config = {}
self.mobility_config = {}
self.setup_bindings() self.setup_bindings()
def setup_bindings(self): def setup_bindings(self):