From 7d8567d57b095dd9a5788b88a8a28e7ae1ccb892 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Fri, 8 May 2020 15:20:19 -0700 Subject: [PATCH] [announce-sender] change SendAnnounce() to return void (#4941) - Move "start" log to common method. - Use default param value instead of duplicate method. --- src/core/thread/announce_begin_server.cpp | 11 +++------- src/core/thread/announce_begin_server.hpp | 12 +---------- src/core/thread/announce_sender.cpp | 25 +++++++++-------------- src/core/thread/announce_sender.hpp | 5 +---- src/core/thread/mle.cpp | 16 +++++++-------- src/core/thread/mle.hpp | 7 ++----- 6 files changed, 24 insertions(+), 52 deletions(-) diff --git a/src/core/thread/announce_begin_server.cpp b/src/core/thread/announce_begin_server.cpp index c8ce16731..fa808d35f 100644 --- a/src/core/thread/announce_begin_server.cpp +++ b/src/core/thread/announce_begin_server.cpp @@ -54,14 +54,9 @@ AnnounceBeginServer::AnnounceBeginServer(Instance &aInstance) IgnoreError(Get().AddResource(mAnnounceBegin)); } -otError AnnounceBeginServer::SendAnnounce(uint32_t aChannelMask) +void AnnounceBeginServer::SendAnnounce(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod) { - return SendAnnounce(aChannelMask, kDefaultCount, kDefaultPeriod); -} - -otError AnnounceBeginServer::SendAnnounce(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod) -{ - return AnnounceSenderBase::SendAnnounce(Mac::ChannelMask(aChannelMask), aCount, aPeriod, kDefaultJitter); + AnnounceSenderBase::SendAnnounce(Mac::ChannelMask(aChannelMask), aCount, aPeriod, kDefaultJitter); } void AnnounceBeginServer::HandleRequest(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo) @@ -83,7 +78,7 @@ void AnnounceBeginServer::HandleRequest(Coap::Message &aMessage, const Ip6::Mess SuccessOrExit(Tlv::ReadUint8Tlv(aMessage, MeshCoP::Tlv::kCount, count)); SuccessOrExit(Tlv::ReadUint16Tlv(aMessage, MeshCoP::Tlv::kPeriod, period)); - IgnoreError(SendAnnounce(mask, count, period)); + SendAnnounce(mask, count, period); if (aMessage.IsConfirmable() && !aMessageInfo.GetSockAddr().IsMulticast()) { diff --git a/src/core/thread/announce_begin_server.hpp b/src/core/thread/announce_begin_server.hpp index b862678b0..054e54af0 100644 --- a/src/core/thread/announce_begin_server.hpp +++ b/src/core/thread/announce_begin_server.hpp @@ -57,16 +57,6 @@ public: */ explicit AnnounceBeginServer(Instance &aInstance); - /** - * This method begins the MLE Announce transmission process using Count=3 and Period=1s. - * - * @param[in] aChannelMask The channels to use for transmission. - * - * @retval OT_ERROR_NONE Successfully started the transmission process. - * - */ - otError SendAnnounce(uint32_t aChannelMask); - /** * This method begins the MLE Announce transmission process. * @@ -77,7 +67,7 @@ public: * @retval OT_ERROR_NONE Successfully started the transmission process. * */ - otError SendAnnounce(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod); + void SendAnnounce(uint32_t aChannelMask, uint8_t aCount = kDefaultCount, uint16_t aPeriod = kDefaultPeriod); private: enum diff --git a/src/core/thread/announce_sender.cpp b/src/core/thread/announce_sender.cpp index d46d22436..d9c98d5f8 100644 --- a/src/core/thread/announce_sender.cpp +++ b/src/core/thread/announce_sender.cpp @@ -57,18 +57,13 @@ AnnounceSenderBase::AnnounceSenderBase(Instance &aInstance, Timer::Handler aHand { } -otError AnnounceSenderBase::SendAnnounce(Mac::ChannelMask aChannelMask, - uint8_t aCount, - uint32_t aPeriod, - uint16_t aJitter) +void AnnounceSenderBase::SendAnnounce(Mac::ChannelMask aChannelMask, uint8_t aCount, uint32_t aPeriod, uint16_t aJitter) { - otError error = OT_ERROR_NONE; - - VerifyOrExit(aPeriod != 0, error = OT_ERROR_INVALID_ARGS); - VerifyOrExit(aJitter < aPeriod, error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(aPeriod != 0, OT_NOOP); + VerifyOrExit(aJitter < aPeriod, OT_NOOP); aChannelMask.Intersect(Get().GetSupportedChannelMask()); - VerifyOrExit(!aChannelMask.IsEmpty(), error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(!aChannelMask.IsEmpty(), OT_NOOP); mChannelMask = aChannelMask; mCount = aCount; @@ -78,8 +73,11 @@ otError AnnounceSenderBase::SendAnnounce(Mac::ChannelMask aChannelMask, mTimer.Start(Random::NonCrypto::AddJitter(mPeriod, mJitter)); + otLogInfoMle("Starting periodic MLE Announcements tx, mask %s, count %u, period %u, jitter %u", + aChannelMask.ToString().AsCString(), aCount, aPeriod, aJitter); + exit: - return error; + return; } void AnnounceSenderBase::HandleTimer(void) @@ -102,7 +100,7 @@ void AnnounceSenderBase::HandleTimer(void) OT_ASSERT(error == OT_ERROR_NONE); - IgnoreError(Get().SendAnnounce(mChannel, false)); + Get().SendAnnounce(mChannel, false); mTimer.Start(Random::NonCrypto::AddJitter(mPeriod, mJitter)); @@ -165,10 +163,7 @@ void AnnounceSender::CheckState(void) VerifyOrExit(!IsRunning() || (period != GetPeriod()) || (GetChannelMask() != channelMask), OT_NOOP); - IgnoreError(SendAnnounce(channelMask, 0, period, kMaxJitter)); - - otLogInfoMle("Starting periodic MLE Announcements tx, period %u, mask %s", period, - channelMask.ToString().AsCString()); + SendAnnounce(channelMask, 0, period, kMaxJitter); exit: return; diff --git a/src/core/thread/announce_sender.hpp b/src/core/thread/announce_sender.hpp index 7c22a4a5b..419b327d8 100644 --- a/src/core/thread/announce_sender.hpp +++ b/src/core/thread/announce_sender.hpp @@ -75,11 +75,8 @@ protected: * @param[in] aPeriod The time between two successive MLE Announce transmissions (in milliseconds). * @param[in] aJitter Maximum random jitter added to @aPeriod per transmission (in milliseconds). * - * @retval OT_ERROR_NONE Successfully started the transmission process. - * @retval OT_ERROR_INVALID_ARGS @p aChanelMask is empty, or @p aPeriod is zero or smaller than @aJitter. - * */ - otError SendAnnounce(Mac::ChannelMask aChannelMask, uint8_t aCount, uint32_t aPeriod, uint16_t aJitter); + void SendAnnounce(Mac::ChannelMask aChannelMask, uint8_t aCount, uint32_t aPeriod, uint16_t aJitter); /** * This method stops the ongoing MLE Announce transmissions. diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index c21beb93a..f6aeb1de8 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -823,7 +823,7 @@ void Mle::InformPreviousChannel(void) #endif mAlternatePanId = Mac::kPanIdBroadcast; - IgnoreError(Get().SendAnnounce(1 << mAlternateChannel)); + Get().SendAnnounce(1 << mAlternateChannel); exit: return; @@ -2441,16 +2441,16 @@ exit: return error; } -otError Mle::SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce) +void Mle::SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce) { Ip6::Address destination; destination.SetToLinkLocalAllNodesMulticast(); - return SendAnnounce(aChannel, aOrphanAnnounce, destination); + SendAnnounce(aChannel, aOrphanAnnounce, destination); } -otError Mle::SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce, const Ip6::Address &aDestination) +void Mle::SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce, const Ip6::Address &aDestination) { otError error = OT_ERROR_NONE; ChannelTlv channel; @@ -2494,8 +2494,6 @@ exit: { message->Free(); } - - return error; } otError Mle::SendOrphanAnnounce(void) @@ -2510,7 +2508,7 @@ otError Mle::SendOrphanAnnounce(void) SuccessOrExit(error = channelMask.GetNextChannel(mAnnounceChannel)); - IgnoreError(SendAnnounce(mAnnounceChannel, true)); + SendAnnounce(mAnnounceChannel, true); exit: return error; @@ -3802,10 +3800,10 @@ void Mle::HandleAnnounce(const Message &aMessage, const Ip6::MessageInfo &aMessa } else if (localTimestamp->Compare(timestamp) < 0) { - IgnoreError(SendAnnounce(channel, false)); + SendAnnounce(channel, false); #if OPENTHREAD_CONFIG_MLE_SEND_UNICAST_ANNOUNCE_RESPONSE - IgnoreError(SendAnnounce(channel, false, aMessageInfo.GetPeerAddr())); + SendAnnounce(channel, false, aMessageInfo.GetPeerAddr()); #endif } else diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 37f59d0a8..f364e1357 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -421,11 +421,8 @@ public: * @param[in] aChannel The channel to use when transmitting. * @param[in] aOrphanAnnounce To indicate if MLE Announce is sent from an orphan end device. * - * @retval OT_ERROR_NONE Successfully generated an MLE Announce message. - * @retval OT_ERROR_NO_BUFS Insufficient buffers to generate the MLE Announce message. - * */ - otError SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce); + void SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce); /** * This method causes the Thread interface to detach from the Thread network. @@ -1731,7 +1728,7 @@ private: otError SendChildIdRequest(void); otError SendOrphanAnnounce(void); bool PrepareAnnounceState(void); - otError SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce, const Ip6::Address &aDestination); + void SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce, const Ip6::Address &aDestination); uint32_t Reattach(void); bool IsBetterParent(uint16_t aRloc16,