From d0c983f0a4c845cfbbf2808b4e2f7b8a1433af41 Mon Sep 17 00:00:00 2001 From: rongli Date: Sat, 3 Feb 2018 14:54:57 +0800 Subject: [PATCH] [mle] delay to send announce for FTD (#2521) --- src/core/thread/mle.cpp | 26 +++++++++++++++++++------- src/core/thread/mle.hpp | 10 ++++++++++ src/core/thread/mle_router.cpp | 9 +++++++++ src/core/thread/mle_router_ftd.hpp | 8 ++++++++ src/core/thread/mle_router_mtd.hpp | 1 + 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index ad4ac8b54..bf845ed88 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -644,13 +644,8 @@ otError Mle::SetStateChild(uint16_t aRloc16) netif.GetIp6().SetForwardingEnabled(false); netif.GetIp6().GetMpl().SetTimerExpirations(kMplChildDataMessageTimerExpirations); - // Once the Thread device receives the new Active Commissioning Dataset, the device MUST - // transmit its own Announce messages on the channel it was on prior to the attachment. - if (mPreviousPanId != Mac::kPanIdBroadcast) - { - mPreviousPanId = Mac::kPanIdBroadcast; - netif.GetAnnounceBeginServer().SendAnnounce(1 << mPreviousChannel); - } + // send announce after attached if needed + InformPreviousChannel(); #if OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH UpdateParentSearchState(); @@ -665,6 +660,23 @@ otError Mle::SetStateChild(uint16_t aRloc16) return OT_ERROR_NONE; } +void Mle::InformPreviousChannel(void) +{ + VerifyOrExit(mPreviousPanId != Mac::kPanIdBroadcast); + VerifyOrExit(mRole == OT_DEVICE_ROLE_CHILD || mRole == OT_DEVICE_ROLE_ROUTER); + + if ((mDeviceMode & ModeTlv::kModeFFD) == 0 || + mRole == OT_DEVICE_ROLE_ROUTER || + GetNetif().GetMle().GetRouterSelectionJitterTimeout() == 0) + { + mPreviousPanId = Mac::kPanIdBroadcast; + GetNetif().GetAnnounceBeginServer().SendAnnounce(1 << mPreviousChannel); + } + +exit: + return; +} + otError Mle::SetTimeout(uint32_t aTimeout) { VerifyOrExit(mTimeout != aTimeout); diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 656fe47b5..c7732de13 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -1360,6 +1360,16 @@ protected: */ void LogMleMessage(const char *aLogMessage, const Ip6::Address &aAddress, uint16_t aRloc) const; + /** + * This method triggers MLE Announce on previous channel after the Thread device successfully + * attaches and receives the new Active Commissioning Dataset if needed. + * + * MTD would send Announce immediately after attached. + * FTD would delay to send Announce after tried to become Router or decided to stay in REED role. + * + */ + void InformPreviousChannel(void); + LeaderDataTlv mLeaderData; ///< Last received Leader Data TLV. bool mRetrieveNewNetworkData; ///< Indicating new Network Data is needed if set. diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 66a9f8e2d..1f8a6bb41 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -1871,6 +1871,11 @@ void MleRouter::HandleStateUpdateTimer(void) // upgrade to Router BecomeRouter(ThreadStatusTlv::kTooFewRouters); } + else + { + // send announce after decided to stay in REED if needed + InformPreviousChannel(); + } if (!mAdvertiseTimer.IsRunning()) { @@ -4360,6 +4365,10 @@ void MleRouter::HandleAddressSolicitResponse(Coap::Header *aHeader, Message *aMe } exit: + + // send announce after received address solicit reply if needed + InformPreviousChannel(); + return; } diff --git a/src/core/thread/mle_router_ftd.hpp b/src/core/thread/mle_router_ftd.hpp index 3bc196483..019d371f8 100644 --- a/src/core/thread/mle_router_ftd.hpp +++ b/src/core/thread/mle_router_ftd.hpp @@ -301,6 +301,14 @@ public: */ otError SetRouterSelectionJitter(uint8_t aRouterJitter); + /** + * This method returns the current router selection jitter timeout value. + * + * @returns The current router selection jitter timeout value. + * + */ + uint8_t GetRouterSelectionJitterTimeout(void) { return mRouterSelectionJitterTimeout; } + /** * This method returns the current Router ID Sequence value. * diff --git a/src/core/thread/mle_router_mtd.hpp b/src/core/thread/mle_router_mtd.hpp index 80be08cd5..b50678a62 100644 --- a/src/core/thread/mle_router_mtd.hpp +++ b/src/core/thread/mle_router_mtd.hpp @@ -59,6 +59,7 @@ public: uint8_t GetActiveRouterCount(void) const { return 0; } uint8_t GetActiveNeighborRouterCount(void) const { return 0; } + uint8_t GetRouterSelectionJitterTimeout(void) { return 0; } uint32_t GetLeaderAge(void) const { return 0; }