Merge branch 'coretk' into coretk-progress
This commit is contained in:
commit
3493b05eb4
6 changed files with 70 additions and 130 deletions
|
@ -84,7 +84,6 @@ class CoreClient:
|
|||
self.interface_to_edge.clear()
|
||||
# session data
|
||||
self.canvas_nodes.clear()
|
||||
self.location = None
|
||||
self.links.clear()
|
||||
self.hooks.clear()
|
||||
self.wlan_configs.clear()
|
||||
|
@ -186,6 +185,15 @@ class CoreClient:
|
|||
self.emane_config = response.config
|
||||
|
||||
# get emane model config
|
||||
response = self.client.get_emane_model_configs(self.session_id)
|
||||
for _id in response.configs:
|
||||
config = response.configs[_id]
|
||||
interface = None
|
||||
node_id = _id
|
||||
if _id >= 1000:
|
||||
interface = _id % 1000
|
||||
node_id = int(_id / 1000)
|
||||
self.set_emane_model_config(node_id, config.model, config.config, interface)
|
||||
|
||||
# draw session
|
||||
self.app.canvas.reset_and_redraw(session)
|
||||
|
@ -251,7 +259,6 @@ class CoreClient:
|
|||
dialog.show()
|
||||
|
||||
response = self.client.get_service_defaults(self.session_id)
|
||||
logging.debug("get service defaults: %s", response)
|
||||
self.default_services = {
|
||||
x.node_type: set(x.services) for x in response.defaults
|
||||
}
|
||||
|
@ -565,6 +572,8 @@ class CoreClient:
|
|||
for key, config in self.emane_model_configs.items():
|
||||
node_id, model, interface = key
|
||||
config = {x: config[x].value for x in config}
|
||||
if interface is None:
|
||||
interface = -1
|
||||
config_proto = core_pb2.EmaneModelConfig(
|
||||
node_id=node_id, interface_id=interface, model=model, config=config
|
||||
)
|
||||
|
@ -615,6 +624,7 @@ class CoreClient:
|
|||
return config
|
||||
|
||||
def get_emane_model_config(self, node_id, model, interface=None):
|
||||
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:
|
||||
if interface is None:
|
||||
|
@ -626,4 +636,5 @@ class CoreClient:
|
|||
return config
|
||||
|
||||
def set_emane_model_config(self, node_id, model, config, interface=None):
|
||||
logging.info("setting emane model config: %s %s %s", node_id, model, interface)
|
||||
self.emane_model_configs[(node_id, model, interface)] = config
|
||||
|
|
|
@ -95,10 +95,7 @@ class EmaneConfigDialog(Dialog):
|
|||
self.radiovar = tk.IntVar()
|
||||
self.radiovar.set(1)
|
||||
self.emane_models = [x.split("_")[1] for x in self.app.core.emane_models]
|
||||
emane_model = None
|
||||
if self.emane_models:
|
||||
emane_model = self.emane_models[0]
|
||||
self.emane_model = tk.StringVar(value=emane_model)
|
||||
self.emane_model = tk.StringVar(value=self.node.emane.split("_")[1])
|
||||
self.emane_model_button = None
|
||||
self.draw()
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@ class CanvasGraph(tk.Canvas):
|
|||
# draw existing nodes
|
||||
for core_node in session.nodes:
|
||||
# peer to peer node is not drawn on the GUI
|
||||
if core_node.type == core_pb2.NodeType.PEER_TO_PEER:
|
||||
if NodeUtils.is_ignore_node(core_node.type):
|
||||
continue
|
||||
|
||||
# draw nodes on the canvas
|
||||
|
@ -200,31 +200,11 @@ class CanvasGraph(tk.Canvas):
|
|||
self.edges[edge.token] = edge
|
||||
self.core.links[edge.token] = link
|
||||
self.helper.redraw_antenna(canvas_node_one, canvas_node_two)
|
||||
|
||||
# TODO add back the link info to grpc manager also redraw
|
||||
# TODO will include throughput and ipv6 in the future
|
||||
interface_one = link.interface_one
|
||||
interface_two = link.interface_two
|
||||
ip4_src = None
|
||||
ip4_dst = None
|
||||
ip6_src = None
|
||||
ip6_dst = None
|
||||
if interface_one is not None:
|
||||
ip4_src = interface_one.ip4
|
||||
ip6_src = interface_one.ip6
|
||||
if interface_two is not None:
|
||||
ip4_dst = interface_two.ip4
|
||||
ip6_dst = interface_two.ip6
|
||||
edge.link_info = LinkInfo(
|
||||
canvas=self,
|
||||
edge=edge,
|
||||
ip4_src=ip4_src,
|
||||
ip6_src=ip6_src,
|
||||
ip4_dst=ip4_dst,
|
||||
ip6_dst=ip6_dst,
|
||||
)
|
||||
canvas_node_one.interfaces.append(interface_one)
|
||||
canvas_node_two.interfaces.append(interface_two)
|
||||
edge.link_info = LinkInfo(self, edge, link)
|
||||
if link.HasField("interface_one"):
|
||||
canvas_node_one.interfaces.append(link.interface_one)
|
||||
if link.HasField("interface_two"):
|
||||
canvas_node_two.interfaces.append(link.interface_two)
|
||||
|
||||
# raise the nodes so they on top of the links
|
||||
self.tag_raise("node")
|
||||
|
@ -320,25 +300,7 @@ class CanvasGraph(tk.Canvas):
|
|||
node_dst = self.nodes[edge.dst]
|
||||
node_dst.edges.add(edge)
|
||||
link = self.core.create_link(edge, node_src, node_dst)
|
||||
|
||||
# draw link info on the edge
|
||||
ip4_and_prefix_1 = None
|
||||
ip4_and_prefix_2 = None
|
||||
if link.HasField("interface_one"):
|
||||
if1 = link.interface_one
|
||||
ip4_and_prefix_1 = f"{if1.ip4}/{if1.ip4mask}"
|
||||
if link.HasField("interface_two"):
|
||||
if2 = link.interface_two
|
||||
ip4_and_prefix_2 = f"{if2.ip4}/{if2.ip4mask}"
|
||||
edge.link_info = LinkInfo(
|
||||
self,
|
||||
edge,
|
||||
ip4_src=ip4_and_prefix_1,
|
||||
ip6_src=None,
|
||||
ip4_dst=ip4_and_prefix_2,
|
||||
ip6_dst=None,
|
||||
)
|
||||
|
||||
edge.link_info = LinkInfo(self, edge, link)
|
||||
logging.debug(f"edges: {self.find_withtag('edge')}")
|
||||
|
||||
def click_press(self, event):
|
||||
|
@ -674,7 +636,7 @@ class CanvasNode:
|
|||
|
||||
new_x, new_y = self.canvas.coords(self.id)
|
||||
|
||||
if self.canvas.core.get_session_state() == core_pb2.SessionState.RUNTIME:
|
||||
if self.canvas.core.is_runtime():
|
||||
self.canvas.core.edit_node(self.core_node.id, int(new_x), int(new_y))
|
||||
|
||||
for edge in self.edges:
|
||||
|
|
|
@ -3,76 +3,60 @@ Link information, such as IPv4, IPv6 and throughput drawn in the canvas
|
|||
"""
|
||||
import logging
|
||||
import math
|
||||
import tkinter as tk
|
||||
|
||||
TEXT_DISTANCE = 0.33
|
||||
|
||||
|
||||
class LinkInfo:
|
||||
def __init__(self, canvas, edge, ip4_src, ip6_src, ip4_dst, ip6_dst):
|
||||
def __init__(self, canvas, edge, link):
|
||||
"""
|
||||
create an instance of LinkInfo object
|
||||
:param coretk.graph.Graph canvas: canvas object
|
||||
:param coretk.graph.CanvasEdge edge: canvas edge onject
|
||||
:param ip4_src:
|
||||
:param ip6_src:
|
||||
:param ip4_dst:
|
||||
:param ip6_dst:
|
||||
:param link: core link to draw info for
|
||||
"""
|
||||
self.canvas = canvas
|
||||
self.edge = edge
|
||||
self.radius = 37
|
||||
self.core = self.canvas.core
|
||||
self.link = link
|
||||
self.id1 = None
|
||||
self.id2 = None
|
||||
self.draw_labels()
|
||||
|
||||
self.ip4_address_1 = ip4_src
|
||||
self.ip6_address_1 = ip6_src
|
||||
self.ip4_address_2 = ip4_dst
|
||||
self.ip6_address_2 = ip6_dst
|
||||
self.id1 = self.create_edge_src_info()
|
||||
self.id2 = self.create_edge_dst_info()
|
||||
|
||||
def slope_src_dst(self):
|
||||
"""
|
||||
calculate slope of the line connecting source node to destination node
|
||||
:rtype: float
|
||||
:return: slope of line
|
||||
"""
|
||||
def get_coordinates(self):
|
||||
x1, y1, x2, y2 = self.canvas.coords(self.edge.id)
|
||||
if x2 - x1 == 0:
|
||||
return 9999.0
|
||||
else:
|
||||
return (y2 - y1) / (x2 - x1)
|
||||
v1 = x2 - x1
|
||||
v2 = y2 - y1
|
||||
d = math.sqrt(v1 ** 2 + v2 ** 2)
|
||||
ux = TEXT_DISTANCE * v1
|
||||
uy = TEXT_DISTANCE * v2
|
||||
x1 = x1 + ux
|
||||
y1 = y1 + uy
|
||||
x2 = x2 - ux
|
||||
y2 = y2 - uy
|
||||
logging.info("line distance: %s", d)
|
||||
return x1, y1, x2, y2
|
||||
|
||||
def create_edge_src_info(self):
|
||||
"""
|
||||
draw the ip address for source node
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
x1, y1, x2, _ = self.canvas.coords(self.edge.id)
|
||||
m = self.slope_src_dst()
|
||||
distance = math.cos(math.atan(m)) * self.radius
|
||||
if x1 > x2:
|
||||
distance = -distance
|
||||
# id1 = self.canvas.create_text(x1, y1, text=self.ip4_address_1)
|
||||
id1 = self.canvas.create_text(
|
||||
x1 + distance, y1 + distance * m, text=self.ip4_address_1, tags="linkinfo"
|
||||
def draw_labels(self):
|
||||
x1, y1, x2, y2 = self.get_coordinates()
|
||||
label_one = None
|
||||
if self.link.HasField("interface_one"):
|
||||
label_one = (
|
||||
f"{self.link.interface_one.ip4}/{self.link.interface_one.ip4mask}\n"
|
||||
f"{self.link.interface_one.ip6}/{self.link.interface_one.ip6mask}\n"
|
||||
)
|
||||
label_two = None
|
||||
if self.link.HasField("interface_two"):
|
||||
label_two = (
|
||||
f"{self.link.interface_two.ip4}/{self.link.interface_two.ip4mask}\n"
|
||||
f"{self.link.interface_two.ip6}/{self.link.interface_two.ip6mask}\n"
|
||||
)
|
||||
self.id1 = self.canvas.create_text(
|
||||
x1, y1, text=label_one, justify=tk.CENTER, tags="linkinfo"
|
||||
)
|
||||
return id1
|
||||
|
||||
def create_edge_dst_info(self):
|
||||
"""
|
||||
draw the ip address for destination node
|
||||
|
||||
:return: nothing
|
||||
"""
|
||||
x1, _, x2, y2 = self.canvas.coords(self.edge.id)
|
||||
m = self.slope_src_dst()
|
||||
distance = math.cos(math.atan(m)) * self.radius
|
||||
if x1 > x2:
|
||||
distance = -distance
|
||||
# id2 = self.canvas.create_text(x2, y2, text=self.ip4_address_2)
|
||||
id2 = self.canvas.create_text(
|
||||
x2 - distance, y2 - distance * m, text=self.ip4_address_2, tags="linkinfo"
|
||||
self.id2 = self.canvas.create_text(
|
||||
x2, y2, text=label_two, justify=tk.CENTER, tags="linkinfo"
|
||||
)
|
||||
return id2
|
||||
|
||||
def recalculate_info(self):
|
||||
"""
|
||||
|
@ -80,32 +64,13 @@ class LinkInfo:
|
|||
|
||||
:return: nothing
|
||||
"""
|
||||
x1, y1, x2, y2 = self.canvas.coords(self.edge.id)
|
||||
m = self.slope_src_dst()
|
||||
distance = math.cos(math.atan(m)) * self.radius
|
||||
if x1 > x2:
|
||||
distance = -distance
|
||||
new_x1 = x1 + distance
|
||||
new_y1 = y1 + distance * m
|
||||
new_x2 = x2 - distance
|
||||
new_y2 = y2 - distance * m
|
||||
self.canvas.coords(self.id1, new_x1, new_y1)
|
||||
self.canvas.coords(self.id2, new_x2, new_y2)
|
||||
|
||||
# def link_througput(self):
|
||||
# x1, y1, x2, y2 = self.canvas.coords(self.edge.id)
|
||||
# x = (x1 + x2) / 2
|
||||
# y = (y1 + y2) / 2
|
||||
# tid = self.canvas.create_text(x, y, text="place text here")
|
||||
# return tid
|
||||
x1, y1, x2, y2 = self.get_coordinates()
|
||||
self.canvas.coords(self.id1, x1, y1)
|
||||
self.canvas.coords(self.id2, x2, y2)
|
||||
|
||||
|
||||
class Throughput:
|
||||
def __init__(self, canvas, core):
|
||||
"""
|
||||
create an instance of Throughput object
|
||||
:param coretk.app.Application app: application
|
||||
"""
|
||||
self.canvas = canvas
|
||||
self.core = core
|
||||
# edge canvas id mapped to throughput value
|
||||
|
|
|
@ -47,8 +47,13 @@ class NodeUtils:
|
|||
CONTAINER_NODES = {NodeType.DEFAULT, NodeType.DOCKER, NodeType.LXC}
|
||||
IMAGE_NODES = {NodeType.DOCKER, NodeType.LXC}
|
||||
WIRELESS_NODES = {NodeType.WIRELESS_LAN, NodeType.EMANE}
|
||||
IGNORE_NODES = {NodeType.CONTROL_NET, NodeType.PEER_TO_PEER}
|
||||
NODE_MODELS = {"router", "host", "PC", "mdr", "prouter"}
|
||||
|
||||
@classmethod
|
||||
def is_ignore_node(cls, node_type):
|
||||
return node_type in cls.IGNORE_NODES
|
||||
|
||||
@classmethod
|
||||
def is_container_node(cls, node_type):
|
||||
return node_type in cls.CONTAINER_NODES
|
||||
|
|
|
@ -25,7 +25,7 @@ class EmaneNet(CoreNetworkBase):
|
|||
"""
|
||||
|
||||
apitype = NodeTypes.EMANE.value
|
||||
linktype = LinkTypes.WIRELESS.value
|
||||
linktype = LinkTypes.WIRED.value
|
||||
type = "wlan"
|
||||
is_emane = True
|
||||
|
||||
|
|
Loading…
Reference in a new issue