From c402ce5284dad4ff7917be7d2b01e4ce5d64dc78 Mon Sep 17 00:00:00 2001 From: Huy Pham <42948410+hpham@users.noreply.github.com> Date: Wed, 8 Jan 2020 09:32:39 -0800 Subject: [PATCH] allow choosing local host machine interface for rj45 node --- daemon/core/gui/coreclient.py | 9 ++++++++- daemon/core/gui/dialogs/nodeconfig.py | 21 ++++++++++++++++++++- daemon/core/gui/nodeutils.py | 5 +++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/daemon/core/gui/coreclient.py b/daemon/core/gui/coreclient.py index f30dcc94..4032d975 100644 --- a/daemon/core/gui/coreclient.py +++ b/daemon/core/gui/coreclient.py @@ -702,10 +702,17 @@ class CoreClient: emane = None if node_type == core_pb2.NodeType.EMANE: emane = self.emane_models[0] + name = f"EMANE{node_id}" + elif node_type == core_pb2.NodeType.WIRELESS_LAN: + name = f"WLAN{node_id}" + elif node_type in [core_pb2.NodeType.RJ45, core_pb2.NodeType.TUNNEL]: + name = "UNASSIGNED" + else: + name = f"n{node_id}" node = core_pb2.Node( id=node_id, type=node_type, - name=f"n{node_id}", + name=name, model=model, position=position, image=image, diff --git a/daemon/core/gui/dialogs/nodeconfig.py b/daemon/core/gui/dialogs/nodeconfig.py index 47ac9389..c3dd646a 100644 --- a/daemon/core/gui/dialogs/nodeconfig.py +++ b/daemon/core/gui/dialogs/nodeconfig.py @@ -10,7 +10,7 @@ from core.gui.dialogs.emaneconfig import EmaneModelDialog from core.gui.images import Images from core.gui.nodeutils import NodeUtils from core.gui.themes import FRAME_PAD, PADX, PADY -from core.gui.widgets import image_chooser +from core.gui.widgets import ListboxScroll, image_chooser def mac_auto(is_auto, entry): @@ -131,6 +131,18 @@ class NodeConfigDialog(Dialog): combobox.grid(row=row, column=1, sticky="ew") row += 1 + if NodeUtils.is_rj45_node(self.node.type): + response = self.app.core.client.get_interfaces() + logging.debug("host machine available interfaces: %s", response) + interfaces = ListboxScroll(frame) + interfaces.grid( + row=row, column=0, columnspan=2, sticky="ew", padx=PADX, pady=PADY + ) + for inf in sorted(response.interfaces[:]): + interfaces.listbox.insert(tk.END, inf) + row += 1 + interfaces.listbox.bind("<>", self.interface_select) + # interfaces if self.canvas_node.interfaces: self.draw_interfaces() @@ -235,3 +247,10 @@ class NodeConfigDialog(Dialog): # redraw self.canvas_node.redraw() self.destroy() + + def interface_select(self, event): + listbox = event.widget + cur = listbox.curselection() + if cur: + interface = listbox.get(cur[0]) + self.name.set(interface) diff --git a/daemon/core/gui/nodeutils.py b/daemon/core/gui/nodeutils.py index 779e52f8..9867998a 100644 --- a/daemon/core/gui/nodeutils.py +++ b/daemon/core/gui/nodeutils.py @@ -47,6 +47,7 @@ class NodeUtils: CONTAINER_NODES = {NodeType.DEFAULT, NodeType.DOCKER, NodeType.LXC} IMAGE_NODES = {NodeType.DOCKER, NodeType.LXC} WIRELESS_NODES = {NodeType.WIRELESS_LAN, NodeType.EMANE} + RJ45_NODES = {NodeType.RJ45} IGNORE_NODES = {NodeType.CONTROL_NET, NodeType.PEER_TO_PEER} NODE_MODELS = {"router", "host", "PC", "mdr", "prouter"} ANTENNA_ICON = None @@ -71,6 +72,10 @@ class NodeUtils: def is_wireless_node(cls, node_type): return node_type in cls.WIRELESS_NODES + @classmethod + def is_rj45_node(cls, node_type): + return node_type in cls.RJ45_NODES + @classmethod def node_icon(cls, node_type, model): if model == "":