[mle] improve logging for address solicit and router upgrade (#11871)

This change introduces `RouterUpgradeReasonToString()` to provide
human-readable strings for router upgrade reasons, which is used to
enhance logging in `BecomeRouter()` and `ProcessAddressSolicit()`.

These additions provide clearer insight into why a device is
attempting to become a router, aiding in debugging and network
analysis.
This commit is contained in:
Abtin Keshavarzian
2025-08-28 07:49:53 -07:00
committed by GitHub
parent b4365d3986
commit 370e822b31
2 changed files with 40 additions and 8 deletions
+35 -8
View File
@@ -206,7 +206,7 @@ Error Mle::BecomeRouter(RouterUpgradeReason aReason)
VerifyOrExit(IsRouterEligible(), error = kErrorNotCapable);
LogInfo("Attempt to become router");
LogInfo("Attempt to become router, reason:%s", RouterUpgradeReasonToString(aReason));
Get<MeshForwarder>().SetRxOnWhenIdle(true);
mRouterRoleTransition.StopTimeout();
@@ -3529,6 +3529,13 @@ void Mle::ProcessAddressSolicit(AddrSolicitInfo &aInfo)
aInfo.mResponse = kAddrSolicitNoAddressAvailable;
aInfo.mRouter = nullptr;
LogInfo("AddrSolicit Reason: %s", RouterUpgradeReasonToString(aInfo.mReason));
if (aInfo.mRequestedRloc16 != kInvalidRloc16)
{
LogInfo("AddrSolicit Requested ID: %u", RouterIdFromRloc16(aInfo.mRequestedRloc16));
}
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
VerifyOrExit(aInfo.mXtalAccuracy <= Get<TimeSync>().GetXtalThreshold());
#endif
@@ -3556,8 +3563,6 @@ void Mle::ProcessAddressSolicit(AddrSolicitInfo &aInfo)
(Get<NetworkData::Leader>().CountBorderRouters(NetworkData::kRouterRoleOnly) >=
kRouterUpgradeBorderRouterRequestThreshold))
{
LogInfo("Rejecting BR %s router role req - have %u BR routers", aInfo.mExtAddress.ToString().AsCString(),
kRouterUpgradeBorderRouterRequestThreshold);
ExitNow();
}
break;
@@ -3570,11 +3575,6 @@ void Mle::ProcessAddressSolicit(AddrSolicitInfo &aInfo)
if (aInfo.mRequestedRloc16 != kInvalidRloc16)
{
aInfo.mRouter = mRouterTable.Allocate(RouterIdFromRloc16(aInfo.mRequestedRloc16));
if (aInfo.mRouter != nullptr)
{
LogInfo("Router id %u requested and provided!", RouterIdFromRloc16(aInfo.mRequestedRloc16));
}
}
if (aInfo.mRouter == nullptr)
@@ -3945,6 +3945,33 @@ exit:
}
#endif // OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
const char *Mle::RouterUpgradeReasonToString(uint8_t aReason)
{
const char *str = "Unknown";
switch (aReason)
{
case kReasonTooFewRouters:
str = "TooFewRouters";
break;
case kReasonHaveChildIdRequest:
str = "HaveChildIdRequest";
break;
case kReasonParentPartitionChange:
str = "ParentPartitionChange";
break;
case kReasonBorderRouterRequest:
str = "BorderRouterRequest";
break;
}
return str;
}
#endif // OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
//----------------------------------------------------------------------------------------------------------------------
// RouterRoleTransition