[br] add a new test for stale favored on-link prefix deprecation (#13620)

Adds a unit test `TestStaleFavoredOnLinkPrefix()` to validate that when
an external router advertises an on-link prefix that becomes favored,
its deprecation after the stale timer expiration triggers the border
router to start advertising its local on-link prefix.
This commit is contained in:
Abtin Keshavarzian
2026-09-22 08:26:35 -07:00
committed by GitHub
parent e04ff19275
commit c71f802c39
+104
View File
@@ -2637,6 +2637,109 @@ void TestFavoredOnLinkPrefix(void)
FinalizeTest();
}
void TestStaleFavoredOnLinkPrefix(void)
{
Ip6::Prefix localOnLink;
Ip6::Prefix localOmr;
Ip6::Prefix onLinkPrefix = PrefixFromString("2000:abba:baba::", 64);
Ip6::Address routerAddressA = AddressFromString("fd00::aaaa");
uint16_t heapAllocations;
Log("--------------------------------------------------------------------------------------------");
Log("TestStaleFavoredOnLinkPrefix");
InitTest();
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Start Routing Manager.
sRsEmitted = false;
sRaValidated = false;
sExpectedPio = kNoPio;
sExpectedRios.Clear();
heapAllocations = sHeapAllocatedPtrs.GetLength();
SuccessOrQuit(sInstance->Get<BorderRouter::RoutingManager>().SetEnabled(true));
SuccessOrQuit(sInstance->Get<BorderRouter::RoutingManager>().GetOnLinkPrefix(localOnLink));
SuccessOrQuit(sInstance->Get<BorderRouter::RoutingManager>().GetOmrPrefix(localOmr));
Log("Local on-link prefix is %s", localOnLink.ToString().AsCString());
Log("Local OMR prefix is %s", localOmr.ToString().AsCString());
sExpectedRios.Add(localOmr);
// Advance time to allow the initial router discovery cycle to start
// and emit the first RS message (random start delay of up to 1 second
// followed by 4-second intervals between RS transmissions).
AdvanceTime(5000);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Send an RA from router A advertising an on-link prefix with a longer valid
// lifetime and a shorter preferred lifetime. It should be chosen as the
// favored on-link prefix, preventing BR from advertising its local prefix.
SendRouterAdvert(routerAddressA, {Pio(onLinkPrefix, kValidLitime, kPreferredLifetime)});
AdvanceTime(30 * 1000);
VerifyOrQuit(sRsEmitted);
VerifyOrQuit(sRaValidated);
VerifyOrQuit(sExpectedRios.SawAll());
VerifyFavoredOnLinkPrefix(onLinkPrefix);
VerifyPrefixTable({OnLinkPrefix(onLinkPrefix, kValidLitime, kPreferredLifetime, routerAddressA)});
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Wait until just before the 600-second stale time expires. Confirm that the
// stale timer has not fired yet and no RS messages are sent.
sRsEmitted = false;
AdvanceTime(560 * 1000);
VerifyOrQuit(!sRsEmitted);
VerifyFavoredOnLinkPrefix(onLinkPrefix);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Wait for the stale timer to expire. This starts RsSender to transmit RS
// messages to check if the router/prefix is still refreshed.
AdvanceTime(12 * 1000);
VerifyOrQuit(sRsEmitted);
VerifyFavoredOnLinkPrefix(onLinkPrefix);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Allow RsSender to complete its RS transmission cycle with no RA response.
// Confirm that the prefix is deprecated and BR begins advertising its own
// local on-link prefix in emitted RAs.
sRaValidated = false;
sExpectedPio = kPioAdvertisingLocalOnLink;
sExpectedRios.Clear();
sExpectedRios.Add(localOmr);
AdvanceTime(30000);
VerifyOrQuit(sRaValidated);
VerifyOrQuit(sExpectedRios.SawAll());
VerifyFavoredOnLinkPrefix(localOnLink);
VerifyPrefixTable({OnLinkPrefix(onLinkPrefix, kValidLitime, 0, routerAddressA)});
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SuccessOrQuit(sInstance->Get<BorderRouter::RoutingManager>().SetEnabled(false));
AdvanceTime(3000);
VerifyOrQuit(heapAllocations == sHeapAllocatedPtrs.GetLength());
Log("End of TestStaleFavoredOnLinkPrefix");
FinalizeTest();
}
void TestLocalOnLinkPrefixDeprecation(void)
{
static constexpr uint32_t kMaxRaTxInterval = 196; // In seconds
@@ -5741,6 +5844,7 @@ int main(void)
ot::TestNonUlaPioWithOnlyOnLinkFlag();
ot::TestAdvNonUlaRoute();
ot::TestFavoredOnLinkPrefix();
ot::TestStaleFavoredOnLinkPrefix();
ot::TestLocalOnLinkPrefixDeprecation();
ot::TestUnadvertisedLocalOnLinkPrefix();
ot::TestExtPanIdChange();