[mesh-diag] add API to configure response timeout (#11753)

This change introduces new APIs to allow configuration of the response
timeout for mesh diagnostic queries. A corresponding CLI command
`meshdiag responsetimeout` is also added to get or set the timeout
value.

When set, the new response timeout is used for subsequent queries and
does not affect any that are ongoing. The timeout value is clamped
between 50 milliseconds and 10 minutes to ensure it stays within a
reasonable range.
This commit is contained in:
Abtin Keshavarzian
2025-07-30 15:53:08 -07:00
committed by GitHub
parent e93d281288
commit 8bd5d73f9d
7 changed files with 109 additions and 7 deletions
+1 -1
View File
@@ -52,7 +52,7 @@ extern "C" {
* *
* @note This number versions both OpenThread platform and user APIs. * @note This number versions both OpenThread platform and user APIs.
*/ */
#define OPENTHREAD_API_VERSION (521) #define OPENTHREAD_API_VERSION (522)
/** /**
* @addtogroup api-instance * @addtogroup api-instance
+23
View File
@@ -387,6 +387,29 @@ otError otMeshDiagQueryRouterNeighborTable(otInstance
otMeshDiagQueryRouterNeighborTableCallback aCallback, otMeshDiagQueryRouterNeighborTableCallback aCallback,
void *aContext); void *aContext);
/**
* Sets the response timeout value to use for any future mesh diagnostic queries.
*
* The default response timeout value is specified by `OPENTHREAD_CONFIG_MESH_DIAG_RESPONSE_TIMEOUT` configuration.
*
* Changing the response timeout does not impact any ongoing query.
*
* The provided @p aTimeout value will be clamped to stay between 50 milliseconds and 10 minutes.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aTimeout The timeout interval in milliseconds.
*/
void otMeshDiagSetResponseTimeout(otInstance *aInstance, uint32_t aTimeout);
/**
* Gets the response timeout value.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @returns The response timeout interval in milliseconds.
*/
uint32_t otMeshDiagGetResponseTimeout(otInstance *aInstance);
/** /**
* @} * @}
*/ */
+21
View File
@@ -2594,6 +2594,27 @@ rloc16:0x7c00 ext-addr:4ed24fceec9bf6d3 ver:4
Done Done
``` ```
### meshdiag responsetimeout [\<timeout-msec\>]
Get or set the response timeout value (in milliseconds).
The default response timeout value is specified by `OPENTHREAD_CONFIG_MESH_DIAG_RESPONSE_TIMEOUT` configuration.
Changing the response timeout does not impact any ongoing query. The given timeout value will be clamped to stay between 50 milliseconds and 10 minutes.
```bash
> responsetimeout
5000
Done
> responsetimeout 7000
Done
> responsetimeout
7000
Done
```
### mliid \<iid\> ### mliid \<iid\>
Set the Mesh Local IID. Set the Mesh Local IID.
+24 -3
View File
@@ -49,6 +49,29 @@ MeshDiag::MeshDiag(otInstance *aInstance, OutputImplementer &aOutputImplementer)
{ {
} }
/** @cli responsetimeout
* @code
* responsetimeout
* 5000
* Done
* @endcode
* @par api_copy
* #otMeshDiagGetResponseTimeout
*/
template <> otError MeshDiag::Process<Cmd("responsetimeout")>(Arg aArgs[])
{
/** @cli responsetimeout (set)
* @code
* responsetimeout 7000
* Done
* @endcode
* @cparam responsetimeout @ca{timeout-msec}
* @par api_copy
* #otMeshDiagSetResponseTimeout
*/
return ProcessGetSet(aArgs, otMeshDiagGetResponseTimeout, otMeshDiagSetResponseTimeout);
}
template <> otError MeshDiag::Process<Cmd("topology")>(Arg aArgs[]) template <> otError MeshDiag::Process<Cmd("topology")>(Arg aArgs[])
{ {
/** /**
@@ -274,9 +297,7 @@ otError MeshDiag::Process(Arg aArgs[])
} }
static constexpr Command kCommands[] = { static constexpr Command kCommands[] = {
CmdEntry("childip6"), CmdEntry("childip6"), CmdEntry("childtable"), CmdEntry("responsetimeout"), CmdEntry("routerneighbortable"),
CmdEntry("childtable"),
CmdEntry("routerneighbortable"),
CmdEntry("topology"), CmdEntry("topology"),
}; };
+10
View File
@@ -84,4 +84,14 @@ otError otMeshDiagQueryRouterNeighborTable(otInstance
return AsCoreType(aInstance).Get<Utils::MeshDiag>().QueryRouterNeighborTable(aRloc16, aCallback, aContext); return AsCoreType(aInstance).Get<Utils::MeshDiag>().QueryRouterNeighborTable(aRloc16, aCallback, aContext);
} }
void otMeshDiagSetResponseTimeout(otInstance *aInstance, uint32_t aTimeout)
{
AsCoreType(aInstance).Get<Utils::MeshDiag>().SetResponseTimeout(aTimeout);
}
uint32_t otMeshDiagGetResponseTimeout(otInstance *aInstance)
{
return AsCoreType(aInstance).Get<Utils::MeshDiag>().GetResponseTimeout();
}
#endif // OPENTHREAD_CONFIG_MESH_DIAG_ENABLE && OPENTHREAD_FTD #endif // OPENTHREAD_CONFIG_MESH_DIAG_ENABLE && OPENTHREAD_FTD
+8 -2
View File
@@ -52,10 +52,16 @@ MeshDiag::MeshDiag(Instance &aInstance)
, mState(kStateIdle) , mState(kStateIdle)
, mExpectedQueryId(0) , mExpectedQueryId(0)
, mExpectedAnswerIndex(0) , mExpectedAnswerIndex(0)
, mResponseTimeout(kResponseTimeout)
, mTimer(aInstance) , mTimer(aInstance)
{ {
} }
void MeshDiag::SetResponseTimeout(uint32_t aTimeout)
{
mResponseTimeout = Clamp(aTimeout, kMinResponseTimeout, kMaxResponseTimeout);
}
Error MeshDiag::DiscoverTopology(const DiscoverConfig &aConfig, DiscoverCallback aCallback, void *aContext) Error MeshDiag::DiscoverTopology(const DiscoverConfig &aConfig, DiscoverCallback aCallback, void *aContext)
{ {
static constexpr uint8_t kMaxTlvsToRequest = 6; static constexpr uint8_t kMaxTlvsToRequest = 6;
@@ -101,7 +107,7 @@ Error MeshDiag::DiscoverTopology(const DiscoverConfig &aConfig, DiscoverCallback
mDiscover.mCallback.Set(aCallback, aContext); mDiscover.mCallback.Set(aCallback, aContext);
mState = kStateDiscoverTopology; mState = kStateDiscoverTopology;
mTimer.Start(kResponseTimeout); mTimer.Start(mResponseTimeout);
exit: exit:
return error; return error;
@@ -178,7 +184,7 @@ Error MeshDiag::SendQuery(uint16_t aRloc16, const uint8_t *aTlvs, uint8_t aTlvsL
mExpectedQueryId = Get<Client>().GetLastQueryId(); mExpectedQueryId = Get<Client>().GetLastQueryId();
mExpectedAnswerIndex = 0; mExpectedAnswerIndex = 0;
mTimer.Start(kResponseTimeout); mTimer.Start(mResponseTimeout);
exit: exit:
return error; return error;
+22 -1
View File
@@ -156,6 +156,24 @@ public:
*/ */
explicit MeshDiag(Instance &aInstance); explicit MeshDiag(Instance &aInstance);
/**
* Sets the response timeout value to use for any future queries.
*
* Changing the response timeout does not impact any ongoing query.
*
* The provided @p aTimeout value will be clamped to stay between 50 milliseconds and 10 minutes.
*
* @param[in] aTimeout The timeout interval in milliseconds.
*/
void SetResponseTimeout(uint32_t aTimeout);
/**
* Gets the response timeout value.
*
* @returns The response timeout interval in milliseconds.
*/
uint32_t GetResponseTimeout(void) const { return mResponseTimeout; }
/** /**
* Starts network topology discovery. * Starts network topology discovery.
* *
@@ -226,7 +244,9 @@ public:
private: private:
typedef ot::NetworkDiagnostic::Tlv Tlv; typedef ot::NetworkDiagnostic::Tlv Tlv;
static constexpr uint32_t kResponseTimeout = OPENTHREAD_CONFIG_MESH_DIAG_RESPONSE_TIMEOUT; static constexpr uint32_t kResponseTimeout = OPENTHREAD_CONFIG_MESH_DIAG_RESPONSE_TIMEOUT;
static constexpr uint32_t kMinResponseTimeout = 50;
static constexpr uint32_t kMaxResponseTimeout = 10 * Time::kOneMinuteInMsec;
enum State : uint8_t enum State : uint8_t
{ {
@@ -298,6 +318,7 @@ private:
State mState; State mState;
uint16_t mExpectedQueryId; uint16_t mExpectedQueryId;
uint16_t mExpectedAnswerIndex; uint16_t mExpectedAnswerIndex;
uint32_t mResponseTimeout;
TimeoutTimer mTimer; TimeoutTimer mTimer;
union union