diff --git a/src/core/openthread-core-default-config.h b/src/core/openthread-core-default-config.h index 6c610e2c0..87b983ff0 100644 --- a/src/core/openthread-core-default-config.h +++ b/src/core/openthread-core-default-config.h @@ -1662,6 +1662,16 @@ #define OPENTHREAD_CONFIG_MLE_PARTITION_MERGE_MARGIN_MIN 10 #endif +/** + * @def OPENTHREAD_CONFIG_MLE_CHILD_ROUTER_LINKS + * + * Specifies the desired number of router links that a REED / FED attempts to maintain. + * + */ +#ifndef OPENTHREAD_CONFIG_MLE_CHILD_ROUTER_LINKS +#define OPENTHREAD_CONFIG_MLE_CHILD_ROUTER_LINKS 3 +#endif + /** * @def OPENTHREAD_CONFIG_ENABLE_DEBUG_UART * diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 38f91c62e..aaa6c8464 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -1352,7 +1352,8 @@ otError MleRouter::HandleAdvertisement(const Message &aMessage, const Ip6::Messa } } else if (IsFullThreadDevice() && (router->GetState() != Neighbor::kStateValid) && - (router->GetState() != Neighbor::kStateLinkRequest)) + (router->GetState() != Neighbor::kStateLinkRequest) && + (mRouterTable.GetActiveLinkCount() < OPENTHREAD_CONFIG_MLE_CHILD_ROUTER_LINKS)) { router->SetExtAddress(macAddr); router->GetLinkInfo().Clear(); diff --git a/src/core/thread/router_table.cpp b/src/core/thread/router_table.cpp index 60bef7622..1f4cc42a9 100644 --- a/src/core/thread/router_table.cpp +++ b/src/core/thread/router_table.cpp @@ -335,6 +335,28 @@ void RouterTable::RemoveNeighbor(Router &aRouter) } } +uint8_t RouterTable::GetActiveLinkCount(void) const +{ + uint8_t activeLinks = 0; + + for (int i = 0; i < Mle::kMaxRouters; i++) + { + const Router &cur = mRouters[i]; + + if (cur.GetRloc16() == 0xffff) + { + break; + } + + if (cur.GetState() == Neighbor::kStateValid) + { + activeLinks++; + } + } + + return activeLinks; +} + Router *RouterTable::GetNeighbor(uint16_t aRloc16) { Router *router = NULL; diff --git a/src/core/thread/router_table.hpp b/src/core/thread/router_table.hpp index 83b697c58..b4e610492 100644 --- a/src/core/thread/router_table.hpp +++ b/src/core/thread/router_table.hpp @@ -176,6 +176,14 @@ public: */ uint8_t GetActiveRouterCount(void) const { return mActiveRouterCount; } + /** + * This method returns the number of active links with neighboring routers. + * + * @returns The number of active links with neighboring routers. + * + */ + uint8_t GetActiveLinkCount(void) const; + /** * This method returns the leader in the Thread network. *