diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index bdfaa14fae9..453f4954917 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -1183,7 +1183,7 @@ void RoutingManager::DiscoveredPrefixTable::ProcessRouterAdvertMessage(const Ip6 if (router == nullptr) { - router = mRouters.PushBack(); + router = AllocateRouter(); if (router == nullptr) { @@ -1193,6 +1193,8 @@ void RoutingManager::DiscoveredPrefixTable::ProcessRouterAdvertMessage(const Ip6 router->Clear(); router->mAddress = aSrcAddress; + + mRouters.Push(*router); } // RA message can indicate router provides default route in the RA @@ -1471,13 +1473,12 @@ void RoutingManager::DiscoveredPrefixTable::RemoveAllEntries(void) for (Router &router : mRouters) { - Entry *entry; - - while ((entry = router.mEntries.Pop()) != nullptr) + if (!router.mEntries.IsEmpty()) { - FreeEntry(*entry); SignalTableChanged(); } + + FreeEntries(router.mEntries); } RemoveRoutersWithNoEntries(); @@ -1579,13 +1580,27 @@ TimeMilli RoutingManager::DiscoveredPrefixTable::CalculateNextStaleTime(TimeMill void RoutingManager::DiscoveredPrefixTable::RemoveRoutersWithNoEntries(void) { - mRouters.RemoveAllMatching(Router::kContainsNoEntries); + LinkedList routersToFree; + + mRouters.RemoveAllMatching(Router::kContainsNoEntries, routersToFree); + FreeRouters(routersToFree); +} + +void RoutingManager::DiscoveredPrefixTable::FreeRouters(LinkedList &aRouters) +{ + // Frees all routers in the given list `aRouters` + + Router *router; + + while ((router = aRouters.Pop()) != nullptr) + { + FreeRouter(*router); + } } void RoutingManager::DiscoveredPrefixTable::FreeEntries(LinkedList &aEntries) { - // Frees all entries in the given list `aEntries` (put them back - // in the entry pool). + // Frees all entries in the given list `aEntries`. Entry *entry; @@ -1768,8 +1783,8 @@ void RoutingManager::DiscoveredPrefixTable::InitIterator(PrefixTableIterator &aI Iterator &iterator = static_cast(aIterator); iterator.SetInitTime(); - iterator.SetRouter(mRouters.Front()); - iterator.SetEntry(mRouters.IsEmpty() ? nullptr : mRouters[0].mEntries.GetHead()); + iterator.SetRouter(mRouters.GetHead()); + iterator.SetEntry(mRouters.IsEmpty() ? nullptr : mRouters.GetHead()->mEntries.GetHead()); } Error RoutingManager::DiscoveredPrefixTable::GetNextEntry(PrefixTableIterator &aIterator, @@ -1795,15 +1810,12 @@ Error RoutingManager::DiscoveredPrefixTable::GetNextEntry(PrefixTableIterator &a if (iterator.GetEntry() == nullptr) { - if (iterator.GetRouter() != mRouters.Back()) + iterator.SetRouter(iterator.GetRouter()->GetNext()); + + if (iterator.GetRouter() != nullptr) { - iterator.SetRouter(iterator.GetRouter() + 1); iterator.SetEntry(iterator.GetRouter()->mEntries.GetHead()); } - else - { - iterator.SetRouter(nullptr); - } } exit: diff --git a/src/core/border_router/routing_manager.hpp b/src/core/border_router/routing_manager.hpp index a00dd34781a..bfcbfa36230 100644 --- a/src/core/border_router/routing_manager.hpp +++ b/src/core/border_router/routing_manager.hpp @@ -53,6 +53,7 @@ #include "border_router/infra_if.hpp" #include "common/array.hpp" #include "common/error.hpp" +#include "common/heap_allocatable.hpp" #include "common/linked_list.hpp" #include "common/locator.hpp" #include "common/message.hpp" @@ -624,10 +625,17 @@ class RoutingManager : public InstanceLocator void HandleRouterTimer(void); private: +#if !OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE static constexpr uint16_t kMaxRouters = OPENTHREAD_CONFIG_BORDER_ROUTING_MAX_DISCOVERED_ROUTERS; static constexpr uint16_t kMaxEntries = OPENTHREAD_CONFIG_BORDER_ROUTING_MAX_DISCOVERED_PREFIXES; +#endif - class Entry : public LinkedListEntry, public Unequatable, private Clearable + class Entry : public LinkedListEntry, + public Unequatable, +#if OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE + public Heap::Allocatable, +#endif + private Clearable { friend class LinkedListEntry; friend class Clearable; @@ -725,7 +733,11 @@ class RoutingManager : public InstanceLocator } mShared; }; - struct Router : public Clearable + struct Router : public LinkedListEntry, +#if OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE + public Heap::Allocatable, +#endif + public Clearable { // The timeout (in msec) for router staying in active state // before starting the Neighbor Solicitation (NS) probes. @@ -746,6 +758,7 @@ class RoutingManager : public InstanceLocator bool Matches(const Ip6::Address &aAddress) const { return aAddress == mAddress; } bool Matches(EmptyChecker) const { return mEntries.IsEmpty(); } + Router *mNext; Ip6::Address mAddress; LinkedList mEntries; TimeMilli mTimeout; @@ -774,8 +787,7 @@ class RoutingManager : public InstanceLocator void RemovePrefix(const Entry::Matcher &aMatcher); void RemoveOrDeprecateEntriesFromInactiveRouters(void); void RemoveRoutersWithNoEntries(void); - Entry *AllocateEntry(void) { return mEntryPool.Allocate(); } - void FreeEntry(Entry &aEntry) { mEntryPool.Free(aEntry); } + void FreeRouters(LinkedList &aRouters); void FreeEntries(LinkedList &aEntries); void UpdateNetworkDataOnChangeTo(Entry &aEntry); const Entry *FindFavoredEntryToPublish(const Ip6::Prefix &aPrefix) const; @@ -783,16 +795,30 @@ class RoutingManager : public InstanceLocator void SignalTableChanged(void); void UpdateRouterOnRx(Router &aRouter); void SendNeighborSolicitToRouter(const Router &aRouter); +#if OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE + Router *AllocateRouter(void) { return Router::Allocate(); } + Entry *AllocateEntry(void) { return Entry::Allocate(); } + void FreeRouter(Router &aRouter) { aRouter.Free(); } + void FreeEntry(Entry &aEntry) { aEntry.Free(); } +#else + Router *AllocateRouter(void) { return mRouterPool.Allocate(); } + Entry *AllocateEntry(void) { return mEntryPool.Allocate(); } + void FreeRouter(Router &aRouter) { mRouterPool.Free(aRouter); } + void FreeEntry(Entry &aEntry) { mEntryPool.Free(aEntry); } +#endif using SignalTask = TaskletIn; using EntryTimer = TimerMilliIn; using RouterTimer = TimerMilliIn; - Array mRouters; - Pool mEntryPool; - EntryTimer mEntryTimer; - RouterTimer mRouterTimer; - SignalTask mSignalTask; + LinkedList mRouters; + EntryTimer mEntryTimer; + RouterTimer mRouterTimer; + SignalTask mSignalTask; +#if !OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE + Pool mEntryPool; + Pool mRouterPool; +#endif }; class OmrPrefixManager; diff --git a/src/core/config/border_routing.h b/src/core/config/border_routing.h index 1b13a8e9f8a..a7f57d1fedd 100644 --- a/src/core/config/border_routing.h +++ b/src/core/config/border_routing.h @@ -45,11 +45,30 @@ #define OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE 0 #endif +/** + * @def OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE + * + * Define to 1 to allow using heap by Routing Manager. + * + * When enabled heap allocated entries will be used to track discovered prefix table contain information about + * discovered routers and the advertised on-link prefixes on infra link. + * + * When disabled pre-allocated pools are used instead where max number of entries are specified by + * `OPENTHREAD_CONFIG_BORDER_ROUTING_MAX_DISCOVERED_ROUTERS` and `MAX_DISCOVERED_PREFIXES` configurations. + * + */ +#ifndef OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE +#define OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE 1 +#endif + /** * @def OPENTHREAD_CONFIG_BORDER_ROUTING_MAX_DISCOVERED_ROUTERS * * Specifies maximum number of routers (on infra link) to track by routing manager. * + * Applicable only when heap allocation is not used, i.e., `OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE` is + * disabled. + * */ #ifndef OPENTHREAD_CONFIG_BORDER_ROUTING_MAX_DISCOVERED_ROUTERS #define OPENTHREAD_CONFIG_BORDER_ROUTING_MAX_DISCOVERED_ROUTERS 16 @@ -60,6 +79,9 @@ * * Specifies maximum number of discovered prefixes (on-link prefixes on the infra link) maintained by routing manager. * + * Applicable only when heap allocation is not used, i.e., `OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE` is + * disabled. + * */ #ifndef OPENTHREAD_CONFIG_BORDER_ROUTING_MAX_DISCOVERED_PREFIXES #define OPENTHREAD_CONFIG_BORDER_ROUTING_MAX_DISCOVERED_PREFIXES 64 diff --git a/tests/unit/test_routing_manager.cpp b/tests/unit/test_routing_manager.cpp index 43089b4e02d..ae1d21e7b75 100644 --- a/tests/unit/test_routing_manager.cpp +++ b/tests/unit/test_routing_manager.cpp @@ -476,6 +476,37 @@ void ValidateRouterAdvert(const Icmp6Packet &aPacket) return; } +//---------------------------------------------------------------------------------------------------------------------- + +Array sHeapAllocatedPtrs; + +#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE + +void *otPlatCAlloc(size_t aNum, size_t aSize) +{ + void *ptr = calloc(aNum, aSize); + + SuccessOrQuit(sHeapAllocatedPtrs.PushBack(ptr)); + + return ptr; +} + +void otPlatFree(void *aPtr) +{ + if (aPtr != nullptr) + { + void **entry = sHeapAllocatedPtrs.Find(aPtr); + + VerifyOrQuit(entry != nullptr, "A heap allocated item is freed twice"); + sHeapAllocatedPtrs.Remove(*entry); + } + + free(aPtr); +} +#endif + +//---------------------------------------------------------------------------------------------------------------------- + void LogRouterAdvert(const Icmp6Packet &aPacket) { Ip6::Nd::RouterAdvertMessage raMsg(aPacket); @@ -1014,6 +1045,7 @@ void TestSamePrefixesFromMultipleRouters(void) Ip6::Prefix routePrefix = PrefixFromString("2000:1234:5678::", 64); Ip6::Address routerAddressA = AddressFromString("fd00::aaaa"); Ip6::Address routerAddressB = AddressFromString("fd00::bbbb"); + uint16_t heapAllocations; Log("--------------------------------------------------------------------------------------------"); Log("TestSamePrefixesFromMultipleRouters"); @@ -1028,6 +1060,7 @@ void TestSamePrefixesFromMultipleRouters(void) sExpectedPio = kPioAdvertisingLocalOnLink; sExpectedRios.Clear(); + heapAllocations = sHeapAllocatedPtrs.GetLength(); SuccessOrQuit(sInstance->Get().SetEnabled(true)); SuccessOrQuit(sInstance->Get().GetOnLinkPrefix(localOnLink)); @@ -1135,6 +1168,9 @@ void TestSamePrefixesFromMultipleRouters(void) //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + SuccessOrQuit(sInstance->Get().SetEnabled(false)); + VerifyOrQuit(heapAllocations == sHeapAllocatedPtrs.GetLength()); + Log("End of TestSamePrefixesFromMultipleRouters"); FinalizeTest(); @@ -1146,6 +1182,7 @@ void TestOmrSelection(void) Ip6::Prefix localOmr; Ip6::Prefix omrPrefix = PrefixFromString("2000:0000:1111:4444::", 64); NetworkData::OnMeshPrefixConfig prefixConfig; + uint16_t heapAllocations; Log("--------------------------------------------------------------------------------------------"); Log("TestOmrSelection"); @@ -1160,6 +1197,7 @@ void TestOmrSelection(void) sExpectedPio = kPioAdvertisingLocalOnLink; sExpectedRios.Clear(); + heapAllocations = sHeapAllocatedPtrs.GetLength(); SuccessOrQuit(sInstance->Get().SetEnabled(true)); SuccessOrQuit(sInstance->Get().GetOnLinkPrefix(localOnLink)); @@ -1250,6 +1288,9 @@ void TestOmrSelection(void) //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + SuccessOrQuit(sInstance->Get().SetEnabled(false)); + VerifyOrQuit(heapAllocations = sHeapAllocatedPtrs.GetLength()); + Log("End of TestOmrSelection"); FinalizeTest(); } @@ -1262,6 +1303,7 @@ void TestDefaultRoute(void) Ip6::Prefix defaultRoute = PrefixFromString("::", 0); Ip6::Address routerAddressA = AddressFromString("fd00::aaaa"); NetworkData::OnMeshPrefixConfig prefixConfig; + uint16_t heapAllocations; Log("--------------------------------------------------------------------------------------------"); Log("TestDefaultRoute"); @@ -1276,6 +1318,7 @@ void TestDefaultRoute(void) sExpectedPio = kPioAdvertisingLocalOnLink; sExpectedRios.Clear(); + heapAllocations = sHeapAllocatedPtrs.GetLength(); SuccessOrQuit(sInstance->Get().SetEnabled(true)); SuccessOrQuit(sInstance->Get().GetOnLinkPrefix(localOnLink)); @@ -1410,6 +1453,9 @@ void TestDefaultRoute(void) //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + SuccessOrQuit(sInstance->Get().SetEnabled(false)); + VerifyOrQuit(heapAllocations = sHeapAllocatedPtrs.GetLength()); + Log("End of TestDefaultRoute"); FinalizeTest(); @@ -1423,6 +1469,7 @@ void TestAdvNonUlaRoute(void) Ip6::Prefix routePrefix = PrefixFromString("2000:1234:5678::", 64); Ip6::Address routerAddressA = AddressFromString("fd00::aaaa"); NetworkData::OnMeshPrefixConfig prefixConfig; + uint16_t heapAllocations; Log("--------------------------------------------------------------------------------------------"); Log("TestAdvNonUlaRoute"); @@ -1437,6 +1484,7 @@ void TestAdvNonUlaRoute(void) sExpectedPio = kPioAdvertisingLocalOnLink; sExpectedRios.Clear(); + heapAllocations = sHeapAllocatedPtrs.GetLength(); SuccessOrQuit(sInstance->Get().SetEnabled(true)); SuccessOrQuit(sInstance->Get().GetOnLinkPrefix(localOnLink)); @@ -1571,6 +1619,9 @@ void TestAdvNonUlaRoute(void) //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + SuccessOrQuit(sInstance->Get().SetEnabled(false)); + VerifyOrQuit(heapAllocations = sHeapAllocatedPtrs.GetLength()); + Log("End of TestAdvNonUlaRoute"); FinalizeTest(); @@ -1585,6 +1636,7 @@ void TestLocalOnLinkPrefixDeprecation(void) Ip6::Prefix onLinkPrefix = PrefixFromString("fd00:abba:baba::", 64); Ip6::Address routerAddressA = AddressFromString("fd00::aaaa"); uint32_t localOnLinkLifetime; + uint16_t heapAllocations; Log("--------------------------------------------------------------------------------------------"); Log("TestLocalOnLinkPrefixDeprecation"); @@ -1594,6 +1646,7 @@ void TestLocalOnLinkPrefixDeprecation(void) //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Start Routing Manager. Check emitted RS and RA messages. + heapAllocations = sHeapAllocatedPtrs.GetLength(); SuccessOrQuit(sInstance->Get().SetEnabled(true)); SuccessOrQuit(sInstance->Get().GetOnLinkPrefix(localOnLink)); @@ -1705,6 +1758,9 @@ void TestLocalOnLinkPrefixDeprecation(void) //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + SuccessOrQuit(sInstance->Get().SetEnabled(false)); + VerifyOrQuit(heapAllocations = sHeapAllocatedPtrs.GetLength()); + Log("End of TestLocalOnLinkPrefixDeprecation"); FinalizeTest(); @@ -1717,6 +1773,7 @@ void TestDomainPrefixAsOmr(void) Ip6::Prefix localOmr; Ip6::Prefix domainPrefix = PrefixFromString("2000:0000:1111:4444::", 64); NetworkData::OnMeshPrefixConfig prefixConfig; + uint16_t heapAllocations; Log("--------------------------------------------------------------------------------------------"); Log("TestDomainPrefixAsOmr"); @@ -1731,6 +1788,7 @@ void TestDomainPrefixAsOmr(void) sExpectedPio = kPioAdvertisingLocalOnLink; sExpectedRios.Clear(); + heapAllocations = sHeapAllocatedPtrs.GetLength(); SuccessOrQuit(sInstance->Get().SetEnabled(true)); SuccessOrQuit(sInstance->Get().GetOnLinkPrefix(localOnLink)); @@ -1852,6 +1910,9 @@ void TestDomainPrefixAsOmr(void) //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + SuccessOrQuit(sInstance->Get().SetEnabled(false)); + VerifyOrQuit(heapAllocations = sHeapAllocatedPtrs.GetLength()); + Log("End of TestDomainPrefixAsOmr"); FinalizeTest(); } @@ -1875,6 +1936,7 @@ void TestExtPanIdChange(void) uint32_t oldPrefixLifetime; Ip6::Prefix oldPrefixes[4]; otOperationalDataset dataset; + uint16_t heapAllocations; Log("--------------------------------------------------------------------------------------------"); Log("TestExtPanIdChange"); @@ -1884,6 +1946,7 @@ void TestExtPanIdChange(void) //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Start Routing Manager. Check emitted RS and RA messages. + heapAllocations = sHeapAllocatedPtrs.GetLength(); SuccessOrQuit(sInstance->Get().SetEnabled(true)); SuccessOrQuit(sInstance->Get().GetOnLinkPrefix(localOnLink)); @@ -2356,6 +2419,9 @@ void TestExtPanIdChange(void) //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + SuccessOrQuit(sInstance->Get().SetEnabled(false)); + VerifyOrQuit(heapAllocations = sHeapAllocatedPtrs.GetLength()); + Log("End of TestExtPanIdChange"); FinalizeTest(); } @@ -2368,6 +2434,7 @@ void TestRouterNsProbe(void) Ip6::Prefix routePrefix = PrefixFromString("2000:1234:5678::", 64); Ip6::Address routerAddressA = AddressFromString("fd00::aaaa"); Ip6::Address routerAddressB = AddressFromString("fd00::bbbb"); + uint16_t heapAllocations; Log("--------------------------------------------------------------------------------------------"); Log("TestRouterNsProbe"); @@ -2382,6 +2449,7 @@ void TestRouterNsProbe(void) sExpectedPio = kPioAdvertisingLocalOnLink; sExpectedRios.Clear(); + heapAllocations = sHeapAllocatedPtrs.GetLength(); SuccessOrQuit(sInstance->Get().SetEnabled(true)); SuccessOrQuit(sInstance->Get().GetOnLinkPrefix(localOnLink)); @@ -2504,6 +2572,9 @@ void TestRouterNsProbe(void) //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + SuccessOrQuit(sInstance->Get().SetEnabled(false)); + VerifyOrQuit(heapAllocations = sHeapAllocatedPtrs.GetLength()); + Log("End of TestRouterNsProbe"); FinalizeTest(); } @@ -2519,6 +2590,7 @@ void TestConflictingPrefix(void) Ip6::Address routerAddressA = AddressFromString("fd00::aaaa"); Ip6::Address routerAddressB = AddressFromString("fd00::bbbb"); otOperationalDataset dataset; + uint16_t heapAllocations; Log("--------------------------------------------------------------------------------------------"); Log("TestConflictingPrefix"); @@ -2533,6 +2605,7 @@ void TestConflictingPrefix(void) sExpectedPio = kPioAdvertisingLocalOnLink; sExpectedRios.Clear(); + heapAllocations = sHeapAllocatedPtrs.GetLength(); SuccessOrQuit(sInstance->Get().SetEnabled(true)); SuccessOrQuit(sInstance->Get().GetOnLinkPrefix(localOnLink)); @@ -2718,6 +2791,9 @@ void TestConflictingPrefix(void) //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + SuccessOrQuit(sInstance->Get().SetEnabled(false)); + VerifyOrQuit(heapAllocations = sHeapAllocatedPtrs.GetLength()); + Log("End of TestConflictingPrefix"); FinalizeTest(); @@ -2945,12 +3021,15 @@ void TestAutoEnableOfSrpServer(void) Ip6::Prefix localOmr; Ip6::Address routerAddressA = AddressFromString("fd00::aaaa"); Ip6::Prefix onLinkPrefix = PrefixFromString("2000:abba:baba::", 64); + uint16_t heapAllocations; Log("--------------------------------------------------------------------------------------------"); Log("TestAutoEnableOfSrpServer"); InitTest(); + heapAllocations = sHeapAllocatedPtrs.GetLength(); + //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Check SRP Server state and enable auto-enable mode @@ -3140,6 +3219,8 @@ void TestAutoEnableOfSrpServer(void) //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + VerifyOrQuit(sHeapAllocatedPtrs.GetLength() == heapAllocations); + Log("End of TestAutoEnableOfSrpServer"); FinalizeTest(); } @@ -3153,6 +3234,7 @@ void TestNat64PrefixSelection(void) Ip6::Prefix localOmr; Ip6::Prefix omrPrefix = PrefixFromString("2000:0000:1111:4444::", 64); NetworkData::OnMeshPrefixConfig prefixConfig; + uint16_t heapAllocations; Log("--------------------------------------------------------------------------------------------"); Log("TestNat64PrefixSelection"); @@ -3162,6 +3244,7 @@ void TestNat64PrefixSelection(void) //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Start Routing Manager. Check local NAT64 prefix generation. + heapAllocations = sHeapAllocatedPtrs.GetLength(); SuccessOrQuit(sInstance->Get().SetEnabled(true)); SuccessOrQuit(sInstance->Get().GetNat64Prefix(localNat64)); SuccessOrQuit(sInstance->Get().GetOmrPrefix(localOmr)); @@ -3222,6 +3305,9 @@ void TestNat64PrefixSelection(void) VerifyOmrPrefixInNetData(omrPrefix, /* aDefaultRoute */ false); VerifyNat64PrefixInNetData(localNat64); + SuccessOrQuit(sInstance->Get().SetEnabled(false)); + VerifyOrQuit(sHeapAllocatedPtrs.GetLength() == heapAllocations); + Log("End of TestNat64PrefixSelection"); FinalizeTest(); } @@ -3246,11 +3332,13 @@ void VerifyNoPdOmrPrefix() void TestBorderRoutingProcessPlatfromGeneratedNd(void) { Ip6::Prefix localOmr; + uint16_t heapAllocations; Log("--------------------------------------------------------------------------------------------"); Log("TestBorderRoutingProcessPlatfromGeneratedNd"); InitTest(/* aEnableBorderRouting */ true); + heapAllocations = sHeapAllocatedPtrs.GetLength(); otBorderRoutingDhcp6PdSetEnabled(sInstance, true); @@ -3433,6 +3521,10 @@ void TestBorderRoutingProcessPlatfromGeneratedNd(void) VerifyNoPdOmrPrefix(); VerifyOmrPrefixInNetData(localOmr, /* aDefaultRoute */ false); } + + SuccessOrQuit(otBorderRoutingSetEnabled(sInstance, false)); + VerifyOrQuit(sHeapAllocatedPtrs.GetLength() == heapAllocations); + Log("End of TestBorderRoutingProcessPlatfromGeneratedNd"); } #endif // OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_ENABLE