[mle] simplify IsSingleton() methods (#8548)

This commit is contained in:
Abtin Keshavarzian
2022-12-19 12:11:25 -08:00
committed by GitHub
parent 81487725b0
commit b366867de2
3 changed files with 25 additions and 39 deletions
+6 -36
View File
@@ -1143,21 +1143,15 @@ exit:
return error;
}
bool MleRouter::IsSingleton(void)
bool MleRouter::IsSingleton(void) const
{
bool rval = true;
bool isSingleton = true;
if (IsAttached() && IsRouterEligible())
{
// not a singleton if any other routers exist
if (mRouterTable.GetActiveRouterCount() > 1)
{
ExitNow(rval = false);
}
}
VerifyOrExit(IsAttached() && IsRouterEligible());
isSingleton = (mRouterTable.GetActiveRouterCount() <= 1);
exit:
return rval;
return isSingleton;
}
int MleRouter::ComparePartitions(bool aSingletonA,
@@ -1180,30 +1174,6 @@ exit:
return rval;
}
bool MleRouter::IsSingleton(const RouteTlv &aRouteTlv)
{
bool rval = true;
uint8_t count = 0;
// REEDs do not include a Route TLV and indicate not a singleton
if (!aRouteTlv.IsValid())
{
ExitNow(rval = false);
}
// Check if 2 or more active routers
for (uint8_t routerId = 0; routerId <= kMaxRouterId; routerId++)
{
if (aRouteTlv.IsRouterIdSet(routerId) && (++count >= 2))
{
ExitNow(rval = false);
}
}
exit:
return rval;
}
Error MleRouter::HandleAdvertisement(RxInfo &aRxInfo)
{
Error error = kErrorNone;
@@ -1258,7 +1228,7 @@ Error MleRouter::HandleAdvertisement(RxInfo &aRxInfo)
ExitNow();
}
if (ComparePartitions(IsSingleton(routeTlv), leaderData, IsSingleton(), mLeaderData) > 0
if (ComparePartitions(routeTlv.IsSingleton(), leaderData, IsSingleton(), mLeaderData) > 0
#if OPENTHREAD_CONFIG_TIME_SYNC_REQUIRED
// if time sync is required, it will only migrate to a better network which also enables time sync.
&& aRxInfo.mMessage.GetTimeSyncSeq() != OT_TIME_SYNC_INVALID_SEQ
+1 -3
View File
@@ -118,7 +118,7 @@ public:
* @retval FALSE It is a child or is not a single router in the network.
*
*/
bool IsSingleton(void);
bool IsSingleton(void) const;
/**
* This method generates an Address Solicit request for a Router ID.
@@ -634,8 +634,6 @@ private:
template <Uri kUri> void HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
static bool IsSingleton(const RouteTlv &aRouteTlv);
void HandlePartitionChange(void);
void SetChildStateToValid(Child &aChild);
+18
View File
@@ -308,6 +308,15 @@ public:
*/
bool IsRouterIdSet(uint8_t aRouterId) const { return mRouterIdMask.Contains(aRouterId); }
/**
* This method indicates whether the `RouteTlv` is a singleton, i.e., only one router is allocated.
*
* @retval TRUE It is a singleton.
* @retval FALSE It is not a singleton.
*
*/
bool IsSingleton(void) const { return IsValid() && (mRouterIdMask.GetNumberOfAllocatedIds() <= 1); }
/**
* This method returns the Route Data Length value.
*
@@ -459,6 +468,15 @@ public:
*/
bool IsRouterIdSet(uint8_t aRouterId) const { return mRouterIdMask.Contains(aRouterId); }
/**
* This method indicates whether the `RouteTlv` is a singleton, i.e., only one router is allocated.
*
* @retval TRUE It is a singleton.
* @retval FALSE It is not a singleton.
*
*/
bool IsSingleton(void) const { return IsValid() && (mRouterIdMask.GetNumberOfAllocatedIds() <= 1); }
/**
* This method sets the Router ID bit.
*