modified wireless links to obtain colors based on connected network from the session, LinkData will no provide a color itself

This commit is contained in:
Blake Harnden 2020-04-15 15:41:37 -07:00
parent 42979f1bb3
commit e2490dee4a
10 changed files with 33 additions and 22 deletions

View file

@ -86,6 +86,7 @@ def handle_link_event(event: LinkData) -> core_pb2.LinkEvent:
options=options,
network_id=event.network_id,
label=event.label,
color=event.color,
)
return core_pb2.LinkEvent(message_type=event.message_type.value, link=link)

View file

@ -372,6 +372,7 @@ def convert_link(session: Session, link_data: LinkData) -> core_pb2.Link:
options=options,
network_id=link_data.network_id,
label=link_data.label,
color=link_data.color,
)

View file

@ -1494,12 +1494,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
flag = MessageFlags.ADD
else:
flag = MessageFlags.DELETE
color = session.get_link_color(emane_one.id)
link = LinkData(
message_type=flag,
link_type=LinkTypes.WIRELESS,
node1_id=node_one.id,
node2_id=node_two.id,
network_id=emane_one.id,
color=color,
)
session.broadcast_link(link)
return EmaneLinkResponse(result=True)

View file

@ -314,6 +314,7 @@ class EmaneLinkMonitor:
node_two: int,
emane_id: int,
) -> None:
color = self.emane_manager.session.get_link_color(emane_id)
link_data = LinkData(
message_type=message_type,
label=label,
@ -321,6 +322,7 @@ class EmaneLinkMonitor:
node2_id=node_two,
network_id=emane_id,
link_type=LinkTypes.WIRELESS,
color=color,
)
self.emane_manager.session.broadcast_link(link_data)

View file

@ -129,3 +129,4 @@ class LinkData:
interface2_ip6: str = None
interface2_ip6_mask: int = None
opaque: str = None
color: str = None

View file

@ -76,6 +76,7 @@ NODES = {
}
NODES_TYPE = {NODES[x]: x for x in NODES}
CTRL_NET_ID = 9001
LINK_COLORS = ["green", "blue", "orange", "purple", "turquoise"]
class Session:
@ -105,6 +106,7 @@ class Session:
self.thumbnail = None
self.user = None
self.event_loop = EventLoop()
self.link_colors = {}
# dict of nodes: all nodes and nets
self.node_id_gen = IdGen()
@ -927,6 +929,7 @@ class Session:
self.location.reset()
self.services.reset()
self.mobility.config_reset()
self.link_colors.clear()
def start_events(self) -> None:
"""
@ -1956,3 +1959,17 @@ class Session:
else:
node = self.get_node(node_id)
node.cmd(data, wait=False)
def get_link_color(self, network_id: int) -> str:
"""
Assign a color for links associated with a network.
:param network_id: network to get a link color for
:return: link color
"""
color = self.link_colors.get(network_id)
if not color:
index = len(self.link_colors) % len(LINK_COLORS)
color = LINK_COLORS[index]
self.link_colors[network_id] = color
return color

View file

@ -212,6 +212,8 @@ class CanvasGraph(tk.Canvas):
edge = CanvasWirelessEdge(self, src.id, dst.id, src_pos, dst_pos, token)
if link.label:
edge.middle_label_text(link.label)
if link.color:
edge.color = link.color
self.wireless_edges[token] = edge
src.wireless_edges.add(edge)
dst.wireless_edges.add(edge)

View file

@ -488,12 +488,14 @@ class BasicRangeModel(WirelessModel):
:param message_type: link message type
:return: link data
"""
color = self.session.get_link_color(self.wlan.id)
return LinkData(
message_type=message_type,
node1_id=interface1.node.id,
node2_id=interface2.node.id,
network_id=self.wlan.id,
link_type=LinkTypes.WIRELESS,
color=color,
)
def sendlinkmsg(

View file

@ -33,7 +33,6 @@ NODE_LAYER = "CORE::Nodes"
LINK_LAYER = "CORE::Links"
CORE_LAYERS = [CORE_LAYER, LINK_LAYER, NODE_LAYER]
DEFAULT_LINK_COLOR = "red"
LINK_COLORS = ["green", "blue", "orange", "purple", "white"]
class Sdt:
@ -73,7 +72,6 @@ class Sdt:
self.url = self.DEFAULT_SDT_URL
self.address = None
self.protocol = None
self.colors = {}
self.network_layers = set()
self.session.node_handlers.append(self.handle_node_update)
self.session.link_handlers.append(self.handle_link_update)
@ -180,7 +178,6 @@ class Sdt:
self.cmd(f"delete layer,{layer}")
self.disconnect()
self.network_layers.clear()
self.colors.clear()
def cmd(self, cmdstr: str) -> bool:
"""
@ -353,24 +350,6 @@ class Sdt:
pass
return result
def get_link_line(self, network_id: int) -> str:
"""
Retrieve link line color based on network.
:param network_id: network id of link, None for wired links
:return: link line configuration
"""
network = self.session.nodes.get(network_id)
if network:
color = self.colors.get(network_id)
if not color:
index = len(self.colors) % len(LINK_COLORS)
color = LINK_COLORS[index]
self.colors[network_id] = color
else:
color = DEFAULT_LINK_COLOR
return f"{color},2"
def add_link(
self, node_one: int, node_two: int, network_id: int = None, label: str = None
) -> None:
@ -388,7 +367,10 @@ class Sdt:
return
if self.wireless_net_check(node_one) or self.wireless_net_check(node_two):
return
line = self.get_link_line(network_id)
color = DEFAULT_LINK_COLOR
if network_id:
color = self.session.get_link_color(network_id)
line = f"{color},2"
link_id = get_link_id(node_one, node_two, network_id)
layer = LINK_LAYER
if network_id:

View file

@ -688,6 +688,7 @@ message Link {
LinkOptions options = 6;
int32 network_id = 7;
string label = 8;
string color = 9;
}
message LinkOptions {