mirror of
https://github.com/espressif/openthread.git
synced 2026-08-03 17:37:46 +00:00
[net-diag] introduce Server and Client classes (#8936)
This commit introduces `Server` and `Client` classes breaking the `NetworkDiagnostic` module into two components. The `Server` responds to queries and requests (handling Net Diag TMF commands), while `Client` issues queries/requests and processes responses. The `Server` is available under both FTD and MTD (which follows the requirement of Thread spec). The client is enabled using newly added `OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE` config option which is also available as `OT_NETDIAG_CLIENT` CMake option or the autoconf build switch `NETDIAG_CLIENT`. The client functionality is by default enabled on Border Routers (tied to `CONFIG_BORDER_ROUTING_ENABLE` config). The previous `TMF_NETWORK_DIAG_MTD_ENABLE` config is now removed along with its CMake `OT_MTD_NETDIAG` and autoconf switch. This commit adds checks to trigger build error if the previous config and/or its related CMake option are used.
This commit is contained in:
+15
-1
@@ -122,12 +122,12 @@ ot_option(OT_MESH_DIAG OPENTHREAD_CONFIG_MESH_DIAG_ENABLE "mesh diag")
|
||||
ot_option(OT_MESSAGE_USE_HEAP OPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE "heap allocator for message buffers")
|
||||
ot_option(OT_MLE_LONG_ROUTES OPENTHREAD_CONFIG_MLE_LONG_ROUTES_ENABLE "MLE long routes extension (experimental)")
|
||||
ot_option(OT_MLR OPENTHREAD_CONFIG_MLR_ENABLE "Multicast Listener Registration (MLR)")
|
||||
ot_option(OT_MTD_NETDIAG OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE "TMF network diagnostics on MTDs")
|
||||
ot_option(OT_MULTIPLE_INSTANCE OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE "multiple instances")
|
||||
ot_option(OT_NAT64_BORDER_ROUTING OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE "border routing NAT64")
|
||||
ot_option(OT_NAT64_TRANSLATOR OPENTHREAD_CONFIG_NAT64_TRANSLATOR_ENABLE "NAT64 translator support")
|
||||
ot_option(OT_NEIGHBOR_DISCOVERY_AGENT OPENTHREAD_CONFIG_NEIGHBOR_DISCOVERY_AGENT_ENABLE "neighbor discovery agent")
|
||||
ot_option(OT_NETDATA_PUBLISHER OPENTHREAD_CONFIG_NETDATA_PUBLISHER_ENABLE "Network Data publisher")
|
||||
ot_option(OT_NETDIAG_CLIENT OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE "Network Diagnostic client")
|
||||
ot_option(OT_OTNS OPENTHREAD_CONFIG_OTNS_ENABLE "OTNS")
|
||||
ot_option(OT_PING_SENDER OPENTHREAD_CONFIG_PING_SENDER_ENABLE "ping sender" ${OT_APP_CLI})
|
||||
ot_option(OT_PLATFORM_NETIF OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE "platform netif")
|
||||
@@ -210,3 +210,17 @@ endif()
|
||||
if(OT_POSIX_SETTINGS_PATH)
|
||||
target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH=${OT_POSIX_SETTINGS_PATH}")
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
# Check removed/replaced options
|
||||
|
||||
macro(ot_removed_option name error)
|
||||
# This macro checks for a remove option and emits an error
|
||||
# if the option is set.
|
||||
get_property(is_set CACHE ${name} PROPERTY VALUE SET)
|
||||
if (is_set)
|
||||
message(FATAL_ERROR "Removed option ${name} is set - ${error}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
ot_removed_option(OT_MTD_NETDIAG "- Use OT_NETDIAG_CLIENT instead - note that server function is always supported")
|
||||
|
||||
@@ -174,8 +174,8 @@ if (openthread_enable_core_config_args) {
|
||||
# Enable MLE long routes extension (experimental, breaks Thread conformance]
|
||||
openthread_config_mle_long_routes_enable = false
|
||||
|
||||
# Enable TMF network diagnostics on MTDs
|
||||
openthread_config_tmf_network_diag_mtd_enable = false
|
||||
# Enable TMF network diagnostics client
|
||||
openthread_config_tmf_netdiag_client_enable = false
|
||||
|
||||
# Enable multiple instances
|
||||
openthread_config_multiple_instance_enable = false
|
||||
|
||||
@@ -59,9 +59,9 @@ JAM_DETECTION ?= 1
|
||||
JOINER ?= 1
|
||||
LINK_RAW ?= 1
|
||||
MAC_FILTER ?= 1
|
||||
MTD_NETDIAG ?= 1
|
||||
NEIGHBOR_DISCOVERY_AGENT ?= 1
|
||||
NETDATA_PUBLISHER ?= 1
|
||||
NETDIAG_CLIENT ?= 1
|
||||
PING_SENDER ?= 1
|
||||
REFERENCE_DEVICE ?= 1
|
||||
SERVICE ?= 1
|
||||
|
||||
+7
-1
@@ -51,11 +51,11 @@ This page lists the available common switches with description. Unless stated ot
|
||||
| MAC_FILTER | OT_MAC_FILTER | Enables support for the MAC filter. |
|
||||
| MLE_LONG_ROUTES | OT_MLE_LONG_ROUTES | Enables the MLE long routes extension. **Note: Enabling this feature breaks conformance to the Thread Specification.** |
|
||||
| MLR | OT_MLR | Enables Multicast Listener Registration feature for Thread 1.2. |
|
||||
| MTD_NETDIAG | OT_MTD_NETDIAG | Enables the TMF network diagnostics on MTDs. |
|
||||
| MULTIPLE_INSTANCE | OT_MULTIPLE_INSTANCE | Enables multiple OpenThread instances. |
|
||||
| NAT64_BORDER_ROUTING | OT_NAT64_BORDER_ROUTING | Enables NAT64 border routing support for Border Router. |
|
||||
| NAT64_TRANSLATOR | OT_NAT64_TRANSLATOR | Enables NAT64 translator for Border Router. |
|
||||
| NETDATA_PUBLISHER | OT_NETDATA_PUBLISHER | Enables support for Thread Network Data publisher. |
|
||||
| NETDIAG_CLIENT | OT_NETDIAG_CLIENT | Enables Network Diagnostics client functionality. |
|
||||
| PING_SENDER | OT_PING_SENDER | Enables support for ping sender. |
|
||||
| OTNS | OT_OTNS | Enables support for [OpenThread Network Simulator](https://github.com/openthread/ot-ns). Enable this switch if you are building OpenThread for OpenThread Network Simulator. |
|
||||
| PLATFORM_UDP | OT_PLATFORM_UDP | Enables platform UDP support. |
|
||||
@@ -73,3 +73,9 @@ This page lists the available common switches with description. Unless stated ot
|
||||
| TREL | OT_TREL | Enables TREL radio link for Thread over Infrastructure feature. |
|
||||
| UDP_FORWARD | OT_UDP_FORWARD | Enables support for UDP forward. Enable this switch on the Border Router device (running on the NCP design) with External Commissioning support to service Thread Commissioner packets on the NCP side. |
|
||||
| UPTIME | OT_UPTIME | Enables support for tracking OpenThread instance's uptime. |
|
||||
|
||||
Removed or replaced switches:
|
||||
|
||||
| Makefile switch | CMake switch | Description |
|
||||
| --- | --- | --- |
|
||||
| MTD_NETDIAG | OT_MTD_NETDIAG | Use NEDIAG_CLIENT to enable client functionality. Server functionality is always supported. |
|
||||
|
||||
@@ -76,6 +76,7 @@ NAT64_BORDER_ROUTING ?= 0
|
||||
NAT64_TRANSLATOR ?= 0
|
||||
NEIGHBOR_DISCOVERY_AGENT ?= 0
|
||||
NETDATA_PUBLISHER ?= 0
|
||||
NETDIAG_CLIENT ?= 0
|
||||
OTNS ?= 0
|
||||
PING_SENDER ?= 1
|
||||
PLATFORM_UDP ?= 0
|
||||
@@ -286,6 +287,9 @@ ifeq ($(MLR),1)
|
||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_MLR_ENABLE=1
|
||||
endif
|
||||
|
||||
# This config is removed but we still check and add the
|
||||
# `OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE` so to
|
||||
# get an error during build if `MTD_NETDIAG` is used.
|
||||
ifeq ($(MTD_NETDIAG),1)
|
||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE=1
|
||||
endif
|
||||
@@ -302,6 +306,10 @@ ifeq ($(NETDATA_PUBLISHER),1)
|
||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_NETDATA_PUBLISHER_ENABLE=1
|
||||
endif
|
||||
|
||||
ifeq ($(NETDIAG_CLIENT),1)
|
||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE=1
|
||||
endif
|
||||
|
||||
ifeq ($(PING_SENDER),1)
|
||||
COMMONCFLAGS += -DOPENTHREAD_CONFIG_PING_SENDER_ENABLE=1
|
||||
endif
|
||||
|
||||
@@ -53,7 +53,7 @@ extern "C" {
|
||||
* @note This number versions both OpenThread platform and user APIs.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_API_VERSION (307)
|
||||
#define OPENTHREAD_API_VERSION (308)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
@@ -47,6 +47,8 @@ extern "C" {
|
||||
*
|
||||
* @{
|
||||
*
|
||||
*
|
||||
* Network Dianostics APIs require OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,8 +65,8 @@ build_nrf52840()
|
||||
"-DOT_MAC_FILTER=ON"
|
||||
"-DOT_MESSAGE_USE_HEAP=ON"
|
||||
"-DOT_MLR=ON"
|
||||
"-DOT_MTD_NETDIAG=ON"
|
||||
"-DOT_NETDATA_PUBLISHER=ON"
|
||||
"-DOT_NETDIAG_CLIENT=ON"
|
||||
"-DOT_PING_SENDER=ON"
|
||||
"-DOT_SERVICE=ON"
|
||||
"-DOT_SLAAC=ON"
|
||||
|
||||
@@ -62,10 +62,10 @@ OT_BUILD_OPTIONS=(
|
||||
"-DOT_LOG_LEVEL_DYNAMIC=ON"
|
||||
"-DOT_MAC_FILTER=ON"
|
||||
"-DOT_MESH_DIAG=ON"
|
||||
"-DOT_MTD_NETDIAG=ON"
|
||||
"-DOT_NAT64_BORDER_ROUTING=ON"
|
||||
"-DOT_NAT64_TRANSLATOR=ON"
|
||||
"-DOT_NEIGHBOR_DISCOVERY_AGENT=ON"
|
||||
"-DOT_NETDIAG_CLIENT=ON"
|
||||
"-DOT_PING_SENDER=ON"
|
||||
"-DOT_PLATFORM=external"
|
||||
"-DOT_RCP_RESTORATION_MAX_COUNT=2"
|
||||
|
||||
@@ -86,7 +86,7 @@ build_all_features()
|
||||
"-DOPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_SRP_CLIENT_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_UDP_FORWARD_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_MAC_BEACON_PAYLOAD_PARSING_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_MAC_OUTGOING_BEACON_PAYLOAD_ENABLE=1"
|
||||
|
||||
@@ -142,7 +142,6 @@ size_nrf52840_version()
|
||||
"-DOT_LINK_RAW=ON"
|
||||
"-DOT_MAC_FILTER=ON"
|
||||
"-DOT_MESSAGE_USE_HEAP=ON"
|
||||
"-DOT_MTD_NETDIAG=ON"
|
||||
"-DOT_NETDATA_PUBLISHER=ON"
|
||||
"-DOT_PING_SENDER=ON"
|
||||
"-DOT_SERVICE=ON"
|
||||
|
||||
+1
-1
@@ -92,9 +92,9 @@ OT_POSIX_SIM_COMMON_OPTIONS=(
|
||||
"-DOT_JAM_DETECTION=ON"
|
||||
"-DOT_JOINER=ON"
|
||||
"-DOT_MAC_FILTER=ON"
|
||||
"-DOT_MTD_NETDIAG=ON"
|
||||
"-DOT_NEIGHBOR_DISCOVERY_AGENT=ON"
|
||||
"-DOT_NETDATA_PUBLISHER=ON"
|
||||
"-DOT_NETDIAG_CLIENT=ON"
|
||||
"-DOT_PING_SENDER=ON"
|
||||
"-DOT_REFERENCE_DEVICE=ON"
|
||||
"-DOT_SERVICE=ON"
|
||||
|
||||
+1
-1
@@ -121,10 +121,10 @@ OT_CLANG_TIDY_BUILD_OPTS=(
|
||||
'-DOT_LINK_METRICS_SUBJECT=ON'
|
||||
'-DOT_MAC_FILTER=ON'
|
||||
'-DOT_MESH_DIAG=ON'
|
||||
'-DOT_MTD_NETDIAG=ON'
|
||||
'-DOT_NAT64_BORDER_ROUTING=ON'
|
||||
'-DOT_NAT64_TRANSLATOR=ON'
|
||||
'-DOT_NETDATA_PUBLISHER=ON'
|
||||
'-DOT_NETDIAG_CLIENT=ON'
|
||||
'-DOT_PING_SENDER=ON'
|
||||
'-DOT_REFERENCE_DEVICE=ON'
|
||||
'-DOT_SERVICE=ON'
|
||||
|
||||
+3
-3
@@ -7950,7 +7950,7 @@ exit:
|
||||
}
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
template <> otError Interpreter::Process<Cmd("networkdiagnostic")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
@@ -8175,7 +8175,7 @@ void Interpreter::OutputChildTableEntry(uint8_t aIndentSize, const otNetworkDiag
|
||||
OutputLine(aIndentSize, "Mode:");
|
||||
OutputMode(aIndentSize + kIndentSize, aChildEntry.mMode);
|
||||
}
|
||||
#endif // OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
#endif // OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
|
||||
void Interpreter::HandleDetachGracefullyResult(void *aContext)
|
||||
{
|
||||
@@ -8394,7 +8394,7 @@ otError Interpreter::ProcessCommand(Arg aArgs[])
|
||||
#endif
|
||||
CmdEntry("netdata"),
|
||||
CmdEntry("netstat"),
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
CmdEntry("networkdiagnostic"),
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
|
||||
+1
-1
@@ -439,7 +439,7 @@ private:
|
||||
static void HandleEnergyScanResult(otEnergyScanResult *aResult, void *aContext);
|
||||
static void HandleLinkPcapReceive(const otRadioFrame *aFrame, bool aIsTx, void *aContext);
|
||||
|
||||
#if OPENTHREAD_FTD || (OPENTHREAD_MTD && OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE)
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
void HandleDiagnosticGetResponse(otError aError, const otMessage *aMessage, const Ip6::MessageInfo *aMessageInfo);
|
||||
static void HandleDiagnosticGetResponse(otError aError,
|
||||
otMessage *aMessage,
|
||||
|
||||
+5
-4
@@ -196,18 +196,19 @@ if (openthread_enable_core_config_args) {
|
||||
defines += [ "OPENTHREAD_CONFIG_MLE_LONG_ROUTES_ENABLE=1" ]
|
||||
}
|
||||
|
||||
if (openthread_config_tmf_network_diag_mtd_enable) {
|
||||
defines += [ "OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE=1" ]
|
||||
}
|
||||
|
||||
if (openthread_config_multiple_instance_enable) {
|
||||
defines += [ "OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE=1" ]
|
||||
}
|
||||
|
||||
if (openthread_config_tmf_netdiag_client_enable) {
|
||||
defines += [ "OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE=1" ]
|
||||
}
|
||||
|
||||
if (openthread_config_platform_netif_enable) {
|
||||
defines += [ "OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE=1" ]
|
||||
}
|
||||
|
||||
|
||||
if (openthread_config_platform_udp_enable) {
|
||||
defines += [ "OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE=1" ]
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
|
||||
#include <openthread/netdiag.h>
|
||||
|
||||
@@ -49,7 +49,7 @@ otError otThreadGetNextDiagnosticTlv(const otMessage *aMessage,
|
||||
AssertPointerIsNotNull(aIterator);
|
||||
AssertPointerIsNotNull(aNetworkDiagTlv);
|
||||
|
||||
return NetworkDiagnostic::NetworkDiagnostic::GetNextDiagTlv(AsCoapMessage(aMessage), *aIterator, *aNetworkDiagTlv);
|
||||
return NetworkDiagnostic::Client::GetNextDiagTlv(AsCoapMessage(aMessage), *aIterator, *aNetworkDiagTlv);
|
||||
}
|
||||
|
||||
otError otThreadSendDiagnosticGet(otInstance *aInstance,
|
||||
@@ -59,7 +59,7 @@ otError otThreadSendDiagnosticGet(otInstance *aInstance,
|
||||
otReceiveDiagnosticGetCallback aCallback,
|
||||
void *aCallbackContext)
|
||||
{
|
||||
return AsCoreType(aInstance).Get<NetworkDiagnostic::NetworkDiagnostic>().SendDiagnosticGet(
|
||||
return AsCoreType(aInstance).Get<NetworkDiagnostic::Client>().SendDiagnosticGet(
|
||||
AsCoreType(aDestination), aTlvTypes, aCount, aCallback, aCallbackContext);
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@ otError otThreadSendDiagnosticReset(otInstance *aInstance,
|
||||
const uint8_t aTlvTypes[],
|
||||
uint8_t aCount)
|
||||
{
|
||||
return AsCoreType(aInstance).Get<NetworkDiagnostic::NetworkDiagnostic>().SendDiagnosticReset(
|
||||
AsCoreType(aDestination), aTlvTypes, aCount);
|
||||
return AsCoreType(aInstance).Get<NetworkDiagnostic::Client>().SendDiagnosticReset(AsCoreType(aDestination),
|
||||
aTlvTypes, aCount);
|
||||
}
|
||||
|
||||
#endif // OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
#endif // OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
|
||||
@@ -136,8 +136,9 @@ Instance::Instance(void)
|
||||
, mNetworkDataPublisher(*this)
|
||||
#endif
|
||||
, mNetworkDataServiceManager(*this)
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
, mNetworkDiagnostic(*this)
|
||||
, mNetworkDiagnosticServer(*this)
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
, mNetworkDiagnosticClient(*this)
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
, mBorderAgent(*this)
|
||||
|
||||
@@ -495,8 +495,9 @@ private:
|
||||
|
||||
NetworkData::Service::Manager mNetworkDataServiceManager;
|
||||
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
NetworkDiagnostic::NetworkDiagnostic mNetworkDiagnostic;
|
||||
NetworkDiagnostic::Server mNetworkDiagnosticServer;
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
NetworkDiagnostic::Client mNetworkDiagnosticClient;
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
@@ -824,8 +825,10 @@ template <> inline Dns::ServiceDiscovery::Server &Instance::Get(void) { return m
|
||||
template <> inline Dns::Dso &Instance::Get(void) { return mDnsDso; }
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
template <> inline NetworkDiagnostic::NetworkDiagnostic &Instance::Get(void) { return mNetworkDiagnostic; }
|
||||
template <> inline NetworkDiagnostic::Server &Instance::Get(void) { return mNetworkDiagnosticServer; }
|
||||
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
template <> inline NetworkDiagnostic::Client &Instance::Get(void) { return mNetworkDiagnosticClient; }
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE
|
||||
|
||||
@@ -648,4 +648,10 @@
|
||||
#error "OPENTHREAD_CONFIG_CHILD_SUPERVISION_MSG_NO_ACK_REQUEST is removed".
|
||||
#endif
|
||||
|
||||
#ifdef OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
#error "OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE is removed. "\
|
||||
"Use OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE to enable client functionality."\
|
||||
"Netdiag server functionality is always supported."
|
||||
#endif
|
||||
|
||||
#endif // OPENTHREAD_CORE_CONFIG_CHECK_H_
|
||||
|
||||
@@ -173,13 +173,16 @@
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
* @def OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
*
|
||||
* Define to 1 to enable TMF network diagnostics on MTDs.
|
||||
* Define to 1 to enable TMF network diagnostics client.
|
||||
*
|
||||
* The network diagnostic client add API to send diagnostic requests and queries to other node and process the response.
|
||||
* It is enabled by default on Border Routers.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
#define OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE 0
|
||||
#ifndef OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
#define OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,8 +33,6 @@
|
||||
|
||||
#include "network_diagnostic.hpp"
|
||||
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
|
||||
#include "coap/coap_message.hpp"
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
@@ -58,82 +56,15 @@ RegisterLogModule("NetDiag");
|
||||
|
||||
namespace NetworkDiagnostic {
|
||||
|
||||
NetworkDiagnostic::NetworkDiagnostic(Instance &aInstance)
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
// Server
|
||||
|
||||
Server::Server(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
{
|
||||
}
|
||||
|
||||
Error NetworkDiagnostic::SendDiagnosticGet(const Ip6::Address &aDestination,
|
||||
const uint8_t aTlvTypes[],
|
||||
uint8_t aCount,
|
||||
GetCallback aCallback,
|
||||
void *aContext)
|
||||
{
|
||||
Error error;
|
||||
|
||||
if (aDestination.IsMulticast())
|
||||
{
|
||||
error = SendCommand(kUriDiagnosticGetQuery, aDestination, aTlvTypes, aCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = SendCommand(kUriDiagnosticGetRequest, aDestination, aTlvTypes, aCount, &HandleGetResponse, this);
|
||||
}
|
||||
|
||||
SuccessOrExit(error);
|
||||
|
||||
mGetCallback.Set(aCallback, aContext);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error NetworkDiagnostic::SendCommand(Uri aUri,
|
||||
const Ip6::Address &aDestination,
|
||||
const uint8_t aTlvTypes[],
|
||||
uint8_t aCount,
|
||||
Coap::ResponseHandler aHandler,
|
||||
void *aContext)
|
||||
{
|
||||
Error error;
|
||||
Coap::Message *message = nullptr;
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
|
||||
switch (aUri)
|
||||
{
|
||||
case kUriDiagnosticGetQuery:
|
||||
message = Get<Tmf::Agent>().NewNonConfirmablePostMessage(aUri);
|
||||
break;
|
||||
|
||||
case kUriDiagnosticGetRequest:
|
||||
case kUriDiagnosticReset:
|
||||
message = Get<Tmf::Agent>().NewConfirmablePostMessage(aUri);
|
||||
break;
|
||||
|
||||
default:
|
||||
OT_ASSERT(false);
|
||||
}
|
||||
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
if (aCount > 0)
|
||||
{
|
||||
SuccessOrExit(error = Tlv::Append<TypeListTlv>(*message, aTlvTypes, aCount));
|
||||
}
|
||||
|
||||
PrepareMessageInfoForDest(aDestination, messageInfo);
|
||||
|
||||
SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, messageInfo, aHandler, aContext));
|
||||
|
||||
Log(kMessageSend, aUri, aDestination);
|
||||
|
||||
exit:
|
||||
FreeMessageOnError(message, error);
|
||||
return error;
|
||||
}
|
||||
|
||||
void NetworkDiagnostic::PrepareMessageInfoForDest(const Ip6::Address &aDestination,
|
||||
Tmf::MessageInfo &aMessageInfo) const
|
||||
void Server::PrepareMessageInfoForDest(const Ip6::Address &aDestination, Tmf::MessageInfo &aMessageInfo) const
|
||||
{
|
||||
if (aDestination.IsMulticast())
|
||||
{
|
||||
@@ -152,41 +83,7 @@ void NetworkDiagnostic::PrepareMessageInfoForDest(const Ip6::Address &aDestinati
|
||||
aMessageInfo.SetPeerAddr(aDestination);
|
||||
}
|
||||
|
||||
void NetworkDiagnostic::HandleGetResponse(void *aContext,
|
||||
otMessage *aMessage,
|
||||
const otMessageInfo *aMessageInfo,
|
||||
Error aResult)
|
||||
{
|
||||
static_cast<NetworkDiagnostic *>(aContext)->HandleGetResponse(AsCoapMessagePtr(aMessage),
|
||||
AsCoreTypePtr(aMessageInfo), aResult);
|
||||
}
|
||||
|
||||
void NetworkDiagnostic::HandleGetResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult)
|
||||
{
|
||||
SuccessOrExit(aResult);
|
||||
VerifyOrExit(aMessage->GetCode() == Coap::kCodeChanged, aResult = kErrorFailed);
|
||||
|
||||
exit:
|
||||
mGetCallback.InvokeIfSet(aResult, aMessage, aMessageInfo);
|
||||
}
|
||||
|
||||
template <>
|
||||
void NetworkDiagnostic::HandleTmf<kUriDiagnosticGetAnswer>(Coap::Message &aMessage,
|
||||
const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
VerifyOrExit(aMessage.IsConfirmablePostRequest());
|
||||
|
||||
Log(kMessageReceive, kUriDiagnosticGetAnswer, aMessageInfo.GetPeerAddr());
|
||||
|
||||
mGetCallback.InvokeIfSet(kErrorNone, &aMessage, &aMessageInfo);
|
||||
|
||||
IgnoreError(Get<Tmf::Agent>().SendEmptyAck(aMessage, aMessageInfo));
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
Error NetworkDiagnostic::AppendIp6AddressList(Message &aMessage)
|
||||
Error Server::AppendIp6AddressList(Message &aMessage)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
uint16_t count = 0;
|
||||
@@ -224,7 +121,7 @@ exit:
|
||||
}
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
Error NetworkDiagnostic::AppendChildTable(Message &aMessage)
|
||||
Error Server::AppendChildTable(Message &aMessage)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
uint16_t count;
|
||||
@@ -276,7 +173,7 @@ exit:
|
||||
}
|
||||
#endif // OPENTHREAD_FTD
|
||||
|
||||
Error NetworkDiagnostic::AppendMacCounters(Message &aMessage)
|
||||
Error Server::AppendMacCounters(Message &aMessage)
|
||||
{
|
||||
MacCountersTlv tlv;
|
||||
const otMacCounters &counters = Get<Mac::Mac>().GetCounters();
|
||||
@@ -298,7 +195,7 @@ Error NetworkDiagnostic::AppendMacCounters(Message &aMessage)
|
||||
return tlv.AppendTo(aMessage);
|
||||
}
|
||||
|
||||
Error NetworkDiagnostic::AppendRequestedTlvs(const Message &aRequest, Message &aResponse)
|
||||
Error Server::AppendRequestedTlvs(const Message &aRequest, Message &aResponse)
|
||||
{
|
||||
Error error;
|
||||
uint16_t offset;
|
||||
@@ -320,7 +217,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error NetworkDiagnostic::AppendDiagTlv(uint8_t aTlvType, Message &aMessage)
|
||||
Error Server::AppendDiagTlv(uint8_t aTlvType, Message &aMessage)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
@@ -437,14 +334,16 @@ exit:
|
||||
}
|
||||
|
||||
template <>
|
||||
void NetworkDiagnostic::HandleTmf<kUriDiagnosticGetQuery>(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
void Server::HandleTmf<kUriDiagnosticGetQuery>(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
Coap::Message *response = nullptr;
|
||||
Tmf::MessageInfo responseInfo(GetInstance());
|
||||
|
||||
VerifyOrExit(aMessage.IsPostRequest(), error = kErrorDrop);
|
||||
Log(kMessageReceive, kUriDiagnosticGetQuery, aMessageInfo.GetPeerAddr());
|
||||
|
||||
LogInfo("Received %s from %s", UriToString<kUriDiagnosticGetQuery>(),
|
||||
aMessageInfo.GetPeerAddr().ToString().AsCString());
|
||||
|
||||
// DIAG_GET.qry may be sent as a confirmable request.
|
||||
if (aMessage.IsConfirmable())
|
||||
@@ -465,14 +364,15 @@ exit:
|
||||
}
|
||||
|
||||
template <>
|
||||
void NetworkDiagnostic::HandleTmf<kUriDiagnosticGetRequest>(Coap::Message &aMessage,
|
||||
const Ip6::MessageInfo &aMessageInfo)
|
||||
void Server::HandleTmf<kUriDiagnosticGetRequest>(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
Coap::Message *response = nullptr;
|
||||
|
||||
VerifyOrExit(aMessage.IsConfirmablePostRequest(), error = kErrorDrop);
|
||||
Log(kMessageReceive, kUriDiagnosticGetRequest, aMessageInfo.GetPeerAddr());
|
||||
|
||||
LogInfo("Received %s from %s", UriToString<kUriDiagnosticGetRequest>(),
|
||||
aMessageInfo.GetPeerAddr().ToString().AsCString());
|
||||
|
||||
response = Get<Tmf::Agent>().NewResponseMessage(aMessage);
|
||||
VerifyOrExit(response != nullptr, error = kErrorNoBufs);
|
||||
@@ -484,22 +384,16 @@ exit:
|
||||
FreeMessageOnError(response, error);
|
||||
}
|
||||
|
||||
Error NetworkDiagnostic::SendDiagnosticReset(const Ip6::Address &aDestination,
|
||||
const uint8_t aTlvTypes[],
|
||||
uint8_t aCount)
|
||||
{
|
||||
return SendCommand(kUriDiagnosticReset, aDestination, aTlvTypes, aCount);
|
||||
}
|
||||
|
||||
template <>
|
||||
void NetworkDiagnostic::HandleTmf<kUriDiagnosticReset>(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
template <> void Server::HandleTmf<kUriDiagnosticReset>(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
uint16_t offset = 0;
|
||||
uint8_t type;
|
||||
Tlv tlv;
|
||||
|
||||
VerifyOrExit(aMessage.IsConfirmablePostRequest());
|
||||
Log(kMessageReceive, kUriDiagnosticReset, aMessageInfo.GetPeerAddr());
|
||||
|
||||
LogInfo("Received %s from %s", UriToString<kUriDiagnosticReset>(),
|
||||
aMessageInfo.GetPeerAddr().ToString().AsCString());
|
||||
|
||||
SuccessOrExit(aMessage.Read(aMessage.GetOffset(), tlv));
|
||||
|
||||
@@ -528,6 +422,121 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
// Client
|
||||
|
||||
Client::Client(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
{
|
||||
}
|
||||
|
||||
Error Client::SendDiagnosticGet(const Ip6::Address &aDestination,
|
||||
const uint8_t aTlvTypes[],
|
||||
uint8_t aCount,
|
||||
GetCallback aCallback,
|
||||
void *aContext)
|
||||
{
|
||||
Error error;
|
||||
|
||||
if (aDestination.IsMulticast())
|
||||
{
|
||||
error = SendCommand(kUriDiagnosticGetQuery, aDestination, aTlvTypes, aCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = SendCommand(kUriDiagnosticGetRequest, aDestination, aTlvTypes, aCount, &HandleGetResponse, this);
|
||||
}
|
||||
|
||||
SuccessOrExit(error);
|
||||
|
||||
mGetCallback.Set(aCallback, aContext);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Client::SendCommand(Uri aUri,
|
||||
const Ip6::Address &aDestination,
|
||||
const uint8_t aTlvTypes[],
|
||||
uint8_t aCount,
|
||||
Coap::ResponseHandler aHandler,
|
||||
void *aContext)
|
||||
{
|
||||
Error error;
|
||||
Coap::Message *message = nullptr;
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
|
||||
switch (aUri)
|
||||
{
|
||||
case kUriDiagnosticGetQuery:
|
||||
message = Get<Tmf::Agent>().NewNonConfirmablePostMessage(aUri);
|
||||
break;
|
||||
|
||||
case kUriDiagnosticGetRequest:
|
||||
case kUriDiagnosticReset:
|
||||
message = Get<Tmf::Agent>().NewConfirmablePostMessage(aUri);
|
||||
break;
|
||||
|
||||
default:
|
||||
OT_ASSERT(false);
|
||||
}
|
||||
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
if (aCount > 0)
|
||||
{
|
||||
SuccessOrExit(error = Tlv::Append<TypeListTlv>(*message, aTlvTypes, aCount));
|
||||
}
|
||||
|
||||
Get<Server>().PrepareMessageInfoForDest(aDestination, messageInfo);
|
||||
|
||||
SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, messageInfo, aHandler, aContext));
|
||||
|
||||
LogInfo("Sent %s to %s", UriToString(aUri), aDestination.ToString().AsCString());
|
||||
|
||||
exit:
|
||||
FreeMessageOnError(message, error);
|
||||
return error;
|
||||
}
|
||||
|
||||
void Client::HandleGetResponse(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo, Error aResult)
|
||||
{
|
||||
static_cast<Client *>(aContext)->HandleGetResponse(AsCoapMessagePtr(aMessage), AsCoreTypePtr(aMessageInfo),
|
||||
aResult);
|
||||
}
|
||||
|
||||
void Client::HandleGetResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult)
|
||||
{
|
||||
SuccessOrExit(aResult);
|
||||
VerifyOrExit(aMessage->GetCode() == Coap::kCodeChanged, aResult = kErrorFailed);
|
||||
|
||||
exit:
|
||||
mGetCallback.InvokeIfSet(aResult, aMessage, aMessageInfo);
|
||||
}
|
||||
|
||||
template <>
|
||||
void Client::HandleTmf<kUriDiagnosticGetAnswer>(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
VerifyOrExit(aMessage.IsConfirmablePostRequest());
|
||||
|
||||
LogInfo("Received %s from %s", ot::UriToString<kUriDiagnosticGetAnswer>(),
|
||||
aMessageInfo.GetPeerAddr().ToString().AsCString());
|
||||
|
||||
mGetCallback.InvokeIfSet(kErrorNone, &aMessage, &aMessageInfo);
|
||||
|
||||
IgnoreError(Get<Tmf::Agent>().SendEmptyAck(aMessage, aMessageInfo));
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
Error Client::SendDiagnosticReset(const Ip6::Address &aDestination, const uint8_t aTlvTypes[], uint8_t aCount)
|
||||
{
|
||||
return SendCommand(kUriDiagnosticReset, aDestination, aTlvTypes, aCount);
|
||||
}
|
||||
|
||||
static void ParseRoute(const RouteTlv &aRouteTlv, otNetworkDiagRoute &aNetworkDiagRoute)
|
||||
{
|
||||
uint8_t routeCount = 0;
|
||||
@@ -561,7 +570,7 @@ static inline void ParseMacCounters(const MacCountersTlv &aMacCountersTlv, otNet
|
||||
aMacCounters.mIfOutDiscards = aMacCountersTlv.GetIfOutDiscards();
|
||||
}
|
||||
|
||||
Error NetworkDiagnostic::GetNextDiagTlv(const Coap::Message &aMessage, Iterator &aIterator, TlvInfo &aTlvInfo)
|
||||
Error Client::GetNextDiagTlv(const Coap::Message &aMessage, Iterator &aIterator, TlvInfo &aTlvInfo)
|
||||
{
|
||||
Error error = kErrorNotFound;
|
||||
uint16_t offset = (aIterator == 0) ? aMessage.GetOffset() : aIterator;
|
||||
@@ -775,7 +784,7 @@ exit:
|
||||
|
||||
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
|
||||
|
||||
const char *NetworkDiagnostic::UriToString(Uri aUri)
|
||||
const char *Client::UriToString(Uri aUri)
|
||||
{
|
||||
const char *str = "";
|
||||
|
||||
@@ -790,9 +799,6 @@ const char *NetworkDiagnostic::UriToString(Uri aUri)
|
||||
case kUriDiagnosticReset:
|
||||
str = ot::UriToString<kUriDiagnosticReset>();
|
||||
break;
|
||||
case kUriDiagnosticGetAnswer:
|
||||
str = ot::UriToString<kUriDiagnosticGetAnswer>();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -800,29 +806,10 @@ const char *NetworkDiagnostic::UriToString(Uri aUri)
|
||||
return str;
|
||||
}
|
||||
|
||||
void NetworkDiagnostic::Log(Action aAction, Uri aUri, const Ip6::Address &aIp6Address) const
|
||||
{
|
||||
static const char *const kActionStrings[] = {
|
||||
"Sent", // (0) kMessageSend
|
||||
"Received", // (1) kMessageReceive
|
||||
};
|
||||
|
||||
static const char *const kActionPrepositionStrings[] = {
|
||||
"to", // (0) kMessageSend
|
||||
"from", // (1) kMessageReceive
|
||||
};
|
||||
|
||||
static_assert(kMessageSend == 0, "kMessageSend value is incorrect");
|
||||
static_assert(kMessageReceive == 1, "kMessageReceive value is incorrect");
|
||||
|
||||
LogInfo("%s %s %s %s", kActionStrings[aAction], UriToString(aUri), kActionPrepositionStrings[aAction],
|
||||
aIp6Address.ToString().AsCString());
|
||||
}
|
||||
|
||||
#endif // #if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
|
||||
} // namespace NetworkDiagnostic
|
||||
|
||||
} // namespace ot
|
||||
|
||||
#endif // OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
|
||||
@@ -36,8 +36,6 @@
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
|
||||
#include <openthread/netdiag.h>
|
||||
|
||||
#include "common/callback.hpp"
|
||||
@@ -61,11 +59,50 @@ namespace NetworkDiagnostic {
|
||||
* @{
|
||||
*/
|
||||
|
||||
class Client;
|
||||
|
||||
/**
|
||||
* This class implements the Network Diagnostic processing.
|
||||
* This class implements the Network Diagnostic server responding to requests.
|
||||
*
|
||||
*/
|
||||
class NetworkDiagnostic : public InstanceLocator, private NonCopyable
|
||||
class Server : public InstanceLocator, private NonCopyable
|
||||
{
|
||||
friend class Tmf::Agent;
|
||||
friend class Client;
|
||||
|
||||
public:
|
||||
/**
|
||||
* This constructor initializes the Server.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance.
|
||||
*
|
||||
*/
|
||||
explicit Server(Instance &aInstance);
|
||||
|
||||
private:
|
||||
static constexpr uint16_t kMaxChildEntries = 398;
|
||||
|
||||
Error AppendDiagTlv(uint8_t aTlvType, Message &aMessage);
|
||||
Error AppendIp6AddressList(Message &aMessage);
|
||||
Error AppendMacCounters(Message &aMessage);
|
||||
Error AppendChildTable(Message &aMessage);
|
||||
Error AppendRequestedTlvs(const Message &aRequest, Message &aResponse);
|
||||
void PrepareMessageInfoForDest(const Ip6::Address &aDestination, Tmf::MessageInfo &aMessageInfo) const;
|
||||
|
||||
template <Uri kUri> void HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
};
|
||||
|
||||
DeclareTmfHandler(Server, kUriDiagnosticGetRequest);
|
||||
DeclareTmfHandler(Server, kUriDiagnosticGetQuery);
|
||||
DeclareTmfHandler(Server, kUriDiagnosticGetAnswer);
|
||||
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
|
||||
/**
|
||||
* This class implements the Network Diagnostic client sending requests and queries.
|
||||
*
|
||||
*/
|
||||
class Client : public InstanceLocator, private NonCopyable
|
||||
{
|
||||
friend class Tmf::Agent;
|
||||
|
||||
@@ -78,10 +115,12 @@ public:
|
||||
static constexpr Iterator kIteratorInit = OT_NETWORK_DIAGNOSTIC_ITERATOR_INIT; ///< Initializer for Iterator.
|
||||
|
||||
/**
|
||||
* This constructor initializes the object.
|
||||
* This constructor initializes the Client.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance.
|
||||
*
|
||||
*/
|
||||
explicit NetworkDiagnostic(Instance &aInstance);
|
||||
explicit Client(Instance &aInstance);
|
||||
|
||||
/**
|
||||
* This method sends Diagnostic Get request. If the @p aDestination is of multicast type, the DIAG_GET.qry
|
||||
@@ -127,12 +166,6 @@ public:
|
||||
private:
|
||||
static constexpr uint16_t kMaxChildEntries = 398;
|
||||
|
||||
enum Action : uint8_t
|
||||
{
|
||||
kMessageSend,
|
||||
kMessageReceive,
|
||||
};
|
||||
|
||||
Error SendCommand(Uri aUri,
|
||||
const Ip6::Address &aDestination,
|
||||
const uint8_t aTlvTypes[],
|
||||
@@ -140,13 +173,6 @@ private:
|
||||
Coap::ResponseHandler aHandler = nullptr,
|
||||
void *aContext = nullptr);
|
||||
|
||||
Error AppendDiagTlv(uint8_t aTlvType, Message &aMessage);
|
||||
Error AppendIp6AddressList(Message &aMessage);
|
||||
Error AppendMacCounters(Message &aMessage);
|
||||
Error AppendChildTable(Message &aMessage);
|
||||
Error AppendRequestedTlvs(const Message &aRequest, Message &aResponse);
|
||||
void PrepareMessageInfoForDest(const Ip6::Address &aDestination, Tmf::MessageInfo &aMessageInfo) const;
|
||||
|
||||
static void HandleGetResponse(void *aContext,
|
||||
otMessage *aMessage,
|
||||
const otMessageInfo *aMessageInfo,
|
||||
@@ -157,18 +183,14 @@ private:
|
||||
|
||||
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
|
||||
static const char *UriToString(Uri aUri);
|
||||
void Log(Action aAction, Uri aUri, const Ip6::Address &aIp6Address) const;
|
||||
#else
|
||||
void Log(Action, Uri, const Ip6::Address &) const {}
|
||||
#endif
|
||||
|
||||
Callback<GetCallback> mGetCallback;
|
||||
};
|
||||
|
||||
DeclareTmfHandler(NetworkDiagnostic, kUriDiagnosticGetRequest);
|
||||
DeclareTmfHandler(NetworkDiagnostic, kUriDiagnosticGetQuery);
|
||||
DeclareTmfHandler(NetworkDiagnostic, kUriDiagnosticGetAnswer);
|
||||
DeclareTmfHandler(NetworkDiagnostic, kUriDiagnosticReset);
|
||||
DeclareTmfHandler(Client, kUriDiagnosticReset);
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -177,6 +199,4 @@ DeclareTmfHandler(NetworkDiagnostic, kUriDiagnosticReset);
|
||||
|
||||
} // namespace ot
|
||||
|
||||
#endif // OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
|
||||
#endif // NETWORK_DIAGNOSTIC_HPP_
|
||||
|
||||
@@ -165,11 +165,12 @@ bool Agent::HandleResource(const char *aUriPath, Message &aMessage, const Ip6::M
|
||||
Case(kUriAnycastLocate, AnycastLocator);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
Case(kUriDiagnosticGetRequest, NetworkDiagnostic::NetworkDiagnostic);
|
||||
Case(kUriDiagnosticGetQuery, NetworkDiagnostic::NetworkDiagnostic);
|
||||
Case(kUriDiagnosticGetAnswer, NetworkDiagnostic::NetworkDiagnostic);
|
||||
Case(kUriDiagnosticReset, NetworkDiagnostic::NetworkDiagnostic);
|
||||
Case(kUriDiagnosticGetRequest, NetworkDiagnostic::Server);
|
||||
Case(kUriDiagnosticGetQuery, NetworkDiagnostic::Server);
|
||||
Case(kUriDiagnosticReset, NetworkDiagnostic::Server);
|
||||
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE
|
||||
Case(kUriDiagnosticGetAnswer, NetworkDiagnostic::Client);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
|
||||
@@ -61,9 +61,9 @@ LINK_RAW ?= 0
|
||||
LOG_OUTPUT ?= PLATFORM_DEFINED
|
||||
MAC_FILTER ?= 1
|
||||
MAX_POWER_TABLE ?= 1
|
||||
MTD_NETDIAG ?= 1
|
||||
NEIGHBOR_DISCOVERY_AGENT ?= 1
|
||||
NETDATA_PUBLISHER ?= 1
|
||||
NETDIAG_CLIENT ?= 1
|
||||
PING_SENDER ?= 1
|
||||
READLINE ?= readline
|
||||
REFERENCE_DEVICE ?= 1
|
||||
|
||||
@@ -62,8 +62,8 @@ set -euxo pipefail
|
||||
-DOT_LINK_RAW=ON \
|
||||
-DOT_LOG_OUTPUT=APP \
|
||||
-DOT_MAC_FILTER=ON \
|
||||
-DOT_MTD_NETDIAG=ON \
|
||||
-DOT_NETDATA_PUBLISHER=ON \
|
||||
-DOT_NETDIAG_CLIENT=ON \
|
||||
-DOT_PING_SENDER=ON \
|
||||
-DOT_SERVICE=ON \
|
||||
-DOT_SLAAC=ON \
|
||||
|
||||
Reference in New Issue
Block a user