[mle] introduce Attacher class (#11835)

This commit introduces a new `Mle::Attacher` class to encapsulate all
logic and state related to the device attach process.

This change moves the attach state machine, parent candidate
management, attach timer, and message handling for Parent Request,
Parent Response, Child ID Request, and Child ID Response from `Mle`
into the new nested `Attacher` class.

This refactoring improves code organization and modularity by
separating the attach logic from the main `Mle` class.
This commit is contained in:
Abtin Keshavarzian
2025-08-21 07:36:32 -07:00
committed by GitHub
parent 968dbb2a04
commit 64e285beef
3 changed files with 346 additions and 282 deletions
+7 -9
View File
@@ -305,7 +305,7 @@ void Mle::HandleDetachStart(void)
Get<TimeTicker>().UnregisterReceiver(TimeTicker::kMle);
}
void Mle::HandleChildStart(AttachMode aMode)
void Mle::HandleChildStart(void)
{
mAddressSolicitRejected = false;
@@ -323,7 +323,7 @@ void Mle::HandleChildStart(AttachMode aMode)
VerifyOrExit(IsRouterIdValid(mPreviousRouterId));
switch (aMode)
switch (mAttacher.GetAttachMode())
{
case kDowngradeToReed:
SendAddressRelease();
@@ -411,10 +411,8 @@ void Mle::SetStateRouterOrLeader(DeviceRole aRole, uint16_t aRloc16, LeaderStart
SetRole(aRole);
mPrevRoleRestorer.Stop();
mAttacher.CancelAttachOnRoleChange();
SetAttachState(kAttachStateIdle);
mAttachCounter = 0;
mAttachTimer.Stop();
mRetxTracker.Stop();
StopAdvertiseTrickleTimer();
ResetAdvertiseInterval();
@@ -1213,7 +1211,7 @@ Error Mle::HandleAdvertisementOnFtd(RxInfo &aRxInfo, uint16_t aSourceAddress, co
#endif
)
{
Attach(kBetterPartition);
mAttacher.Attach(kBetterPartition);
}
ExitNow(error = kErrorDrop);
@@ -1590,13 +1588,13 @@ void Mle::HandleTimeTick(void)
if ((mRouterTable.GetActiveRouterCount() > 0) && (mRouterTable.GetLeaderAge() >= mNetworkIdTimeout))
{
LogInfo("Leader age timeout");
Attach(kSamePartition);
mAttacher.Attach(kSamePartition);
}
if (roleTransitionTimeoutExpired && mRouterTable.GetActiveRouterCount() > mRouterDowngradeThreshold)
{
LogNote("Downgrade to REED");
Attach(kDowngradeToReed);
mAttacher.Attach(kDowngradeToReed);
}
OT_FALL_THROUGH;
@@ -3220,7 +3218,7 @@ void Mle::RemoveNeighbor(Neighbor &aNeighbor)
}
else if (&aNeighbor == &GetParentCandidate())
{
ClearParentCandidate();
mAttacher.ClearParentCandidate();
}
else if (IsChildRloc16(aNeighbor.GetRloc16()))
{