From a5593e79801bddfbe0b9a0e4a335cdde63bd2107 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 25 Mar 2026 08:36:11 -0700 Subject: [PATCH] [nexus] remove active node tracking (#12754) This commit removes the active node tracking logic from the Nexus simulation framework. Previously, `Core` maintained a pointer to the `mActiveNode` and updated it dynamically during processing and network events. This was necessary so that log messages could be attributed to the correct node/instance. With the recent introduction of "instance-aware logging" in the OpenThread core, the logging mechanism natively knows which `otInstance` generated a log. Therefore, manually tracking and context-switching the active node in the Nexus framework is no longer required. This change simplifies `nexus::Core`, removes context-switching overhead from heavily utilized inline methods like `Node::Get()`, and allows us to simplify the signature of `InfraIf::Receive()`. --- tests/nexus/platform/nexus_core.cpp | 7 +------ tests/nexus/platform/nexus_core.hpp | 4 ---- tests/nexus/platform/nexus_infra_if.cpp | 8 +++----- tests/nexus/platform/nexus_infra_if.hpp | 2 +- tests/nexus/platform/nexus_node.cpp | 2 -- tests/nexus/platform/nexus_node.hpp | 12 ++---------- 6 files changed, 7 insertions(+), 28 deletions(-) diff --git a/tests/nexus/platform/nexus_core.cpp b/tests/nexus/platform/nexus_core.cpp index 0d3845685..c0401ed4f 100644 --- a/tests/nexus/platform/nexus_core.cpp +++ b/tests/nexus/platform/nexus_core.cpp @@ -44,7 +44,6 @@ Core::Core(void) : mCurNodeId(0) , mPendingAction(false) , mNow(0) - , mActiveNode(nullptr) { const char *pcapFile; @@ -379,8 +378,6 @@ void Core::AdvanceTime(uint32_t aDuration) void Core::Process(Node &aNode) { - SetActiveNode(&aNode); - otTaskletsProcess(&aNode.GetInstance()); ProcessRadio(aNode); @@ -400,8 +397,6 @@ void Core::Process(Node &aNode) aNode.mAlarmMicro.mScheduled = false; otPlatAlarmMicroFired(&aNode.GetInstance()); } - - SetActiveNode(nullptr); } void Core::ProcessRadio(Node &aNode) @@ -620,7 +615,7 @@ void Core::ProcessInfraIf(Node &aNode) continue; } - rxNode.mInfraIf.Receive(aNode, *message); + rxNode.mInfraIf.Receive(*message); } message->Free(); diff --git a/tests/nexus/platform/nexus_core.hpp b/tests/nexus/platform/nexus_core.hpp index 336dfdbdd..b66ea7034 100644 --- a/tests/nexus/platform/nexus_core.hpp +++ b/tests/nexus/platform/nexus_core.hpp @@ -76,9 +76,6 @@ public: //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Used by platform implementation - void SetActiveNode(Node *aNode) { mActiveNode = aNode; } - Node *GetActiveNode(void) { return mActiveNode; } - void UpdateNextAlarmMilli(const Alarm &aAlarm); void UpdateNextAlarmMicro(const Alarm &aAlarm); void MarkPendingAction(void) { mPendingAction = true; } @@ -134,7 +131,6 @@ private: bool mPendingAction; uint64_t mNow; uint64_t mNextAlarmTime; - Node *mActiveNode; }; void Log(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); diff --git a/tests/nexus/platform/nexus_infra_if.cpp b/tests/nexus/platform/nexus_infra_if.cpp index 518812d53..9b503f7d8 100644 --- a/tests/nexus/platform/nexus_infra_if.cpp +++ b/tests/nexus/platform/nexus_infra_if.cpp @@ -410,20 +410,18 @@ void InfraIf::SendUdp(const Ip6::Address &aSrcAddress, Message *loopbackMessage = aPayload.Clone(); VerifyOrQuit(loopbackMessage != nullptr); - Receive(GetNode(), *loopbackMessage); + Receive(*loopbackMessage); loopbackMessage->Free(); } mPendingTxQueue.Enqueue(aPayload); } -void InfraIf::Receive(Node &aSrcNode, Message &aMessage) +void InfraIf::Receive(Message &aMessage) { Node &node = GetNode(); Ip6::Headers headers; - Core::Get().SetActiveNode(&node); - aMessage.SetOffset(0); SuccessOrExit(headers.ParseFrom(aMessage)); @@ -515,7 +513,7 @@ void InfraIf::Receive(Node &aSrcNode, Message &aMessage) } exit: - Core::Get().SetActiveNode(&aSrcNode); + return; } void InfraIf::HandleEchoRequest(const Ip6::Header &aHeader, Message &aMessage) diff --git a/tests/nexus/platform/nexus_infra_if.hpp b/tests/nexus/platform/nexus_infra_if.hpp index 6e2074440..2ca103d1a 100644 --- a/tests/nexus/platform/nexus_infra_if.hpp +++ b/tests/nexus/platform/nexus_infra_if.hpp @@ -84,7 +84,7 @@ public: uint16_t aDestPort, Message &aPayload); - void Receive(Node &aSrcNode, Message &aMessage); + void Receive(Message &aMessage); void GetLinkLayerAddress(LinkLayerAddress &aLinkLayerAddress) const; typedef void (*EchoReplyHandler)(void *aContext, const Ip6::Address &aSource, uint16_t aId, uint16_t aSequence); diff --git a/tests/nexus/platform/nexus_node.cpp b/tests/nexus/platform/nexus_node.cpp index e35174d72..46511f6f0 100644 --- a/tests/nexus/platform/nexus_node.cpp +++ b/tests/nexus/platform/nexus_node.cpp @@ -166,8 +166,6 @@ void Node::HandleReceive(otMessage *aMessage) VerifyOrExit(header->GetDestination().GetScope() > Ip6::Address::kRealmLocalScope); - Core::Get().SetActiveNode(this); - if (header->GetDestination().IsMulticast()) { VerifyOrExit(Get().IsPrimary()); diff --git a/tests/nexus/platform/nexus_node.hpp b/tests/nexus/platform/nexus_node.hpp index 4055e46dc..e0ea29218 100644 --- a/tests/nexus/platform/nexus_node.hpp +++ b/tests/nexus/platform/nexus_node.hpp @@ -121,17 +121,9 @@ public: //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template Type &Get(void) - { - Core::Get().SetActiveNode(this); - return Instance::Get(); - } + template Type &Get(void) { return Instance::Get(); } - Instance &GetInstance(void) - { - Core::Get().SetActiveNode(this); - return *this; - } + Instance &GetInstance(void) { return *this; } uint32_t GetId(void) { return GetInstance().GetId(); }