diff --git a/daemon/core/api/grpc/server.py b/daemon/core/api/grpc/server.py index 842400ca..f657c20a 100644 --- a/daemon/core/api/grpc/server.py +++ b/daemon/core/api/grpc/server.py @@ -1104,7 +1104,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): node_id = request.wlan_config.node_id config = request.wlan_config.config session.mobility.set_model_config(node_id, BasicRangeModel.name, config) - if session.state == EventTypes.RUNTIME_STATE: + if session.is_running(): node = self.get_node(session, node_id, context, WlanNode) node.updatemodel(config) return SetWlanConfigResponse(result=True) diff --git a/daemon/core/emane/nodes.py b/daemon/core/emane/nodes.py index 1a0b6e75..7264fe88 100644 --- a/daemon/core/emane/nodes.py +++ b/daemon/core/emane/nodes.py @@ -10,7 +10,7 @@ from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Type, Union from core.emulator.data import InterfaceData, LinkData, LinkOptions from core.emulator.distributed import DistributedServer -from core.emulator.enumerations import EventTypes, MessageFlags, RegisterTlvs +from core.emulator.enumerations import MessageFlags, RegisterTlvs from core.errors import CoreCommandError, CoreError from core.nodes.base import CoreNetworkBase, CoreNode, NodeOptions from core.nodes.interface import CoreInterface @@ -167,7 +167,7 @@ class EmaneNet(CoreNetworkBase): self.mobility: Optional[WayPointMobility] = None model_class = self.session.emane.get_model(options.emane_model) self.wireless_model: Optional["EmaneModel"] = model_class(self.session, self.id) - if self.session.state == EventTypes.RUNTIME_STATE: + if self.session.is_running(): self.session.emane.add_node(self) @classmethod @@ -280,7 +280,7 @@ class EmaneNet(CoreNetworkBase): self.attach(iface) if self.up: iface.startup() - if self.session.state == EventTypes.RUNTIME_STATE: + if self.session.is_running(): self.session.emane.start_iface(self, iface) return iface diff --git a/daemon/core/emulator/session.py b/daemon/core/emulator/session.py index b8b1b35e..bd4953d1 100644 --- a/daemon/core/emulator/session.py +++ b/daemon/core/emulator/session.py @@ -520,8 +520,7 @@ class Session: if isinstance(node, WlanNode): self.mobility.set_model_config(node.id, BasicRangeModel.name) # boot core nodes after runtime - is_runtime = self.state == EventTypes.RUNTIME_STATE - if is_runtime and isinstance(node, CoreNode): + if self.is_running() and isinstance(node, CoreNode): self.add_remove_control_iface(node, remove=False) self.boot_node(node) self.sdt.add_node(node) @@ -1011,7 +1010,7 @@ class Session: :return: list of service boot errors during startup """ - if self.state == EventTypes.RUNTIME_STATE: + if self.is_running(): logger.warning("ignoring instantiate, already in runtime state") return [] # create control net interfaces and network tunnels @@ -1365,7 +1364,7 @@ class Session: Return the current time we have been in the runtime state, or zero if not in runtime. """ - if self.state == EventTypes.RUNTIME_STATE: + if self.is_running(): return time.monotonic() - self.state_time else: return 0.0 @@ -1442,3 +1441,11 @@ class Session: color = LINK_COLORS[index] self.link_colors[network_id] = color return color + + def is_running(self) -> bool: + """ + Convenience for checking if this session is in the runtime state. + + :return: True if in the runtime state, False otherwise + """ + return self.state == EventTypes.RUNTIME_STATE