Skip to content

Commit

Permalink
[dbus] Implement D-BUS API GetTrelInfo
Browse files Browse the repository at this point in the history
Introduce D-BUS API GetTrelInfo to support getting TREL telemetry.
  • Loading branch information
yangliu1333 committed Dec 25, 2023
1 parent 29cea6a commit 9a86784
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
BUILD_TARGET: check
OTBR_BUILD_TYPE: ${{ matrix.build_type }}
OTBR_MDNS: ${{ matrix.mdns }}
OTBR_OPTIONS: "-DOTBR_SRP_ADVERTISING_PROXY=ON -DOTBR_BORDER_ROUTING=ON -DOTBR_NAT64=1 -DOTBR_SRP_SERVER_AUTO_ENABLE=OFF"
OTBR_OPTIONS: "-DOTBR_SRP_ADVERTISING_PROXY=ON -DOTBR_BORDER_ROUTING=ON -DOTBR_NAT64=1 -DOTBR_SRP_SERVER_AUTO_ENABLE=OFF, -DOTBR_TREL=ON"
OTBR_COVERAGE: 1
steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 5 additions & 0 deletions src/dbus/client/thread_api_dbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,11 @@ ClientError ThreadApiDBus::GetSrpServerInfo(SrpServerInfo &aSrpServerInfo)
return GetProperty(OTBR_DBUS_PROPERTY_SRP_SERVER_INFO, aSrpServerInfo);
}

ClientError ThreadApiDBus::GetTrelInfo(TrelInfo &aTrelInfo)
{
return GetProperty(OTBR_DBUS_PROPERTY_TREL_INFO, aTrelInfo);
}

