[nexus] migrate test_ping_lla_src.py to nexus (#12990)

This commit migrates the test_ping_lla_src.py script from thread-cert
to the Nexus test framework.

The new test_ping_lla_src.cpp implements the same test logic:
- Forms a network with a Leader and two Routers.
- Verifies that pings using a Link-Local Address (LLA) as the source
  succeed when sent to a neighbor's Mesh-Local EID (ML-EID).
- Verifies that pings using an LLA source fail when sent to a
  non-neighbor's ML-EID, as LLAs are only valid for single-hop
  communication.
- Verifies that external routes are not used for LLA-sourced packets.

To support this migration, the Nexus Core class was enhanced with:
- Overloads for SendAndVerifyEchoRequest that allow specifying a
  source address.
- New SendAndVerifyNoEchoResponse methods to verify that no echo
  response is received (useful for negative test scenarios).

Changes:
- Added tests/nexus/test_ping_lla_src.cpp
- Updated tests/nexus/CMakeLists.txt to include the new test.
- Enhanced tests/nexus/platform/nexus_core.hpp/cpp with new helpers.
- Removed tests/scripts/thread-cert/test_ping_lla_src.py.
This commit is contained in:
Jonathan Hui
2026-04-28 14:36:19 -07:00
committed by GitHub
parent 752581826b
commit ef3122b496
6 changed files with 195 additions and 130 deletions
+1
View File
@@ -410,6 +410,7 @@ 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(ping_lla_src "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")
+49 -3
View File
@@ -1093,7 +1093,8 @@ void Core::SendAndVerifyEchoRequest(Node &aSender,
const Ip6::Address &aDestination,
uint16_t aPayloadSize,
uint8_t aHopLimit,
uint32_t aResponseTimeout)
uint32_t aResponseTimeout,
bool aForceSource)
{
static constexpr uint16_t kIdentifier = 0x1234;
@@ -1105,11 +1106,56 @@ void Core::SendAndVerifyEchoRequest(Node &aSender,
SuccessOrQuit(aSender.Get<Ip6::Icmp>().RegisterHandler(icmpHandler));
aSender.SendEchoRequest(aDestination, kIdentifier, aPayloadSize, aHopLimit);
aSender.SendEchoRequest(aDestination, kIdentifier, aPayloadSize, aHopLimit,
aForceSource ? &aExpectedSource : nullptr);
AdvanceTime(aResponseTimeout);
VerifyOrQuit(icmpContext.mResponseReceived);
SuccessOrQuit(aSender.Get<Ip6::Icmp>().UnregisterHandler(icmpHandler));
VerifyOrQuit(icmpContext.mResponseReceived);
}
void Core::SendAndVerifyNoEchoResponse(Node &aSender,
const Ip6::Address &aDestination,
uint16_t aPayloadSize,
uint8_t aHopLimit,
uint32_t aResponseTimeout)
{
static constexpr uint16_t kIdentifier = 0x1234;
IcmpEchoResponseContext icmpContext(aSender, kIdentifier);
Ip6::Icmp::Handler icmpHandler(HandleIcmpResponse, &icmpContext);
SuccessOrQuit(aSender.Get<Ip6::Icmp>().RegisterHandler(icmpHandler));
aSender.SendEchoRequest(aDestination, kIdentifier, aPayloadSize, aHopLimit);
AdvanceTime(aResponseTimeout);
SuccessOrQuit(aSender.Get<Ip6::Icmp>().UnregisterHandler(icmpHandler));
VerifyOrQuit(!icmpContext.mResponseReceived);
}
void Core::SendAndVerifyNoEchoResponse(Node &aSender,
const Ip6::Address &aSrcAddress,
const Ip6::Address &aDestination,
uint16_t aPayloadSize,
uint8_t aHopLimit,
uint32_t aResponseTimeout)
{
static constexpr uint16_t kIdentifier = 0x1234;
IcmpEchoResponseContext icmpContext(aSender, kIdentifier);
Ip6::Icmp::Handler icmpHandler(HandleIcmpResponse, &icmpContext);
SuccessOrQuit(aSender.Get<Ip6::Icmp>().RegisterHandler(icmpHandler));
aSender.SendEchoRequest(aDestination, kIdentifier, aPayloadSize, aHopLimit, &aSrcAddress);
AdvanceTime(aResponseTimeout);
SuccessOrQuit(aSender.Get<Ip6::Icmp>().UnregisterHandler(icmpHandler));
VerifyOrQuit(!icmpContext.mResponseReceived);
}
} // namespace Nexus
+15 -1
View File
@@ -96,7 +96,21 @@ public:
const Ip6::Address &aDestination,
uint16_t aPayloadSize = 0,
uint8_t aHopLimit = Ip6::kDefaultHopLimit,
uint32_t aResponseTimeout = 1000);
uint32_t aResponseTimeout = 1000,
bool aForceSource = true);
void SendAndVerifyNoEchoResponse(Node &aSender,
const Ip6::Address &aDestination,
uint16_t aPayloadSize = 0,
uint8_t aHopLimit = Ip6::kDefaultHopLimit,
uint32_t aResponseTimeout = 1000);
void SendAndVerifyNoEchoResponse(Node &aSender,
const Ip6::Address &aSrcAddress,
const Ip6::Address &aDestination,
uint16_t aPayloadSize = 0,
uint8_t aHopLimit = Ip6::kDefaultHopLimit,
uint32_t aResponseTimeout = 1000);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Used by platform implementation
+7 -7
View File
@@ -78,25 +78,25 @@ void TestIPv6SourceSelection(void)
Log("---------------------------------------------------------------------------------------");
Log("Step 1: RLOC source for RLOC destination");
nexus.SendAndVerifyEchoRequest(router, routerRloc, leaderRloc);
nexus.SendAndVerifyEchoRequest(router, routerRloc, leaderRloc, 0, Ip6::kDefaultHopLimit, 1000, false);
Log("---------------------------------------------------------------------------------------");
Log("Step 2: ML-EID source for ALOC destination");
nexus.SendAndVerifyEchoRequest(router, routerMleid, leaderAloc);
nexus.SendAndVerifyEchoRequest(router, routerMleid, leaderAloc, 0, Ip6::kDefaultHopLimit, 1000, false);
Log("---------------------------------------------------------------------------------------");
Log("Step 3: ML-EID source for ML-EID destination");
nexus.SendAndVerifyEchoRequest(router, routerMleid, leaderMleid);
nexus.SendAndVerifyEchoRequest(router, routerMleid, leaderMleid, 0, Ip6::kDefaultHopLimit, 1000, false);
Log("---------------------------------------------------------------------------------------");
Log("Step 4: Link-local source for Link-local destination");
nexus.SendAndVerifyEchoRequest(router, routerLinkLocal, leaderLinkLocal);
nexus.SendAndVerifyEchoRequest(router, routerLinkLocal, leaderLinkLocal, 0, Ip6::kDefaultHopLimit, 1000, false);
Log("---------------------------------------------------------------------------------------");
Log("Step 5: ML-EID source for Realm-local multicast destination");
Ip6::Address multicastAddr;
SuccessOrQuit(multicastAddr.FromString("ff03::1"));
nexus.SendAndVerifyEchoRequest(router, routerMleid, multicastAddr);
nexus.SendAndVerifyEchoRequest(router, routerMleid, multicastAddr, 0, Ip6::kDefaultHopLimit, 1000, false);
Log("---------------------------------------------------------------------------------------");
Log("Step 6: GUA source for GUA destination");
@@ -120,7 +120,7 @@ void TestIPv6SourceSelection(void)
VerifyOrQuit(!leaderGua.IsUnspecified());
VerifyOrQuit(!routerGua.IsUnspecified());
nexus.SendAndVerifyEchoRequest(router, routerGua, leaderGua);
nexus.SendAndVerifyEchoRequest(router, routerGua, leaderGua, 0, Ip6::kDefaultHopLimit, 1000, false);
Log("---------------------------------------------------------------------------------------");
Log("Step 7: GUA source for external address (default route)");
@@ -137,7 +137,7 @@ void TestIPv6SourceSelection(void)
extNetifAddr.mValid = true;
SuccessOrQuit(otIp6AddUnicastAddress(&leader.GetInstance(), &extNetifAddr));
nexus.SendAndVerifyEchoRequest(router, routerGua, externalAddr);
nexus.SendAndVerifyEchoRequest(router, routerGua, externalAddr, 0, Ip6::kDefaultHopLimit, 1000, false);
nexus.SaveTestInfo("test_ipv6_source_selection.json");
}
+123
View File
@@ -0,0 +1,123 @@
/*
* 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 {
void TestPingLlaSrc(void)
{
/**
* Test ping with LLA source address.
*
* Topology:
* ROUTER_2 ----- ROUTER_1 ---- ROUTER_3
*
* ROUTER_1 is leader. ROUTER_2 and ROUTER_3 are routers.
*/
Core nexus;
Node &router1 = nexus.CreateNode();
Node &router2 = nexus.CreateNode();
Node &router3 = nexus.CreateNode();
router1.SetName("Router_1");
router2.SetName("Router_2");
router3.SetName("Router_3");
AllowLinkBetween(router1, router2);
AllowLinkBetween(router1, router3);
nexus.AdvanceTime(0);
Log("---------------------------------------------------------------------------------------");
Log("Step 1: Form network");
router1.Form();
nexus.AdvanceTime(13 * 1000); // kFormNetworkTime
VerifyOrQuit(router1.Get<Mle::Mle>().IsLeader());
router2.Join(router1);
nexus.AdvanceTime(200 * 1000); // kAttachToRouterTime
VerifyOrQuit(router2.Get<Mle::Mle>().IsRouter());
router3.Join(router1);
nexus.AdvanceTime(200 * 1000); // kAttachToRouterTime
VerifyOrQuit(router3.Get<Mle::Mle>().IsRouter());
Ip6::Address router1Mleid = router1.Get<Mle::Mle>().GetMeshLocalEid();
Ip6::Address router2LinkLocal = router2.Get<Mle::Mle>().GetLinkLocalAddress();
Ip6::Address router3Mleid = router3.Get<Mle::Mle>().GetMeshLocalEid();
Log("---------------------------------------------------------------------------------------");
Log("Step 2: Ping a neighbor with LLA src should succeed");
// router2 pings router1's MLEID using its own LLA as source.
nexus.SendAndVerifyEchoRequest(router2, router2LinkLocal, router1Mleid);
Log("---------------------------------------------------------------------------------------");
Log("Step 3: Ping a non-neighbor with LLA src should fail");
// router2 pings router3's MLEID using its own LLA as source.
// It should fail because LLA is only valid for one-hop.
nexus.SendAndVerifyNoEchoResponse(router2, router2LinkLocal, router3Mleid);
Log("---------------------------------------------------------------------------------------");
Log("Step 4: Make sure external routes are not used for LLA src");
NetworkData::ExternalRouteConfig routeConfig;
routeConfig.Clear();
SuccessOrQuit(routeConfig.GetPrefix().FromString("2001::/64"));
routeConfig.mStable = true;
SuccessOrQuit(router1.Get<NetworkData::Local>().AddHasRoutePrefix(routeConfig));
router1.Get<NetworkData::Notifier>().HandleServerDataUpdated();
nexus.AdvanceTime(10 * 1000);
Ip6::Address externalAddr;
SuccessOrQuit(externalAddr.FromString("2001::1"));
// router2 pings external address using its own LLA as source.
// External routes should not be used for LLA source.
nexus.SendAndVerifyNoEchoResponse(router2, router2LinkLocal, externalAddr);
nexus.SaveTestInfo("test_ping_lla_src.json");
}
} // namespace Nexus
} // namespace ot
int main(void)
{
ot::Nexus::TestPingLlaSrc();
printf("All tests passed\n");
return 0;
}
@@ -1,119 +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 logging
import unittest
import pktverify
from pktverify import packet_verifier
import config
import thread_cert
# Test description:
# The purpose of this test is to verify the Router's routing behavior using LLA as source address.
#
# Topology:
#
#
# ROUTER_2 ----- ROUTER_1 ---- ROUTER_3
#
#
ROUTER_1 = 1
ROUTER_2 = 2
ROUTER_3 = 3
class TestPing(thread_cert.TestCase):
USE_MESSAGE_FACTORY = False
SUPPORT_NCP = False
TOPOLOGY = {
ROUTER_1: {
'name': 'Router_1',
'allowlist': [ROUTER_2, ROUTER_3],
},
ROUTER_2: {
'name': 'Router_2',
'allowlist': [ROUTER_1],
},
ROUTER_3: {
'name': 'Router_3',
'allowlist': [ROUTER_1],
},
}
def test(self):
router1 = self.nodes[ROUTER_1]
router2 = self.nodes[ROUTER_2]
router3 = self.nodes[ROUTER_3]
router1.start()
self.simulator.go(config.LEADER_STARTUP_DELAY)
self.assertEqual('leader', router1.get_state())
router2.start()
self.simulator.go(config.ROUTER_STARTUP_DELAY)
self.assertEqual('router', router2.get_state())
router3.start()
self.simulator.go(config.ROUTER_STARTUP_DELAY)
self.assertEqual('router', router3.get_state())
self.simulator.go(10)
left, center, right = router2, router1, router3
left_lla = left.get_ip6_address(config.ADDRESS_TYPE.LINK_LOCAL)
# Ping a neighbor with LLA src should succeed.
self.assertTrue(left.ping(center.get_mleid(), interface=left_lla))
self.simulator.go(3)
# Ping a non-neighbor with LLA src should fail.
self.assertFalse(left.ping(right.get_mleid(), interface=left_lla))
self.simulator.go(3)
center.add_route('2001::/64', stable=True)
center.register_netdata()
self.simulator.go(3)
# Make sure external routes are not used for LLA src.
self.assertFalse(left.ping("2001::1", interface=left_lla))
self.simulator.go(3)
def verify(self, pv: pktverify.packet_verifier.PacketVerifier):
pkts = pv.pkts
# Make sure the Ping Request to 2001::1 was not sent
pkts.filter_ipv6_dst('2001::1').filter_ping_request().must_not_next()
if __name__ == '__main__':
unittest.main()