From 322671e682af0b5b24b52e50e037772fe77ebdd2 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 23 Sep 2022 09:02:37 -0700 Subject: [PATCH] [routing-manager] remove old deprecating prefix on multiple xpanid change (#8151) This commit updates `RoutingManager` to ensure to unpublish the old local on-link prefix being deprecated on ext PAN ID change if the ext PAN ID happens to change again before the previous deprecating prefix is expired. Note that the code supports retaining one old deprecating prefix entry since back-to-back ext pan ID change is not expected as a typical use-case. This commit also updates `test_routing_manager` to cover and test this scenario. --- src/core/border_router/routing_manager.cpp | 5 +++ tests/unit/test_routing_manager.cpp | 38 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index b80059865..8075aee21 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -2145,6 +2145,11 @@ void RoutingManager::LocalOnLinkPrefix::HandleExtPanIdChange(void) case kAdvertising: case kDeprecating: + if (mOldPrefix.GetLength() != 0) + { + Unpublish(mOldPrefix); + } + mOldPrefix = mPrefix; mOldExpireTime = mExpireTime; mTimer.FireAtIfEarlier(mOldExpireTime); diff --git a/tests/unit/test_routing_manager.cpp b/tests/unit/test_routing_manager.cpp index 36da3aff5..1b7c2a353 100644 --- a/tests/unit/test_routing_manager.cpp +++ b/tests/unit/test_routing_manager.cpp @@ -1487,6 +1487,7 @@ void TestExtPanIdChange(void) static const otExtendedPanId kExtPanId1 = {{0x01, 0x02, 0x03, 0x04, 0x05, 0x6, 0x7, 0x08}}; static const otExtendedPanId kExtPanId2 = {{0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x99, 0x88}}; + static const otExtendedPanId kExtPanId3 = {{0x12, 0x34, 056, 0x78, 0x9a, 0xab, 0xcd, 0xef}}; Ip6::Prefix localOnLink; Ip6::Prefix oldLocalOnLink; @@ -1566,6 +1567,43 @@ void TestExtPanIdChange(void) // Validate the Network Data to contain both the current and old // local on-link prefixes. + VerifyOmrPrefixInNetData(localOmr); + VerifyExternalRoutesInNetData({ExternalRoute(localOnLink, NetworkData::kRoutePreferenceMedium), + ExternalRoute(oldLocalOnLink, NetworkData::kRoutePreferenceMedium)}); + + //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // Change the extended PAN ID again. + + Log("Changing ext PAN ID again"); + + oldLocalOnLink = localOnLink; + oldPrefixLifetime = sOnLinkLifetime; + + sRaValidated = false; + sExpectOldOnLinkPio = true; + sExpectedPio = kPioAdvertisingLocalOnLink; + + dataset.mExtendedPanId = kExtPanId3; + SuccessOrQuit(otDatasetSetActive(sInstance, &dataset)); + + AdvanceTime(500); + SuccessOrQuit(sInstance->Get().GetOnLinkPrefix(localOnLink)); + Log("Local on-link prefix changed to %s from %s", localOnLink.ToString().AsCString(), + oldLocalOnLink.ToString().AsCString()); + + //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // Validate the received RA message and that it contains the + // old on-link prefix being deprecated. + + AdvanceTime(30000); + + VerifyOrQuit(sRaValidated); + VerifyOrQuit(sOldOnLinkPrefix == oldLocalOnLink); + + //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // Validate the Network Data to contain both the current and old + // local on-link prefixes and the previous old prefix is now removed. + VerifyOmrPrefixInNetData(localOmr); VerifyExternalRoutesInNetData({ExternalRoute(localOnLink, NetworkData::kRoutePreferenceMedium), ExternalRoute(oldLocalOnLink, NetworkData::kRoutePreferenceMedium)});