daemon/gui: adjustments to account for network node wired links having proper interface ids, which allow for unique configuration with the new linking semantics

This commit is contained in:
Blake Harnden 2022-03-18 15:53:13 -07:00
parent b71272519d
commit dc9b6adc98
7 changed files with 61 additions and 45 deletions

View file

@ -28,7 +28,7 @@ from core.nodes.base import CoreNode, CoreNodeBase, NodeBase
from core.nodes.docker import DockerNode
from core.nodes.interface import CoreInterface
from core.nodes.lxd import LxcNode
from core.nodes.network import CtrlNet, PtpNet, WlanNode
from core.nodes.network import CoreNetwork, CtrlNet, PtpNet, WlanNode
from core.services.coreservices import CoreService
logger = logging.getLogger(__name__)
@ -365,6 +365,9 @@ def convert_iface(iface: CoreInterface) -> core_pb2.Interface:
:param iface: interface to convert
:return: protobuf interface
"""
if isinstance(iface.node, CoreNetwork):
return core_pb2.Interface(id=iface.id)
else:
ip4 = iface.get_ip4()
ip4_mask = ip4.prefixlen if ip4 else None
ip4 = str(ip4.ip) if ip4 else None

View file

@ -81,7 +81,7 @@ from core.emulator.session import NT, Session
from core.errors import CoreCommandError, CoreError
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
from core.nodes.base import CoreNode, NodeBase
from core.nodes.network import WlanNode
from core.nodes.network import CoreNetwork, WlanNode
from core.services.coreservices import ServiceManager
logger = logging.getLogger(__name__)
@ -706,9 +706,15 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
)
iface1_data = None
if node1_iface:
if isinstance(node1_iface.node, CoreNetwork):
iface1_data = InterfaceData(id=node1_iface.id)
else:
iface1_data = node1_iface.get_data()
iface2_data = None
if node2_iface:
if isinstance(node2_iface.node, CoreNetwork):
iface2_data = InterfaceData(id=node2_iface.id)
else:
iface2_data = node2_iface.get_data()
source = request.source if request.source else None
link_data = LinkData(

View file

@ -307,12 +307,8 @@ class Session:
:param options: options to configure interfaces with
:return: interfaces created for both nodes
"""
# create interface
if iface1_data and isinstance(node1, CoreNetworkBase):
iface1_data.id = None
# create interfaces
iface1 = node1.create_iface(iface1_data, options)
if iface2_data and isinstance(node2, CoreNetworkBase):
iface2_data.id = None
iface2 = node2.create_iface(iface2_data, options)
# join and attach to ptp bridge
ptp = self.create_node(PtpNet, self.state.should_start())

View file

@ -275,7 +275,7 @@ class NodeConfigDialog(Dialog):
ifaces_scroll.listbox.bind("<<ListboxSelect>>", self.iface_select)
# interfaces
if self.canvas_node.ifaces:
if nutils.is_container(self.node):
self.draw_ifaces()
self.draw_spacer()

View file

@ -298,7 +298,10 @@ class CanvasNode:
other_iface = edge.other_iface(self)
label = other_node.core_node.name
if other_iface:
label = f"{label}:{other_iface.name}"
iface_label = other_iface.id
if other_iface.name:
iface_label = other_iface.name
label = f"{label}:{iface_label}"
func_unlink = functools.partial(self.click_unlink, edge)
unlink_menu.add_command(label=label, command=func_unlink)
themes.style_menu(unlink_menu)

View file

@ -241,10 +241,10 @@ class InterfaceManager:
dst_node = edge.dst.core_node
self.determine_subnets(edge.src, edge.dst)
src_iface = None
if nutils.is_container(src_node):
if nutils.is_iface_node(src_node):
src_iface = self.create_iface(edge.src, edge.linked_wireless)
dst_iface = None
if nutils.is_container(dst_node):
if nutils.is_iface_node(dst_node):
dst_iface = self.create_iface(edge.dst, edge.linked_wireless)
link = Link(
type=LinkType.WIRED,
@ -258,6 +258,10 @@ class InterfaceManager:
def create_iface(self, canvas_node: CanvasNode, wireless_link: bool) -> Interface:
node = canvas_node.core_node
if nutils.is_bridge(node):
iface_id = canvas_node.next_iface_id()
iface = Interface(id=iface_id)
else:
ip4, ip6 = self.get_ips(node)
if wireless_link:
ip4_mask = WIRELESS_IP4_MASK

View file

@ -97,6 +97,10 @@ def is_custom(node: Node) -> bool:
return is_model(node) and node.model not in NODE_MODELS
def is_iface_node(node: Node) -> bool:
return is_container(node) or is_bridge(node)
def get_custom_services(gui_config: GuiConfig, name: str) -> List[str]:
for custom_node in gui_config.nodes:
if custom_node.name == name: