diff --git a/tests/nexus/CMakeLists.txt b/tests/nexus/CMakeLists.txt index 4a1fe0f4d..0f66f9fb3 100644 --- a/tests/nexus/CMakeLists.txt +++ b/tests/nexus/CMakeLists.txt @@ -199,6 +199,7 @@ ot_nexus_test(9_2_2 "cert;nexus") ot_nexus_test(9_2_3 "cert;nexus") ot_nexus_test(9_2_4 "cert;nexus") ot_nexus_test(9_2_5 "cert;nexus") +ot_nexus_test(9_2_6 "cert;nexus") # Misc tests ot_nexus_test(border_admitter "core;nexus") diff --git a/tests/nexus/run_nexus_tests.sh b/tests/nexus/run_nexus_tests.sh index 6b8043a84..d3a731f56 100755 --- a/tests/nexus/run_nexus_tests.sh +++ b/tests/nexus/run_nexus_tests.sh @@ -135,6 +135,7 @@ DEFAULT_TESTS=( "9_2_3" "9_2_4" "9_2_5" + "9_2_6" ) # Use provided arguments or the default test list diff --git a/tests/nexus/test_9_2_6.cpp b/tests/nexus/test_9_2_6.cpp new file mode 100644 index 000000000..058847b96 --- /dev/null +++ b/tests/nexus/test_9_2_6.cpp @@ -0,0 +1,735 @@ +/* + * 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 +#include + +#include "mac/data_poll_sender.hpp" +#include "meshcop/commissioner.hpp" +#include "meshcop/dataset_manager.hpp" +#include "meshcop/meshcop_tlvs.hpp" +#include "platform/nexus_core.hpp" +#include "platform/nexus_node.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 a network, in milliseconds. + */ +static constexpr uint32_t kJoinTime = 200 * 1000; + +/** + * Time to advance for a commissioner to become active, in milliseconds. + */ +static constexpr uint32_t kPetitionTime = 5 * 1000; + +/** + * Time to wait for a response, in milliseconds. + */ +static constexpr uint32_t kResponseTime = 5000; + +/** + * Time to wait for MLE Data propagation, in milliseconds. + */ +static constexpr uint32_t kDataPropagationTime = 10000; + +/** + * Time for Delay Timer, in milliseconds (1 minute). + */ +static constexpr uint32_t kDelayTimerTime = 60 * 1000; + +/** + * Time to wait for ICMPv6 Echo response, in milliseconds. + */ +static constexpr uint32_t kEchoTimeout = 5000; + +/** + * Primary and Secondary channels. + */ +static constexpr uint16_t kPrimaryChannel = 11; +static constexpr uint16_t kSecondaryChannel = 12; + +/** + * Network Name and PSKc. + */ +static const char kNetworkName[] = "Thread"; +static const uint8_t kPskc[] = {0x74, 0x68, 0x72, 0x65, 0x61, 0x64, 0x6a, 0x70, + 0x61, 0x6b, 0x65, 0x74, 0x65, 0x73, 0x74, 0x02}; + +/** + * Timestamps. + */ +static constexpr uint64_t kActiveTimestampInitial = 10; +static constexpr uint64_t kActiveTimestampNew = 15; +static constexpr uint64_t kActiveTimestampFinal = 75; +static constexpr uint64_t kPendingTimestamp = 30; + +void Test9_2_6(void) +{ + /** + * 9.2.6 Commissioning - Dissemination of Operational Datasets + * + * 9.2.6.1 Topology + * - DUT as Leader (Topology A) + * - DUT as Router (Topology B) + * - DUT as MED/SED (Topologies C and D) + * + * Note: Two sniffers are required to run this test case! + * + * 9.2.6.2 Purpose & Description + * - DUT as Leader (Topology A): The purpose of this test case is to verify that the Leader device properly collects + * and disseminates Operational Datasets through a Thread network. + * - DUT as Router (Topology B): The purpose of this test case is to show that the Router device correctly sets the + * Commissioning information propagated by the Leader device and sends it properly to devices already attached to + * it. + * - DUT as MED/SED (Topologies C and D): + * - MED - requires full network data + * - SED - requires only stable network data + * - Set on Leader: Active TimeStamp = 10s + * + * Spec Reference | V1.1 Section | V1.3.0 Section + * ---------------------------------------------------|---------------|--------------- + * Updating the Active / Pending Operational Dataset | 8.7.4 / 8.7.5 | 8.7.4 / 8.7.5 + */ + + Core nexus; + + Node &leader = nexus.CreateNode(); + Node &commissioner = nexus.CreateNode(); + Node &router1 = nexus.CreateNode(); + Node &med1 = nexus.CreateNode(); + Node &sed1 = nexus.CreateNode(); + + leader.SetName("LEADER"); + commissioner.SetName("COMMISSIONER"); + router1.SetName("ROUTER_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 + */ + + leader.AllowList(commissioner); + leader.AllowList(router1); + commissioner.AllowList(leader); + router1.AllowList(leader); + router1.AllowList(med1); + router1.AllowList(sed1); + med1.AllowList(router1); + sed1.AllowList(router1); + + { + MeshCoP::Dataset::Info datasetInfo; + MeshCoP::Timestamp timestamp; + + datasetInfo.Clear(); + SuccessOrQuit(datasetInfo.GenerateRandom(leader.GetInstance())); + datasetInfo.Set(kPrimaryChannel); + timestamp.SetSeconds(kActiveTimestampInitial); + datasetInfo.Set(timestamp); + + leader.Get().SaveLocal(datasetInfo); + leader.Get().Up(); + SuccessOrQuit(leader.Get().Start()); + } + nexus.AdvanceTime(kFormNetworkTime); + VerifyOrQuit(leader.Get().IsLeader()); + + commissioner.Join(leader); + router1.Join(leader); + nexus.AdvanceTime(kJoinTime); + VerifyOrQuit(commissioner.Get().IsAttached()); + VerifyOrQuit(router1.Get().IsRouter()); + + med1.Join(router1, Node::kAsMed); + sed1.Join(router1, Node::kAsSed); + SuccessOrQuit(sed1.Get().SetExternalPollPeriod(500)); + nexus.AdvanceTime(kJoinTime); + VerifyOrQuit(med1.Get().IsAttached()); + VerifyOrQuit(sed1.Get().IsAttached()); + + SuccessOrQuit(commissioner.Get().Start(nullptr, nullptr, nullptr)); + nexus.AdvanceTime(kPetitionTime); + VerifyOrQuit(commissioner.Get().IsActive()); + + uint16_t sessionId = commissioner.Get().GetSessionId(); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 2: Commissioner"); + + /** + * Step 2: Commissioner + * - Description: Harness instructs Commissioner to send MGMT_COMMISSIONER_SET.req to the Leader Anycast or Routing + * Locator: + * - CoAP URI-Path: coap (S)://[]:MM/c/cs + * - CoAP Payload: Commissioner Session ID TLV (valid value), Steering Data TLV (allowed TLV) + * - Pass Criteria: N/A + */ + + { + Tmf::Agent &agent = commissioner.Get(); + Coap::Message *message = agent.NewPriorityConfirmablePostMessage(kUriCommissionerSet); + VerifyOrQuit(message != nullptr); + + SuccessOrQuit(Tlv::Append(*message, sessionId)); + { + MeshCoP::SteeringData steeringData; + steeringData.SetToPermitAllJoiners(); + SuccessOrQuit( + Tlv::Append(*message, steeringData.GetData(), steeringData.GetLength())); + } + + Tmf::MessageInfo messageInfo(commissioner.GetInstance()); + messageInfo.SetSockAddrToRlocPeerAddrToLeaderAloc(); + SuccessOrQuit(agent.SendMessage(*message, messageInfo)); + } + nexus.AdvanceTime(kResponseTime); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 3: Leader"); + + /** + * Step 3: Leader + * - Description: Automatically sends MGMT_COMMISSIONER_SET.rsp to the Commissioner. + * - Pass Criteria: For DUT = Leader: The DUT MUST send MGMT_COMMISSIONER_SET.rsp with the following format: + * - CoAP Response Code: 2.04 Changed + * - CoAP Payload: State TLV + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 4: Leader"); + + /** + * Step 4: Leader + * - Description: Automatically sends new network data to neighbors and rx-on-when-idle Children (MED_1) via a + * multicast MLE Data Response. + * - Pass Criteria: For DUT = Leader: The DUT MUST send a multicast MLE Data Response to the Link-Local All Nodes + * multicast address (FF02::1) with the new information, including the following TLVs: + * - Source Address TLV + * - Leader Data TLV: Data Version field , Stable Data Version field + * - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + * Session ID TLV, Steering Data TLV + * - Active Timestamp TLV + */ + + nexus.AdvanceTime(kDataPropagationTime); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 5: Router_1"); + + /** + * Step 5: Router_1 + * - Description: Automatically sends new network data to neighbors and rx-on-when-idle Children (MED_1) via a + * multicast MLE Data Response. + * - Pass Criteria: For DUT = Router: The DUT MUST send a multicast MLE Data Response with the new information, + * including the following TLVs: + * - Source Address TLV + * - Leader Data TLV: Data Version field , Stable Data Version field + * - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + * Session ID TLV, Steering Data TLV + * - Active Timestamp TLV + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 6: Router_1"); + + /** + * Step 6: Router_1 + * - Description: No update is sent to SED_1 because Stable Data Version is unchanged. + * - Pass Criteria: For DUT = Router: The DUT MUST NOT send a unicast MLE Data Response or MLE Child Update Request + * to SED_1. + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 7: Commissioner"); + + /** + * Step 7: Commissioner + * - Description: Harness instructs the Commissioner to send MGMT_ACTIVE_SET.req to the Leader Anycast or Routing + * Locator: + * - CoAP Request: coap://[]:MM/c/as + * - CoAP Payload: valid Commissioner Session ID TLV, Active Timestamp TLV : 15s, Network Name TLV : Thread, + * PSKc TLV: 74:68:72:65:61:64:6a:70:61:6b:65:74:65:73:74:02 (new value) + * - Pass Criteria: N/A + */ + + { + Tmf::Agent &agent = commissioner.Get(); + Coap::Message *message = agent.NewPriorityConfirmablePostMessage(kUriActiveSet); + VerifyOrQuit(message != nullptr); + + SuccessOrQuit(Tlv::Append(*message, sessionId)); + { + MeshCoP::Timestamp timestamp; + timestamp.SetSeconds(kActiveTimestampNew); + SuccessOrQuit(Tlv::Append(*message, timestamp)); + } + SuccessOrQuit(Tlv::Append(*message, kNetworkName)); + SuccessOrQuit(Tlv::Append(*message, AsCoreType(reinterpret_cast(kPskc)))); + + Tmf::MessageInfo messageInfo(commissioner.GetInstance()); + messageInfo.SetSockAddrToRlocPeerAddrToLeaderAloc(); + SuccessOrQuit(agent.SendMessage(*message, messageInfo)); + } + nexus.AdvanceTime(kResponseTime); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 8: Leader"); + + /** + * Step 8: Leader + * - Description: Automatically sends MGMT_ACTIVE_SET.rsp to the Commissioner with Status = Accept. + * - Pass Criteria: For DUT = Leader: The DUT MUST send a MGMT_ACTIVE_SET.rsp frame with the following format: + * - CoAP Response Code: 2.04 Changed + * - CoAP Payload: State TLV + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 9: Leader"); + + /** + * Step 9: Leader + * - Description: Automatically sends new network data to neighbors via a multicast MLE Data Response. + * - Pass Criteria: For DUT = Leader: The DUT MUST send a multicast MLE Data Response to the Link-Local All Nodes + * multicast address (FF02::1) with the new information, including the following TLVs: + * - Source Address TLV + * - Leader Data TLV: Data Version field , Stable Data Version field + * - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + * Session ID TLV, Steering Data TLV + * - Active Timestamp TLV: 15s + */ + + nexus.AdvanceTime(kDataPropagationTime); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 10: Router_1"); + + /** + * Step 10: Router_1 + * - Description: Automatically requests the full network data from the Leader via a unicast MLE Data Request. + * - Pass Criteria: For DUT = Router: The DUT MUST send a unicast MLE Data Request to the Leader, which includes the + * following TLVs: + * - TLV Request TLV: Network Data TLV + * - Active Timestamp TLV + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 11: Leader"); + + /** + * Step 11: Leader + * - Description: Automatically sends the requested full network data to Router_1 via a unicast MLE Data Response. + * - Pass Criteria: For DUT = Leader: The DUT MUST send a unicast MLE Data Response to Router_1 including the + * following TLVs: + * - Source Address TLV + * - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + * step 9 + * - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + * Session ID TLV, Steering Data TLV + * - Active Timestamp TLV + * - Active Operational Dataset TLV (MUST NOT contain the Active Timestamp TLV): Channel TLV, Channel Mask TLV, + * Extended PAN ID TLV, Network Mesh-Local Prefix TLV, Network Master Key TLV, Network Name TLV , PAN + * ID TLV, PSKc TLV, Security Policy TLV + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 12: Router_1"); + + /** + * Step 12: Router_1 + * - Description: Automatically sends the full network data to neighbors and rx-on-while-idle Children (MED_1) via a + * multicast MLE Data Response. + * - Pass Criteria: For DUT = Router: The DUT MUST send a multicast MLE Data Response with the new information, + * including the following TLVs: + * - Source Address TLV + * - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + * step 9 + * - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + * Session ID TLV, Steering Data TLV + * - Active Timestamp TLV <15s> + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 13: MED_1"); + + /** + * Step 13: MED_1 + * - Description: Automatically requests full network data from Router_1 via a unicast MLE Data Request. + * - Pass Criteria: For DUT = MED: The DUT MUST send a unicast MLE Data Request to Router_1, including the following + * TLVs: + * - TLV Request TLV: Network Data TLV + * - Active Timestamp TLV + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 14: Router_1"); + + /** + * Step 14: Router_1 + * - Description: Automatically sends full network data to MED_1 via a unicast MLE Data Response. + * - Pass Criteria: For DUT = Router: The DUT MUST send a unicast MLE Data Response to MED_1, which includes the + * following TLVs: + * - Source Address TLV + * - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + * step 9. + * - Network Data TLV: Commissioning Data TLV:: Stable flag , Commissioner Session ID TLV, Border Agent + * Locator TLV, Steering Data TLV + * - Active Timestamp TLV (new value) + * - Active Operational Dataset TLV (MUST NOT contain the Active Timestamp TLV): Channel TLV, Channel Mask TLV, + * Extended PAN ID TLV, Network Mesh-Local Prefix TLV, Network Master Key TLV, Network Name TLV (New Value), PAN + * ID TLV, PSKc TLV, Security Policy TLV + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 15A: Router_1"); + + /** + * Step 15A: Router_1 + * - Description: Automatically sends notification of new network data to SED_1 via a unicast MLE Child Update + * Request. + * - Pass Criteria: For DUT = Router: The DUT MUST send MLE Child Update Request to SED_1, including the following + * TLVs: + * - Source Address TLV + * - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + * step 9 + * - Network Data TLV + * - Active Timestamp TLV <15s> + * - Goto step 16 + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 15B: Router_1"); + + /** + * Step 15B: Router_1 + * - Description: Automatically sends notification of new network data to SED_1 via a unicast MLE Data Response. + * - Pass Criteria: For DUT = Router: The DUT MUST send MLE Data Response to SED_1, including the following TLVs: + * - Source Address TLV + * - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + * step 9 + * - Network Data TLV + * - Active Timestamp TLV <15s> + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 16: SED_1"); + + /** + * Step 16: SED_1 + * - Description: Automatically requests the full network data from Router_1 via a unicast MLE Data Request. + * - Pass Criteria: For DUT = SED: The DUT MUST send a unicast MLE Data Request to Router_1, including the following + * TLVs: + * - TLV Request TLV: Network Data TLV + * - Active Timestamp TLV + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 17: Router_1"); + + /** + * Step 17: Router_1 + * - Description: Automatically sends the requested full network data to SED_1. + * - Pass Criteria: For DUT = Router: The DUT MUST send a unicast MLE Data Response to SED_1, including the + * following TLVs: + * - Source Address TLV + * - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + * step 9 + * - Network Data TLV + * - Active Timestamp TLV <15s> + * - Active Operational Dataset TLV (MUST NOT contain the Active Timestamp TLV): Channel TLV, Channel Mask TLV, + * Extended PAN ID TLV, Network Mesh-Local Prefix TLV, Network Master Key TLV, Network Name TLV , PAN + * ID TLV, PSKc TLV, Security Policy TLV. + */ + + nexus.AdvanceTime(kDataPropagationTime); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 18: Commissioner"); + + /** + * Step 18: Commissioner + * - Description: Harness instructs Commissioner to send MGMT_PENDING_SET.req to the Leader Anycast or Routing + * Locator: + * - CoAP Request: coap://[]:MM/c/ps + * - CoAP Payload: Commissioner Session ID TLV , Pending Timestamp TLV <30s>, Active Timestamp TLV + * <75s>, Delay Timer TLV <1 min>, Channel TLV + * - Pass Criteria: N/A + */ + + { + Tmf::Agent &agent = commissioner.Get(); + Coap::Message *message = agent.NewPriorityConfirmablePostMessage(kUriPendingSet); + VerifyOrQuit(message != nullptr); + + SuccessOrQuit(Tlv::Append(*message, sessionId)); + { + MeshCoP::Timestamp timestamp; + timestamp.SetSeconds(kActiveTimestampFinal); + SuccessOrQuit(Tlv::Append(*message, timestamp)); + } + { + MeshCoP::Timestamp timestamp; + timestamp.SetSeconds(kPendingTimestamp); + SuccessOrQuit(Tlv::Append(*message, timestamp)); + } + SuccessOrQuit(Tlv::Append(*message, kDelayTimerTime)); + SuccessOrQuit(Tlv::Append(*message, Mle::ChannelTlvValue(kSecondaryChannel))); + + Tmf::MessageInfo messageInfo(commissioner.GetInstance()); + messageInfo.SetSockAddrToRlocPeerAddrToLeaderAloc(); + SuccessOrQuit(agent.SendMessage(*message, messageInfo)); + } + nexus.AdvanceTime(kResponseTime); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 19: Leader"); + + /** + * Step 19: Leader + * - Description: Automatically sends MGMT_PENDING_SET.rsp to the Commissioner with Status = Accept. + * - Pass Criteria: For DUT = Leader: The Leader MUST send MGMT_PENDING_SET.rsp frame to the Commissioner with the + * following format: + * - CoAP Response Code: 2.04 Changed + * - CoAP Payload: State TLV + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 20: Leader"); + + /** + * Step 20: Leader + * - Description: Automatically sends new network data to neighbors via a multicast MLE Data Response. + * - Pass Criteria: For DUT = Leader: The DUT MUST multicast a MLE Data Response with the new information, including + * the following TLVs: + * - Source Address TLV + * - Leader Data TLV: Data version field , Stable Version field + * - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + * Session ID TLV, Steering Data TLV + * - Active Timestamp TLV + * - Pending Timestamp TLV + */ + + nexus.AdvanceTime(kDataPropagationTime); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 21: Router_1"); + + /** + * Step 21: Router_1 + * - Description: Automatically requests full network data from the Leader via a unicast MLE Data Request. + * - Pass Criteria: For DUT = Router_1: The DUT MUST send a unicast MLE Data Request to the Leader, including the + * following TLVs: + * - Request TLV: Network Data TLV + * - Active Timestamp TLV + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 22: Leader"); + + /** + * Step 22: Leader + * - Description: Automatically sends full network data to Router_1 via a unicast MLE Data Response. + * - Pass Criteria: For DUT = Leader: The DUT MUST send a unicast MLE Data Response to Router_1, including the + * following TLVs: + * - Source Address TLV + * - Leader Data TLV + * - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + * Session ID TLV, Steering Data TLV + * - Pending Operational Dataset TLV + * - Active Timestamp TLV + * - Pending Timestamp TLV + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 23: Router_1"); + + /** + * Step 23: Router_1 + * - Description: Automatically sends new network data to neighbors and rx-on-when-idle Children via a multicast MLE + * Data Response. + * - Pass Criteria: For DUT = Router: The DUT MUST multicast a MLE Data Response with the new information, including + * the following TLVs: + * - Source Address TLV + * - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + * step 20 + * - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + * Session ID TLV, Steering Data TLV + * - Active Timestamp TLV <15s> + * - Pending Timestamp TLV <30s> + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 24: MED_1"); + + /** + * Step 24: MED_1 + * - Description: Automatically requests full network data from Router_1 via a unicast MLE Data Request. + * - Pass Criteria: For DUT = MED: The DUT MUST send a unicast MLE Data Request to Router_1 including the following + * TLVs: + * - TLV Request TLV: Network Data TLV + * - Active Timestamp TLV + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 25: Router_1"); + + /** + * Step 25: Router_1 + * - Description: Automatically sends full network data to MED_1 via a unicast MLE Data Response. + * - Pass Criteria: For DUT = Router: The DUT MUST send a unicast MLE Data Response to MED_1, including the + * following TLVs: + * - Source Address TLV + * - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + * step 20 + * - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + * Session ID TLV, Steering Data TLV + * - Pending Operational Dataset TLV: Channel TLV, Active Timestamp TLV, Channel Mask TLV, Extended PAN ID TLV, + * Network Mesh-Local Prefix TLV, Network Master Key TLV, Network Name TLV, PAN ID TLV, PSKc TLV, Security + * Policy TLV, Delay Timer TLV + * - Active Timestamp TLV + * - Pending Timestamp TLV + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 26A: Router_1"); + + /** + * Step 26A: Router_1 + * - Description: Automatically sends notification of new network data to SED_1 via a unicast MLE Child Update + * Request. + * - Pass Criteria: For DUT = Router: The DUT MUST send MLE Child Update Request to SED_1, including the following + * TLVs: + * - Source Address TLV + * - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + * step 20 + * - Network Data TLV + * - Active Timestamp TLV <15s> + * - Pending Timestamp TLV <30s> + * - Goto step 27 + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 26B: Router_1"); + + /** + * Step 26B: Router_1 + * - Description: Automatically sends notification of new network data to SED_1 via a unicast MLE Data Response. + * - Pass Criteria: For DUT = Router: The DUT MUST send MLE Data Response to SED_1, including the following TLVs: + * - Source Address TLV + * - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + * step 20 + * - Network Data TLV + * - Active Timestamp TLV <15s> + * - Pending Timestamp TLV <30s> + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 27: SED_1"); + + /** + * Step 27: SED_1 + * - Description: Automatically requests the full network data from Router_1 via a unicast MLE Data Request. + * - Pass Criteria: For DUT = SED: The DUT MUST send a unicast MLE Data Request to Router_1, including the following + * TLVs: + * - TLV Request TLV: Network Data TLV + * - Active Timestamp TLV + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 28: Router_1"); + + /** + * Step 28: Router_1 + * - Description: Automatically sends the requested full network data to SED_1. + * - Pass Criteria: For DUT = Router: The DUT MUST send a unicast MLE Data Response to SED_1, including the + * following TLVs: + * - Source Address TLV + * - Network Data TLV + * - Pending Operational Dataset TLV: Channel TLV, Active Timestamp TLV, Channel Mask TLV, Extended PAN ID TLV, + * Network Mesh-Local Prefix TLV, Network Master Key TLV, Network Name TLV, PAN ID TLV, PSKc TLV, Security + * Policy TLV, Delay Timer TLV + * - Active Timestamp TLV <15s> + * - Pending Timestamp TLV <30s> + */ + + nexus.AdvanceTime(kDataPropagationTime); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 29: Harness"); + + /** + * Step 29: Harness + * - Description: Wait for delay timer to expire. + * - Pass Criteria: N/A + */ + + nexus.AdvanceTime(kDelayTimerTime); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 30: Harness"); + + /** + * Step 30: Harness + * - Description: Harness verifies connectivity by sending an ICMPv6 Echo Request to the DUT mesh local address on + * the (new) Secondary channel. + * - Pass Criteria: The DUT MUST respond with an ICMPv6 Echo Reply. + */ + + nexus.SendAndVerifyEchoRequest(commissioner, leader.Get().GetMeshLocalEid(), 0, 64, kEchoTimeout); + nexus.SendAndVerifyEchoRequest(commissioner, router1.Get().GetMeshLocalEid(), 0, 64, kEchoTimeout); + nexus.SendAndVerifyEchoRequest(commissioner, med1.Get().GetMeshLocalEid(), 0, 64, kEchoTimeout); + nexus.SendAndVerifyEchoRequest(commissioner, sed1.Get().GetMeshLocalEid(), 0, 64, kEchoTimeout); + + nexus.SaveTestInfo("test_9_2_6.json"); +} + +} // namespace Nexus +} // namespace ot + +int main(void) +{ + ot::Nexus::Test9_2_6(); + printf("All tests passed\n"); + return 0; +} diff --git a/tests/nexus/verify_9_2_1.py b/tests/nexus/verify_9_2_1.py index c800adf43..e3be2dbee 100644 --- a/tests/nexus/verify_9_2_1.py +++ b/tests/nexus/verify_9_2_1.py @@ -40,20 +40,6 @@ from pktverify import consts from pktverify.null_field import nullField -# Monkey-patch CoapTlvParser to parse MeshCoP TLVs in CoAP payload -def meshcop_coap_tlv_parse(t, v, layer=None): - kvs = [] - if t == consts.NM_COMMISSIONER_SESSION_ID_TLV: - kvs.append(('comm_sess_id', str(struct.unpack('>H', v)[0]))) - elif t == consts.NM_STEERING_DATA_TLV: - kvs.append(('steering_data', v.hex())) - elif t == consts.NM_BORDER_AGENT_LOCATOR_TLV: - kvs.append(('border_agent_rloc16', hex(struct.unpack('>H', v)[0]))) - elif t == consts.TLV_REQUEST_TLV: - kvs.append(('tlv_request', v.hex())) - return kvs - - def verify(pv): # 9.2.1 Commissioner – MGMT_COMMISSIONER_GET.req & rsp # @@ -71,20 +57,6 @@ def verify(pv): # ----------------------------------|--------------|--------------- # Updating the Commissioner Dataset | 8.7.3 | 8.7.3 - # Add MeshCoP TLVs to CoapTlvParser - old_parse = verify_utils.CoapTlvParser.parse - - from pktverify import layer_fields - layer_fields._LAYER_FIELDS['coap.tlv.tlv_request'] = layer_fields._bytes - - def new_parse(t, v, layer=None): - if t in (consts.NM_COMMISSIONER_SESSION_ID_TLV, consts.NM_STEERING_DATA_TLV, - consts.NM_BORDER_AGENT_LOCATOR_TLV, consts.TLV_REQUEST_TLV): - return meshcop_coap_tlv_parse(t, v, layer=layer) - return old_parse(t, v, layer=layer) - - verify_utils.CoapTlvParser.parse = staticmethod(new_parse) - pkts = pv.pkts pv.summary.show() diff --git a/tests/nexus/verify_9_2_4.py b/tests/nexus/verify_9_2_4.py index 14e4614ea..3e75878a0 100644 --- a/tests/nexus/verify_9_2_4.py +++ b/tests/nexus/verify_9_2_4.py @@ -40,56 +40,6 @@ from pktverify import consts from pktverify.null_field import nullField from pktverify.addrs import Ipv6Addr -# MeshCop TLVs constants for Active Dataset -NM_ACTIVE_TIMESTAMP_TLV = 14 -NM_CHANNEL_TLV = 0 -NM_CHANNEL_MASK_TLV = 53 -NM_EXTENDED_PAN_ID_TLV = 2 -NM_NETWORK_MESH_LOCAL_PREFIX_TLV = 7 -NM_NETWORK_KEY_TLV = 5 -NM_NETWORK_NAME_TLV = 3 -NM_PAN_ID_TLV = 1 -NM_PSKC_TLV = 4 -NM_SECURITY_POLICY_TLV = 12 -NM_STATE_TLV = 16 -NM_COMMISSIONER_SESSION_ID_TLV = 11 -NM_STEERING_DATA_TLV = 8 -NM_FUTURE_TLV = 130 - - -# Monkey-patch CoapTlvParser to parse MeshCoP TLVs in CoAP payload -def meshcop_coap_tlv_parse(t, v, layer=None): - kvs = [] - if t == NM_COMMISSIONER_SESSION_ID_TLV: - kvs.append(('comm_sess_id', str(struct.unpack('>H', v)[0]))) - elif t == NM_STATE_TLV: - kvs.append(('state', str(v[0]))) - elif t == NM_ACTIVE_TIMESTAMP_TLV: - kvs.append(('active_timestamp', str(struct.unpack('>Q', v)[0] >> 16))) - elif t == NM_CHANNEL_TLV: - kvs.append(('channel', str(struct.unpack('>H', v[1:3])[0]))) - elif t == NM_CHANNEL_MASK_TLV: - kvs.append(('channel_mask', v.hex())) - elif t == NM_EXTENDED_PAN_ID_TLV: - kvs.append(('ext_pan_id', v.hex())) - elif t == NM_NETWORK_MESH_LOCAL_PREFIX_TLV: - kvs.append(('mesh_local_prefix', v.hex())) - elif t == NM_NETWORK_KEY_TLV: - kvs.append(('network_key', v.hex())) - elif t == NM_NETWORK_NAME_TLV: - kvs.append(('network_name', v.decode('utf-8'))) - elif t == NM_PAN_ID_TLV: - kvs.append(('pan_id', hex(struct.unpack('>H', v)[0]))) - elif t == NM_PSKC_TLV: - kvs.append(('pskc', v.hex())) - elif t == NM_SECURITY_POLICY_TLV: - kvs.append(('security_policy', v.hex())) - elif t == NM_STEERING_DATA_TLV: - kvs.append(('steering_data', v.hex())) - elif t == NM_FUTURE_TLV: - kvs.append(('future_tlv', v.hex())) - return kvs - def verify(pv): # 9.2.4 Updating the Active Operational Dataset via Commissioner @@ -108,35 +58,6 @@ def verify(pv): # ----------------------------------------|--------------|--------------- # Updating the Active Operational Dataset | 8.7.4 | 8.7.4 - # Add MeshCoP TLVs to CoapTlvParser - old_parse = verify_utils.CoapTlvParser.parse - - from pktverify import layer_fields - layer_fields._LAYER_FIELDS['coap.tlv.comm_sess_id'] = layer_fields._auto - layer_fields._LAYER_FIELDS['coap.tlv.state'] = layer_fields._auto - layer_fields._LAYER_FIELDS['coap.tlv.active_timestamp'] = layer_fields._auto - layer_fields._LAYER_FIELDS['coap.tlv.channel'] = layer_fields._auto - layer_fields._LAYER_FIELDS['coap.tlv.channel_mask'] = layer_fields._bytes - layer_fields._LAYER_FIELDS['coap.tlv.ext_pan_id'] = layer_fields._bytes - layer_fields._LAYER_FIELDS['coap.tlv.mesh_local_prefix'] = layer_fields._bytes - layer_fields._LAYER_FIELDS['coap.tlv.network_key'] = layer_fields._bytes - layer_fields._LAYER_FIELDS['coap.tlv.network_name'] = layer_fields._str - layer_fields._LAYER_FIELDS['coap.tlv.pan_id'] = layer_fields._auto - layer_fields._LAYER_FIELDS['coap.tlv.pskc'] = layer_fields._bytes - layer_fields._LAYER_FIELDS['coap.tlv.security_policy'] = layer_fields._bytes - layer_fields._LAYER_FIELDS['coap.tlv.steering_data'] = layer_fields._bytes - layer_fields._LAYER_FIELDS['coap.tlv.future_tlv'] = layer_fields._bytes - - def new_parse(t, v, layer=None): - if t in (NM_COMMISSIONER_SESSION_ID_TLV, NM_STATE_TLV, NM_ACTIVE_TIMESTAMP_TLV, NM_CHANNEL_TLV, - NM_CHANNEL_MASK_TLV, NM_EXTENDED_PAN_ID_TLV, NM_NETWORK_MESH_LOCAL_PREFIX_TLV, NM_NETWORK_KEY_TLV, - NM_NETWORK_NAME_TLV, NM_PAN_ID_TLV, NM_PSKC_TLV, NM_SECURITY_POLICY_TLV, NM_STEERING_DATA_TLV, - NM_FUTURE_TLV): - return meshcop_coap_tlv_parse(t, v, layer=layer) - return old_parse(t, v, layer=layer) - - verify_utils.CoapTlvParser.parse = staticmethod(new_parse) - pkts = pv.pkts pv.summary.show() @@ -166,13 +87,13 @@ def verify(pv): print("Step 2: Commissioner sends MGMT_ACTIVE_SET.req to Leader.") pkts.filter_coap_request(consts.MGMT_ACTIVE_SET_URI).\ filter(lambda p: { - NM_COMMISSIONER_SESSION_ID_TLV, - NM_ACTIVE_TIMESTAMP_TLV, - NM_CHANNEL_MASK_TLV, - NM_EXTENDED_PAN_ID_TLV, - NM_NETWORK_NAME_TLV, - NM_PSKC_TLV, - NM_SECURITY_POLICY_TLV + consts.NM_COMMISSIONER_SESSION_ID_TLV, + consts.NM_ACTIVE_TIMESTAMP_TLV, + consts.NM_CHANNEL_MASK_TLV, + consts.NM_EXTENDED_PAN_ID_TLV, + consts.NM_NETWORK_NAME_TLV, + consts.NM_PSKC_TLV, + consts.NM_SECURITY_POLICY_TLV } <= set(p.coap.tlv.type) and p.coap.tlv.active_timestamp == 101 and p.coap.tlv.channel_mask == '0004001fffe0' and @@ -218,16 +139,16 @@ def verify(pv): print("Step 5: Leader sends MGMT_ACTIVE_GET.rsp to Commissioner.") pkts.filter_coap_ack(consts.MGMT_ACTIVE_GET_URI).\ filter(lambda p: { - NM_ACTIVE_TIMESTAMP_TLV, - NM_CHANNEL_TLV, - NM_CHANNEL_MASK_TLV, - NM_EXTENDED_PAN_ID_TLV, - NM_NETWORK_MESH_LOCAL_PREFIX_TLV, - NM_NETWORK_KEY_TLV, - NM_NETWORK_NAME_TLV, - NM_PAN_ID_TLV, - NM_PSKC_TLV, - NM_SECURITY_POLICY_TLV + consts.NM_ACTIVE_TIMESTAMP_TLV, + consts.NM_CHANNEL_TLV, + consts.NM_CHANNEL_MASK_TLV, + consts.NM_EXTENDED_PAN_ID_TLV, + consts.NM_NETWORK_MESH_LOCAL_PREFIX_TLV, + consts.NM_NETWORK_KEY_TLV, + consts.NM_NETWORK_NAME_TLV, + consts.NM_PAN_ID_TLV, + consts.NM_PSKC_TLV, + consts.NM_SECURITY_POLICY_TLV } <= set(p.coap.tlv.type) and p.coap.tlv.active_timestamp == 101 and p.coap.tlv.channel_mask == '0004001fffe0' and @@ -253,11 +174,11 @@ def verify(pv): print("Step 6: Commissioner sends MGMT_ACTIVE_SET.req with Channel TLV (invalid for active set).") pkts.filter_coap_request(consts.MGMT_ACTIVE_SET_URI).\ filter(lambda p: { - NM_COMMISSIONER_SESSION_ID_TLV, - NM_ACTIVE_TIMESTAMP_TLV, - NM_CHANNEL_TLV, - NM_EXTENDED_PAN_ID_TLV, - NM_NETWORK_NAME_TLV + consts.NM_COMMISSIONER_SESSION_ID_TLV, + consts.NM_ACTIVE_TIMESTAMP_TLV, + consts.NM_CHANNEL_TLV, + consts.NM_EXTENDED_PAN_ID_TLV, + consts.NM_NETWORK_NAME_TLV } <= set(p.coap.tlv.type) and p.coap.tlv.active_timestamp == 102 and p.coap.tlv.channel == 12 and @@ -292,12 +213,12 @@ def verify(pv): print("Step 8: Commissioner sends MGMT_ACTIVE_SET.req with Mesh-Local Prefix TLV (invalid for active set).") pkts.filter_coap_request(consts.MGMT_ACTIVE_SET_URI).\ filter(lambda p: { - NM_COMMISSIONER_SESSION_ID_TLV, - NM_ACTIVE_TIMESTAMP_TLV, - NM_CHANNEL_MASK_TLV, - NM_NETWORK_MESH_LOCAL_PREFIX_TLV, - NM_NETWORK_NAME_TLV, - NM_PSKC_TLV + consts.NM_COMMISSIONER_SESSION_ID_TLV, + consts.NM_ACTIVE_TIMESTAMP_TLV, + consts.NM_CHANNEL_MASK_TLV, + consts.NM_NETWORK_MESH_LOCAL_PREFIX_TLV, + consts.NM_NETWORK_NAME_TLV, + consts.NM_PSKC_TLV } <= set(p.coap.tlv.type) and p.coap.tlv.active_timestamp == 103 and p.coap.tlv.channel_mask == '0004001ffee0' and @@ -333,10 +254,10 @@ def verify(pv): print("Step 10: Commissioner sends MGMT_ACTIVE_SET.req with Network Key TLV (invalid for active set).") pkts.filter_coap_request(consts.MGMT_ACTIVE_SET_URI).\ filter(lambda p: { - NM_COMMISSIONER_SESSION_ID_TLV, - NM_ACTIVE_TIMESTAMP_TLV, - NM_NETWORK_KEY_TLV, - NM_SECURITY_POLICY_TLV + consts.NM_COMMISSIONER_SESSION_ID_TLV, + consts.NM_ACTIVE_TIMESTAMP_TLV, + consts.NM_NETWORK_KEY_TLV, + consts.NM_SECURITY_POLICY_TLV } <= set(p.coap.tlv.type) and p.coap.tlv.active_timestamp == 104 and p.coap.tlv.network_key == '00112233445566778899aabbccddeeff' and @@ -368,9 +289,9 @@ def verify(pv): print("Step 12: Commissioner sends MGMT_ACTIVE_SET.req with PAN ID TLV (invalid for active set).") pkts.filter_coap_request(consts.MGMT_ACTIVE_SET_URI).\ filter(lambda p: { - NM_COMMISSIONER_SESSION_ID_TLV, - NM_ACTIVE_TIMESTAMP_TLV, - NM_PAN_ID_TLV + consts.NM_COMMISSIONER_SESSION_ID_TLV, + consts.NM_ACTIVE_TIMESTAMP_TLV, + consts.NM_PAN_ID_TLV } <= set(p.coap.tlv.type) and p.coap.tlv.active_timestamp == 105 and p.coap.tlv.pan_id == 0xafce).\ @@ -401,13 +322,12 @@ def verify(pv): print("Step 14: Commissioner sends MGMT_ACTIVE_SET.req with invalid Session ID.") pkts.filter_coap_request(consts.MGMT_ACTIVE_SET_URI).\ filter(lambda p: { - NM_COMMISSIONER_SESSION_ID_TLV, - NM_ACTIVE_TIMESTAMP_TLV + consts.NM_COMMISSIONER_SESSION_ID_TLV, + consts.NM_ACTIVE_TIMESTAMP_TLV } <= set(p.coap.tlv.type) and p.coap.tlv.active_timestamp == 106 and p.coap.tlv.comm_sess_id == 65535).\ must_next() - # Step 15: Leader # - Description: Automatically sends MGMT_ACTIVE_SET.rsp to the Commissioner. # - Pass Criteria: For DUT = Leader: The DUT MUST send MGMT_ACTIVE_SET.rsp to the Commissioner with the following @@ -433,8 +353,8 @@ def verify(pv): print("Step 16: Commissioner sends MGMT_ACTIVE_SET.req with old Active Timestamp.") pkts.filter_coap_request(consts.MGMT_ACTIVE_SET_URI).\ filter(lambda p: { - NM_COMMISSIONER_SESSION_ID_TLV, - NM_ACTIVE_TIMESTAMP_TLV + consts.NM_COMMISSIONER_SESSION_ID_TLV, + consts.NM_ACTIVE_TIMESTAMP_TLV } <= set(p.coap.tlv.type) and p.coap.tlv.active_timestamp == 101).\ must_next() @@ -465,9 +385,9 @@ def verify(pv): print("Step 18: Commissioner sends MGMT_ACTIVE_SET.req with unexpected Steering Data TLV.") pkts.filter_coap_request(consts.MGMT_ACTIVE_SET_URI).\ filter(lambda p: { - NM_COMMISSIONER_SESSION_ID_TLV, - NM_ACTIVE_TIMESTAMP_TLV, - NM_STEERING_DATA_TLV + consts.NM_COMMISSIONER_SESSION_ID_TLV, + consts.NM_ACTIVE_TIMESTAMP_TLV, + consts.NM_STEERING_DATA_TLV } <= set(p.coap.tlv.type) and p.coap.tlv.active_timestamp == 107 and p.coap.tlv.steering_data == '113320440000').\ @@ -499,9 +419,9 @@ def verify(pv): print("Step 20: Commissioner sends MGMT_ACTIVE_SET.req with Future TLV.") pkts.filter_coap_request(consts.MGMT_ACTIVE_SET_URI).\ filter(lambda p: { - NM_COMMISSIONER_SESSION_ID_TLV, - NM_ACTIVE_TIMESTAMP_TLV, - NM_FUTURE_TLV + consts.NM_COMMISSIONER_SESSION_ID_TLV, + consts.NM_ACTIVE_TIMESTAMP_TLV, + consts.NM_FUTURE_TLV } <= set(p.coap.tlv.type) and p.coap.tlv.active_timestamp == 108 and p.coap.tlv.future_tlv == 'aa55').\ diff --git a/tests/nexus/verify_9_2_6.py b/tests/nexus/verify_9_2_6.py new file mode 100644 index 000000000..8bba3df1c --- /dev/null +++ b/tests/nexus/verify_9_2_6.py @@ -0,0 +1,696 @@ +#!/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 struct +import verify_utils +from pktverify import consts + + +def verify(pv): + # 9.2.6 Commissioning - Dissemination of Operational Datasets + # + # 9.2.6.1 Topology + # - DUT as Leader (Topology A) + # - DUT as Router (Topology B) + # - DUT as MED/SED (Topologies C and D) + # + # Note: Two sniffers are required to run this test case! + # + # 9.2.6.2 Purpose & Description + # - DUT as Leader (Topology A): The purpose of this test case is to verify that the Leader device properly collects + # and disseminates Operational Datasets through a Thread network. + # - DUT as Router (Topology B): The purpose of this test case is to show that the Router device correctly sets the + # Commissioning information propagated by the Leader device and sends it properly to devices already attached to + # it. + # - DUT as MED/SED (Topologies C and D): + # - MED - requires full network data + # - SED - requires only stable network data + # - Set on Leader: Active TimeStamp = 10s + # + # Spec Reference | V1.1 Section | V1.3.0 Section + # ---------------------------------------------------|---------------|--------------- + # Updating the Active / Pending Operational Dataset | 8.7.4 / 8.7.5 | 8.7.4 / 8.7.5 + + from pktverify import consts + from pktverify.null_field import nullField + + pkts = pv.pkts + pv.summary.show() + + LEADER = pv.vars['LEADER'] + COMMISSIONER = pv.vars['COMMISSIONER'] + ROUTER_1 = pv.vars['ROUTER_1'] + MED_1 = pv.vars['MED_1'] + SED_1 = pv.vars['SED_1'] + + # Step 1: All + # - Description: Ensure topology is formed correctly. + # - Pass Criteria: N/A + print("Step 1: Ensure topology is formed correctly.") + + # Step 2: Commissioner + # - Description: Harness instructs Commissioner to send MGMT_COMMISSIONER_SET.req to the Leader Anycast or Routing + # Locator: + # - CoAP URI-Path: coap (S)://[]:MM/c/cs + # - CoAP Payload: Commissioner Session ID TLV (valid value), Steering Data TLV (allowed TLV) + # - Pass Criteria: N/A + print("Step 2: Commissioner sends MGMT_COMMISSIONER_SET.req") + pkts.filter_coap_request(consts.MGMT_COMMISSIONER_SET_URI).\ + filter(lambda p: p.coap.tlv.type is not nullField and\ + { + consts.NM_COMMISSIONER_SESSION_ID_TLV, + consts.NM_STEERING_DATA_TLV + } <= set(p.coap.tlv.type)).\ + must_next() + + # Step 3: Leader + # - Description: Automatically sends MGMT_COMMISSIONER_SET.rsp to the Commissioner. + # - Pass Criteria: For DUT = Leader: The DUT MUST send MGMT_COMMISSIONER_SET.rsp with the following format: + # - CoAP Response Code: 2.04 Changed + # - CoAP Payload: State TLV + print("Step 3: Leader sends MGMT_COMMISSIONER_SET.rsp") + pkts.filter_coap_ack(consts.MGMT_COMMISSIONER_SET_URI).\ + filter(lambda p: p.coap.tlv.state == consts.MESHCOP_ACCEPT).\ + must_next() + + # Step 4: Leader + # - Description: Automatically sends new network data to neighbors and rx-on-when-idle Children (MED_1) via a + # multicast MLE Data Response. + # - Pass Criteria: For DUT = Leader: The DUT MUST send a multicast MLE Data Response to the Link-Local All Nodes + # multicast address (FF02::1) with the new information, including the following TLVs: + # - Source Address TLV + # - Leader Data TLV: Data Version field , Stable Data Version field + # - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + # Session ID TLV, Steering Data TLV + # - Active Timestamp TLV + print("Step 4: Leader multicasts MLE Data Response") + index4 = pkts.index + pkts.filter_wpan_src64(LEADER).\ + filter_LLANMA().\ + filter_mle_cmd(consts.MLE_DATA_RESPONSE).\ + filter(lambda p: p.mle.tlv.type is not nullField and\ + { + consts.SOURCE_ADDRESS_TLV, + consts.LEADER_DATA_TLV, + consts.NETWORK_DATA_TLV, + consts.ACTIVE_TIMESTAMP_TLV + } <= set(p.mle.tlv.type)).\ + must_next() + + # Step 5: Router_1 + # - Description: Automatically sends new network data to neighbors and rx-on-when-idle Children (MED_1) via a + # multicast MLE Data Response. + # - Pass Criteria: For DUT = Router: The DUT MUST send a multicast MLE Data Response with the new information, + # including the following TLVs: + # - Source Address TLV + # - Leader Data TLV: Data Version field , Stable Data Version field + # - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + # Session ID TLV, Steering Data TLV + # - Active Timestamp TLV + print("Step 5: Router_1 multicasts MLE Data Response") + pkts.filter_wpan_src64(ROUTER_1).\ + filter_LLANMA().\ + filter_mle_cmd(consts.MLE_DATA_RESPONSE).\ + filter(lambda p: p.mle.tlv.type is not nullField and\ + { + consts.SOURCE_ADDRESS_TLV, + consts.LEADER_DATA_TLV, + consts.NETWORK_DATA_TLV, + consts.ACTIVE_TIMESTAMP_TLV + } <= set(p.mle.tlv.type)).\ + must_next() + + # Step 7: Commissioner + # - Description: Harness instructs the Commissioner to send MGMT_ACTIVE_SET.req to the Leader Anycast or Routing + # Locator: + # - CoAP Request: coap://[]:MM/c/as + # - CoAP Payload: valid Commissioner Session ID TLV, Active Timestamp TLV : 15s, Network Name TLV : Thread, + # PSKc TLV: 74:68:72:65:61:64:6a:70:61:6b:65:74:65:73:74:02 (new value) + # - Pass Criteria: N/A + print("Step 7: Commissioner sends MGMT_ACTIVE_SET.req") + pkts.filter_coap_request(consts.MGMT_ACTIVE_SET_URI).\ + filter(lambda p: p.coap.tlv.type is not nullField and\ + { + consts.NM_COMMISSIONER_SESSION_ID_TLV, + consts.NM_ACTIVE_TIMESTAMP_TLV, + consts.NM_NETWORK_NAME_TLV, + consts.NM_PSKC_TLV + } <= set(p.coap.tlv.type)).\ + must_next() + + # Step 6: Router_1 + # - Description: No update is sent to SED_1 because Stable Data Version is unchanged. + # - Pass Criteria: For DUT = Router: The DUT MUST NOT send a unicast MLE Data Response or MLE Child Update Request + # to SED_1. + print("Step 6: Router_1 does NOT send update to SED_1") + pkts.range(index4, pkts.index).filter_wpan_src64(ROUTER_1).\ + filter_wpan_dst64(SED_1).\ + filter(lambda p: p.mle.cmd in (consts.MLE_DATA_RESPONSE, consts.MLE_CHILD_UPDATE_REQUEST)).\ + must_not_next() + + # Step 8: Leader + # - Description: Automatically sends MGMT_ACTIVE_SET.rsp to the Commissioner with Status = Accept. + # - Pass Criteria: For DUT = Leader: The DUT MUST send a MGMT_ACTIVE_SET.rsp frame with the following format: + # - CoAP Response Code: 2.04 Changed + # - CoAP Payload: State TLV + print("Step 8: Leader sends MGMT_ACTIVE_SET.rsp") + pkts.filter_coap_ack(consts.MGMT_ACTIVE_SET_URI).\ + filter(lambda p: p.coap.tlv.state == consts.MESHCOP_ACCEPT).\ + must_next() + + # Step 9: Leader + # - Description: Automatically sends new network data to neighbors via a multicast MLE Data Response. + # - Pass Criteria: For DUT = Leader: The DUT MUST send a multicast MLE Data Response to the Link-Local All Nodes + # multicast address (FF02::1) with the new information, including the following TLVs: + # - Source Address TLV + # - Leader Data TLV: Data Version field , Stable Data Version field + # - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + # Session ID TLV, Steering Data TLV + # - Active Timestamp TLV: 15s + print("Step 9: Leader multicasts MLE Data Response") + pkts.filter_wpan_src64(LEADER).\ + filter_LLANMA().\ + filter_mle_cmd(consts.MLE_DATA_RESPONSE).\ + filter(lambda p: p.mle.tlv.type is not nullField and\ + { + consts.SOURCE_ADDRESS_TLV, + consts.LEADER_DATA_TLV, + consts.NETWORK_DATA_TLV, + consts.ACTIVE_TIMESTAMP_TLV + } <= set(p.mle.tlv.type)).\ + must_next() + index9 = pkts.index + + # Step 10: Router_1 + # - Description: Automatically requests the full network data from the Leader via a unicast MLE Data Request. + # - Pass Criteria: For DUT = Router: The DUT MUST send a unicast MLE Data Request to the Leader, which includes the + # following TLVs: + # - TLV Request TLV: Network Data TLV + # - Active Timestamp TLV + print("Step 10: Router_1 sends MLE Data Request to Leader") + pkts.filter_wpan_src64(ROUTER_1).\ + filter_wpan_dst64(LEADER).\ + filter_mle_cmd(consts.MLE_DATA_REQUEST).\ + filter(lambda p: p.mle.tlv.type is not nullField and\ + { + consts.TLV_REQUEST_TLV, + } <= set(p.mle.tlv.type)).\ + must_next() + + # Step 11: Leader + # - Description: Automatically sends the requested full network data to Router_1 via a unicast MLE Data Response. + # - Pass Criteria: For DUT = Leader: The DUT MUST send a unicast MLE Data Response to Router_1 including the + # following TLVs: + # - Source Address TLV + # - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + # step 9 + # - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + # Session ID TLV, Steering Data TLV + # - Active Timestamp TLV + # - Active Operational Dataset TLV (MUST NOT contain the Active Timestamp TLV): Channel TLV, Channel Mask TLV, + # Extended PAN ID TLV, Network Mesh-Local Prefix TLV, Network Master Key TLV, Network Name TLV , PAN + # ID TLV, PSKc TLV, Security Policy TLV + print("Step 11: Leader sends unicast MLE Data Response to Router_1") + pkts.filter_wpan_src64(LEADER).\ + filter_wpan_dst64(ROUTER_1).\ + filter_mle_cmd(consts.MLE_DATA_RESPONSE).\ + filter(lambda p: p.mle.tlv.type is not nullField and\ + { + consts.SOURCE_ADDRESS_TLV, + consts.LEADER_DATA_TLV, + consts.NETWORK_DATA_TLV, + consts.ACTIVE_TIMESTAMP_TLV, + } <= set(p.mle.tlv.type)).\ + must_next() + + # Step 12: Router_1 + # - Description: Automatically sends the full network data to neighbors and rx-on-while-idle Children (MED_1) via a + # multicast MLE Data Response. + # - Pass Criteria: For DUT = Router: The DUT MUST send a multicast MLE Data Response with the new information, + # including the following TLVs: + # - Source Address TLV + # - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + # step 9 + # - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + # Session ID TLV, Steering Data TLV + # - Active Timestamp TLV <15s> + print("Step 12: Router_1 multicasts MLE Data Response") + pkts.filter_wpan_src64(ROUTER_1).\ + filter_LLANMA().\ + filter_mle_cmd(consts.MLE_DATA_RESPONSE).\ + filter(lambda p: p.mle.tlv.type is not nullField and\ + { + consts.SOURCE_ADDRESS_TLV, + consts.LEADER_DATA_TLV, + consts.NETWORK_DATA_TLV, + consts.ACTIVE_TIMESTAMP_TLV + } <= set(p.mle.tlv.type)).\ + must_next() + index12 = pkts.index + + # The MED and SED update groups (Steps 13-14 and 15-17) can happen in any order. + # We search from index9 because proactive requests might happen early. + med_pkts = pkts.range(index9, cascade=False) + sed_pkts = pkts.range(index9, cascade=False) + + # Step 13: MED_1 + # - Description: Automatically requests full network data from Router_1 via a unicast MLE Data Request. + # - Pass Criteria: For DUT = MED: The DUT MUST send a unicast MLE Data Request to Router_1, including the following + # TLVs: + # - TLV Request TLV: Network Data TLV + # - Active Timestamp TLV + print("Step 13: MED_1 sends MLE Data Request to Router_1") + # MED_1 is rx-on-when-idle and may have already updated from multicast Step 12. + pkt13 = med_pkts.filter_wpan_src64(MED_1).\ + filter_wpan_dst64(ROUTER_1).\ + filter(lambda p: (p.mle.cmd == consts.MLE_DATA_REQUEST) and \ + p.mle.tlv.type is not nullField and\ + { + consts.TLV_REQUEST_TLV, + } <= set(p.mle.tlv.type)).\ + next() + + if pkt13: + # Step 14: Router_1 + # - Description: Automatically sends full network data to MED_1 via a unicast MLE Data Response. + # - Pass Criteria: For DUT = Router: The DUT MUST send a unicast MLE Data Response to MED_1, which includes the + # following TLVs: + # - Source Address TLV + # - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + # step 9. + # - Network Data TLV: Commissioning Data TLV:: Stable flag , Commissioner Session ID TLV, Border Agent + # Locator TLV, Steering Data TLV + # - Active Timestamp TLV (new value) + # - Active Operational Dataset TLV (MUST NOT contain the Active Timestamp TLV): Channel TLV, Channel Mask TLV, + # Extended PAN ID TLV, Network Mesh-Local Prefix TLV, Network Master Key TLV, Network Name TLV (New Value), PAN + # ID TLV, PSKc TLV, Security Policy TLV + print("Step 14: Router_1 sends unicast MLE Data Response to MED_1") + med_pkts.filter_wpan_src64(ROUTER_1).\ + filter_wpan_dst64(MED_1).\ + filter(lambda p: (p.mle.cmd == consts.MLE_DATA_RESPONSE or \ + p.mle.cmd == consts.MLE_CHILD_UPDATE_RESPONSE) and \ + p.mle.tlv.type is not nullField and\ + { + consts.SOURCE_ADDRESS_TLV, + } <= set(p.mle.tlv.type)).\ + must_next() + + # Step 15A: Router_1 + # - Description: Automatically sends notification of new network data to SED_1 via a unicast MLE Child Update + # Request. + # - Pass Criteria: For DUT = Router: The DUT MUST send MLE Child Update Request to SED_1, including the following + # TLVs: + # - Source Address TLV + # - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + # step 9 + # - Network Data TLV + # - Active Timestamp TLV <15s> + # - Goto step 16 + print("Step 15A: Router_1 sends Child Update Request or Data Response to SED_1") + pkt15 = sed_pkts.filter_wpan_src64(ROUTER_1).\ + filter_wpan_dst64(SED_1).\ + filter(lambda p: (p.mle.cmd == consts.MLE_CHILD_UPDATE_REQUEST or \ + p.mle.cmd == consts.MLE_DATA_RESPONSE) and \ + p.mle.tlv.type is not nullField and\ + { + consts.SOURCE_ADDRESS_TLV, + consts.LEADER_DATA_TLV, + } <= set(p.mle.tlv.type)).\ + must_next() + + # Step 15B: Router_1 + # - Description: Automatically sends notification of new network data to SED_1 via a unicast MLE Data Response. + # - Pass Criteria: For DUT = Router: The DUT MUST send MLE Data Response to SED_1, including the following TLVs: + # - Source Address TLV + # - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + # step 9 + # - Network Data TLV + # - Active Timestamp TLV <15s> + print("Step 15B: Already verified in Step 15A") + + # If the notification didn't include the full Active Operational Dataset, SED_1 must request it. + if consts.ACTIVE_OPERATION_DATASET_TLV not in set(pkt15.mle.tlv.type): + # Step 16: SED_1 + # - Description: Automatically requests the full network data from Router_1 via a unicast MLE Data Request. + # - Pass Criteria: For DUT = SED: The DUT MUST send a unicast MLE Data Request to Router_1, including the following + # TLVs: + # - TLV Request TLV: Network Data TLV + # - Active Timestamp TLV + print("Step 16: SED_1 sends MLE Data Request to Router_1") + # Search from index9 to allow request before notification + pkts.range(index9).filter_wpan_src64(SED_1).\ + filter_wpan_dst64(ROUTER_1).\ + filter(lambda p: (p.mle.cmd == consts.MLE_DATA_REQUEST) and \ + p.mle.tlv.type is not nullField and\ + { + consts.TLV_REQUEST_TLV, + } <= set(p.mle.tlv.type)).\ + must_next() + + # Step 17: Router_1 + # - Description: Automatically sends the requested full network data to SED_1. + # - Pass Criteria: For DUT = Router: The DUT MUST send a unicast MLE Data Response to SED_1, including the + # following TLVs: + # - Source Address TLV + # - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + # step 9 + # - Network Data TLV + # - Active Timestamp TLV <15s> + # - Active Operational Dataset TLV (MUST NOT contain the Active Timestamp TLV): Channel TLV, Channel Mask TLV, + # Extended PAN ID TLV, Network Mesh-Local Prefix TLV, Network Master Key TLV, Network Name TLV , PAN + # ID TLV, PSKc TLV, Security Policy TLV. + print("Step 17: Router_1 sends unicast MLE Data Response to SED_1") + pkts.range(index9).filter_wpan_src64(ROUTER_1).\ + filter_wpan_dst64(SED_1).\ + filter(lambda p: (p.mle.cmd == consts.MLE_DATA_RESPONSE or \ + p.mle.cmd == consts.MLE_CHILD_UPDATE_RESPONSE) and \ + p.mle.tlv.type is not nullField and\ + { + consts.SOURCE_ADDRESS_TLV, + } <= set(p.mle.tlv.type)).\ + must_next() + + pkts.index = max(med_pkts.index, sed_pkts.index) + + # Step 18: Commissioner + # - Description: Harness instructs Commissioner to send MGMT_PENDING_SET.req to the Leader Anycast or Routing + # Locator: + # - CoAP Request: coap://[]:MM/c/ps + # - CoAP Payload: Commissioner Session ID TLV , Pending Timestamp TLV <30s>, Active Timestamp TLV + # <75s>, Delay Timer TLV <1 min>, Channel TLV + # - Pass Criteria: N/A + print("Step 18: Commissioner sends MGMT_PENDING_SET.req") + # Commissioner sends MGMT_PENDING_SET.req after Step 12. + # It might overlap with MED/SED updates (Steps 13-17). + pkts_step18 = pv.pkts.range(index12) + pkts_step18.filter_coap_request(consts.MGMT_PENDING_SET_URI).\ + filter(lambda p: p.coap.tlv.type is not nullField and\ + { + consts.NM_COMMISSIONER_SESSION_ID_TLV, + consts.NM_PENDING_TIMESTAMP_TLV, + } <= set(p.coap.tlv.type)).\ + must_next() + index18 = pkts_step18.index + + # Step 19: Leader + # - Description: Automatically sends MGMT_PENDING_SET.rsp to the Commissioner with Status = Accept. + # - Pass Criteria: For DUT = Leader: The Leader MUST send MGMT_PENDING_SET.rsp frame to the Commissioner with the + # following format: + # - CoAP Response Code: 2.04 Changed + # - CoAP Payload: State TLV + print("Step 19: Leader sends MGMT_PENDING_SET.rsp") + pkts.range(index18).filter_coap_ack(consts.MGMT_PENDING_SET_URI).\ + filter(lambda p: p.coap.tlv.state == consts.MESHCOP_ACCEPT).\ + must_next() + + # Step 20: Leader + # - Description: Automatically sends new network data to neighbors via a multicast MLE Data Response. + # - Pass Criteria: For DUT = Leader: The DUT MUST multicast a MLE Data Response with the new information, including + # the following TLVs: + # - Source Address TLV + # - Leader Data TLV: Data version field , Stable Version field + # - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + # Session ID TLV, Steering Data TLV + # - Active Timestamp TLV + # - Pending Timestamp TLV + print("Step 20: Leader multicasts MLE Data Response") + pkts.range(index18).filter_wpan_src64(LEADER).\ + filter_LLANMA().\ + filter_mle_cmd(consts.MLE_DATA_RESPONSE).\ + filter(lambda p: p.mle.tlv.type is not nullField and\ + { + consts.SOURCE_ADDRESS_TLV, + consts.LEADER_DATA_TLV, + consts.NETWORK_DATA_TLV, + consts.ACTIVE_TIMESTAMP_TLV, + consts.PENDING_TIMESTAMP_TLV + } <= set(p.mle.tlv.type)).\ + must_next() + index20 = pkts.index + + # Step 21: Router_1 + # - Description: Automatically requests full network data from the Leader via a unicast MLE Data Request. + # - Pass Criteria: For DUT = Router_1: The DUT MUST send a unicast MLE Data Request to the Leader, including the + # following TLVs: + # - Request TLV: Network Data TLV + # - Active Timestamp TLV + print("Step 21: Router_1 sends MLE Data Request to Leader") + pkts.filter_wpan_src64(ROUTER_1).\ + filter_wpan_dst64(LEADER).\ + filter_mle_cmd(consts.MLE_DATA_REQUEST).\ + filter(lambda p: p.mle.tlv.type is not nullField and\ + { + consts.TLV_REQUEST_TLV, + } <= set(p.mle.tlv.type)).\ + must_next() + + # Step 22: Leader + # - Description: Automatically sends full network data to Router_1 via a unicast MLE Data Response. + # - Pass Criteria: For DUT = Leader: The DUT MUST send a unicast MLE Data Response to Router_1, including the + # following TLVs: + # - Source Address TLV + # - Leader Data TLV + # - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + # Session ID TLV, Steering Data TLV + # - Pending Operational Dataset TLV + # - Active Timestamp TLV + # - Pending Timestamp TLV + print("Step 22: Leader sends unicast MLE Data Response to Router_1") + pkts.filter_wpan_src64(LEADER).\ + filter_wpan_dst64(ROUTER_1).\ + filter_mle_cmd(consts.MLE_DATA_RESPONSE).\ + filter(lambda p: p.mle.tlv.type is not nullField and\ + { + consts.SOURCE_ADDRESS_TLV, + consts.LEADER_DATA_TLV, + consts.NETWORK_DATA_TLV, + consts.ACTIVE_TIMESTAMP_TLV, + } <= set(p.mle.tlv.type)).\ + must_next() + + # Step 23: Router_1 + # - Description: Automatically sends new network data to neighbors and rx-on-when-idle Children via a multicast MLE + # Data Response. + # - Pass Criteria: For DUT = Router: The DUT MUST multicast a MLE Data Response with the new information, including + # the following TLVs: + # - Source Address TLV + # - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + # step 20 + # - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + # Session ID TLV, Steering Data TLV + # - Active Timestamp TLV <15s> + # - Pending Timestamp TLV <30s> + print("Step 23: Router_1 multicasts MLE Data Response") + pkts.filter_wpan_src64(ROUTER_1).\ + filter_LLANMA().\ + filter_mle_cmd(consts.MLE_DATA_RESPONSE).\ + filter(lambda p: p.mle.tlv.type is not nullField and\ + { + consts.SOURCE_ADDRESS_TLV, + consts.LEADER_DATA_TLV, + consts.NETWORK_DATA_TLV, + consts.ACTIVE_TIMESTAMP_TLV, + consts.PENDING_TIMESTAMP_TLV + } <= set(p.mle.tlv.type)).\ + must_next() + index23 = pkts.index + + # The MED and SED update groups (Steps 24-25 and 26-28) can happen in any order. + # We search from index20 because proactive requests might happen early. + med_pkts = pkts.range(index20, cascade=False) + sed_pkts = pkts.range(index20, cascade=False) + + # Step 24: MED_1 + # - Description: Automatically requests full network data from Router_1 via a unicast MLE Data Request. + # - Pass Criteria: For DUT = MED: The DUT MUST send a unicast MLE Data Request to Router_1 including the following + # TLVs: + # - TLV Request TLV: Network Data TLV + # - Active Timestamp TLV + print("Step 24: MED_1 sends MLE Data Request to Router_1") + # MED_1 is rx-on-when-idle and may have already updated from multicast Step 23. + pkt24 = med_pkts.filter_wpan_src64(MED_1).\ + filter_wpan_dst64(ROUTER_1).\ + filter(lambda p: (p.mle.cmd == consts.MLE_DATA_REQUEST) and \ + p.mle.tlv.type is not nullField and\ + { + consts.TLV_REQUEST_TLV, + } <= set(p.mle.tlv.type)).\ + next() + + if pkt24: + # Step 25: Router_1 + # - Description: Automatically sends full network data to MED_1 via a unicast MLE Data Response. + # - Pass Criteria: For DUT = Router: The DUT MUST send a unicast MLE Data Response to MED_1, including the + # following TLVs: + # - Source Address TLV + # - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + # step 20 + # - Network Data TLV: Commissioning Data TLV:: Stable flag , Border Agent Locator TLV, Commissioner + # Session ID TLV, Steering Data TLV + # - Pending Operational Dataset TLV: Channel TLV, Active Timestamp TLV, Channel Mask TLV, Extended PAN ID TLV, + # Network Mesh-Local Prefix TLV, Network Master Key TLV, Network Name TLV, PAN ID TLV, PSKc TLV, Security + # Policy TLV, Delay Timer TLV + # - Active Timestamp TLV + # - Pending Timestamp TLV + print("Step 25: Router_1 sends unicast MLE Data Response to MED_1") + med_pkts.filter_wpan_src64(ROUTER_1).\ + filter_wpan_dst64(MED_1).\ + filter(lambda p: (p.mle.cmd == consts.MLE_DATA_RESPONSE or \ + p.mle.cmd == consts.MLE_CHILD_UPDATE_RESPONSE) and \ + p.mle.tlv.type is not nullField and\ + { + consts.SOURCE_ADDRESS_TLV, + consts.PENDING_OPERATION_DATASET_TLV + } <= set(p.mle.tlv.type)).\ + must_next() + + # Step 26A: Router_1 + # - Description: Automatically sends notification of new network data to SED_1 via a unicast MLE Child Update + # Request. + # - Pass Criteria: For DUT = Router: The DUT MUST send MLE Child Update Request to SED_1, including the following + # TLVs: + # - Source Address TLV + # - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + # step 20 + # - Network Data TLV + # - Active Timestamp TLV <15s> + # - Pending Timestamp TLV <30s> + # - Goto step 27 + print("Step 26A: Router_1 sends Child Update Request or Data Response to SED_1") + pkt26 = sed_pkts.filter_wpan_src64(ROUTER_1).\ + filter_wpan_dst64(SED_1).\ + filter(lambda p: (p.mle.cmd == consts.MLE_CHILD_UPDATE_REQUEST or \ + p.mle.cmd == consts.MLE_DATA_RESPONSE) and \ + p.mle.tlv.type is not nullField and\ + { + consts.SOURCE_ADDRESS_TLV, + consts.LEADER_DATA_TLV, + } <= set(p.mle.tlv.type)).\ + must_next() + + # Step 26B: Router_1 + # - Description: Automatically sends notification of new network data to SED_1 via a unicast MLE Data Response. + # - Pass Criteria: For DUT = Router: The DUT MUST send MLE Data Response to SED_1, including the following TLVs: + # - Source Address TLV + # - Leader Data TLV: Data version numbers should be the same as the ones sent in the multicast data response in + # step 20 + # - Network Data TLV + # - Active Timestamp TLV <15s> + # - Pending Timestamp TLV <30s> + print("Step 26B: Already verified in Step 26A") + + # If the notification didn't include the full Pending Operational Dataset, SED_1 must request it. + if consts.PENDING_OPERATION_DATASET_TLV not in set(pkt26.mle.tlv.type): + # Step 27: SED_1 + # - Description: Automatically requests the full network data from Router_1 via a unicast MLE Data Request. + # - Pass Criteria: For DUT = SED: The DUT MUST send a unicast MLE Data Request to Router_1, including the following + # TLVs: + # - TLV Request TLV: Network Data TLV + # - Active Timestamp TLV + print("Step 27: SED_1 sends MLE Data Request to Router_1") + # Search from index20 to allow request before notification + pkts.range(index20).filter_wpan_src64(SED_1).\ + filter_wpan_dst64(ROUTER_1).\ + filter(lambda p: (p.mle.cmd == consts.MLE_DATA_REQUEST) and \ + p.mle.tlv.type is not nullField and\ + { + consts.TLV_REQUEST_TLV, + } <= set(p.mle.tlv.type)).\ + must_next() + + # Step 28: Router_1 + # - Description: Automatically sends the requested full network data to SED_1. + # - Pass Criteria: For DUT = Router: The DUT MUST send a unicast MLE Data Response to SED_1, including the + # following TLVs: + # - Source Address TLV + # - Network Data TLV + # - Pending Operational Dataset TLV: Channel TLV, Active Timestamp TLV, Channel Mask TLV, Extended PAN ID TLV, + # Network Mesh-Local Prefix TLV, Network Master Key TLV, Network Name TLV, PAN ID TLV, PSKc TLV, Security + # Policy TLV, Delay Timer TLV + # - Active Timestamp TLV <15s> + # - Pending Timestamp TLV <30s> + print("Step 28: Router_1 sends unicast MLE Data Response to SED_1") + pkts.range(index20).filter_wpan_src64(ROUTER_1).\ + filter_wpan_dst64(SED_1).\ + filter(lambda p: (p.mle.cmd == consts.MLE_DATA_RESPONSE or \ + p.mle.cmd == consts.MLE_CHILD_UPDATE_RESPONSE) and \ + p.mle.tlv.type is not nullField and\ + { + consts.SOURCE_ADDRESS_TLV, + } <= set(p.mle.tlv.type)).\ + must_next() + + pkts.index = max(med_pkts.index, sed_pkts.index) + + # Step 29: Harness + # - Description: Wait for delay timer to expire. + # - Pass Criteria: N/A + print("Step 29: Wait for delay timer to expire.") + + # Step 30: Harness + # - Description: Harness verifies connectivity by sending an ICMPv6 Echo Request to the DUT mesh local address on + # the (new) Secondary channel. + # - Pass Criteria: The DUT MUST respond with an ICMPv6 Echo Reply. + print("Step 30: ICMPv6 Echo Request/Reply on Secondary channel") + # LEADER + _pkt = pkts.filter_ping_request().\ + filter_wpan_src64(COMMISSIONER).\ + filter_ipv6_dst(pv.vars['LEADER_MLEID']).\ + must_next() + pkts.filter_ping_reply(identifier=_pkt.icmpv6.echo.identifier).\ + filter_wpan_src64(LEADER).\ + must_next() + # ROUTER_1 + _pkt = pkts.filter_ping_request().\ + filter_wpan_src64(COMMISSIONER).\ + filter_ipv6_dst(pv.vars['ROUTER_1_MLEID']).\ + must_next() + pkts.filter_ping_reply(identifier=_pkt.icmpv6.echo.identifier).\ + filter_wpan_src64(ROUTER_1).\ + must_next() + # MED_1 + _pkt = pkts.filter_ping_request().\ + filter_wpan_src64(COMMISSIONER).\ + filter_ipv6_dst(pv.vars['MED_1_MLEID']).\ + must_next() + pkts.filter_ping_reply(identifier=_pkt.icmpv6.echo.identifier).\ + filter_wpan_src64(MED_1).\ + must_next() + # SED_1 + _pkt = pkts.filter_ping_request().\ + filter_wpan_src64(COMMISSIONER).\ + filter_ipv6_dst(pv.vars['SED_1_MLEID']).\ + must_next() + pkts.filter_ping_reply(identifier=_pkt.icmpv6.echo.identifier).\ + filter_wpan_src64(SED_1).\ + must_next() + + +if __name__ == '__main__': + verify_utils.run_main(verify) diff --git a/tests/nexus/verify_utils.py b/tests/nexus/verify_utils.py index d1a05a9d3..baa3c030e 100644 --- a/tests/nexus/verify_utils.py +++ b/tests/nexus/verify_utils.py @@ -62,17 +62,19 @@ def thread_coap_tlv_parse(t, v, layer=None): # MeshCoP TLVs (often overlap with Diagnostic TLVs) if t == consts.NM_COMMISSIONER_SESSION_ID_TLV and len(v) == 2 and not is_diag: - kvs.append(('comm_sess_id', str(struct.unpack('>H', v)[0]))) + kvs.append(('comm_sess_id', struct.unpack('>H', v)[0])) elif t == consts.NM_STATE_TLV and len(v) == 1 and not is_diag: - kvs.append(('state', str(v[0]))) + kvs.append(('state', v[0])) elif t == consts.NM_STEERING_DATA_TLV and not is_diag: # DG_IPV6_ADDRESS_LIST_TLV is 16*n kvs.append(('steering_data', v.hex())) elif t == consts.NM_BORDER_AGENT_LOCATOR_TLV and len(v) == 2 and not is_diag: # DG_MAC_COUNTERS_TLV is 4*n - kvs.append(('border_agent_rloc16', hex(struct.unpack('>H', v)[0]))) + kvs.append(('border_agent_rloc16', struct.unpack('>H', v)[0])) + elif t == consts.TLV_REQUEST_TLV: + kvs.append(('tlv_request', v.hex())) elif t == consts.NM_CHANNEL_TLV and len(v) == 3 and not is_diag: # DG_MAC_EXTENDED_ADDRESS_TLV is 8 - kvs.append(('channel', str(struct.unpack('>H', v[1:3])[0]))) + kvs.append(('channel', struct.unpack('>H', v[1:3])[0])) elif t == consts.NM_ACTIVE_TIMESTAMP_TLV and len(v) == 8 and not is_diag: - kvs.append(('active_timestamp', str(struct.unpack('>Q', v)[0] >> 16))) + kvs.append(('active_timestamp', struct.unpack('>Q', v)[0] >> 16)) elif t == consts.NM_CHANNEL_MASK_TLV and not is_diag: kvs.append(('channel_mask', v.hex())) elif t == consts.NM_EXTENDED_PAN_ID_TLV and len(v) == 8 and not is_diag: @@ -86,7 +88,11 @@ def thread_coap_tlv_parse(t, v, layer=None): elif t == consts.NM_NETWORK_KEY_TLV and len(v) == 16 and not is_diag: kvs.append(('network_key', v.hex())) elif t == consts.NM_PAN_ID_TLV and len(v) == 2 and not is_diag: - kvs.append(('pan_id', hex(struct.unpack('>H', v)[0]))) + kvs.append(('pan_id', struct.unpack('>H', v)[0])) + elif t == consts.NM_NETWORK_MESH_LOCAL_PREFIX_TLV and len(v) == 8 and not is_diag: + kvs.append(('mesh_local_prefix', v.hex())) + elif t == consts.NM_FUTURE_TLV: + kvs.append(('future_tlv', v.hex())) # Other Thread TLVs elif t == consts.NL_TARGET_EID_TLV and len(v) == 16: @@ -145,6 +151,9 @@ def apply_patches(): CoapTlvParser.parse = staticmethod(thread_coap_tlv_parse) from pktverify import layer_fields + layer_fields._LAYER_FIELDS['coap.tlv.tlv_request'] = layer_fields._bytes + layer_fields._LAYER_FIELDS['mle.tlv.active_operational_dataset'] = layer_fields._bytes + layer_fields._LAYER_FIELDS['mle.tlv.pending_operational_dataset'] = layer_fields._bytes 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 @@ -153,6 +162,7 @@ def apply_patches(): 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 layer_fields._LAYER_FIELDS['coap.tlv.steering_data'] = layer_fields._bytes + layer_fields._LAYER_FIELDS['coap.tlv.future_tlv'] = layer_fields._bytes layer_fields._LAYER_FIELDS['coap.tlv.comm_sess_id'] = layer_fields._auto layer_fields._LAYER_FIELDS['coap.tlv.state'] = layer_fields._auto layer_fields._LAYER_FIELDS['coap.tlv.border_agent_rloc16'] = layer_fields._auto @@ -165,6 +175,7 @@ def apply_patches(): layer_fields._LAYER_FIELDS['coap.tlv.security_policy'] = layer_fields._bytes layer_fields._LAYER_FIELDS['coap.tlv.network_key'] = layer_fields._bytes layer_fields._LAYER_FIELDS['coap.tlv.pan_id'] = layer_fields._auto + layer_fields._LAYER_FIELDS['coap.tlv.mesh_local_prefix'] = layer_fields._bytes def which_tshark_patch(): default_path = '/tmp/thread-wireshark/tshark' diff --git a/tests/scripts/thread-cert/pktverify/coap.py b/tests/scripts/thread-cert/pktverify/coap.py index 4c225c52e..69a25992a 100644 --- a/tests/scripts/thread-cert/pktverify/coap.py +++ b/tests/scripts/thread-cert/pktverify/coap.py @@ -91,8 +91,8 @@ class CoapLayer(Layer): self._add_field('coap.tlv.type', hex(t)) for k, v in tvs: assert isinstance(k, str), (t, k, v) - assert isinstance(v, str), (t, k, v) - self._add_field('coap.tlv.' + k, v) + assert isinstance(v, (str, int)), (t, k, v) + self._add_field('coap.tlv.' + k, str(v)) @staticmethod def _parse_next_tlv(payload, read_pos, layer=None) -> tuple: diff --git a/tests/scripts/thread-cert/pktverify/consts.py b/tests/scripts/thread-cert/pktverify/consts.py index 8fea33e00..e81de672f 100644 --- a/tests/scripts/thread-cert/pktverify/consts.py +++ b/tests/scripts/thread-cert/pktverify/consts.py @@ -217,6 +217,7 @@ NM_SCAN_DURATION = 56 NM_ENERGY_LIST_TLV = 57 NM_DISCOVERY_REQUEST_TLV = 128 NM_DISCOVERY_RESPONSE_TLV = 129 +NM_FUTURE_TLV = 130 # Diagnostic TLVs DG_MAC_EXTENDED_ADDRESS_TLV = 0