mirror of
https://github.com/espressif/openthread.git
synced 2026-09-21 00:17:37 +00:00
[uptime] enforce UPTIME feature for MTD and FTD builds (#11354)
This commit makes `OPENTHREAD_CONFIG_UPTIME_ENABLE` mandatory for FTD and MTD builds. This requirement is now explicitly enforced in the `uptime.hpp` header file. Consequently, this configuration is only applicable for RADIO/RCP builds. This commit also removes unnecessary `#if` checks for this configuration within core modules used in MTD or FTD builds. The OpenThread API and CLI command documentation are updated accordingly.
This commit is contained in:
@@ -52,7 +52,7 @@ extern "C" {
|
||||
*
|
||||
* @note This number versions both OpenThread platform and user APIs.
|
||||
*/
|
||||
#define OPENTHREAD_API_VERSION (486)
|
||||
#define OPENTHREAD_API_VERSION (487)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
@@ -178,11 +178,6 @@ typedef struct otMleCounters
|
||||
uint16_t mBetterPartitionAttachAttempts; ///< Number of attempts to attach to a better partition.
|
||||
uint16_t mBetterParentAttachAttempts; ///< Number of attempts to attach to find a better parent (parent search).
|
||||
|
||||
/**
|
||||
* Role time tracking.
|
||||
*
|
||||
* When uptime feature is enabled (OPENTHREAD_CONFIG_UPTIME_ENABLE = 1) time spent in each MLE role is tracked.
|
||||
*/
|
||||
uint64_t mDisabledTime; ///< Number of milliseconds device has been in OT_DEVICE_ROLE_DISABLED role.
|
||||
uint64_t mDetachedTime; ///< Number of milliseconds device has been in OT_DEVICE_ROLE_DETACHED role.
|
||||
uint64_t mChildTime; ///< Number of milliseconds device has been in OT_DEVICE_ROLE_CHILD role.
|
||||
@@ -934,8 +929,6 @@ void otThreadResetMleCounters(otInstance *aInstance);
|
||||
/**
|
||||
* Gets the current attach duration (number of seconds since the device last attached).
|
||||
*
|
||||
* Requires the `OPENTHREAD_CONFIG_UPTIME_ENABLE` feature.
|
||||
*
|
||||
* If the device is not currently attached, zero will be returned.
|
||||
*
|
||||
* Unlike the role-tracking variables in `otMleCounters`, which track the cumulative time the device is in each role,
|
||||
|
||||
@@ -57,7 +57,7 @@ typedef struct
|
||||
otExtAddress mExtAddress; ///< IEEE 802.15.4 Extended Address
|
||||
uint32_t mTimeout; ///< Timeout
|
||||
uint32_t mAge; ///< Seconds since last heard
|
||||
uint64_t mConnectionTime; ///< Seconds since attach (requires `OPENTHREAD_CONFIG_UPTIME_ENABLE`)
|
||||
uint64_t mConnectionTime; ///< Seconds since attach
|
||||
uint16_t mRloc16; ///< RLOC16
|
||||
uint16_t mChildId; ///< Child ID
|
||||
uint8_t mNetworkDataVersion; ///< Network Data Version
|
||||
|
||||
@@ -143,8 +143,6 @@ Done
|
||||
|
||||
Prints the attach time (duration since device was last attached).
|
||||
|
||||
Requires `OPENTHREAD_CONFIG_UPTIME_ENABLE`.
|
||||
|
||||
Duration is formatted as `{hh}:{mm}:{ss}` for hours, minutes, and seconds if it is less than one day. If the duration is longer than one day, the format is `{dd}d.{hh}:{mm}:{ss}`.
|
||||
|
||||
```bash
|
||||
@@ -1103,7 +1101,6 @@ Get the counter value.
|
||||
|
||||
Note:
|
||||
|
||||
- `OPENTHREAD_CONFIG_UPTIME_ENABLE` is required for MLE role time tracking in `counters mle`
|
||||
- `OPENTHREAD_CONFIG_IP6_BR_COUNTERS_ENABLE` is required for `counters br`
|
||||
|
||||
```bash
|
||||
|
||||
+20
-29
@@ -410,7 +410,6 @@ otError Interpreter::SetUserCommands(const otCliCommand *aCommands, uint8_t aLen
|
||||
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
/**
|
||||
* @cli attachtime
|
||||
* @code
|
||||
@@ -419,7 +418,7 @@ otError Interpreter::SetUserCommands(const otCliCommand *aCommands, uint8_t aLen
|
||||
* Done
|
||||
* @endcode
|
||||
* @par
|
||||
* Prints the current attach time (duration since device was last attached). Requires `OPENTHREAD_CONFIG_UPTIME_ENABLE`.
|
||||
* Prints the current attach time (duration since device was last attached).
|
||||
* Duration is formatted as `{hh}:{mm}:{ss}` for hours, minutes, and seconds if it is less than one day. If the
|
||||
* duration is longer than one day, the format is `{dd}d.{hh}:{mm}:{ss}`.
|
||||
*/
|
||||
@@ -436,7 +435,6 @@ template <> otError Interpreter::Process<Cmd("attachtime")>(Arg aArgs[])
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE
|
||||
template <> otError Interpreter::Process<Cmd("history")>(Arg aArgs[]) { return mHistory.Process(aArgs); }
|
||||
@@ -2459,6 +2457,12 @@ template <> otError Interpreter::Process<Cmd("counters")>(Arg aArgs[])
|
||||
const char *mName;
|
||||
};
|
||||
|
||||
struct MleTimeCounterName
|
||||
{
|
||||
const uint64_t otMleCounters::*mValuePtr;
|
||||
const char *mName;
|
||||
};
|
||||
|
||||
static const MleCounterName kCounterNames[] = {
|
||||
{&otMleCounters::mDisabledRole, "Role Disabled"},
|
||||
{&otMleCounters::mDetachedRole, "Role Detached"},
|
||||
@@ -2472,36 +2476,27 @@ template <> otError Interpreter::Process<Cmd("counters")>(Arg aArgs[])
|
||||
{&otMleCounters::mParentChanges, "Parent Changes"},
|
||||
};
|
||||
|
||||
static const MleTimeCounterName kTimeCounterNames[] = {
|
||||
{&otMleCounters::mDisabledTime, "Disabled"}, {&otMleCounters::mDetachedTime, "Detached"},
|
||||
{&otMleCounters::mChildTime, "Child"}, {&otMleCounters::mRouterTime, "Router"},
|
||||
{&otMleCounters::mLeaderTime, "Leader"},
|
||||
};
|
||||
|
||||
const otMleCounters *mleCounters = otThreadGetMleCounters(GetInstancePtr());
|
||||
|
||||
for (const MleCounterName &counter : kCounterNames)
|
||||
{
|
||||
OutputLine("%s: %u", counter.mName, mleCounters->*counter.mValuePtr);
|
||||
}
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
|
||||
for (const MleTimeCounterName &counter : kTimeCounterNames)
|
||||
{
|
||||
struct MleTimeCounterName
|
||||
{
|
||||
const uint64_t otMleCounters::*mValuePtr;
|
||||
const char *mName;
|
||||
};
|
||||
|
||||
static const MleTimeCounterName kTimeCounterNames[] = {
|
||||
{&otMleCounters::mDisabledTime, "Disabled"}, {&otMleCounters::mDetachedTime, "Detached"},
|
||||
{&otMleCounters::mChildTime, "Child"}, {&otMleCounters::mRouterTime, "Router"},
|
||||
{&otMleCounters::mLeaderTime, "Leader"},
|
||||
};
|
||||
|
||||
for (const MleTimeCounterName &counter : kTimeCounterNames)
|
||||
{
|
||||
OutputFormat("Time %s Milli: ", counter.mName);
|
||||
OutputUint64Line(mleCounters->*counter.mValuePtr);
|
||||
}
|
||||
|
||||
OutputFormat("Time Tracked Milli: ");
|
||||
OutputUint64Line(mleCounters->mTrackedTime);
|
||||
OutputFormat("Time %s Milli: ", counter.mName);
|
||||
OutputUint64Line(mleCounters->*counter.mValuePtr);
|
||||
}
|
||||
#endif
|
||||
|
||||
OutputFormat("Time Tracked Milli: ");
|
||||
OutputUint64Line(mleCounters->mTrackedTime);
|
||||
}
|
||||
/**
|
||||
* @cli counters mle reset
|
||||
@@ -4570,7 +4565,6 @@ template <> otError Interpreter::Process<Cmd("neighbor")>(Arg aArgs[])
|
||||
OutputLine("| %5lu |", ToUlong(neighborInfo.mAge));
|
||||
}
|
||||
}
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
/**
|
||||
* @cli neighbor conntime
|
||||
* @code
|
||||
@@ -4649,7 +4643,6 @@ template <> otError Interpreter::Process<Cmd("neighbor")>(Arg aArgs[])
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
error = OT_ERROR_INVALID_ARGS;
|
||||
@@ -8149,9 +8142,7 @@ otError Interpreter::ProcessCommand(Arg aArgs[])
|
||||
|
||||
static constexpr Command kCommands[] = {
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
CmdEntry("attachtime"),
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
CmdEntry("ba"),
|
||||
#endif
|
||||
|
||||
@@ -475,12 +475,10 @@ const otMleCounters *otThreadGetMleCounters(otInstance *aInstance)
|
||||
|
||||
void otThreadResetMleCounters(otInstance *aInstance) { AsCoreType(aInstance).Get<Mle::MleRouter>().ResetCounters(); }
|
||||
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
uint32_t otThreadGetCurrentAttachDuration(otInstance *aInstance)
|
||||
{
|
||||
return AsCoreType(aInstance).Get<Mle::MleRouter>().GetCurrentAttachDuration();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_MLE_PARENT_RESPONSE_CALLBACK_API_ENABLE
|
||||
void otThreadRegisterParentResponseCallback(otInstance *aInstance,
|
||||
|
||||
@@ -46,10 +46,6 @@
|
||||
#error "OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE is required for OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE."
|
||||
#endif
|
||||
|
||||
#if !OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
#error "OPENTHREAD_CONFIG_UPTIME_ENABLE is required for OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE"
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_TRACK_PEER_BR_INFO_ENABLE && !OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE
|
||||
#error "TRACK_PEER_BR_INFO_ENABLE feature requires OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE"
|
||||
#endif
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
|
||||
#if !OPENTHREAD_CONFIG_UPTIME_ENABLE && OPENTHREAD_FTD
|
||||
#error "OPENTHREAD_CONFIG_UPTIME_ENABLE is required for FTD"
|
||||
#if (OPENTHREAD_FTD || OPENTHREAD_MTD) && !OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
#error "OPENTHREAD_CONFIG_UPTIME_ENABLE is required for FTD or MTD builds"
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
|
||||
@@ -117,6 +117,10 @@
|
||||
* @def OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
*
|
||||
* Define to 1 to enable tracking the uptime of OpenThread instance.
|
||||
*
|
||||
* On FTD/MTD builds this feature is now mandatory and MUST be enabled. This config is therefore only applicable for
|
||||
* RADIO/RCP builds.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
#define OPENTHREAD_CONFIG_UPTIME_ENABLE (OPENTHREAD_FTD || OPENTHREAD_MTD)
|
||||
|
||||
@@ -66,10 +66,6 @@ namespace MeshCoP {
|
||||
#error "Border Agent feature requires `OPENTHREAD_CONFIG_SECURE_TRANSPORT_ENABLE`"
|
||||
#endif
|
||||
|
||||
#if !OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
#error "Border Agent feature requires `OPENTHREAD_CONFIG_UPTIME_ENABLE`"
|
||||
#endif
|
||||
|
||||
class BorderAgent : public InstanceLocator, private NonCopyable
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
|
||||
@@ -68,9 +68,7 @@ void Child::Info::SetFrom(const Child &aChild)
|
||||
#else
|
||||
mIsCslSynced = false;
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
mConnectionTime = aChild.GetConnectionTime();
|
||||
#endif
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -243,9 +243,7 @@ exit:
|
||||
|
||||
const Counters &Mle::GetCounters(void)
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
UpdateRoleTimeCounters(mRole);
|
||||
#endif
|
||||
|
||||
return mCounters;
|
||||
}
|
||||
@@ -253,13 +251,9 @@ const Counters &Mle::GetCounters(void)
|
||||
void Mle::ResetCounters(void)
|
||||
{
|
||||
ClearAllBytes(mCounters);
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
mLastUpdatedTimestamp = Get<Uptime>().GetUptime();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
|
||||
uint32_t Mle::GetCurrentAttachDuration(void) const
|
||||
{
|
||||
return IsAttached() ? Uptime::MsecToSec(Get<Uptime>().GetUptime()) - mLastAttachTime : 0;
|
||||
@@ -294,8 +288,6 @@ void Mle::UpdateRoleTimeCounters(DeviceRole aRole)
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
|
||||
void Mle::SetRole(DeviceRole aRole)
|
||||
{
|
||||
DeviceRole oldRole = mRole;
|
||||
@@ -304,14 +296,12 @@ void Mle::SetRole(DeviceRole aRole)
|
||||
|
||||
LogNote("Role %s -> %s", RoleToString(oldRole), RoleToString(mRole));
|
||||
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
if ((oldRole == kRoleDetached) && IsAttached())
|
||||
{
|
||||
mLastAttachTime = Uptime::MsecToSec(Get<Uptime>().GetUptime());
|
||||
}
|
||||
|
||||
UpdateRoleTimeCounters(oldRole);
|
||||
#endif
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
|
||||
@@ -605,14 +605,12 @@ public:
|
||||
*/
|
||||
void ResetCounters(void);
|
||||
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
/**
|
||||
* Determines the current attach duration (number of seconds since the device last attached).
|
||||
*
|
||||
* @returns Current attach duration in seconds.
|
||||
*/
|
||||
uint32_t GetCurrentAttachDuration(void) const;
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_MLE_PARENT_RESPONSE_CALLBACK_API_ENABLE
|
||||
/**
|
||||
@@ -1389,9 +1387,7 @@ private:
|
||||
void InformPreviousParent(void);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
void UpdateRoleTimeCounters(DeviceRole aRole);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
ServiceAloc *FindInServiceAlocs(uint16_t aAloc16);
|
||||
@@ -1500,10 +1496,8 @@ private:
|
||||
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
|
||||
uint32_t mCslTimeout;
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
uint32_t mLastAttachTime;
|
||||
uint64_t mLastUpdatedTimestamp;
|
||||
#endif
|
||||
uint64_t mAlternateTimestamp;
|
||||
|
||||
LeaderData mLeaderData;
|
||||
|
||||
@@ -42,23 +42,19 @@ void Neighbor::SetState(State aState)
|
||||
VerifyOrExit(mState != aState);
|
||||
mState = static_cast<uint8_t>(aState);
|
||||
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
if (mState == kStateValid)
|
||||
{
|
||||
mConnectionStart = Uptime::MsecToSec(Get<Uptime>().GetUptime());
|
||||
}
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
uint32_t Neighbor::GetConnectionTime(void) const
|
||||
{
|
||||
return IsStateValid() ? Uptime::MsecToSec(Get<Uptime>().GetUptime()) - mConnectionStart : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool Neighbor::AddressMatcher::Matches(const Neighbor &aNeighbor) const
|
||||
{
|
||||
@@ -101,9 +97,7 @@ void Neighbor::Info::SetFrom(const Neighbor &aNeighbor)
|
||||
mFullThreadDevice = aNeighbor.IsFullThreadDevice();
|
||||
mFullNetworkData = (aNeighbor.GetNetworkDataType() == NetworkData::kFullSet);
|
||||
mVersion = aNeighbor.GetVersion();
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
mConnectionTime = aNeighbor.GetConnectionTime();
|
||||
#endif
|
||||
mConnectionTime = aNeighbor.GetConnectionTime();
|
||||
}
|
||||
|
||||
void Neighbor::Init(Instance &aInstance)
|
||||
|
||||
@@ -597,14 +597,12 @@ public:
|
||||
*/
|
||||
const Mle::TxChallenge &GetChallenge(void) const { return mValidPending.mPending.mChallenge; }
|
||||
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
/**
|
||||
* Returns the connection time (in seconds) of the neighbor (seconds since entering `kStateValid`).
|
||||
*
|
||||
* @returns The connection time (in seconds), zero if device is not currently in `kStateValid`.
|
||||
*/
|
||||
uint32_t GetConnectionTime(void) const;
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
/**
|
||||
@@ -762,9 +760,7 @@ private:
|
||||
// and this neighbor is the Subject.
|
||||
LinkMetrics::Metrics mEnhAckProbingMetrics;
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
uint32_t mConnectionStart;
|
||||
#endif
|
||||
};
|
||||
|
||||
DefineCoreType(otNeighborInfo, Neighbor::Info);
|
||||
|
||||
@@ -136,12 +136,8 @@
|
||||
#define OPENTHREAD_CONFIG_CLI_UART_RX_BUFFER_SIZE 640
|
||||
#endif
|
||||
|
||||
#ifndef OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
#define OPENTHREAD_CONFIG_UPTIME_ENABLE !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
|
||||
#endif
|
||||
|
||||
#ifndef OPENTHREAD_CONFIG_LOG_PREPEND_UPTIME
|
||||
#define OPENTHREAD_CONFIG_LOG_PREPEND_UPTIME 1
|
||||
#define OPENTHREAD_CONFIG_LOG_PREPEND_UPTIME !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
|
||||
#endif
|
||||
|
||||
#ifndef OPENTHREAD_CONFIG_SRP_CLIENT_BUFFERS_MAX_SERVICES
|
||||
|
||||
Reference in New Issue
Block a user