mirror of
https://github.com/espressif/openthread.git
synced 2026-08-04 09:57:47 +00:00
[nexus] add SRP-TC-6 for DNS name compression handling (#12765)
This commit adds the Nexus test case 1_3_SRP_TC_6 which verifies that the SRP server correctly handles SRP Updates both with and without DNS name compression, according to the Thread 1.3 test specification. The implementation includes: - tests/nexus/test_1_3_SRP_TC_6.cpp: Executes the test sequence by configuring a Thread Border Router (DUT), an End Device (ED), and an Infrastructure node (Eth). It uses SetDnsNameCompressionEnabled() to toggle name compression for SRP Updates. - tests/nexus/verify_1_3_SRP_TC_6.py: Performs automated verification of the captured traffic (PCAP), ensuring that SRP Updates, DNS queries, and mDNS responses are correctly formatted and contain the expected resource records. - Updating tests/nexus/CMakeLists.txt and tests/nexus/run_nexus_tests.sh to integrate the new test into the build and default test suite. The test ensures that the SRP server can successfully parse uncompressed names in SRP Updates and that subsequent DNS/mDNS discovery remains functional for both compressed and uncompressed registration formats.
This commit is contained in:
@@ -269,6 +269,7 @@ ot_nexus_test(1_3_SRP_TC_2 "cert;nexus")
|
||||
ot_nexus_test(1_3_SRP_TC_3 "cert;nexus")
|
||||
ot_nexus_test(1_3_SRP_TC_4 "cert;nexus")
|
||||
ot_nexus_test(1_3_SRP_TC_5 "cert;nexus")
|
||||
ot_nexus_test(1_3_SRP_TC_6 "cert;nexus")
|
||||
|
||||
# Misc tests
|
||||
ot_nexus_test(border_admitter "core;nexus")
|
||||
|
||||
@@ -204,6 +204,7 @@ DEFAULT_TESTS=(
|
||||
"1_3_SRP_TC_3"
|
||||
"1_3_SRP_TC_4"
|
||||
"1_3_SRP_TC_5"
|
||||
"1_3_SRP_TC_6"
|
||||
)
|
||||
|
||||
# Use provided arguments or the default test list
|
||||
|
||||
@@ -0,0 +1,391 @@
|
||||
/*
|
||||
* 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 <string.h>
|
||||
|
||||
#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 kJoinNetworkTime = 10 * 1000;
|
||||
|
||||
/**
|
||||
* Time to advance for the BR to perform automatic actions (RA, Network Data), in milliseconds.
|
||||
*/
|
||||
static constexpr uint32_t kBrActionTime = 20 * 1000;
|
||||
|
||||
/**
|
||||
* Time to advance for SRP server information to be updated in Network Data.
|
||||
*/
|
||||
static constexpr uint32_t kSrpServerInfoUpdateTime = 20 * 1000;
|
||||
|
||||
/**
|
||||
* Time to advance for SRP registration, in milliseconds.
|
||||
*/
|
||||
static constexpr uint32_t kSrpRegistrationTime = 10 * 1000;
|
||||
|
||||
/**
|
||||
* Time to advance for DNS query processing, in milliseconds.
|
||||
*/
|
||||
static constexpr uint32_t kDnsQueryTime = 5 * 1000;
|
||||
|
||||
/**
|
||||
* Infrastructure interface index.
|
||||
*/
|
||||
static constexpr uint32_t kInfraIfIndex = 1;
|
||||
|
||||
/**
|
||||
* SRP service registration parameters.
|
||||
*/
|
||||
static const char kSrpServiceType[] = "_thread-test._udp";
|
||||
static const char kSrpInstanceName[] = "service-test-1";
|
||||
static const char kSrpHostName[] = "host-test-1";
|
||||
static const char kSrpFullServiceType[] = "_thread-test._udp.default.service.arpa.";
|
||||
static constexpr uint16_t kSrpServicePort = 55555;
|
||||
static constexpr uint32_t kLease = 20 * 60; // 20 minutes
|
||||
static constexpr uint32_t kKeyLease = 20 * 60; // 20 minutes
|
||||
|
||||
void Test_1_3_SRP_TC_6(const char *aJsonFileName)
|
||||
{
|
||||
Srp::Client::Service service;
|
||||
|
||||
/**
|
||||
* 2.6. [1.3] [CERT] Name Compression
|
||||
*
|
||||
* 2.6.1. Purpose
|
||||
* To test the following:
|
||||
* - 1. Handle RRs without name compression.
|
||||
* - 2. Handle RRs with name compression
|
||||
*
|
||||
* 2.6.2. Topology
|
||||
* - 1. BR 1 (DUT) - Thread Border Router and the Leader
|
||||
* - 2. ED 1-Test Bed device operating as a Thread End Device, attached to BR_1
|
||||
* - 3. Eth 1-Test Bed border router device on an Adjacent Infrastructure Link
|
||||
*
|
||||
* Spec Reference | V1.1 Section | V1.3.0 Section
|
||||
* ---------------|--------------|---------------
|
||||
* SRP Server | N/A | 1.3
|
||||
*/
|
||||
|
||||
Core nexus;
|
||||
|
||||
Node &br1 = nexus.CreateNode();
|
||||
Node &ed1 = nexus.CreateNode();
|
||||
Node ð1 = nexus.CreateNode();
|
||||
|
||||
br1.SetName("BR_1");
|
||||
ed1.SetName("ED_1");
|
||||
eth1.SetName("Eth_1");
|
||||
|
||||
br1.Form();
|
||||
nexus.AdvanceTime(0);
|
||||
|
||||
Instance::SetLogLevel(kLogLevelNote);
|
||||
|
||||
Log("---------------------------------------------------------------------------------------");
|
||||
|
||||
/**
|
||||
* Step 1
|
||||
* - Device: BR 1 (DUT)
|
||||
* - Description (SRP-2.6): Enable
|
||||
* - Pass Criteria:
|
||||
* - N/A
|
||||
*/
|
||||
Log("Step 1: BR 1 (DUT) Enable.");
|
||||
SuccessOrQuit(br1.Get<Srp::Server>().SetAddressMode(Srp::Server::kAddressModeUnicast));
|
||||
br1.Get<Srp::Server>().SetEnabled(true);
|
||||
br1.Get<BorderRouter::InfraIf>().Init(kInfraIfIndex, true);
|
||||
br1.Get<BorderRouter::RoutingManager>().Init();
|
||||
SuccessOrQuit(br1.Get<BorderRouter::RoutingManager>().SetEnabled(true));
|
||||
nexus.AdvanceTime(kFormNetworkTime);
|
||||
|
||||
/**
|
||||
* Step 2
|
||||
* - Device: Eth 1. ED 1
|
||||
* - Description (SRP-2.6): Enable
|
||||
* - Pass Criteria:
|
||||
* - N/A
|
||||
*/
|
||||
Log("Step 2: Eth 1, ED 1 Enable.");
|
||||
ed1.Join(br1, Node::kAsFed);
|
||||
SuccessOrQuit(eth1.Get<Dns::Multicast::Core>().SetEnabled(true, kInfraIfIndex));
|
||||
nexus.AdvanceTime(kJoinNetworkTime);
|
||||
|
||||
// Wait for BR to advertise prefixes and ED to get an OMR address
|
||||
nexus.AdvanceTime(kBrActionTime);
|
||||
|
||||
/**
|
||||
* Step 3
|
||||
* - Device: BR 1 (DUT)
|
||||
* - Description (SRP-2.6): Automatically adds SRP Server information in the Thread Network Data. Automatically
|
||||
* adds OMR prefix to the Thread Network Data.
|
||||
* - Pass Criteria:
|
||||
* - The DUT's SRP Server information MUST appear in the Thread Network Data.
|
||||
*/
|
||||
Log("Step 3: BR 1 (DUT) adds SRP Server information in the Thread Network Data.");
|
||||
nexus.AdvanceTime(kSrpServerInfoUpdateTime);
|
||||
|
||||
/**
|
||||
* Step 4
|
||||
* - Device: ED 1
|
||||
* - Description (SRP-2.6): Harness instructs the device to send SRP Update without name compression: $ORIGIN
|
||||
* default.service.arpa. _thread-test. udp PTR service-test-1._thread-test._udp
|
||||
* service-test-1._thread-test._udp ( SRV 55555 host-test-1) host-test-1 AAAA OMR address of ED 1> with the
|
||||
* following options: Update Lease Option Lease: 20 minutes Key Lease: 20 minutes
|
||||
* - Pass Criteria:
|
||||
* - N/A
|
||||
*/
|
||||
Log("Step 4: ED 1 sends SRP Update without name compression.");
|
||||
{
|
||||
SuccessOrQuit(ed1.SetDnsNameCompressionEnabled(false));
|
||||
ed1.Get<Srp::Client>().EnableAutoStartMode(nullptr, nullptr);
|
||||
|
||||
ed1.Get<Srp::Client>().SetLeaseInterval(kLease);
|
||||
ed1.Get<Srp::Client>().SetKeyLeaseInterval(kKeyLease);
|
||||
|
||||
SuccessOrQuit(ed1.Get<Srp::Client>().SetHostName(kSrpHostName));
|
||||
SuccessOrQuit(ed1.Get<Srp::Client>().EnableAutoHostAddress());
|
||||
|
||||
ClearAllBytes(service);
|
||||
service.mName = kSrpServiceType;
|
||||
service.mInstanceName = kSrpInstanceName;
|
||||
service.mPort = kSrpServicePort;
|
||||
SuccessOrQuit(ed1.Get<Srp::Client>().AddService(service));
|
||||
}
|
||||
nexus.AdvanceTime(kSrpRegistrationTime);
|
||||
|
||||
/**
|
||||
* Step 5
|
||||
* - Device: BR 1 (DUT)
|
||||
* - Description (SRP-2.6): Automatically sends SRP Update Response.
|
||||
* - Pass Criteria:
|
||||
* - The DUT MUST send a valid SRP Update Response with Rcode=0 (NoError).
|
||||
*/
|
||||
Log("Step 5: BR 1 (DUT) sends SRP Update Response.");
|
||||
|
||||
/**
|
||||
* Step 6
|
||||
* - Device: ED 1
|
||||
* - Description (SRP-2.6): Harness instructs the device to unicast DNS QType PTR query to the DUT for all
|
||||
* services of type \"_thread-test._udp.local.\".
|
||||
* - Pass Criteria:
|
||||
* - N/A
|
||||
*/
|
||||
Log("Step 6: ED 1 sends unicast DNS QType PTR query.");
|
||||
{
|
||||
SuccessOrQuit(ed1.Get<Dns::Client>().Browse(kSrpFullServiceType, nullptr, nullptr));
|
||||
}
|
||||
nexus.AdvanceTime(kDnsQueryTime);
|
||||
|
||||
/**
|
||||
* Step 7
|
||||
* - Device: BR 1 (DUT)
|
||||
* - Description (SRP-2.6): Automatically sends DNS response.
|
||||
* - Pass Criteria:
|
||||
* - The DUT MUST send a valid DNS Response with RCODE=0 (NoError), containing in the Answers section: $ORIGIN
|
||||
* default.service.arpa. _thread-test. udp PTR service-test-1. thread-test._udp
|
||||
* - It MAY contain in the Additional records section: $ORIGIN local. Service-test-1_thread-test._udp ( SRV 0
|
||||
* 55555 host-test-1) testAAAA <OMR address of ED_1> host--1
|
||||
*/
|
||||
Log("Step 7: BR 1 (DUT) sends DNS response.");
|
||||
|
||||
/**
|
||||
* Step 8
|
||||
* - Device: Eth_1
|
||||
* - Description (SRP-2.6): Hamess instructs the device to send mDNS query QType=PTR query for all services of
|
||||
* type \"_thread-test._udp.local\"..
|
||||
* - Pass Criteria:
|
||||
* - N/A
|
||||
*/
|
||||
Log("Step 8: Eth 1 sends mDNS query QType=PTR.");
|
||||
{
|
||||
Dns::Multicast::Core::Browser browser;
|
||||
ClearAllBytes(browser);
|
||||
browser.mCallback = [](otInstance *, const otPlatDnssdBrowseResult *) {};
|
||||
browser.mServiceType = kSrpServiceType;
|
||||
browser.mInfraIfIndex = kInfraIfIndex;
|
||||
SuccessOrQuit(eth1.Get<Dns::Multicast::Core>().StartBrowser(browser));
|
||||
nexus.AdvanceTime(kDnsQueryTime);
|
||||
SuccessOrQuit(eth1.Get<Dns::Multicast::Core>().StopBrowser(browser));
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 9
|
||||
* - Device: BR 1 (DUT)
|
||||
* - Description (SRP-2.6): Automatically sends mDNS Response.
|
||||
* - Pass Criteria:
|
||||
* - The DUT MUST send a valid mDNS Response with Rcode=0 (NoError), containing in the Answers section: $ORIGIN
|
||||
* local. _thread-test. udp PTR service-test-1._thread-test._udp
|
||||
* - It MAY contain in the Additional records section: $ORIGIN local. Service-test-1. thread-test._udp SRV 55555
|
||||
* host-test-1) host-test-1 AAAA OMR address of ED_1>
|
||||
*/
|
||||
Log("Step 9: BR 1 (DUT) sends mDNS Response.");
|
||||
|
||||
/**
|
||||
* Step 9b
|
||||
* - Device: Eth 1
|
||||
* - Description (SRP-2.6): Harness instructs the device to send mDNS query QTYPE=SRV
|
||||
* QNAME-service-test-1._thread-test._udp.local
|
||||
* - Pass Criteria:
|
||||
* - The DUT MUST send a valid mDNS Response with RCODE=0, containing in the Answers section record:
|
||||
* service-test-1. thread-test. udp.local ( SRV 55555 host-test-1.local)
|
||||
*/
|
||||
Log("Step 9b: Eth 1 sends mDNS query QTYPE=SRV.");
|
||||
{
|
||||
Dns::Multicast::Core::SrvResolver resolver;
|
||||
|
||||
// Clear cache to force a new query
|
||||
SuccessOrQuit(eth1.Get<Dns::Multicast::Core>().SetEnabled(false, kInfraIfIndex));
|
||||
SuccessOrQuit(eth1.Get<Dns::Multicast::Core>().SetEnabled(true, kInfraIfIndex));
|
||||
|
||||
ClearAllBytes(resolver);
|
||||
resolver.mCallback = [](otInstance *, const otPlatDnssdSrvResult *) {};
|
||||
resolver.mServiceInstance = kSrpInstanceName;
|
||||
resolver.mServiceType = kSrpServiceType;
|
||||
resolver.mInfraIfIndex = kInfraIfIndex;
|
||||
SuccessOrQuit(eth1.Get<Dns::Multicast::Core>().StartSrvResolver(resolver));
|
||||
nexus.AdvanceTime(kDnsQueryTime);
|
||||
SuccessOrQuit(eth1.Get<Dns::Multicast::Core>().StopSrvResolver(resolver));
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 10
|
||||
* - Device: N/A
|
||||
* - Description (SRP-2.6): Repeat Steps 4 through 9b, where in step 4 name compression is enabled for all
|
||||
* repeated names in the SRP Update.
|
||||
* - Pass Criteria:
|
||||
* - Repeat Steps 4 through 9b.
|
||||
*/
|
||||
Log("Step 10: Repeat Steps 4 through 9b with name compression.");
|
||||
|
||||
// Repeat Step 4 (with compression)
|
||||
Log("Step 4 (Repeat): ED 1 sends SRP Update with name compression.");
|
||||
{
|
||||
SuccessOrQuit(ed1.SetDnsNameCompressionEnabled(true));
|
||||
ed1.Get<Srp::Client>().ClearHostAndServices();
|
||||
|
||||
ed1.Get<Srp::Client>().SetLeaseInterval(kLease);
|
||||
ed1.Get<Srp::Client>().SetKeyLeaseInterval(kKeyLease);
|
||||
|
||||
SuccessOrQuit(ed1.Get<Srp::Client>().SetHostName(kSrpHostName));
|
||||
SuccessOrQuit(ed1.Get<Srp::Client>().EnableAutoHostAddress());
|
||||
|
||||
ClearAllBytes(service);
|
||||
service.mName = kSrpServiceType;
|
||||
service.mInstanceName = kSrpInstanceName;
|
||||
service.mPort = kSrpServicePort;
|
||||
SuccessOrQuit(ed1.Get<Srp::Client>().AddService(service));
|
||||
}
|
||||
nexus.AdvanceTime(kSrpRegistrationTime);
|
||||
|
||||
// Step 5 (Repeat)
|
||||
Log("Step 5 (Repeat): BR 1 (DUT) sends SRP Update Response.");
|
||||
|
||||
// Step 6 (Repeat)
|
||||
Log("Step 6 (Repeat): ED 1 sends unicast DNS QType PTR query.");
|
||||
{
|
||||
SuccessOrQuit(ed1.Get<Dns::Client>().Browse(kSrpFullServiceType, nullptr, nullptr));
|
||||
}
|
||||
nexus.AdvanceTime(kDnsQueryTime);
|
||||
|
||||
// Step 7 (Repeat)
|
||||
Log("Step 7 (Repeat): BR 1 (DUT) sends DNS response.");
|
||||
|
||||
// Step 8 (Repeat)
|
||||
Log("Step 8 (Repeat): Eth 1 sends mDNS query QType=PTR.");
|
||||
{
|
||||
Dns::Multicast::Core::Browser browser;
|
||||
ClearAllBytes(browser);
|
||||
browser.mCallback = [](otInstance *, const otPlatDnssdBrowseResult *) {};
|
||||
browser.mServiceType = kSrpServiceType;
|
||||
browser.mInfraIfIndex = kInfraIfIndex;
|
||||
SuccessOrQuit(eth1.Get<Dns::Multicast::Core>().StartBrowser(browser));
|
||||
nexus.AdvanceTime(kDnsQueryTime);
|
||||
SuccessOrQuit(eth1.Get<Dns::Multicast::Core>().StopBrowser(browser));
|
||||
}
|
||||
|
||||
// Step 9 (Repeat)
|
||||
Log("Step 9 (Repeat): BR 1 (DUT) sends mDNS Response.");
|
||||
|
||||
// Step 9b (Repeat)
|
||||
Log("Step 9b (Repeat): Eth 1 sends mDNS query QTYPE=SRV.");
|
||||
{
|
||||
Dns::Multicast::Core::SrvResolver resolver;
|
||||
|
||||
// Clear cache to force a new query
|
||||
SuccessOrQuit(eth1.Get<Dns::Multicast::Core>().SetEnabled(false, kInfraIfIndex));
|
||||
SuccessOrQuit(eth1.Get<Dns::Multicast::Core>().SetEnabled(true, kInfraIfIndex));
|
||||
|
||||
ClearAllBytes(resolver);
|
||||
resolver.mCallback = [](otInstance *, const otPlatDnssdSrvResult *) {};
|
||||
resolver.mServiceInstance = kSrpInstanceName;
|
||||
resolver.mServiceType = kSrpServiceType;
|
||||
resolver.mInfraIfIndex = kInfraIfIndex;
|
||||
SuccessOrQuit(eth1.Get<Dns::Multicast::Core>().StartSrvResolver(resolver));
|
||||
nexus.AdvanceTime(kDnsQueryTime);
|
||||
SuccessOrQuit(eth1.Get<Dns::Multicast::Core>().StopSrvResolver(resolver));
|
||||
}
|
||||
|
||||
nexus.AddTestVar("ED_1_MLEID_ADDR", ed1.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
{
|
||||
Ip6::Prefix omrPrefix;
|
||||
SuccessOrQuit(br1.Get<BorderRouter::RoutingManager>().GetOmrPrefix(omrPrefix));
|
||||
nexus.AddTestVar("ED_1_OMR_ADDR",
|
||||
ed1.FindMatchingAddress(omrPrefix.ToString().AsCString()).ToString().AsCString());
|
||||
}
|
||||
nexus.AddTestVar("BR_1_MLEID_ADDR", br1.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
{
|
||||
String<10> portStr;
|
||||
portStr.Append("%u", br1.Get<Srp::Server>().GetPort());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", portStr.AsCString());
|
||||
}
|
||||
|
||||
nexus.SaveTestInfo(aJsonFileName);
|
||||
}
|
||||
|
||||
} // namespace Nexus
|
||||
} // namespace ot
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ot::Nexus::Test_1_3_SRP_TC_6((argc > 2) ? argv[2] : "test_1_3_SRP_TC_6.json");
|
||||
|
||||
printf("All tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
#!/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.addrs import Ipv6Addr, EthAddr
|
||||
|
||||
|
||||
def verify(pv):
|
||||
#
|
||||
# 2.6. [1.3] [CERT] Name Compression
|
||||
#
|
||||
# 2.6.1. Purpose
|
||||
# To test the following:
|
||||
# - 1. Handle RRs without name compression.
|
||||
# - 2. Handle RRs with name compression
|
||||
#
|
||||
# 2.6.2. Topology
|
||||
# - 1. BR 1 (DUT) - Thread Border Router and the Leader
|
||||
# - 2. ED 1-Test Bed device operating as a Thread End Device, attached to BR_1
|
||||
# - 3. Eth 1-Test Bed border router device on an Adjacent Infrastructure Link
|
||||
#
|
||||
# Spec Reference | V1.1 Section | V1.3.0 Section
|
||||
# ---------------|--------------|---------------
|
||||
# SRP Server | N/A | 1.3
|
||||
pkts = pv.pkts
|
||||
pv.summary.show()
|
||||
|
||||
ED_1_MLEID = Ipv6Addr(pv.vars['ED_1_MLEID_ADDR'])
|
||||
ED_1_OMR = Ipv6Addr(pv.vars['ED_1_OMR_ADDR'])
|
||||
BR_1_MLEID = Ipv6Addr(pv.vars['BR_1_MLEID_ADDR'])
|
||||
br1_srp_port = int(pv.vars['BR_1_SRP_PORT'])
|
||||
BR_1_ETH = EthAddr(pv.vars['BR_1_ETH'])
|
||||
|
||||
SRP_SERVICE_NAME = '_thread-test._udp.default.service.arpa'
|
||||
SRP_INSTANCE_NAME = 'service-test-1.' + SRP_SERVICE_NAME
|
||||
SRP_HOST_NAME = 'host-test-1.default.service.arpa'
|
||||
MDNS_SERVICE_NAME = '_thread-test._udp.local'
|
||||
MDNS_INSTANCE_NAME = 'service-test-1.' + MDNS_SERVICE_NAME
|
||||
MDNS_HOST_NAME = 'host-test-1.local'
|
||||
|
||||
SRP_SERVICE_PORT = 55555
|
||||
|
||||
SERVICE_ID_SRP_SERVER = 93
|
||||
|
||||
# Step 1: BR 1 (DUT) Enable.
|
||||
print("Step 1: BR 1 (DUT) Enable.")
|
||||
|
||||
# Step 2: Eth 1, ED 1 Enable.
|
||||
print("Step 2: Eth 1, ED 1 Enable.")
|
||||
|
||||
# Step 3: BR 1 (DUT) adds its SRP Server information in the Thread Network Data.
|
||||
print("Step 3: BR 1 (DUT) adds its SRP Server information in the Thread Network Data.")
|
||||
pkts.\
|
||||
filter_mle_cmd(consts.MLE_DATA_RESPONSE).\
|
||||
filter(lambda p: SERVICE_ID_SRP_SERVER in verify_utils.as_list(p.thread_nwd.tlv.service.srp_dataset_identifier)).\
|
||||
filter(lambda p: any(l in (1, 19) for l in verify_utils.as_list(p.thread_nwd.tlv.service.s_data_len))).\
|
||||
must_next()
|
||||
|
||||
# Step 4: ED 1 sends SRP Update without name compression.
|
||||
print("Step 4: ED 1 sends SRP Update without name compression.")
|
||||
pkts.\
|
||||
filter_ipv6_dst(BR_1_MLEID).\
|
||||
filter_ipv6_src(ED_1_MLEID).\
|
||||
filter(lambda p: p.udp.dstport == br1_srp_port).\
|
||||
filter(lambda p: p.dns.flags.opcode == 5).\
|
||||
filter(lambda p: not verify_utils.is_dns_compression_used(p)).\
|
||||
filter(lambda p: SRP_INSTANCE_NAME in verify_utils.as_list(p.dns.resp.name)).\
|
||||
filter(lambda p: SRP_SERVICE_PORT in verify_utils.as_list(p.dns.srv.port)).\
|
||||
filter(lambda p: SRP_HOST_NAME in verify_utils.as_list(p.dns.srv.target)).\
|
||||
filter(lambda p: ED_1_OMR in verify_utils.as_list(p.dns.aaaa)).\
|
||||
must_next()
|
||||
|
||||
# Step 5: BR 1 (DUT) sends SRP Update Response.
|
||||
print("Step 5: BR 1 (DUT) sends SRP Update Response.")
|
||||
pkts.\
|
||||
filter_ipv6_dst(ED_1_MLEID).\
|
||||
filter_ipv6_src(BR_1_MLEID).\
|
||||
filter(lambda p: p.udp.srcport == br1_srp_port).\
|
||||
filter(lambda p: p.dns.flags.response == 1).\
|
||||
filter(lambda p: p.dns.flags.rcode == 0).\
|
||||
must_next()
|
||||
|
||||
# Step 6: ED 1 sends unicast DNS QType PTR query.
|
||||
print("Step 6: ED 1 sends unicast DNS QType PTR query.")
|
||||
pkts.\
|
||||
filter_ipv6_dst(BR_1_MLEID).\
|
||||
filter_ipv6_src(ED_1_MLEID).\
|
||||
filter(lambda p: p.udp.dstport == 53).\
|
||||
filter(lambda p: p.dns.flags.response == 0).\
|
||||
filter(lambda p: SRP_SERVICE_NAME in verify_utils.as_list(p.dns.qry.name)).\
|
||||
must_next()
|
||||
|
||||
# Step 7: BR 1 (DUT) sends DNS response.
|
||||
print("Step 7: BR 1 (DUT) sends DNS response.")
|
||||
pkts.\
|
||||
filter_ipv6_dst(ED_1_MLEID).\
|
||||
filter_ipv6_src(BR_1_MLEID).\
|
||||
filter(lambda p: p.udp.srcport == 53).\
|
||||
filter(lambda p: p.dns.flags.response == 1).\
|
||||
filter(lambda p: p.dns.flags.rcode == 0).\
|
||||
filter(lambda p: SRP_INSTANCE_NAME in verify_utils.as_list(p.dns.ptr.domain_name)).\
|
||||
must_next()
|
||||
|
||||
# Step 8: Eth 1 sends mDNS query QType=PTR.
|
||||
print("Step 8: Eth 1 sends mDNS query QType=PTR.")
|
||||
pkts.\
|
||||
filter(lambda p: p.udp.dstport == 5353).\
|
||||
filter(lambda p: p.mdns.flags.response == 0).\
|
||||
filter(lambda p: MDNS_SERVICE_NAME in verify_utils.as_list(p.mdns.qry.name)).\
|
||||
must_next()
|
||||
|
||||
# Step 9: BR 1 (DUT) sends mDNS Response.
|
||||
print("Step 9: BR 1 (DUT) sends mDNS Response.")
|
||||
pkts.\
|
||||
filter_eth_src(BR_1_ETH).\
|
||||
filter(lambda p: p.udp.dstport == 5353).\
|
||||
filter(lambda p: p.mdns.flags.response == 1).\
|
||||
filter(lambda p: MDNS_SERVICE_NAME in verify_utils.as_list(p.mdns.resp.name)).\
|
||||
filter(lambda p: MDNS_INSTANCE_NAME in verify_utils.as_list(p.mdns.ptr.domain_name)).\
|
||||
must_next()
|
||||
|
||||
# Step 9b: Eth 1 sends mDNS query QTYPE=SRV.
|
||||
print("Step 9b: Eth 1 sends mDNS query QTYPE=SRV.")
|
||||
pkts.\
|
||||
filter(lambda p: p.udp.dstport == 5353).\
|
||||
filter(lambda p: p.mdns.flags.response == 0).\
|
||||
filter(lambda p: MDNS_INSTANCE_NAME in verify_utils.as_list(p.mdns.qry.name)).\
|
||||
must_next()
|
||||
|
||||
pkts.\
|
||||
filter_eth_src(BR_1_ETH).\
|
||||
filter(lambda p: p.udp.dstport == 5353).\
|
||||
filter(lambda p: p.mdns.flags.response == 1).\
|
||||
filter(lambda p: MDNS_INSTANCE_NAME in verify_utils.as_list(p.mdns.resp.name)).\
|
||||
filter(lambda p: SRP_SERVICE_PORT in verify_utils.as_list(p.mdns.srv.port)).\
|
||||
filter(lambda p: MDNS_HOST_NAME in verify_utils.as_list(p.mdns.srv.target)).\
|
||||
must_next()
|
||||
|
||||
# Step 10: Repeat Steps 4 through 9b with name compression.
|
||||
print("Step 10: Repeat Steps 4 through 9b with name compression.")
|
||||
|
||||
# Step 4 (Repeat)
|
||||
print("Step 4 (Repeat): ED 1 sends SRP Update with name compression.")
|
||||
pkts.\
|
||||
filter_ipv6_dst(BR_1_MLEID).\
|
||||
filter_ipv6_src(ED_1_MLEID).\
|
||||
filter(lambda p: p.udp.dstport == br1_srp_port).\
|
||||
filter(lambda p: p.dns.flags.opcode == 5).\
|
||||
filter(lambda p: verify_utils.is_dns_compression_used(p)).\
|
||||
filter(lambda p: SRP_INSTANCE_NAME in verify_utils.as_list(p.dns.resp.name)).\
|
||||
filter(lambda p: SRP_SERVICE_PORT in verify_utils.as_list(p.dns.srv.port)).\
|
||||
filter(lambda p: SRP_HOST_NAME in verify_utils.as_list(p.dns.srv.target)).\
|
||||
filter(lambda p: ED_1_OMR in verify_utils.as_list(p.dns.aaaa)).\
|
||||
must_next()
|
||||
|
||||
# Step 5 (Repeat)
|
||||
print("Step 5 (Repeat): BR 1 (DUT) sends SRP Update Response.")
|
||||
pkts.\
|
||||
filter_ipv6_dst(ED_1_MLEID).\
|
||||
filter_ipv6_src(BR_1_MLEID).\
|
||||
filter(lambda p: p.udp.srcport == br1_srp_port).\
|
||||
filter(lambda p: p.dns.flags.response == 1).\
|
||||
filter(lambda p: p.dns.flags.rcode == 0).\
|
||||
must_next()
|
||||
|
||||
# Step 6 (Repeat)
|
||||
print("Step 6 (Repeat): ED 1 sends unicast DNS QType PTR query.")
|
||||
pkts.\
|
||||
filter_ipv6_dst(BR_1_MLEID).\
|
||||
filter_ipv6_src(ED_1_MLEID).\
|
||||
filter(lambda p: p.udp.dstport == 53).\
|
||||
filter(lambda p: p.dns.flags.response == 0).\
|
||||
filter(lambda p: SRP_SERVICE_NAME in verify_utils.as_list(p.dns.qry.name)).\
|
||||
must_next()
|
||||
|
||||
# Step 7 (Repeat)
|
||||
print("Step 7 (Repeat): BR 1 (DUT) sends DNS response.")
|
||||
pkts.\
|
||||
filter_ipv6_dst(ED_1_MLEID).\
|
||||
filter_ipv6_src(BR_1_MLEID).\
|
||||
filter(lambda p: p.udp.srcport == 53).\
|
||||
filter(lambda p: p.dns.flags.response == 1).\
|
||||
filter(lambda p: p.dns.flags.rcode == 0).\
|
||||
filter(lambda p: SRP_INSTANCE_NAME in verify_utils.as_list(p.dns.ptr.domain_name)).\
|
||||
must_next()
|
||||
|
||||
# Step 8 (Repeat)
|
||||
print("Step 8 (Repeat): Eth 1 sends mDNS query QType=PTR.")
|
||||
pkts.\
|
||||
filter(lambda p: p.udp.dstport == 5353).\
|
||||
filter(lambda p: p.mdns.flags.response == 0).\
|
||||
filter(lambda p: MDNS_SERVICE_NAME in verify_utils.as_list(p.mdns.qry.name)).\
|
||||
must_next()
|
||||
|
||||
pkts.\
|
||||
filter_eth_src(BR_1_ETH).\
|
||||
filter(lambda p: p.udp.dstport == 5353).\
|
||||
filter(lambda p: p.mdns.flags.response == 1).\
|
||||
filter(lambda p: MDNS_SERVICE_NAME in verify_utils.as_list(p.mdns.resp.name)).\
|
||||
filter(lambda p: MDNS_INSTANCE_NAME in verify_utils.as_list(p.mdns.ptr.domain_name)).\
|
||||
must_next()
|
||||
|
||||
# Step 9 (Repeat)
|
||||
print("Step 9 (Repeat): BR 1 (DUT) sends mDNS Response.")
|
||||
|
||||
# Step 9b (Repeat)
|
||||
print("Step 9b (Repeat): Eth 1 sends mDNS query QTYPE=SRV.")
|
||||
pkts.\
|
||||
filter(lambda p: p.udp.dstport == 5353).\
|
||||
filter(lambda p: p.mdns.flags.response == 0).\
|
||||
filter(lambda p: MDNS_INSTANCE_NAME in verify_utils.as_list(p.mdns.qry.name)).\
|
||||
must_next()
|
||||
|
||||
pkts.\
|
||||
filter_eth_src(BR_1_ETH).\
|
||||
filter(lambda p: p.udp.dstport == 5353).\
|
||||
filter(lambda p: p.mdns.flags.response == 1).\
|
||||
filter(lambda p: MDNS_INSTANCE_NAME in verify_utils.as_list(p.mdns.resp.name)).\
|
||||
filter(lambda p: SRP_SERVICE_PORT in verify_utils.as_list(p.mdns.srv.port)).\
|
||||
filter(lambda p: MDNS_HOST_NAME in verify_utils.as_list(p.mdns.srv.target)).\
|
||||
must_next()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
verify_utils.run_main(verify)
|
||||
@@ -461,6 +461,34 @@ def is_leader_aloc_or_rloc(addr_str: str) -> bool:
|
||||
return is_aloc or is_rloc
|
||||
|
||||
|
||||
def is_dns_compression_used(p) -> bool:
|
||||
"""
|
||||
Check if any DNS name in the packet is compressed.
|
||||
"""
|
||||
dns = getattr(p, 'dns', None)
|
||||
if not dns:
|
||||
dns = getattr(p, 'mdns', None)
|
||||
if not dns:
|
||||
return False
|
||||
|
||||
try:
|
||||
raw_layer = dns._layer
|
||||
for field_name, field in raw_layer._all_fields.items():
|
||||
# Check fields that might contain DNS names
|
||||
if '.name' in field_name or '.target' in field_name or '.domain_name' in field_name:
|
||||
fields = field.fields if hasattr(field, 'fields') else [field]
|
||||
for f in fields:
|
||||
rv = f.raw_value
|
||||
if rv:
|
||||
for i in range(0, len(rv), 2):
|
||||
if int(rv[i:i + 2], 16) & 0xc0 == 0xc0:
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def apply_patches():
|
||||
CoapTlvParser.parse = staticmethod(thread_coap_tlv_parse)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user