Skip to content

Commit

Permalink
[link-metrics] add cli command to show link metrics manager state (op…
Browse files Browse the repository at this point in the history
  • Loading branch information
Irving-cl authored Apr 25, 2024
1 parent 9a9853b commit 93f3113
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 5 deletions.
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 (408)
#define OPENTHREAD_API_VERSION (409)

/**
* @addtogroup api-instance
Expand Down
11 changes: 11 additions & 0 deletions include/openthread/link_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,17 @@ otError otLinkMetricsSendLinkProbe(otInstance *aInstance,
uint8_t aSeriesId,
uint8_t aLength);

/**
* If Link Metrics Manager is enabled.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @retval TRUE Link Metrics Manager is enabled.
* @retval FALSE Link Metrics Manager is not enabled.
*
*/
bool otLinkMetricsManagerIsEnabled(otInstance *aInstance);

/**
* Enable or disable Link Metrics Manager.
*
Expand Down
5 changes: 1 addition & 4 deletions src/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3812,8 +3812,6 @@ template <> otError Interpreter::Process<Cmd("linkmetricsmgr")>(Arg aArgs[])
{
otError error = OT_ERROR_NONE;

VerifyOrExit(!aArgs[0].IsEmpty(), error = OT_ERROR_INVALID_ARGS);

/**
* @cli linkmetricsmgr (enable,disable)
* @code
Expand All @@ -3829,7 +3827,7 @@ template <> otError Interpreter::Process<Cmd("linkmetricsmgr")>(Arg aArgs[])
* #otLinkMetricsManagerSetEnabled
*
*/
if (ProcessEnableDisable(aArgs, otLinkMetricsManagerSetEnabled) == OT_ERROR_NONE)
if (ProcessEnableDisable(aArgs, otLinkMetricsManagerIsEnabled, otLinkMetricsManagerSetEnabled) == OT_ERROR_NONE)
{
}
/**
Expand Down Expand Up @@ -3868,7 +3866,6 @@ template <> otError Interpreter::Process<Cmd("linkmetricsmgr")>(Arg aArgs[])
error = OT_ERROR_INVALID_COMMAND;
}

exit:
return error;
}
#endif // OPENTHREAD_CONFIG_LINK_METRICS_MANAGER_ENABLE
Expand Down
5 changes: 5 additions & 0 deletions src/core/api/link_metrics_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ otError otLinkMetricsSendLinkProbe(otInstance *aInstance,
}

#if OPENTHREAD_CONFIG_LINK_METRICS_MANAGER_ENABLE
bool otLinkMetricsManagerIsEnabled(otInstance *aInstance)
{
return AsCoreType(aInstance).Get<Utils::LinkMetricsManager>().IsEnabled();
}

void otLinkMetricsManagerSetEnabled(otInstance *aInstance, bool aEnable)
{
AsCoreType(aInstance).Get<Utils::LinkMetricsManager>().SetEnabled(aEnable);
Expand Down
9 changes: 9 additions & 0 deletions src/core/utils/link_metrics_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ class LinkMetricsManager : public InstanceLocator, private NonCopyable
*/
explicit LinkMetricsManager(Instance &aInstance);

/**
* Is the LinkMetricsManager feature enabled.
*
* @retval TRUE Link Metrics Manager is enabled.
* @retval FALSE Link Metrics Manager is not enabled.
*
*/
bool IsEnabled(void) { return mEnabled; }

/**
* Enable/Disable the LinkMetricsManager feature.
*
Expand Down
18 changes: 18 additions & 0 deletions tests/scripts/expect/v1_2-linkmetricsmgr.exp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ setup_two_nodes
switch_node 1
send "linkmetricsmgr enable\n"
expect_line "Done"
send "linkmetricsmgr\n"
expect_line "Enabled"
expect_line "Done"

sleep 10

Expand All @@ -52,6 +55,9 @@ sleep 5

send "linkmetricsmgr disable\n"
expect_line "Done"
send "linkmetricsmgr\n"
expect_line "Disabled"
expect_line "Done"
send "linkmetricsmgr show\n"
expect_line "Done"
send "linkmetricsmgr xxx\n"
Expand All @@ -64,6 +70,9 @@ send "linkmetricsmgr enable\n"
expect_line "Done"
send "linkmetricsmgr enable\n"
expect_line "Done"
send "linkmetricsmgr\n"
expect_line "Enabled"
expect_line "Done"

send "ping $addr\n"
expect "16 bytes from $addr: icmp_seq="
Expand All @@ -84,6 +93,9 @@ send "linkmetricsmgr disable\n"
expect_line "Done"
send "linkmetricsmgr disable\n"
expect_line "Done"
send "linkmetricsmgr\n"
expect_line "Disabled"
expect_line "Done"

send "ping $addr\n"
expect "16 bytes from $addr: icmp_seq="
Expand All @@ -103,6 +115,9 @@ send "linkmetricsmgr disable\n"
expect_line "Done"
send "linkmetricsmgr enable\n"
expect_line "Done"
send "linkmetricsmgr\n"
expect_line "Enabled"
expect_line "Done"

send "ping $addr\n"
expect "16 bytes from $addr: icmp_seq="
Expand All @@ -122,6 +137,9 @@ send "linkmetricsmgr enable\n"
expect_line "Done"
send "linkmetricsmgr disable\n"
expect_line "Done"
send "linkmetricsmgr\n"
expect_line "Disabled"
expect_line "Done"

send "ping $addr\n"
expect "16 bytes from $addr: icmp_seq="
Expand Down

0 comments on commit 93f3113

Please sign in to comment.