Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mNumMessagesToAllowBeforeDropping (#21321) #21462

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions src/transport/raw/tests/NetworkTestHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class LoopbackTransportDelegate
public:
virtual ~LoopbackTransportDelegate() {}

// Called by the loopback transport when it drops a message due to a nonzero mNumMessagesToDrop.
// Called by the loopback transport when it drops one of a configurable number of messages (mDroppedMessageCount) after a
// configurable allowed number of messages (mNumMessagesToAllowBeforeDropping)
virtual void OnMessageDropped() {}
};

Expand Down Expand Up @@ -102,19 +103,30 @@ class LoopbackTransport : public Transport::Base
{
ReturnErrorOnFailure(mMessageSendError);
mSentMessageCount++;

if (mNumMessagesToDrop == 0)
bool dropMessage = false;
if (mNumMessagesToAllowBeforeDropping > 0)
{
System::PacketBufferHandle receivedMessage = msgBuf.CloneData();
mPendingMessageQueue.push(PendingMessageItem(address, std::move(receivedMessage)));
mSystemLayer->ScheduleWork(OnMessageReceived, this);
--mNumMessagesToAllowBeforeDropping;
}
else
else if (mNumMessagesToDrop > 0)
{
dropMessage = true;
--mNumMessagesToDrop;
}

if (dropMessage)
{
mNumMessagesToDrop--;
mDroppedMessageCount++;
if (mDelegate != nullptr)
{
mDelegate->OnMessageDropped();
}
}
else
{
System::PacketBufferHandle receivedMessage = msgBuf.CloneData();
mPendingMessageQueue.push(PendingMessageItem(address, std::move(receivedMessage)));
mSystemLayer->ScheduleWork(OnMessageReceived, this);
}

return CHIP_NO_ERROR;
Expand All @@ -124,10 +136,11 @@ class LoopbackTransport : public Transport::Base

void Reset()
{
mNumMessagesToDrop = 0;
mDroppedMessageCount = 0;
mSentMessageCount = 0;
mMessageSendError = CHIP_NO_ERROR;
mNumMessagesToDrop = 0;
mDroppedMessageCount = 0;
mSentMessageCount = 0;
mNumMessagesToAllowBeforeDropping = 0;
mMessageSendError = CHIP_NO_ERROR;
}

struct PendingMessageItem
Expand All @@ -143,11 +156,12 @@ class LoopbackTransport : public Transport::Base
System::Layer * mSystemLayer = nullptr;
std::queue<PendingMessageItem> mPendingMessageQueue;
Transport::PeerAddress mTxAddress;
uint32_t mNumMessagesToDrop = 0;
uint32_t mDroppedMessageCount = 0;
uint32_t mSentMessageCount = 0;
CHIP_ERROR mMessageSendError = CHIP_NO_ERROR;
LoopbackTransportDelegate * mDelegate = nullptr;
uint32_t mNumMessagesToDrop = 0;
uint32_t mDroppedMessageCount = 0;
uint32_t mSentMessageCount = 0;
uint32_t mNumMessagesToAllowBeforeDropping = 0;
CHIP_ERROR mMessageSendError = CHIP_NO_ERROR;
LoopbackTransportDelegate * mDelegate = nullptr;
};

} // namespace Test
Expand Down