mirror of
https://github.com/espressif/openthread.git
synced 2026-08-30 13:59:54 +00:00
[cli] add commands for Border Routing counters (#8372)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user