[routing-manager] ensure local prefix is changed on xpanid change (#8436)

This commit updates `RoutingManager` to check if a change to xpanid
does impact the generated local on-link prefix. This can address two
situations: (1) when BR is started before Thread/MLE operation where
we can get a signal that xpanid is changed on MLE start (without it
actually changing), (2) if the xpanid does change but since not all
the xpanid bytes are used in the derivation of the local prefix, it
can remain as before.

This commit also updates the unit test to start the BR early (along
with MLE operation) under the `TestSavedOnLinkPrefixes()` case.
This commit is contained in:
Abtin Keshavarzian
2022-11-22 22:04:55 -08:00
committed by GitHub
parent b468a25a61
commit eeb6ab0c8e
2 changed files with 21 additions and 16 deletions
@@ -2122,6 +2122,7 @@ void RoutingManager::OnLinkPrefixManager::GenerateLocalPrefix(void)
{
const MeshCoP::ExtendedPanId &extPanId = Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId();
OldPrefix * entry;
Ip6::Prefix oldLocalPrefix = mLocalPrefix;
// Global ID: 40 most significant bits of Extended PAN ID
// Subnet ID: 16 least significant bits of Extended PAN ID
@@ -2132,6 +2133,11 @@ void RoutingManager::OnLinkPrefixManager::GenerateLocalPrefix(void)
mLocalPrefix.SetLength(kOnLinkPrefixLength);
// We ensure that the local prefix did change, since not all the
// bytes in Extended PAN ID are used in derivation of the local prefix.
VerifyOrExit(mLocalPrefix != oldLocalPrefix);
LogNote("Local on-link prefix: %s", mLocalPrefix.ToString().AsCString());
// Check if the new local prefix happens to be in `mOldLocalPrefixes` array.
@@ -2149,6 +2155,9 @@ void RoutingManager::OnLinkPrefixManager::GenerateLocalPrefix(void)
{
mState = kIdle;
}
exit:
return;
}
void RoutingManager::OnLinkPrefixManager::Start(void)
@@ -2462,6 +2471,8 @@ void RoutingManager::OnLinkPrefixManager::HandleExtPanIdChange(void)
GenerateLocalPrefix();
VerifyOrExit(oldPrefix != mLocalPrefix);
switch (oldState)
{
case kIdle:
@@ -2481,6 +2492,9 @@ void RoutingManager::OnLinkPrefixManager::HandleExtPanIdChange(void)
{
Get<RoutingManager>().ScheduleRoutingPolicyEvaluation(kAfterRandomDelay);
}
exit:
return;
}
void RoutingManager::OnLinkPrefixManager::DeprecateOldPrefix(const Ip6::Prefix &aPrefix, TimeMilli aExpireTime)
+7 -16
View File
@@ -829,7 +829,7 @@ void VerifyPrefixTable(const OnLinkPrefix *aOnLinkPrefixes,
VerifyOrQuit(routePrefixCount == aNumRoutePrefixes);
}
void InitTest(void)
void InitTest(bool aEnablBorderRouting = false)
{
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Initialize OT instance.
@@ -843,13 +843,14 @@ void InitTest(void)
SuccessOrQuit(sInfraIfAddress.FromString(kInfraIfAddress));
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Initialize Border Router and start Thread operation.
// Initialize and start Border Router and Thread operation.
SuccessOrQuit(otBorderRoutingInit(sInstance, kInfraIfIndex, /* aInfraIfIsRunning */ true));
SuccessOrQuit(otLinkSetPanId(sInstance, 0x1234));
SuccessOrQuit(otIp6SetEnabled(sInstance, true));
SuccessOrQuit(otThreadSetEnabled(sInstance, true));
SuccessOrQuit(otBorderRoutingSetEnabled(sInstance, aEnablBorderRouting));
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Ensure device starts as leader.
@@ -2514,18 +2515,16 @@ void TestSavedOnLinkPrefixes(void)
Log("--------------------------------------------------------------------------------------------");
Log("TestSavedOnLinkPrefixes");
InitTest();
InitTest(/* aEnablBorderRouting */ true);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Start Routing Manager. Check emitted RS and RA messages.
// Check emitted RS and RA messages.
sRsEmitted = false;
sRaValidated = false;
sExpectedPio = kPioAdvertisingLocalOnLink;
sExpectedRios.Clear();
SuccessOrQuit(sInstance->Get<BorderRouter::RoutingManager>().SetEnabled(true));
SuccessOrQuit(sInstance->Get<BorderRouter::RoutingManager>().GetOnLinkPrefix(localOnLink));
SuccessOrQuit(sInstance->Get<BorderRouter::RoutingManager>().GetOmrPrefix(localOmr));
@@ -2553,10 +2552,7 @@ void TestSavedOnLinkPrefixes(void)
testFreeInstance(sInstance);
InitTest();
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Start Routing Manager.
InitTest(/* aEnablBorderRouting */ true);
SuccessOrQuit(sInstance->Get<BorderRouter::RoutingManager>().SetEnabled(true));
@@ -2594,12 +2590,7 @@ void TestSavedOnLinkPrefixes(void)
testFreeInstance(sInstance);
InitTest();
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Start Routing Manager.
SuccessOrQuit(sInstance->Get<BorderRouter::RoutingManager>().SetEnabled(true));
InitTest(/* aEnablBorderRouting */ true);
sExpectedPio = kPioAdvertisingLocalOnLink;