Skip to content

Commit

Permalink
[diag] count the number of packets that are sent succeed and failed
Browse files Browse the repository at this point in the history
When using the `diag send` and `diag radio receive` commands to test the
success rate of the radio driver sending and receiving 15.4 frames, we
found that the `mStats.mSentPackets` and `mStats.mReceivedPackets`
sometimes do not match each other. It is caused by the transmision
failure and the re-transmition logic in the diag module.

This commit counts the number of packets that are sent succeed and failed,
outputs the transmision failure reason and do not re-transmit the frame
after it fails to send.
  • Loading branch information
zhanglongxia committed Jan 2, 2025
1 parent 1024a1f commit 1f13c93
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
4 changes: 4 additions & 0 deletions src/core/diags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ received packets: 10
sent packets: 10
first received packet: rssi=-65, lqi=101
last received packet: rssi=-64, lqi=98
sent success packets: 10
sent failed packets: 0
Done
```

Expand Down Expand Up @@ -420,6 +422,8 @@ received packets: 10
sent packets: 10
first received packet: rssi=-65, lqi=101
last received packet: rssi=-61, lqi=98
sent success packets: 10
sent failed packets: 0

stop diagnostics mode
Done
Expand Down
53 changes: 30 additions & 23 deletions src/core/diags/factory_diags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,16 @@ Error Diags::ProcessStart(uint8_t aArgsLength, char *aArgs[])
return error;
}

void Diags::OutputStats(void)
{
Output("received packets: %lu\r\nsent packets: %lu\r\n"
"first received packet: rssi=%d, lqi=%d\r\n"
"last received packet: rssi=%d, lqi=%d\r\n"
"sent success packets: %lu\r\nsent failed packets: %lu\r\n",
ToUlong(mStats.mReceivedPackets), ToUlong(mStats.mSentPackets), mStats.mFirstRssi, mStats.mFirstLqi,
mStats.mLastRssi, mStats.mLastLqi, ToUlong(mStats.mSentSuccessPackets), ToUlong(mStats.mSentFailedPackets));
}

Error Diags::ProcessStats(uint8_t aArgsLength, char *aArgs[])
{
Error error = kErrorNone;
Expand All @@ -504,12 +514,7 @@ Error Diags::ProcessStats(uint8_t aArgsLength, char *aArgs[])
else
{
VerifyOrExit(aArgsLength == 0, error = kErrorInvalidArgs);
Output("received packets: %d\r\nsent packets: %d\r\n"
"first received packet: rssi=%d, lqi=%d\r\n"
"last received packet: rssi=%d, lqi=%d\r\n",
static_cast<int>(mStats.mReceivedPackets), static_cast<int>(mStats.mSentPackets),
static_cast<int>(mStats.mFirstRssi), static_cast<int>(mStats.mFirstLqi),
static_cast<int>(mStats.mLastRssi), static_cast<int>(mStats.mLastLqi));
OutputStats();
}

exit:
Expand All @@ -526,13 +531,8 @@ Error Diags::ProcessStop(uint8_t aArgsLength, char *aArgs[])
Get<Radio>().SetPromiscuous(false);
Get<Mac::SubMac>().SetRxOnWhenIdle(false);

Output("received packets: %d\r\nsent packets: %d\r\n"
"first received packet: rssi=%d, lqi=%d\r\n"
"last received packet: rssi=%d, lqi=%d\r\n"
"\nstop diagnostics mode\r\n",
static_cast<int>(mStats.mReceivedPackets), static_cast<int>(mStats.mSentPackets),
static_cast<int>(mStats.mFirstRssi), static_cast<int>(mStats.mFirstLqi), static_cast<int>(mStats.mLastRssi),
static_cast<int>(mStats.mLastLqi));
OutputStats();
Output("\nstop diagnostics mode\r\n");

return kErrorNone;
}
Expand Down Expand Up @@ -846,19 +846,26 @@ void Diags::TransmitDone(Error aError)

if (aError == kErrorNone)
{
mStats.mSentPackets++;

if (mTxPackets > 1)
{
mTxPackets--;
}
else
{
ExitNow();
}
mStats.mSentSuccessPackets++;
}
else
{
mStats.mSentFailedPackets++;
Output("Failed to transmit the frame, error: %s\r\n", ErrorToString(aError));
}

mStats.mSentPackets++;
VerifyOrExit(!mRepeatActive);

if (mTxPackets > 1)
{
mTxPackets--;
}
else
{
ExitNow();
}

TransmitPacket();

exit:
Expand Down
3 changes: 3 additions & 0 deletions src/core/diags/factory_diags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class Diags : public InstanceLocator, private NonCopyable
{
uint32_t mReceivedPackets;
uint32_t mSentPackets;
uint32_t mSentSuccessPackets;
uint32_t mSentFailedPackets;
int8_t mFirstRssi;
uint8_t mFirstLqi;
int8_t mLastRssi;
Expand Down Expand Up @@ -235,6 +237,7 @@ class Diags : public InstanceLocator, private NonCopyable
void Output(const char *aFormat, ...);
void AppendErrorResult(Error aError);
void ResetTxPacket(void);
void OutputStats(void);

static bool IsChannelValid(uint8_t aChannel);

Expand Down
6 changes: 6 additions & 0 deletions tests/scripts/expect/cli-diags.exp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ expect "received packets: 0"
expect "sent packets: 10"
expect "first received packet: rssi=0, lqi=0"
expect "last received packet: rssi=0, lqi=0"
expect "sent success packets: 10"
expect "sent failed packets: 0"
expect_line "Done"

switch_node 1
Expand All @@ -80,6 +82,8 @@ expect "received packets: 10"
expect "sent packets: 0"
expect "first received packet: rssi=-20, lqi=0"
expect "last received packet: rssi=-20, lqi=0"
expect "sent success packets: 0"
expect "sent failed packets: 0"
expect_line "Done"

send "diag stats clear\n"
Expand All @@ -103,6 +107,8 @@ expect -r {received packets: \d+}
expect "sent packets: 0"
expect "first received packet: rssi=-20, lqi=0"
expect "last received packet: rssi=-20, lqi=0"
expect "sent success packets: 0"
expect "sent failed packets: 0"
expect_line "Done"

send "diag stats clear\n"
Expand Down
3 changes: 3 additions & 0 deletions tools/otci/otci/otci.py
Original file line number Diff line number Diff line change
Expand Up @@ -2613,6 +2613,9 @@ def diag_get_stats(self) -> Dict[str, int]:
result['last_received_packet_rssi'] = int(values[0])
result['last_received_packet_lqi'] = int(values[1])

result['sent_success_packets'] = int(output[4].split(":")[1])
result['sent_failed_packets'] = int(output[5].split(":")[1])

return result

def diag_stats_clear(self):
Expand Down

0 comments on commit 1f13c93

Please sign in to comment.