ClientError ThreadApiDBus::GetMdnsTelemetryInfo(MdnsTelemetryInfo &aMdnsTelemetryInfo)
{
return GetProperty(OTBR_DBUS_PROPERTY_MDNS_TELEMETRY_INFO, aMdnsTelemetryInfo);
Expand Down
12 changes: 12 additions & 0 deletions src/dbus/client/thread_api_dbus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,18 @@ class ThreadApiDBus
*/
ClientError GetSrpServerInfo(SrpServerInfo &aSrpServerInfo);

/**
* This method gets the TREL information.
*
* @param[out] aTrelInfo The TREL information.
*
* @retval ERROR_NONE Successfully performed the dbus function call
* @retval ERROR_DBUS dbus encode/decode error
* @retval ... OpenThread defined error value otherwise
*
*/
ClientError GetTrelInfo(TrelInfo &aTrelInfo);

/**
* This method gets the MDNS telemetry information.
*
Expand Down
1 change: 1 addition & 0 deletions src/dbus/common/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
#define OTBR_DBUS_PROPERTY_FEATURE_FLAG_LIST_DATA "FeatureFlagListData"
#define OTBR_DBUS_PROPERTY_RADIO_REGION "RadioRegion"
#define OTBR_DBUS_PROPERTY_SRP_SERVER_INFO "SrpServerInfo"
#define OTBR_DBUS_PROPERTY_TREL_INFO "TrelInfo"
#define OTBR_DBUS_PROPERTY_DNSSD_COUNTERS "DnssdCounters"
#define OTBR_DBUS_PROPERTY_OTBR_VERSION "OtbrVersion"
#define OTBR_DBUS_PROPERTY_OT_HOST_VERSION "OtHostVersion"
Expand Down
19 changes: 19 additions & 0 deletions src/dbus/common/dbus_message_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ otbrError DBusMessageEncode(DBusMessageIter *aIter, const Nat64ErrorCounters &aC
otbrError DBusMessageExtract(DBusMessageIter *aIter, Nat64ErrorCounters &aCounters);
otbrError DBusMessageEncode(DBusMessageIter *aIter, const InfraLinkInfo &aInfraLinkInfo);
otbrError DBusMessageExtract(DBusMessageIter *aIter, InfraLinkInfo &aInfraLinkInfo);
otbrError DBusMessageEncode(DBusMessageIter *aIter, const TrelInfo &aTrelInfo);
otbrError DBusMessageExtract(DBusMessageIter *aIter, TrelInfo &aTrelInfo);
otbrError DBusMessageEncode(DBusMessageIter *aIter, const TrelInfo::TrelCounters &aCounters);
otbrError DBusMessageExtract(DBusMessageIter *aIter, TrelInfo::TrelCounters &aCounters);

template <typename T> struct DBusTypeTrait;

Expand Down Expand Up @@ -382,6 +386,21 @@ template <> struct DBusTypeTrait<Nat64ErrorCounters>
static constexpr const char *TYPE_AS_STRING = "((tt)(tt)(tt)(tt))";
};

template <> struct DBusTypeTrait<TrelInfo>
{
// struct of { bool,
// uint16,
// struct of {
// uint64, uint64, uint64, uint64, uint64 } }
static constexpr const char *TYPE_AS_STRING = "(bq(ttttt))";
};

template <> struct DBusTypeTrait<TrelInfo::TrelCounters>
{
// struct of { uint64, uint64, uint64, uint64, uint64 }
static constexpr const char *TYPE_AS_STRING = "(ttttt)";
};

template <> struct DBusTypeTrait<InfraLinkInfo>
{
// struct of { string, bool, bool, bool, uint32, uint32, uint32 }
Expand Down
64 changes: 64 additions & 0 deletions src/dbus/common/dbus_message_helper_openthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,5 +1194,69 @@ otbrError DBusMessageExtract(DBusMessageIter *aIter, InfraLinkInfo &aInfraLinkIn
return error;
}

otbrError DBusMessageEncode(DBusMessageIter *aIter, const TrelInfo &aTrelInfo)
{
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

VerifyOrExit(dbus_message_iter_open_container(aIter, DBUS_TYPE_STRUCT, nullptr, &sub), error = OTBR_ERROR_DBUS);

SuccessOrExit(error = DBusMessageEncode(&sub, aTrelInfo.mEnabled));
SuccessOrExit(error = DBusMessageEncode(&sub, aTrelInfo.mNumTrelPeers));
SuccessOrExit(error = DBusMessageEncode(&sub, aTrelInfo.mTrelCounters));

VerifyOrExit(dbus_message_iter_close_container(aIter, &sub), error = OTBR_ERROR_DBUS);
exit:
return error;
}

otbrError DBusMessageExtract(DBusMessageIter *aIter, TrelInfo &aTrelInfo)
{
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);

SuccessOrExit(error = DBusMessageExtract(&sub, aTrelInfo.mEnabled));
SuccessOrExit(error = DBusMessageExtract(&sub, aTrelInfo.mNumTrelPeers));
SuccessOrExit(error = DBusMessageExtract(&sub, aTrelInfo.mTrelCounters));

dbus_message_iter_next(aIter);
exit:
return error;
}

otbrError DBusMessageEncode(DBusMessageIter *aIter, const TrelInfo::TrelCounters &aTrelCounters)
{
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;
auto args = std::tie(aTrelCounters.mTxPackets, aTrelCounters.mTxBytes, aTrelCounters.mRxPackets,
aTrelCounters.mRxBytes, aTrelCounters.mTxFailure);

VerifyOrExit(dbus_message_iter_open_container(aIter, DBUS_TYPE_STRUCT, nullptr, &sub), error = OTBR_ERROR_DBUS);
SuccessOrExit(error = ConvertToDBusMessage(&sub, args));
VerifyOrExit(dbus_message_iter_close_container(aIter, &sub) == true, error = OTBR_ERROR_DBUS);
exit:
return error;
}

otbrError DBusMessageExtract(DBusMessageIter *aIter, TrelInfo::TrelCounters &aTrelCounters)
{
DBusMessageIter sub;
otbrError error = OTBR_ERROR_NONE;

dbus_message_iter_recurse(aIter, &sub);

SuccessOrExit(error = DBusMessageExtract(&sub, aTrelCounters.mTxPackets));
SuccessOrExit(error = DBusMessageExtract(&sub, aTrelCounters.mTxBytes));
SuccessOrExit(error = DBusMessageExtract(&sub, aTrelCounters.mRxPackets));
SuccessOrExit(error = DBusMessageExtract(&sub, aTrelCounters.mRxBytes));
SuccessOrExit(error = DBusMessageExtract(&sub, aTrelCounters.mTxFailure));

dbus_message_iter_next(aIter);
exit:
return error;
}

} // namespace DBus
} // namespace otbr
16 changes: 16 additions & 0 deletions src/dbus/common/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,22 @@ struct InfraLinkInfo
uint32_t mGlobalUnicastAddresses; ///< The number of global unicast addresses on the infra network interface.
};

struct TrelInfo
{
struct TrelCounters
{
uint64_t mTxPackets; ///< Number of packets transmitted through TREL.
uint64_t mTxBytes; ///< Sum of size of packets transmitted through TREL.
uint64_t mRxPackets; ///< Number of packets received through TREL.
uint64_t mRxBytes; ///< Sum of size of packets received through TREL.
uint64_t mTxFailure; ///< Number of packets transmission failures through TREL.
};

bool mEnabled; ///< Whether TREL is enabled.
u_int16_t mNumTrelPeers; ///< The number of TREL peers.
TrelCounters mTrelCounters; ///< The TREL counters.
};

} // namespace DBus
} // namespace otbr

Expand Down
32 changes: 32 additions & 0 deletions src/dbus/server/dbus_thread_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <openthread/openthread-system.h>
#include <openthread/srp_server.h>
#include <openthread/thread_ftd.h>
#include <openthread/trel.h>
#include <openthread/platform/radio.h>

#include "common/api_strings.hpp"
Expand Down Expand Up @@ -270,6 +271,8 @@ otbrError DBusThreadObject::Init(void)
std::bind(&DBusThreadObject::GetNat64Cidr, this, _1));
RegisterGetPropertyHandler(OTBR_DBUS_THREAD_INTERFACE, OTBR_DBUS_PROPERTY_INFRA_LINK_INFO,
std::bind(&DBusThreadObject::GetInfraLinkInfo, this, _1));
RegisterGetPropertyHandler(OTBR_DBUS_THREAD_INTERFACE, OTBR_DBUS_PROPERTY_TREL_INFO,
std::bind(&DBusThreadObject::GetTrelInfoHandler, this, _1));
RegisterGetPropertyHandler(OTBR_DBUS_THREAD_INTERFACE, OTBR_DBUS_PROPERTY_DNS_UPSTREAM_QUERY_STATE,
std::bind(&DBusThreadObject::GetDnsUpstreamQueryState, this, _1));
RegisterGetPropertyHandler(OTBR_DBUS_THREAD_INTERFACE, OTBR_DBUS_PROPERTY_TELEMETRY_DATA,
Expand Down Expand Up @@ -1407,6 +1410,35 @@ otError DBusThreadObject::GetDnssdCountersHandler(DBusMessageIter &aIter)
#endif // OTBR_ENABLE_DNSSD_DISCOVERY_PROXY
}

otError DBusThreadObject::GetTrelInfoHandler(DBusMessageIter &aIter)
{
#if OTBR_ENABLE_TREL
auto threadHelper = mNcp->GetThreadHelper();
auto instance = threadHelper->GetInstance();
otError error = OT_ERROR_NONE;
TrelInfo trelInfo;
otTrelCounters otTrelCounters = *otTrelGetCounters(instance);

trelInfo.mTrelCounters.mTxPackets = otTrelCounters.mTxPackets;
trelInfo.mTrelCounters.mTxBytes = otTrelCounters.mTxBytes;
trelInfo.mTrelCounters.mRxPackets = otTrelCounters.mRxPackets;
trelInfo.mTrelCounters.mRxBytes = otTrelCounters.mRxBytes;
trelInfo.mTrelCounters.mTxFailure = otTrelCounters.mTxFailure;

trelInfo.mNumTrelPeers = otTrelGetNumberOfPeers(instance);
trelInfo.mEnabled = otTrelIsEnabled(instance);

VerifyOrExit(DBusMessageEncodeToVariant(&aIter, trelInfo) == OTBR_ERROR_NONE, error = OT_ERROR_INVALID_ARGS);

exit:
return error;
#else // OTBR_ENABLE_TREL
OTBR_UNUSED_VARIABLE(aIter);

return OT_ERROR_NOT_IMPLEMENTED;
#endif // OTBR_ENABLE_TREL
}

otError DBusThreadObject::GetTelemetryDataHandler(DBusMessageIter &aIter)
{
#if OTBR_ENABLE_TELEMETRY_DATA_API
Expand Down
1 change: 1 addition & 0 deletions src/dbus/server/dbus_thread_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class DBusThreadObject : public DBusObject
otError GetRadioSpinelMetricsHandler(DBusMessageIter &aIter);
otError GetRcpInterfaceMetricsHandler(DBusMessageIter &aIter);
otError GetUptimeHandler(DBusMessageIter &aIter);
otError GetTrelInfoHandler(DBusMessageIter &aIter);
otError GetRadioCoexMetrics(DBusMessageIter &aIter);
otError GetBorderRoutingCountersHandler(DBusMessageIter &aIter);
otError GetNat64State(DBusMessageIter &aIter);
Expand Down
19 changes: 19 additions & 0 deletions src/proto/thread_telemetry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,25 @@ message TelemetryData {
optional SrpServerResponseCounters response_counters = 6;
}

message TrelPacketCounters {
optional int64 trel_frame_tx = 1;
optional int64 trel_bytes_tx = 2;
optional int64 trel_frame_rx = 3;
optional int64 trel_bytes_rx = 4;
optional int64 trel_frame_tx_failed = 5;
}

message TrelInfo {
// Whether TREL is enabled.
optional bool is_trel_enabled = 1;

// The number of trel peers.
optional uint32 num_trel_peers = 2;

// Trel packet counters
optional TrelPacketCounters counters = 3;
}

message DnsServerResponseCounters {
// The number of successful responses
optional uint32 success_count = 1;
Expand Down
16 changes: 16 additions & 0 deletions tests/dbus/test_dbus_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ using otbr::DBus::LinkModeConfig;
using otbr::DBus::OnMeshPrefix;
using otbr::DBus::SrpServerInfo;
using otbr::DBus::ThreadApiDBus;
using otbr::DBus::TrelInfo;
using otbr::DBus::TxtEntry;

#if OTBR_ENABLE_DNSSD_DISCOVERY_PROXY
Expand Down Expand Up @@ -182,6 +183,20 @@ void CheckSrpServerInfo(ThreadApiDBus *aApi)
TEST_ASSERT(srpServerInfo.mResponseCounters.mOther == 0);
}

void CheckTrelInfo(ThreadApiDBus *aApi)
{
TrelInfo trelInfo;

TEST_ASSERT(aApi->GetTrelInfo(trelInfo) == OTBR_ERROR_NONE);
TEST_ASSERT(trelInfo.mEnabled);
TEST_ASSERT(trelInfo.mNumTrelPeers == 0);
TEST_ASSERT(trelInfo.mTrelCounters.mRxBytes == 0);
TEST_ASSERT(trelInfo.mTrelCounters.mRxPackets == 0);
TEST_ASSERT(trelInfo.mTrelCounters.mTxBytes == 0);
TEST_ASSERT(trelInfo.mTrelCounters.mTxPackets == 0);
TEST_ASSERT(trelInfo.mTrelCounters.mTxFailure == 0);
}

void CheckDnssdCounters(ThreadApiDBus *aApi)
{
OTBR_UNUSED_VARIABLE(aApi);
Expand Down Expand Up @@ -420,6 +435,7 @@ int main()
TEST_ASSERT(api->GetRadioTxPower(txPower) == OTBR_ERROR_NONE);
TEST_ASSERT(api->GetActiveDatasetTlvs(activeDataset) == OTBR_ERROR_NONE);
CheckSrpServerInfo(api.get());
CheckTrelInfo(api.get());
CheckMdnsInfo(api.get());
CheckDnssdCounters(api.get());
CheckNat64(api.get());
Expand Down
2 changes: 1 addition & 1 deletion third_party/openthread/repo
Submodule repo updated 94 files
+0 −1 .github/dependabot.yml
+1 −1 .github/workflows/docker.yml
+0 −89 doc/ot_config_doc.h
+9 −4 examples/platforms/simulation/trel.c
+1 −1 include/openthread/instance.h
+20 −0 include/openthread/platform/trel.h
+33 −0 include/openthread/trel.h
+0 −2 src/cli/ftd.cmake
+0 −2 src/cli/mtd.cmake
+0 −2 src/cli/radio.cmake
+10 −0 src/core/api/trel_api.cpp
+1 −16 src/core/config/announce_sender.h
+0 −15 src/core/config/backbone_router.h
+0 −15 src/core/config/border_agent.h
+0 −15 src/core/config/border_router.h
+0 −15 src/core/config/border_routing.h
+0 −15 src/core/config/channel_manager.h
+0 −15 src/core/config/channel_monitor.h
+0 −15 src/core/config/child_supervision.h
+0 −15 src/core/config/coap.h
+0 −15 src/core/config/commissioner.h
+0 −15 src/core/config/crypto.h
+0 −15 src/core/config/dataset_updater.h
+0 −15 src/core/config/dhcp6_client.h
+0 −15 src/core/config/dhcp6_server.h
+0 −15 src/core/config/diag.h
+0 −15 src/core/config/dns_client.h
+0 −15 src/core/config/dns_dso.h
+1 −16 src/core/config/dnssd_server.h
+0 −15 src/core/config/history_tracker.h
+0 −15 src/core/config/ip6.h
+0 −15 src/core/config/joiner.h
+0 −15 src/core/config/link_metrics_manager.h
+0 −15 src/core/config/link_quality.h
+0 −15 src/core/config/link_raw.h
+0 −15 src/core/config/logging.h
+0 −15 src/core/config/mac.h
+0 −15 src/core/config/mesh_diag.h
+0 −15 src/core/config/mesh_forwarder.h
+0 −15 src/core/config/misc.h
+0 −15 src/core/config/mle.h
+0 −15 src/core/config/nat64.h
+0 −15 src/core/config/netdata_publisher.h
+0 −15 src/core/config/network_diagnostic.h
+0 −15 src/core/config/parent_search.h
+0 −15 src/core/config/ping_sender.h
+0 −15 src/core/config/platform.h
+0 −15 src/core/config/power_calibration.h
+0 −15 src/core/config/radio_link.h
+0 −15 src/core/config/secure_transport.h
+0 −15 src/core/config/sntp_client.h
+1 −16 src/core/config/srp_client.h
+0 −15 src/core/config/srp_server.h
+0 −15 src/core/config/time_sync.h
+0 −16 src/core/config/tmf.h
+1 −1 src/core/diags/factory_diags.cpp
+0 −2 src/core/ftd.cmake
+0 −2 src/core/mtd.cmake
+0 −62 src/core/net/dns_types.cpp
+0 −145 src/core/net/dns_types.hpp
+29 −29 src/core/net/dnssd_server.cpp
+6 −4 src/core/net/dnssd_server.hpp
+35 −33 src/core/net/srp_server.cpp
+0 −6 src/core/net/srp_server.hpp
+0 −2 src/core/radio.cmake
+11 −0 src/core/radio/trel_interface.cpp
+17 −0 src/core/radio/trel_interface.hpp
+0 −2 src/core/radio_cli.cmake
+2 −14 src/lib/spinel/CMakeLists.txt
+2 −2 src/lib/spinel/example_vendor_hook.cpp
+2 −2 src/lib/spinel/example_vendor_hook.hpp
+3 −3 src/lib/spinel/openthread-spinel-config.h
+1 −1 src/lib/spinel/radio_spinel.cpp
+1 −1 src/lib/spinel/radio_spinel.hpp
+5 −3 src/lib/spinel/spinel.c
+0 −2 src/lib/spinel/spinel.h
+0 −2 src/ncp/ftd.cmake
+0 −2 src/ncp/mtd.cmake
+0 −2 src/ncp/radio.cmake
+0 −1 src/posix/platform/CMakeLists.txt
+0 −2 src/posix/platform/openthread-core-posix-config.h
+34 −0 src/posix/platform/openthread-posix-config.h
+0 −72 src/posix/platform/openthread-posix-daemon-config.h
+1 −1 src/posix/platform/radio.cpp
+2 −2 src/posix/platform/radio.hpp
+1 −1 src/posix/platform/radio_url.cpp
+1 −14 src/posix/platform/radio_url.hpp
+28 −6 src/posix/platform/trel.cpp
+0 −2 tests/fuzz/CMakeLists.txt
+0 −4 tests/unit/CMakeLists.txt
+37 −84 tests/unit/test_dns.cpp
+11 −11 tests/unit/test_dns_client.cpp
+2 −0 tests/unit/test_platform.cpp
+1 −0 tests/unit/test_platform.h

0 comments on commit 9a86784

Please sign in to comment.