Merge branch 'coretk' of https://github.com/coreemu/core into coretk

This commit is contained in:
Blake Harnden 2019-12-10 19:25:20 -08:00
commit e5430ab5e7
8 changed files with 93 additions and 63 deletions

View file

@ -70,8 +70,6 @@ class CoreClient:
# helpers
self.interface_to_edge = {}
self.interfaces_manager = InterfaceManager(self.app)
self.created_nodes = set()
self.created_links = set()
# session data
self.state = None
@ -90,8 +88,6 @@ class CoreClient:
def reset(self):
# helpers
self.created_nodes.clear()
self.created_links.clear()
self.interfaces_manager.reset()
self.interface_to_edge.clear()
# session data
@ -181,7 +177,6 @@ class CoreClient:
canvas_node.move(x, y)
def handle_throughputs(self, event):
# print(event.interface_throughputs)
if self.throughput:
self.app.canvas.throughput_draw.process_grpc_throughput_event(
event.interface_throughputs
@ -243,8 +238,6 @@ class CoreClient:
# save and retrieve data, needed for session nodes
for node in session.nodes:
# get node service config and file config
self.created_nodes.add(node.id)
# get wlan configs for wlan nodes
if node.type == core_pb2.NodeType.WIRELESS_LAN:
response = self.client.get_wlan_config(self.session_id, node.id)
@ -436,8 +429,6 @@ class CoreClient:
hooks = list(self.hooks.values())
service_configs = self.get_service_config_proto()
file_configs = self.get_service_file_config_proto()
self.created_links.clear()
self.created_nodes.clear()
if self.emane_config:
emane_config = {x: self.emane_config[x].value for x in self.emane_config}
else:
@ -586,19 +577,11 @@ class CoreClient:
self.session_id, core_pb2.SessionState.DEFINITION
)
# temp
self.client.set_session_state(self.session_id, core_pb2.SessionState.DEFINITION)
for node_proto in node_protos:
if node_proto.id not in self.created_nodes or True:
response = self.client.add_node(self.session_id, node_proto)
logging.debug("create node: %s", response)
self.created_nodes.add(node_proto.id)
for link_proto in link_protos:
if (
tuple([link_proto.node_one_id, link_proto.node_two_id])
not in self.created_links
or True
):
response = self.client.add_link(
self.session_id,
link_proto.node_one_id,
@ -608,9 +591,6 @@ class CoreClient:
link_proto.options,
)
logging.debug("create link: %s", response)
self.created_links.add(
tuple([link_proto.node_one_id, link_proto.node_two_id])
)
def close(self):
"""

View file

@ -66,7 +66,7 @@ class SizeAndScaleDialog(Dialog):
validate="key",
validatecommand=(self.validation.positive_int, "%P"),
)
entry.bind("<FocusOut>", self.validation.focus_out)
entry.bind("<FocusOut>", lambda event: self.validation.focus_out(event, "0"))
entry.grid(row=0, column=1, sticky="ew", padx=PAD)
label = ttk.Label(frame, text="x Height")
label.grid(row=0, column=2, sticky="w", padx=PAD)
@ -76,7 +76,7 @@ class SizeAndScaleDialog(Dialog):
validate="key",
validatecommand=(self.validation.positive_int, "%P"),
)
entry.bind("<FocusOut>", self.validation.focus_out)
entry.bind("<FocusOut>", lambda event: self.validation.focus_out(event, "0"))
entry.grid(row=0, column=3, sticky="ew", padx=PAD)
label = ttk.Label(frame, text="Pixels")
label.grid(row=0, column=4, sticky="w")
@ -94,7 +94,7 @@ class SizeAndScaleDialog(Dialog):
validate="key",
validatecommand=(self.validation.positive_float, "%P"),
)
entry.bind("<FocusOut>", self.validation.focus_out)
entry.bind("<FocusOut>", lambda event: self.validation.focus_out(event, "0"))
entry.grid(row=0, column=1, sticky="ew", padx=PAD)
label = ttk.Label(frame, text="x Height")
label.grid(row=0, column=2, sticky="w", padx=PAD)
@ -104,7 +104,7 @@ class SizeAndScaleDialog(Dialog):
validate="key",
validatecommand=(self.validation.positive_float, "%P"),
)
entry.bind("<FocusOut>", self.validation.focus_out)
entry.bind("<FocusOut>", lambda event: self.validation.focus_out(event, "0"))
entry.grid(row=0, column=3, sticky="ew", padx=PAD)
label = ttk.Label(frame, text="Meters")
label.grid(row=0, column=4, sticky="w")
@ -125,7 +125,7 @@ class SizeAndScaleDialog(Dialog):
validate="key",
validatecommand=(self.validation.positive_float, "%P"),
)
entry.bind("<FocusOut>", self.validation.focus_out)
entry.bind("<FocusOut>", lambda event: self.validation.focus_out(event, "0"))
entry.grid(row=0, column=1, sticky="ew", padx=PAD)
label = ttk.Label(frame, text="Meters")
label.grid(row=0, column=2, sticky="w")
@ -153,7 +153,7 @@ class SizeAndScaleDialog(Dialog):
validate="key",
validatecommand=(self.validation.positive_float, "%P"),
)
entry.bind("<FocusOut>", self.validation.focus_out)
entry.bind("<FocusOut>", lambda event: self.validation.focus_out(event, "0"))
entry.grid(row=0, column=1, sticky="ew", padx=PAD)
label = ttk.Label(frame, text="Y")
@ -164,7 +164,7 @@ class SizeAndScaleDialog(Dialog):
validate="key",
validatecommand=(self.validation.positive_float, "%P"),
)
entry.bind("<FocusOut>", self.validation.focus_out)
entry.bind("<FocusOut>", lambda event: self.validation.focus_out(event, "0"))
entry.grid(row=0, column=3, sticky="ew", padx=PAD)
label = ttk.Label(label_frame, text="Translates To")
@ -184,7 +184,7 @@ class SizeAndScaleDialog(Dialog):
validate="key",
validatecommand=(self.validation.positive_float, "%P"),
)
entry.bind("<FocusOut>", self.validation.focus_out)
entry.bind("<FocusOut>", lambda event: self.validation.focus_out(event, "0"))
entry.grid(row=0, column=1, sticky="ew", padx=PAD)
label = ttk.Label(frame, text="Lon")
@ -195,7 +195,7 @@ class SizeAndScaleDialog(Dialog):
validate="key",
validatecommand=(self.validation.positive_float, "%P"),
)
entry.bind("<FocusOut>", self.validation.focus_out)
entry.bind("<FocusOut>", lambda event: self.validation.focus_out(event, "0"))
entry.grid(row=0, column=3, sticky="ew", padx=PAD)
label = ttk.Label(frame, text="Alt")
@ -206,7 +206,7 @@ class SizeAndScaleDialog(Dialog):
validate="key",
validatecommand=(self.validation.positive_float, "%P"),
)
entry.bind("<FocusOut>", self.validation.focus_out)
entry.bind("<FocusOut>", lambda event: self.validation.focus_out(event, "0"))
entry.grid(row=0, column=5, sticky="ew")
def draw_save_as_default(self):

View file

@ -75,7 +75,9 @@ class NodeConfigDialog(Dialog):
validate="key",
validatecommand=(self.app.validation.name, "%P"),
)
entry.bind("<FocusOut>", self.app.validation.name_focus_out)
entry.bind(
"<FocusOut>", lambda event: self.app.validation.focus_out(event, "noname")
)
entry.grid(row=row, column=1, sticky="ew")
row += 1
@ -165,12 +167,14 @@ class NodeConfigDialog(Dialog):
label.grid(row=1, column=0, padx=PAD, pady=PAD)
ip4 = tk.StringVar(value=f"{interface.ip4}/{interface.ip4mask}")
entry = ttk.Entry(frame, textvariable=ip4)
entry.bind("<FocusOut>", self.app.validation.ip_focus_out)
entry.grid(row=1, column=1, columnspan=2, sticky="ew")
label = ttk.Label(frame, text="IPv6")
label.grid(row=2, column=0, padx=PAD, pady=PAD)
ip6 = tk.StringVar(value=f"{interface.ip6}/{interface.ip6mask}")
entry = ttk.Entry(frame, textvariable=ip6)
entry.bind("<FocusOut>", self.app.validation.ip_focus_out)
entry.grid(row=2, column=1, columnspan=2, sticky="ew")
self.interfaces[interface.id] = InterfaceData(is_auto, mac, ip4, ip6)

View file

@ -72,7 +72,15 @@ class ServersDialog(Dialog):
label = ttk.Label(frame, text="Port")
label.grid(row=0, column=4, sticky="w")
entry = ttk.Entry(frame, textvariable=self.port)
entry = ttk.Entry(
frame,
textvariable=self.port,
validate="key",
validatecommand=(self.app.validation.positive_int, "%P"),
)
entry.bind(
"<FocusOut>", lambda event: self.app.validation.focus_out(event, "50051")
)
entry.grid(row=0, column=5, sticky="ew")
def draw_servers_buttons(self):

View file

@ -51,7 +51,6 @@ class ServiceConfiguration(Dialog):
def load(self):
try:
# create nodes and links in definition state for getting and setting service file
self.app.core.create_nodes_and_links()
service_configs = self.app.core.service_configs
if (

View file

@ -7,6 +7,7 @@ from core.api.grpc.core_pb2 import NodeType
from coretk.dialogs.emaneconfig import EmaneConfigDialog
from coretk.dialogs.mobilityconfig import MobilityConfigDialog
from coretk.dialogs.nodeconfig import NodeConfigDialog
from coretk.dialogs.nodeservice import NodeService
from coretk.dialogs.wlanconfig import WlanConfigDialog
from coretk.errors import show_grpc_error
from coretk.graph import tags
@ -179,7 +180,7 @@ class CanvasNode:
else:
context.add_command(label="Configure", command=self.show_config)
if NodeUtils.is_container_node(self.core_node.type):
context.add_command(label="Services", state=tk.DISABLED)
context.add_command(label="Services", command=self.show_services)
if is_emane:
context.add_command(
label="EMANE Config", command=self.show_emane_config
@ -227,3 +228,8 @@ class CanvasNode:
self.canvas.context = None
dialog = EmaneConfigDialog(self.app, self.app, self)
dialog.show()
def show_services(self):
self.canvas.context = None
dialog = NodeService(self.app.master, self.app, self)
dialog.show()

View file

@ -1,9 +1,12 @@
"""
input validation
"""
import logging
import re
import tkinter as tk
import netaddr
from netaddr import IPNetwork
class InputValidation:
def __init__(self, app):
@ -11,26 +14,29 @@ class InputValidation:
self.positive_int = None
self.positive_float = None
self.name = None
self.ip4 = None
self.register()
def register(self):
self.positive_int = self.master.register(self.check_positive_int)
self.positive_float = self.master.register(self.check_positive_float)
self.name = self.master.register(self.check_node_name)
self.ip4 = self.master.register(self.check_ip4)
def focus_out(self, event):
def ip_focus_out(self, event):
value = event.widget.get()
try:
IPNetwork(value)
except netaddr.core.AddrFormatError:
event.widget.delete(0, tk.END)
event.widget.insert(tk.END, "invalid")
def focus_out(self, event, default):
value = event.widget.get()
if value == "":
event.widget.insert(tk.END, 0)
def name_focus_out(self, event):
logging.debug("name focus out")
value = event.widget.get()
if value == "":
event.widget.insert(tk.END, "empty")
event.widget.insert(tk.END, default)
def check_positive_int(self, s):
logging.debug("int validation...")
if len(s) == 0:
return True
try:
@ -42,7 +48,6 @@ class InputValidation:
return False
def check_positive_float(self, s):
logging.debug("float validation...")
if len(s) == 0:
return True
try:
@ -54,7 +59,6 @@ class InputValidation:
return False
def check_node_name(self, s):
logging.debug("node name validation...")
if len(s) < 0:
return False
if len(s) == 0:
@ -65,7 +69,6 @@ class InputValidation:
return True
def check_canvas_int(sefl, s):
logging.debug("int validation...")
if len(s) == 0:
return True
try:
@ -77,7 +80,6 @@ class InputValidation:
return False
def check_canvas_float(self, s):
logging.debug("canvas float validation")
if not s:
return True
try:
@ -87,3 +89,18 @@ class InputValidation:
return False
except ValueError:
return False
def check_ip4(self, s):
if not s:
return True
pat = re.compile("^([0-9]+[.])*[0-9]*$")
if pat.match(s) is not None:
_32bits = s.split(".")
if len(_32bits) > 4:
return False
for _8bits in _32bits:
if (_8bits and int(_8bits) > 255) or len(_8bits) > 3:
return False
return True
else:
return False

View file

@ -116,9 +116,19 @@ class ConfigFrame(FrameScroll):
func = partial(file_button_click, value)
button = ttk.Button(file_frame, text="...", command=func)
button.grid(row=0, column=1)
else:
if "controlnet" in option.name and "script" not in option.name:
entry = ttk.Entry(
frame,
textvariable=value,
validate="key",
validatecommand=(self.app.validation.ip4, "%P"),
)
entry.grid(row=index, column=1, sticky="ew", pady=pady)
else:
entry = ttk.Entry(frame, textvariable=value)
entry.grid(row=index, column=1, sticky="ew", pady=pady)
elif option.type in INT_TYPES:
value.set(option.value)
entry = ttk.Entry(
@ -127,7 +137,10 @@ class ConfigFrame(FrameScroll):
validate="key",
validatecommand=(self.app.validation.positive_int, "%P"),
)
entry.bind("<FocusOut>", self.app.validation.focus_out)
entry.bind(
"<FocusOut>",
lambda event: self.app.validation.focus_out(event, "0"),
)
entry.grid(row=index, column=1, sticky="ew", pady=pady)
elif option.type == core_pb2.ConfigOptionType.FLOAT:
value.set(option.value)
@ -137,7 +150,10 @@ class ConfigFrame(FrameScroll):
validate="key",
validatecommand=(self.app.validation.positive_float, "%P"),
)
entry.bind("<FocusOut>", self.app.validation.focus_out)
entry.bind(
"<FocusOut>",
lambda event: self.app.validation.focus_out(event, "0"),
)
entry.grid(row=index, column=1, sticky="ew", pady=pady)
else:
logging.error("unhandled config option type: %s", option.type)