diff --git a/include/openthread.h b/include/openthread.h index ea5ec44a0..98343d9c2 100644 --- a/include/openthread.h +++ b/include/openthread.h @@ -458,13 +458,35 @@ OTAPI uint8_t OTCALL otGetChannel(otInstance *aInstance); * @param[in] aInstance A pointer to an OpenThread instance. * @param[in] aChannel The IEEE 802.15.4 channel. * - * @retval kThreadErrorNone Successfully set the channel. - * @retval kThreadErrorInvalidArgs If @p aChnanel is not in the range [11, 26]. + * @retval kThreadError_None Successfully set the channel. + * @retval kThreadError_InvalidArgs If @p aChannel is not in the range [11, 26]. * * @sa otGetChannel */ OTAPI ThreadError OTCALL otSetChannel(otInstance *aInstance, uint8_t aChannel); +/** + * Set minimal delay timer. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aDelayTimerMinimal The value of minimal delay timer (in ms). + * + * @retval kThreadError_None Successfully set minimal delay timer. + * @retval kThreadError_InvalidArgs If @p aDelayTimerMinimal is not valid. + * + */ +OTAPI ThreadError OTCALL otSetDelayTimerMinimal(otInstance *aInstance, uint32_t aDelayTimerMinimal); + +/** + * Get minimal delay timer. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @retval the value of minimal delay timer (in ms). + * + */ +OTAPI uint32_t OTCALL otGetDelayTimerMinimal(otInstance *aInstance); + /** * Get the maximum number of children currently allowed. * diff --git a/src/cli/README.md b/src/cli/README.md index 087c2fd65..4dbdd62a2 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -16,6 +16,7 @@ OpenThread test scripts use the CLI to execute test cases. * [contextreusedelay](#contextreusedelay) * [counter](#counter) * [dataset](#dataset) +* [delaytimermin](#delaytimermin) * [discover](#discover) * [eidcache](#eidcache) * [eui64](#eui64) @@ -117,6 +118,7 @@ Remove an IEEE 802.15.4 Extended Address from the blacklist. > blacklist remove 166e0a0000000002 Done ``` + ### channel Get the IEEE 802.15.4 Channel value. @@ -664,6 +666,25 @@ Set user specific data for the command. Done ``` +### delaytimermin + +Get the minimal delay timer (in seconds). + +```bash +> delaytimermin +30 +Done +``` + +### delaytimermin \ + +Set the minimal delay timer (in seconds). + +```bash +> delaytimermin 60 +Done +``` + ### discover \[channel\] Perform an MLE Discovery operation. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index fdb1e86b8..3e503e02d 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -79,6 +79,7 @@ const struct Command Interpreter::sCommands[] = { "contextreusedelay", &Interpreter::ProcessContextIdReuseDelay }, { "counter", &Interpreter::ProcessCounters }, { "dataset", &Interpreter::ProcessDataset }, + { "delaytimermin", &Interpreter::ProcessDelayTimerMin}, #if OPENTHREAD_ENABLE_DIAG { "diag", &Interpreter::ProcessDiag }, #endif @@ -568,6 +569,29 @@ void Interpreter::ProcessDataset(int argc, char *argv[]) AppendResult(error); } +void Interpreter::ProcessDelayTimerMin(int argc, char *argv[]) +{ + ThreadError error = kThreadError_None; + + if (argc == 0) + { + sServer->OutputFormat("%d\r\n", (otGetDelayTimerMinimal(mInstance) / 1000)); + } + else if (argc == 1) + { + unsigned long value; + SuccessOrExit(error = ParseUnsignedLong(argv[0], value)); + SuccessOrExit(error = otSetDelayTimerMinimal(mInstance, static_cast(value * 1000))); + } + else + { + error = kThreadError_InvalidArgs; + } + +exit: + AppendResult(error); +} + void Interpreter::ProcessDiscover(int argc, char *argv[]) { ThreadError error = kThreadError_None; diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index f09b6a1f7..cc3528a4f 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -153,6 +153,7 @@ private: void ProcessContextIdReuseDelay(int argc, char *argv[]); void ProcessCounters(int argc, char *argv[]); void ProcessDataset(int argc, char *argv[]); + void ProcessDelayTimerMin(int argc, char *argv[]); #if OPENTHREAD_ENABLE_DIAG void ProcessDiag(int argc, char *argv[]); #endif // OPENTHREAD_ENABLE_DIAG diff --git a/src/core/meshcop/dataset_manager.cpp b/src/core/meshcop/dataset_manager.cpp index 06b50882d..8c1b328aa 100644 --- a/src/core/meshcop/dataset_manager.cpp +++ b/src/core/meshcop/dataset_manager.cpp @@ -506,9 +506,9 @@ ThreadError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const { delayTimerTlv->SetDelayTimer(DelayTimerTlv::kDelayTimerDefault); } - else if (delayTimerTlv->GetDelayTimer() < DelayTimerTlv::kDelayTimerMinimal) + else if (delayTimerTlv->GetDelayTimer() < mNetif.GetLeader().GetDelayTimerMinimal()) { - delayTimerTlv->SetDelayTimer(DelayTimerTlv::kDelayTimerMinimal); + delayTimerTlv->SetDelayTimer(mNetif.GetLeader().GetDelayTimerMinimal()); } } @@ -1118,7 +1118,7 @@ void PendingDatasetBase::ApplyActiveDataset(const Timestamp &aTimestamp, Message // add delay timer tlv delayTimer.Init(); - delayTimer.SetDelayTimer(DelayTimerTlv::kDelayTimerMinimal); + delayTimer.SetDelayTimer(mNetif.GetLeader().GetDelayTimerMinimal()); mNetwork.Set(delayTimer); // add pending timestamp tlv diff --git a/src/core/meshcop/leader.cpp b/src/core/meshcop/leader.cpp index bd84c7722..fcb3c135e 100644 --- a/src/core/meshcop/leader.cpp +++ b/src/core/meshcop/leader.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,7 @@ Leader::Leader(ThreadNetif &aThreadNetif): mPetition(OPENTHREAD_URI_LEADER_PETITION, Leader::HandlePetition, this), mKeepAlive(OPENTHREAD_URI_LEADER_KEEP_ALIVE, Leader::HandleKeepAlive, this), mTimer(aThreadNetif.GetIp6().mTimerScheduler, HandleTimer, this), + mDelayTimerMinimal(DelayTimerTlv::kDelayTimerMinimal), mSessionId(0xffff), mNetif(aThreadNetif) { @@ -254,6 +256,22 @@ exit: return error; } +ThreadError Leader::SetDelayTimerMinimal(uint32_t aDelayTimerMinimal) +{ + ThreadError error = kThreadError_None; + VerifyOrExit((aDelayTimerMinimal != 0 && aDelayTimerMinimal < DelayTimerTlv::kDelayTimerDefault), + error = kThreadError_InvalidArgs); + mDelayTimerMinimal = aDelayTimerMinimal; + +exit: + return error; +} + +uint32_t Leader::GetDelayTimerMinimal(void) const +{ + return mDelayTimerMinimal; +} + void Leader::HandleTimer(void *aContext) { static_cast(aContext)->HandleTimer(); diff --git a/src/core/meshcop/leader_ftd.hpp b/src/core/meshcop/leader_ftd.hpp index 1c9d3b366..d628b313d 100644 --- a/src/core/meshcop/leader_ftd.hpp +++ b/src/core/meshcop/leader_ftd.hpp @@ -81,6 +81,25 @@ public: */ ThreadError SendDatasetChanged(const Ip6::Address &aAddress); + /** + * This method sets minimal delay timer. + * + * @param[in] aDelayTimerMinimal The value of minimal delay timer (in ms). + * + * @retval kThreadError_None Successfully set the minimal delay timer. + * @retval kThreadError_InvalidArgs If @p aDelayTimerMinimal is not valid. + * + */ + ThreadError SetDelayTimerMinimal(uint32_t aDelayTimerMinimal); + + /** + * This method gets minimal delay timer. + * + * @retval the miniaml delay timer (in ms). + * + */ + uint32_t GetDelayTimerMinimal(void) const; + private: enum { @@ -110,6 +129,8 @@ private: Coap::Resource mKeepAlive; Timer mTimer; + uint32_t mDelayTimerMinimal; + CommissionerIdTlv mCommissionerId; uint16_t mSessionId; ThreadNetif &mNetif; diff --git a/src/core/meshcop/leader_mtd.hpp b/src/core/meshcop/leader_mtd.hpp index 5fa2b3178..9552f2486 100644 --- a/src/core/meshcop/leader_mtd.hpp +++ b/src/core/meshcop/leader_mtd.hpp @@ -44,6 +44,8 @@ class Leader public: Leader(ThreadNetif &) { } ThreadError SendDatasetChanged(const Ip6::Address &) { return kThreadError_NotImplemented; } + ThreadError SetDelayTimerMinimal(uint32_t) { return kThreadError_NotImplemented; } + uint32_t GetDelayTimerMinimal(void) { return 0; } }; } // namespace MeshCoP diff --git a/src/core/openthread.cpp b/src/core/openthread.cpp index 6fec3bd06..a637f6c5e 100644 --- a/src/core/openthread.cpp +++ b/src/core/openthread.cpp @@ -120,6 +120,16 @@ ThreadError otSetChannel(otInstance *aInstance, uint8_t aChannel) return aInstance->mThreadNetif.GetMac().SetChannel(aChannel); } +ThreadError otSetDelayTimerMinimal(otInstance *aInstance, uint32_t aDelayTimerMinimal) +{ + return aInstance->mThreadNetif.GetLeader().SetDelayTimerMinimal(aDelayTimerMinimal); +} + +uint32_t otGetDelayTimerMinimal(otInstance *aInstance) +{ + return aInstance->mThreadNetif.GetLeader().GetDelayTimerMinimal(); +} + uint8_t otGetMaxAllowedChildren(otInstance *aInstance) { uint8_t aNumChildren; diff --git a/tools/harness-thci/OpenThread.py b/tools/harness-thci/OpenThread.py index 73ad4a815..9a6904ea9 100644 --- a/tools/harness-thci/OpenThread.py +++ b/tools/harness-thci/OpenThread.py @@ -2534,3 +2534,6 @@ class OpenThread(IThci): def setMinDelayTimer(self, iSeconds): print '%s call setMinDelayTimer' % self.port + cmd = 'delaytimermin %s' % iSeconds + print cmd + return self.__sendCommand(cmd)[0] == 'Done'