mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
[nexus] add test 5.7.3 CoAP Diagnostic Query and Answer – Router, FED (#12477)
This commit adds a new Nexus test case for 'CoAP Diagnostic Query and
Answer Commands – Router, FED' (5.7.3) as specified in the test
specification.
Summary of changes:
- Implemented Nexus test 5.7.3:
- Added tests/nexus/test_5_7_3.cpp: Sets up a network topology
with a Leader, Router 1, and three children (FED 1, MED 1,
SED 1) attached to Router 1. Implemented internal callback
to validate that diagnostic responses contain essential TLVs
(MAC Address, RLOC16, Mode) and verified that at least two
nodes (Router and FED) respond.
- Added tests/nexus/verify_5_7_3.py: PCAP verification script.
Validates the multicast query and the subsequent answers from
the Router and FED DUTs. Performed deep validation of returned
TLVs (MAC Address, RLOC16, Mode, Leader Router ID, IPv6 Address
List, Child Table).
- Enhanced packet verification utilities:
- Updated tests/nexus/verify_utils.py to support parsing and
registering more Thread Diagnostic TLVs (MAC Address, IPv6
Address List, Child Table, Channel Pages).
- Updated build and execution scripts:
- Modified tests/nexus/CMakeLists.txt and run_nexus_tests.sh to
include the new test.
Review fixes:
- tests/nexus/test_5_7_3.cpp: Use Tlv::Find() for more concise and
idiomatic parsing of Network Diagnostic TLVs.
- tests/nexus/verify_5_7_3.py: Include MED_1 in Router 1's child table
verification.
This commit is contained in:
@@ -157,6 +157,7 @@ ot_nexus_test(5_5_5 "cert;nexus")
|
||||
ot_nexus_test(5_5_7 "cert;nexus")
|
||||
ot_nexus_test(5_7_1 "cert;nexus")
|
||||
ot_nexus_test(5_7_2 "cert;nexus")
|
||||
ot_nexus_test(5_7_3 "cert;nexus")
|
||||
ot_nexus_test(5_8_2 "cert;nexus")
|
||||
ot_nexus_test(5_8_3 "cert;nexus")
|
||||
ot_nexus_test(6_1_1 "cert;nexus")
|
||||
|
||||
@@ -87,6 +87,7 @@ DEFAULT_TESTS=(
|
||||
"5_5_7"
|
||||
"5_7_1"
|
||||
"5_7_2"
|
||||
"5_7_3"
|
||||
"5_8_2"
|
||||
"5_8_3"
|
||||
"6_1_1_A"
|
||||
|
||||
@@ -0,0 +1,288 @@
|
||||
/*
|
||||
* Copyright (c) 2026, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "mac/data_poll_sender.hpp"
|
||||
#include "platform/nexus_core.hpp"
|
||||
#include "platform/nexus_node.hpp"
|
||||
#include "thread/network_diagnostic.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Nexus {
|
||||
|
||||
/**
|
||||
* Time to advance for a node to form a network and become leader, in milliseconds.
|
||||
*/
|
||||
static constexpr uint32_t kFormNetworkTime = 13 * 1000;
|
||||
|
||||
/**
|
||||
* Time to advance for a node to join as a child and upgrade to a router, in milliseconds.
|
||||
*/
|
||||
static constexpr uint32_t kAttachToRouterTime = 200 * 1000;
|
||||
|
||||
/**
|
||||
* Time to advance for the network to stabilize after nodes have attached.
|
||||
*/
|
||||
static constexpr uint32_t kStabilizationTime = 10 * 1000;
|
||||
|
||||
/**
|
||||
* Time to advance for the diagnostic response to be received.
|
||||
*/
|
||||
static constexpr uint32_t kDiagResponseTime = 5 * 1000;
|
||||
|
||||
/**
|
||||
* Data poll period for SED, in milliseconds.
|
||||
*/
|
||||
static constexpr uint32_t kPollPeriod = 500;
|
||||
|
||||
/**
|
||||
* Diagnostic TLV types used in the query.
|
||||
*/
|
||||
static constexpr uint8_t kDiagGetTlvs[] = {
|
||||
NetworkDiagnostic::Tlv::kExtMacAddress, NetworkDiagnostic::Tlv::kAddress16,
|
||||
NetworkDiagnostic::Tlv::kMode, NetworkDiagnostic::Tlv::kConnectivity,
|
||||
NetworkDiagnostic::Tlv::kRoute, NetworkDiagnostic::Tlv::kLeaderData,
|
||||
NetworkDiagnostic::Tlv::kNetworkData, NetworkDiagnostic::Tlv::kIp6AddressList,
|
||||
NetworkDiagnostic::Tlv::kChildTable, NetworkDiagnostic::Tlv::kChannelPages,
|
||||
};
|
||||
|
||||
struct DiagGetContext
|
||||
{
|
||||
uint8_t mResponseCount;
|
||||
};
|
||||
|
||||
static void HandleDiagnosticGetAnswer(otError aError,
|
||||
otMessage *aMessage,
|
||||
const otMessageInfo *aMessageInfo,
|
||||
void *aContext)
|
||||
{
|
||||
DiagGetContext *context = static_cast<DiagGetContext *>(aContext);
|
||||
Coap::Message *message = AsCoapMessagePtr(aMessage);
|
||||
Mac::ExtAddress extAddress;
|
||||
uint16_t shortAddress;
|
||||
uint8_t mode;
|
||||
|
||||
OT_UNUSED_VARIABLE(extAddress);
|
||||
OT_UNUSED_VARIABLE(shortAddress);
|
||||
OT_UNUSED_VARIABLE(mode);
|
||||
|
||||
VerifyOrQuit(aError == OT_ERROR_NONE);
|
||||
VerifyOrQuit(message != nullptr);
|
||||
VerifyOrQuit(aMessageInfo != nullptr);
|
||||
|
||||
context->mResponseCount++;
|
||||
|
||||
Log("Diagnostic Answer from %s", AsCoreType(&aMessageInfo->mPeerAddr).ToString().AsCString());
|
||||
|
||||
SuccessOrQuit(Tlv::Find<NetworkDiagnostic::ExtMacAddressTlv>(*message, extAddress));
|
||||
SuccessOrQuit(Tlv::Find<NetworkDiagnostic::Address16Tlv>(*message, shortAddress));
|
||||
SuccessOrQuit(Tlv::Find<NetworkDiagnostic::ModeTlv>(*message, mode));
|
||||
}
|
||||
|
||||
void Test5_7_3(void)
|
||||
{
|
||||
/**
|
||||
* 5.7.3 CoAP Diagnostic Query and Answer Commands - Router, FED
|
||||
*
|
||||
* 5.7.3.1 Topology
|
||||
* - Topology A
|
||||
* - Topology B
|
||||
*
|
||||
* 5.7.3.2 Purpose & Description
|
||||
* The purpose of this test case is to verify functionality of commands Diagnostic_Get.query and Diagnostic_Get.ans.
|
||||
* Thread Diagnostic commands MUST be supported by FTDs.
|
||||
*
|
||||
* Spec Reference | V1.1 Section | V1.3.0 Section
|
||||
* ---------------------------------------------|-----------------------|-----------------------
|
||||
* Get Diagnostic Query / Get Diagnostic Answer | 10.11.2.3 / 10.11.2.4 | 10.11.2.3 / 10.11.2.4
|
||||
*/
|
||||
|
||||
Core nexus;
|
||||
DiagGetContext context = {0};
|
||||
|
||||
Node &leader = nexus.CreateNode();
|
||||
Node &router1 = nexus.CreateNode();
|
||||
Node &fed1 = nexus.CreateNode();
|
||||
Node &med1 = nexus.CreateNode();
|
||||
Node &sed1 = nexus.CreateNode();
|
||||
|
||||
leader.SetName("LEADER");
|
||||
router1.SetName("ROUTER_1");
|
||||
fed1.SetName("FED_1");
|
||||
med1.SetName("MED_1");
|
||||
sed1.SetName("SED_1");
|
||||
|
||||
nexus.AdvanceTime(0);
|
||||
|
||||
Instance::SetLogLevel(kLogLevelNote);
|
||||
|
||||
Log("---------------------------------------------------------------------------------------");
|
||||
Log("Step 1: All");
|
||||
|
||||
/**
|
||||
* Step 1: All
|
||||
* - Description: Ensure topology is formed correctly.
|
||||
* - Pass Criteria: N/A.
|
||||
*/
|
||||
|
||||
/** Use AllowList to specify links between nodes. */
|
||||
leader.AllowList(router1);
|
||||
router1.AllowList(leader);
|
||||
|
||||
router1.AllowList(fed1);
|
||||
fed1.AllowList(router1);
|
||||
|
||||
router1.AllowList(med1);
|
||||
med1.AllowList(router1);
|
||||
|
||||
router1.AllowList(sed1);
|
||||
sed1.AllowList(router1);
|
||||
|
||||
leader.Form();
|
||||
nexus.AdvanceTime(kFormNetworkTime);
|
||||
|
||||
router1.Join(leader);
|
||||
nexus.AdvanceTime(kAttachToRouterTime);
|
||||
VerifyOrQuit(router1.Get<Mle::Mle>().IsRouter());
|
||||
|
||||
fed1.Join(router1, Node::kAsFed);
|
||||
med1.Join(router1, Node::kAsMed);
|
||||
sed1.Join(router1, Node::kAsSed);
|
||||
|
||||
SuccessOrQuit(sed1.Get<DataPollSender>().SetExternalPollPeriod(kPollPeriod));
|
||||
|
||||
nexus.AdvanceTime(kAttachToRouterTime);
|
||||
nexus.AdvanceTime(kStabilizationTime);
|
||||
|
||||
VerifyOrQuit(fed1.Get<Mle::Mle>().IsChild());
|
||||
VerifyOrQuit(med1.Get<Mle::Mle>().IsChild());
|
||||
VerifyOrQuit(sed1.Get<Mle::Mle>().IsChild());
|
||||
|
||||
Log("---------------------------------------------------------------------------------------");
|
||||
Log("Step 2: Leader");
|
||||
|
||||
/**
|
||||
* Step 2: Leader
|
||||
* - Description: Harness instructs the device to send DIAG_GET.query to the Realm-Local All-Thread-Nodes multicast
|
||||
* address for the following diagnostic TLV types:
|
||||
* - Topology A (Router DUT):
|
||||
* - TLV Type 0 - MAC Extended Address (64-bit)
|
||||
* - TLV Type 1 - MAC Address (16-bit)
|
||||
* - TLV Type 2 - Mode (Capability information)
|
||||
* - TLV Type 4 - Connectivity
|
||||
* - TLV Type 5 - Route64
|
||||
* - TLV Type 6 - Leader Data
|
||||
* - TLV Type 7 - Network Data
|
||||
* - TLV Type 8 - IPv6 address list
|
||||
* - TLV Type 16 - Child Table
|
||||
* - TLV Type 17 - Channel Pages
|
||||
* - Topology B (FED DUT):
|
||||
* - TLV Type 0 - MAC Extended Address (64-bit)
|
||||
* - TLV Type 1 - MAC Address (16-bit)
|
||||
* - TLV Type 2 - Mode (Capability information)
|
||||
* - TLV Type 6 - Leader Data
|
||||
* - TLV Type 7 - Network Data
|
||||
* - TLV Type 8 - IPv6 address list
|
||||
* - TLV Type 17 - Channel Pages
|
||||
* - Pass Criteria: N/A.
|
||||
*/
|
||||
|
||||
SuccessOrQuit(leader.Get<NetworkDiagnostic::Client>().SendDiagnosticGet(
|
||||
leader.Get<Mle::Mle>().GetRealmLocalAllThreadNodesAddress(), kDiagGetTlvs, sizeof(kDiagGetTlvs),
|
||||
HandleDiagnosticGetAnswer, &context));
|
||||
|
||||
Log("---------------------------------------------------------------------------------------");
|
||||
Log("Step 3: Topology A (Router DUT)");
|
||||
|
||||
/**
|
||||
* Step 3: Topology A (Router DUT)
|
||||
* - Description: Automatically responds with a DIAG_GET.ans response.
|
||||
* - Pass Criteria:
|
||||
* - The DIAG_GET.ans response MUST contain the requested diagnostic TLVs:
|
||||
* - CoAP Payload:
|
||||
* - TLV Type 0 - MAC Extended Address (64-bit)
|
||||
* - TLV Type 1 - MAC Address (16-bit)
|
||||
* - TLV Type 2 - Mode (Capability information)
|
||||
* - TLV Type 4 - Connectivity
|
||||
* - TLV Type 5 - Route64
|
||||
* - TLV Type 6 - Leader Data
|
||||
* - TLV Type 7 - Network Data
|
||||
* - TLV Type 8 - IPv6 address list
|
||||
* - TLV Type 16 - Child Table
|
||||
* - TLV Type 17 - Channel Pages
|
||||
* - The presence of each TLV MUST be validated. Where possible, the value of the TLVs MUST be validated.
|
||||
*/
|
||||
|
||||
nexus.AdvanceTime(kDiagResponseTime);
|
||||
|
||||
Log("---------------------------------------------------------------------------------------");
|
||||
Log("Step 4: Topology A (Router DUT)");
|
||||
|
||||
/**
|
||||
* Step 4: Topology A (Router DUT)
|
||||
* - Description: The DUT automatically multicasts the DIAG_GET.query frame.
|
||||
* - Pass Criteria:
|
||||
* - The DUT MUST use IEEE 802.15.4 indirect transmissions to forward the DIAG_GET.query to SED_1.
|
||||
*/
|
||||
|
||||
Log("---------------------------------------------------------------------------------------");
|
||||
Log("Step 5: Topology B (FED DUT)");
|
||||
|
||||
/**
|
||||
* Step 5: Topology B (FED DUT)
|
||||
* - Description: The DUT automatically responds with DIAG_GET.ans.
|
||||
* - Pass Criteria:
|
||||
* - The DIAG_GET.ans response MUST contain the requested diagnostic TLVs:
|
||||
* - CoAP Payload:
|
||||
* - TLV Type 0 - MAC Extended Address (64-bit)
|
||||
* - TLV Type 1 - MAC Address (16-bit)
|
||||
* - TLV Type 2 - Mode (Capability information)
|
||||
* - TLV Type 6 - Leader Data
|
||||
* - TLV Type 7 - Network Data
|
||||
* - TLV Type 8 - IPv6 address list
|
||||
* - TLV Type 17 - Channel Pages
|
||||
* - The presence of each TLV MUST be validated. Where possible, the value of the TLVs MUST be validated.
|
||||
*/
|
||||
|
||||
// Verify that we received at least 4 responses (Leader, Router, FED, MED, SED)
|
||||
// Note: Leader doesn't respond to its own multicast query, so 4 responses.
|
||||
VerifyOrQuit(context.mResponseCount >= 4);
|
||||
|
||||
nexus.SaveTestInfo("test_5_7_3.json");
|
||||
}
|
||||
|
||||
} // namespace Nexus
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ot::Nexus::Test5_7_3();
|
||||
printf("All tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (c) 2026, The OpenThread Authors.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# 3. Neither the name of the copyright holder nor the
|
||||
# names of its contributors may be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add the current directory to sys.path to find verify_utils
|
||||
CUR_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.append(CUR_DIR)
|
||||
|
||||
import verify_utils
|
||||
from pktverify import consts
|
||||
|
||||
|
||||
def verify(pv):
|
||||
# 5.7.3 CoAP Diagnostic Query and Answer Commands - Router, FED
|
||||
#
|
||||
# 5.7.3.1 Topology
|
||||
# - Topology A
|
||||
# - Topology B
|
||||
#
|
||||
# 5.7.3.2 Purpose & Description
|
||||
# The purpose of this test case is to verify functionality of commands Diagnostic_Get.query and Diagnostic_Get.ans.
|
||||
# Thread Diagnostic commands MUST be supported by FTDs.
|
||||
#
|
||||
# Spec Reference | V1.1 Section | V1.3.0 Section
|
||||
# ---------------------------------------------|-----------------------|-----------------------
|
||||
# Get Diagnostic Query / Get Diagnostic Answer | 10.11.2.3 / 10.11.2.4 | 10.11.2.3 / 10.11.2.4
|
||||
|
||||
pkts = pv.pkts
|
||||
pv.summary.show()
|
||||
|
||||
LEADER_RLOC16 = pv.vars['LEADER_RLOC16']
|
||||
ROUTER_1_RLOC16 = pv.vars['ROUTER_1_RLOC16']
|
||||
FED_1_RLOC16 = pv.vars['FED_1_RLOC16']
|
||||
MED_1_RLOC16 = pv.vars['MED_1_RLOC16']
|
||||
SED_1_RLOC16 = pv.vars['SED_1_RLOC16']
|
||||
|
||||
# Step 1: All
|
||||
# - Description: Ensure topology is formed correctly.
|
||||
# - Pass Criteria: N/A.
|
||||
print("Step 1: All")
|
||||
|
||||
# Step 2: Leader
|
||||
# - Description: Harness instructs the device to send DIAG_GET.query to the Realm-Local All-Thread-Nodes multicast
|
||||
# address for the following diagnostic TLV types:
|
||||
# - Topology A (Router DUT):
|
||||
# - TLV Type 0 - MAC Extended Address (64-bit)
|
||||
# - TLV Type 1 - MAC Address (16-bit)
|
||||
# - TLV Type 2 - Mode (Capability information)
|
||||
# - TLV Type 4 - Connectivity
|
||||
# - TLV Type 5 - Route64
|
||||
# - TLV Type 6 - Leader Data
|
||||
# - TLV Type 7 - Network Data
|
||||
# - TLV Type 8 - IPv6 address list
|
||||
# - TLV Type 16 - Child Table
|
||||
# - TLV Type 17 - Channel Pages
|
||||
# - Topology B (FED DUT):
|
||||
# - TLV Type 0 - MAC Extended Address (64-bit)
|
||||
# - TLV Type 1 - MAC Address (16-bit)
|
||||
# - TLV Type 2 - Mode (Capability information)
|
||||
# - TLV Type 6 - Leader Data
|
||||
# - TLV Type 7 - Network Data
|
||||
# - TLV Type 8 - IPv6 address list
|
||||
# - TLV Type 17 - Channel Pages
|
||||
# - Pass Criteria: N/A.
|
||||
print("Step 2: Leader")
|
||||
pkts.filter_wpan_src16(LEADER_RLOC16). \
|
||||
filter_coap_request(consts.DIAG_GET_QRY_URI). \
|
||||
filter(lambda p: {
|
||||
consts.DG_TYPE_LIST_TLV
|
||||
} <= set(p.coap.tlv.type)). \
|
||||
must_next()
|
||||
|
||||
# Step 3: Topology A (Router DUT)
|
||||
# - Description: Automatically responds with a DIAG_GET.ans response.
|
||||
# - Pass Criteria:
|
||||
# - The DIAG_GET.ans response MUST contain the requested diagnostic TLVs:
|
||||
# - CoAP Payload:
|
||||
# - TLV Type 0 - MAC Extended Address (64-bit)
|
||||
# - TLV Type 1 - MAC Address (16-bit)
|
||||
# - TLV Type 2 - Mode (Capability information)
|
||||
# - TLV Type 4 - Connectivity
|
||||
# - TLV Type 5 - Route64
|
||||
# - TLV Type 6 - Leader Data
|
||||
# - TLV Type 7 - Network Data
|
||||
# - TLV Type 8 - IPv6 address list
|
||||
# - TLV Type 16 - Child Table
|
||||
# - TLV Type 17 - Channel Pages
|
||||
# - The presence of each TLV MUST be validated. Where possible, the value of the TLVs MUST be validated.
|
||||
print("Step 3: Topology A (Router DUT)")
|
||||
with pkts.save_index():
|
||||
pkts.filter_wpan_src16(ROUTER_1_RLOC16). \
|
||||
filter_coap_request(consts.DIAG_GET_ANS_URI). \
|
||||
filter(lambda p: {
|
||||
consts.DG_MAC_EXTENDED_ADDRESS_TLV,
|
||||
consts.DG_MAC_ADDRESS_TLV,
|
||||
consts.DG_MODE_TLV,
|
||||
consts.DG_CONNECTIVITY_TLV,
|
||||
consts.DG_ROUTE64_TLV,
|
||||
consts.DG_LEADER_DATA_TLV,
|
||||
consts.DG_NETWORK_DATA_TLV,
|
||||
consts.DG_IPV6_ADDRESS_LIST_TLV,
|
||||
consts.DG_CHILD_TABLE_TLV,
|
||||
consts.DG_CHANNEL_PAGES_TLV
|
||||
} <= set(p.coap.tlv.type)). \
|
||||
filter(lambda p:
|
||||
p.coap.tlv.mac_addr == pv.vars['ROUTER_1'] and
|
||||
p.coap.tlv.rloc16 == ROUTER_1_RLOC16 and
|
||||
p.coap.tlv.mode == 0x0f and
|
||||
p.coap.tlv.leader_router_id == (LEADER_RLOC16 >> 10) and
|
||||
set(p.coap.tlv.ipv6_address) >= {pv.vars['ROUTER_1_RLOC'], pv.vars['ROUTER_1_MLEID']} and
|
||||
set(p.coap.tlv.child_id) >= {
|
||||
FED_1_RLOC16 & 0x1ff,
|
||||
MED_1_RLOC16 & 0x1ff,
|
||||
SED_1_RLOC16 & 0x1ff
|
||||
}
|
||||
). \
|
||||
must_next()
|
||||
|
||||
# Step 4: Topology A (Router DUT)
|
||||
# - Description: The DUT automatically multicasts the DIAG_GET.query frame.
|
||||
# - Pass Criteria:
|
||||
# - The DUT MUST use IEEE 802.15.4 indirect transmissions to forward the DIAG_GET.query to SED_1.
|
||||
print("Step 4: Topology A (Router DUT)")
|
||||
with pkts.save_index():
|
||||
pkts.filter_wpan_src16(ROUTER_1_RLOC16). \
|
||||
filter_wpan_dst16(SED_1_RLOC16). \
|
||||
filter_coap_request(consts.DIAG_GET_QRY_URI). \
|
||||
must_next()
|
||||
|
||||
# Step 5: Topology B (FED DUT)
|
||||
# - Description: The DUT automatically responds with DIAG_GET.ans.
|
||||
# - Pass Criteria:
|
||||
# - The DIAG_GET.ans response MUST contain the requested diagnostic TLVs:
|
||||
# - CoAP Payload:
|
||||
# - TLV Type 0 - MAC Extended Address (64-bit)
|
||||
# - TLV Type 1 - MAC Address (16-bit)
|
||||
# - TLV Type 2 - Mode (Capability information)
|
||||
# - TLV Type 6 - Leader Data
|
||||
# - TLV Type 7 - Network Data
|
||||
# - TLV Type 8 - IPv6 address list
|
||||
# - TLV Type 17 - Channel Pages
|
||||
# - The presence of each TLV MUST be validated. Where possible, the value of the TLVs MUST be validated.
|
||||
print("Step 5: Topology B (FED DUT)")
|
||||
with pkts.save_index():
|
||||
pkts.filter_wpan_src16(FED_1_RLOC16). \
|
||||
filter_coap_request(consts.DIAG_GET_ANS_URI). \
|
||||
filter(lambda p: {
|
||||
consts.DG_MAC_EXTENDED_ADDRESS_TLV,
|
||||
consts.DG_MAC_ADDRESS_TLV,
|
||||
consts.DG_MODE_TLV,
|
||||
consts.DG_LEADER_DATA_TLV,
|
||||
consts.DG_NETWORK_DATA_TLV,
|
||||
consts.DG_IPV6_ADDRESS_LIST_TLV,
|
||||
consts.DG_CHANNEL_PAGES_TLV
|
||||
} <= set(p.coap.tlv.type)). \
|
||||
filter(lambda p:
|
||||
p.coap.tlv.mac_addr == pv.vars['FED_1'] and
|
||||
p.coap.tlv.rloc16 == FED_1_RLOC16 and
|
||||
p.coap.tlv.mode == 0x0f and
|
||||
p.coap.tlv.leader_router_id == (LEADER_RLOC16 >> 10) and
|
||||
set(p.coap.tlv.ipv6_address) >= {pv.vars['FED_1_RLOC'], pv.vars['FED_1_MLEID']}
|
||||
). \
|
||||
must_next()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
verify_utils.run_main(verify)
|
||||
@@ -55,6 +55,8 @@ def thread_coap_tlv_parse(t, v):
|
||||
kvs.append(('target_eid', str(Ipv6Addr(v))))
|
||||
elif t == consts.DG_MAC_EXTENDED_ADDRESS_TLV and len(v) == 8:
|
||||
kvs.append(('mac_addr', v.hex()))
|
||||
elif t == consts.DG_MAC_ADDRESS_TLV and len(v) == 2:
|
||||
kvs.append(('rloc16', hex(struct.unpack('>H', v)[0])))
|
||||
elif t == consts.NL_MAC_EXTENDED_ADDRESS_TLV and len(v) == 8:
|
||||
kvs.append(('mac_addr', v.hex()))
|
||||
elif t == consts.NL_ML_EID_TLV and len(v) == 8:
|
||||
@@ -72,6 +74,9 @@ def thread_coap_tlv_parse(t, v):
|
||||
kvs.append(('mac_counter', str(val)))
|
||||
elif t == consts.DG_MODE_TLV and len(v) == 1:
|
||||
kvs.append(('mode', hex(v[0])))
|
||||
elif t == consts.DG_IPV6_ADDRESS_LIST_TLV:
|
||||
for i in range(0, len(v), 16):
|
||||
kvs.append(('ipv6_address', str(Ipv6Addr(v[i:i + 16]))))
|
||||
elif t == consts.DG_LEADER_DATA_TLV and len(v) == 8:
|
||||
# Leader data contains Partition ID (4), Weighting (1), Data Version (1), Stable Data Version (1), Leader Router ID (1)
|
||||
kvs.append(('partition_id', hex(struct.unpack('>I', v[0:4])[0])))
|
||||
@@ -80,12 +85,33 @@ def thread_coap_tlv_parse(t, v):
|
||||
# Route64 contains Router ID Sequence (1), and Router ID Mask (8), then link qualities
|
||||
kvs.append(('router_id_sequence', str(v[0])))
|
||||
kvs.append(('router_id_mask', v[1:9].hex()))
|
||||
elif t == consts.DG_CHILD_TABLE_TLV:
|
||||
# Child table contains a list of child entries.
|
||||
# Each entry: [Timeout(5 bits), LQI(2 bits), Child ID(9 bits), Mode(8 bits)] -> total 3 bytes
|
||||
for i in range(0, len(v), 3):
|
||||
if i + 3 <= len(v):
|
||||
timeout_child_id = struct.unpack('>H', v[i:i + 2])[0]
|
||||
child_id = timeout_child_id & 0x1ff
|
||||
mode = v[i + 2]
|
||||
kvs.append(('child_id', hex(child_id)))
|
||||
kvs.append(('child_mode', hex(mode)))
|
||||
elif t == consts.DG_CHANNEL_PAGES_TLV:
|
||||
kvs.append(('channel_pages', v.hex()))
|
||||
return kvs
|
||||
|
||||
|
||||
def apply_patches():
|
||||
CoapTlvParser.parse = staticmethod(thread_coap_tlv_parse)
|
||||
|
||||
from pktverify import layer_fields
|
||||
layer_fields._LAYER_FIELDS['coap.tlv.ipv6_address'] = layer_fields._list(layer_fields._ipv6_addr)
|
||||
layer_fields._LAYER_FIELDS['coap.tlv.rloc16'] = layer_fields._auto
|
||||
layer_fields._LAYER_FIELDS['coap.tlv.mode'] = layer_fields._auto
|
||||
layer_fields._LAYER_FIELDS['coap.tlv.leader_router_id'] = layer_fields._auto
|
||||
layer_fields._LAYER_FIELDS['coap.tlv.child_id'] = layer_fields._list(layer_fields._auto)
|
||||
layer_fields._LAYER_FIELDS['coap.tlv.child_mode'] = layer_fields._list(layer_fields._auto)
|
||||
layer_fields._LAYER_FIELDS['coap.tlv.channel_pages'] = layer_fields._bytes
|
||||
|
||||
def which_tshark_patch():
|
||||
default_path = '/tmp/thread-wireshark/tshark'
|
||||
if os.path.exists(default_path):
|
||||
|
||||
Reference in New Issue
Block a user