[mle] refactor previous router/leader role restoration (#11728)

This commit updates `RestorePrevRole()` to directly start the
`RouterRoleRestorer` instead of calling `BecomeRouter()`.

Consequently, `BecomeRouter()` is simplified by removing the logic for
handling the `kRoleDetached` state. The method now focuses on the
child-to-router transition by sending an Address Solicit message, and
its initial role validation is made more explicit.

This change ensures the logic for restoring a previous router/leader
role is separate from the child-to-router transition logic.
This commit is contained in:
Abtin Keshavarzian
2025-07-16 10:31:16 -07:00
committed by GitHub
parent 5108ccdcf5
commit 23e54f680d
2 changed files with 21 additions and 16 deletions
+5 -1
View File
@@ -290,13 +290,17 @@ Error Mle::RestorePrevRole(void)
Error error = kErrorFailed;
VerifyOrExit(IsDetached());
VerifyOrExit(GetRloc16() != kInvalidRloc16);
if (IsRouterRloc16(GetRloc16()))
{
#if OPENTHREAD_FTD
VerifyOrExit(mLastSavedRole == kRoleRouter || mLastSavedRole == kRoleLeader);
error = BecomeRouter(ThreadStatusTlv::kTooFewRouters);
VerifyOrExit(IsRouterEligible());
Get<MeshForwarder>().SetRxOnWhenIdle(true);
mRouterRoleRestorer.Start(mLastSavedRole);
error = kErrorNone;
#endif
ExitNow();
}
+16 -15
View File
@@ -189,8 +189,21 @@ Error Mle::BecomeRouter(ThreadStatusTlv::Status aStatus)
{
Error error = kErrorNone;
VerifyOrExit(!IsDisabled(), error = kErrorInvalidState);
VerifyOrExit(!IsRouterOrLeader(), error = kErrorNone);
switch (mRole)
{
case kRoleChild:
break;
case kRoleDisabled:
case kRoleDetached:
error = kErrorInvalidState;
OT_FALL_THROUGH;
case kRoleRouter:
case kRoleLeader:
ExitNow();
}
VerifyOrExit(IsRouterEligible(), error = kErrorNotCapable);
LogInfo("Attempt to become router");
@@ -198,19 +211,7 @@ Error Mle::BecomeRouter(ThreadStatusTlv::Status aStatus)
Get<MeshForwarder>().SetRxOnWhenIdle(true);
mRouterRoleTransition.StopTimeout();
switch (mRole)
{
case kRoleDetached:
mRouterRoleRestorer.Start(mLastSavedRole);
break;
case kRoleChild:
SuccessOrExit(error = SendAddressSolicit(aStatus));
break;
default:
OT_ASSERT(false);
}
error = SendAddressSolicit(aStatus);
exit:
return error;