diff --git a/coretk/coretk/coreclient.py b/coretk/coretk/coreclient.py index 63816cb4..da75d3bd 100644 --- a/coretk/coretk/coreclient.py +++ b/coretk/coretk/coreclient.py @@ -305,23 +305,19 @@ class CoreClient: ) logging.info("delete links %s", response) - # TODO add location, hooks, emane_config, etc... - def start_session( - self, - nodes, - links, - location=None, - hooks=None, - emane_config=None, - emane_model_configs=None, - wlan_configs=None, - mobility_configs=None, - ): + def start_session(self): + nodes = self.get_nodes_proto() + links = self.get_links_proto() + wlan_configs = self.get_wlan_configs_proto() + mobility_configs = self.get_mobility_configs_proto() + emane_model_configs = self.get_emane_model_configs_proto() + hooks = list(self.hooks.values()) + emane_config = {x: self.emane_config[x].value for x in self.emane_config} response = self.client.start_session( self.session_id, nodes, links, - hooks=list(self.hooks.values()), + hooks=hooks, wlan_configs=wlan_configs, emane_config=emane_config, emane_model_configs=emane_model_configs, @@ -675,3 +671,59 @@ class CoreClient: else: logging.error("grpcmanagement.py INVALID CANVAS NODE ID") + + def get_nodes_proto(self): + nodes = [] + for node in self.nodes.values(): + pos = core_pb2.Position(x=int(node.x), y=int(node.y)) + proto_node = core_pb2.Node( + id=node.node_id, type=node.type, position=pos, model=node.model + ) + nodes.append(proto_node) + return nodes + + def get_links_proto(self): + links = [] + for edge in self.edges.values(): + interface_one = self.create_interface(edge.type1, edge.interface_1) + interface_two = self.create_interface(edge.type2, edge.interface_2) + link = core_pb2.Link( + node_one_id=edge.id1, + node_two_id=edge.id2, + type=core_pb2.LinkType.WIRED, + interface_one=interface_one, + interface_two=interface_two, + ) + links.append(link) + return links + + def get_wlan_configs_proto(self): + configs = [] + wlan_configs = self.wlanconfig_management.configurations + for node_id in wlan_configs: + config = wlan_configs[node_id] + config_proto = core_pb2.WlanConfig(node_id=node_id, config=config) + configs.append(config_proto) + return configs + + def get_mobility_configs_proto(self): + configs = [] + mobility_configs = self.mobilityconfig_management.configurations + for node_id in mobility_configs: + config = mobility_configs[node_id] + config_proto = core_pb2.MobilityConfig(node_id=node_id, config=config) + configs.append(config_proto) + return configs + + def get_emane_model_configs_proto(self): + configs = [] + emane_configs = self.emaneconfig_management.configurations + for key, value in emane_configs.items(): + node_id, interface_id = key + model, options = value + config = {x: options[x].value for x in options} + config_proto = core_pb2.EmaneModelConfig( + node_id=node_id, interface_id=interface_id, model=model, config=config + ) + configs.append(config_proto) + return configs diff --git a/coretk/coretk/toolbar.py b/coretk/coretk/toolbar.py index c97a326f..ace49796 100644 --- a/coretk/coretk/toolbar.py +++ b/coretk/coretk/toolbar.py @@ -5,7 +5,6 @@ from functools import partial from coretk.dialogs.customnodes import CustomNodesDialog from coretk.graph import GraphMode from coretk.images import ImageEnum, Images -from coretk.toolbarhelper import ToolbarHelper from coretk.tooltip import CreateToolTip @@ -216,8 +215,7 @@ class Toolbar(tk.Frame): """ logging.debug("clicked start button") self.canvas.mode = GraphMode.SELECT - helper = ToolbarHelper(self.app) - helper.gui_start_session() + self.app.core.start_session() self.runtime_frame.tkraise() def click_link_tool(self): diff --git a/coretk/coretk/toolbaraction.py b/coretk/coretk/toolbaraction.py deleted file mode 100644 index bbbc689b..00000000 --- a/coretk/coretk/toolbaraction.py +++ /dev/null @@ -1,17 +0,0 @@ -""" -Python file that store button actions -""" - -import logging - - -def click_selection_tool(): - logging.debug("Click SELECTION TOOL") - - -def click_start_stop_session_tool(): - logging.debug("Click START STOP SELECTION TOOL") - - -def click_link_tool(): - logging.debug("Click LINK TOOL") diff --git a/coretk/coretk/toolbarhelper.py b/coretk/coretk/toolbarhelper.py deleted file mode 100644 index 80b31506..00000000 --- a/coretk/coretk/toolbarhelper.py +++ /dev/null @@ -1,112 +0,0 @@ -""" -CoreToolbar help to draw on canvas, and make grpc client call -""" -from core.api.grpc.client import core_pb2 - - -class ToolbarHelper: - def __init__(self, app): - self.app = app - - def get_node_list(self): - """ - form a list node protobuf nodes to pass in start_session in grpc - - :return: nothing - """ - nodes = [] - for node in self.app.core.nodes.values(): - pos = core_pb2.Position(x=int(node.x), y=int(node.y)) - n = core_pb2.Node( - id=node.node_id, type=node.type, position=pos, model=node.model - ) - nodes.append(n) - return nodes - - def get_link_list(self): - """ - form a list of links to pass into grpc start session - - :rtype: list(core_pb2.Link) - :return: list of protobuf links - """ - links = [] - for edge in self.app.core.edges.values(): - interface_one = self.app.core.create_interface(edge.type1, edge.interface_1) - interface_two = self.app.core.create_interface(edge.type2, edge.interface_2) - link = core_pb2.Link( - node_one_id=edge.id1, - node_two_id=edge.id2, - type=core_pb2.LinkType.WIRED, - interface_one=interface_one, - interface_two=interface_two, - ) - links.append(link) - - return links - - def get_wlan_configuration_list(self): - """ - form a list of wlan configuration to pass to start_session - - :return: nothing - """ - configs = [] - manager_configs = self.app.core.wlanconfig_management.configurations - for key in manager_configs: - cnf = core_pb2.WlanConfig(node_id=key, config=manager_configs[key]) - configs.append(cnf) - return configs - - def get_mobility_configuration_list(self): - """ - form a list of mobility configuration to pass to start_session - - :return: nothing - """ - configs = [] - core = self.app.canvas.core - manager_configs = core.mobilityconfig_management.configurations - for key in manager_configs: - cnf = core_pb2.MobilityConfig(node_id=key, config=manager_configs[key]) - configs.append(cnf) - return configs - - def get_emane_configuration_list(self): - """ - form a list of emane configuration for the nodes - - :return: nothing - """ - configs = [] - manager_configs = self.app.core.emaneconfig_management.configurations - for key, value in manager_configs.items(): - config = {x: value[1][x].value for x in value[1]} - configs.append( - core_pb2.EmaneModelConfig( - node_id=key[0], interface_id=key[1], model=value[0], config=config - ) - ) - return configs - - def gui_start_session(self): - nodes = self.get_node_list() - links = self.get_link_list() - wlan_configs = self.get_wlan_configuration_list() - mobility_configs = self.get_mobility_configuration_list() - - # get emane config (global configuration) - pb_emane_config = self.app.core.emane_config - emane_config = {x: pb_emane_config[x].value for x in pb_emane_config} - - # get emane configuration list - emane_model_configs = self.get_emane_configuration_list() - - self.app.core.start_session( - nodes, - links, - wlan_configs=wlan_configs, - mobility_configs=mobility_configs, - emane_config=emane_config, - emane_model_configs=emane_model_configs, - )