diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index 1cd1881955c..d2395d3e7e9 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -184,32 +184,6 @@ void MeshForwarder::PrepareEmptyFrame(Mac::TxFrame &aFrame, const Mac::Address & aFrame.SetPayloadLength(0); } -void MeshForwarder::EvictMessage(Message &aMessage) -{ - PriorityQueue *queue = aMessage.GetPriorityQueue(); - - OT_ASSERT(queue != nullptr); - - LogMessage(kMessageEvict, aMessage, kErrorNoBufs); - - if (queue == &mSendQueue) - { -#if OPENTHREAD_FTD - for (Child &child : Get().Iterate(Child::kInStateAnyExceptInvalid)) - { - IgnoreError(mIndirectSender.RemoveMessageFromSleepyChild(aMessage, child)); - } -#endif - - FinalizeMessageDirectTx(aMessage, kErrorNoBufs); - RemoveMessageIfNoPendingTx(aMessage); - } - else - { - queue->DequeueAndFree(aMessage); - } -} - void MeshForwarder::ResumeMessageTransmissions(void) { if (mTxPaused) @@ -1361,6 +1335,18 @@ void MeshForwarder::FinalizeMessageDirectTx(Message &aMessage, Error aError) return; } +void MeshForwarder::FinalizeAndRemoveMessage(Message &aMessage, Error aError, MessageAction aAction) +{ + LogMessage(aAction, aMessage, aError); + +#if OPENTHREAD_FTD + FinalizeMessageIndirectTxs(aMessage); +#endif + + FinalizeMessageDirectTx(aMessage, aError); + RemoveMessageIfNoPendingTx(aMessage); +} + bool MeshForwarder::RemoveMessageIfNoPendingTx(Message &aMessage) { bool didRemove = false; diff --git a/src/core/thread/mesh_forwarder.hpp b/src/core/thread/mesh_forwarder.hpp index 932da99a968..1714bba1ad6 100644 --- a/src/core/thread/mesh_forwarder.hpp +++ b/src/core/thread/mesh_forwarder.hpp @@ -530,7 +530,6 @@ class MeshForwarder : public InstanceLocator, private NonCopyable Message::Priority aPriority); Error HandleDatagram(Message &aMessage, const Mac::Address &aMacSource); void ClearReassemblyList(void); - void EvictMessage(Message &aMessage); void HandleDiscoverComplete(void); void HandleReceivedFrame(Mac::RxFrame &aFrame); @@ -543,6 +542,7 @@ class MeshForwarder : public InstanceLocator, private NonCopyable void HandleSentFrame(Mac::TxFrame &aFrame, Error aError); void UpdateSendMessage(Error aFrameTxError, Mac::Address &aMacDest, Neighbor *aNeighbor); void FinalizeMessageDirectTx(Message &aMessage, Error aError); + void FinalizeAndRemoveMessage(Message &aMessage, Error aError, MessageAction aAction); bool RemoveMessageIfNoPendingTx(Message &aMessage); void HandleTimeTick(void); @@ -551,6 +551,7 @@ class MeshForwarder : public InstanceLocator, private NonCopyable Error GetFramePriority(RxInfo &aRxInfo, Message::Priority &aPriority); #if OPENTHREAD_FTD + void FinalizeMessageIndirectTxs(Message &aMessage); FwdFrameInfo *FindFwdFrameInfoEntry(uint16_t aSrcRloc16, uint16_t aDatagramTag); bool UpdateFwdFrameInfoArrayOnTimeTick(void); @@ -558,6 +559,7 @@ class MeshForwarder : public InstanceLocator, private NonCopyable uint16_t aSrcRloc16, Message::Priority &aPriority); void GetForwardFramePriority(RxInfo &aRxInfo, Message::Priority &aPriority); + #endif void PauseMessageTransmissions(void) { mTxPaused = true; } diff --git a/src/core/thread/mesh_forwarder_ftd.cpp b/src/core/thread/mesh_forwarder_ftd.cpp index be9ce015cf6..270a41b3074 100644 --- a/src/core/thread/mesh_forwarder_ftd.cpp +++ b/src/core/thread/mesh_forwarder_ftd.cpp @@ -255,7 +255,7 @@ Error MeshForwarder::EvictMessage(Message::Priority aPriority) exit: if ((error == kErrorNone) && (evict != nullptr)) { - EvictMessage(*evict); + FinalizeAndRemoveMessage(*evict, kErrorNoBufs, kMessageEvict); } return error; @@ -299,30 +299,28 @@ void MeshForwarder::RemoveMessagesForChild(Child &aChild, MessageChecker &aMessa } } -void MeshForwarder::RemoveDataResponseMessages(void) +void MeshForwarder::FinalizeMessageIndirectTxs(Message &aMessage) { - Ip6::Header ip6Header; + VerifyOrExit(!aMessage.GetIndirectTxChildMask().IsEmpty()); - for (Message &message : mSendQueue) + for (Child &child : Get().Iterate(Child::kInStateAnyExceptInvalid)) { - if (!message.IsMleCommand(Mle::kCommandDataResponse)) - { - continue; - } + IgnoreError(mIndirectSender.RemoveMessageFromSleepyChild(aMessage, child)); + VerifyOrExit(!aMessage.GetIndirectTxChildMask().IsEmpty()); + } - IgnoreError(message.Read(0, ip6Header)); +exit: + return; +} - if (!(ip6Header.GetDestination().IsMulticast())) +void MeshForwarder::RemoveDataResponseMessages(void) +{ + for (Message &message : mSendQueue) + { + if (message.IsMleCommand(Mle::kCommandDataResponse)) { - for (Child &child : Get().Iterate(Child::kInStateAnyExceptInvalid)) - { - IgnoreError(mIndirectSender.RemoveMessageFromSleepyChild(message, child)); - } + FinalizeAndRemoveMessage(message, kErrorDrop, kMessageDrop); } - - LogMessage(kMessageDrop, message); - FinalizeMessageDirectTx(message, kErrorDrop); - RemoveMessageIfNoPendingTx(message); } } diff --git a/src/core/thread/mesh_forwarder_mtd.cpp b/src/core/thread/mesh_forwarder_mtd.cpp index 2bdca2b044f..9dec26b43b8 100644 --- a/src/core/thread/mesh_forwarder_mtd.cpp +++ b/src/core/thread/mesh_forwarder_mtd.cpp @@ -68,7 +68,7 @@ Error MeshForwarder::EvictMessage(Message::Priority aPriority) if (message->GetPriority() < static_cast(aPriority)) { - EvictMessage(*message); + FinalizeAndRemoveMessage(*message, kErrorNoBufs, kMessageEvict); ExitNow(error = kErrorNone); }