From 7d75fc62e1a8dc48031433035af496127f74d4ba Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Tue, 13 Jul 2021 15:24:47 -0700 Subject: [PATCH] [meshcop] fix issues in sending updated datasets to leader (#6813) This commit fixes a couple issues with sending MGMT_SET.req to udpate the leader with a new operational datset. - When handling an MLE Child ID Response message, DatasetManager::Save() is called before the role is updated to child. As a result, a device with a newer dataset prior to attaching the network will not send a MGMT_SET.req message. This commit adds a delay to allow the role to change to child. - When receiving a MGMT_SET.rsp, the device will immediately check if it should send a MGMT_SET.req message again. However, the operational dataset may not have had a chance to propagate from the leader. This commit adds additional delay to allow the new operational dataset to propagate. --- src/core/meshcop/dataset_manager.cpp | 9 ++++----- src/core/meshcop/dataset_manager.hpp | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/core/meshcop/dataset_manager.cpp b/src/core/meshcop/dataset_manager.cpp index 11011bc41..9dd70bc2a 100644 --- a/src/core/meshcop/dataset_manager.cpp +++ b/src/core/meshcop/dataset_manager.cpp @@ -167,8 +167,7 @@ Error DatasetManager::Save(const Dataset &aDataset) } else if (compare < 0) { - VerifyOrExit(!Get().IsLeader(), error = kErrorInvalidState); - SendSet(); + mTimer.Start(kSendSetDelay); } SignalDatasetChange(); @@ -279,7 +278,7 @@ void DatasetManager::SendSet(void) Dataset dataset(GetType()); VerifyOrExit(!mCoapPending, error = kErrorBusy); - VerifyOrExit(Get().IsAttached(), error = kErrorInvalidState); + VerifyOrExit(Get().IsChild() || Get().IsRouter(), error = kErrorInvalidState); VerifyOrExit(mLocal.Compare(GetTimestamp()) < 0, error = kErrorInvalidState); if (IsActiveDataset()) @@ -323,7 +322,7 @@ exit: break; case kErrorNoBufs: - mTimer.Start(kDelayNoBufs); + mTimer.Start(kSendSetDelay); OT_FALL_THROUGH; default: @@ -348,7 +347,7 @@ void DatasetManager::HandleCoapResponse(void * aContext, void DatasetManager::HandleCoapResponse(void) { mCoapPending = false; - SendSet(); + mTimer.Start(kSendSetDelay); } void DatasetManager::HandleGet(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) const diff --git a/src/core/meshcop/dataset_manager.hpp b/src/core/meshcop/dataset_manager.hpp index 5fbcd9446..4010068df 100644 --- a/src/core/meshcop/dataset_manager.hpp +++ b/src/core/meshcop/dataset_manager.hpp @@ -363,7 +363,7 @@ private: enum { kMaxDatasetTlvs = 16, // Maximum number of TLVs in a Dataset. - kDelayNoBufs = 1000, // Milliseconds + kSendSetDelay = 5000, // Milliseconds }; bool mCoapPending : 1;