From c71f802c39611af67d78a957d27199a81d989b24 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 22 Sep 2026 08:26:35 -0700 Subject: [PATCH] [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. --- tests/unit/test_routing_manager.cpp | 104 ++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/tests/unit/test_routing_manager.cpp b/tests/unit/test_routing_manager.cpp index 90b3a1179..25e5d8aa4 100644 --- a/tests/unit/test_routing_manager.cpp +++ b/tests/unit/test_routing_manager.cpp @@ -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().SetEnabled(true)); + + SuccessOrQuit(sInstance->Get().GetOnLinkPrefix(localOnLink)); + SuccessOrQuit(sInstance->Get().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().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();