From f07bcc2bfe561797f2b9ca859399dcaaa7d02a0b Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 17 Sep 2024 18:20:37 -0700 Subject: [PATCH] [mle] rename `Mle::Handle{Command}()` methods to indicate constraints (#10721) This commit renames `Mle::Handle{Command}()` methods where different overloads are provided (e.g. in `Mle` and `MleRouter`) based on device role or being an FTD. The method names now explicitly mention the constraints (e.g. `HandleChildUpdateRequestOnChild()` or `HandleAdvertisementOnFtd()`). This change aims to improve code readability, making it easier to determine the purpose of each method. --- src/core/thread/mle.cpp | 54 +++++++++++++++++++--------------- src/core/thread/mle.hpp | 2 ++ src/core/thread/mle_router.cpp | 6 ++-- src/core/thread/mle_router.hpp | 6 ++-- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 05425ec1f60..cb5799b6d38 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -2567,31 +2567,11 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn break; case kCommandChildUpdateRequest: -#if OPENTHREAD_FTD - if (IsRouterOrLeader()) - { - Get().HandleChildUpdateRequest(rxInfo); - } - else -#endif - { - HandleChildUpdateRequest(rxInfo); - } - + HandleChildUpdateRequest(rxInfo); break; case kCommandChildUpdateResponse: -#if OPENTHREAD_FTD - if (IsRouterOrLeader()) - { - Get().HandleChildUpdateResponse(rxInfo); - } - else -#endif - { - HandleChildUpdateResponse(rxInfo); - } - + HandleChildUpdateResponse(rxInfo); break; #if OPENTHREAD_FTD @@ -2786,7 +2766,7 @@ void Mle::HandleAdvertisement(RxInfo &aRxInfo) #if OPENTHREAD_FTD if (IsFullThreadDevice()) { - SuccessOrExit(error = Get().HandleAdvertisement(aRxInfo, sourceAddress, leaderData)); + SuccessOrExit(error = Get().HandleAdvertisementOnFtd(aRxInfo, sourceAddress, leaderData)); } #endif @@ -3389,6 +3369,20 @@ void Mle::HandleChildIdResponse(RxInfo &aRxInfo) } void Mle::HandleChildUpdateRequest(RxInfo &aRxInfo) +{ +#if OPENTHREAD_FTD + if (IsRouterOrLeader()) + { + Get().HandleChildUpdateRequestOnParent(aRxInfo); + } + else +#endif + { + HandleChildUpdateRequestOnChild(aRxInfo); + } +} + +void Mle::HandleChildUpdateRequestOnChild(RxInfo &aRxInfo) { Error error = kErrorNone; uint16_t sourceAddress; @@ -3498,6 +3492,20 @@ void Mle::HandleChildUpdateRequest(RxInfo &aRxInfo) } void Mle::HandleChildUpdateResponse(RxInfo &aRxInfo) +{ +#if OPENTHREAD_FTD + if (IsRouterOrLeader()) + { + Get().HandleChildUpdateResponseOnParent(aRxInfo); + } + else +#endif + { + HandleChildUpdateResponseOnChild(aRxInfo); + } +} + +void Mle::HandleChildUpdateResponseOnChild(RxInfo &aRxInfo) { Error error = kErrorNone; uint8_t status; diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 8c3a6b870e2..ad1bd69d2bd 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -1315,7 +1315,9 @@ class Mle : public InstanceLocator, private NonCopyable void HandleAdvertisement(RxInfo &aRxInfo); void HandleChildIdResponse(RxInfo &aRxInfo); void HandleChildUpdateRequest(RxInfo &aRxInfo); + void HandleChildUpdateRequestOnChild(RxInfo &aRxInfo); void HandleChildUpdateResponse(RxInfo &aRxInfo); + void HandleChildUpdateResponseOnChild(RxInfo &aRxInfo); void HandleDataResponse(RxInfo &aRxInfo); void HandleParentResponse(RxInfo &aRxInfo); void HandleAnnounce(RxInfo &aRxInfo); diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index d4c065decca..32ed6b96f7e 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -1174,7 +1174,7 @@ int MleRouter::ComparePartitions(bool aSingletonA, return rval; } -Error MleRouter::HandleAdvertisement(RxInfo &aRxInfo, uint16_t aSourceAddress, const LeaderData &aLeaderData) +Error MleRouter::HandleAdvertisementOnFtd(RxInfo &aRxInfo, uint16_t aSourceAddress, const LeaderData &aLeaderData) { // This method processes a received MLE Advertisement message on // an FTD device. It is called from `Mle::HandleAdvertisement()` @@ -2149,7 +2149,7 @@ void MleRouter::HandleChildIdRequest(RxInfo &aRxInfo) LogProcessError(kTypeChildIdRequest, error); } -void MleRouter::HandleChildUpdateRequest(RxInfo &aRxInfo) +void MleRouter::HandleChildUpdateRequestOnParent(RxInfo &aRxInfo) { Error error = kErrorNone; Mac::ExtAddress extAddr; @@ -2367,7 +2367,7 @@ void MleRouter::HandleChildUpdateRequest(RxInfo &aRxInfo) LogProcessError(kTypeChildUpdateRequestOfChild, error); } -void MleRouter::HandleChildUpdateResponse(RxInfo &aRxInfo) +void MleRouter::HandleChildUpdateResponseOnParent(RxInfo &aRxInfo) { Error error = kErrorNone; uint16_t sourceAddress; diff --git a/src/core/thread/mle_router.hpp b/src/core/thread/mle_router.hpp index 84d3647d1e8..04e42dfb212 100644 --- a/src/core/thread/mle_router.hpp +++ b/src/core/thread/mle_router.hpp @@ -607,11 +607,11 @@ class MleRouter : public Mle void HandleLinkAccept(RxInfo &aRxInfo); Error HandleLinkAccept(RxInfo &aRxInfo, bool aRequest); void HandleLinkAcceptAndRequest(RxInfo &aRxInfo); - Error HandleAdvertisement(RxInfo &aRxInfo, uint16_t aSourceAddress, const LeaderData &aLeaderData); + Error HandleAdvertisementOnFtd(RxInfo &aRxInfo, uint16_t aSourceAddress, const LeaderData &aLeaderData); void HandleParentRequest(RxInfo &aRxInfo); void HandleChildIdRequest(RxInfo &aRxInfo); - void HandleChildUpdateRequest(RxInfo &aRxInfo); - void HandleChildUpdateResponse(RxInfo &aRxInfo); + void HandleChildUpdateRequestOnParent(RxInfo &aRxInfo); + void HandleChildUpdateResponseOnParent(RxInfo &aRxInfo); void HandleDataRequest(RxInfo &aRxInfo); void HandleNetworkDataUpdateRouter(void); void HandleDiscoveryRequest(RxInfo &aRxInfo);