mirror of
https://github.com/espressif/openthread.git
synced 2026-09-26 19:07:32 +00:00
[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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user