From b9a318092c06244ac8254ca32c31f2f46e01edd7 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 2 May 2023 12:05:17 -0700 Subject: [PATCH] [mle] fix how time per role is tracked after counters are reset (#9011) This commit fixes an issue with tracking time spent in each role after `Mle::ResetCounters()`. The `mLastUpdatedTimestamp` is now updated from `ResetCounters()`. --- src/core/thread/mle.cpp | 8 ++++++++ src/core/thread/mle.hpp | 7 ++++--- src/core/thread/mle_types.hpp | 6 ++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 9ff77af46..4fad3a71c 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -259,6 +259,14 @@ exit: } } +void Mle::ResetCounters(void) +{ + memset(&mCounters, 0, sizeof(mCounters)); +#if OPENTHREAD_CONFIG_UPTIME_ENABLE + mLastUpdatedTimestamp = Get().GetUptime(); +#endif +} + #if OPENTHREAD_CONFIG_UPTIME_ENABLE void Mle::UpdateRoleTimeCounters(DeviceRole aRole) { diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index aa011e515..517ab094b 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -610,7 +610,7 @@ public: * @returns A reference to the MLE counters. * */ - const otMleCounters &GetCounters(void) + const Counters &GetCounters(void) { #if OPENTHREAD_CONFIG_UPTIME_ENABLE UpdateRoleTimeCounters(mRole); @@ -622,7 +622,7 @@ public: * This method resets the MLE counters. * */ - void ResetCounters(void) { memset(&mCounters, 0, sizeof(mCounters)); } + void ResetCounters(void); #if OPENTHREAD_CONFIG_MLE_PARENT_RESPONSE_CALLBACK_API_ENABLE /** @@ -2122,10 +2122,11 @@ private: ServiceAloc mServiceAlocs[kMaxServiceAlocs]; #endif - otMleCounters mCounters; + Counters mCounters; #if OPENTHREAD_CONFIG_UPTIME_ENABLE uint64_t mLastUpdatedTimestamp; #endif + static const otMeshLocalPrefix sMeshLocalPrefixInit; Ip6::Netif::UnicastAddress mLinkLocal64; diff --git a/src/core/thread/mle_types.hpp b/src/core/thread/mle_types.hpp index b4543970d..286e63ae6 100644 --- a/src/core/thread/mle_types.hpp +++ b/src/core/thread/mle_types.hpp @@ -646,6 +646,12 @@ typedef Mac::KeyMaterial KeyMaterial; */ typedef Mac::Key Key; +/** + * This structure represents the Thread MLE counters. + * + */ +typedef otMleCounters Counters; + /** * This function derives the Child ID from a given RLOC16. *