From b4ec4ce365fab94069f120afdc499df041b08216 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 3 Jun 2024 18:25:54 -0700 Subject: [PATCH] [mle] add `ConnectivityTlv::IsSingleton()` (#10329) This is used to simplify `Mle::HandleParentResponse()`. --- src/core/thread/mle.cpp | 6 +++--- src/core/thread/mle_tlvs.hpp | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 9be918d8a..0a0c7fa03 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -3224,7 +3224,7 @@ void Mle::HandleParentResponse(RxInfo &aRxInfo) case kBetterPartition: VerifyOrExit(!isPartitionIdSame); - VerifyOrExit(MleRouter::ComparePartitions(connectivityTlv.GetActiveRouters() <= 1, leaderData, + VerifyOrExit(MleRouter::ComparePartitions(connectivityTlv.IsSingleton(), leaderData, Get().IsSingleton(), mLeaderData) > 0); break; } @@ -3243,7 +3243,7 @@ void Mle::HandleParentResponse(RxInfo &aRxInfo) #if OPENTHREAD_FTD if (IsFullThreadDevice()) { - compare = MleRouter::ComparePartitions(connectivityTlv.GetActiveRouters() <= 1, leaderData, + compare = MleRouter::ComparePartitions(connectivityTlv.IsSingleton(), leaderData, mParentCandidate.mIsSingleton, mParentCandidate.mLeaderData); } @@ -3305,7 +3305,7 @@ void Mle::HandleParentResponse(RxInfo &aRxInfo) mParentCandidate.mSedBufferSize = connectivityTlv.GetSedBufferSize(); mParentCandidate.mSedDatagramCount = connectivityTlv.GetSedDatagramCount(); mParentCandidate.mLeaderData = leaderData; - mParentCandidate.mIsSingleton = connectivityTlv.GetActiveRouters() <= 1; + mParentCandidate.mIsSingleton = connectivityTlv.IsSingleton(); mParentCandidate.mLinkMargin = linkMargin; exit: diff --git a/src/core/thread/mle_tlvs.hpp b/src/core/thread/mle_tlvs.hpp index 68f62a49f..023bac0ee 100644 --- a/src/core/thread/mle_tlvs.hpp +++ b/src/core/thread/mle_tlvs.hpp @@ -851,6 +851,15 @@ public: */ uint8_t GetActiveRouters(void) const { return mActiveRouters; } + /** + * Indicates whether or not the partition is a singleton based on Active Routers value. + * + * @retval TRUE The partition is a singleton. + * @retval FALSE The partition is not a singleton. + * + */ + bool IsSingleton(void) const { return (mActiveRouters <= 1); } + /** * Sets the Active Routers value. *