From 60db56f0c056c18cfab21be8649caa86a600f30c Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Fri, 30 Jun 2023 09:53:28 -0700 Subject: [PATCH] [dataset] add build option for `GenerateLocal` (#9215) --- etc/cmake/options.cmake | 1 + src/core/config/misc.h | 12 ++++++++++++ src/core/meshcop/dataset_manager.cpp | 2 ++ src/core/meshcop/dataset_manager.hpp | 15 +++++++++++++-- src/core/meshcop/dataset_manager_ftd.cpp | 4 ++++ src/core/thread/mle_router.cpp | 4 ++++ tests/toranj/build.sh | 7 ++++--- 7 files changed, 40 insertions(+), 5 deletions(-) diff --git a/etc/cmake/options.cmake b/etc/cmake/options.cmake index be85e29d3..236a9053d 100644 --- a/etc/cmake/options.cmake +++ b/etc/cmake/options.cmake @@ -134,6 +134,7 @@ ot_option(OT_NAT64_TRANSLATOR OPENTHREAD_CONFIG_NAT64_TRANSLATOR_ENABLE "NAT64 t ot_option(OT_NEIGHBOR_DISCOVERY_AGENT OPENTHREAD_CONFIG_NEIGHBOR_DISCOVERY_AGENT_ENABLE "neighbor discovery agent") ot_option(OT_NETDATA_PUBLISHER OPENTHREAD_CONFIG_NETDATA_PUBLISHER_ENABLE "Network Data publisher") ot_option(OT_NETDIAG_CLIENT OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE "Network Diagnostic client") +ot_option(OT_OPERATIONAL_DATASET_AUTO_INIT OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT "operational dataset auto init") ot_option(OT_OTNS OPENTHREAD_CONFIG_OTNS_ENABLE "OTNS") ot_option(OT_PING_SENDER OPENTHREAD_CONFIG_PING_SENDER_ENABLE "ping sender" ${OT_APP_CLI}) ot_option(OT_PLATFORM_NETIF OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE "platform netif") diff --git a/src/core/config/misc.h b/src/core/config/misc.h index 790e7dd79..df9fd28fa 100644 --- a/src/core/config/misc.h +++ b/src/core/config/misc.h @@ -530,4 +530,16 @@ #define OPENTHREAD_CONFIG_ALLOW_EMPTY_NETWORK_NAME 0 #endif +/** + * @def OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT + * + * Define as 1 to enable support for locally initializing an Active Operational Dataset. + * + * @note This functionality is deprecated and not recommended. + * + */ +#ifndef OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT +#define OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT 0 +#endif + #endif // CONFIG_MISC_H_ diff --git a/src/core/meshcop/dataset_manager.cpp b/src/core/meshcop/dataset_manager.cpp index 7dcef3da2..b95b99ea9 100644 --- a/src/core/meshcop/dataset_manager.cpp +++ b/src/core/meshcop/dataset_manager.cpp @@ -633,6 +633,8 @@ ActiveDatasetManager::ActiveDatasetManager(Instance &aInstance) bool ActiveDatasetManager::IsPartiallyComplete(void) const { return mLocal.IsSaved() && !mTimestampValid; } +bool ActiveDatasetManager::IsComplete(void) const { return mLocal.IsSaved() && mTimestampValid; } + bool ActiveDatasetManager::IsCommissioned(void) const { Dataset::Info datasetInfo; diff --git a/src/core/meshcop/dataset_manager.hpp b/src/core/meshcop/dataset_manager.hpp index c1af58a67..6637f002c 100644 --- a/src/core/meshcop/dataset_manager.hpp +++ b/src/core/meshcop/dataset_manager.hpp @@ -382,12 +382,21 @@ public: * Is primarily used to determine whether a user has supplied a partial Active Dataset for use * with joining a network. * - * @retval TRUE if an Active Dataset is saved but does not include an Active Timestamp. - * @retval FALSE if an Active Dataset is not saved or does include an Active Timestamp. + * @retval TRUE If an Active Dataset is saved but does not include an Active Timestamp. + * @retval FALSE If an Active Dataset is not saved or does include an Active Timestamp. * */ bool IsPartiallyComplete(void) const; + /** + * Indicates whether the Active Dataset is complete. + * + * @retval TRUE If an Active Dataset is saved and includes an Active Timestamp. + * @retval FALSE If an Active Dataset is not saved or does include an Active Timestamp. + * + */ + bool IsComplete(void) const; + /** * Indicates whether or not a valid network is present in the Active Operational Dataset. * @@ -471,6 +480,7 @@ public: */ void StartLeader(void); +#if OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT /** * Generate a default Active Operational Dataset. * @@ -481,6 +491,7 @@ public: */ Error GenerateLocal(void); #endif +#endif private: template void HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo); diff --git a/src/core/meshcop/dataset_manager_ftd.cpp b/src/core/meshcop/dataset_manager_ftd.cpp index 32644e6af..0fe978d30 100644 --- a/src/core/meshcop/dataset_manager_ftd.cpp +++ b/src/core/meshcop/dataset_manager_ftd.cpp @@ -296,6 +296,7 @@ exit: return error; } +#if OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT Error ActiveDatasetManager::GenerateLocal(void) { Error error = kErrorNone; @@ -395,6 +396,9 @@ exit: } void ActiveDatasetManager::StartLeader(void) { IgnoreError(GenerateLocal()); } +#else // OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT +void ActiveDatasetManager::StartLeader(void) {} +#endif // OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT template <> void ActiveDatasetManager::HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index c79a0745e..3e63ebe1b 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -246,7 +246,11 @@ Error MleRouter::BecomeLeader(void) uint32_t partitionId; uint8_t leaderId; +#if OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT VerifyOrExit(!Get().IsPartiallyComplete(), error = kErrorInvalidState); +#else + VerifyOrExit(Get().IsComplete(), error = kErrorInvalidState); +#endif VerifyOrExit(!IsDisabled(), error = kErrorInvalidState); VerifyOrExit(!IsLeader(), error = kErrorNone); VerifyOrExit(IsRouterEligible(), error = kErrorNotCapable); diff --git a/tests/toranj/build.sh b/tests/toranj/build.sh index fb5634853..16a4535cc 100755 --- a/tests/toranj/build.sh +++ b/tests/toranj/build.sh @@ -108,6 +108,7 @@ case ${build_config} in cd "${top_builddir}" || die "cd failed" cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=OFF -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \ + -DOT_OPERATIONAL_DATASET_AUTO_INIT=ON \ -DOT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \ "${top_srcdir}" || die ninja || die @@ -120,7 +121,7 @@ case ${build_config} in cd "${top_builddir}" || die "cd failed" cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=OFF -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \ - -DOT_15_4=ON -DOT_TREL=OFF \ + -DOT_15_4=ON -DOT_TREL=OFF -DOT_OPERATIONAL_DATASET_AUTO_INIT=ON \ -DOT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \ "${top_srcdir}" || die ninja || die @@ -134,7 +135,7 @@ case ${build_config} in cd "${top_builddir}" || die "cd failed" cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=OFF -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \ - -DOT_15_4=OFF -DOT_TREL=ON \ + -DOT_15_4=OFF -DOT_TREL=ON -DOT_OPERATIONAL_DATASET_AUTO_INIT=ON \ -DOT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \ "${top_srcdir}" || die ninja || die @@ -148,7 +149,7 @@ case ${build_config} in cd "${top_builddir}" || die "cd failed" cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \ -DOT_THREAD_VERSION=1.3.1 -DOT_APP_CLI=OFF -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \ - -DOT_15_4=ON -DOT_TREL=ON \ + -DOT_15_4=ON -DOT_TREL=ON -DOT_OPERATIONAL_DATASET_AUTO_INIT=ON \ -DOT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \ "${top_srcdir}" || die ninja || die