From 473fbcaba93972b62d94c5e0492044bdda340e1f Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 21 Jun 2024 11:26:13 -0700 Subject: [PATCH] [child-table] add `HasMinimalChild()` and move logic from `MleRouter` (#10418) This commit adds the `HasMinimalChild()` method to the `ChildTable` class and moves the logic for checking if a device has an MTD child with a given RLOC16 from the `MleRouter` class to `ChildTable`. This aligns better with the `ChildTable` class's responsibility of managing all children and providing methods to search and find child entries in the table. --- src/core/thread/address_resolver.cpp | 4 ++-- src/core/thread/child_table.cpp | 16 ++++++++++++++++ src/core/thread/child_table.hpp | 13 +++++++++++++ src/core/thread/mesh_forwarder_ftd.cpp | 2 +- src/core/thread/mle_router.cpp | 16 ---------------- src/core/thread/mle_router.hpp | 11 ----------- 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/core/thread/address_resolver.cpp b/src/core/thread/address_resolver.cpp index db0390386..5acb9c7fe 100644 --- a/src/core/thread/address_resolver.cpp +++ b/src/core/thread/address_resolver.cpp @@ -397,12 +397,12 @@ void AddressResolver::UpdateSnoopedCacheEntry(const Ip6::Address &aEid, // is this device or an MTD (minimal) child of the device itself. macAddress = Get().GetShortAddress(); - VerifyOrExit((aRloc16 != macAddress) && !Get().IsMinimalChild(aRloc16)); + VerifyOrExit((aRloc16 != macAddress) && !Get().HasMinimalChild(aRloc16)); // Ensure that the destination of the snooped message is this device // or a minimal child of this device. - VerifyOrExit((aDest == macAddress) || Get().IsMinimalChild(aDest)); + VerifyOrExit((aDest == macAddress) || Get().HasMinimalChild(aDest)); entry = NewCacheEntry(/* aSnoopedEntry */ true); VerifyOrExit(entry != nullptr); diff --git a/src/core/thread/child_table.cpp b/src/core/thread/child_table.cpp index 7fb557dbd..1f9b3b6d3 100644 --- a/src/core/thread/child_table.cpp +++ b/src/core/thread/child_table.cpp @@ -315,6 +315,22 @@ exit: return; } +bool ChildTable::HasMinimalChild(uint16_t aRloc16) const +{ + bool hasMinimalChild = false; + const Child *child; + + VerifyOrExit(Mle::RouterIdMatch(aRloc16, Get().GetRloc16())); + + child = FindChild(Child::AddressMatcher(aRloc16, Child::kInStateValidOrRestoring)); + VerifyOrExit(child != nullptr); + + hasMinimalChild = !child->IsFullThreadDevice(); + +exit: + return hasMinimalChild; +} + bool ChildTable::HasSleepyChildWithAddress(const Ip6::Address &aIp6Address) const { bool hasChild = false; diff --git a/src/core/thread/child_table.hpp b/src/core/thread/child_table.hpp index 61d930742..510db7ef5 100644 --- a/src/core/thread/child_table.hpp +++ b/src/core/thread/child_table.hpp @@ -292,6 +292,19 @@ public: */ Error StoreChild(const Child &aChild); + /** + * Indicates whether or not the child table contains an MTD child with a given @p aRloc16. + * + * Only children in `kInStateValidOrRestoring` are considered. + * + * @param[in] aRloc16 The RLOC16 to check. + * + * @retval TRUE If the child table contains an MTD child with @p aRloc16. + * @retval FALSE If the child table does not contain an MTD child with @p aRloc16. + * + */ + bool HasMinimalChild(uint16_t aRloc16) const; + /** * Indicates whether the child table contains any sleepy child (in states valid or restoring) with a * given IPv6 address. diff --git a/src/core/thread/mesh_forwarder_ftd.cpp b/src/core/thread/mesh_forwarder_ftd.cpp index 78020bc9d..4b29627d5 100644 --- a/src/core/thread/mesh_forwarder_ftd.cpp +++ b/src/core/thread/mesh_forwarder_ftd.cpp @@ -677,7 +677,7 @@ void MeshForwarder::HandleMesh(FrameData &aFrameData, const Mac::Address &aMacSo UpdateRoutes(aFrameData, meshAddrs); if (meshAddrs.mDestination.GetShort() == Get().GetShortAddress() || - Get().IsMinimalChild(meshAddrs.mDestination.GetShort())) + Get().HasMinimalChild(meshAddrs.mDestination.GetShort())) { if (Lowpan::FragmentHeader::IsFragmentHeader(aFrameData)) { diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 8374accaa..9642aaef1 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -3107,22 +3107,6 @@ exit: LogSendError(kTypeDataResponse, error); } -bool MleRouter::IsMinimalChild(uint16_t aRloc16) -{ - bool isMinimalChild = false; - Neighbor *neighbor; - - VerifyOrExit(RouterIdMatch(aRloc16, GetRloc16())); - - neighbor = mNeighborTable.FindNeighbor(aRloc16); - VerifyOrExit(neighbor != nullptr); - - isMinimalChild = !neighbor->IsFullThreadDevice(); - -exit: - return isMinimalChild; -} - void MleRouter::RemoveRouterLink(Router &aRouter) { switch (mRole) diff --git a/src/core/thread/mle_router.hpp b/src/core/thread/mle_router.hpp index 2b4d0fb79..8dbcb0807 100644 --- a/src/core/thread/mle_router.hpp +++ b/src/core/thread/mle_router.hpp @@ -361,17 +361,6 @@ public: */ void RemoveRouterLink(Router &aRouter); - /** - * Indicates whether or not the RLOC16 is an MTD child of this device. - * - * @param[in] aRloc16 The RLOC16. - * - * @retval TRUE if @p aRloc16 is an MTD child of this device. - * @retval FALSE if @p aRloc16 is not an MTD child of this device. - * - */ - bool IsMinimalChild(uint16_t aRloc16); - /** * Indicates whether or not the given Thread partition attributes are preferred. *