From fd7746b1e15820cc5f95ef60962f7448545d5228 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 28 Aug 2025 14:29:48 -0700 Subject: [PATCH] [core] harmonize access to MLE component using `Get()` (#11874) This change updates multiple modules to consistently use `Get()` for accessing the MLE component, removing the need for local `Mle::Mle &mle` references. This approach aligns with the common `Get()` access pattern used across the codebase, improving consistency. --- src/core/thread/dua_manager.cpp | 29 ++++++++++++-------------- src/core/thread/mesh_forwarder.cpp | 11 +++++----- src/core/thread/mesh_forwarder_ftd.cpp | 8 +++---- src/core/thread/mlr_manager.cpp | 17 +++++++-------- src/core/thread/neighbor_table.cpp | 9 ++++---- 5 files changed, 33 insertions(+), 41 deletions(-) diff --git a/src/core/thread/dua_manager.cpp b/src/core/thread/dua_manager.cpp index 037adcad0..5904e5b53 100644 --- a/src/core/thread/dua_manager.cpp +++ b/src/core/thread/dua_manager.cpp @@ -291,8 +291,6 @@ void DuaManager::UpdateCheckDelay(uint8_t aDelay) void DuaManager::HandleNotifierEvents(Events aEvents) { - Mle::Mle &mle = Get(); - #if OPENTHREAD_CONFIG_DUA_ENABLE if (aEvents.Contains(kEventThreadNetdataChanged) && Get().HasUnicastAddress(GetDomainUnicastAddress())) { @@ -307,24 +305,24 @@ void DuaManager::HandleNotifierEvents(Events aEvents) } #endif - VerifyOrExit(mle.IsAttached(), mDelay.mValue = 0); + VerifyOrExit(Get().IsAttached(), mDelay.mValue = 0); if (aEvents.Contains(kEventThreadRoleChanged)) { - if (mle.HasRestored()) + if (Get().HasRestored()) { UpdateReregistrationDelay(); } #if OPENTHREAD_CONFIG_DUA_ENABLE && OPENTHREAD_FTD - else if (mle.IsRouter()) + else if (Get().IsRouter()) { // Wait for link establishment with neighboring routers. UpdateRegistrationDelay(kNewRouterRegistrationDelay); } - else if (mle.WillBecomeRouterSoon()) + else if (Get().WillBecomeRouterSoon()) { // Will check again in case the device decides to stay REED when jitter timeout expires. - UpdateRegistrationDelay(mle.GetRouterRoleTransitionTimeout() + kNewRouterRegistrationDelay + 1); + UpdateRegistrationDelay(Get().GetRouterRoleTransitionTimeout() + kNewRouterRegistrationDelay + 1); } #endif } @@ -421,12 +419,11 @@ void DuaManager::UpdateTimeTickerRegistration(void) void DuaManager::PerformNextRegistration(void) { Error error = kErrorNone; - Mle::Mle &mle = Get(); Coap::Message *message = nullptr; Tmf::MessageInfo messageInfo(GetInstance()); Ip6::Address dua; - VerifyOrExit(mle.IsAttached()); + VerifyOrExit(Get().IsAttached()); VerifyOrExit(Get().HasPrimary()); // Only allow one outgoing DUA.req @@ -435,13 +432,13 @@ void DuaManager::PerformNextRegistration(void) // Only send DUA.req when necessary #if OPENTHREAD_CONFIG_DUA_ENABLE #if OPENTHREAD_FTD - if (!mle.IsRouterOrLeader() && mle.WillBecomeRouterSoon()) + if (!Get().IsRouterOrLeader() && Get().WillBecomeRouterSoon()) { - UpdateRegistrationDelay(mle.GetRouterRoleTransitionTimeout() + kNewRouterRegistrationDelay + 1); + UpdateRegistrationDelay(Get().GetRouterRoleTransitionTimeout() + kNewRouterRegistrationDelay + 1); ExitNow(); } #endif - VerifyOrExit(mle.IsFullThreadDevice() || mle.GetParent().IsThreadVersion1p1()); + VerifyOrExit(Get().IsFullThreadDevice() || Get().GetParent().IsThreadVersion1p1()); #endif // OPENTHREAD_CONFIG_DUA_ENABLE { @@ -466,7 +463,7 @@ void DuaManager::PerformNextRegistration(void) { dua = GetDomainUnicastAddress(); SuccessOrExit(error = Tlv::Append(*message, dua)); - SuccessOrExit(error = Tlv::Append(*message, mle.GetMeshLocalEid().GetIid())); + SuccessOrExit(error = Tlv::Append(*message, Get().GetMeshLocalEid().GetIid())); mDuaState = kRegistering; mLastRegistrationTime = TimerMilli::GetNow(); } @@ -501,16 +498,16 @@ void DuaManager::PerformNextRegistration(void) #endif // OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_DUA_ENABLE } - if (!mle.IsFullThreadDevice() && mle.GetParent().IsThreadVersion1p1()) + if (!Get().IsFullThreadDevice() && Get().GetParent().IsThreadVersion1p1()) { uint8_t pbbrServiceId; SuccessOrExit(error = Get().GetServiceId(pbbrServiceId)); - mle.GetServiceAloc(pbbrServiceId, messageInfo.GetPeerAddr()); + Get().GetServiceAloc(pbbrServiceId, messageInfo.GetPeerAddr()); } else { - messageInfo.GetPeerAddr().SetToRoutingLocator(mle.GetMeshLocalPrefix(), + messageInfo.GetPeerAddr().SetToRoutingLocator(Get().GetMeshLocalPrefix(), Get().GetServer16()); } diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index ac41081f0..4efa3d8e9 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -564,7 +564,6 @@ exit: Error MeshForwarder::UpdateIp6Route(Message &aMessage) { - Mle::Mle &mle = Get(); Error error = kErrorNone; Ip6::Header ip6Header; @@ -576,7 +575,7 @@ Error MeshForwarder::UpdateIp6Route(Message &aMessage) Get().DetermineMacSourceAddress(ip6Header.GetSource(), mMacAddrs); - if (mle.IsDisabled() || mle.IsDetached()) + if (Get().IsDisabled() || Get().IsDetached()) { if (ip6Header.GetDestination().IsLinkLocalMulticast()) { @@ -600,9 +599,9 @@ Error MeshForwarder::UpdateIp6Route(Message &aMessage) // with link security disabled, an End Device transmits // multicasts, as IEEE 802.15.4 unicasts to its parent. - if (mle.IsChild() && aMessage.IsLinkSecurityEnabled() && !aMessage.IsSubTypeMle()) + if (Get().IsChild() && aMessage.IsLinkSecurityEnabled() && !aMessage.IsSubTypeMle()) { - mMacAddrs.mDestination.SetShort(mle.GetParentRloc16()); + mMacAddrs.mDestination.SetShort(Get().GetParentRloc16()); } else { @@ -613,9 +612,9 @@ Error MeshForwarder::UpdateIp6Route(Message &aMessage) { mMacAddrs.mDestination.SetExtendedFromIid(ip6Header.GetDestination().GetIid()); } - else if (mle.IsMinimalEndDevice()) + else if (Get().IsMinimalEndDevice()) { - mMacAddrs.mDestination.SetShort(mle.GetParentRloc16()); + mMacAddrs.mDestination.SetShort(Get().GetParentRloc16()); } else { diff --git a/src/core/thread/mesh_forwarder_ftd.cpp b/src/core/thread/mesh_forwarder_ftd.cpp index 249523d60..88efcbe02 100644 --- a/src/core/thread/mesh_forwarder_ftd.cpp +++ b/src/core/thread/mesh_forwarder_ftd.cpp @@ -369,7 +369,6 @@ exit: Error MeshForwarder::UpdateIp6RouteFtd(const Ip6::Header &aIp6Header, Message &aMessage) { - Mle::Mle &mle = Get(); Error error = kErrorNone; Neighbor *neighbor; @@ -379,14 +378,14 @@ Error MeshForwarder::UpdateIp6RouteFtd(const Ip6::Header &aIp6Header, Message &a { mMeshDest = aMessage.GetMeshDest(); } - else if (mle.IsRoutingLocator(aIp6Header.GetDestination())) + else if (Get().IsRoutingLocator(aIp6Header.GetDestination())) { uint16_t rloc16 = aIp6Header.GetDestination().GetIid().GetLocator(); VerifyOrExit(Mle::IsRouterIdValid(Mle::RouterIdFromRloc16(rloc16)), error = kErrorDrop); mMeshDest = rloc16; } - else if (mle.IsAnycastLocator(aIp6Header.GetDestination())) + else if (Get().IsAnycastLocator(aIp6Header.GetDestination())) { uint16_t aloc16 = aIp6Header.GetDestination().GetIid().GetLocator(); @@ -396,7 +395,8 @@ Error MeshForwarder::UpdateIp6RouteFtd(const Ip6::Header &aIp6Header, Message &a // child of this device, prepare the message for indirect tx // to the sleepy child and un-mark message for direct tx. - if (mle.IsRouterOrLeader() && Mle::IsChildRloc16(mMeshDest) && mle.HasMatchingRouterIdWith(mMeshDest)) + if (Get().IsRouterOrLeader() && Mle::IsChildRloc16(mMeshDest) && + Get().HasMatchingRouterIdWith(mMeshDest)) { Child *child = Get().FindChild(mMeshDest, Child::kInStateValid); diff --git a/src/core/thread/mlr_manager.cpp b/src/core/thread/mlr_manager.cpp index 34ed3f0fe..c1f8189d6 100644 --- a/src/core/thread/mlr_manager.cpp +++ b/src/core/thread/mlr_manager.cpp @@ -212,12 +212,12 @@ void MlrManager::UpdateTimeTickerRegistration(void) void MlrManager::SendMlr(void) { Error error; - Mle::Mle &mle = Get(); AddressArray addresses; VerifyOrExit(!mMlrPending, error = kErrorBusy); - VerifyOrExit(mle.IsAttached(), error = kErrorInvalidState); - VerifyOrExit(mle.IsFullThreadDevice() || mle.GetParent().IsThreadVersion1p1(), error = kErrorInvalidState); + VerifyOrExit(Get().IsAttached(), error = kErrorInvalidState); + VerifyOrExit(Get().IsFullThreadDevice() || Get().GetParent().IsThreadVersion1p1(), + error = kErrorInvalidState); VerifyOrExit(Get().HasPrimary(), error = kErrorInvalidState); #if OPENTHREAD_CONFIG_MLR_ENABLE @@ -370,7 +370,6 @@ Error MlrManager::SendMlrMessage(const Ip6::Address *aAddresses, OT_UNUSED_VARIABLE(aTimeout); Error error = kErrorNone; - Mle::Mle &mle = Get(); Coap::Message *message = nullptr; Tmf::MessageInfo messageInfo(GetInstance()); Ip6AddressesTlv addressesTlv; @@ -400,16 +399,16 @@ Error MlrManager::SendMlrMessage(const Ip6::Address *aAddresses, OT_ASSERT(aTimeout == nullptr); #endif - if (!mle.IsFullThreadDevice() && mle.GetParent().IsThreadVersion1p1()) + if (!Get().IsFullThreadDevice() && Get().GetParent().IsThreadVersion1p1()) { uint8_t pbbrServiceId; SuccessOrExit(error = Get().GetServiceId(pbbrServiceId)); - mle.GetServiceAloc(pbbrServiceId, messageInfo.GetPeerAddr()); + Get().GetServiceAloc(pbbrServiceId, messageInfo.GetPeerAddr()); } else { - messageInfo.GetPeerAddr().SetToRoutingLocator(mle.GetMeshLocalPrefix(), + messageInfo.GetPeerAddr().SetToRoutingLocator(Get().GetMeshLocalPrefix(), Get().GetServer16()); } @@ -607,9 +606,7 @@ void MlrManager::Reregister(void) void MlrManager::UpdateReregistrationDelay(bool aRereg) { - Mle::Mle &mle = Get(); - - bool needSendMlr = (mle.IsFullThreadDevice() || mle.GetParent().IsThreadVersion1p1()) && + bool needSendMlr = (Get().IsFullThreadDevice() || Get().GetParent().IsThreadVersion1p1()) && Get().HasPrimary(); if (!needSendMlr) diff --git a/src/core/thread/neighbor_table.cpp b/src/core/thread/neighbor_table.cpp index c3c71e7b6..7bef8947e 100644 --- a/src/core/thread/neighbor_table.cpp +++ b/src/core/thread/neighbor_table.cpp @@ -46,15 +46,14 @@ NeighborTable::NeighborTable(Instance &aInstance) Neighbor *NeighborTable::FindParent(const Neighbor::AddressMatcher &aMatcher) { Neighbor *neighbor = nullptr; - Mle::Mle &mle = Get(); - if (mle.GetParent().Matches(aMatcher)) + if (Get().GetParent().Matches(aMatcher)) { - neighbor = &mle.GetParent(); + neighbor = &Get().GetParent(); } - else if (mle.GetParentCandidate().Matches(aMatcher)) + else if (Get().GetParentCandidate().Matches(aMatcher)) { - neighbor = &mle.GetParentCandidate(); + neighbor = &Get().GetParentCandidate(); } return neighbor;