2020-12-31 06:11:45 +00:00
|
|
|
import functools
|
2019-12-17 19:47:05 +00:00
|
|
|
import logging
|
2020-04-14 18:47:42 +01:00
|
|
|
import math
|
2019-12-05 19:12:25 +00:00
|
|
|
import tkinter as tk
|
2021-01-02 20:59:15 +00:00
|
|
|
from typing import TYPE_CHECKING, Optional, Tuple, Union
|
2019-12-05 19:12:25 +00:00
|
|
|
|
2020-08-27 19:02:02 +01:00
|
|
|
from core.api.grpc.wrappers import Interface, Link
|
2019-12-19 17:30:21 +00:00
|
|
|
from core.gui import themes
|
2019-12-19 17:50:58 +00:00
|
|
|
from core.gui.dialogs.linkconfig import LinkConfigurationDialog
|
2020-06-26 17:13:38 +01:00
|
|
|
from core.gui.frames.link import EdgeInfoFrame, WirelessEdgeInfoFrame
|
2019-12-19 17:30:21 +00:00
|
|
|
from core.gui.graph import tags
|
2020-08-02 18:03:21 +01:00
|
|
|
from core.gui.utils import bandwidth_text, delay_jitter_text
|
2019-12-06 00:37:48 +00:00
|
|
|
|
2021-04-22 05:09:35 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2020-01-14 19:06:52 +00:00
|
|
|
if TYPE_CHECKING:
|
2020-12-31 06:11:45 +00:00
|
|
|
from core.gui.app import Application
|
2020-01-14 19:06:52 +00:00
|
|
|
from core.gui.graph.graph import CanvasGraph
|
2020-12-31 06:11:45 +00:00
|
|
|
from core.gui.graph.manager import CanvasManager
|
2021-01-15 07:46:25 +00:00
|
|
|
from core.gui.graph.node import CanvasNode, ShadowNode
|
2020-01-14 19:06:52 +00:00
|
|
|
|
2020-10-11 18:05:57 +01:00
|
|
|
TEXT_DISTANCE: int = 60
|
2020-06-20 07:24:07 +01:00
|
|
|
EDGE_WIDTH: int = 3
|
|
|
|
EDGE_COLOR: str = "#ff0000"
|
2020-10-13 14:45:37 +01:00
|
|
|
EDGE_LOSS: float = 100.0
|
2020-06-26 17:13:38 +01:00
|
|
|
WIRELESS_WIDTH: float = 3
|
2020-06-20 07:24:07 +01:00
|
|
|
WIRELESS_COLOR: str = "#009933"
|
|
|
|
ARC_DISTANCE: int = 50
|
2019-12-19 00:51:05 +00:00
|
|
|
|
2019-12-05 19:12:25 +00:00
|
|
|
|
2020-10-13 04:28:27 +01:00
|
|
|
def create_wireless_token(src: int, dst: int, network: int) -> str:
|
2021-01-20 18:09:46 +00:00
|
|
|
if src < dst:
|
|
|
|
node1, node2 = src, dst
|
|
|
|
else:
|
|
|
|
node1, node2 = dst, src
|
|
|
|
return f"{node1}-{node2}-{network}"
|
2020-10-13 04:28:27 +01:00
|
|
|
|
|
|
|
|
2020-10-13 18:25:40 +01:00
|
|
|
def create_edge_token(link: Link) -> str:
|
2020-12-03 04:40:03 +00:00
|
|
|
iface1_id = link.iface1.id if link.iface1 else 0
|
|
|
|
iface2_id = link.iface2.id if link.iface2 else 0
|
2021-01-20 18:09:46 +00:00
|
|
|
if link.node1_id < link.node2_id:
|
|
|
|
node1 = link.node1_id
|
|
|
|
node1_iface = iface1_id
|
|
|
|
node2 = link.node2_id
|
|
|
|
node2_iface = iface2_id
|
|
|
|
else:
|
|
|
|
node1 = link.node2_id
|
|
|
|
node1_iface = iface2_id
|
|
|
|
node2 = link.node1_id
|
|
|
|
node2_iface = iface1_id
|
|
|
|
return f"{node1}-{node1_iface}-{node2}-{node2_iface}"
|
2020-04-14 23:51:28 +01:00
|
|
|
|
|
|
|
|
2020-12-31 06:11:45 +00:00
|
|
|
def node_label_positions(
|
|
|
|
src_x: int, src_y: int, dst_x: int, dst_y: int
|
|
|
|
) -> Tuple[Tuple[float, float], Tuple[float, float]]:
|
|
|
|
v_x, v_y = dst_x - src_x, dst_y - src_y
|
|
|
|
v_len = math.sqrt(v_x ** 2 + v_y ** 2)
|
|
|
|
if v_len == 0:
|
|
|
|
u_x, u_y = 0.0, 0.0
|
|
|
|
else:
|
|
|
|
u_x, u_y = v_x / v_len, v_y / v_len
|
|
|
|
offset_x, offset_y = TEXT_DISTANCE * u_x, TEXT_DISTANCE * u_y
|
2020-12-31 19:43:11 +00:00
|
|
|
return (src_x + offset_x, src_y + offset_y), (dst_x - offset_x, dst_y - offset_y)
|
2020-12-31 06:11:45 +00:00
|
|
|
|
|
|
|
|
2020-04-14 23:51:28 +01:00
|
|
|
def arc_edges(edges) -> None:
|
|
|
|
if not edges:
|
|
|
|
return
|
|
|
|
mid_index = len(edges) // 2
|
|
|
|
if mid_index == 0:
|
|
|
|
arc_step = ARC_DISTANCE
|
|
|
|
else:
|
|
|
|
arc_step = ARC_DISTANCE / mid_index
|
|
|
|
# below edges
|
|
|
|
arc = 0
|
|
|
|
for edge in edges[:mid_index]:
|
|
|
|
arc -= arc_step
|
|
|
|
edge.arc = arc
|
|
|
|
edge.redraw()
|
|
|
|
# mid edge
|
|
|
|
if len(edges) % 2 != 0:
|
|
|
|
arc = 0
|
|
|
|
edge = edges[mid_index]
|
|
|
|
edge.arc = arc
|
|
|
|
edge.redraw()
|
|
|
|
mid_index += 1
|
|
|
|
# above edges
|
|
|
|
arc = 0
|
|
|
|
for edge in edges[mid_index:]:
|
|
|
|
arc += arc_step
|
|
|
|
edge.arc = arc
|
|
|
|
edge.redraw()
|
2020-04-14 18:47:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Edge:
|
2020-06-20 07:24:07 +01:00
|
|
|
tag: str = tags.EDGE
|
2020-04-14 18:47:42 +01:00
|
|
|
|
2020-12-31 06:11:45 +00:00
|
|
|
def __init__(
|
|
|
|
self, app: "Application", src: "CanvasNode", dst: "CanvasNode" = None
|
|
|
|
) -> None:
|
|
|
|
self.app: "Application" = app
|
|
|
|
self.manager: CanvasManager = app.manager
|
2020-06-20 07:24:07 +01:00
|
|
|
self.id: Optional[int] = None
|
2020-12-31 06:11:45 +00:00
|
|
|
self.id2: Optional[int] = None
|
|
|
|
self.src: "CanvasNode" = src
|
|
|
|
self.src_shadow: Optional[ShadowNode] = None
|
|
|
|
self.dst: Optional["CanvasNode"] = dst
|
|
|
|
self.dst_shadow: Optional[ShadowNode] = None
|
2021-01-15 07:31:53 +00:00
|
|
|
self.link: Optional[Link] = None
|
2020-06-20 07:24:07 +01:00
|
|
|
self.arc: int = 0
|
2020-10-13 04:28:27 +01:00
|
|
|
self.token: Optional[str] = None
|
2020-06-20 07:24:07 +01:00
|
|
|
self.src_label: Optional[int] = None
|
2020-12-31 06:11:45 +00:00
|
|
|
self.src_label2: Optional[int] = None
|
2020-06-20 07:24:07 +01:00
|
|
|
self.middle_label: Optional[int] = None
|
2020-12-31 06:11:45 +00:00
|
|
|
self.middle_label2: Optional[int] = None
|
2020-06-20 07:24:07 +01:00
|
|
|
self.dst_label: Optional[int] = None
|
2020-12-31 06:11:45 +00:00
|
|
|
self.dst_label2: Optional[int] = None
|
2020-06-20 07:24:07 +01:00
|
|
|
self.color: str = EDGE_COLOR
|
|
|
|
self.width: int = EDGE_WIDTH
|
2021-01-04 06:08:09 +00:00
|
|
|
self.linked_wireless: bool = False
|
2021-01-10 04:35:24 +00:00
|
|
|
self.hidden: bool = False
|
2021-01-04 06:08:09 +00:00
|
|
|
if self.dst:
|
|
|
|
self.linked_wireless = self.src.is_wireless() or self.dst.is_wireless()
|
2020-04-14 18:47:42 +01:00
|
|
|
|
2020-04-15 20:41:09 +01:00
|
|
|
def scaled_width(self) -> float:
|
2020-12-31 06:11:45 +00:00
|
|
|
return self.width * self.app.app_scale
|
2020-04-15 20:41:09 +01:00
|
|
|
|
2020-04-14 23:51:28 +01:00
|
|
|
def _get_arcpoint(
|
2020-04-14 18:47:42 +01:00
|
|
|
self, src_pos: Tuple[float, float], dst_pos: Tuple[float, float]
|
|
|
|
) -> Tuple[float, float]:
|
|
|
|
src_x, src_y = src_pos
|
|
|
|
dst_x, dst_y = dst_pos
|
2020-04-14 23:51:28 +01:00
|
|
|
mp_x = (src_x + dst_x) / 2
|
|
|
|
mp_y = (src_y + dst_y) / 2
|
|
|
|
slope_denominator = src_x - dst_x
|
|
|
|
slope_numerator = src_y - dst_y
|
|
|
|
# vertical line
|
|
|
|
if slope_denominator == 0:
|
|
|
|
return mp_x + self.arc, mp_y
|
|
|
|
# horizontal line
|
|
|
|
if slope_numerator == 0:
|
|
|
|
return mp_x, mp_y + self.arc
|
|
|
|
# everything else
|
|
|
|
m = slope_numerator / slope_denominator
|
|
|
|
perp_m = -1 / m
|
|
|
|
b = mp_y - (perp_m * mp_x)
|
|
|
|
# get arc x and y
|
|
|
|
offset = math.sqrt(self.arc ** 2 / (1 + (1 / m ** 2)))
|
|
|
|
arc_x = mp_x
|
|
|
|
if self.arc >= 0:
|
|
|
|
arc_x += offset
|
|
|
|
else:
|
|
|
|
arc_x -= offset
|
|
|
|
arc_y = (perp_m * arc_x) + b
|
|
|
|
return arc_x, arc_y
|
2020-04-14 18:47:42 +01:00
|
|
|
|
2020-12-31 06:11:45 +00:00
|
|
|
def arc_common_edges(self) -> None:
|
|
|
|
common_edges = list(self.src.edges & self.dst.edges)
|
|
|
|
common_edges += list(self.src.wireless_edges & self.dst.wireless_edges)
|
|
|
|
arc_edges(common_edges)
|
|
|
|
|
2021-01-04 06:08:09 +00:00
|
|
|
def has_shadows(self) -> bool:
|
|
|
|
# still drawing
|
2020-12-31 06:11:45 +00:00
|
|
|
if not self.dst:
|
2021-01-04 06:08:09 +00:00
|
|
|
return False
|
|
|
|
return self.src.canvas != self.dst.canvas
|
2020-12-31 06:11:45 +00:00
|
|
|
|
|
|
|
def draw(self, state: str) -> None:
|
2021-01-04 06:08:09 +00:00
|
|
|
if not self.has_shadows():
|
2021-01-05 23:42:46 +00:00
|
|
|
dst = self.dst if self.dst else self.src
|
|
|
|
self.id = self.draw_edge(self.src.canvas, self.src, dst, state)
|
|
|
|
elif self.linked_wireless:
|
|
|
|
if self.src.is_wireless():
|
|
|
|
self.src_shadow = self.dst.canvas.get_shadow(self.src)
|
|
|
|
self.id2 = self.draw_edge(
|
|
|
|
self.dst.canvas, self.src_shadow, self.dst, state
|
|
|
|
)
|
|
|
|
if self.dst.is_wireless():
|
|
|
|
self.dst_shadow = self.src.canvas.get_shadow(self.dst)
|
|
|
|
self.id = self.draw_edge(
|
|
|
|
self.src.canvas, self.src, self.dst_shadow, state
|
|
|
|
)
|
2020-12-31 06:11:45 +00:00
|
|
|
else:
|
|
|
|
# draw shadow nodes and 2 lines
|
2021-01-02 20:59:15 +00:00
|
|
|
self.src_shadow = self.dst.canvas.get_shadow(self.src)
|
|
|
|
self.dst_shadow = self.src.canvas.get_shadow(self.dst)
|
|
|
|
self.id = self.draw_edge(self.src.canvas, self.src, self.dst_shadow, state)
|
|
|
|
self.id2 = self.draw_edge(self.dst.canvas, self.src_shadow, self.dst, state)
|
2021-01-16 06:49:01 +00:00
|
|
|
self.src.canvas.organize()
|
|
|
|
if self.has_shadows():
|
2021-01-05 23:42:46 +00:00
|
|
|
self.dst.canvas.organize()
|
2021-01-02 18:46:05 +00:00
|
|
|
|
|
|
|
def draw_edge(
|
2021-01-02 20:59:15 +00:00
|
|
|
self,
|
|
|
|
canvas: "CanvasGraph",
|
|
|
|
src: Union["CanvasNode", "ShadowNode"],
|
|
|
|
dst: Union["CanvasNode", "ShadowNode"],
|
|
|
|
state: str,
|
2021-01-02 18:46:05 +00:00
|
|
|
) -> int:
|
|
|
|
src_pos = src.position()
|
|
|
|
dst_pos = dst.position()
|
|
|
|
arc_pos = self._get_arcpoint(src_pos, dst_pos)
|
|
|
|
return canvas.create_line(
|
|
|
|
*src_pos,
|
|
|
|
*arc_pos,
|
|
|
|
*dst_pos,
|
|
|
|
smooth=True,
|
|
|
|
tags=self.tag,
|
|
|
|
width=self.scaled_width(),
|
|
|
|
fill=self.color,
|
|
|
|
state=state,
|
|
|
|
)
|
2019-12-05 19:12:25 +00:00
|
|
|
|
2020-06-20 07:24:07 +01:00
|
|
|
def redraw(self) -> None:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.src.canvas.itemconfig(self.id, width=self.scaled_width(), fill=self.color)
|
|
|
|
self.move_src()
|
2021-01-05 23:42:46 +00:00
|
|
|
if self.id2:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.dst.canvas.itemconfig(
|
|
|
|
self.id2, width=self.scaled_width(), fill=self.color
|
|
|
|
)
|
|
|
|
self.move_dst()
|
2020-04-15 20:41:09 +01:00
|
|
|
|
|
|
|
def middle_label_text(self, text: str) -> None:
|
|
|
|
if self.middle_label is None:
|
2020-12-31 06:11:45 +00:00
|
|
|
_, _, x, y, _, _ = self.src.canvas.coords(self.id)
|
|
|
|
self.middle_label = self.src.canvas.create_text(
|
2020-04-19 23:47:07 +01:00
|
|
|
x,
|
|
|
|
y,
|
2020-12-31 06:11:45 +00:00
|
|
|
font=self.app.edge_font,
|
2020-04-19 23:47:07 +01:00
|
|
|
text=text,
|
|
|
|
tags=tags.LINK_LABEL,
|
2020-06-24 06:53:48 +01:00
|
|
|
justify=tk.CENTER,
|
2020-12-31 06:11:45 +00:00
|
|
|
state=self.manager.show_link_labels.state(),
|
2020-04-15 20:41:09 +01:00
|
|
|
)
|
2021-01-05 23:42:46 +00:00
|
|
|
if self.id2:
|
2020-12-31 06:11:45 +00:00
|
|
|
_, _, x, y, _, _ = self.dst.canvas.coords(self.id2)
|
|
|
|
self.middle_label2 = self.dst.canvas.create_text(
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
font=self.app.edge_font,
|
|
|
|
text=text,
|
|
|
|
tags=tags.LINK_LABEL,
|
|
|
|
justify=tk.CENTER,
|
|
|
|
state=self.manager.show_link_labels.state(),
|
|
|
|
)
|
2020-04-15 20:41:09 +01:00
|
|
|
else:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.src.canvas.itemconfig(self.middle_label, text=text)
|
2021-01-05 23:42:46 +00:00
|
|
|
if self.middle_label2:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.dst.canvas.itemconfig(self.middle_label2, text=text)
|
2020-04-15 20:41:09 +01:00
|
|
|
|
2020-06-23 22:48:27 +01:00
|
|
|
def clear_middle_label(self) -> None:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.src.canvas.delete(self.middle_label)
|
2020-06-23 22:48:27 +01:00
|
|
|
self.middle_label = None
|
2021-01-05 23:42:46 +00:00
|
|
|
if self.middle_label2:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.dst.canvas.delete(self.middle_label2)
|
|
|
|
self.middle_label2 = None
|
2020-06-23 22:48:27 +01:00
|
|
|
|
2020-04-15 21:39:11 +01:00
|
|
|
def src_label_text(self, text: str) -> None:
|
2021-01-05 23:42:46 +00:00
|
|
|
if self.src_label is None and self.src_label2 is None:
|
|
|
|
if self.id:
|
|
|
|
src_x, src_y, _, _, dst_x, dst_y = self.src.canvas.coords(self.id)
|
|
|
|
src_pos, _ = node_label_positions(src_x, src_y, dst_x, dst_y)
|
|
|
|
self.src_label = self.src.canvas.create_text(
|
|
|
|
*src_pos,
|
|
|
|
text=text,
|
|
|
|
justify=tk.CENTER,
|
|
|
|
font=self.app.edge_font,
|
|
|
|
tags=tags.LINK_LABEL,
|
|
|
|
state=self.manager.show_link_labels.state(),
|
|
|
|
)
|
|
|
|
if self.id2:
|
2020-12-31 06:11:45 +00:00
|
|
|
src_x, src_y, _, _, dst_x, dst_y = self.dst.canvas.coords(self.id2)
|
|
|
|
src_pos, _ = node_label_positions(src_x, src_y, dst_x, dst_y)
|
|
|
|
self.src_label2 = self.dst.canvas.create_text(
|
|
|
|
*src_pos,
|
|
|
|
text=text,
|
|
|
|
justify=tk.CENTER,
|
|
|
|
font=self.app.edge_font,
|
|
|
|
tags=tags.LINK_LABEL,
|
|
|
|
state=self.manager.show_link_labels.state(),
|
|
|
|
)
|
2020-04-15 21:39:11 +01:00
|
|
|
else:
|
2021-01-05 23:42:46 +00:00
|
|
|
if self.src_label:
|
|
|
|
self.src.canvas.itemconfig(self.src_label, text=text)
|
|
|
|
if self.src_label2:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.dst.canvas.itemconfig(self.src_label2, text=text)
|
2020-04-15 21:39:11 +01:00
|
|
|
|
|
|
|
def dst_label_text(self, text: str) -> None:
|
2021-01-05 23:42:46 +00:00
|
|
|
if self.dst_label is None and self.dst_label2 is None:
|
|
|
|
if self.id:
|
|
|
|
src_x, src_y, _, _, dst_x, dst_y = self.src.canvas.coords(self.id)
|
|
|
|
_, dst_pos = node_label_positions(src_x, src_y, dst_x, dst_y)
|
|
|
|
self.dst_label = self.src.canvas.create_text(
|
|
|
|
*dst_pos,
|
|
|
|
text=text,
|
|
|
|
justify=tk.CENTER,
|
|
|
|
font=self.app.edge_font,
|
|
|
|
tags=tags.LINK_LABEL,
|
|
|
|
state=self.manager.show_link_labels.state(),
|
|
|
|
)
|
|
|
|
if self.id2:
|
2020-12-31 06:11:45 +00:00
|
|
|
src_x, src_y, _, _, dst_x, dst_y = self.dst.canvas.coords(self.id2)
|
|
|
|
_, dst_pos = node_label_positions(src_x, src_y, dst_x, dst_y)
|
|
|
|
self.dst_label2 = self.dst.canvas.create_text(
|
|
|
|
*dst_pos,
|
|
|
|
text=text,
|
|
|
|
justify=tk.CENTER,
|
|
|
|
font=self.app.edge_font,
|
|
|
|
tags=tags.LINK_LABEL,
|
|
|
|
state=self.manager.show_link_labels.state(),
|
|
|
|
)
|
2020-04-15 21:39:11 +01:00
|
|
|
else:
|
2021-01-05 23:42:46 +00:00
|
|
|
if self.dst_label:
|
|
|
|
self.src.canvas.itemconfig(self.dst_label, text=text)
|
|
|
|
if self.dst_label2:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.dst.canvas.itemconfig(self.dst_label2, text=text)
|
2020-04-15 21:39:11 +01:00
|
|
|
|
2020-12-31 06:11:45 +00:00
|
|
|
def drawing(self, pos: Tuple[float, float]) -> None:
|
|
|
|
src_x, src_y, _, _, _, _ = self.src.canvas.coords(self.id)
|
|
|
|
src_pos = src_x, src_y
|
|
|
|
self.moved(src_pos, pos)
|
|
|
|
|
|
|
|
def move_node(self, node: "CanvasNode") -> None:
|
|
|
|
if self.src == node:
|
|
|
|
self.move_src()
|
|
|
|
else:
|
|
|
|
self.move_dst()
|
|
|
|
|
|
|
|
def move_shadow(self, node: "ShadowNode") -> None:
|
|
|
|
if self.src_shadow == node:
|
|
|
|
self.move_src_shadow()
|
2021-01-05 23:42:46 +00:00
|
|
|
elif self.dst_shadow == node:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.move_dst_shadow()
|
|
|
|
|
|
|
|
def move_src_shadow(self) -> None:
|
2021-01-05 23:42:46 +00:00
|
|
|
if not self.id2:
|
|
|
|
return
|
2020-12-31 06:11:45 +00:00
|
|
|
_, _, _, _, dst_x, dst_y = self.dst.canvas.coords(self.id2)
|
|
|
|
dst_pos = dst_x, dst_y
|
|
|
|
self.moved2(self.src_shadow.position(), dst_pos)
|
2020-04-14 18:47:42 +01:00
|
|
|
|
2020-12-31 06:11:45 +00:00
|
|
|
def move_dst_shadow(self) -> None:
|
2021-01-05 23:42:46 +00:00
|
|
|
if not self.id:
|
|
|
|
return
|
2020-12-31 06:11:45 +00:00
|
|
|
src_x, src_y, _, _, _, _ = self.src.canvas.coords(self.id)
|
2020-04-15 20:51:35 +01:00
|
|
|
src_pos = src_x, src_y
|
2020-12-31 06:11:45 +00:00
|
|
|
self.moved(src_pos, self.dst_shadow.position())
|
2020-04-14 18:47:42 +01:00
|
|
|
|
2020-12-31 06:11:45 +00:00
|
|
|
def move_dst(self) -> None:
|
2021-01-05 23:42:46 +00:00
|
|
|
if self.dst.is_wireless() and self.has_shadows():
|
|
|
|
return
|
2020-12-31 06:11:45 +00:00
|
|
|
dst_pos = self.dst.position()
|
2021-01-05 23:42:46 +00:00
|
|
|
if self.id2:
|
2020-12-31 20:24:21 +00:00
|
|
|
src_x, src_y, _, _, _, _ = self.dst.canvas.coords(self.id2)
|
|
|
|
src_pos = src_x, src_y
|
2020-12-31 06:11:45 +00:00
|
|
|
self.moved2(src_pos, dst_pos)
|
2021-01-05 23:42:46 +00:00
|
|
|
elif self.id:
|
|
|
|
src_x, src_y, _, _, _, _ = self.dst.canvas.coords(self.id)
|
|
|
|
src_pos = src_x, src_y
|
|
|
|
self.moved(src_pos, dst_pos)
|
2020-12-31 06:11:45 +00:00
|
|
|
|
|
|
|
def move_src(self) -> None:
|
2021-01-05 23:42:46 +00:00
|
|
|
if not self.id:
|
|
|
|
return
|
2020-12-31 06:11:45 +00:00
|
|
|
_, _, _, _, dst_x, dst_y = self.src.canvas.coords(self.id)
|
2020-04-15 20:51:35 +01:00
|
|
|
dst_pos = dst_x, dst_y
|
2020-12-31 06:11:45 +00:00
|
|
|
self.moved(self.src.position(), dst_pos)
|
2020-04-15 20:41:09 +01:00
|
|
|
|
|
|
|
def moved(self, src_pos: Tuple[float, float], dst_pos: Tuple[float, float]) -> None:
|
2020-04-14 23:51:28 +01:00
|
|
|
arc_pos = self._get_arcpoint(src_pos, dst_pos)
|
2020-12-31 06:11:45 +00:00
|
|
|
self.src.canvas.coords(self.id, *src_pos, *arc_pos, *dst_pos)
|
2020-04-15 20:41:09 +01:00
|
|
|
if self.middle_label:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.src.canvas.coords(self.middle_label, *arc_pos)
|
2020-12-31 19:43:11 +00:00
|
|
|
src_x, src_y, _, _, dst_x, dst_y = self.src.canvas.coords(self.id)
|
|
|
|
src_pos, dst_pos = node_label_positions(src_x, src_y, dst_x, dst_y)
|
2020-04-15 21:39:11 +01:00
|
|
|
if self.src_label:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.src.canvas.coords(self.src_label, *src_pos)
|
2020-04-15 21:39:11 +01:00
|
|
|
if self.dst_label:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.src.canvas.coords(self.dst_label, *dst_pos)
|
|
|
|
|
|
|
|
def moved2(
|
|
|
|
self, src_pos: Tuple[float, float], dst_pos: Tuple[float, float]
|
|
|
|
) -> None:
|
|
|
|
arc_pos = self._get_arcpoint(src_pos, dst_pos)
|
|
|
|
self.dst.canvas.coords(self.id2, *src_pos, *arc_pos, *dst_pos)
|
|
|
|
if self.middle_label2:
|
|
|
|
self.dst.canvas.coords(self.middle_label2, *arc_pos)
|
2020-12-31 19:43:11 +00:00
|
|
|
src_x, src_y, _, _, dst_x, dst_y = self.dst.canvas.coords(self.id2)
|
|
|
|
src_pos, dst_pos = node_label_positions(src_x, src_y, dst_x, dst_y)
|
2020-12-31 06:11:45 +00:00
|
|
|
if self.src_label2:
|
|
|
|
self.dst.canvas.coords(self.src_label2, *src_pos)
|
|
|
|
if self.dst_label2:
|
|
|
|
self.dst.canvas.coords(self.dst_label2, *dst_pos)
|
2020-04-14 18:47:42 +01:00
|
|
|
|
|
|
|
def delete(self) -> None:
|
2021-04-22 05:09:35 +01:00
|
|
|
logger.debug("deleting canvas edge, id: %s", self.id)
|
2020-12-31 06:11:45 +00:00
|
|
|
self.src.canvas.delete(self.id)
|
|
|
|
self.src.canvas.delete(self.src_label)
|
|
|
|
self.src.canvas.delete(self.dst_label)
|
|
|
|
if self.dst:
|
|
|
|
self.dst.canvas.delete(self.id2)
|
|
|
|
self.dst.canvas.delete(self.src_label2)
|
|
|
|
self.dst.canvas.delete(self.dst_label2)
|
2021-01-02 20:59:15 +00:00
|
|
|
if self.src_shadow and self.src_shadow.should_delete():
|
2020-12-31 06:11:45 +00:00
|
|
|
self.src_shadow.delete()
|
|
|
|
self.src_shadow = None
|
2021-01-02 20:59:15 +00:00
|
|
|
if self.dst_shadow and self.dst_shadow.should_delete():
|
2020-12-31 06:11:45 +00:00
|
|
|
self.dst_shadow.delete()
|
|
|
|
self.dst_shadow = None
|
2020-06-23 22:48:27 +01:00
|
|
|
self.clear_middle_label()
|
2020-04-15 21:39:11 +01:00
|
|
|
self.id = None
|
2020-12-31 06:11:45 +00:00
|
|
|
self.id2 = None
|
2020-04-15 21:39:11 +01:00
|
|
|
self.src_label = None
|
2020-12-31 06:11:45 +00:00
|
|
|
self.src_label2 = None
|
2020-04-15 21:39:11 +01:00
|
|
|
self.dst_label = None
|
2020-12-31 06:11:45 +00:00
|
|
|
self.dst_label2 = None
|
2022-04-26 18:16:36 +01:00
|
|
|
if self.dst:
|
|
|
|
self.arc_common_edges()
|
2019-12-05 19:12:25 +00:00
|
|
|
|
2021-01-10 04:35:24 +00:00
|
|
|
def hide(self) -> None:
|
|
|
|
self.hidden = True
|
|
|
|
if self.src_shadow:
|
|
|
|
self.src_shadow.hide()
|
|
|
|
if self.dst_shadow:
|
|
|
|
self.dst_shadow.hide()
|
|
|
|
self.src.canvas.itemconfigure(self.id, state=tk.HIDDEN)
|
|
|
|
self.src.canvas.itemconfigure(self.src_label, state=tk.HIDDEN)
|
|
|
|
self.src.canvas.itemconfigure(self.dst_label, state=tk.HIDDEN)
|
|
|
|
self.src.canvas.itemconfigure(self.middle_label, state=tk.HIDDEN)
|
|
|
|
if self.id2:
|
|
|
|
self.dst.canvas.itemconfigure(self.id2, state=tk.HIDDEN)
|
|
|
|
self.dst.canvas.itemconfigure(self.src_label2, state=tk.HIDDEN)
|
|
|
|
self.dst.canvas.itemconfigure(self.dst_label2, state=tk.HIDDEN)
|
|
|
|
self.dst.canvas.itemconfigure(self.middle_label2, state=tk.HIDDEN)
|
|
|
|
|
|
|
|
def show(self) -> None:
|
|
|
|
self.hidden = False
|
|
|
|
if self.src_shadow:
|
|
|
|
self.src_shadow.show()
|
|
|
|
if self.dst_shadow:
|
|
|
|
self.dst_shadow.show()
|
|
|
|
self.src.canvas.itemconfigure(self.id, state=tk.NORMAL)
|
2021-02-17 23:23:04 +00:00
|
|
|
state = self.manager.show_link_labels.state()
|
|
|
|
self.set_labels(state)
|
|
|
|
|
|
|
|
def set_labels(self, state: str) -> None:
|
|
|
|
self.src.canvas.itemconfigure(self.src_label, state=state)
|
|
|
|
self.src.canvas.itemconfigure(self.dst_label, state=state)
|
|
|
|
self.src.canvas.itemconfigure(self.middle_label, state=state)
|
2021-01-10 04:35:24 +00:00
|
|
|
if self.id2:
|
2021-02-17 23:23:04 +00:00
|
|
|
self.dst.canvas.itemconfigure(self.id2, state=state)
|
|
|
|
self.dst.canvas.itemconfigure(self.src_label2, state=state)
|
|
|
|
self.dst.canvas.itemconfigure(self.dst_label2, state=state)
|
|
|
|
self.dst.canvas.itemconfigure(self.middle_label2, state=state)
|
2021-01-10 04:35:24 +00:00
|
|
|
|
2021-01-15 07:31:53 +00:00
|
|
|
def other_node(self, node: "CanvasNode") -> "CanvasNode":
|
|
|
|
if self.src == node:
|
|
|
|
return self.dst
|
|
|
|
elif self.dst == node:
|
|
|
|
return self.src
|
|
|
|
else:
|
|
|
|
raise ValueError(f"node({node.core_node.name}) does not belong to edge")
|
|
|
|
|
|
|
|
def other_iface(self, node: "CanvasNode") -> Optional[Interface]:
|
|
|
|
if self.src == node:
|
|
|
|
return self.link.iface2 if self.link else None
|
|
|
|
elif self.dst == node:
|
|
|
|
return self.link.iface1 if self.link else None
|
|
|
|
else:
|
|
|
|
raise ValueError(f"node({node.core_node.name}) does not belong to edge")
|
|
|
|
|
|
|
|
def iface(self, node: "CanvasNode") -> Optional[Interface]:
|
|
|
|
if self.src == node:
|
|
|
|
return self.link.iface1 if self.link else None
|
|
|
|
elif self.dst == node:
|
|
|
|
return self.link.iface2 if self.link else None
|
|
|
|
else:
|
|
|
|
raise ValueError(f"node({node.core_node.name}) does not belong to edge")
|
|
|
|
|
2019-12-05 19:12:25 +00:00
|
|
|
|
2020-04-14 18:47:42 +01:00
|
|
|
class CanvasWirelessEdge(Edge):
|
|
|
|
tag = tags.WIRELESS_EDGE
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
2020-12-31 06:11:45 +00:00
|
|
|
app: "Application",
|
|
|
|
src: "CanvasNode",
|
|
|
|
dst: "CanvasNode",
|
2020-10-13 04:28:27 +01:00
|
|
|
network_id: int,
|
|
|
|
token: str,
|
2020-06-26 17:13:38 +01:00
|
|
|
link: Link,
|
2020-04-14 18:47:42 +01:00
|
|
|
) -> None:
|
2021-04-22 05:09:35 +01:00
|
|
|
logger.debug("drawing wireless link from node %s to node %s", src, dst)
|
2020-12-31 06:11:45 +00:00
|
|
|
super().__init__(app, src, dst)
|
2021-01-16 06:49:01 +00:00
|
|
|
self.src.wireless_edges.add(self)
|
|
|
|
self.dst.wireless_edges.add(self)
|
2020-10-13 04:28:27 +01:00
|
|
|
self.network_id: int = network_id
|
2020-06-26 17:13:38 +01:00
|
|
|
self.link: Link = link
|
2020-10-13 04:28:27 +01:00
|
|
|
self.token: str = token
|
2020-06-20 07:24:07 +01:00
|
|
|
self.width: float = WIRELESS_WIDTH
|
2020-06-26 17:13:38 +01:00
|
|
|
color = link.color if link.color else WIRELESS_COLOR
|
|
|
|
self.color: str = color
|
2021-02-18 00:03:01 +00:00
|
|
|
state = self.manager.show_wireless.state()
|
|
|
|
self.draw(state)
|
2020-06-26 17:13:38 +01:00
|
|
|
if link.label:
|
|
|
|
self.middle_label_text(link.label)
|
2021-02-18 00:03:01 +00:00
|
|
|
if self.src.hidden or self.dst.hidden:
|
|
|
|
self.hide()
|
2020-06-26 17:13:38 +01:00
|
|
|
self.set_binding()
|
2022-04-26 18:16:36 +01:00
|
|
|
self.arc_common_edges()
|
2020-06-26 17:13:38 +01:00
|
|
|
|
|
|
|
def set_binding(self) -> None:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.src.canvas.tag_bind(self.id, "<Button-1>", self.show_info)
|
|
|
|
if self.id2 is not None:
|
|
|
|
self.dst.canvas.tag_bind(self.id2, "<Button-1>", self.show_info)
|
2020-06-26 17:13:38 +01:00
|
|
|
|
|
|
|
def show_info(self, _event: tk.Event) -> None:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.app.display_info(WirelessEdgeInfoFrame, app=self.app, edge=self)
|
2020-04-14 18:47:42 +01:00
|
|
|
|
2021-01-05 23:42:46 +00:00
|
|
|
def delete(self) -> None:
|
|
|
|
self.src.wireless_edges.discard(self)
|
|
|
|
self.dst.wireless_edges.remove(self)
|
|
|
|
super().delete()
|
|
|
|
|
2020-04-14 18:47:42 +01:00
|
|
|
|
|
|
|
class CanvasEdge(Edge):
|
2019-12-05 19:12:25 +00:00
|
|
|
"""
|
|
|
|
Canvas edge class
|
|
|
|
"""
|
|
|
|
|
2020-01-14 19:06:52 +00:00
|
|
|
def __init__(
|
2020-12-31 06:11:45 +00:00
|
|
|
self, app: "Application", src: "CanvasNode", dst: "CanvasNode" = None
|
2020-04-14 18:47:42 +01:00
|
|
|
) -> None:
|
2019-12-05 19:12:25 +00:00
|
|
|
"""
|
|
|
|
Create an instance of canvas edge object
|
|
|
|
"""
|
2020-12-31 06:11:45 +00:00
|
|
|
super().__init__(app, src, dst)
|
2020-06-20 07:24:07 +01:00
|
|
|
self.text_src: Optional[int] = None
|
|
|
|
self.text_dst: Optional[int] = None
|
|
|
|
self.asymmetric_link: Optional[Link] = None
|
|
|
|
self.throughput: Optional[float] = None
|
2020-12-31 06:11:45 +00:00
|
|
|
self.draw(tk.NORMAL)
|
2020-05-02 16:41:10 +01:00
|
|
|
|
2020-12-04 08:03:30 +00:00
|
|
|
def is_customized(self) -> bool:
|
|
|
|
return self.width != EDGE_WIDTH or self.color != EDGE_COLOR
|
|
|
|
|
2021-01-05 23:42:46 +00:00
|
|
|
def set_bindings(self) -> None:
|
|
|
|
if self.id:
|
|
|
|
show_context = functools.partial(self.show_context, self.src.canvas)
|
|
|
|
self.src.canvas.tag_bind(self.id, "<ButtonRelease-3>", show_context)
|
|
|
|
self.src.canvas.tag_bind(self.id, "<Button-1>", self.show_info)
|
|
|
|
if self.id2:
|
2021-01-02 08:10:23 +00:00
|
|
|
show_context = functools.partial(self.show_context, self.dst.canvas)
|
2020-12-31 06:11:45 +00:00
|
|
|
self.dst.canvas.tag_bind(self.id2, "<ButtonRelease-3>", show_context)
|
|
|
|
self.dst.canvas.tag_bind(self.id2, "<Button-1>", self.show_info)
|
2019-12-05 19:12:25 +00:00
|
|
|
|
2020-07-25 18:30:14 +01:00
|
|
|
def iface_label(self, iface: Interface) -> str:
|
2020-04-19 23:47:07 +01:00
|
|
|
label = ""
|
2020-12-31 06:11:45 +00:00
|
|
|
if iface.name and self.manager.show_iface_names.get():
|
2020-06-16 17:30:16 +01:00
|
|
|
label = f"{iface.name}"
|
2020-12-31 06:11:45 +00:00
|
|
|
if iface.ip4 and self.manager.show_ip4s.get():
|
2020-04-19 23:47:07 +01:00
|
|
|
label = f"{label}\n" if label else ""
|
2020-06-17 06:05:36 +01:00
|
|
|
label += f"{iface.ip4}/{iface.ip4_mask}"
|
2020-12-31 06:11:45 +00:00
|
|
|
if iface.ip6 and self.manager.show_ip6s.get():
|
2020-04-19 23:47:07 +01:00
|
|
|
label = f"{label}\n" if label else ""
|
2020-06-17 06:05:36 +01:00
|
|
|
label += f"{iface.ip6}/{iface.ip6_mask}"
|
2020-04-19 23:47:07 +01:00
|
|
|
return label
|
|
|
|
|
2020-04-15 21:39:11 +01:00
|
|
|
def create_node_labels(self) -> Tuple[str, str]:
|
2020-06-13 00:52:41 +01:00
|
|
|
label1 = None
|
2020-07-25 18:30:14 +01:00
|
|
|
if self.link.iface1:
|
2020-06-16 17:30:16 +01:00
|
|
|
label1 = self.iface_label(self.link.iface1)
|
2020-06-13 00:52:41 +01:00
|
|
|
label2 = None
|
2020-07-25 18:30:14 +01:00
|
|
|
if self.link.iface2:
|
2020-06-16 17:30:16 +01:00
|
|
|
label2 = self.iface_label(self.link.iface2)
|
2020-06-13 00:52:41 +01:00
|
|
|
return label1, label2
|
2020-03-04 19:38:24 +00:00
|
|
|
|
2020-04-14 18:47:42 +01:00
|
|
|
def draw_labels(self) -> None:
|
2020-04-15 21:39:11 +01:00
|
|
|
src_text, dst_text = self.create_node_labels()
|
|
|
|
self.src_label_text(src_text)
|
|
|
|
self.dst_label_text(dst_text)
|
2020-10-10 14:15:59 +01:00
|
|
|
if not self.linked_wireless:
|
|
|
|
self.draw_link_options()
|
2019-12-19 00:51:05 +00:00
|
|
|
|
2020-04-14 18:47:42 +01:00
|
|
|
def redraw(self) -> None:
|
2020-04-14 23:51:28 +01:00
|
|
|
super().redraw()
|
2020-04-15 21:39:11 +01:00
|
|
|
self.draw_labels()
|
2019-12-27 08:32:10 +00:00
|
|
|
|
2021-02-17 23:23:04 +00:00
|
|
|
def show(self) -> None:
|
|
|
|
super().show()
|
|
|
|
self.check_visibility()
|
|
|
|
|
|
|
|
def check_visibility(self) -> None:
|
|
|
|
state = tk.NORMAL
|
|
|
|
hide_links = self.manager.show_links.state() == tk.HIDDEN
|
|
|
|
if self.linked_wireless or hide_links:
|
2020-10-13 14:45:37 +01:00
|
|
|
state = tk.HIDDEN
|
2021-02-17 23:23:04 +00:00
|
|
|
elif self.link.options:
|
|
|
|
hide_loss = self.manager.show_loss_links.state() == tk.HIDDEN
|
|
|
|
should_hide = self.link.options.loss >= EDGE_LOSS
|
|
|
|
if hide_loss and should_hide:
|
|
|
|
state = tk.HIDDEN
|
|
|
|
if self.id:
|
|
|
|
self.src.canvas.itemconfigure(self.id, state=state)
|
|
|
|
if self.id2:
|
|
|
|
self.dst.canvas.itemconfigure(self.id2, state=state)
|
2020-10-13 14:45:37 +01:00
|
|
|
|
2020-04-14 18:47:42 +01:00
|
|
|
def set_throughput(self, throughput: float) -> None:
|
2019-12-27 08:32:10 +00:00
|
|
|
throughput = 0.001 * throughput
|
2020-04-15 20:41:09 +01:00
|
|
|
text = f"{throughput:.3f} kbps"
|
|
|
|
self.middle_label_text(text)
|
2020-12-31 06:11:45 +00:00
|
|
|
if throughput > self.manager.throughput_threshold:
|
|
|
|
color = self.manager.throughput_color
|
|
|
|
width = self.manager.throughput_width
|
2019-12-27 08:32:10 +00:00
|
|
|
else:
|
2020-04-15 20:41:09 +01:00
|
|
|
color = self.color
|
|
|
|
width = self.scaled_width()
|
2020-12-31 06:11:45 +00:00
|
|
|
self.src.canvas.itemconfig(self.id, fill=color, width=width)
|
2021-01-05 23:42:46 +00:00
|
|
|
if self.id2:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.dst.canvas.itemconfig(self.id2, fill=color, width=width)
|
2019-12-19 00:51:05 +00:00
|
|
|
|
2020-10-10 14:15:59 +01:00
|
|
|
def clear_throughput(self) -> None:
|
|
|
|
self.clear_middle_label()
|
|
|
|
if not self.linked_wireless:
|
|
|
|
self.draw_link_options()
|
|
|
|
|
2021-01-16 07:39:38 +00:00
|
|
|
def complete(self, dst: "CanvasNode", link: Link = None) -> None:
|
2021-04-22 05:09:35 +01:00
|
|
|
logger.debug(
|
2021-01-16 07:39:38 +00:00
|
|
|
"completing wired link from node(%s) to node(%s)",
|
|
|
|
self.src.core_node.name,
|
|
|
|
dst.core_node.name,
|
|
|
|
)
|
2019-12-05 19:12:25 +00:00
|
|
|
self.dst = dst
|
2021-01-04 06:08:09 +00:00
|
|
|
self.linked_wireless = self.src.is_wireless() or self.dst.is_wireless()
|
2021-01-05 23:42:46 +00:00
|
|
|
self.set_bindings()
|
2019-12-06 00:37:48 +00:00
|
|
|
self.check_wireless()
|
2021-01-16 07:39:38 +00:00
|
|
|
if link is None:
|
|
|
|
link = self.app.core.ifaces_manager.create_link(self)
|
|
|
|
if link.iface1:
|
|
|
|
iface1 = link.iface1
|
|
|
|
self.src.ifaces[iface1.id] = iface1
|
|
|
|
if link.iface2:
|
|
|
|
iface2 = link.iface2
|
|
|
|
self.dst.ifaces[iface2.id] = iface2
|
|
|
|
self.token = create_edge_token(link)
|
|
|
|
self.link = link
|
|
|
|
self.src.edges.add(self)
|
|
|
|
self.dst.edges.add(self)
|
|
|
|
if not self.linked_wireless:
|
|
|
|
self.arc_common_edges()
|
|
|
|
self.draw_labels()
|
2021-02-17 23:23:04 +00:00
|
|
|
self.check_visibility()
|
2021-01-16 07:39:38 +00:00
|
|
|
self.app.core.save_edge(self)
|
|
|
|
self.src.canvas.organize()
|
|
|
|
if self.has_shadows():
|
|
|
|
self.dst.canvas.organize()
|
|
|
|
self.manager.edges[self.token] = self
|
2019-12-27 08:32:10 +00:00
|
|
|
|
2020-04-14 18:47:42 +01:00
|
|
|
def check_wireless(self) -> None:
|
2020-12-31 06:11:45 +00:00
|
|
|
if not self.linked_wireless:
|
|
|
|
return
|
2021-01-05 23:42:46 +00:00
|
|
|
if self.id:
|
2021-01-08 18:10:46 +00:00
|
|
|
self.src.canvas.itemconfig(self.id, state=tk.HIDDEN)
|
2021-01-05 23:42:46 +00:00
|
|
|
self.src.canvas.dtag(self.id, tags.EDGE)
|
|
|
|
if self.id2:
|
2021-01-08 18:10:46 +00:00
|
|
|
self.dst.canvas.itemconfig(self.id2, state=tk.HIDDEN)
|
2020-12-31 06:11:45 +00:00
|
|
|
self.dst.canvas.dtag(self.id2, tags.EDGE)
|
2021-01-05 23:42:46 +00:00
|
|
|
# add antenna to node
|
2021-01-04 06:08:09 +00:00
|
|
|
if self.src.is_wireless() and not self.dst.is_wireless():
|
|
|
|
self.dst.add_antenna()
|
|
|
|
elif not self.src.is_wireless() and self.dst.is_wireless():
|
|
|
|
self.src.add_antenna()
|
|
|
|
else:
|
|
|
|
self.src.add_antenna()
|
2019-12-06 00:37:48 +00:00
|
|
|
|
2020-04-14 18:47:42 +01:00
|
|
|
def reset(self) -> None:
|
2021-01-05 23:42:46 +00:00
|
|
|
if self.middle_label:
|
|
|
|
self.src.canvas.delete(self.middle_label)
|
|
|
|
self.middle_label = None
|
|
|
|
if self.middle_label2:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.dst.canvas.delete(self.middle_label2)
|
|
|
|
self.middle_label2 = None
|
2021-01-05 23:42:46 +00:00
|
|
|
if self.id:
|
|
|
|
self.src.canvas.itemconfig(
|
|
|
|
self.id, fill=self.color, width=self.scaled_width()
|
|
|
|
)
|
|
|
|
if self.id2:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.dst.canvas.itemconfig(
|
|
|
|
self.id2, fill=self.color, width=self.scaled_width()
|
|
|
|
)
|
2019-12-17 19:47:05 +00:00
|
|
|
|
2020-06-25 18:35:01 +01:00
|
|
|
def show_info(self, _event: tk.Event) -> None:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.app.display_info(EdgeInfoFrame, app=self.app, edge=self)
|
2020-06-25 18:35:01 +01:00
|
|
|
|
2020-12-31 06:11:45 +00:00
|
|
|
def show_context(self, canvas: "CanvasGraph", event: tk.Event) -> None:
|
|
|
|
context: tk.Menu = tk.Menu(canvas)
|
|
|
|
themes.style_menu(context)
|
|
|
|
context.add_command(label="Configure", command=self.click_configure)
|
|
|
|
context.add_command(label="Delete", command=self.click_delete)
|
|
|
|
state = tk.DISABLED if self.app.core.is_runtime() else tk.NORMAL
|
|
|
|
context.entryconfigure(1, state=state)
|
|
|
|
context.tk_popup(event.x_root, event.y_root)
|
2019-12-17 19:47:05 +00:00
|
|
|
|
2020-06-20 07:24:07 +01:00
|
|
|
def click_delete(self) -> None:
|
2020-12-31 06:11:45 +00:00
|
|
|
self.delete()
|
2020-05-02 07:47:37 +01:00
|
|
|
|
2020-05-02 16:41:10 +01:00
|
|
|
def click_configure(self) -> None:
|
2020-12-31 06:11:45 +00:00
|
|
|
dialog = LinkConfigurationDialog(self.app, self)
|
2019-12-17 19:47:05 +00:00
|
|
|
dialog.show()
|
2020-06-24 06:53:48 +01:00
|
|
|
|
|
|
|
def draw_link_options(self):
|
2020-07-25 18:30:14 +01:00
|
|
|
if not self.link.options:
|
|
|
|
return
|
2020-06-24 06:53:48 +01:00
|
|
|
options = self.link.options
|
2020-08-02 18:03:21 +01:00
|
|
|
asym_options = None
|
|
|
|
if self.asymmetric_link and self.asymmetric_link.options:
|
|
|
|
asym_options = self.asymmetric_link.options
|
2020-06-24 06:53:48 +01:00
|
|
|
lines = []
|
2020-08-02 18:03:21 +01:00
|
|
|
# bandwidth
|
|
|
|
if options.bandwidth > 0:
|
|
|
|
bandwidth_line = bandwidth_text(options.bandwidth)
|
|
|
|
if asym_options and asym_options.bandwidth > 0:
|
|
|
|
bandwidth_line += f" / {bandwidth_text(asym_options.bandwidth)}"
|
|
|
|
lines.append(bandwidth_line)
|
|
|
|
# delay/jitter
|
|
|
|
dj_line = delay_jitter_text(options.delay, options.jitter)
|
|
|
|
if dj_line and asym_options:
|
|
|
|
asym_dj_line = delay_jitter_text(asym_options.delay, asym_options.jitter)
|
|
|
|
if asym_dj_line:
|
|
|
|
dj_line += f" / {asym_dj_line}"
|
|
|
|
if dj_line:
|
|
|
|
lines.append(dj_line)
|
|
|
|
# loss
|
|
|
|
if options.loss > 0:
|
|
|
|
loss_line = f"loss={options.loss}%"
|
|
|
|
if asym_options and asym_options.loss > 0:
|
|
|
|
loss_line += f" / loss={asym_options.loss}%"
|
|
|
|
lines.append(loss_line)
|
|
|
|
# duplicate
|
|
|
|
if options.dup > 0:
|
|
|
|
dup_line = f"dup={options.dup}%"
|
|
|
|
if asym_options and asym_options.dup > 0:
|
|
|
|
dup_line += f" / dup={asym_options.dup}%"
|
|
|
|
lines.append(dup_line)
|
2020-06-24 06:53:48 +01:00
|
|
|
label = "\n".join(lines)
|
|
|
|
self.middle_label_text(label)
|
2020-12-31 06:11:45 +00:00
|
|
|
|
|
|
|
def delete(self) -> None:
|
|
|
|
self.src.edges.discard(self)
|
|
|
|
if self.dst:
|
|
|
|
self.dst.edges.discard(self)
|
2021-01-02 18:46:05 +00:00
|
|
|
if self.link.iface1:
|
|
|
|
del self.src.ifaces[self.link.iface1.id]
|
2020-12-31 06:11:45 +00:00
|
|
|
if self.link.iface2:
|
|
|
|
del self.dst.ifaces[self.link.iface2.id]
|
2021-01-04 06:08:09 +00:00
|
|
|
if self.src.is_wireless():
|
2020-12-31 06:11:45 +00:00
|
|
|
self.dst.delete_antenna()
|
2021-01-04 06:08:09 +00:00
|
|
|
if self.dst.is_wireless():
|
2020-12-31 06:11:45 +00:00
|
|
|
self.src.delete_antenna()
|
|
|
|
self.app.core.deleted_canvas_edges([self])
|
2021-01-02 20:59:15 +00:00
|
|
|
super().delete()
|
2021-01-16 07:39:38 +00:00
|
|
|
self.manager.edges.pop(self.token, None)
|