[nexus] migrate test_pbbr_aloc.py to nexus (#12989)

This commit migrates the 'test_pbbr_aloc.py' script from the
thread-cert framework to the Nexus simulation framework.

The new 'test_pbbr_aloc.cpp' replicates the original test:
- Forms a network with PBBR, Leader, and Router nodes.
- Enables Backbone Router (BBR) on the PBBR node and waits for it
  to become the Primary BBR.
- Verifies connectivity to the Leader ALOC (0xfc00) and the PBBR
  ALOC (0xfc38) from the Router node using ICMPv6 Echo Requests.
- Confirms that the stack correctly uses Network Data for ALOC
  resolution.

Nexus tests provide faster and more scalable network simulations
within a single process, improving CI efficiency and reliability.

Original Python script 'tests/scripts/thread-cert/test_pbbr_aloc.py'
is removed as its functionality is now fully covered by Nexus.
This commit is contained in:
Jonathan Hui
2026-04-28 12:44:15 -07:00
committed by GitHub
parent 698c290a36
commit d8d1fe2134
5 changed files with 189 additions and 117 deletions
+1
View File
@@ -409,6 +409,7 @@ ot_nexus_test(mle_msg_key_seq_jump "core;nexus")
ot_nexus_test(nat64_translator "core;nexus")
ot_nexus_test(netdata_publisher "core;nexus")
ot_nexus_test(on_mesh_prefix "core;nexus")
ot_nexus_test(pbbr_aloc "core;nexus")
ot_nexus_test(reed_address_solicit_rejected "core;nexus")
ot_nexus_test(reset "core;nexus")
ot_nexus_test(router_downgrade_on_sec_policy_change "core;nexus")
+1
View File
@@ -237,6 +237,7 @@ DEFAULT_TESTS=(
"inform_previous_parent_on_reattach"
"leader_reboot_multiple_link_request"
"router_reboot_multiple_link_request"
"pbbr_aloc"
)
# Use provided arguments or the default test list
+111
View File
@@ -0,0 +1,111 @@
/*
* Copyright (c) 2026, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "platform/nexus_core.hpp"
#include "platform/nexus_node.hpp"
namespace ot {
namespace Nexus {
/** Delay in milliseconds for node startup/joining */
static constexpr uint32_t kNodeJoinDelay = 20 * 1000;
/** Delay in milliseconds for network to stabilize and PBBR to become primary */
static constexpr uint32_t kStabilizationDelay = 300 * 1000;
void TestPbbrAloc(void)
{
// Topology:
// PBBR -- LEADER -- ROUTER
Core nexus;
Node &pbbr = nexus.CreateNode();
Node &leader = nexus.CreateNode();
Node &router = nexus.CreateNode();
pbbr.SetName("PBBR");
leader.SetName("LEADER");
router.SetName("ROUTER");
nexus.AdvanceTime(0);
Log("---------------------------------------------------------------------------------------");
Log("Form network and enable PBBR");
AllowLinkBetween(pbbr, leader);
AllowLinkBetween(leader, router);
leader.Form();
nexus.AdvanceTime(kNodeJoinDelay);
pbbr.Join(leader);
pbbr.Get<BackboneRouter::Local>().SetEnabled(true);
nexus.AdvanceTime(kNodeJoinDelay);
router.Join(leader);
nexus.AdvanceTime(kNodeJoinDelay);
// Wait for network to stabilize and PBBR to become primary
nexus.AdvanceTime(kStabilizationDelay);
VerifyOrQuit(leader.Get<Mle::Mle>().IsLeader());
VerifyOrQuit(pbbr.Get<Mle::Mle>().IsRouter());
VerifyOrQuit(router.Get<Mle::Mle>().IsRouter());
VerifyOrQuit(pbbr.Get<BackboneRouter::Local>().IsPrimary());
Log("---------------------------------------------------------------------------------------");
Log("Verify ALOC connectivity");
Ip6::Address aloc;
// 1. Leader ALOC
leader.Get<Mle::Mle>().GetLeaderAloc(aloc);
Log("Pinging Leader ALOC %s from ROUTER", aloc.ToString().AsCString());
nexus.SendAndVerifyEchoRequest(router, aloc);
// 2. PBBR ALOC
aloc.SetPrefix(leader.Get<Mle::Mle>().GetMeshLocalPrefix());
aloc.GetIid().SetToLocator(Mle::Aloc16::ForPrimaryBackboneRouter());
Log("Pinging PBBR ALOC %s from ROUTER", aloc.ToString().AsCString());
nexus.SendAndVerifyEchoRequest(router, aloc);
Log("All tests passed");
nexus.SaveTestInfo("test_pbbr_aloc.json", &leader);
}
} // namespace Nexus
} // namespace ot
int main(void)
{
ot::Nexus::TestPbbrAloc();
return 0;
}
+76
View File
@@ -0,0 +1,76 @@
#!/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
from pktverify.bytes import Bytes
def verify(pv):
# The purpose of this test is to verify ALOC connectivity and ensure no Address Query is sent.
pkts = pv.pkts
pv.summary.show()
# Get Mesh-Local Prefix
mesh_local_prefix = pv.vars.get('mesh_local_prefix')
if mesh_local_prefix:
prefix = Bytes(Ipv6Addr(mesh_local_prefix.split('/')[0]))[:8]
else:
# Fallback to default if not provided
prefix = consts.DEFAULT_MESH_LOCAL_PREFIX
# Get ALOCs
LEADER_ALOC = pv.vars.get('LEADER_ALOC') or Ipv6Addr(prefix + consts.LEADER_ALOC_IID)
PBBR_ALOC = pv.vars.get('PBBR_ALOC') or Ipv6Addr(prefix + consts.PBBR_ALOC_IID)
# Verify Leader ALOC ping from ROUTER
print(f"Verifying Leader ALOC ({LEADER_ALOC}) ping from ROUTER")
pkts.filter_ping_request().filter_ipv6_dst(LEADER_ALOC).must_next()
pkts.filter_ping_reply().filter_ipv6_src(LEADER_ALOC).must_next()
# Verify PBBR ALOC ping from ROUTER
print(f"Verifying PBBR ALOC ({PBBR_ALOC}) ping from ROUTER")
pkts.filter_ping_request().filter_ipv6_dst(PBBR_ALOC).must_next()
pkts.filter_ping_reply().filter_ipv6_src(PBBR_ALOC).must_next()
# Make sure no ADDR_QUERY.qry is ever sent
pkts.filter_coap_request(consts.ADDR_QRY_URI).must_not_next()
if __name__ == '__main__':
verify_utils.run_main(verify)
-117
View File
@@ -1,117 +0,0 @@
#!/usr/bin/env python3
#
# Copyright (c) 2021, 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 re
import unittest
import config
import thread_cert
from config import MESH_LOCAL_PREFIX_REGEX_PATTERN, ROUTING_LOCATOR_REGEX_PATTERN
from pktverify.packet_verifier import PacketVerifier
# Test description:
# The purpose of this test is to verify ALOC connectivity.
#
# Topology:
#
#
# PBBR ----- LEADER ---- ROUTER
#
#
LEADER = 1
PBBR = 2
ROUTER = 3
class TestPing(thread_cert.TestCase):
USE_MESSAGE_FACTORY = False
SUPPORT_NCP = False
SUPPORT_THREAD_1_1 = False
TOPOLOGY = {
LEADER: {
'name': 'Router_1',
'allowlist': [PBBR, ROUTER],
},
PBBR: {
'name': 'Router_2',
'allowlist': [LEADER],
'is_bbr': True,
},
ROUTER: {
'name': 'Router_3',
'allowlist': [LEADER],
},
}
def test(self):
leader = self.nodes[LEADER]
pbbr = self.nodes[PBBR]
router = self.nodes[ROUTER]
leader.start()
self.simulator.go(config.LEADER_STARTUP_DELAY)
self.assertEqual('leader', leader.get_state())
pbbr.enable_backbone_router()
pbbr.start()
self.simulator.go(config.ROUTER_STARTUP_DELAY)
self.assertEqual('router', pbbr.get_state())
self.assertTrue(pbbr.is_primary_backbone_router)
router.start()
self.simulator.go(config.ROUTER_STARTUP_DELAY)
self.assertEqual('router', router.get_state())
for node in (leader, pbbr):
for addr in self.get_alocs(node):
self.assertTrue(router.ping(addr))
def verify(self, pv: PacketVerifier):
pkts = pv.pkts
# Must sure no ADDR_QUERY.qry is ever sent
pkts.filter_coap_request('/a/aq').must_not_next()
def get_alocs(self, node):
mleid = node.get_mleid()
for ip in node.get_addrs():
if not re.match(MESH_LOCAL_PREFIX_REGEX_PATTERN, ip):
continue
if ip == mleid:
continue
self.assertIsNotNone(re.match(ROUTING_LOCATOR_REGEX_PATTERN, ip), ip)
locator = int(ip.split(':')[-1], 16)
if locator >= 0xfc00:
yield ip
if __name__ == '__main__':
unittest.main()