[mle] simplify HandleParentRequest (#11705)

This commit simplifies the `HandleParentRequest()`.

- The logic for detecting duplicate Parent Requests is made more
  readable by introducing the `kParentRequestDuplicateTimeout`
  constant.
- To reduce unnecessary log noise, checks like `IsRouterEligible()`
  or `!IsDetached()` no longer set and return an error. This
  prevents logging failure messages for conditions that are not
  actual errors.
- Verbose comments are removed in favor of self-documenting code.
This commit is contained in:
Abtin Keshavarzian
2025-07-14 10:20:48 -07:00
committed by GitHub
parent 8c9dd22d2c
commit 5944b5e983
2 changed files with 7 additions and 22 deletions
+1 -1
View File
@@ -1182,7 +1182,7 @@ private:
// All time intervals are in milliseconds
static constexpr uint32_t kParentRequestRouterTimeout = 750; // Wait time after tx of Parent Req to routers
static constexpr uint32_t kParentRequestReedTimeout = 1250; // Wait timer after tx of Parent Req to REEDs
static constexpr uint32_t kParentRequestDuplicateMargin = 50; // Margin to detect duplicate received Parent Req
static constexpr uint32_t kParentRequestDuplicateTimeout = 700; // Min time to detect duplicate Parent Req rx
static constexpr uint32_t kChildIdResponseTimeout = 1250; // Wait time to receive Child ID Response
static constexpr uint32_t kAttachStartJitter = 50; // Max jitter time added to start of attach
static constexpr uint32_t kAnnounceProcessTimeout = 250; // Delay after Announce rx before processing
+6 -21
View File
@@ -1401,29 +1401,12 @@ void Mle::HandleParentRequest(RxInfo &aRxInfo)
Log(kMessageReceive, kTypeParentRequest, aRxInfo.mMessageInfo.GetPeerAddr());
VerifyOrExit(IsRouterEligible(), error = kErrorInvalidState);
VerifyOrExit(IsRouterEligible());
VerifyOrExit(!IsDetached() && !IsAttaching());
// A Router/REED MUST NOT send an MLE Parent Response if:
// 0. It is detached or attempting to another partition
VerifyOrExit(!IsDetached() && !IsAttaching(), error = kErrorDrop);
// 1. It has no available Child capacity (if Max Child Count minus
// Child Count would be equal to zero)
// ==> verified below when allocating a child entry
// 2. It is disconnected from its Partition (that is, it has not
// received an updated ID sequence number within LEADER_TIMEOUT
// seconds)
VerifyOrExit(mRouterTable.GetLeaderAge() < mNetworkIdTimeout, error = kErrorDrop);
// 3. Its current routing path cost to the Leader is infinite.
VerifyOrExit(mRouterTable.GetPathCostToLeader() < kMaxRouteCost, error = kErrorDrop);
// 4. It is a REED and there are already `kMaxRouters` active routers in
// the network (because Leader would reject any further address solicit).
// ==> Verified below when checking the scan mask.
info.mChildExtAddress.SetFromIid(aRxInfo.mMessageInfo.GetPeerAddr().GetIid());
SuccessOrExit(error = aRxInfo.mMessage.ReadVersionTlv(version));
@@ -1466,9 +1449,11 @@ void Mle::HandleParentRequest(RxInfo &aRxInfo)
child->SetVersion(version);
}
}
else if (TimerMilli::GetNow() - child->GetLastHeard() < kParentRequestRouterTimeout - kParentRequestDuplicateMargin)
else
{
ExitNow(error = kErrorDuplicated);
uint32_t durSinceLastHeard = TimerMilli::GetNow() - child->GetLastHeard();
VerifyOrExit(durSinceLastHeard >= kParentRequestDuplicateTimeout, error = kErrorDuplicated);
}
if (!child->IsStateValidOrRestoring())