mirror of
https://github.com/espressif/openthread.git
synced 2026-07-28 22:57:47 +00:00
[routing-manager] stop PD if there is another prefix with higher preference in netdata (#10289)
This commit adds a new IDLE state to PdPrefixManager. PdPrefixManager enters idle state when PD is enabled and there is already a BR requesting PD prefix. When there are multiple BRs publishing PD prefix at the same time, the one with lexcial smaller prefix wins.
This commit is contained in:
+124
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (c) 2024, 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 ipaddress
|
||||
import typing
|
||||
import unittest
|
||||
|
||||
import config
|
||||
import thread_cert
|
||||
|
||||
# Test description:
|
||||
#
|
||||
# This test verifies DHCP6 PD pauses requesting PD prefix when there is another BR advertising PD prefix.
|
||||
#
|
||||
|
||||
LEADER = 1
|
||||
ROUTER = 2
|
||||
|
||||
|
||||
class TestDhcp6Pd(thread_cert.TestCase):
|
||||
SUPPORT_NCP = False
|
||||
USE_MESSAGE_FACTORY = False
|
||||
|
||||
TOPOLOGY = {
|
||||
LEADER: {
|
||||
'name': 'Leader',
|
||||
'allowlist': [ROUTER],
|
||||
'is_otbr': True,
|
||||
'mode': 'rdn',
|
||||
},
|
||||
ROUTER: {
|
||||
'name': 'Router',
|
||||
'allowlist': [LEADER],
|
||||
'is_otbr': True,
|
||||
'mode': 'rdn',
|
||||
},
|
||||
}
|
||||
|
||||
def test(self):
|
||||
leader = self.nodes[LEADER]
|
||||
router = self.nodes[ROUTER]
|
||||
|
||||
#---------------------------------------------------------------
|
||||
# Start the server & client devices.
|
||||
|
||||
# Case 1: Only 1 BR receives PD prefix
|
||||
|
||||
leader.start()
|
||||
self.simulator.go(config.LEADER_STARTUP_DELAY)
|
||||
self.assertEqual(leader.get_state(), 'leader')
|
||||
leader.pd_set_enabled(True)
|
||||
|
||||
router.start()
|
||||
self.simulator.go(config.ROUTER_STARTUP_DELAY)
|
||||
self.assertEqual(router.get_state(), 'router')
|
||||
router.pd_set_enabled(True)
|
||||
|
||||
leader.start_pd_radvd_service("2001:db8:abcd:1234::/64")
|
||||
self.simulator.go(30)
|
||||
|
||||
self.assertSetEqual({leader.pd_state, router.pd_state}, {"running", "idle"})
|
||||
|
||||
self.assertEqual(leader.pd_get_prefix(), "2001:db8:abcd:1234::/64")
|
||||
|
||||
# Case 2: More than one BR receives PD prefix
|
||||
# The BR with "smaller" PD prefix wins
|
||||
|
||||
# Clean up and ensure no prefix is currently published.
|
||||
leader.pd_set_enabled(False)
|
||||
router.pd_set_enabled(False)
|
||||
self.simulator.go(30)
|
||||
|
||||
leader.start_pd_radvd_service("2001:db8:abcd:1234::/64")
|
||||
router.start_pd_radvd_service("2001:db8:1234:abcd::/64")
|
||||
leader.pd_set_enabled(True)
|
||||
router.pd_set_enabled(True)
|
||||
self.simulator.go(30)
|
||||
|
||||
self.assertSetEqual({leader.pd_state, router.pd_state}, {"running", "idle"})
|
||||
|
||||
# Case 3: When the other BR lost PD prefix, the remaining BR should try to request one.
|
||||
|
||||
if leader.pd_state == 'running':
|
||||
br_to_stop = leader
|
||||
br_to_continue = router
|
||||
expected_prefix = "2001:db8:1234:abcd::/64"
|
||||
else:
|
||||
br_to_stop = router
|
||||
br_to_continue = leader
|
||||
expected_prefix = "2001:db8:abcd:1234::/64"
|
||||
br_to_stop.pd_set_enabled(False)
|
||||
self.simulator.go(30)
|
||||
|
||||
self.assertEqual(br_to_continue.pd_state, "running")
|
||||
self.assertEqual(br_to_continue.pd_get_prefix(), expected_prefix)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -2310,6 +2310,20 @@ class NodeImpl:
|
||||
self.send_command(cmd)
|
||||
return self._expect_command_output()[0]
|
||||
|
||||
def pd_get_prefix(self):
|
||||
cmd = 'br pd omrprefix'
|
||||
self.send_command(cmd)
|
||||
return self._expect_command_output()[0].split(" ")[0]
|
||||
|
||||
def pd_set_enabled(self, enable):
|
||||
self.send_command('br pd {}'.format("enable" if enable else "disable"))
|
||||
self._expect_done()
|
||||
|
||||
@property
|
||||
def pd_state(self):
|
||||
self.send_command('br pd state')
|
||||
return self._expect_command_output()[0].strip()
|
||||
|
||||
def get_netdata_non_nat64_routes(self):
|
||||
nat64_routes = []
|
||||
routes = self.get_routes()
|
||||
@@ -4097,6 +4111,33 @@ EOF
|
||||
self.bash('service radvd start')
|
||||
self.bash('service radvd status') # Make sure radvd service is running
|
||||
|
||||
def start_pd_radvd_service(self, prefix):
|
||||
self.bash("""cat >/etc/radvd.conf <<EOF
|
||||
interface wpan0
|
||||
{
|
||||
AdvSendAdvert on;
|
||||
|
||||
AdvReachableTime 20;
|
||||
AdvRetransTimer 20;
|
||||
AdvDefaultLifetime 180;
|
||||
MinRtrAdvInterval 120;
|
||||
MaxRtrAdvInterval 180;
|
||||
AdvDefaultPreference low;
|
||||
|
||||
prefix %s
|
||||
{
|
||||
AdvOnLink on;
|
||||
AdvAutonomous on;
|
||||
AdvRouterAddr off;
|
||||
AdvPreferredLifetime 180;
|
||||
AdvValidLifetime 180;
|
||||
};
|
||||
};
|
||||
EOF
|
||||
""" % (prefix,))
|
||||
self.bash('service radvd start')
|
||||
self.bash('service radvd status') # Make sure radvd service is running
|
||||
|
||||
def stop_radvd_service(self):
|
||||
self.bash('service radvd stop')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user