[cli] add commands for Border Routing counters (#8372)

This commit is contained in:
whd
2022-11-09 11:31:11 +01:00
committed by GitHub
parent 537002352f
commit 8045c829d7
6 changed files with 97 additions and 2 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ extern "C" {
* @note This number versions both OpenThread platform and user APIs.
*
*/
#define OPENTHREAD_API_VERSION (260)
#define OPENTHREAD_API_VERSION (261)
/**
* @addtogroup api-instance
+8
View File
@@ -885,6 +885,14 @@ typedef struct otBorderRoutingCounters
*/
const otBorderRoutingCounters *otIp6GetBorderRoutingCounters(otInstance *aInstance);
/**
* Resets the Border Routing counters.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
*/
void otIp6ResetBorderRoutingCounters(otInstance *aInstance);
/**
* @}
*
+11 -1
View File
@@ -834,6 +834,7 @@ Get the supported counter names.
```bash
> counters
br
ip
mac
mle
@@ -844,7 +845,10 @@ Done
Get the counter value.
Note: `OPENTHREAD_CONFIG_UPTIME_ENABLE` is required for MLE role time tracking in `counters mle`
Note:
- `OPENTHREAD_CONFIG_UPTIME_ENABLE` is required for MLE role time tracking in `counters mle`
- `OPENTHREAD_CONFIG_IP6_BR_COUNTERS_ENABLE` is required for `counters br`
```bash
> counters mac
@@ -903,6 +907,12 @@ TxFailed: 0
RxSuccess: 5
RxFailed: 0
Done
> counters br
Inbound Unicast: Packets 4 Bytes 320
Inbound Multicast: Packets 0 Bytes 0
Outbound Unicast: Packets 2 Bytes 160
Outbound Multicast: Packets 0 Bytes 0
Done
```
### counters \<countername\> reset
+66
View File
@@ -2481,10 +2481,76 @@ template <> otError Interpreter::Process<Cmd("counters")>(Arg aArgs[])
*/
if (aArgs[0].IsEmpty())
{
#if OPENTHREAD_CONFIG_IP6_BR_COUNTERS_ENABLE
OutputLine("br");
#endif
OutputLine("ip");
OutputLine("mac");
OutputLine("mle");
}
#if OPENTHREAD_CONFIG_IP6_BR_COUNTERS_ENABLE
/**
* @cli counters br
* @code
* counters br
* Inbound Unicast: Packets 4 Bytes 320
* Inbound Multicast: Packets 0 Bytes 0
* Outbound Unicast: Packets 2 Bytes 160
* Outbound Multicast: Packets 0 Bytes 0
* Done
* @endcode
* @par api_copy
* #otIp6GetBorderRoutingCounters
*/
else if (aArgs[0] == "br")
{
if (aArgs[1].IsEmpty())
{
struct BrCounterName
{
const otPacketsAndBytes otBorderRoutingCounters::*mPacketsAndBytes;
const char * mName;
};
static const BrCounterName kCounterNames[] = {
{&otBorderRoutingCounters::mInboundUnicast, "Inbound Unicast"},
{&otBorderRoutingCounters::mInboundMulticast, "Inbound Multicast"},
{&otBorderRoutingCounters::mOutboundUnicast, "Outbound Unicast"},
{&otBorderRoutingCounters::mOutboundMulticast, "Outbound Multicast"},
};
const otBorderRoutingCounters *brCounters = otIp6GetBorderRoutingCounters(GetInstancePtr());
Uint64StringBuffer uint64StringBuffer;
for (const BrCounterName &counter : kCounterNames)
{
OutputFormat("%s:", counter.mName);
OutputFormat(" Packets %s",
Uint64ToString((brCounters->*counter.mPacketsAndBytes).mPackets, uint64StringBuffer));
OutputFormat(" Bytes %s",
Uint64ToString((brCounters->*counter.mPacketsAndBytes).mBytes, uint64StringBuffer));
OutputNewLine();
}
}
/**
* @cli counters br reset
* @code
* counters br reset
* Done
* @endcode
* @par api_copy
* #otIp6ResetBorderRoutingCounters
*/
else if ((aArgs[1] == "reset") && aArgs[2].IsEmpty())
{
otIp6ResetBorderRoutingCounters(GetInstancePtr());
}
else
{
error = OT_ERROR_INVALID_ARGS;
}
}
#endif
/**
* @cli counters (mac)
* @code
+5
View File
@@ -300,4 +300,9 @@ const otBorderRoutingCounters *otIp6GetBorderRoutingCounters(otInstance *aInstan
{
return &AsCoreType(aInstance).Get<Ip6::Ip6>().GetBorderRoutingCounters();
}
void otIp6ResetBorderRoutingCounters(otInstance *aInstance)
{
AsCoreType(aInstance).Get<Ip6::Ip6>().ResetBorderRoutingCounters();
}
#endif
+6
View File
@@ -348,6 +348,12 @@ public:
*
*/
const otBorderRoutingCounters &GetBorderRoutingCounters(void) const { return mBorderRoutingCounters; }
/**
* This method resets the Border Routing counters.
*
*/
void ResetBorderRoutingCounters(void) { memset(&mBorderRoutingCounters, 0, sizeof(mBorderRoutingCounters)); }
#endif
private: