mirror of
https://github.com/espressif/openthread.git
synced 2026-08-25 19:59:51 +00:00
[mesh-forwarder] introduce FinalizeAndRemoveMessage() (#10830)
This commit adds a new helper method, `FinalizeAndRemoveMessage()`, which finalizes all direct and indirect transmissions of a message before removing it from the send queue. This helper is used by `EvictMessage()` and `RemoveDataResponseMessages()`, simplifying the code.
This commit is contained in:
@@ -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<ChildTable>().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 @@ exit:
|
||||
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;
|
||||
|
||||
@@ -530,7 +530,6 @@ private:
|
||||
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 @@ private:
|
||||
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 @@ private:
|
||||
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 @@ private:
|
||||
uint16_t aSrcRloc16,
|
||||
Message::Priority &aPriority);
|
||||
void GetForwardFramePriority(RxInfo &aRxInfo, Message::Priority &aPriority);
|
||||
|
||||
#endif
|
||||
|
||||
void PauseMessageTransmissions(void) { mTxPaused = true; }
|
||||
|
||||
@@ -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::FinalizeMessageIndirectTxs(Message &aMessage)
|
||||
{
|
||||
VerifyOrExit(!aMessage.GetIndirectTxChildMask().IsEmpty());
|
||||
|
||||
for (Child &child : Get<ChildTable>().Iterate(Child::kInStateAnyExceptInvalid))
|
||||
{
|
||||
IgnoreError(mIndirectSender.RemoveMessageFromSleepyChild(aMessage, child));
|
||||
VerifyOrExit(!aMessage.GetIndirectTxChildMask().IsEmpty());
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void MeshForwarder::RemoveDataResponseMessages(void)
|
||||
{
|
||||
Ip6::Header ip6Header;
|
||||
|
||||
for (Message &message : mSendQueue)
|
||||
{
|
||||
if (!message.IsMleCommand(Mle::kCommandDataResponse))
|
||||
if (message.IsMleCommand(Mle::kCommandDataResponse))
|
||||
{
|
||||
continue;
|
||||
FinalizeAndRemoveMessage(message, kErrorDrop, kMessageDrop);
|
||||
}
|
||||
|
||||
IgnoreError(message.Read(0, ip6Header));
|
||||
|
||||
if (!(ip6Header.GetDestination().IsMulticast()))
|
||||
{
|
||||
for (Child &child : Get<ChildTable>().Iterate(Child::kInStateAnyExceptInvalid))
|
||||
{
|
||||
IgnoreError(mIndirectSender.RemoveMessageFromSleepyChild(message, child));
|
||||
}
|
||||
}
|
||||
|
||||
LogMessage(kMessageDrop, message);
|
||||
FinalizeMessageDirectTx(message, kErrorDrop);
|
||||
RemoveMessageIfNoPendingTx(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ Error MeshForwarder::EvictMessage(Message::Priority aPriority)
|
||||
|
||||
if (message->GetPriority() < static_cast<uint8_t>(aPriority))
|
||||
{
|
||||
EvictMessage(*message);
|
||||
FinalizeAndRemoveMessage(*message, kErrorNoBufs, kMessageEvict);
|
||||
ExitNow(error = kErrorNone);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user