[mle] introduce Connectivity and ConnectivityTlvValue types (#12300)

This change separates the Connectivity TLV value format from its
logical structure by introducing `ConnectivityTlvValue` (raw format)
and `Connectivity` (parsed info). This replaces the `ConnectivityTlv`
class and enables value format sharing between MLE and Network
Diagnostics (without improper TLV inheritance).

It also updates `ParentCandidate` to use the new `Connectivity` class
for better field encapsulation. It also updates `ConnectivityTlvValue`
parsing to handle optional fields and enforce spec-defined minimums
for these fields.
This commit is contained in:
Abtin Keshavarzian
2026-01-15 07:43:01 -08:00
committed by GitHub
parent e3b565cc40
commit 0e72f56941
9 changed files with 300 additions and 320 deletions
+22 -22
View File
@@ -3660,38 +3660,30 @@ exit:
return;
}
void Mle::FillConnectivityTlv(ConnectivityTlv &aTlv)
void Mle::DetermineConnectivity(Connectivity &aConnectivity) const
{
int8_t parentPriority = kParentPriorityMedium;
aConnectivity.Clear();
if (mParentPriority != kParentPriorityUnspecified)
{
parentPriority = mParentPriority;
}
else
aConnectivity.mParentPriority = GetAssignParentPriority();
if (aConnectivity.mParentPriority == kParentPriorityUnspecified)
{
uint16_t numChildren = mChildTable.GetNumChildren(Child::kInStateValid);
uint16_t maxAllowed = mChildTable.GetMaxChildrenAllowed();
if ((maxAllowed - numChildren) < (maxAllowed / 3))
{
parentPriority = kParentPriorityLow;
aConnectivity.mParentPriority = kParentPriorityLow;
}
else
{
parentPriority = kParentPriorityMedium;
aConnectivity.mParentPriority = kParentPriorityMedium;
}
}
aTlv.SetParentPriority(parentPriority);
aTlv.SetLinkQuality1(0);
aTlv.SetLinkQuality2(0);
aTlv.SetLinkQuality3(0);
if (IsChild())
{
aTlv.IncrementLinkQuality(mParent.GetLinkQualityIn());
aConnectivity.IncrementNumForLinkQuality(mParent.GetLinkQualityIn());
}
for (const Router &router : Get<RouterTable>())
@@ -3706,14 +3698,22 @@ void Mle::FillConnectivityTlv(ConnectivityTlv &aTlv)
continue;
}
aTlv.IncrementLinkQuality(router.GetTwoWayLinkQuality());
aConnectivity.IncrementNumForLinkQuality(router.GetTwoWayLinkQuality());
}
aTlv.SetActiveRouters(mRouterTable.GetActiveRouterCount());
aTlv.SetLeaderCost(Min(mRouterTable.GetPathCostToLeader(), kMaxRouteCost));
aTlv.SetIdSequence(mRouterTable.GetRouterIdSequence());
aTlv.SetSedBufferSize(OPENTHREAD_CONFIG_DEFAULT_SED_BUFFER_SIZE);
aTlv.SetSedDatagramCount(OPENTHREAD_CONFIG_DEFAULT_SED_DATAGRAM_COUNT);
aConnectivity.mLeaderCost = Min(mRouterTable.GetPathCostToLeader(), kMaxRouteCost);
aConnectivity.mIdSequence = mRouterTable.GetRouterIdSequence();
aConnectivity.mActiveRouters = mRouterTable.GetActiveRouterCount();
aConnectivity.mSedBufferSize = Connectivity::kDefaultSedBufferSize;
aConnectivity.mSedDatagramCount = Connectivity::kDefaultSedDatagramCount;
}
void Mle::FillConnectivityTlvValue(ConnectivityTlvValue &aTlvValue) const
{
Connectivity connectivity;
DetermineConnectivity(connectivity);
aTlvValue.InitFrom(connectivity);
}
bool Mle::ShouldDowngrade(uint8_t aNeighborId, const RouteTlv &aRouteTlv) const