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:
parent
b71272519d
commit
dc9b6adc98
7 changed files with 61 additions and 45 deletions
|
@ -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,22 +365,25 @@ def convert_iface(iface: CoreInterface) -> core_pb2.Interface:
|
|||
:param iface: interface to convert
|
||||
:return: protobuf interface
|
||||
"""
|
||||
ip4 = iface.get_ip4()
|
||||
ip4_mask = ip4.prefixlen if ip4 else None
|
||||
ip4 = str(ip4.ip) if ip4 else None
|
||||
ip6 = iface.get_ip6()
|
||||
ip6_mask = ip6.prefixlen if ip6 else None
|
||||
ip6 = str(ip6.ip) if ip6 else None
|
||||
mac = str(iface.mac) if iface.mac else None
|
||||
return core_pb2.Interface(
|
||||
id=iface.id,
|
||||
name=iface.name,
|
||||
mac=mac,
|
||||
ip4=ip4,
|
||||
ip4_mask=ip4_mask,
|
||||
ip6=ip6,
|
||||
ip6_mask=ip6_mask,
|
||||
)
|
||||
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
|
||||
ip6 = iface.get_ip6()
|
||||
ip6_mask = ip6.prefixlen if ip6 else None
|
||||
ip6 = str(ip6.ip) if ip6 else None
|
||||
mac = str(iface.mac) if iface.mac else None
|
||||
return core_pb2.Interface(
|
||||
id=iface.id,
|
||||
name=iface.name,
|
||||
mac=mac,
|
||||
ip4=ip4,
|
||||
ip4_mask=ip4_mask,
|
||||
ip6=ip6,
|
||||
ip6_mask=ip6_mask,
|
||||
)
|
||||
|
||||
|
||||
def convert_core_link(core_link: CoreLink) -> List[core_pb2.Link]:
|
||||
|
|
|
@ -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,10 +706,16 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
)
|
||||
iface1_data = None
|
||||
if node1_iface:
|
||||
iface1_data = node1_iface.get_data()
|
||||
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:
|
||||
iface2_data = node2_iface.get_data()
|
||||
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(
|
||||
message_type=MessageFlags.ADD,
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,22 +258,26 @@ class InterfaceManager:
|
|||
|
||||
def create_iface(self, canvas_node: CanvasNode, wireless_link: bool) -> Interface:
|
||||
node = canvas_node.core_node
|
||||
ip4, ip6 = self.get_ips(node)
|
||||
if wireless_link:
|
||||
ip4_mask = WIRELESS_IP4_MASK
|
||||
ip6_mask = WIRELESS_IP6_MASK
|
||||
if nutils.is_bridge(node):
|
||||
iface_id = canvas_node.next_iface_id()
|
||||
iface = Interface(id=iface_id)
|
||||
else:
|
||||
ip4_mask = IP4_MASK
|
||||
ip6_mask = IP6_MASK
|
||||
iface_id = canvas_node.next_iface_id()
|
||||
name = f"eth{iface_id}"
|
||||
iface = Interface(
|
||||
id=iface_id,
|
||||
name=name,
|
||||
ip4=ip4,
|
||||
ip4_mask=ip4_mask,
|
||||
ip6=ip6,
|
||||
ip6_mask=ip6_mask,
|
||||
)
|
||||
ip4, ip6 = self.get_ips(node)
|
||||
if wireless_link:
|
||||
ip4_mask = WIRELESS_IP4_MASK
|
||||
ip6_mask = WIRELESS_IP6_MASK
|
||||
else:
|
||||
ip4_mask = IP4_MASK
|
||||
ip6_mask = IP6_MASK
|
||||
iface_id = canvas_node.next_iface_id()
|
||||
name = f"eth{iface_id}"
|
||||
iface = Interface(
|
||||
id=iface_id,
|
||||
name=name,
|
||||
ip4=ip4,
|
||||
ip4_mask=ip4_mask,
|
||||
ip6=ip6,
|
||||
ip6_mask=ip6_mask,
|
||||
)
|
||||
logger.info("create node(%s) interface(%s)", node.name, iface)
|
||||
return iface
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue