Skip to content

Commit

Permalink
[telemetry] add api for DHCPv6 PD telemetry (openthread#9645)
Browse files Browse the repository at this point in the history
  • Loading branch information
sherysheng authored Dec 4, 2023
1 parent e76ddf1 commit 19af711
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 5 deletions.
26 changes: 26 additions & 0 deletions include/openthread/border_routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion include/openthread/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions include/openthread/ip6.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/core/api/border_routing_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 31 additions & 1 deletion src/core/border_router/routing_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -3519,6 +3533,20 @@ Error RoutingManager::PdPrefixManager::GetPrefixInfo(PrefixTableEntry &aInfo) co
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());
Expand All @@ -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)
Expand All @@ -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()))
Expand Down
17 changes: 17 additions & 0 deletions src/core/border_router/routing_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class RoutingManager : public InstanceLocator
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`
Expand Down Expand Up @@ -292,6 +293,18 @@ class RoutingManager : public InstanceLocator
*
*/
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

/**
Expand Down Expand Up @@ -1178,6 +1191,7 @@ class RoutingManager : public InstanceLocator

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);
Expand All @@ -1199,6 +1213,9 @@ class RoutingManager : public InstanceLocator

bool mEnabled;
bool mIsRunning;
uint32_t mNumPlatformPioProcessed;
uint32_t mNumPlatformRaReceived;
TimeMilli mLastPlatformRaTime;
PlatformOmrPrefixTimer mTimer;
DiscoveredPrefixTable::Entry mPrefix;
};
Expand Down
19 changes: 16 additions & 3 deletions src/core/net/ip6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -1499,6 +1507,11 @@ void Ip6::UpdateBorderRoutingCounters(const Header &aHeader, uint16_t aMessageLe
counter->mPackets += 1;
counter->mBytes += aMessageLength;
}
if (internetCounter)
{
internetCounter->mPackets += 1;
internetCounter->mBytes += aMessageLength;
}
}
#endif

Expand Down

0 comments on commit 19af711

Please sign in to comment.