[nexus] add test 5.7.1 CoAP Diagnostic Get, Response, and Reset (#12456)

This commit adds a new Nexus test case for 'CoAP Diagnostic Get
Request, Response and Reset Commands' (5.7.1) as specified in the
test specification.

Summary of changes:
- Implemented Nexus test 5.7.1:
    - Added test_5_7_1.cpp: Sets up a network topology with a Leader,
      Router 1 (DUT), and various child nodes (FED, MED, SED, REED).
      Executes the 8-step test sequence by sending CoAP Diagnostic
      Get and Reset commands from the Leader to the DUT using direct
      method calls. Uses AllowList for topology management and sets
      log level to note.
    - Added verify_5_7_1.py: PCAP verification script for test 5.7.1.
      Validates the presence and values of requested Network
      Diagnostic TLVs in CoAP requests and responses. Ensures the
      DUT correctly handles requests for MAC Counters, Timeout
      (omitted), and Child Table, and verifies the reset functionality.
- Enhanced verification utilities:
    - Updated verify_utils.py: Added length checks during Thread TLV
      parsing in CoAP payloads to handle overlapping TLV types
      correctly and prevent verification failures.
- Updated build and execution scripts:
    - Modified CMakeLists.txt to build the new 5.7.1 test executable.
    - Updated run_nexus_tests.sh to include 5.7.1 in the default test
      list.
This commit is contained in:
Jonathan Hui
2026-02-16 21:35:59 -06:00
committed by GitHub
parent 1d97236a88
commit 295bd70514
6 changed files with 622 additions and 5 deletions
+1
View File
@@ -155,6 +155,7 @@ ot_nexus_test(5_5_4_1 "cert;nexus")
ot_nexus_test(5_5_4_2 "cert;nexus")
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_8_2 "cert;nexus")
ot_nexus_test(6_1_1 "cert;nexus")
+1
View File
@@ -85,6 +85,7 @@ DEFAULT_TESTS=(
"5_5_4_2"
"5_5_5"
"5_5_7"
"5_7_1"
"5_8_2"
"6_1_1_A"
"6_1_1_B"
+305
View File
@@ -0,0 +1,305 @@
/*
* 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 "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;
void Test5_7_1(void)
{
/**
* 5.7.1 CoAP Diagnostic Get Request, Response and Reset Commands
*
* 5.7.1.1 Topology
* - Topology A
* - Topology B
*
* 5.7.1.2 Purpose & Description
* These cases test the Diagnostic Get and Reset Commands as a part of the Network Management.
*
* Spec Reference | V1.1 Section | V1.3.0 Section
* --------------------|--------------|---------------
* Diagnostic Commands | 10.11.2 | 10.11.2
*/
Core nexus;
Node &dut = nexus.CreateNode();
Node &leader = nexus.CreateNode();
Node &fed1 = nexus.CreateNode();
Node &med1 = nexus.CreateNode();
Node &sed1 = nexus.CreateNode();
Node &reed1 = nexus.CreateNode();
dut.SetName("DUT");
leader.SetName("LEADER");
fed1.SetName("FED_1");
med1.SetName("MED_1");
sed1.SetName("SED_1");
reed1.SetName("REED_1");
nexus.AdvanceTime(0);
Instance::SetLogLevel(kLogLevelNote);
/**
* Step 1: All
* - Description: Ensure topology is formed correctly.
* - Pass Criteria: N/A
*/
Log("Step 1: All");
/** Use AllowList to specify links between nodes. */
dut.AllowList(leader);
dut.AllowList(fed1);
dut.AllowList(med1);
dut.AllowList(sed1);
dut.AllowList(reed1);
leader.AllowList(dut);
fed1.AllowList(dut);
med1.AllowList(dut);
sed1.AllowList(dut);
reed1.AllowList(dut);
leader.Form();
nexus.AdvanceTime(kFormNetworkTime);
dut.Join(leader);
nexus.AdvanceTime(kAttachToRouterTime);
VerifyOrQuit(dut.Get<Mle::Mle>().IsRouter());
fed1.Join(dut, Node::kAsFed);
med1.Join(dut, Node::kAsMed);
sed1.Join(dut, Node::kAsSed);
reed1.Join(dut, Node::kAsFtd);
nexus.AdvanceTime(kAttachToRouterTime);
nexus.AdvanceTime(kStabilizationTime);
const Ip6::Address &dutRloc = dut.Get<Mle::Mle>().GetMeshLocalRloc();
/**
* Step 2: Leader
* - Description: Harness instructs the device to send DIAG_GET.req to the DUTs Routing Locator (RLOC) for the
* following diagnostic TLV types:
* - 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 17 Channel Pages
* - Pass Criteria:
* - The DUT MUST respond with a DIAG_GET.rsp response containing the requested diagnostic TLVs:
* - CoAP Response Code: 2.04 Changed
* - 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 (required ONLY for Topology A)
* - 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.
* - Route64 TLV MUST be omitted in Topology B.
*/
Log("Step 2: Leader");
uint8_t tlvTypes2[] = {
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::kChannelPages,
};
SuccessOrQuit(leader.Get<NetworkDiagnostic::Client>().SendDiagnosticGet(dutRloc, tlvTypes2, sizeof(tlvTypes2),
nullptr, nullptr));
nexus.AdvanceTime(kDiagResponseTime);
/**
* Step 3: Leader
* - Description: Harness instructs the device to send DIAG_GET.req to the DUTs Routing Locator (RLOC) for the
* following diagnostic TLV type:
* - TLV Type 9 - MAC Counters
* - Pass Criteria:
* - The DUT MUST respond with a DIAG_GET.rsp response containing the requested diagnostic TLV:
* - CoAP Response Code: 2.04 Changed
* - CoAP Payload:
* - TLV Type 9 - MAC Counters
* - TLV Type 9 - MAC Counters MUST contain a list of MAC Counters.
*/
Log("Step 3: Leader");
uint8_t tlvTypes3[] = {NetworkDiagnostic::Tlv::kMacCounters};
SuccessOrQuit(leader.Get<NetworkDiagnostic::Client>().SendDiagnosticGet(dutRloc, tlvTypes3, sizeof(tlvTypes3),
nullptr, nullptr));
nexus.AdvanceTime(kDiagResponseTime);
/**
* Step 4: Leader
* - Description: Harness instructs the device to send DIAG_GET.req to the DUTs Routing Locator (RLOC) for the
* following diagnostic TLV type:
* - TLV Type 3 Timeout
* - Pass Criteria:
* - The DUT MUST respond with a DIAG_GET.rsp response containing the required diagnostic TLV payload:
* - CoAP Response Code: 2.04 Changed
* - CoAP Payload:
* - TLV Value 3 - Timeout MUST be omitted from the response.
*/
Log("Step 4: Leader");
uint8_t tlvTypes4[] = {NetworkDiagnostic::Tlv::kTimeout};
SuccessOrQuit(leader.Get<NetworkDiagnostic::Client>().SendDiagnosticGet(dutRloc, tlvTypes4, sizeof(tlvTypes4),
nullptr, nullptr));
nexus.AdvanceTime(kDiagResponseTime);
/**
* Step 5: Leader
* - Description: Harness instructs the device to send DIAG_GET.req to the DUTs Routing Locator (RLOC) for the
* following diagnostic TLV types:
* - TLV Type 14 Battery Level
* - TLV Type 15 Supply Voltage
* - Pass Criteria:
* - The DUT MUST respond with a DIAG_GET.rsp response optionally containing the requested diagnostic TLVs:
* - CoAP Response Code: 2.04 Changed
* - CoAP Payload:
* - TLV Type 14 Battery Level (optional)
* - TLV Type 15 Supply Voltage (optional)
*/
Log("Step 5: Leader");
uint8_t tlvTypes5[] = {NetworkDiagnostic::Tlv::kBatteryLevel, NetworkDiagnostic::Tlv::kSupplyVoltage};
SuccessOrQuit(leader.Get<NetworkDiagnostic::Client>().SendDiagnosticGet(dutRloc, tlvTypes5, sizeof(tlvTypes5),
nullptr, nullptr));
nexus.AdvanceTime(kDiagResponseTime);
/**
* Step 6: Leader
* - Description: Harness instructs the device to send DIAG_GET.req to the DUTs Routing Locator (RLOC) for the
* following diagnostic TLV type:
* - TLV Type 16 Child Table
* - Pass Criteria:
* - For Topology A:
* - CoAP Response Code: 2.04 Changed
* - CoAP Payload: TLV Type 16 Child Table. The content of the TLV MUST be correct.
* - For Topology B:
* - CoAP Response Code: 2.04 Changed
* - CoAP Payload: Empty
*/
Log("Step 6: Leader");
uint8_t tlvTypes6[] = {NetworkDiagnostic::Tlv::kChildTable};
SuccessOrQuit(leader.Get<NetworkDiagnostic::Client>().SendDiagnosticGet(dutRloc, tlvTypes6, sizeof(tlvTypes6),
nullptr, nullptr));
nexus.AdvanceTime(kDiagResponseTime);
/**
* Step 7: Leader
* - Description: Harness instructs the device to send DIAG_RST.ntf to DUTs Routing Locator (RLOC) for the
* following diagnostic TLV type:
* - TLV Type 9 - MAC Counters
* - Pass Criteria:
* - The DUT MUST respond with a CoAP response:
* - CoAP Response Code: 2.04 Changed
*/
Log("Step 7: Leader");
uint8_t tlvTypes7[] = {NetworkDiagnostic::Tlv::kMacCounters};
SuccessOrQuit(leader.Get<NetworkDiagnostic::Client>().SendDiagnosticReset(dutRloc, tlvTypes7, sizeof(tlvTypes7)));
nexus.AdvanceTime(kDiagResponseTime);
/**
* Step 8: Leader
* - Description: Harness instructs the device to send DIAG_GET.req to the DUTs Routing Locator (RLOC) for the
* following diagnostic TLV type:
* - TLV Type 9 - MAC Counters
* - Pass Criteria:
* - The DUT MUST respond with a DIAG_GET.rsp response containing the requested diagnostic TLV:
* - CoAP Response Code: 2.04 Changed
* - CoAP Payload:
* - TLV Type 9 - MAC Counters
* - TLV Type 9 - MAC Counters MUST contain a list of MAC Counters with 0 value or less than value returned in
* step 3.
*/
Log("Step 8: Leader");
uint8_t tlvTypes8[] = {NetworkDiagnostic::Tlv::kMacCounters};
SuccessOrQuit(leader.Get<NetworkDiagnostic::Client>().SendDiagnosticGet(dutRloc, tlvTypes8, sizeof(tlvTypes8),
nullptr, nullptr));
nexus.AdvanceTime(kDiagResponseTime);
nexus.SaveTestInfo("test_5_7_1.json");
}
} // namespace Nexus
} // namespace ot
int main(void)
{
ot::Nexus::Test5_7_1();
printf("All tests passed\n");
return 0;
}
+286
View File
@@ -0,0 +1,286 @@
#!/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
from pktverify.null_field import nullField
def verify(pv):
# 5.7.1 CoAP Diagnostic Get Request, Response and Reset Commands
#
# 5.7.1.1 Topology
# - Topology A
# - Topology B
#
# 5.7.1.2 Purpose & Description
# These cases test the Diagnostic Get and Reset Commands as a part of the Network Management.
#
# Spec Reference | V1.1 Section | V1.3.0 Section
# --------------------|--------------|---------------
# Diagnostic Commands | 10.11.2 | 10.11.2
pkts = pv.pkts
pv.summary.show()
DUT = pv.vars['DUT']
DUT_RLOC = pv.vars['DUT_RLOC']
LEADER = pv.vars['LEADER']
LEADER_RLOC = pv.vars['LEADER_RLOC']
# Step 1: All
# - Description: Ensure topology is formed correctly.
# - Pass Criteria: N/A
print("Step 1: Ensure topology is formed correctly.")
# Step 2: Leader
# - Description: Harness instructs the device to send DIAG_GET.req to the DUTs Routing Locator (RLOC) for the
# following diagnostic TLV types:
# - 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 17 Channel Pages
# - Pass Criteria:
# - The DUT MUST respond with a DIAG_GET.rsp response containing the requested diagnostic TLVs:
# - CoAP Response Code: 2.04 Changed
# - 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 (required ONLY for Topology A)
# - 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.
# - Route64 TLV MUST be omitted in Topology B.
print("Step 2: Leader sends DIAG_GET.req and DUT responds with all requested TLVs.")
pkts.filter_wpan_src64(LEADER).\
filter_ipv6_dst(DUT_RLOC).\
filter_coap_request(consts.DIAG_GET_URI).\
filter(lambda p: p.coap.tlv.type is not nullField and\
consts.DG_TYPE_LIST_TLV in p.coap.tlv.type).\
must_next()
pkts.filter_wpan_src64(DUT).\
filter_ipv6_dst(LEADER_RLOC).\
filter_coap_ack(consts.DIAG_GET_URI).\
filter(lambda p: p.coap.tlv.type is not nullField and\
{\
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_CHANNEL_PAGES_TLV\
} <= set(p.coap.tlv.type)).\
filter(lambda p: p.coap.tlv.mac_addr == DUT).\
filter(lambda p: p.coap.tlv.mode is not nullField).\
filter(lambda p: p.coap.tlv.leader_router_id is not nullField).\
must_next()
# Step 3: Leader
# - Description: Harness instructs the device to send DIAG_GET.req to the DUTs Routing Locator (RLOC) for the
# following diagnostic TLV type:
# - TLV Type 9 - MAC Counters
# - Pass Criteria:
# - The DUT MUST respond with a DIAG_GET.rsp response containing the requested diagnostic TLV:
# - CoAP Response Code: 2.04 Changed
# - CoAP Payload:
# - TLV Type 9 - MAC Counters
# - TLV Type 9 - MAC Counters MUST contain a list of MAC Counters.
print("Step 3: Leader sends DIAG_GET.req for MAC Counters.")
pkts.filter_wpan_src64(LEADER).\
filter_ipv6_dst(DUT_RLOC).\
filter_coap_request(consts.DIAG_GET_URI).\
filter(lambda p: p.coap.tlv.type is not nullField and\
consts.DG_TYPE_LIST_TLV in p.coap.tlv.type).\
must_next()
p3 = pkts.filter_wpan_src64(DUT).\
filter_ipv6_dst(LEADER_RLOC).\
filter_coap_ack(consts.DIAG_GET_URI).\
filter(lambda p: p.coap.tlv.type is not nullField and\
consts.DG_MAC_COUNTERS_TLV in p.coap.tlv.type).\
filter(lambda p: p.coap.tlv.mac_counter is not nullField and\
len(p.coap.tlv.mac_counter) >= 9).\
must_next()
# Capture MAC counters from step 3 for comparison in step 8
mac_counters_step_3 = [int(val) for val in p3.coap.tlv.mac_counter]
# Step 4: Leader
# - Description: Harness instructs the device to send DIAG_GET.req to the DUTs Routing Locator (RLOC) for the
# following diagnostic TLV type:
# - TLV Type 3 Timeout
# - Pass Criteria:
# - The DUT MUST respond with a DIAG_GET.rsp response containing the required diagnostic TLV payload:
# - CoAP Response Code: 2.04 Changed
# - CoAP Payload:
# - TLV Value 3 - Timeout MUST be omitted from the response.
print("Step 4: Leader sends DIAG_GET.req for Timeout (expected to be omitted).")
pkts.filter_wpan_src64(LEADER).\
filter_ipv6_dst(DUT_RLOC).\
filter_coap_request(consts.DIAG_GET_URI).\
filter(lambda p: p.coap.tlv.type is not nullField and\
consts.DG_TYPE_LIST_TLV in p.coap.tlv.type).\
must_next()
pkts.filter_wpan_src64(DUT).\
filter_ipv6_dst(LEADER_RLOC).\
filter_coap_ack(consts.DIAG_GET_URI).\
filter(lambda p: p.coap.tlv.type is nullField or\
consts.DG_TIMEOUT_TLV not in p.coap.tlv.type).\
must_next()
# Step 5: Leader
# - Description: Harness instructs the device to send DIAG_GET.req to the DUTs Routing Locator (RLOC) for the
# following diagnostic TLV types:
# - TLV Type 14 Battery Level
# - TLV Type 15 Supply Voltage
# - Pass Criteria:
# - The DUT MUST respond with a DIAG_GET.rsp response optionally containing the requested diagnostic TLVs:
# - CoAP Response Code: 2.04 Changed
# - CoAP Payload:
# - TLV Type 14 Battery Level (optional)
# - TLV Type 15 Supply Voltage (optional)
print("Step 5: Leader sends DIAG_GET.req for Battery Level and Supply Voltage.")
pkts.filter_wpan_src64(LEADER).\
filter_ipv6_dst(DUT_RLOC).\
filter_coap_request(consts.DIAG_GET_URI).\
filter(lambda p: p.coap.tlv.type is not nullField and\
consts.DG_TYPE_LIST_TLV in p.coap.tlv.type).\
must_next()
pkts.filter_wpan_src64(DUT).\
filter_ipv6_dst(LEADER_RLOC).\
filter_coap_ack(consts.DIAG_GET_URI).\
must_next()
# Step 6: Leader
# - Description: Harness instructs the device to send DIAG_GET.req to the DUTs Routing Locator (RLOC) for the
# following diagnostic TLV type:
# - TLV Type 16 Child Table
# - Pass Criteria:
# - For Topology A:
# - CoAP Response Code: 2.04 Changed
# - CoAP Payload: TLV Type 16 Child Table. The content of the TLV MUST be correct.
# - For Topology B:
# - CoAP Response Code: 2.04 Changed
# - CoAP Payload: Empty
print("Step 6: Leader sends DIAG_GET.req for Child Table.")
pkts.filter_wpan_src64(LEADER).\
filter_ipv6_dst(DUT_RLOC).\
filter_coap_request(consts.DIAG_GET_URI).\
filter(lambda p: p.coap.tlv.type is not nullField and\
consts.DG_TYPE_LIST_TLV in p.coap.tlv.type).\
must_next()
pkts.filter_wpan_src64(DUT).\
filter_ipv6_dst(LEADER_RLOC).\
filter_coap_ack(consts.DIAG_GET_URI).\
filter(lambda p: p.coap.tlv.type is not nullField and\
consts.DG_CHILD_TABLE_TLV in p.coap.tlv.type).\
must_next()
# Step 7: Leader
# - Description: Harness instructs the device to send DIAG_RST.ntf to DUTs Routing Locator (RLOC) for the
# following diagnostic TLV type:
# - TLV Type 9 - MAC Counters
# - Pass Criteria:
# - The DUT MUST respond with a CoAP response:
# - CoAP Response Code: 2.04 Changed
print("Step 7: Leader sends DIAG_RST.ntf for MAC Counters.")
pkts.filter_wpan_src64(LEADER).\
filter_ipv6_dst(DUT_RLOC).\
filter_coap_request(consts.DIAG_RST_URI).\
filter(lambda p: p.coap.tlv.type is not nullField and\
consts.DG_TYPE_LIST_TLV in p.coap.tlv.type).\
must_next()
pkts.filter_wpan_src64(DUT).\
filter_ipv6_dst(LEADER_RLOC).\
filter_coap_ack(consts.DIAG_RST_URI).\
must_next()
# Step 8: Leader
# - Description: Harness instructs the device to send DIAG_GET.req to the DUTs Routing Locator (RLOC) for the
# following diagnostic TLV type:
# - TLV Type 9 - MAC Counters
# - Pass Criteria:
# - The DUT MUST respond with a DIAG_GET.rsp response containing the requested diagnostic TLV:
# - CoAP Response Code: 2.04 Changed
# - CoAP Payload:
# - TLV Type 9 - MAC Counters
# - TLV Type 9 - MAC Counters MUST contain a list of MAC Counters with 0 value or less than value returned in
# step 3.
print("Step 8: Leader sends DIAG_GET.req for MAC Counters (verify reset).")
pkts.filter_wpan_src64(LEADER).\
filter_ipv6_dst(DUT_RLOC).\
filter_coap_request(consts.DIAG_GET_URI).\
filter(lambda p: p.coap.tlv.type is not nullField and\
consts.DG_TYPE_LIST_TLV in p.coap.tlv.type).\
must_next()
p8 = pkts.filter_wpan_src64(DUT).\
filter_ipv6_dst(LEADER_RLOC).\
filter_coap_ack(consts.DIAG_GET_URI).\
filter(lambda p: p.coap.tlv.type is not nullField and\
consts.DG_MAC_COUNTERS_TLV in p.coap.tlv.type).\
filter(lambda p: p.coap.tlv.mac_counter is not nullField and\
len(p.coap.tlv.mac_counter) >= 9).\
must_next()
# Verify MAC counters were reset (sum of counters should be less than before, or most should be 0)
mac_counters_step_8 = [int(val) for val in p8.coap.tlv.mac_counter]
for i in range(len(mac_counters_step_3)):
assert mac_counters_step_8[i] <= mac_counters_step_3[i], \
f"MAC counter {i} increased after reset: {mac_counters_step_3[i]} -> {mac_counters_step_8[i]}"
assert sum(mac_counters_step_8) <= sum(mac_counters_step_3), "Total MAC counters increased after reset"
if __name__ == '__main__':
verify_utils.run_main(verify)
+22 -5
View File
@@ -51,18 +51,35 @@ from pktverify.bytes import Bytes
# Monkey-patch CoapTlvParser to parse Thread TLVs in CoAP payload
def thread_coap_tlv_parse(t, v):
kvs = []
if t == consts.NL_TARGET_EID_TLV:
if t == consts.NL_TARGET_EID_TLV and len(v) == 16:
kvs.append(('target_eid', str(Ipv6Addr(v))))
elif t == consts.NL_MAC_EXTENDED_ADDRESS_TLV:
elif t == consts.DG_MAC_EXTENDED_ADDRESS_TLV and len(v) == 8:
kvs.append(('mac_addr', v.hex()))
elif t == consts.NL_ML_EID_TLV:
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:
kvs.append(('ml_eid', Bytes(v).format_hextets()))
elif t == consts.NL_RLOC16_TLV:
elif t == consts.NL_RLOC16_TLV and len(v) == 2:
kvs.append(('rloc16', hex(struct.unpack('>H', v)[0])))
elif t == consts.NL_STATUS_TLV:
elif t == consts.NL_STATUS_TLV and len(v) == 1:
kvs.append(('status', str(v[0])))
elif t == consts.NL_ROUTER_MASK_TLV:
kvs.append(('router_mask', v.hex()))
elif t == consts.DG_MAC_COUNTERS_TLV:
# MAC counters are a list of 4-byte values
for i in range(0, len(v), 4):
val = struct.unpack('>I', v[i:i + 4])[0]
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_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])))
kvs.append(('leader_router_id', str(v[7])))
elif t == consts.DG_ROUTE64_TLV:
# 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()))
return kvs
@@ -528,6 +528,13 @@ _LAYER_FIELDS = {
'coap.tlv.ext_mac_addr': _ext_addr,
'coap.tlv.router_mask_assigned': _auto,
'coap.tlv.router_mask_id_seq': _auto,
'coap.tlv.mac_addr': _ext_addr,
'coap.tlv.mode': _auto,
'coap.tlv.partition_id': _auto,
'coap.tlv.leader_router_id': _auto,
'coap.tlv.router_id_sequence': _auto,
'coap.tlv.router_id_mask': _str,
'coap.tlv.mac_counter': _list(_auto),
# dtls
'dtls.handshake.type': _list(_auto),