[telemetry] implement RA/RS counters (#8416)

This commit is contained in:
whd
2022-11-22 09:23:58 -08:00
committed by GitHub
parent a8367287a5
commit 9f702782bd
7 changed files with 53 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 (263)
#define OPENTHREAD_API_VERSION (264)
/**
* @addtogroup api-instance
+6
View File
@@ -871,6 +871,12 @@ typedef struct otBorderRoutingCounters
otPacketsAndBytes mInboundMulticast; ///< The counters for inbound multicast.
otPacketsAndBytes mOutboundUnicast; ///< The counters for outbound unicast.
otPacketsAndBytes mOutboundMulticast; ///< The counters for outbound multicast.
uint32_t mRaRx; ///< The number of received RA packets.
uint32_t mRaTxSuccess; ///< The number of RA packets successfully transmitted.
uint32_t mRaTxFailure; ///< The number of RA packets failed to transmit.
uint32_t mRsRx; ///< The number of received RS packets.
uint32_t mRsTxSuccess; ///< The number of RS packets successfully transmitted.
uint32_t mRsTxFailure; ///< The number of RS packets failed to transmit.
} otBorderRoutingCounters;
/**
+6
View File
@@ -979,6 +979,12 @@ Inbound Unicast: Packets 4 Bytes 320
Inbound Multicast: Packets 0 Bytes 0
Outbound Unicast: Packets 2 Bytes 160
Outbound Multicast: Packets 0 Bytes 0
RA Rx: 4
RA TxSuccess: 2
RA TxFailed: 0
RS Rx: 0
RS TxSuccess: 2
RS TxFailed: 0
Done
```
+13
View File
@@ -2497,6 +2497,12 @@ template <> otError Interpreter::Process<Cmd("counters")>(Arg aArgs[])
* Inbound Multicast: Packets 0 Bytes 0
* Outbound Unicast: Packets 2 Bytes 160
* Outbound Multicast: Packets 0 Bytes 0
* RA Rx: 4
* RA TxSuccess: 2
* RA TxFailed: 0
* RS Rx: 0
* RS TxSuccess: 2
* RS TxFailed: 0
* Done
* @endcode
* @par api_copy
@@ -2531,6 +2537,13 @@ template <> otError Interpreter::Process<Cmd("counters")>(Arg aArgs[])
Uint64ToString((brCounters->*counter.mPacketsAndBytes).mBytes, uint64StringBuffer));
OutputNewLine();
}
OutputLine("RA Rx: %u", brCounters->mRaRx);
OutputLine("RA TxSuccess: %u", brCounters->mRaTxSuccess);
OutputLine("RA TxFailed: %u", brCounters->mRaTxFailure);
OutputLine("RS Rx: %u", brCounters->mRsRx);
OutputLine("RS TxSuccess: %u", brCounters->mRsTxSuccess);
OutputLine("RS TxFailed: %u", brCounters->mRsTxFailure);
}
/**
* @cli counters br reset
+16 -1
View File
@@ -758,12 +758,14 @@ void RoutingManager::SendRouterAdvertisement(RouterAdvTxMode aRaTxMode)
if (error == kErrorNone)
{
mRaInfo.mLastTxTime = TimerMilli::GetNow();
Get<Ip6::Ip6>().GetBorderRoutingCounters().mRaTxSuccess++;
LogInfo("Sent Router Advertisement on %s", mInfraIf.ToString().AsCString());
DumpDebg("[BR-CERT] direction=send | type=RA |", raMsg.GetAsPacket().GetBytes(),
raMsg.GetAsPacket().GetLength());
}
else
{
Get<Ip6::Ip6>().GetBorderRoutingCounters().mRaTxFailure++;
LogWarn("Failed to send Router Advertisement on %s: %s", mInfraIf.ToString().AsCString(),
ErrorToString(error));
}
@@ -901,6 +903,7 @@ void RoutingManager::HandleRouterSolicit(const InfraIf::Icmp6Packet &aPacket, co
OT_UNUSED_VARIABLE(aPacket);
OT_UNUSED_VARIABLE(aSrcAddress);
Get<Ip6::Ip6>().GetBorderRoutingCounters().mRsRx++;
LogInfo("Received Router Solicitation from %s on %s", aSrcAddress.ToString().AsCString(),
mInfraIf.ToString().AsCString());
@@ -928,6 +931,7 @@ void RoutingManager::HandleRouterAdvertisement(const InfraIf::Icmp6Packet &aPack
VerifyOrExit(routerAdvMessage.IsValid());
Get<Ip6::Ip6>().GetBorderRoutingCounters().mRaRx++;
LogInfo("Received Router Advertisement from %s on %s", aSrcAddress.ToString().AsCString(),
mInfraIf.ToString().AsCString());
DumpDebg("[BR-CERT] direction=recv | type=RA |", aPacket.GetBytes(), aPacket.GetLength());
@@ -2882,11 +2886,22 @@ Error RoutingManager::RsSender::SendRs(void)
Ip6::Address destAddress;
Ip6::Nd::RouterSolicitMessage routerSolicit;
InfraIf::Icmp6Packet packet;
Error error;
packet.InitFrom(routerSolicit);
destAddress.SetToLinkLocalAllRoutersMulticast();
return Get<RoutingManager>().mInfraIf.Send(packet, destAddress);
error = Get<RoutingManager>().mInfraIf.Send(packet, destAddress);
if (error == kErrorNone)
{
Get<Ip6::Ip6>().GetBorderRoutingCounters().mRsTxSuccess++;
}
else
{
Get<Ip6::Ip6>().GetBorderRoutingCounters().mRsTxFailure++;
}
return error;
}
void RoutingManager::RsSender::HandleTimer(void)
+3
View File
@@ -83,6 +83,9 @@ Ip6::Ip6(Instance &aInstance)
, mTcp(aInstance)
#endif
{
#if OPENTHREAD_CONFIG_IP6_BR_COUNTERS_ENABLE
ResetBorderRoutingCounters();
#endif
}
Message *Ip6::NewMessage(uint16_t aReserved, const Message::Settings &aSettings)
+8
View File
@@ -349,6 +349,14 @@ public:
*/
const otBorderRoutingCounters &GetBorderRoutingCounters(void) const { return mBorderRoutingCounters; }
/**
* This method returns a reference to the Border Routing counters.
*
* @returns A reference to the Border Routing counters.
*
*/
otBorderRoutingCounters &GetBorderRoutingCounters(void) { return mBorderRoutingCounters; }
/**
* This method resets the Border Routing counters.
*