merged latest from coretk
This commit is contained in:
commit
bf710b9afc
4 changed files with 94 additions and 96 deletions
|
@ -29,7 +29,6 @@ LIFT_ORDER = [
|
||||||
"node",
|
"node",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
OBSERVERS = {
|
OBSERVERS = {
|
||||||
"processes": "ps",
|
"processes": "ps",
|
||||||
"ifconfig": "ifconfig",
|
"ifconfig": "ifconfig",
|
||||||
|
@ -190,16 +189,21 @@ class CoreClient:
|
||||||
canvas_node.move(x, y, update=False)
|
canvas_node.move(x, y, update=False)
|
||||||
|
|
||||||
def handle_throughputs(self, event):
|
def handle_throughputs(self, event):
|
||||||
interface_throughputs = event.interface_throughputs
|
# interface_throughputs = event.interface_throughputs
|
||||||
for i in interface_throughputs:
|
# # print(interface_throughputs)
|
||||||
print("")
|
# # return
|
||||||
# return
|
# # for i in interface_throughputs:
|
||||||
throughputs_belong_to_session = []
|
# # print("")
|
||||||
for if_tp in interface_throughputs:
|
# # # return
|
||||||
if if_tp.node_id in self.node_ids:
|
# print(event)
|
||||||
throughputs_belong_to_session.append(if_tp)
|
# throughputs_belong_to_session = []
|
||||||
self.throughput_draw.process_grpc_throughput_event(
|
# print(self.node_ids)
|
||||||
throughputs_belong_to_session
|
# for throughput in interface_throughputs:
|
||||||
|
# if throughput.node_id in self.node_ids:
|
||||||
|
# throughputs_belong_to_session.append(throughput)
|
||||||
|
# print(throughputs_belong_to_session)
|
||||||
|
self.app.canvas.throughput_draw.process_grpc_throughput_event(
|
||||||
|
event.interface_throughputs
|
||||||
)
|
)
|
||||||
|
|
||||||
def join_session(self, session_id, query_location=True):
|
def join_session(self, session_id, query_location=True):
|
||||||
|
@ -215,6 +219,7 @@ class CoreClient:
|
||||||
session = response.session
|
session = response.session
|
||||||
self.state = session.state
|
self.state = session.state
|
||||||
self.client.events(self.session_id, self.handle_events)
|
self.client.events(self.session_id, self.handle_events)
|
||||||
|
self.client.throughputs(self.handle_throughputs)
|
||||||
|
|
||||||
# get location
|
# get location
|
||||||
if query_location:
|
if query_location:
|
||||||
|
|
|
@ -361,6 +361,7 @@ class CanvasGraph(tk.Canvas):
|
||||||
if edge in edges:
|
if edge in edges:
|
||||||
continue
|
continue
|
||||||
edges.add(edge)
|
edges.add(edge)
|
||||||
|
self.throughput_draw.delete(edge)
|
||||||
del self.edges[edge.token]
|
del self.edges[edge.token]
|
||||||
edge.delete()
|
edge.delete()
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
"""
|
"""
|
||||||
Link information, such as IPv4, IPv6 and throughput drawn in the canvas
|
Link information, such as IPv4, IPv6 and throughput drawn in the canvas
|
||||||
"""
|
"""
|
||||||
import logging
|
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from tkinter import font
|
from tkinter import font
|
||||||
|
|
||||||
|
from core.api.grpc import core_pb2
|
||||||
|
|
||||||
TEXT_DISTANCE = 0.30
|
TEXT_DISTANCE = 0.30
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,6 +77,7 @@ class Throughput:
|
||||||
self.tracker = {}
|
self.tracker = {}
|
||||||
# map an edge canvas id to a throughput canvas id
|
# map an edge canvas id to a throughput canvas id
|
||||||
self.map = {}
|
self.map = {}
|
||||||
|
# map edge canvas id to token
|
||||||
self.edge_id_to_token = {}
|
self.edge_id_to_token = {}
|
||||||
|
|
||||||
def load_throughput_info(self, interface_throughputs):
|
def load_throughput_info(self, interface_throughputs):
|
||||||
|
@ -86,21 +88,23 @@ class Throughput:
|
||||||
throughputs
|
throughputs
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
for t in interface_throughputs:
|
for throughput in interface_throughputs:
|
||||||
nid = t.node_id
|
nid = throughput.node_id
|
||||||
iid = t.interface_id
|
iid = throughput.interface_id
|
||||||
tp = t.throughput
|
tp = throughput.throughput
|
||||||
token = self.core.interface_to_edge[(nid, iid)]
|
token = self.core.interface_to_edge.get((nid, iid))
|
||||||
print(token)
|
if token:
|
||||||
edge_id = self.canvas.edges[token].id
|
edge = self.canvas.edges.get(token)
|
||||||
|
if edge:
|
||||||
self.edge_id_to_token[edge_id] = token
|
edge_id = edge.id
|
||||||
|
self.edge_id_to_token[edge_id] = token
|
||||||
if edge_id not in self.tracker:
|
if edge_id not in self.tracker:
|
||||||
self.tracker[edge_id] = tp
|
self.tracker[edge_id] = tp
|
||||||
else:
|
else:
|
||||||
temp = self.tracker[edge_id]
|
temp = self.tracker[edge_id]
|
||||||
self.tracker[edge_id] = (temp + tp) / 2
|
self.tracker[edge_id] = (temp + tp) / 2
|
||||||
|
else:
|
||||||
|
self.core.interface_to_edge.pop((nid, iid), None)
|
||||||
|
|
||||||
def edge_is_wired(self, token):
|
def edge_is_wired(self, token):
|
||||||
"""
|
"""
|
||||||
|
@ -112,41 +116,35 @@ class Throughput:
|
||||||
canvas_edge = self.canvas.edges[token]
|
canvas_edge = self.canvas.edges[token]
|
||||||
canvas_src_id = canvas_edge.src
|
canvas_src_id = canvas_edge.src
|
||||||
canvas_dst_id = canvas_edge.dst
|
canvas_dst_id = canvas_edge.dst
|
||||||
src_node = self.canvas.nodes[canvas_src_id]
|
src = self.canvas.nodes[canvas_src_id].core_node
|
||||||
dst_node = self.canvas.nodes[canvas_dst_id]
|
dst = self.canvas.nodes[canvas_dst_id].core_node
|
||||||
|
return not (
|
||||||
if src_node.node_type == "wlan":
|
src.type == core_pb2.NodeType.WIRELESS_LAN
|
||||||
if dst_node.node_type == "mdr":
|
and dst.model == "mdr"
|
||||||
return False
|
or src.model == "mdr"
|
||||||
else:
|
and dst.type == core_pb2.NodeType.WIRELESS_LAN
|
||||||
logging.debug("linkinfo.py is_wired WARNING wlan only connected to mdr")
|
)
|
||||||
return True
|
|
||||||
if dst_node.node_type == "wlan":
|
|
||||||
if src_node.node_type == "mdr":
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
logging.debug("linkinfo.py is_wired WARNING wlan only connected to mdr")
|
|
||||||
return True
|
|
||||||
return True
|
|
||||||
|
|
||||||
def draw_wired_throughput(self, edge_id):
|
def draw_wired_throughput(self, edge_id):
|
||||||
|
|
||||||
x1, y1, x2, y2 = self.canvas.coords(edge_id)
|
x0, y0, x1, y1 = self.canvas.coords(edge_id)
|
||||||
x = (x1 + x2) / 2
|
x = (x0 + x1) / 2
|
||||||
y = (y1 + y2) / 2
|
y = (y0 + y1) / 2
|
||||||
|
|
||||||
if edge_id not in self.map:
|
if edge_id not in self.map:
|
||||||
tp_id = self.canvas.create_text(
|
tpid = self.canvas.create_text(
|
||||||
x, y, text="{0:.3f} kbps".format(0.001 * self.tracker[edge_id])
|
x,
|
||||||
)
|
y,
|
||||||
self.map[edge_id] = tp_id
|
tags="throughput",
|
||||||
|
font=("Arial", 8),
|
||||||
# redraw throughput
|
|
||||||
else:
|
|
||||||
self.canvas.itemconfig(
|
|
||||||
self.map[edge_id],
|
|
||||||
text="{0:.3f} kbps".format(0.001 * self.tracker[edge_id]),
|
text="{0:.3f} kbps".format(0.001 * self.tracker[edge_id]),
|
||||||
)
|
)
|
||||||
|
self.map[edge_id] = tpid
|
||||||
|
else:
|
||||||
|
tpid = self.map[edge_id]
|
||||||
|
self.canvas.coords(tpid, x, y)
|
||||||
|
self.canvas.itemconfig(
|
||||||
|
tpid, text="{0:.3f} kbps".format(0.001 * self.tracker[edge_id])
|
||||||
|
)
|
||||||
|
|
||||||
def draw_wireless_throughput(self, edge_id):
|
def draw_wireless_throughput(self, edge_id):
|
||||||
token = self.edge_id_to_token[edge_id]
|
token = self.edge_id_to_token[edge_id]
|
||||||
|
@ -156,17 +154,19 @@ class Throughput:
|
||||||
src_node = self.canvas.nodes[canvas_src_id]
|
src_node = self.canvas.nodes[canvas_src_id]
|
||||||
dst_node = self.canvas.nodes[canvas_dst_id]
|
dst_node = self.canvas.nodes[canvas_dst_id]
|
||||||
|
|
||||||
# non_wlan_node = None
|
not_wlan = (
|
||||||
if src_node.node_type == "wlan":
|
dst_node
|
||||||
non_wlan_node = dst_node
|
if src_node.core_node.type == core_pb2.NodeType.WIRELESS_LAN
|
||||||
else:
|
else src_node
|
||||||
non_wlan_node = src_node
|
)
|
||||||
|
|
||||||
x, y = self.canvas.coords(non_wlan_node.id)
|
x, y = self.canvas.coords(not_wlan.id)
|
||||||
if edge_id not in self.map:
|
if edge_id not in self.map:
|
||||||
tp_id = self.canvas.create_text(
|
tp_id = self.canvas.create_text(
|
||||||
x + 50,
|
x + 50,
|
||||||
y + 25,
|
y + 25,
|
||||||
|
font=("Arial", 8),
|
||||||
|
tags="throughput",
|
||||||
text="{0:.3f} kbps".format(0.001 * self.tracker[edge_id]),
|
text="{0:.3f} kbps".format(0.001 * self.tracker[edge_id]),
|
||||||
)
|
)
|
||||||
self.map[edge_id] = tp_id
|
self.map[edge_id] = tp_id
|
||||||
|
@ -184,43 +184,33 @@ class Throughput:
|
||||||
self.draw_wired_throughput(edge_id)
|
self.draw_wired_throughput(edge_id)
|
||||||
else:
|
else:
|
||||||
self.draw_wireless_throughput(edge_id)
|
self.draw_wireless_throughput(edge_id)
|
||||||
# draw wireless throughput
|
|
||||||
|
|
||||||
# x1, y1, x2, y2 = self.canvas.coords(edge_id)
|
|
||||||
# x = (x1 + x2) / 2
|
|
||||||
# y = (y1 + y2) / 2
|
|
||||||
#
|
|
||||||
# print(self.is_wired(self.edge_id_to_token[edge_id]))
|
|
||||||
# # new throughput
|
|
||||||
# if edge_id not in self.map:
|
|
||||||
# tp_id = self.canvas.create_text(
|
|
||||||
# x, y, text="{0:.3f} kbps".format(0.001 * self.tracker[edge_id])
|
|
||||||
# )
|
|
||||||
# self.map[edge_id] = tp_id
|
|
||||||
#
|
|
||||||
# # redraw throughput
|
|
||||||
# else:
|
|
||||||
# self.canvas.itemconfig(
|
|
||||||
# self.map[edge_id],
|
|
||||||
# text="{0:.3f} kbps".format(0.001 * self.tracker[edge_id]),
|
|
||||||
# )
|
|
||||||
|
|
||||||
def process_grpc_throughput_event(self, interface_throughputs):
|
def process_grpc_throughput_event(self, interface_throughputs):
|
||||||
self.load_throughput_info(interface_throughputs)
|
self.load_throughput_info(interface_throughputs)
|
||||||
self.draw_throughputs()
|
self.draw_throughputs()
|
||||||
|
|
||||||
def update_throughtput_location(self, edge):
|
def move(self, edge):
|
||||||
tp_id = self.map[edge.id]
|
tpid = self.map.get(edge.id)
|
||||||
if self.edge_is_wired(self.edge_id_to_token[edge.id]):
|
if tpid:
|
||||||
x1, y1 = self.canvas.coords(edge.src)
|
if self.edge_is_wired(edge.token):
|
||||||
x2, y2 = self.canvas.coords(edge.dst)
|
x0, y0, x1, y1 = self.canvas.coords(edge.id)
|
||||||
x = (x1 + x2) / 2
|
self.canvas.coords(tpid, (x0 + x1) / 2, (y0 + y1) / 2)
|
||||||
y = (y1 + y2) / 2
|
|
||||||
self.canvas.coords(tp_id, x, y)
|
|
||||||
else:
|
|
||||||
if self.canvas.nodes[edge.src].node_type == "wlan":
|
|
||||||
x, y = self.canvas.coords(edge.dst)
|
|
||||||
self.canvas.coords(tp_id, x + 50, y + 20)
|
|
||||||
else:
|
else:
|
||||||
x, y = self.canvas.coords(edge.src)
|
if (
|
||||||
self.canvas.coords(tp_id, x + 50, y + 25)
|
self.canvas.nodes[edge.src].core_node.type
|
||||||
|
== core_pb2.NodeType.WIRELESS_LAN
|
||||||
|
):
|
||||||
|
x, y = self.canvas.coords(edge.dst)
|
||||||
|
self.canvas.coords(tpid, x + 50, y + 20)
|
||||||
|
else:
|
||||||
|
x, y = self.canvas.coords(edge.src)
|
||||||
|
self.canvas.coords(tpid, x + 50, y + 25)
|
||||||
|
|
||||||
|
def delete(self, edge):
|
||||||
|
tpid = self.map.get(edge.id)
|
||||||
|
if tpid:
|
||||||
|
eid = edge.id
|
||||||
|
self.canvas.delete(tpid)
|
||||||
|
self.tracker.pop(eid)
|
||||||
|
self.map.pop(eid)
|
||||||
|
self.edge_id_to_token.pop(eid)
|
||||||
|
|
|
@ -122,6 +122,8 @@ class CanvasNode:
|
||||||
self.canvas.coords(edge.id, x, y, x2, y2)
|
self.canvas.coords(edge.id, x, y, x2, y2)
|
||||||
else:
|
else:
|
||||||
self.canvas.coords(edge.id, x1, y1, x, y)
|
self.canvas.coords(edge.id, x1, y1, x, y)
|
||||||
|
self.canvas.throughput_draw.move(edge)
|
||||||
|
|
||||||
edge.link_info.recalculate_info()
|
edge.link_info.recalculate_info()
|
||||||
for edge in self.wireless_edges:
|
for edge in self.wireless_edges:
|
||||||
x1, y1, x2, y2 = self.canvas.coords(edge.id)
|
x1, y1, x2, y2 = self.canvas.coords(edge.id)
|
||||||
|
|
Loading…
Add table
Reference in a new issue