Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[telemetry] add link metrics telemetry #2036

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions etc/cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,10 @@ option(OTBR_VENDOR_SERVER "Enable vendor server" OFF)
if (OTBR_VENDOR_SERVER)
target_compile_definitions(otbr-config INTERFACE OTBR_ENABLE_VENDOR_SERVER=1)
endif()

option(OTBR_LINK_METRICS_TELEMETRY "Enable Link Metrics Telemetry Upload" OFF)
if (OTBR_LINK_METRICS_TELEMETRY)
target_compile_definitions(otbr-config INTERFACE OTBR_ENABLE_LINK_METRICS_TELEMETRY=1)
else()
target_compile_definitions(otbr-config INTERFACE OTBR_ENABLE_LINK_METRICS_TELEMETRY=0)
endif()
1 change: 1 addition & 0 deletions script/test
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ do_build()
"-DOTBR_WEB=ON"
"-DOTBR_UNSECURE_JOIN=ON"
"-DOTBR_TREL=ON"
"-DOTBR_LINK_METRICS_TELEMETRY=ON"
${otbr_options[@]+"${otbr_options[@]}"}
)

Expand Down
10 changes: 10 additions & 0 deletions src/proto/thread_telemetry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,15 @@ message TelemetryData {
optional uint32 rx_average_request_to_grant_time_us = 15;
}

message LinkMetricsEntry {
optional int32 link_margin = 1;
optional int32 rssi = 2;
}

message LowPowerMetrics {
repeated LinkMetricsEntry link_metrics_entries = 1;
}

optional WpanStats wpan_stats = 1;
optional WpanTopoFull wpan_topo_full = 2;
repeated TopoEntry topo_entries = 3;
Expand All @@ -486,4 +495,5 @@ message TelemetryData {
// Deprecate CoexMetrics with int64 as its fields types to save storage.
reserved 6;
optional CoexMetrics coex_metrics = 7;
optional LowPowerMetrics low_power_metrics = 8;
}
33 changes: 29 additions & 4 deletions src/utils/thread_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
#include <openthread/nat64.h>
#include "utils/sha256.hpp"
#endif
#if OTBR_ENABLE_LINK_METRICS_TELEMETRY
#include <openthread/link_metrics.h>
#endif
#if OTBR_ENABLE_SRP_ADVERTISING_PROXY
#include <openthread/srp_server.h>
#endif
Expand Down Expand Up @@ -890,7 +893,8 @@ void ThreadHelper::DetachGracefullyCallback(void)
#if OTBR_ENABLE_TELEMETRY_DATA_API
otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadnetwork::TelemetryData &telemetryData)
{
otError error = OT_ERROR_NONE;
otError error = OT_ERROR_NONE;
std::vector<otNeighborInfo> neighborTable;

// Begin of WpanStats section.
auto wpanStats = telemetryData.mutable_wpan_stats();
Expand Down Expand Up @@ -973,9 +977,8 @@ otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadn
VerifyOrExit(otThreadGetRouterInfo(mInstance, rloc16, &info) == OT_ERROR_NONE, error = OT_ERROR_INVALID_STATE);
wpanTopoFull->set_router_id(info.mRouterId);

otNeighborInfoIterator iter = OT_NEIGHBOR_INFO_ITERATOR_INIT;
otNeighborInfo neighborInfo;
std::vector<otNeighborInfo> neighborTable;
otNeighborInfoIterator iter = OT_NEIGHBOR_INFO_ITERATOR_INIT;
otNeighborInfo neighborInfo;

while (otThreadGetNextNeighborInfo(mInstance, &iter, &neighborInfo) == OT_ERROR_NONE)
{
Expand Down Expand Up @@ -1383,6 +1386,28 @@ otError ThreadHelper::RetrieveTelemetryData(Mdns::Publisher *aPublisher, threadn
// End of CoexMetrics section.
}

#if OTBR_ENABLE_LINK_METRICS_TELEMETRY
{
auto lowPowerMetrics = telemetryData.mutable_low_power_metrics();
// Begin of Link Metrics section.
for (const otNeighborInfo &neighborInfo : neighborTable)
{
otError query_error;
otLinkMetricsValues values;

query_error = otLinkMetricsManagerGetMetricsValueByExtAddr(mInstance, &neighborInfo.mExtAddress, &values);
Irving-cl marked this conversation as resolved.
Show resolved Hide resolved
// Some neighbors don't support Link Metrics Subject feature. So it's expected that some other errors
// are returned.
if (query_error == OT_ERROR_NONE)
{
auto linkMetricsStats = lowPowerMetrics->add_link_metrics_entries();
linkMetricsStats->set_link_margin(values.mLinkMarginValue);
linkMetricsStats->set_rssi(values.mRssiValue);
}
}
}
#endif // OTBR_ENABLE_LINK_METRICS_TELEMETRY

exit:
return error;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/dbus/test_dbus_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ void CheckTelemetryData(ThreadApiDBus *aApi)
#endif
TEST_ASSERT(telemetryData.wpan_rcp().rcp_interface_statistics().transferred_frames_count() > 0);
TEST_ASSERT(telemetryData.coex_metrics().count_tx_request() > 0);
#if OTBR_ENABLE_LINK_METRICS_TELEMETRY
TEST_ASSERT(telemetryData.low_power_metrics().link_metrics_entries_size() >= 0);
#endif
}
#endif

Expand Down
2 changes: 2 additions & 0 deletions third_party/openthread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ set(OT_ECDSA ON CACHE STRING "enable ECDSA" FORCE)
set(OT_FIREWALL ON CACHE STRING "enable firewall feature")
set(OT_HISTORY_TRACKER ON CACHE STRING "enable history tracker" FORCE)
set(OT_JOINER ON CACHE STRING "enable joiner" FORCE)
set(OT_LINK_METRICS_INITIATOR ${OTBR_LINK_METRICS_TELEMETRY} CACHE STRING "enable link metrics initiator" FORCE)
set(OT_LINK_METRICS_MANAGER ${OTBR_LINK_METRICS_TELEMETRY} CACHE STRING "enable link metrics manager" FORCE)
set(OT_LOG_LEVEL_DYNAMIC ON CACHE STRING "enable dynamic log level control" FORCE)
set(OT_MAC_FILTER ON CACHE STRING "enable MAC filter" FORCE)
set(OT_NAT64_BORDER_ROUTING ${OTBR_NAT64} CACHE STRING "enable NAT64 in border routing manager" FORCE)
Expand Down