Skip to content

Commit

Permalink
[dataset] add build option for GenerateLocal (openthread#9215)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhui authored Jun 30, 2023
1 parent 77d1f3d commit 60db56f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions etc/cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 12 additions & 0 deletions src/core/config/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
2 changes: 2 additions & 0 deletions src/core/meshcop/dataset_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 13 additions & 2 deletions src/core/meshcop/dataset_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,21 @@ class ActiveDatasetManager : public DatasetManager, private NonCopyable
* 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.
*
Expand Down Expand Up @@ -471,6 +480,7 @@ class ActiveDatasetManager : public DatasetManager, private NonCopyable
*/
void StartLeader(void);

#if OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT
/**
* Generate a default Active Operational Dataset.
*
Expand All @@ -481,6 +491,7 @@ class ActiveDatasetManager : public DatasetManager, private NonCopyable
*/
Error GenerateLocal(void);
#endif
#endif

private:
template <Uri kUri> void HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
Expand Down
4 changes: 4 additions & 0 deletions src/core/meshcop/dataset_manager_ftd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ Error DatasetManager::DatasetTlv::ReadFromMessage(const Message &aMessage, uint1
return error;
}

#if OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT
Error ActiveDatasetManager::GenerateLocal(void)
{
Error error = kErrorNone;
Expand Down Expand Up @@ -395,6 +396,9 @@ Error ActiveDatasetManager::GenerateLocal(void)
}

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<kUriActiveSet>(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
Expand Down
4 changes: 4 additions & 0 deletions src/core/thread/mle_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,11 @@ Error MleRouter::BecomeLeader(void)
uint32_t partitionId;
uint8_t leaderId;

#if OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT
VerifyOrExit(!Get<MeshCoP::ActiveDatasetManager>().IsPartiallyComplete(), error = kErrorInvalidState);
#else
VerifyOrExit(Get<MeshCoP::ActiveDatasetManager>().IsComplete(), error = kErrorInvalidState);
#endif
VerifyOrExit(!IsDisabled(), error = kErrorInvalidState);
VerifyOrExit(!IsLeader(), error = kErrorNone);
VerifyOrExit(IsRouterEligible(), error = kErrorNotCapable);
Expand Down
7 changes: 4 additions & 3 deletions tests/toranj/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 60db56f

Please sign in to comment.