From 0ded98b011b70cef262270f594eeded731652fc2 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Mon, 15 Jul 2019 13:44:34 -0700 Subject: [PATCH] [config] announce sender (#4020) --- .travis/script.sh | 2 +- src/core/Makefile.am | 1 + src/core/common/instance.cpp | 2 +- src/core/common/instance.hpp | 4 +- src/core/config/announce_sender.h | 83 +++++++++++++++++++ .../config/openthread-core-default-config.h | 45 ---------- src/core/openthread-core-config.h | 2 + src/core/thread/announce_sender.cpp | 4 +- src/core/thread/announce_sender.hpp | 4 +- 9 files changed, 94 insertions(+), 53 deletions(-) create mode 100644 src/core/config/announce_sender.h diff --git a/.travis/script.sh b/.travis/script.sh index 28c3cf71d..6b7e2f2c2 100755 --- a/.travis/script.sh +++ b/.travis/script.sh @@ -402,7 +402,7 @@ build_samr21() { --disable-tests || die make -j 8 || die - export CPPFLAGS="-DOPENTHREAD_CONFIG_ENABLE_TIME_SYNC=1 -DOPENTHREAD_CONFIG_ENABLE_ANNOUNCE_SENDER=1" + export CPPFLAGS="-DOPENTHREAD_CONFIG_ENABLE_TIME_SYNC=1 -DOPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE=1" git checkout -- . || die git clean -xfd || die diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 1749c87bc..6561cda8e 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -318,6 +318,7 @@ HEADERS_COMMON = \ common/timer.hpp \ common/tlvs.hpp \ common/trickle_timer.hpp \ + config/announce_sender.h \ config/openthread-core-config-check.h \ config/openthread-core-default-config.h \ crypto/aes_ccm.hpp \ diff --git a/src/core/common/instance.cpp b/src/core/common/instance.cpp index bccc8035e..e156d3807 100644 --- a/src/core/common/instance.cpp +++ b/src/core/common/instance.cpp @@ -83,7 +83,7 @@ Instance::Instance(void) #if OPENTHREAD_ENABLE_CHANNEL_MANAGER , mChannelManager(*this) #endif -#if OPENTHREAD_CONFIG_ENABLE_ANNOUNCE_SENDER +#if OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE , mAnnounceSender(*this) #endif #endif // OPENTHREAD_MTD || OPENTHREAD_FTD diff --git a/src/core/common/instance.hpp b/src/core/common/instance.hpp index 16288401a..6f9ffc00c 100644 --- a/src/core/common/instance.hpp +++ b/src/core/common/instance.hpp @@ -355,7 +355,7 @@ private: Utils::ChannelManager mChannelManager; #endif -#if OPENTHREAD_CONFIG_ENABLE_ANNOUNCE_SENDER +#if OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE AnnounceSender mAnnounceSender; #endif @@ -664,7 +664,7 @@ template <> inline MeshCoP::BorderAgent &Instance::Get(void) } #endif -#if OPENTHREAD_CONFIG_ENABLE_ANNOUNCE_SENDER +#if OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE template <> inline AnnounceSender &Instance::Get(void) { return mAnnounceSender; diff --git a/src/core/config/announce_sender.h b/src/core/config/announce_sender.h new file mode 100644 index 000000000..9b551fc17 --- /dev/null +++ b/src/core/config/announce_sender.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2019, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file includes compile-time configurations for the DNS Client. + * + */ + +#ifndef CONFIG_ANNOUNCE_SENDER_H_ +#define CONFIG_ANNOUNCE_SENDER_H_ + +/** + * @def OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE + * + * Define as 1 to enable `AnnounceSender` which will periodically send MLE Announce message on all channels. + * + * The list of channels is determined from the Operational Dataset's ChannelMask. The period intervals are determined + * by `OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_ROUTER` and `OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_REED` + * configuration options. + * + */ +#ifndef OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE +#define OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE 0 +#endif + +/** + * @def OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_ROUTER + * + * Specifies the time interval (in milliseconds) between `AnnounceSender` transmit cycles on a device in Router role. + * + * In a cycle, the `AnnounceSender` sends MLE Announcement on all channels in Active Operational Dataset's ChannelMask. + * The transmissions on different channels happen uniformly over the given interval (i.e., if there are 16 channels, + * there will be 16 MLE Announcement messages each on one channel with `interval / 16` between two consecutive MLE + * Announcement transmissions). + * + * Applicable only if `AnnounceSender` feature is enabled (see `OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE`). + * + */ +#ifndef OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_ROUTER +#define OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_ROUTER 688000 // 668 seconds = 11 min and 28 sec. +#endif + +/** + * @def OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_REED + * + * Specifies the time interval (in milliseconds) between `AnnounceSender` transmit cycles on a device in REED role. + * + * This is similar to `OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_ROUTER` but used when device is in REED role. + * + * Applicable only if `AnnounceSender` feature is enabled (see `OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE`). + * + */ +#ifndef OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_REED +#define OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_REED (668000 * 3) +#endif + +#endif // CONFIG_ANNOUNCE_SENDER_H_ diff --git a/src/core/config/openthread-core-default-config.h b/src/core/config/openthread-core-default-config.h index 59b3bb39a..93f28decb 100644 --- a/src/core/config/openthread-core-default-config.h +++ b/src/core/config/openthread-core-default-config.h @@ -1528,51 +1528,6 @@ #define OPENTHREAD_CONFIG_SEND_UNICAST_ANNOUNCE_RESPONSE 1 #endif -/** - * @def OPENTHREAD_CONFIG_ENABLE_ANNOUNCE_SENDER - * - * Define as 1 to enable `AnnounceSender` which will periodically send MLE Announce message on all channels. - * - * The list of channels is determined from the Operational Dataset's ChannelMask. The period intervals are determined - * by `OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_ROUTER` and `OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_REED` - * configuration options. - * - */ -#ifndef OPENTHREAD_CONFIG_ENABLE_ANNOUNCE_SENDER -#define OPENTHREAD_CONFIG_ENABLE_ANNOUNCE_SENDER 0 -#endif - -/** - * @def OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_ROUTER - * - * Specifies the time interval (in milliseconds) between `AnnounceSender` transmit cycles on a device in Router role. - * - * In a cycle, the `AnnounceSender` sends MLE Announcement on all channels in Active Operational Dataset's ChannelMask. - * The transmissions on different channels happen uniformly over the given interval (i.e., if there are 16 channels, - * there will be 16 MLE Announcement messages each on one channel with `interval / 16` between two consecutive MLE - * Announcement transmissions). - * - * Applicable only if `AnnounceSender` feature is enabled (see `OPENTHREAD_CONFIG_ENABLE_ANNOUNCE_SENDER`). - * - */ -#ifndef OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_ROUTER -#define OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_ROUTER 688000 // 668 seconds = 11 min and 28 sec. -#endif - -/** - * @def OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_REED - * - * Specifies the time interval (in milliseconds) between `AnnounceSender` transmit cycles on a device in REED role. - * - * This is similar to `OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_ROUTER` but used when device is in REED role. - * - * Applicable only if `AnnounceSender` feature is enabled (see `OPENTHREAD_CONFIG_ENABLE_ANNOUNCE_SENDER`). - * - */ -#ifndef OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_REED -#define OPENTHREAD_CONFIG_ANNOUNCE_SENDER_INTERVAL_REED (668000 * 3) -#endif - /** * @def OPENTHREAD_CONFIG_NCP_ENABLE_PEEK_POKE * diff --git a/src/core/openthread-core-config.h b/src/core/openthread-core-config.h index 64e63240f..981040d02 100644 --- a/src/core/openthread-core-config.h +++ b/src/core/openthread-core-config.h @@ -44,6 +44,8 @@ #include "config/openthread-core-default-config.h" +#include "config/announce_sender.h" + #if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE || OPENTHREAD_ENABLE_BORDER_AGENT || OPENTHREAD_ENABLE_COMMISSIONER || \ OPENTHREAD_ENABLE_JOINER #define OPENTHREAD_CONFIG_DTLS_ENABLE 1 diff --git a/src/core/thread/announce_sender.cpp b/src/core/thread/announce_sender.cpp index f9a6ba8be..dfbdc8ef3 100644 --- a/src/core/thread/announce_sender.cpp +++ b/src/core/thread/announce_sender.cpp @@ -110,7 +110,7 @@ exit: return; } -#if OPENTHREAD_CONFIG_ENABLE_ANNOUNCE_SENDER +#if OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE AnnounceSender::AnnounceSender(Instance &aInstance) : AnnounceSenderBase(aInstance, &AnnounceSender::HandleTimer) @@ -191,6 +191,6 @@ void AnnounceSender::HandleStateChanged(otChangedFlags aFlags) } } -#endif // OPENTHREAD_CONFIG_ENABLE_ANNOUNCE_SENDER +#endif // OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE } // namespace ot diff --git a/src/core/thread/announce_sender.hpp b/src/core/thread/announce_sender.hpp index e2f747633..7c22a4a5b 100644 --- a/src/core/thread/announce_sender.hpp +++ b/src/core/thread/announce_sender.hpp @@ -130,7 +130,7 @@ private: TimerMilli mTimer; }; -#if OPENTHREAD_CONFIG_ENABLE_ANNOUNCE_SENDER +#if OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE /** * This class implements an AnnounceSender. @@ -165,7 +165,7 @@ private: Notifier::Callback mNotifierCallback; }; -#endif // OPENTHREAD_CONFIG_ENABLE_ANNOUNCE_SENDER +#endif // OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE /** * @}