diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 8a5c40c9f..7db5df0df 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -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 diff --git a/include/openthread/ip6.h b/include/openthread/ip6.h index 078b189a8..ca15f1e8c 100644 --- a/include/openthread/ip6.h +++ b/include/openthread/ip6.h @@ -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; /** diff --git a/src/cli/README.md b/src/cli/README.md index a6e9d7fce..e616de7c2 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -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 ``` diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 4e1392d78..9a670f4a3 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -2497,6 +2497,12 @@ template <> otError Interpreter::Process(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(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 diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index 5c12bea57..80aeac3fa 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -758,12 +758,14 @@ void RoutingManager::SendRouterAdvertisement(RouterAdvTxMode aRaTxMode) if (error == kErrorNone) { mRaInfo.mLastTxTime = TimerMilli::GetNow(); + Get().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().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().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().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().mInfraIf.Send(packet, destAddress); + error = Get().mInfraIf.Send(packet, destAddress); + + if (error == kErrorNone) + { + Get().GetBorderRoutingCounters().mRsTxSuccess++; + } + else + { + Get().GetBorderRoutingCounters().mRsTxFailure++; + } + return error; } void RoutingManager::RsSender::HandleTimer(void) diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 3071236a9..e6e011712 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -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) diff --git a/src/core/net/ip6.hpp b/src/core/net/ip6.hpp index 24e4c4b21..94449d26b 100644 --- a/src/core/net/ip6.hpp +++ b/src/core/net/ip6.hpp @@ -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. *