[telemetry] add api for DHCPv6 PD telemetry (#9645)

This commit is contained in:
SherySheng
2023-12-04 14:42:51 -08:00
committed by GitHub
parent e76ddf1050
commit 19af7118b0
7 changed files with 100 additions and 5 deletions
+26
View File
@@ -118,6 +118,17 @@ typedef struct otBorderRoutingPrefixTableEntry
uint32_t mPreferredLifetime; ///< Preferred lifetime of the on-link prefix when `mIsOnLink`.
} otBorderRoutingPrefixTableEntry;
/**
* Represents a group of data of platform-generated RA messages processed.
*
*/
typedef struct otPdProcessedRaInfo
{
uint32_t mNumPlatformRaReceived; ///< The number of platform generated RA handled by ProcessPlatfromGeneratedRa.
uint32_t mNumPlatformPioProcessed; ///< The number of PIO processed for adding OMR prefixes.
uint32_t mLastPlatformRaMsec; ///< The timestamp of last processed RA message.
} otPdProcessedRaInfo;
/**
* Represents the state of Border Routing Manager.
*
@@ -307,6 +318,21 @@ otError otBorderRoutingGetOmrPrefix(otInstance *aInstance, otIp6Prefix *aPrefix)
*/
otError otBorderRoutingGetPdOmrPrefix(otInstance *aInstance, otBorderRoutingPrefixTableEntry *aPrefixInfo);
/**
* Gets the data of platform generated RA message processed..
*
* `OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_ENABLE` must be enabled.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[out] aPrefixInfo A pointer to where the prefix info will be output to.
*
* @retval OT_ERROR_NONE Successfully retrieved the Info.
* @retval OT_ERROR_INVALID_STATE The Border Routing Manager is not initialized yet.
* @retval OT_ERROR_NOT_FOUND There are no valid Info on this BR.
*
*/
otError otBorderRoutingGetPdProcessedRaInfo(otInstance *aInstance, otPdProcessedRaInfo *aPdProcessedRaInfo);
/**
* Gets the currently favored Off-Mesh-Routable (OMR) Prefix.
*
+1 -1
View File
@@ -53,7 +53,7 @@ extern "C" {
* @note This number versions both OpenThread platform and user APIs.
*
*/
#define OPENTHREAD_API_VERSION (382)
#define OPENTHREAD_API_VERSION (383)
/**
* @addtogroup api-instance
+2
View File
@@ -907,6 +907,8 @@ typedef struct otBorderRoutingCounters
otPacketsAndBytes mInboundMulticast; ///< The counters for inbound multicast.
otPacketsAndBytes mOutboundUnicast; ///< The counters for outbound unicast.
otPacketsAndBytes mOutboundMulticast; ///< The counters for outbound multicast.
otPacketsAndBytes mInboundInternet; ///< The counters for inbound Internet when DHCPv6 PD enabled.
otPacketsAndBytes mOutboundInternet; ///< The counters for outbound Internet when DHCPv6 PD enabled.
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.
+7
View File
@@ -104,6 +104,13 @@ otError otBorderRoutingGetPdOmrPrefix(otInstance *aInstance, otBorderRoutingPref
return AsCoreType(aInstance).Get<BorderRouter::RoutingManager>().GetPdOmrPrefix(*aPrefixInfo);
}
otError otBorderRoutingGetPdProcessedRaInfo(otInstance *aInstance, otPdProcessedRaInfo *aPdProcessedRaInfo)
{
AssertPointerIsNotNull(aPdProcessedRaInfo);
return AsCoreType(aInstance).Get<BorderRouter::RoutingManager>().GetPdProcessedRaInfo(*aPdProcessedRaInfo);
}
#endif
otError otBorderRoutingGetFavoredOmrPrefix(otInstance *aInstance, otIp6Prefix *aPrefix, otRoutePreference *aPreference)
+31 -1
View File
@@ -211,6 +211,17 @@ Error RoutingManager::GetPdOmrPrefix(PrefixTableEntry &aPrefixInfo) const
VerifyOrExit(IsInitialized(), error = kErrorInvalidState);
error = mPdPrefixManager.GetPrefixInfo(aPrefixInfo);
exit:
return error;
}
Error RoutingManager::GetPdProcessedRaInfo(PdProcessedRaInfo &aPdProcessedRaInfo)
{
Error error = kErrorNone;
VerifyOrExit(IsInitialized(), error = kErrorInvalidState);
error = mPdPrefixManager.GetProcessedRaInfo(aPdProcessedRaInfo);
exit:
return error;
}
@@ -3453,6 +3464,9 @@ RoutingManager::PdPrefixManager::PdPrefixManager(Instance &aInstance)
: InstanceLocator(aInstance)
, mEnabled(false)
, mIsRunning(false)
, mNumPlatformPioProcessed(0)
, mNumPlatformRaReceived(0)
, mLastPlatformRaTime(0)
, mTimer(aInstance)
{
mPrefix.Clear();
@@ -3519,6 +3533,20 @@ exit:
return error;
}
Error RoutingManager::PdPrefixManager::GetProcessedRaInfo(PdProcessedRaInfo &aPdProcessedRaInfo) const
{
Error error = kErrorNone;
VerifyOrExit(IsRunning() && HasPrefix(), error = kErrorNotFound);
aPdProcessedRaInfo.mNumPlatformRaReceived = mNumPlatformRaReceived;
aPdProcessedRaInfo.mNumPlatformPioProcessed = mNumPlatformPioProcessed;
aPdProcessedRaInfo.mLastPlatformRaMsec = TimerMilli::GetNow() - mLastPlatformRaTime;
exit:
return error;
}
void RoutingManager::PdPrefixManager::WithdrawPrefix(void)
{
VerifyOrExit(HasPrefix());
@@ -3542,6 +3570,8 @@ void RoutingManager::PdPrefixManager::ProcessPlatformGeneratedRa(const uint8_t *
VerifyOrExit(IsRunning(), LogWarn("Ignore platform generated RA since PD is disabled or not running."));
packet.Init(aRouterAdvert, aLength);
error = Process(Ip6::Nd::RouterAdvertMessage(packet));
mNumPlatformRaReceived++;
mLastPlatformRaTime = TimerMilli::GetNow();
exit:
if (error != kErrorNone)
@@ -3568,7 +3598,7 @@ Error RoutingManager::PdPrefixManager::Process(const Ip6::Nd::RouterAdvertMessag
{
continue;
}
mNumPlatformPioProcessed++;
entry.SetFrom(static_cast<const Ip6::Nd::PrefixInfoOption &>(option));
if (!IsValidPdPrefix(entry.GetPrefix()))
@@ -88,6 +88,7 @@ public:
typedef otBorderRoutingPrefixTableIterator PrefixTableIterator; ///< Prefix Table Iterator.
typedef otBorderRoutingPrefixTableEntry PrefixTableEntry; ///< Prefix Table Entry.
typedef otBorderRoutingRouterEntry RouterEntry; ///< Router Entry.
typedef otPdProcessedRaInfo PdProcessedRaInfo; ///< Data of PdProcessedRaInfo.
/**
* This constant specifies the maximum number of route prefixes that may be published by `RoutingManager`
@@ -292,6 +293,18 @@ public:
*
*/
Error GetPdOmrPrefix(PrefixTableEntry &aPrefixInfo) const;
/**
* Returns platform generated RA message processed information.
*
* @param[out] aPdProcessedRaInfo A reference to where the PD processed RA info will be output to.
*
* @retval kErrorNone Successfully retrieved the Info.
* @retval kErrorNotFound There are no valid RA process info on this BR.
* @retval kErrorInvalidState The Border Routing Manager is not initialized yet.
*
*/
Error GetPdProcessedRaInfo(PdProcessedRaInfo &aPdProcessedRaInfo);
#endif
/**
@@ -1178,6 +1191,7 @@ private:
void ProcessPlatformGeneratedRa(const uint8_t *aRouterAdvert, uint16_t aLength);
Error GetPrefixInfo(PrefixTableEntry &aInfo) const;
Error GetProcessedRaInfo(PdProcessedRaInfo &aPdProcessedRaInfo) const;
void HandleTimer(void) { WithdrawPrefix(); }
static const char *StateToString(Dhcp6PdState aState);
@@ -1199,6 +1213,9 @@ private:
bool mEnabled;
bool mIsRunning;
uint32_t mNumPlatformPioProcessed;
uint32_t mNumPlatformRaReceived;
TimeMilli mLastPlatformRaTime;
PlatformOmrPrefixTimer mTimer;
DiscoveredPrefixTable::Entry mPrefix;
};
+16 -3
View File
@@ -1456,7 +1456,9 @@ Error Ip6::RouteLookup(const Address &aSource, const Address &aDestination) cons
#if OPENTHREAD_CONFIG_IP6_BR_COUNTERS_ENABLE
void Ip6::UpdateBorderRoutingCounters(const Header &aHeader, uint16_t aMessageLength, bool aIsInbound)
{
otPacketsAndBytes *counter = nullptr;
static constexpr uint8_t kPrefixLength = 48;
otPacketsAndBytes *counter = nullptr;
otPacketsAndBytes *internetCounter = nullptr;
VerifyOrExit(!aHeader.GetSource().IsLinkLocal());
VerifyOrExit(!aHeader.GetDestination().IsLinkLocal());
@@ -1466,7 +1468,10 @@ void Ip6::UpdateBorderRoutingCounters(const Header &aHeader, uint16_t aMessageLe
if (aIsInbound)
{
VerifyOrExit(!Get<Netif>().HasUnicastAddress(aHeader.GetSource()));
if (!aHeader.GetSource().MatchesPrefix(aHeader.GetDestination().GetPrefix().m8, kPrefixLength))
{
internetCounter = &mBorderRoutingCounters.mInboundInternet;
}
if (aHeader.GetDestination().IsMulticast())
{
VerifyOrExit(aHeader.GetDestination().IsMulticastLargerThanRealmLocal());
@@ -1480,7 +1485,10 @@ void Ip6::UpdateBorderRoutingCounters(const Header &aHeader, uint16_t aMessageLe
else
{
VerifyOrExit(!Get<Netif>().HasUnicastAddress(aHeader.GetDestination()));
if (!aHeader.GetSource().MatchesPrefix(aHeader.GetDestination().GetPrefix().m8, kPrefixLength))
{
internetCounter = &mBorderRoutingCounters.mOutboundInternet;
}
if (aHeader.GetDestination().IsMulticast())
{
VerifyOrExit(aHeader.GetDestination().IsMulticastLargerThanRealmLocal());
@@ -1499,6 +1507,11 @@ exit:
counter->mPackets += 1;
counter->mBytes += aMessageLength;
}
if (internetCounter)
{
internetCounter->mPackets += 1;
internetCounter->mBytes += aMessageLength;
}
}
#endif