From 2bc32a36d13a37a174fd3f2f67639b7d3235c9dc Mon Sep 17 00:00:00 2001 From: Rongli Sun Date: Sun, 16 Feb 2020 17:13:37 +0800 Subject: [PATCH] [network-data] introduce 5s delay between SRV_DATA.ntf when deregister for child (#4485) --- src/core/thread/network_data.cpp | 27 ++++++++++++++++----------- src/core/thread/network_data.hpp | 4 +++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/core/thread/network_data.cpp b/src/core/thread/network_data.cpp index 88f1299c5..36098812d 100644 --- a/src/core/thread/network_data.cpp +++ b/src/core/thread/network_data.cpp @@ -977,8 +977,16 @@ otError NetworkData::SendServerDataNotification(uint16_t aRloc16) Coap::Message * message = NULL; Ip6::MessageInfo messageInfo; - VerifyOrExit(mLastAttempt.GetValue() == 0 || ((TimerMilli::GetNow() - mLastAttempt) > kDataResubmitDelay), - error = OT_ERROR_ALREADY); + if (mLastAttempt.GetValue() != 0) + { + uint32_t diff = TimerMilli::GetNow() - mLastAttempt; + + if (((mType == kTypeLocal) && (diff > kDataResubmitDelay)) || + ((mType == kTypeLeader) && (diff > kProxyResubmitDelay))) + { + ExitNow(error = OT_ERROR_ALREADY); + } + } VerifyOrExit((message = Get().NewMessage()) != NULL, error = OT_ERROR_NO_BUFS); @@ -1007,16 +1015,13 @@ otError NetworkData::SendServerDataNotification(uint16_t aRloc16) messageInfo.SetPeerPort(kCoapUdpPort); SuccessOrExit(error = Get().SendMessage(*message, messageInfo)); - if (mType == kTypeLocal) - { - mLastAttempt = TimerMilli::GetNow(); + mLastAttempt = TimerMilli::GetNow(); - // `0` is a special value to indicate no delay limitation on sending SRV_DATA.ntf. - // Here avoids possible impact in rate limitation of SRV_DATA.ntf in case of wrap. - if (mLastAttempt.GetValue() == 0) - { - mLastAttempt.SetValue(1); - } + // `0` is a special value to indicate no delay limitation on sending SRV_DATA.ntf. + // Here avoids possible impact in rate limitation of SRV_DATA.ntf in case of wrap. + if (mLastAttempt.GetValue() == 0) + { + mLastAttempt.SetValue(1); } otLogInfoNetData("Sent server data notification"); diff --git a/src/core/thread/network_data.hpp b/src/core/thread/network_data.hpp index bd273dbac..2bde55049 100644 --- a/src/core/thread/network_data.hpp +++ b/src/core/thread/network_data.hpp @@ -496,7 +496,9 @@ protected: private: enum { - kDataResubmitDelay = 300000, ///< DATA_RESUBMIT_DELAY (milliseconds) + kDataResubmitDelay = 300000, ///< DATA_RESUBMIT_DELAY (milliseconds) if the device itself is the server. + kProxyResubmitDelay = 5000, ///< Resubmit delay (milliseconds) if deregister as the child server proxy. + }; class NetworkDataIterator