From ad839bbc07f39d7e3f19357e2785e8e5d7b31a12 Mon Sep 17 00:00:00 2001 From: Riley Baxter Date: Mon, 14 Dec 2020 13:08:52 -0500 Subject: [PATCH 1/3] Fix session id attribute name in UDP TLV API Handler --- daemon/core/api/tlv/corehandlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon/core/api/tlv/corehandlers.py b/daemon/core/api/tlv/corehandlers.py index b99b8630..65abed8c 100644 --- a/daemon/core/api/tlv/corehandlers.py +++ b/daemon/core/api/tlv/corehandlers.py @@ -2029,7 +2029,7 @@ class CoreUdpHandler(CoreHandler): for session_id in sessions: session = self.server.mainserver.coreemu.sessions.get(session_id) if session: - logging.debug("session handling message: %s", session.session_id) + logging.debug("session handling message: %s", session.id) self.session = session self.handle_message(message) self.broadcast(message) From 4b6afe4db7dacc5928e8ac8e26b49c321eee00c4 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Tue, 15 Dec 2020 09:34:42 -0800 Subject: [PATCH 2/3] daemon: fix for deleting an interface from rj45 node, better error messaging when trying to add an interface to a node that already exists --- daemon/core/nodes/base.py | 7 ++++++- daemon/core/nodes/physical.py | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/daemon/core/nodes/base.py b/daemon/core/nodes/base.py index 9069b14c..9a301432 100644 --- a/daemon/core/nodes/base.py +++ b/daemon/core/nodes/base.py @@ -837,7 +837,12 @@ class CoreNode(CoreNodeBase): if net.has_custom_iface: return net.custom_iface(self, iface_data) else: - iface_id = self.newveth(iface_data.id, iface_data.name) + iface_id = iface_data.id + if iface_id is not None and iface_id in self.ifaces: + raise CoreError( + f"node({self.name}) already has interface({iface_id})" + ) + iface_id = self.newveth(iface_id, iface_data.name) self.attachnet(iface_id, net) if iface_data.mac: self.set_mac(iface_id, iface_data.mac) diff --git a/daemon/core/nodes/physical.py b/daemon/core/nodes/physical.py index e69985ef..4e8c9464 100644 --- a/daemon/core/nodes/physical.py +++ b/daemon/core/nodes/physical.py @@ -266,7 +266,9 @@ class Rj45Node(CoreNodeBase): will run on, default is None for localhost """ super().__init__(session, _id, name, server) - self.iface = CoreInterface(session, self, name, name, mtu, server) + self.iface: CoreInterface = CoreInterface( + session, self, name, name, mtu, server + ) self.iface.transport_type = TransportType.RAW self.lock: threading.RLock = threading.RLock() self.iface_id: Optional[int] = None @@ -335,11 +337,12 @@ class Rj45Node(CoreNodeBase): if iface_id is None: iface_id = 0 if self.iface.net is not None: - raise CoreError("RJ45 nodes support at most 1 network interface") + raise CoreError( + f"RJ45({self.name}) nodes support at most 1 network interface" + ) self.ifaces[iface_id] = self.iface self.iface_id = iface_id - if net is not None: - self.iface.attachnet(net) + self.iface.attachnet(net) for ip in iface_data.get_ips(): self.add_ip(ip) return self.iface @@ -353,6 +356,12 @@ class Rj45Node(CoreNodeBase): """ self.get_iface(iface_id) self.ifaces.pop(iface_id) + if self.iface.net is None: + raise CoreError( + f"RJ45({self.name}) is not currently connected to a network" + ) + self.iface.detachnet() + self.iface.net = None self.shutdown() def get_iface(self, iface_id: int) -> CoreInterface: From 4ec9ea7b1622de31dc4171ef41bfc1e192ef89b8 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Wed, 16 Dec 2020 10:19:17 -0800 Subject: [PATCH 3/3] daemon: small cleanup to boot nodes logic, moved control interface creation to occur before service startup avoiding thread race conditions validating if an interface is for a control network --- daemon/core/emulator/session.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/daemon/core/emulator/session.py b/daemon/core/emulator/session.py index d98564ed..29f85917 100644 --- a/daemon/core/emulator/session.py +++ b/daemon/core/emulator/session.py @@ -13,7 +13,7 @@ import tempfile import threading import time from pathlib import Path -from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, TypeVar +from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, TypeVar, Union from core import constants, utils from core.configservice.manager import ConfigServiceManager @@ -571,11 +571,11 @@ class Session: if isinstance(node, WlanNode): self.mobility.set_model_config(_id, BasicRangeModel.name) - # boot nodes after runtime, CoreNodes, Physical, and RJ45 are all nodes - is_boot_node = isinstance(node, CoreNodeBase) and not isinstance(node, Rj45Node) + # boot nodes after runtime CoreNodes and PhysicalNodes + is_boot_node = isinstance(node, (CoreNode, PhysicalNode)) if self.state == EventTypes.RUNTIME_STATE and is_boot_node: self.write_nodes() - self.add_remove_control_iface(node=node, remove=False) + self.add_remove_control_iface(node, remove=False) self.services.boot_services(node) self.sdt.add_node(node) @@ -1310,7 +1310,6 @@ class Session: :return: nothing """ logging.info("booting node(%s): %s", node.name, [x.name for x in node.services]) - self.add_remove_control_iface(node=node, remove=False) self.services.boot_services(node) node.start_config_services() @@ -1325,11 +1324,10 @@ class Session: with self.nodes_lock: funcs = [] start = time.monotonic() - for _id in self.nodes: - node = self.nodes[_id] - if isinstance(node, CoreNodeBase) and not isinstance(node, Rj45Node): - args = (node,) - funcs.append((self.boot_node, args, {})) + for node in self.nodes.values(): + if isinstance(node, (CoreNode, PhysicalNode)): + self.add_remove_control_iface(node, remove=False) + funcs.append((self.boot_node, (node,), {})) results, exceptions = utils.threadpool(funcs) total = time.monotonic() - start logging.debug("boot run time: %s", total) @@ -1477,7 +1475,7 @@ class Session: def add_remove_control_iface( self, - node: CoreNode, + node: Union[CoreNode, PhysicalNode], net_index: int = 0, remove: bool = False, conf_required: bool = True,