From c82664c48f4ec2e22a5d19421d9383df98946ffd Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Mon, 16 Mar 2026 22:27:55 -0500 Subject: [PATCH] [nexus] add MATN-TC-09 test case for Primary BBR failure (#12696) This commit implements the MATN-TC-09 test case in the Nexus simulation framework to verify that a Secondary BBR correctly takes over forwarding of outbound multicast transmissions when the Primary BBR fails. Key implementation details include: - Implementation of the MATN-TC-09 test scenario in C++ simulating a topology with two Border Routers (BR_1 as initial Primary, BR_2 as Secondary/DUT) and a Thread Router. - Verification that BR_2 takes over as the Primary BBR and Leader after BR_1 is stopped. - Addition of a Python verification script to validate that only the Primary BBR forwards outbound multicast packets to the backbone link. - Use of distinct ICMPv6 identifiers to reliably distinguish between multicast pings sent before and after the Primary BBR failure. - Inclusion of the full test specification as inline comments in both the C++ and Python files. - Registration of the new test case in tests/nexus/CMakeLists.txt and tests/nexus/run_nexus_tests.sh. --- tests/nexus/CMakeLists.txt | 1 + tests/nexus/run_nexus_tests.sh | 1 + tests/nexus/test_1_2_MATN_TC_9.cpp | 264 ++++++++++++++++++ tests/nexus/verify_1_2_MATN_TC_9.py | 166 +++++++++++ .../thread-cert/pktverify/packet_filter.py | 2 +- 5 files changed, 433 insertions(+), 1 deletion(-) create mode 100644 tests/nexus/test_1_2_MATN_TC_9.cpp create mode 100644 tests/nexus/verify_1_2_MATN_TC_9.py diff --git a/tests/nexus/CMakeLists.txt b/tests/nexus/CMakeLists.txt index 5310ebed5..fe049b3cd 100644 --- a/tests/nexus/CMakeLists.txt +++ b/tests/nexus/CMakeLists.txt @@ -240,6 +240,7 @@ ot_nexus_test(1_2_MATN_TC_3 "cert;nexus") ot_nexus_test(1_2_MATN_TC_4 "cert;nexus") ot_nexus_test(1_2_MATN_TC_5 "cert;nexus") ot_nexus_test(1_2_MATN_TC_7 "cert;nexus") +ot_nexus_test(1_2_MATN_TC_9 "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 1eb59345c..31e23f867 100755 --- a/tests/nexus/run_nexus_tests.sh +++ b/tests/nexus/run_nexus_tests.sh @@ -175,6 +175,7 @@ DEFAULT_TESTS=( "1_2_MATN_TC_4" "1_2_MATN_TC_5" "1_2_MATN_TC_7" + "1_2_MATN_TC_9" ) # Use provided arguments or the default test list diff --git a/tests/nexus/test_1_2_MATN_TC_9.cpp b/tests/nexus/test_1_2_MATN_TC_9.cpp new file mode 100644 index 000000000..4416503cd --- /dev/null +++ b/tests/nexus/test_1_2_MATN_TC_9.cpp @@ -0,0 +1,264 @@ +/* + * 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 "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 = 10 * 1000; + +/** + * Time to advance for a node to join as a router, in milliseconds. + */ +static constexpr uint32_t kAttachToRouterTime = 200 * 1000; + +/** + * Time to advance for the network to stabilize, in milliseconds. + */ +static constexpr uint32_t kStabilizationTime = 10 * 1000; + +/** + * Time to advance for the BBR selection to complete, in milliseconds. + */ +static constexpr uint32_t kBbrSelectionTime = 10 * 1000; + +/** + * ICMPv6 Echo Request identifier. + */ +static constexpr uint16_t kEchoIdentifier = 0x1234; + +/** + * ICMPv6 Echo Request payload size. + */ +static constexpr uint16_t kEchoPayloadSize = 10; + +/** + * Multicast address MA1 (admin-local). + */ +static const char kMA1[] = "ff04::1234:777a:1"; + +void TestMatnTc9(void) +{ + /** + * 5.10.7 MATN-TC-09: Failure of Primary BBR – Outbound Multicast + * + * 5.10.7.1 Topology + * - BR_1: Test bed BR device initially operating as the Primary BBR. + * - BR_2 (DUT): BR Device initially operating as a Secondary BBR. BR_1 is disconnected during this test; the DUT + * becomes the Primary BBR afterwards. + * - Router: Test bed device operating as a Thread Router. + * + * 5.10.7.2 Purpose & Description + * Verify that a Secondary BBR can take over forwarding of outbound multicast transmissions from the Thread Network + * when the Primary BBR disconnects. The Secondary in that case becomes Primary. + * + * Spec Reference | V1.2 Section + * ---------------|------------- + * Multicast | 5.10.1 + */ + + Core nexus; + Node &br1 = nexus.CreateNode(); + Node &br2 = nexus.CreateNode(); + Node &router = nexus.CreateNode(); + Ip6::Address ma1; + + br1.SetName("BR_1"); + br2.SetName("BR_2"); + router.SetName("Router"); + + SuccessOrQuit(ma1.FromString(kMA1)); + + nexus.AdvanceTime(0); + + Instance::SetLogLevel(kLogLevelNote); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 0: Topology formation – BR_1, Router, BR_2 (DUT)"); + + /** + * Step 0 + * - Device: N/A + * - Description: Topology formation – BR_1, Router, BR_2 (DUT) + * - Pass Criteria: + * - N/A + */ + br1.AllowList(router); + br1.AllowList(br2); + router.AllowList(br1); + router.AllowList(br2); + br2.AllowList(br1); + br2.AllowList(router); + + br1.Form(); + nexus.AdvanceTime(kFormNetworkTime); + VerifyOrQuit(br1.Get().IsLeader()); + + br1.Get().Init(1, true); + br1.Get().Init(); + SuccessOrQuit(br1.Get().SetEnabled(true)); + br1.Get().SetEnabled(true); + + router.Join(br1, Node::kAsFtd); + nexus.AdvanceTime(kAttachToRouterTime); + VerifyOrQuit(router.Get().IsRouter()); + + /** + * P1: Router is configured such that it cannot become Leader when BR_1 disconnects during the test. + */ + router.Get().SetLeaderWeight(0); + + br2.Join(br1, Node::kAsFtd); + nexus.AdvanceTime(kAttachToRouterTime); + VerifyOrQuit(br2.Get().IsRouter()); + + /** + * Set BR_2 leader weight high to ensure it becomes leader. + */ + br2.Get().SetLeaderWeight(255); + + br2.Get().Init(1, true); + br2.Get().Init(); + SuccessOrQuit(br2.Get().SetEnabled(true)); + br2.Get().SetEnabled(true); + + nexus.AdvanceTime(kBbrSelectionTime); + nexus.AdvanceTime(kStabilizationTime); + + nexus.AddTestVar("MA1", kMA1); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 1: Router sends ICMPv6 Echo Request to MA1"); + + /** + * Step 1 + * - Device: Router + * - Description: Harness instructs the device to send a ICMPv6 Echo (ping) Request packet to the multicast address, + * MA1, encapsulated in an MPL packet + * - Pass Criteria: + * - N/A + */ + router.SendEchoRequest(ma1, kEchoIdentifier, kEchoPayloadSize); + nexus.AdvanceTime(kStabilizationTime); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 2: BR_1 forwards to LAN"); + + /** + * Step 2 + * - Device: BR_1 + * - Description: Automatically forwards the multicast ping request packet with multicast address, MA1, to the LAN. + * - Pass Criteria: + * - N/A + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 3: BR_2 (DUT) does not forward to LAN"); + + /** + * Step 3 + * - Device: BR_2 (DUT) + * - Description: Does not forward the multicast ping request packet to the LAN. + * - Pass Criteria: + * - The DUT MUST NOT forward the multicast ICMPv6 Echo (ping) Request packet with multicast address, MA1, to the + * LAN. + */ + + Log("---------------------------------------------------------------------------------------"); + Log("Step 4a: BR_1 powers down"); + + /** + * Step 4a + * - Device: BR_1 + * - Description: Harness instructs the device to power-down + * - Pass Criteria: + * - N/A + */ + br1.Get().Stop(); + nexus.AdvanceTime(kAttachToRouterTime); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 4b: BR_2 (DUT) becomes Leader/PBBR"); + + /** + * Step 4b + * - Device: BR_2 (DUT) + * - Description: Detects the missing Primary BBR and automatically becomes the Leader/PBBR of the Thread Network, + * distributing its BBR dataset. + * - Pass Criteria: + * - The DUT MUST become the Leader of the Thread Network by checking the Leader data. + * - Router MUST receive the new BBR Dataset from BR_2, where: + * - • RLOC16 in Server TLV == The RLOC16 of BR_2 + * - All fields in the BBR Dataset Service TLV MUST contain valid values. + */ + VerifyOrQuit(br2.Get().IsLeader()); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 5: Router sends ICMPv6 Echo Request to MA1"); + + /** + * Step 5 + * - Device: Router + * - Description: Harness instructs the device to send a ICMPv6 Echo (ping) Request packet to the multicast address, + * MA1, encapsulated in an MPL packet. + * - Pass Criteria: + * - N/A + */ + router.SendEchoRequest(ma1, kEchoIdentifier + 1, kEchoPayloadSize); + nexus.AdvanceTime(kStabilizationTime); + + Log("---------------------------------------------------------------------------------------"); + Log("Step 6: BR_2 (DUT) forwards to LAN"); + + /** + * Step 6 + * - Device: BR_2 (DUT) + * - Description: Automatically forwards the multicast ping request packet to the LAN. + * - Pass Criteria: + * - The DUT MUST forward the multicast ICMPv6 Echo (ping) Request packet with multicast address, MA1, to the LAN. + */ + + nexus.SaveTestInfo("test_1_2_MATN_TC_9.json"); +} + +} // namespace Nexus +} // namespace ot + +int main(void) +{ + ot::Nexus::TestMatnTc9(); + printf("All tests passed\n"); + return 0; +} diff --git a/tests/nexus/verify_1_2_MATN_TC_9.py b/tests/nexus/verify_1_2_MATN_TC_9.py new file mode 100644 index 000000000..8067c54eb --- /dev/null +++ b/tests/nexus/verify_1_2_MATN_TC_9.py @@ -0,0 +1,166 @@ +#!/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 + + +def verify(pv): + # 5.10.7 MATN-TC-09: Failure of Primary BBR – Outbound Multicast + # + # 5.10.7.1 Topology + # - BR_1 + # - BR_2 (DUT) + # - Router + # + # 5.10.7.2 Purpose & Description + # Verify that a Secondary BBR can take over forwarding of outbound multicast transmissions from the Thread Network + # when the Primary BBR disconnects. The Secondary in that case becomes Primary. + # + # Spec Reference | V1.2 Section + # ---------------|------------- + # Multicast | 5.10.1 + + pkts = pv.pkts + vars = pv.vars + pv.summary.show() + + ECHO_ID1 = 0x1234 + ECHO_ID2 = 0x1235 + + # Step 0 + # - Device: N/A + # - Description: Topology formation – BR_1, Router, BR_2 (DUT) + # - Pass Criteria: + # - N/A + print("Step 0: Topology formation – BR_1, Router, BR_2 (DUT)") + + # Step 1 + # - Device: Router + # - Description: Harness instructs the device to send a ICMPv6 Echo (ping) Request packet to the multicast address, + # MA1, encapsulated in an MPL packet + # - Pass Criteria: + # - N/A + print("Step 1: Router sends ICMPv6 Echo (ping) Request packet to MA1") + pkts.filter_ping_request(identifier=ECHO_ID1).\ + filter_wpan().\ + filter(lambda p: p.ipv6.dst == Ipv6Addr(vars['MA1']) or\ + p.ipv6.dst == 'ff03::fc').\ + must_next() + + # Step 2 + # - Device: BR_1 + # - Description: Automatically forwards the multicast ping request packet with multicast address, MA1, to the LAN. + # - Pass Criteria: + # - N/A + print("Step 2: BR_1 forwards the multicast ping request packet to the LAN") + pkts.filter_ping_request(identifier=ECHO_ID1).\ + filter(lambda p: not p.wpan).\ + filter(lambda p: p.eth.src == vars['BR_1_ETH']).\ + filter(lambda p: p.ipv6.dst == Ipv6Addr(vars['MA1'])).\ + must_next() + + # Step 3 + # - Device: BR_2 (DUT) + # - Description: Does not forward the multicast ping request packet to the LAN. + # - Pass Criteria: + # - The DUT MUST NOT forward the multicast ICMPv6 Echo (ping) Request packet with multicast address, MA1, to the + # LAN. + print("Step 3: BR_2 (DUT) does not forward the multicast ping request packet to the LAN") + pkts.copy().\ + filter_ping_request(identifier=ECHO_ID1).\ + filter(lambda p: not p.wpan).\ + filter(lambda p: p.eth.src == vars['BR_2_ETH']).\ + filter(lambda p: p.ipv6.dst == Ipv6Addr(vars['MA1'])).\ + must_not_next() + + # Step 4a + # - Device: BR_1 + # - Description: Harness instructs the device to power-down + # - Pass Criteria: + # - N/A + print("Step 4a: BR_1 powers down") + + # Step 4b: BR_2 (DUT) becomes Leader/PBBR + # - Device: BR_2 (DUT) + # - Description: Detects the missing Primary BBR and automatically becomes the Leader/PBBR of the Thread Network, + # distributing its BBR dataset. + # - Pass Criteria: + # - The DUT MUST become the Leader of the Thread Network by checking the Leader data. + # - Router MUST receive the new BBR Dataset from BR_2, where: + # - • RLOC16 in Server TLV == The RLOC16 of BR_2 + # - All fields in the BBR Dataset Service TLV MUST contain valid values. + print("Step 4b: BR_2 (DUT) becomes Leader/PBBR") + pkts.filter_wpan_src64(vars['BR_2']).\ + filter_mle_cmd(consts.MLE_ADVERTISEMENT).\ + filter(lambda p: p.mle.tlv.leader_data.router_id == vars['BR_2_RLOC16'] >> 10).\ + must_next() + + pkts.filter_wpan_src64(vars['BR_2']).\ + filter_mle_cmd(consts.MLE_DATA_RESPONSE).\ + filter_has_bbr_dataset().\ + filter(lambda p: vars['BR_2_RLOC16'] in p.thread_nwd.tlv.server_16).\ + must_next() + + # Step 5 + # - Device: Router + # - Description: Harness instructs the device to send a ICMPv6 Echo (ping) Request packet to the multicast address, + # MA1, encapsulated in an MPL packet. + # - Pass Criteria: + # - N/A + print("Step 5: Router sends ICMPv6 Echo (ping) Request packet to MA1") + pkts.filter_ping_request(identifier=ECHO_ID2).\ + filter_wpan().\ + filter(lambda p: p.ipv6.dst == Ipv6Addr(vars['MA1']) or\ + p.ipv6.dst == 'ff03::fc').\ + must_next() + + # Step 6 + # - Device: BR_2 (DUT) + # - Description: Automatically forwards the multicast ping request packet to the LAN. + # - Pass Criteria: + # - The DUT MUST forward the multicast ICMPv6 Echo (ping) Request packet with multicast address, MA1, to the LAN. + print("Step 6: BR_2 (DUT) forwards the multicast ping request packet to the LAN") + pkts.filter_ping_request(identifier=ECHO_ID2).\ + filter(lambda p: not p.wpan).\ + filter(lambda p: p.eth.src == vars['BR_2_ETH']).\ + filter(lambda p: p.ipv6.dst == Ipv6Addr(vars['MA1'])).\ + must_next() + + +if __name__ == '__main__': + verify_utils.run_main(verify) diff --git a/tests/scripts/thread-cert/pktverify/packet_filter.py b/tests/scripts/thread-cert/pktverify/packet_filter.py index 20aa65d65..cdd74f67c 100644 --- a/tests/scripts/thread-cert/pktverify/packet_filter.py +++ b/tests/scripts/thread-cert/pktverify/packet_filter.py @@ -629,7 +629,7 @@ class PacketFilter(object): def filter_has_bbr_dataset(self): return self.filter(""" - thread_nwd.tlv.server.has('16') + thread_nwd.tlv.server_16 is not null and thread_nwd.tlv.service.s_data.seqno is not null and thread_nwd.tlv.service.s_data.rrdelay is not null and thread_nwd.tlv.service.s_data.mlrtimeout is not null