linkinfo cleanup, changed text distance to be proprotionate of line distance
This commit is contained in:
parent
3d2e372663
commit
e3fc318a1b
2 changed files with 48 additions and 121 deletions
|
@ -200,31 +200,11 @@ class CanvasGraph(tk.Canvas):
|
||||||
self.edges[edge.token] = edge
|
self.edges[edge.token] = edge
|
||||||
self.core.links[edge.token] = link
|
self.core.links[edge.token] = link
|
||||||
self.helper.redraw_antenna(canvas_node_one, canvas_node_two)
|
self.helper.redraw_antenna(canvas_node_one, canvas_node_two)
|
||||||
|
edge.link_info = LinkInfo(self, edge, link)
|
||||||
# TODO add back the link info to grpc manager also redraw
|
if link.HasField("interface_one"):
|
||||||
# TODO will include throughput and ipv6 in the future
|
canvas_node_one.interfaces.append(link.interface_one)
|
||||||
interface_one = link.interface_one
|
if link.HasField("interface_two"):
|
||||||
interface_two = link.interface_two
|
canvas_node_two.interfaces.append(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)
|
|
||||||
|
|
||||||
# raise the nodes so they on top of the links
|
# raise the nodes so they on top of the links
|
||||||
self.tag_raise("node")
|
self.tag_raise("node")
|
||||||
|
@ -320,25 +300,7 @@ class CanvasGraph(tk.Canvas):
|
||||||
node_dst = self.nodes[edge.dst]
|
node_dst = self.nodes[edge.dst]
|
||||||
node_dst.edges.add(edge)
|
node_dst.edges.add(edge)
|
||||||
link = self.core.create_link(edge, node_src, node_dst)
|
link = self.core.create_link(edge, node_src, node_dst)
|
||||||
|
edge.link_info = LinkInfo(self, edge, link)
|
||||||
# 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,
|
|
||||||
)
|
|
||||||
|
|
||||||
logging.debug(f"edges: {self.find_withtag('edge')}")
|
logging.debug(f"edges: {self.find_withtag('edge')}")
|
||||||
|
|
||||||
def click_press(self, event):
|
def click_press(self, event):
|
||||||
|
|
|
@ -3,76 +3,60 @@ Link information, such as IPv4, IPv6 and throughput drawn in the canvas
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
|
import tkinter as tk
|
||||||
|
|
||||||
|
TEXT_DISTANCE = 0.25
|
||||||
|
|
||||||
|
|
||||||
class LinkInfo:
|
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
|
create an instance of LinkInfo object
|
||||||
:param coretk.graph.Graph canvas: canvas object
|
:param coretk.graph.Graph canvas: canvas object
|
||||||
:param coretk.graph.CanvasEdge edge: canvas edge onject
|
:param coretk.graph.CanvasEdge edge: canvas edge onject
|
||||||
:param ip4_src:
|
:param link: core link to draw info for
|
||||||
:param ip6_src:
|
|
||||||
:param ip4_dst:
|
|
||||||
:param ip6_dst:
|
|
||||||
"""
|
"""
|
||||||
self.canvas = canvas
|
self.canvas = canvas
|
||||||
self.edge = edge
|
self.edge = edge
|
||||||
self.radius = 37
|
self.link = link
|
||||||
self.core = self.canvas.core
|
self.id1 = None
|
||||||
|
self.id2 = None
|
||||||
|
self.draw_labels()
|
||||||
|
|
||||||
self.ip4_address_1 = ip4_src
|
def get_coordinates(self):
|
||||||
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
|
|
||||||
"""
|
|
||||||
x1, y1, x2, y2 = self.canvas.coords(self.edge.id)
|
x1, y1, x2, y2 = self.canvas.coords(self.edge.id)
|
||||||
if x2 - x1 == 0:
|
v1 = x2 - x1
|
||||||
return 9999.0
|
v2 = y2 - y1
|
||||||
else:
|
d = math.sqrt(v1 ** 2 + v2 ** 2)
|
||||||
return (y2 - y1) / (x2 - x1)
|
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):
|
def draw_labels(self):
|
||||||
"""
|
x1, y1, x2, y2 = self.get_coordinates()
|
||||||
draw the ip address for source node
|
label_one = None
|
||||||
|
if self.link.HasField("interface_one"):
|
||||||
:return: nothing
|
label_one = (
|
||||||
"""
|
f"{self.link.interface_one.ip4}/{self.link.interface_one.ip4mask}\n"
|
||||||
x1, y1, x2, _ = self.canvas.coords(self.edge.id)
|
f"{self.link.interface_one.ip6}/{self.link.interface_one.ip6mask}\n"
|
||||||
m = self.slope_src_dst()
|
)
|
||||||
distance = math.cos(math.atan(m)) * self.radius
|
label_two = None
|
||||||
if x1 > x2:
|
if self.link.HasField("interface_two"):
|
||||||
distance = -distance
|
label_two = (
|
||||||
# id1 = self.canvas.create_text(x1, y1, text=self.ip4_address_1)
|
f"{self.link.interface_two.ip4}/{self.link.interface_two.ip4mask}\n"
|
||||||
id1 = self.canvas.create_text(
|
f"{self.link.interface_two.ip6}/{self.link.interface_two.ip6mask}\n"
|
||||||
x1 + distance, y1 + distance * m, text=self.ip4_address_1, tags="linkinfo"
|
)
|
||||||
|
self.id1 = self.canvas.create_text(
|
||||||
|
x1, y1, text=label_one, justify=tk.CENTER, tags="linkinfo"
|
||||||
)
|
)
|
||||||
return id1
|
self.id2 = self.canvas.create_text(
|
||||||
|
x2, y2, text=label_two, justify=tk.CENTER, tags="linkinfo"
|
||||||
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"
|
|
||||||
)
|
)
|
||||||
return id2
|
|
||||||
|
|
||||||
def recalculate_info(self):
|
def recalculate_info(self):
|
||||||
"""
|
"""
|
||||||
|
@ -80,32 +64,13 @@ class LinkInfo:
|
||||||
|
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
x1, y1, x2, y2 = self.canvas.coords(self.edge.id)
|
x1, y1, x2, y2 = self.get_coordinates()
|
||||||
m = self.slope_src_dst()
|
self.canvas.coords(self.id1, x1, y1)
|
||||||
distance = math.cos(math.atan(m)) * self.radius
|
self.canvas.coords(self.id2, x2, y2)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class Throughput:
|
class Throughput:
|
||||||
def __init__(self, canvas, core):
|
def __init__(self, canvas, core):
|
||||||
"""
|
|
||||||
create an instance of Throughput object
|
|
||||||
:param coretk.app.Application app: application
|
|
||||||
"""
|
|
||||||
self.canvas = canvas
|
self.canvas = canvas
|
||||||
self.core = core
|
self.core = core
|
||||||
# edge canvas id mapped to throughput value
|
# edge canvas id mapped to throughput value
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue