work on wlan config
This commit is contained in:
parent
ef213dc66f
commit
60fff54918
15 changed files with 606 additions and 107 deletions
|
@ -8,6 +8,7 @@ from core.api.grpc import core_pb2
|
||||||
from coretk.nodeconfigtable import NodeConfig
|
from coretk.nodeconfigtable import NodeConfig
|
||||||
from coretk.wlanconfiguration import WlanConfiguration
|
from coretk.wlanconfiguration import WlanConfiguration
|
||||||
|
|
||||||
|
# TODO, finish classifying node types
|
||||||
NODE_TO_TYPE = {
|
NODE_TO_TYPE = {
|
||||||
"router": core_pb2.NodeType.DEFAULT,
|
"router": core_pb2.NodeType.DEFAULT,
|
||||||
"wlan": core_pb2.NodeType.WIRELESS_LAN,
|
"wlan": core_pb2.NodeType.WIRELESS_LAN,
|
||||||
|
@ -27,12 +28,16 @@ class CanvasAction:
|
||||||
if pb_type == core_pb2.NodeType.DEFAULT:
|
if pb_type == core_pb2.NodeType.DEFAULT:
|
||||||
self.display_node_configuration()
|
self.display_node_configuration()
|
||||||
elif pb_type == core_pb2.NodeType.WIRELESS_LAN:
|
elif pb_type == core_pb2.NodeType.WIRELESS_LAN:
|
||||||
self.display_wlan_configuration()
|
self.display_wlan_configuration(canvas_node)
|
||||||
|
|
||||||
def display_node_configuration(self):
|
def display_node_configuration(self):
|
||||||
NodeConfig(self.canvas, self.node_to_show_config)
|
NodeConfig(self.canvas, self.node_to_show_config)
|
||||||
self.node_to_show_config = None
|
self.node_to_show_config = None
|
||||||
|
|
||||||
def display_wlan_configuration(self):
|
def display_wlan_configuration(self, canvas_node):
|
||||||
WlanConfiguration(self.canvas, self.node_to_show_config)
|
# print(self.canvas.grpc_manager.wlanconfig_management.configurations)
|
||||||
|
wlan_config = self.canvas.grpc_manager.wlanconfig_management.configurations[
|
||||||
|
canvas_node.core_id
|
||||||
|
]
|
||||||
|
WlanConfiguration(self.canvas, self.node_to_show_config, wlan_config)
|
||||||
self.node_to_show_config = None
|
self.node_to_show_config = None
|
||||||
|
|
|
@ -29,8 +29,10 @@ class CoreGrpc:
|
||||||
self.wireless_draw = WirelessConnection(app.canvas, self)
|
self.wireless_draw = WirelessConnection(app.canvas, self)
|
||||||
|
|
||||||
def log_event(self, event):
|
def log_event(self, event):
|
||||||
logging.info("event: %s", event)
|
# logging.info("event: %s", event)
|
||||||
if event.link_event is not None:
|
if event.link_event is not None:
|
||||||
|
logging.info("event: %s", event)
|
||||||
|
|
||||||
self.wireless_draw.hangle_link_event(event.link_event)
|
self.wireless_draw.hangle_link_event(event.link_event)
|
||||||
|
|
||||||
def log_throughput(self, event):
|
def log_throughput(self, event):
|
||||||
|
@ -206,6 +208,54 @@ class CoreGrpc:
|
||||||
)
|
)
|
||||||
logging.info("delete links %s", response)
|
logging.info("delete links %s", response)
|
||||||
|
|
||||||
|
def create_interface(self, node_type, gui_interface):
|
||||||
|
"""
|
||||||
|
create a protobuf interface given the interface object stored by the programmer
|
||||||
|
|
||||||
|
:param core_bp2.NodeType type: node type
|
||||||
|
:param coretk.interface.Interface gui_interface: the programmer's interface object
|
||||||
|
:rtype: core_bp2.Interface
|
||||||
|
:return: protobuf interface object
|
||||||
|
"""
|
||||||
|
if node_type != core_pb2.NodeType.DEFAULT:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
interface = core_pb2.Interface(
|
||||||
|
id=gui_interface.id,
|
||||||
|
name=gui_interface.name,
|
||||||
|
mac=gui_interface.mac,
|
||||||
|
ip4=gui_interface.ipv4,
|
||||||
|
ip4mask=gui_interface.ip4prefix,
|
||||||
|
)
|
||||||
|
logging.debug("create interface 1 %s", interface)
|
||||||
|
|
||||||
|
return interface
|
||||||
|
|
||||||
|
# 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,
|
||||||
|
):
|
||||||
|
response = self.core.start_session(
|
||||||
|
session_id=self.session_id,
|
||||||
|
nodes=nodes,
|
||||||
|
links=links,
|
||||||
|
wlan_configs=wlan_configs,
|
||||||
|
)
|
||||||
|
logging.debug("Start session %s, result: %s", self.session_id, response.result)
|
||||||
|
|
||||||
|
def stop_session(self):
|
||||||
|
response = self.core.stop_session(session_id=self.session_id)
|
||||||
|
logging.debug("coregrpc.py Stop session, result: %s", response.result)
|
||||||
|
|
||||||
|
# TODO no need, might get rid of this
|
||||||
def add_link(self, id1, id2, type1, type2, edge):
|
def add_link(self, id1, id2, type1, type2, edge):
|
||||||
"""
|
"""
|
||||||
Grpc client request add link
|
Grpc client request add link
|
||||||
|
@ -217,30 +267,30 @@ class CoreGrpc:
|
||||||
:param core_pb2.NodeType type2: node 2 core node type
|
:param core_pb2.NodeType type2: node 2 core node type
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
if1 = None
|
if1 = self.create_interface(type1, edge.interface_1)
|
||||||
if2 = None
|
if2 = self.create_interface(type2, edge.interface_2)
|
||||||
if type1 == core_pb2.NodeType.DEFAULT:
|
# if type1 == core_pb2.NodeType.DEFAULT:
|
||||||
interface = edge.interface_1
|
# interface = edge.interface_1
|
||||||
if1 = core_pb2.Interface(
|
# if1 = core_pb2.Interface(
|
||||||
id=interface.id,
|
# id=interface.id,
|
||||||
name=interface.name,
|
# name=interface.name,
|
||||||
mac=interface.mac,
|
# mac=interface.mac,
|
||||||
ip4=interface.ipv4,
|
# ip4=interface.ipv4,
|
||||||
ip4mask=interface.ip4prefix,
|
# ip4mask=interface.ip4prefix,
|
||||||
)
|
# )
|
||||||
logging.debug("create interface 1 %s", if1)
|
# logging.debug("create interface 1 %s", if1)
|
||||||
# interface1 = self.interface_helper.create_interface(id1, 0)
|
# # interface1 = self.interface_helper.create_interface(id1, 0)
|
||||||
|
#
|
||||||
if type2 == core_pb2.NodeType.DEFAULT:
|
# if type2 == core_pb2.NodeType.DEFAULT:
|
||||||
interface = edge.interface_2
|
# interface = edge.interface_2
|
||||||
if2 = core_pb2.Interface(
|
# if2 = core_pb2.Interface(
|
||||||
id=interface.id,
|
# id=interface.id,
|
||||||
name=interface.name,
|
# name=interface.name,
|
||||||
mac=interface.mac,
|
# mac=interface.mac,
|
||||||
ip4=interface.ipv4,
|
# ip4=interface.ipv4,
|
||||||
ip4mask=interface.ip4prefix,
|
# ip4mask=interface.ip4prefix,
|
||||||
)
|
# )
|
||||||
logging.debug("create interface 2: %s", if2)
|
# logging.debug("create interface 2: %s", if2)
|
||||||
|
|
||||||
response = self.core.add_link(self.session_id, id1, id2, if1, if2)
|
response = self.core.add_link(self.session_id, id1, id2, if1, if2)
|
||||||
logging.info("created link: %s", response)
|
logging.info("created link: %s", response)
|
||||||
|
|
|
@ -1,22 +1,23 @@
|
||||||
import logging
|
import logging
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
from core.api.grpc import core_pb2
|
# from core.api.grpc import core_pb2
|
||||||
from coretk.coretoolbarhelp import CoreToolbarHelp
|
from coretk.coretoolbarhelp import CoreToolbarHelp
|
||||||
from coretk.graph import GraphMode
|
from coretk.graph import GraphMode
|
||||||
from coretk.images import ImageEnum, Images
|
from coretk.images import ImageEnum, Images
|
||||||
from coretk.tooltip import CreateToolTip
|
from coretk.tooltip import CreateToolTip
|
||||||
|
|
||||||
|
# from enum import Enum
|
||||||
|
|
||||||
class SessionStateEnum(Enum):
|
|
||||||
NONE = "none"
|
# class SessionStateEnum(Enum):
|
||||||
DEFINITION = "definition"
|
# NONE = "none"
|
||||||
CONFIGURATION = "configuration"
|
# DEFINITION = "definition"
|
||||||
RUNTIME = "runtime"
|
# CONFIGURATION = "configuration"
|
||||||
DATACOLLECT = "datacollect"
|
# RUNTIME = "runtime"
|
||||||
SHUTDOWN = "shutdown"
|
# DATACOLLECT = "datacollect"
|
||||||
INSTANTIATION = "instantiation"
|
# SHUTDOWN = "shutdown"
|
||||||
|
# INSTANTIATION = "instantiation"
|
||||||
|
|
||||||
|
|
||||||
class CoreToolbar(object):
|
class CoreToolbar(object):
|
||||||
|
@ -161,21 +162,22 @@ class CoreToolbar(object):
|
||||||
"""
|
"""
|
||||||
logging.debug("Click START STOP SESSION button")
|
logging.debug("Click START STOP SESSION button")
|
||||||
helper = CoreToolbarHelp(self.application)
|
helper = CoreToolbarHelp(self.application)
|
||||||
# self.destroy_children_widgets(self.edit_frame)
|
|
||||||
self.destroy_children_widgets()
|
self.destroy_children_widgets()
|
||||||
self.canvas.mode = GraphMode.SELECT
|
self.canvas.mode = GraphMode.SELECT
|
||||||
|
|
||||||
# set configuration state
|
# set configuration state
|
||||||
state = self.canvas.core_grpc.get_session_state()
|
# state = self.canvas.core_grpc.get_session_state()
|
||||||
|
# if state == core_pb2.SessionState.SHUTDOWN or self.application.is_open_xml:
|
||||||
|
# self.canvas.core_grpc.set_session_state(SessionStateEnum.DEFINITION.value)
|
||||||
|
# self.application.is_open_xml = False
|
||||||
|
#
|
||||||
|
# self.canvas.core_grpc.set_session_state(SessionStateEnum.CONFIGURATION.value)
|
||||||
|
# helper.add_nodes()
|
||||||
|
# helper.add_edges()
|
||||||
|
# self.canvas.core_grpc.set_session_state(SessionStateEnum.INSTANTIATION.value)
|
||||||
|
helper.gui_start_session()
|
||||||
|
self.create_runtime_toolbar()
|
||||||
|
|
||||||
if state == core_pb2.SessionState.SHUTDOWN or self.application.is_open_xml:
|
|
||||||
self.canvas.core_grpc.set_session_state(SessionStateEnum.DEFINITION.value)
|
|
||||||
self.application.is_open_xml = False
|
|
||||||
|
|
||||||
self.canvas.core_grpc.set_session_state(SessionStateEnum.CONFIGURATION.value)
|
|
||||||
|
|
||||||
helper.add_nodes()
|
|
||||||
helper.add_edges()
|
|
||||||
# for node in self.canvas.grpc_manager.nodes.values():
|
# for node in self.canvas.grpc_manager.nodes.values():
|
||||||
# print(node.type, node.model, int(node.x), int(node.y), node.name, node.node_id)
|
# print(node.type, node.model, int(node.x), int(node.y), node.name, node.node_id)
|
||||||
# self.canvas.core_grpc.add_node(
|
# self.canvas.core_grpc.add_node(
|
||||||
|
@ -188,10 +190,8 @@ class CoreToolbar(object):
|
||||||
# self.canvas.core_grpc.add_link(
|
# self.canvas.core_grpc.add_link(
|
||||||
# edge.id1, edge.id2, edge.type1, edge.type2, edge
|
# edge.id1, edge.id2, edge.type1, edge.type2, edge
|
||||||
# )
|
# )
|
||||||
self.canvas.core_grpc.set_session_state(SessionStateEnum.INSTANTIATION.value)
|
|
||||||
# self.canvas.core_grpc.get_session()
|
# self.canvas.core_grpc.get_session()
|
||||||
# self.application.is_open_xml = False
|
# self.application.is_open_xml = False
|
||||||
self.create_runtime_toolbar()
|
|
||||||
|
|
||||||
def click_link_tool(self):
|
def click_link_tool(self):
|
||||||
logging.debug("Click LINK button")
|
logging.debug("Click LINK button")
|
||||||
|
@ -366,6 +366,13 @@ class CoreToolbar(object):
|
||||||
self.canvas.draw_node_image = Images.get(ImageEnum.TUNNEL.value)
|
self.canvas.draw_node_image = Images.get(ImageEnum.TUNNEL.value)
|
||||||
self.canvas.draw_node_name = "tunnel"
|
self.canvas.draw_node_name = "tunnel"
|
||||||
|
|
||||||
|
def pick_emane(self, main_button):
|
||||||
|
self.link_layer_option_menu.destroy()
|
||||||
|
main_button.configure(image=Images.get(ImageEnum.EMANE.value))
|
||||||
|
self.canvas.mode = GraphMode.PICKNODE
|
||||||
|
self.canvas.draw_node_image = Images.get(ImageEnum.EMANE.value)
|
||||||
|
self.canvas.draw_node_name = "emane"
|
||||||
|
|
||||||
def draw_link_layer_options(self, link_layer_button):
|
def draw_link_layer_options(self, link_layer_button):
|
||||||
"""
|
"""
|
||||||
Draw the options for link-layer button
|
Draw the options for link-layer button
|
||||||
|
@ -380,6 +387,7 @@ class CoreToolbar(object):
|
||||||
Images.get(ImageEnum.HUB.value),
|
Images.get(ImageEnum.HUB.value),
|
||||||
Images.get(ImageEnum.SWITCH.value),
|
Images.get(ImageEnum.SWITCH.value),
|
||||||
Images.get(ImageEnum.WLAN.value),
|
Images.get(ImageEnum.WLAN.value),
|
||||||
|
Images.get(ImageEnum.EMANE.value),
|
||||||
Images.get(ImageEnum.RJ45.value),
|
Images.get(ImageEnum.RJ45.value),
|
||||||
Images.get(ImageEnum.TUNNEL.value),
|
Images.get(ImageEnum.TUNNEL.value),
|
||||||
]
|
]
|
||||||
|
@ -387,6 +395,7 @@ class CoreToolbar(object):
|
||||||
self.pick_hub,
|
self.pick_hub,
|
||||||
self.pick_switch,
|
self.pick_switch,
|
||||||
self.pick_wlan,
|
self.pick_wlan,
|
||||||
|
self.pick_emane,
|
||||||
self.pick_rj45,
|
self.pick_rj45,
|
||||||
self.pick_tunnel,
|
self.pick_tunnel,
|
||||||
]
|
]
|
||||||
|
@ -394,6 +403,7 @@ class CoreToolbar(object):
|
||||||
"ethernet hub",
|
"ethernet hub",
|
||||||
"ethernet switch",
|
"ethernet switch",
|
||||||
"wireless LAN",
|
"wireless LAN",
|
||||||
|
"emane",
|
||||||
"rj45 physical interface tool",
|
"rj45 physical interface tool",
|
||||||
"tunnel tool",
|
"tunnel tool",
|
||||||
]
|
]
|
||||||
|
@ -582,12 +592,12 @@ class CoreToolbar(object):
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
logging.debug("Click on STOP button ")
|
logging.debug("Click on STOP button ")
|
||||||
# self.destroy_children_widgets(self.edit_frame)
|
|
||||||
self.destroy_children_widgets()
|
self.destroy_children_widgets()
|
||||||
|
|
||||||
self.canvas.core_grpc.set_session_state(SessionStateEnum.DATACOLLECT.value)
|
# self.canvas.core_grpc.set_session_state(SessionStateEnum.DATACOLLECT.value)
|
||||||
self.canvas.core_grpc.delete_links()
|
# self.canvas.core_grpc.delete_links()
|
||||||
self.canvas.core_grpc.delete_nodes()
|
# self.canvas.core_grpc.delete_nodes()
|
||||||
|
self.canvas.core_grpc.stop_session()
|
||||||
self.create_toolbar()
|
self.create_toolbar()
|
||||||
|
|
||||||
def click_run_button(self):
|
def click_run_button(self):
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
CoreToolbar help to draw on canvas, and make grpc client call
|
CoreToolbar help to draw on canvas, and make grpc client call
|
||||||
"""
|
"""
|
||||||
|
from core.api.grpc.client import core_pb2
|
||||||
|
|
||||||
|
|
||||||
class CoreToolbarHelp:
|
class CoreToolbarHelp:
|
||||||
|
@ -8,24 +9,114 @@ class CoreToolbarHelp:
|
||||||
self.application = application
|
self.application = application
|
||||||
self.core_grpc = application.core_grpc
|
self.core_grpc = application.core_grpc
|
||||||
|
|
||||||
def add_nodes(self):
|
def get_node_list(self):
|
||||||
"""
|
"""
|
||||||
add the nodes stored in grpc manager
|
form a list node protobuf nodes to pass in start_session in grpc
|
||||||
|
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
grpc_manager = self.application.canvas.grpc_manager
|
grpc_manager = self.application.canvas.grpc_manager
|
||||||
for node in grpc_manager.nodes.values():
|
|
||||||
self.application.core_grpc.add_node(
|
|
||||||
node.type, node.model, int(node.x), int(node.y), node.name, node.node_id
|
|
||||||
)
|
|
||||||
|
|
||||||
def add_edges(self):
|
# list(core_pb2.Node)
|
||||||
|
nodes = []
|
||||||
|
|
||||||
|
for node in grpc_manager.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):
|
||||||
"""
|
"""
|
||||||
add the edges stored in grpc manager
|
form a list of links to pass into grpc start session
|
||||||
:return:
|
|
||||||
|
:rtype: list(core_pb2.Link)
|
||||||
|
:return: list of protobuf links
|
||||||
"""
|
"""
|
||||||
grpc_manager = self.application.canvas.grpc_manager
|
grpc_manager = self.application.canvas.grpc_manager
|
||||||
|
|
||||||
|
# list(core_bp2.Link)
|
||||||
|
links = []
|
||||||
for edge in grpc_manager.edges.values():
|
for edge in grpc_manager.edges.values():
|
||||||
self.application.core_grpc.add_link(
|
interface_one = self.application.core_grpc.create_interface(
|
||||||
edge.id1, edge.id2, edge.type1, edge.type2, edge
|
edge.type1, edge.interface_1
|
||||||
)
|
)
|
||||||
|
interface_two = self.application.core_grpc.create_interface(
|
||||||
|
edge.type2, edge.interface_2
|
||||||
|
)
|
||||||
|
# TODO for now only consider the basic cases
|
||||||
|
if (
|
||||||
|
edge.type1 == core_pb2.NodeType.WIRELESS_LAN
|
||||||
|
or edge.type2 == core_pb2.NodeType.WIRELESS_LAN
|
||||||
|
):
|
||||||
|
link_type = core_pb2.LinkType.WIRELESS
|
||||||
|
else:
|
||||||
|
link_type = core_pb2.LinkType.WIRED
|
||||||
|
link = core_pb2.Link(
|
||||||
|
node_one_id=edge.id1,
|
||||||
|
node_two_id=edge.id2,
|
||||||
|
type=link_type,
|
||||||
|
interface_one=interface_one,
|
||||||
|
interface_two=interface_two,
|
||||||
|
)
|
||||||
|
links.append(link)
|
||||||
|
# self.id1 = edge.id1
|
||||||
|
# self.id2 = edge.id2
|
||||||
|
# self.type = link_type
|
||||||
|
# self.if1 = interface_one
|
||||||
|
# self.if2 = interface_two
|
||||||
|
|
||||||
|
return links
|
||||||
|
|
||||||
|
def get_wlan_configuration_list(self):
|
||||||
|
configs = []
|
||||||
|
grpc_manager = self.application.canvas.grpc_manager
|
||||||
|
manager_configs = grpc_manager.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 gui_start_session(self):
|
||||||
|
# list(core_pb2.Node)
|
||||||
|
nodes = self.get_node_list()
|
||||||
|
|
||||||
|
# list(core_bp2.Link)
|
||||||
|
links = self.get_link_list()
|
||||||
|
|
||||||
|
# print(links[0])
|
||||||
|
wlan_configs = self.get_wlan_configuration_list()
|
||||||
|
# print(wlan_configs)
|
||||||
|
self.core_grpc.start_session(nodes, links, wlan_configs=wlan_configs)
|
||||||
|
# self.core_grpc.core.add_link(self.core_grpc.session_id, self.id1, self.id2, self.if1, self.if2)
|
||||||
|
# res = self.core_grpc.core.get_wlan_config(self.core_grpc.session_id, 1)
|
||||||
|
|
||||||
|
# res = self.core_grpc.core.get_session(self.core_grpc.session_id).session
|
||||||
|
# print(res)
|
||||||
|
# res = self.core_grpc.core.get_wlan_config(self.core_grpc.session_id, 1)
|
||||||
|
|
||||||
|
# print(res)
|
||||||
|
|
||||||
|
# def add_nodes(self):
|
||||||
|
# """
|
||||||
|
# add the nodes stored in grpc manager
|
||||||
|
# :return: nothing
|
||||||
|
# """
|
||||||
|
# grpc_manager = self.application.canvas.grpc_manager
|
||||||
|
# for node in grpc_manager.nodes.values():
|
||||||
|
# self.application.core_grpc.add_node(
|
||||||
|
# node.type, node.model, int(node.x), int(node.y), node.name, node.node_id
|
||||||
|
# )
|
||||||
|
#
|
||||||
|
# def add_edges(self):
|
||||||
|
# """
|
||||||
|
# add the edges stored in grpc manager
|
||||||
|
# :return:
|
||||||
|
# """
|
||||||
|
# grpc_manager = self.application.canvas.grpc_manager
|
||||||
|
# for edge in grpc_manager.edges.values():
|
||||||
|
# self.application.core_grpc.add_link(
|
||||||
|
# edge.id1, edge.id2, edge.type1, edge.type2, edge
|
||||||
|
# )
|
||||||
|
|
|
@ -58,10 +58,6 @@ class CanvasGraph(tk.Canvas):
|
||||||
# self.core_map = CoreToCanvasMapping()
|
# self.core_map = CoreToCanvasMapping()
|
||||||
# self.draw_existing_component()
|
# self.draw_existing_component()
|
||||||
|
|
||||||
def test(self):
|
|
||||||
print("testing the button")
|
|
||||||
print(self.node_context.winfo_rootx())
|
|
||||||
|
|
||||||
def setup_menus(self):
|
def setup_menus(self):
|
||||||
self.node_context = tk.Menu(self.master)
|
self.node_context = tk.Menu(self.master)
|
||||||
self.node_context.add_command(
|
self.node_context.add_command(
|
||||||
|
|
|
@ -7,6 +7,7 @@ import logging
|
||||||
from core.api.grpc import core_pb2
|
from core.api.grpc import core_pb2
|
||||||
from coretk.coretocanvas import CoreToCanvasMapping
|
from coretk.coretocanvas import CoreToCanvasMapping
|
||||||
from coretk.interface import Interface, InterfaceManager
|
from coretk.interface import Interface, InterfaceManager
|
||||||
|
from coretk.wlannodeconfig import WlanNodeConfig
|
||||||
|
|
||||||
link_layer_nodes = ["switch", "hub", "wlan", "rj45", "tunnel"]
|
link_layer_nodes = ["switch", "hub", "wlan", "rj45", "tunnel"]
|
||||||
network_layer_nodes = ["router", "host", "PC", "mdr", "prouter", "OVS"]
|
network_layer_nodes = ["router", "host", "PC", "mdr", "prouter", "OVS"]
|
||||||
|
@ -72,6 +73,8 @@ class GrpcManager:
|
||||||
# self.node_id_and_interface_to_edge_token = {}
|
# self.node_id_and_interface_to_edge_token = {}
|
||||||
self.core_mapping = CoreToCanvasMapping()
|
self.core_mapping = CoreToCanvasMapping()
|
||||||
|
|
||||||
|
self.wlanconfig_management = WlanNodeConfig()
|
||||||
|
|
||||||
def update_preexisting_ids(self):
|
def update_preexisting_ids(self):
|
||||||
"""
|
"""
|
||||||
get preexisting node ids
|
get preexisting node ids
|
||||||
|
@ -145,6 +148,10 @@ class GrpcManager:
|
||||||
logging.error("grpcmanagemeny.py INVALID node name")
|
logging.error("grpcmanagemeny.py INVALID node name")
|
||||||
nid = self.get_id()
|
nid = self.get_id()
|
||||||
create_node = Node(session_id, nid, node_type, node_model, x, y, name)
|
create_node = Node(session_id, nid, node_type, node_model, x, y, name)
|
||||||
|
|
||||||
|
# set default configuration for wireless node
|
||||||
|
self.wlanconfig_management.set_default_config(node_type, nid)
|
||||||
|
|
||||||
self.nodes[canvas_id] = create_node
|
self.nodes[canvas_id] = create_node
|
||||||
self.core_mapping.map_core_id_to_canvas_id(nid, canvas_id)
|
self.core_mapping.map_core_id_to_canvas_id(nid, canvas_id)
|
||||||
# self.core_id_to_canvas_id[nid] = canvas_id
|
# self.core_id_to_canvas_id[nid] = canvas_id
|
||||||
|
|
BIN
coretk/coretk/icons/emane.gif
Normal file
BIN
coretk/coretk/icons/emane.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -40,6 +40,8 @@ class Images:
|
||||||
return Images.get(ImageEnum.HUB.value), "hub"
|
return Images.get(ImageEnum.HUB.value), "hub"
|
||||||
if node_type == core_pb2.NodeType.WIRELESS_LAN:
|
if node_type == core_pb2.NodeType.WIRELESS_LAN:
|
||||||
return Images.get(ImageEnum.WLAN.value), "wlan"
|
return Images.get(ImageEnum.WLAN.value), "wlan"
|
||||||
|
if node_type == core_pb2.NodeType.EMANE:
|
||||||
|
return Images.get(ImageEnum.EMANE.value), "emane"
|
||||||
if node_type == core_pb2.NodeType.RJ45:
|
if node_type == core_pb2.NodeType.RJ45:
|
||||||
return Images.get(ImageEnum.RJ45.value), "rj45"
|
return Images.get(ImageEnum.RJ45.value), "rj45"
|
||||||
if node_type == core_pb2.NodeType.TUNNEL:
|
if node_type == core_pb2.NodeType.TUNNEL:
|
||||||
|
@ -71,6 +73,7 @@ class ImageEnum(Enum):
|
||||||
LINK = "link"
|
LINK = "link"
|
||||||
HUB = "hub"
|
HUB = "hub"
|
||||||
WLAN = "wlan"
|
WLAN = "wlan"
|
||||||
|
EMANE = "emane"
|
||||||
RJ45 = "rj45"
|
RJ45 = "rj45"
|
||||||
TUNNEL = "tunnel"
|
TUNNEL = "tunnel"
|
||||||
OVAL = "oval"
|
OVAL = "oval"
|
||||||
|
|
|
@ -51,7 +51,7 @@ class InterfaceManager:
|
||||||
ipaddress.ip_network("10.0.0.0/12").subnets(prefixlen_diff=12)
|
ipaddress.ip_network("10.0.0.0/12").subnets(prefixlen_diff=12)
|
||||||
)
|
)
|
||||||
self.subnet_index = 0
|
self.subnet_index = 0
|
||||||
self.address_index = None
|
self.address_index = 0
|
||||||
|
|
||||||
# self.network = ipaddress.ip_network("10.0.0.0/24")
|
# self.network = ipaddress.ip_network("10.0.0.0/24")
|
||||||
# self.addresses = list(self.network.hosts())
|
# self.addresses = list(self.network.hosts())
|
||||||
|
@ -81,9 +81,9 @@ class InterfaceManager:
|
||||||
|
|
||||||
def new_subnet(self):
|
def new_subnet(self):
|
||||||
self.network = self.core_subnets[self.subnet_index]
|
self.network = self.core_subnets[self.subnet_index]
|
||||||
self.subnet_index = self.subnet_index + 1
|
# self.subnet_index = self.subnet_index + 1
|
||||||
self.addresses = list(self.network.hosts())
|
self.addresses = list(self.network.hosts())
|
||||||
self.address_index = 0
|
# self.address_index = 0
|
||||||
|
|
||||||
# def new_subnet(self):
|
# def new_subnet(self):
|
||||||
# """
|
# """
|
||||||
|
|
|
@ -332,7 +332,7 @@ class MenuAction:
|
||||||
self.application = application
|
self.application = application
|
||||||
self.core_grpc = application.core_grpc
|
self.core_grpc = application.core_grpc
|
||||||
|
|
||||||
def clean_nodes_links_and_set_configuarations(self):
|
def prompt_save_running_session(self):
|
||||||
"""
|
"""
|
||||||
Prompt use to stop running session before application is closed
|
Prompt use to stop running session before application is closed
|
||||||
|
|
||||||
|
@ -356,9 +356,7 @@ class MenuAction:
|
||||||
|
|
||||||
if msgbox or msgbox is False:
|
if msgbox or msgbox is False:
|
||||||
if msgbox:
|
if msgbox:
|
||||||
grpc.set_session_state("datacollect")
|
grpc.stop_session()
|
||||||
grpc.delete_links()
|
|
||||||
grpc.delete_nodes()
|
|
||||||
grpc.delete_session()
|
grpc.delete_session()
|
||||||
# else:
|
# else:
|
||||||
# grpc.set_session_state("definition")
|
# grpc.set_session_state("definition")
|
||||||
|
@ -371,7 +369,7 @@ class MenuAction:
|
||||||
|
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
self.clean_nodes_links_and_set_configuarations()
|
self.prompt_save_running_session()
|
||||||
# self.application.core_grpc.close()
|
# self.application.core_grpc.close()
|
||||||
self.application.quit()
|
self.application.quit()
|
||||||
|
|
||||||
|
@ -384,8 +382,6 @@ class MenuAction:
|
||||||
filetypes=(("EmulationScript XML files", "*.xml"), ("All files", "*")),
|
filetypes=(("EmulationScript XML files", "*.xml"), ("All files", "*")),
|
||||||
defaultextension=".xml",
|
defaultextension=".xml",
|
||||||
)
|
)
|
||||||
# with open("prev_saved_xml.txt", "a") as file:
|
|
||||||
# file.write(file_path + "\n")
|
|
||||||
grpc.save_xml(file_path)
|
grpc.save_xml(file_path)
|
||||||
|
|
||||||
def file_open_xml(self):
|
def file_open_xml(self):
|
||||||
|
@ -397,7 +393,7 @@ class MenuAction:
|
||||||
filetypes=(("EmulationScript XML File", "*.xml"), ("All Files", "*")),
|
filetypes=(("EmulationScript XML File", "*.xml"), ("All Files", "*")),
|
||||||
)
|
)
|
||||||
# clean up before opening a new session
|
# clean up before opening a new session
|
||||||
self.clean_nodes_links_and_set_configuarations()
|
self.prompt_save_running_session()
|
||||||
# grpc = CoreGrpc(self.application.master)
|
# grpc = CoreGrpc(self.application.master)
|
||||||
# grpc.core.connect()
|
# grpc.core.connect()
|
||||||
core_grpc = self.application.core_grpc
|
core_grpc = self.application.core_grpc
|
||||||
|
|
|
@ -9,6 +9,7 @@ from tkinter import filedialog
|
||||||
from PIL import Image, ImageTk
|
from PIL import Image, ImageTk
|
||||||
|
|
||||||
from coretk.imagemodification import ImageModification
|
from coretk.imagemodification import ImageModification
|
||||||
|
from coretk.nodeservice import NodeServices
|
||||||
|
|
||||||
PATH = os.path.abspath(os.path.dirname(__file__))
|
PATH = os.path.abspath(os.path.dirname(__file__))
|
||||||
ICONS_DIR = os.path.join(PATH, "icons")
|
ICONS_DIR = os.path.join(PATH, "icons")
|
||||||
|
@ -19,6 +20,12 @@ DEFAULTNODES = ["router", "host", "PC"]
|
||||||
|
|
||||||
class NodeConfig:
|
class NodeConfig:
|
||||||
def __init__(self, canvas, canvas_node):
|
def __init__(self, canvas, canvas_node):
|
||||||
|
"""
|
||||||
|
create an instance of node configuration
|
||||||
|
|
||||||
|
:param coretk.graph.CanvasGraph canvas: canvas object
|
||||||
|
:param coretk.graph.CanvasNode canvas_node: canvas node object
|
||||||
|
"""
|
||||||
self.canvas = canvas
|
self.canvas = canvas
|
||||||
self.image = canvas_node.image
|
self.image = canvas_node.image
|
||||||
self.node_type = canvas_node.node_type
|
self.node_type = canvas_node.node_type
|
||||||
|
@ -118,7 +125,9 @@ class NodeConfig:
|
||||||
type_button = tk.Button(f, text="None")
|
type_button = tk.Button(f, text="None")
|
||||||
type_button.grid(row=0, column=1)
|
type_button.grid(row=0, column=1)
|
||||||
|
|
||||||
service_button = tk.Button(f, text="Services...")
|
service_button = tk.Button(
|
||||||
|
f, text="Services...", command=lambda: NodeServices()
|
||||||
|
)
|
||||||
service_button.grid(row=0, column=2)
|
service_button.grid(row=0, column=2)
|
||||||
|
|
||||||
f.grid(padx=2, pady=2)
|
f.grid(padx=2, pady=2)
|
||||||
|
|
195
coretk/coretk/nodeservice.py
Normal file
195
coretk/coretk/nodeservice.py
Normal file
|
@ -0,0 +1,195 @@
|
||||||
|
"""
|
||||||
|
core node services
|
||||||
|
"""
|
||||||
|
import tkinter as tk
|
||||||
|
from tkinter import messagebox
|
||||||
|
|
||||||
|
CORE_DEFAULT_GROUPS = ["EMANE", "FRR", "ProtoSvc", "Quagga", "Security", "Utility"]
|
||||||
|
DEFAULT_GROUP_RADIO_VALUE = {
|
||||||
|
"EMANE": 1,
|
||||||
|
"FRR": 2,
|
||||||
|
"ProtoSvc": 3,
|
||||||
|
"Quagga": 4,
|
||||||
|
"Security": 5,
|
||||||
|
"Utility": 6,
|
||||||
|
}
|
||||||
|
DEFAULT_GROUP_SERVICES = {
|
||||||
|
"EMANE": ["transportd"],
|
||||||
|
"FRR": [
|
||||||
|
"FRRBable",
|
||||||
|
"FRRBGP",
|
||||||
|
"FRROSPFv2",
|
||||||
|
"FRROSPFv3",
|
||||||
|
"FRRpimd",
|
||||||
|
"FRRRIP",
|
||||||
|
"FRRRIPNG",
|
||||||
|
"FRRzebra",
|
||||||
|
],
|
||||||
|
"ProtoSvc": ["MGEN_Sink", "MgenActor", "SMF"],
|
||||||
|
"Quagga": [
|
||||||
|
"Babel",
|
||||||
|
"BGP",
|
||||||
|
"OSPFv2",
|
||||||
|
"OSPFv3",
|
||||||
|
"OSPFv3MDR",
|
||||||
|
"RIP",
|
||||||
|
"RIPNG",
|
||||||
|
"Xpimd",
|
||||||
|
"zebra",
|
||||||
|
],
|
||||||
|
"Security": ["Firewall", "IPsec", "NAT", "VPNClient", "VPNServer"],
|
||||||
|
"Utility": [
|
||||||
|
"atd",
|
||||||
|
"DefaultMulticastRoute",
|
||||||
|
"DefaultRoute",
|
||||||
|
"DHCP",
|
||||||
|
"DHCPClient",
|
||||||
|
"FTP",
|
||||||
|
"HTTP",
|
||||||
|
"IPForward ",
|
||||||
|
"pcap",
|
||||||
|
"radvd",
|
||||||
|
"SSH",
|
||||||
|
"StaticRoute",
|
||||||
|
"ucarp",
|
||||||
|
"UserDefined",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class NodeServices:
|
||||||
|
def __init__(self):
|
||||||
|
self.core_groups = []
|
||||||
|
self.service_to_config = None
|
||||||
|
|
||||||
|
self.top = tk.Toplevel()
|
||||||
|
self.top.title("Node services")
|
||||||
|
self.config_frame = tk.Frame(self.top)
|
||||||
|
self.config_frame.grid()
|
||||||
|
self.draw_group()
|
||||||
|
self.group_services()
|
||||||
|
self.current_services()
|
||||||
|
self.node_service_options()
|
||||||
|
|
||||||
|
def display_group_services(self, group_name):
|
||||||
|
group_services_frame = self.config_frame.grid_slaves(row=0, column=1)[0]
|
||||||
|
listbox = group_services_frame.grid_slaves(row=1, column=0)[0]
|
||||||
|
listbox.delete(0, tk.END)
|
||||||
|
for s in DEFAULT_GROUP_SERVICES[group_name]:
|
||||||
|
listbox.insert(tk.END, s)
|
||||||
|
for i in range(listbox.size()):
|
||||||
|
listbox.itemconfig(i, selectbackground="white")
|
||||||
|
|
||||||
|
def group_select(self, event):
|
||||||
|
listbox = event.widget
|
||||||
|
cur_selection = listbox.curselection()
|
||||||
|
if cur_selection:
|
||||||
|
s = listbox.get(listbox.curselection())
|
||||||
|
self.display_group_services(s)
|
||||||
|
|
||||||
|
def draw_group(self):
|
||||||
|
"""
|
||||||
|
draw the group tab
|
||||||
|
|
||||||
|
:return: nothing
|
||||||
|
"""
|
||||||
|
f = tk.Frame(self.config_frame)
|
||||||
|
|
||||||
|
lbl = tk.Label(f, text="Group")
|
||||||
|
lbl.grid()
|
||||||
|
|
||||||
|
sb = tk.Scrollbar(f, orient=tk.VERTICAL)
|
||||||
|
sb.grid(row=1, column=1, sticky=tk.S + tk.N)
|
||||||
|
|
||||||
|
listbox = tk.Listbox(
|
||||||
|
f,
|
||||||
|
selectmode=tk.SINGLE,
|
||||||
|
yscrollcommand=sb.set,
|
||||||
|
relief=tk.FLAT,
|
||||||
|
highlightbackground="#b3b3b3",
|
||||||
|
highlightcolor="#b3b3b3",
|
||||||
|
highlightthickness=0.5,
|
||||||
|
bd=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
for grp in CORE_DEFAULT_GROUPS:
|
||||||
|
listbox.insert(tk.END, grp)
|
||||||
|
for i in range(0, listbox.size()):
|
||||||
|
listbox.itemconfig(i, selectbackground="white")
|
||||||
|
listbox.grid(row=1, column=0)
|
||||||
|
|
||||||
|
sb.config(command=listbox.yview)
|
||||||
|
f.grid(padx=3, pady=3)
|
||||||
|
listbox.bind("<<ListboxSelect>>", self.group_select)
|
||||||
|
|
||||||
|
def group_service_select(self, event):
|
||||||
|
print("select group service")
|
||||||
|
listbox = event.widget
|
||||||
|
cur_selection = listbox.curselection()
|
||||||
|
if cur_selection:
|
||||||
|
s = listbox.get(listbox.curselection())
|
||||||
|
self.service_to_config = s
|
||||||
|
else:
|
||||||
|
self.service_to_config = None
|
||||||
|
|
||||||
|
def group_services(self):
|
||||||
|
f = tk.Frame(self.config_frame)
|
||||||
|
lbl = tk.Label(f, text="Group services")
|
||||||
|
lbl.grid()
|
||||||
|
|
||||||
|
sb = tk.Scrollbar(f, orient=tk.VERTICAL)
|
||||||
|
sb.grid(row=1, column=1, sticky=tk.S + tk.N)
|
||||||
|
|
||||||
|
listbox = tk.Listbox(
|
||||||
|
f,
|
||||||
|
selectmode=tk.SINGLE,
|
||||||
|
yscrollcommand=sb.set,
|
||||||
|
relief=tk.FLAT,
|
||||||
|
highlightbackground="#b3b3b3",
|
||||||
|
highlightcolor="#b3b3b3",
|
||||||
|
highlightthickness=0.5,
|
||||||
|
bd=0,
|
||||||
|
)
|
||||||
|
listbox.grid(row=1, column=0)
|
||||||
|
sb.config(command=listbox.yview)
|
||||||
|
f.grid(padx=3, pady=3, row=0, column=1)
|
||||||
|
|
||||||
|
listbox.bind("<<ListboxSelect>>", self.group_service_select)
|
||||||
|
|
||||||
|
def current_services(self):
|
||||||
|
f = tk.Frame(self.config_frame)
|
||||||
|
lbl = tk.Label(f, text="Current services")
|
||||||
|
lbl.grid()
|
||||||
|
|
||||||
|
sb = tk.Scrollbar(f, orient=tk.VERTICAL)
|
||||||
|
sb.grid(row=1, column=1, sticky=tk.S + tk.N)
|
||||||
|
|
||||||
|
listbox = tk.Listbox(
|
||||||
|
f,
|
||||||
|
selectmode=tk.MULTIPLE,
|
||||||
|
yscrollcommand=sb.set,
|
||||||
|
relief=tk.FLAT,
|
||||||
|
highlightbackground="#b3b3b3",
|
||||||
|
highlightcolor="#b3b3b3",
|
||||||
|
highlightthickness=0.5,
|
||||||
|
bd=0,
|
||||||
|
)
|
||||||
|
listbox.grid(row=1, column=0)
|
||||||
|
sb.config(command=listbox.yview)
|
||||||
|
f.grid(padx=3, pady=3, row=0, column=2)
|
||||||
|
|
||||||
|
def config_service(self):
|
||||||
|
if self.service_to_config is None:
|
||||||
|
messagebox.showinfo("CORE info", "Choose a service to configure.")
|
||||||
|
else:
|
||||||
|
print(self.service_to_config)
|
||||||
|
|
||||||
|
def node_service_options(self):
|
||||||
|
f = tk.Frame(self.top)
|
||||||
|
b = tk.Button(f, text="Connfigure", command=self.config_service)
|
||||||
|
b.grid(row=0, column=0)
|
||||||
|
b = tk.Button(f, text="Apply")
|
||||||
|
b.grid(row=0, column=1)
|
||||||
|
b = tk.Button(f, text="Cancel", command=self.top.destroy)
|
||||||
|
b.grid(row=0, column=2)
|
||||||
|
f.grid(sticky=tk.E)
|
|
@ -1,10 +0,0 @@
|
||||||
"""
|
|
||||||
service configuration
|
|
||||||
"""
|
|
||||||
|
|
||||||
# import tkinter as tk
|
|
||||||
|
|
||||||
|
|
||||||
class ServiceConfiguration:
|
|
||||||
def __init__(self):
|
|
||||||
return
|
|
|
@ -2,13 +2,20 @@
|
||||||
wlan configuration
|
wlan configuration
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import ast
|
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
from coretk.imagemodification import ImageModification
|
||||||
|
|
||||||
|
|
||||||
class WlanConfiguration:
|
class WlanConfiguration:
|
||||||
def __init__(self, canvas, canvas_node):
|
def __init__(self, canvas, canvas_node, config):
|
||||||
|
"""
|
||||||
|
create an instance of WlanConfiguration
|
||||||
|
|
||||||
|
:param coretk.grpah.CanvasGraph canvas: canvas object
|
||||||
|
:param coretk.graph.CanvasNode canvas_node: canvas node object
|
||||||
|
"""
|
||||||
|
|
||||||
self.canvas = canvas
|
self.canvas = canvas
|
||||||
self.image = canvas_node.image
|
self.image = canvas_node.image
|
||||||
|
@ -20,10 +27,14 @@ class WlanConfiguration:
|
||||||
self.top.title("wlan configuration")
|
self.top.title("wlan configuration")
|
||||||
self.node_name = tk.StringVar()
|
self.node_name = tk.StringVar()
|
||||||
|
|
||||||
self.range_var = tk.DoubleVar()
|
# self.range_var = tk.DoubleVar()
|
||||||
self.range_var.set(275.0)
|
# self.range_var.set(275.0)
|
||||||
self.bandwidth_var = tk.IntVar()
|
self.config = config
|
||||||
self.bandwidth_var.set(54000000)
|
self.range_var = tk.StringVar()
|
||||||
|
self.range_var.set(config["basic_range"])
|
||||||
|
# self.bandwidth_var = tk.IntVar()
|
||||||
|
self.bandwidth_var = tk.StringVar()
|
||||||
|
self.bandwidth_var.set(config["bandwidth"])
|
||||||
|
|
||||||
self.delay_var = tk.StringVar()
|
self.delay_var = tk.StringVar()
|
||||||
|
|
||||||
|
@ -34,6 +45,11 @@ class WlanConfiguration:
|
||||||
self.config_option()
|
self.config_option()
|
||||||
|
|
||||||
def image_modification(self):
|
def image_modification(self):
|
||||||
|
"""
|
||||||
|
draw image modification part
|
||||||
|
|
||||||
|
:return: nothing
|
||||||
|
"""
|
||||||
f = tk.Frame(self.top, bg="#d9d9d9")
|
f = tk.Frame(self.top, bg="#d9d9d9")
|
||||||
lbl = tk.Label(f, text="Node name: ", bg="#d9d9d9")
|
lbl = tk.Label(f, text="Node name: ", bg="#d9d9d9")
|
||||||
lbl.grid(row=0, column=0, padx=3, pady=3)
|
lbl.grid(row=0, column=0, padx=3, pady=3)
|
||||||
|
@ -41,20 +57,40 @@ class WlanConfiguration:
|
||||||
e.grid(row=0, column=1, padx=3, pady=3)
|
e.grid(row=0, column=1, padx=3, pady=3)
|
||||||
b = tk.Button(f, text="None")
|
b = tk.Button(f, text="None")
|
||||||
b.grid(row=0, column=2, padx=3, pady=3)
|
b.grid(row=0, column=2, padx=3, pady=3)
|
||||||
b = tk.Button(f, text="not implemented")
|
b = tk.Button(
|
||||||
|
f,
|
||||||
|
image=self.image,
|
||||||
|
command=lambda: ImageModification(
|
||||||
|
canvas=self.canvas, canvas_node=self.canvas_node, node_config=self
|
||||||
|
),
|
||||||
|
)
|
||||||
b.grid(row=0, column=3, padx=3, pady=3)
|
b.grid(row=0, column=3, padx=3, pady=3)
|
||||||
f.grid(padx=2, pady=2, ipadx=2, ipady=2)
|
f.grid(padx=2, pady=2, ipadx=2, ipady=2)
|
||||||
|
|
||||||
def create_string_var(self, val):
|
def create_string_var(self, val):
|
||||||
|
"""
|
||||||
|
create string variable for convenience
|
||||||
|
|
||||||
|
:param str val: text value
|
||||||
|
:return: nothing
|
||||||
|
"""
|
||||||
v = tk.StringVar()
|
v = tk.StringVar()
|
||||||
v.set(val)
|
v.set(val)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
def scrollbar_command(self, entry_widget, delta, event):
|
def scrollbar_command(self, entry_widget, delta, event):
|
||||||
|
"""
|
||||||
|
change text in entry based on scrollbar action (click up or down)
|
||||||
|
|
||||||
|
:param tkinter.Entry entry_widget: entry needed for changing text
|
||||||
|
:param int or float delta: the amount to change
|
||||||
|
:param event: scrollbar event
|
||||||
|
:return: nothing
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
value = int(entry_widget.get())
|
value = int(entry_widget.get())
|
||||||
except ValueError:
|
except ValueError:
|
||||||
value = ast.literal_eval(entry_widget.get())
|
value = float(entry_widget.get())
|
||||||
entry_widget.delete(0, tk.END)
|
entry_widget.delete(0, tk.END)
|
||||||
if event == "-1":
|
if event == "-1":
|
||||||
entry_widget.insert(tk.END, str(round(value + delta, 1)))
|
entry_widget.insert(tk.END, str(round(value + delta, 1)))
|
||||||
|
@ -62,6 +98,11 @@ class WlanConfiguration:
|
||||||
entry_widget.insert(tk.END, str(round(value - delta, 1)))
|
entry_widget.insert(tk.END, str(round(value - delta, 1)))
|
||||||
|
|
||||||
def wlan_configuration(self):
|
def wlan_configuration(self):
|
||||||
|
"""
|
||||||
|
create wireless configuration table
|
||||||
|
|
||||||
|
:return: nothing
|
||||||
|
"""
|
||||||
lbl = tk.Label(self.top, text="Wireless")
|
lbl = tk.Label(self.top, text="Wireless")
|
||||||
lbl.grid(sticky=tk.W, padx=3, pady=3)
|
lbl.grid(sticky=tk.W, padx=3, pady=3)
|
||||||
|
|
||||||
|
@ -86,7 +127,12 @@ class WlanConfiguration:
|
||||||
lbl = tk.Label(f1, text="Range: ", bg="#d9d9d9")
|
lbl = tk.Label(f1, text="Range: ", bg="#d9d9d9")
|
||||||
lbl.grid(row=0, column=0)
|
lbl.grid(row=0, column=0)
|
||||||
|
|
||||||
e = tk.Entry(f1, textvariable=self.range_var, width=5, bg="white")
|
e = tk.Entry(
|
||||||
|
f1,
|
||||||
|
textvariable=self.create_string_var(self.config["basic_range"]),
|
||||||
|
width=5,
|
||||||
|
bg="white",
|
||||||
|
)
|
||||||
e.grid(row=0, column=1)
|
e.grid(row=0, column=1)
|
||||||
|
|
||||||
lbl = tk.Label(f1, text="Bandwidth (bps): ", bg="#d9d9d9")
|
lbl = tk.Label(f1, text="Bandwidth (bps): ", bg="#d9d9d9")
|
||||||
|
@ -94,7 +140,12 @@ class WlanConfiguration:
|
||||||
|
|
||||||
f11 = tk.Frame(f1, bg="#d9d9d9")
|
f11 = tk.Frame(f1, bg="#d9d9d9")
|
||||||
sb = tk.Scrollbar(f11, orient=tk.VERTICAL)
|
sb = tk.Scrollbar(f11, orient=tk.VERTICAL)
|
||||||
e = tk.Entry(f11, textvariable=self.bandwidth_var, width=10, bg="white")
|
e = tk.Entry(
|
||||||
|
f11,
|
||||||
|
textvariable=self.create_string_var(self.config["bandwidth"]),
|
||||||
|
width=10,
|
||||||
|
bg="white",
|
||||||
|
)
|
||||||
sb.config(command=partial(self.scrollbar_command, e, 1000000))
|
sb.config(command=partial(self.scrollbar_command, e, 1000000))
|
||||||
e.grid()
|
e.grid()
|
||||||
sb.grid(row=0, column=1)
|
sb.grid(row=0, column=1)
|
||||||
|
@ -110,7 +161,9 @@ class WlanConfiguration:
|
||||||
|
|
||||||
f21 = tk.Frame(f2, bg="#d9d9d9")
|
f21 = tk.Frame(f2, bg="#d9d9d9")
|
||||||
sb = tk.Scrollbar(f21, orient=tk.VERTICAL)
|
sb = tk.Scrollbar(f21, orient=tk.VERTICAL)
|
||||||
e = tk.Entry(f21, textvariable=self.create_string_var(20000), bg="white")
|
e = tk.Entry(
|
||||||
|
f21, textvariable=self.create_string_var(self.config["delay"]), bg="white"
|
||||||
|
)
|
||||||
sb.config(command=partial(self.scrollbar_command, e, 5000))
|
sb.config(command=partial(self.scrollbar_command, e, 5000))
|
||||||
e.grid()
|
e.grid()
|
||||||
sb.grid(row=0, column=1)
|
sb.grid(row=0, column=1)
|
||||||
|
@ -121,7 +174,9 @@ class WlanConfiguration:
|
||||||
|
|
||||||
f22 = tk.Frame(f2, bg="#d9d9d9")
|
f22 = tk.Frame(f2, bg="#d9d9d9")
|
||||||
sb = tk.Scrollbar(f22, orient=tk.VERTICAL)
|
sb = tk.Scrollbar(f22, orient=tk.VERTICAL)
|
||||||
e = tk.Entry(f22, textvariable=self.create_string_var(0), bg="white")
|
e = tk.Entry(
|
||||||
|
f22, textvariable=self.create_string_var(self.config["error"]), bg="white"
|
||||||
|
)
|
||||||
sb.config(command=partial(self.scrollbar_command, e, 0.1))
|
sb.config(command=partial(self.scrollbar_command, e, 0.1))
|
||||||
e.grid()
|
e.grid()
|
||||||
sb.grid(row=0, column=1)
|
sb.grid(row=0, column=1)
|
||||||
|
@ -136,7 +191,9 @@ class WlanConfiguration:
|
||||||
lbl.grid()
|
lbl.grid()
|
||||||
f31 = tk.Frame(f3, bg="#d9d9d9")
|
f31 = tk.Frame(f3, bg="#d9d9d9")
|
||||||
sb = tk.Scrollbar(f31, orient=tk.VERTICAL)
|
sb = tk.Scrollbar(f31, orient=tk.VERTICAL)
|
||||||
e = tk.Entry(f31, textvariable=self.create_string_var(0), bg="white")
|
e = tk.Entry(
|
||||||
|
f31, textvariable=self.create_string_var(self.config["jitter"]), bg="white"
|
||||||
|
)
|
||||||
sb.config(command=partial(self.scrollbar_command, e, 5000))
|
sb.config(command=partial(self.scrollbar_command, e, 5000))
|
||||||
e.grid()
|
e.grid()
|
||||||
sb.grid(row=0, column=1)
|
sb.grid(row=0, column=1)
|
||||||
|
@ -146,23 +203,33 @@ class WlanConfiguration:
|
||||||
f.grid(padx=3, pady=3)
|
f.grid(padx=3, pady=3)
|
||||||
|
|
||||||
def subnet(self):
|
def subnet(self):
|
||||||
|
"""
|
||||||
|
create the entries for ipv4 subnet and ipv6 subnet
|
||||||
|
|
||||||
|
:return: nothing
|
||||||
|
"""
|
||||||
f = tk.Frame(self.top)
|
f = tk.Frame(self.top)
|
||||||
f1 = tk.Frame(f)
|
f1 = tk.Frame(f)
|
||||||
lbl = tk.Label(f1, text="IPv4 subnet")
|
lbl = tk.Label(f1, text="IPv4 subnet")
|
||||||
lbl.grid()
|
lbl.grid()
|
||||||
e = tk.Entry(f1, width=30, bg="white")
|
e = tk.Entry(f1, width=30, bg="white", textvariable=self.create_string_var(""))
|
||||||
e.grid(row=0, column=1)
|
e.grid(row=0, column=1)
|
||||||
f1.grid()
|
f1.grid()
|
||||||
|
|
||||||
f2 = tk.Frame(f)
|
f2 = tk.Frame(f)
|
||||||
lbl = tk.Label(f2, text="IPv6 subnet")
|
lbl = tk.Label(f2, text="IPv6 subnet")
|
||||||
lbl.grid()
|
lbl.grid()
|
||||||
e = tk.Entry(f2, width=30, bg="white")
|
e = tk.Entry(f2, width=30, bg="white", textvariable=self.create_string_var(""))
|
||||||
e.grid(row=0, column=1)
|
e.grid(row=0, column=1)
|
||||||
f2.grid()
|
f2.grid()
|
||||||
f.grid(sticky=tk.W, padx=3, pady=3)
|
f.grid(sticky=tk.W, padx=3, pady=3)
|
||||||
|
|
||||||
def wlan_options(self):
|
def wlan_options(self):
|
||||||
|
"""
|
||||||
|
create wireless node options
|
||||||
|
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
f = tk.Frame(self.top)
|
f = tk.Frame(self.top)
|
||||||
b = tk.Button(f, text="ns-2 mobility script...")
|
b = tk.Button(f, text="ns-2 mobility script...")
|
||||||
b.pack(side=tk.LEFT, padx=1)
|
b.pack(side=tk.LEFT, padx=1)
|
||||||
|
@ -172,9 +239,60 @@ class WlanConfiguration:
|
||||||
b.pack(side=tk.LEFT, padx=1)
|
b.pack(side=tk.LEFT, padx=1)
|
||||||
f.grid(sticky=tk.W)
|
f.grid(sticky=tk.W)
|
||||||
|
|
||||||
|
def wlan_config_apply(self):
|
||||||
|
"""
|
||||||
|
retrieve user's wlan configuration and store the new configuration values
|
||||||
|
|
||||||
|
:return: nothing
|
||||||
|
"""
|
||||||
|
config_frame = self.top.grid_slaves(row=2, column=0)[0]
|
||||||
|
range_and_bandwidth_frame = config_frame.grid_slaves(row=1, column=0)[0]
|
||||||
|
range_val = range_and_bandwidth_frame.grid_slaves(row=0, column=1)[0].get()
|
||||||
|
bandwidth = (
|
||||||
|
range_and_bandwidth_frame.grid_slaves(row=0, column=3)[0]
|
||||||
|
.grid_slaves(row=0, column=0)[0]
|
||||||
|
.get()
|
||||||
|
)
|
||||||
|
|
||||||
|
delay_and_loss_frame = config_frame.grid_slaves(row=2, column=0)[0]
|
||||||
|
delay = (
|
||||||
|
delay_and_loss_frame.grid_slaves(row=0, column=1)[0]
|
||||||
|
.grid_slaves(row=0, column=0)[0]
|
||||||
|
.get()
|
||||||
|
)
|
||||||
|
loss = (
|
||||||
|
delay_and_loss_frame.grid_slaves(row=0, column=3)[0]
|
||||||
|
.grid_slaves(row=0, column=0)[0]
|
||||||
|
.get()
|
||||||
|
)
|
||||||
|
|
||||||
|
jitter_frame = config_frame.grid_slaves(row=3, column=0)[0]
|
||||||
|
jitter_val = (
|
||||||
|
jitter_frame.grid_slaves(row=0, column=1)[0]
|
||||||
|
.grid_slaves(row=0, column=0)[0]
|
||||||
|
.get()
|
||||||
|
)
|
||||||
|
|
||||||
|
# set wireless node configuration here
|
||||||
|
wlanconfig_manager = self.canvas.grpc_manager.wlanconfig_management
|
||||||
|
wlanconfig_manager.set_custom_config(
|
||||||
|
node_id=self.canvas_node.core_id,
|
||||||
|
range=range_val,
|
||||||
|
bandwidth=bandwidth,
|
||||||
|
jitter=jitter_val,
|
||||||
|
delay=delay,
|
||||||
|
error=loss,
|
||||||
|
)
|
||||||
|
self.top.destroy()
|
||||||
|
|
||||||
def config_option(self):
|
def config_option(self):
|
||||||
|
"""
|
||||||
|
create node configuration options
|
||||||
|
|
||||||
|
:return: nothing
|
||||||
|
"""
|
||||||
f = tk.Frame(self.top, bg="#d9d9d9")
|
f = tk.Frame(self.top, bg="#d9d9d9")
|
||||||
b = tk.Button(f, text="Apply", bg="#d9d9d9")
|
b = tk.Button(f, text="Apply", bg="#d9d9d9", command=self.wlan_config_apply)
|
||||||
b.grid(padx=2, pady=2)
|
b.grid(padx=2, pady=2)
|
||||||
b = tk.Button(f, text="Cancel", bg="#d9d9d9", command=self.top.destroy)
|
b = tk.Button(f, text="Cancel", bg="#d9d9d9", command=self.top.destroy)
|
||||||
b.grid(row=0, column=1, padx=2, pady=2)
|
b.grid(row=0, column=1, padx=2, pady=2)
|
||||||
|
|
29
coretk/coretk/wlannodeconfig.py
Normal file
29
coretk/coretk/wlannodeconfig.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
"""
|
||||||
|
wireless node configuration for all the wireless node
|
||||||
|
"""
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
from core.api.grpc import core_pb2
|
||||||
|
|
||||||
|
|
||||||
|
class WlanNodeConfig:
|
||||||
|
def __init__(self):
|
||||||
|
# maps node id to wlan configuration
|
||||||
|
self.configurations = {}
|
||||||
|
|
||||||
|
def set_default_config(self, node_type, node_id):
|
||||||
|
if node_type == core_pb2.NodeType.WIRELESS_LAN:
|
||||||
|
config = OrderedDict()
|
||||||
|
config["basic_range"] = "275"
|
||||||
|
config["bandwidth"] = "54000000"
|
||||||
|
config["jitter"] = "0"
|
||||||
|
config["delay"] = "20000"
|
||||||
|
config["error"] = "0"
|
||||||
|
self.configurations[node_id] = config
|
||||||
|
|
||||||
|
def set_custom_config(self, node_id, range, bandwidth, jitter, delay, error):
|
||||||
|
self.configurations[node_id]["basic_range"] = range
|
||||||
|
self.configurations[node_id]["bandwidth"] = bandwidth
|
||||||
|
self.configurations[node_id]["jitter"] = jitter
|
||||||
|
self.configurations[node_id]["delay"] = delay
|
||||||
|
self.configurations[node_id]["error"] = error
|
Loading…
Add table
Reference in a new issue