xref: /aosp_15_r20/external/openthread/tests/toranj/cli/test-027-slaac-address.py (revision cfb92d1480a9e65faed56933e9c12405f45898b4)
1*cfb92d14SAndroid Build Coastguard Worker#!/usr/bin/env python3
2*cfb92d14SAndroid Build Coastguard Worker#
3*cfb92d14SAndroid Build Coastguard Worker#  Copyright (c) 2023, The OpenThread Authors.
4*cfb92d14SAndroid Build Coastguard Worker#  All rights reserved.
5*cfb92d14SAndroid Build Coastguard Worker#
6*cfb92d14SAndroid Build Coastguard Worker#  Redistribution and use in source and binary forms, with or without
7*cfb92d14SAndroid Build Coastguard Worker#  modification, are permitted provided that the following conditions are met:
8*cfb92d14SAndroid Build Coastguard Worker#  1. Redistributions of source code must retain the above copyright
9*cfb92d14SAndroid Build Coastguard Worker#     notice, this list of conditions and the following disclaimer.
10*cfb92d14SAndroid Build Coastguard Worker#  2. Redistributions in binary form must reproduce the above copyright
11*cfb92d14SAndroid Build Coastguard Worker#     notice, this list of conditions and the following disclaimer in the
12*cfb92d14SAndroid Build Coastguard Worker#     documentation and/or other materials provided with the distribution.
13*cfb92d14SAndroid Build Coastguard Worker#  3. Neither the name of the copyright holder nor the
14*cfb92d14SAndroid Build Coastguard Worker#     names of its contributors may be used to endorse or promote products
15*cfb92d14SAndroid Build Coastguard Worker#     derived from this software without specific prior written permission.
16*cfb92d14SAndroid Build Coastguard Worker#
17*cfb92d14SAndroid Build Coastguard Worker#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18*cfb92d14SAndroid Build Coastguard Worker#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*cfb92d14SAndroid Build Coastguard Worker#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*cfb92d14SAndroid Build Coastguard Worker#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21*cfb92d14SAndroid Build Coastguard Worker#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*cfb92d14SAndroid Build Coastguard Worker#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*cfb92d14SAndroid Build Coastguard Worker#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*cfb92d14SAndroid Build Coastguard Worker#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25*cfb92d14SAndroid Build Coastguard Worker#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26*cfb92d14SAndroid Build Coastguard Worker#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27*cfb92d14SAndroid Build Coastguard Worker#  POSSIBILITY OF SUCH DAMAGE.
28*cfb92d14SAndroid Build Coastguard Worker
29*cfb92d14SAndroid Build Coastguard Workerfrom cli import verify
30*cfb92d14SAndroid Build Coastguard Workerfrom cli import verify_within
31*cfb92d14SAndroid Build Coastguard Workerimport cli
32*cfb92d14SAndroid Build Coastguard Workerimport time
33*cfb92d14SAndroid Build Coastguard Worker
34*cfb92d14SAndroid Build Coastguard Worker# -----------------------------------------------------------------------------------------------------------------------
35*cfb92d14SAndroid Build Coastguard Worker# Test description: Validate SLAAC module, addition/deprecation/removal of SLAAC addresses.
36*cfb92d14SAndroid Build Coastguard Worker#
37*cfb92d14SAndroid Build Coastguard Worker# Network topology
38*cfb92d14SAndroid Build Coastguard Worker#
39*cfb92d14SAndroid Build Coastguard Worker#    r1 ---- r2
40*cfb92d14SAndroid Build Coastguard Worker#
41*cfb92d14SAndroid Build Coastguard Worker
42*cfb92d14SAndroid Build Coastguard Workertest_name = __file__[:-3] if __file__.endswith('.py') else __file__
43*cfb92d14SAndroid Build Coastguard Workerprint('-' * 120)
44*cfb92d14SAndroid Build Coastguard Workerprint('Starting \'{}\''.format(test_name))
45*cfb92d14SAndroid Build Coastguard Worker
46*cfb92d14SAndroid Build Coastguard Worker# -----------------------------------------------------------------------------------------------------------------------
47*cfb92d14SAndroid Build Coastguard Worker# Creating `cli.Node` instances
48*cfb92d14SAndroid Build Coastguard Worker
49*cfb92d14SAndroid Build Coastguard Workerspeedup = 40
50*cfb92d14SAndroid Build Coastguard Workercli.Node.set_time_speedup_factor(speedup)
51*cfb92d14SAndroid Build Coastguard Worker
52*cfb92d14SAndroid Build Coastguard Workerr1 = cli.Node()
53*cfb92d14SAndroid Build Coastguard Workerr2 = cli.Node()
54*cfb92d14SAndroid Build Coastguard Workerc2 = cli.Node()
55*cfb92d14SAndroid Build Coastguard Worker
56*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - - -
57*cfb92d14SAndroid Build Coastguard Worker
58*cfb92d14SAndroid Build Coastguard Worker
59*cfb92d14SAndroid Build Coastguard Workerdef verify_slaac_address_for_prefix(prefix, preferred, nodes=[r1, r2], origin='slaac'):
60*cfb92d14SAndroid Build Coastguard Worker    # Verify that both nodes have SLAAC address based on `prefix`.
61*cfb92d14SAndroid Build Coastguard Worker    for node in nodes:
62*cfb92d14SAndroid Build Coastguard Worker        ip_addrs = node.get_ip_addrs('-v')
63*cfb92d14SAndroid Build Coastguard Worker        matched_addrs = [addr for addr in ip_addrs if addr.startswith(prefix)]
64*cfb92d14SAndroid Build Coastguard Worker        verify(len(matched_addrs) == 1)
65*cfb92d14SAndroid Build Coastguard Worker        addr = matched_addrs[0]
66*cfb92d14SAndroid Build Coastguard Worker        verify('origin:' + origin in addr)
67*cfb92d14SAndroid Build Coastguard Worker        verify('plen:64' in addr)
68*cfb92d14SAndroid Build Coastguard Worker        verify('valid:1' in addr)
69*cfb92d14SAndroid Build Coastguard Worker        if (preferred):
70*cfb92d14SAndroid Build Coastguard Worker            verify('preferred:1' in addr)
71*cfb92d14SAndroid Build Coastguard Worker        else:
72*cfb92d14SAndroid Build Coastguard Worker            verify('preferred:0' in addr)
73*cfb92d14SAndroid Build Coastguard Worker
74*cfb92d14SAndroid Build Coastguard Worker
75*cfb92d14SAndroid Build Coastguard Workerdef verify_no_slaac_address_for_prefix(prefix):
76*cfb92d14SAndroid Build Coastguard Worker    for node in [r1, r2]:
77*cfb92d14SAndroid Build Coastguard Worker        ip_addrs = node.get_ip_addrs('-v')
78*cfb92d14SAndroid Build Coastguard Worker        matched_addrs = [addr for addr in ip_addrs if addr.startswith(prefix)]
79*cfb92d14SAndroid Build Coastguard Worker        verify(len(matched_addrs) == 0)
80*cfb92d14SAndroid Build Coastguard Worker
81*cfb92d14SAndroid Build Coastguard Worker
82*cfb92d14SAndroid Build Coastguard Workerdef check_num_netdata_prefixes(num_prefixes):
83*cfb92d14SAndroid Build Coastguard Worker    for node in [r1, r2]:
84*cfb92d14SAndroid Build Coastguard Worker        verify(len(node.get_netdata_prefixes()) == num_prefixes)
85*cfb92d14SAndroid Build Coastguard Worker
86*cfb92d14SAndroid Build Coastguard Worker
87*cfb92d14SAndroid Build Coastguard Workerdef check_num_netdata_routes(num_routes):
88*cfb92d14SAndroid Build Coastguard Worker    for node in [r1, r2]:
89*cfb92d14SAndroid Build Coastguard Worker        verify(len(node.get_netdata_routes()) == num_routes)
90*cfb92d14SAndroid Build Coastguard Worker
91*cfb92d14SAndroid Build Coastguard Worker
92*cfb92d14SAndroid Build Coastguard Worker# -----------------------------------------------------------------------------------------------------------------------
93*cfb92d14SAndroid Build Coastguard Worker# Form topology
94*cfb92d14SAndroid Build Coastguard Worker
95*cfb92d14SAndroid Build Coastguard Workerr1.allowlist_node(r2)
96*cfb92d14SAndroid Build Coastguard Workerr2.allowlist_node(r1)
97*cfb92d14SAndroid Build Coastguard Workerr2.allowlist_node(c2)
98*cfb92d14SAndroid Build Coastguard Workerc2.allowlist_node(r2)
99*cfb92d14SAndroid Build Coastguard Worker
100*cfb92d14SAndroid Build Coastguard Workerr1.form('slaac')
101*cfb92d14SAndroid Build Coastguard Workerr2.join(r1)
102*cfb92d14SAndroid Build Coastguard Workerc2.join(r2, cli.JOIN_TYPE_END_DEVICE)
103*cfb92d14SAndroid Build Coastguard Worker
104*cfb92d14SAndroid Build Coastguard Workerverify(r1.get_state() == 'leader')
105*cfb92d14SAndroid Build Coastguard Workerverify(r2.get_state() == 'router')
106*cfb92d14SAndroid Build Coastguard Workerverify(c2.get_state() == 'child')
107*cfb92d14SAndroid Build Coastguard Worker
108*cfb92d14SAndroid Build Coastguard Worker# Ensure `c2` is attached to `r2` as its parent
109*cfb92d14SAndroid Build Coastguard Workerverify(int(c2.get_parent_info()['Rloc'], 16) == int(r2.get_rloc16(), 16))
110*cfb92d14SAndroid Build Coastguard Worker
111*cfb92d14SAndroid Build Coastguard Worker# -----------------------------------------------------------------------------------------------------------------------
112*cfb92d14SAndroid Build Coastguard Worker# Test Implementation
113*cfb92d14SAndroid Build Coastguard Worker
114*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
115*cfb92d14SAndroid Build Coastguard Worker# Add first prefix `fd00:11::/64` and check that SLAAC
116*cfb92d14SAndroid Build Coastguard Worker# addressed are added based on it on all nodes.
117*cfb92d14SAndroid Build Coastguard Worker
118*cfb92d14SAndroid Build Coastguard Workerr1.add_prefix("fd00:11:0:0::/64", "paos")
119*cfb92d14SAndroid Build Coastguard Workerr1.register_netdata()
120*cfb92d14SAndroid Build Coastguard Workerverify_within(check_num_netdata_prefixes, 100, 1)
121*cfb92d14SAndroid Build Coastguard Worker
122*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=True)
123*cfb92d14SAndroid Build Coastguard Worker
124*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
125*cfb92d14SAndroid Build Coastguard Worker# Add `fd00:22::/64` and check its related SLAAC addresses.
126*cfb92d14SAndroid Build Coastguard Worker
127*cfb92d14SAndroid Build Coastguard Workerr2.add_prefix("fd00:22:0:0::/64", "paos")
128*cfb92d14SAndroid Build Coastguard Workerr2.register_netdata()
129*cfb92d14SAndroid Build Coastguard Worker
130*cfb92d14SAndroid Build Coastguard Workerverify_within(check_num_netdata_prefixes, 100, 2)
131*cfb92d14SAndroid Build Coastguard Worker
132*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=True)
133*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:22:0:0:', preferred=True)
134*cfb92d14SAndroid Build Coastguard Worker
135*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
136*cfb92d14SAndroid Build Coastguard Worker# Add prefix `fd00:11::/64` now from `r2`, and since this was
137*cfb92d14SAndroid Build Coastguard Worker# previously added by `r1`, there should not change to SLAAC
138*cfb92d14SAndroid Build Coastguard Worker# addresses.
139*cfb92d14SAndroid Build Coastguard Worker
140*cfb92d14SAndroid Build Coastguard Workerr2.add_prefix("fd00:11:0:0::/64", "paos")
141*cfb92d14SAndroid Build Coastguard Workerr2.register_netdata()
142*cfb92d14SAndroid Build Coastguard Worker
143*cfb92d14SAndroid Build Coastguard Workerverify_within(check_num_netdata_prefixes, 100, 3)
144*cfb92d14SAndroid Build Coastguard Worker
145*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=True)
146*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:22:0:0:', preferred=True)
147*cfb92d14SAndroid Build Coastguard Worker
148*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
149*cfb92d14SAndroid Build Coastguard Worker# Remove prefix `fd00:11::/64` from `r2`, and since this is
150*cfb92d14SAndroid Build Coastguard Worker# also added by `r1`, there should not change to SLAAC addresses.
151*cfb92d14SAndroid Build Coastguard Worker
152*cfb92d14SAndroid Build Coastguard Workerr2.remove_prefix("fd00:11:0:0::/64")
153*cfb92d14SAndroid Build Coastguard Workerr2.register_netdata()
154*cfb92d14SAndroid Build Coastguard Worker
155*cfb92d14SAndroid Build Coastguard Workerverify_within(check_num_netdata_prefixes, 100, 2)
156*cfb92d14SAndroid Build Coastguard Worker
157*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=True)
158*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:22:0:0:', preferred=True)
159*cfb92d14SAndroid Build Coastguard Worker
160*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
161*cfb92d14SAndroid Build Coastguard Worker# Remove all prefixes and validate that all SLAAC addresses
162*cfb92d14SAndroid Build Coastguard Worker# start deprecating.
163*cfb92d14SAndroid Build Coastguard Worker
164*cfb92d14SAndroid Build Coastguard Workerr1.remove_prefix("fd00:11:0:0::/64")
165*cfb92d14SAndroid Build Coastguard Workerr1.register_netdata()
166*cfb92d14SAndroid Build Coastguard Workerr2.remove_prefix("fd00:22:0:0::/64")
167*cfb92d14SAndroid Build Coastguard Workerr2.register_netdata()
168*cfb92d14SAndroid Build Coastguard Worker
169*cfb92d14SAndroid Build Coastguard Workerverify_within(check_num_netdata_prefixes, 100, 0)
170*cfb92d14SAndroid Build Coastguard Worker
171*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=False)
172*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:22:0:0:', preferred=False)
173*cfb92d14SAndroid Build Coastguard Worker
174*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
175*cfb92d14SAndroid Build Coastguard Worker# Validate that the deprecating address can still be used
176*cfb92d14SAndroid Build Coastguard Worker# and proper route look up happens when it is used.
177*cfb92d14SAndroid Build Coastguard Worker
178*cfb92d14SAndroid Build Coastguard Worker# Add an off-mesh route `::/0` (default route) on `r1`.
179*cfb92d14SAndroid Build Coastguard Worker
180*cfb92d14SAndroid Build Coastguard Workerr1.add_route('::/0', 's', 'med')
181*cfb92d14SAndroid Build Coastguard Workerr1.register_netdata()
182*cfb92d14SAndroid Build Coastguard Worker
183*cfb92d14SAndroid Build Coastguard Workerverify_within(check_num_netdata_routes, 10, 1)
184*cfb92d14SAndroid Build Coastguard Worker
185*cfb92d14SAndroid Build Coastguard Worker# Now we ping from `r2` an off-mesh address, `r2` should pick one of
186*cfb92d14SAndroid Build Coastguard Worker# its deprecating addresses as the source address for this message.
187*cfb92d14SAndroid Build Coastguard Worker# Since the SLAAC module tracks the associated Domain ID from the
188*cfb92d14SAndroid Build Coastguard Worker# original Prefix TLV, the route lookup for this message should
189*cfb92d14SAndroid Build Coastguard Worker# successfully match to `r1` off-mesh route. We validate that the
190*cfb92d14SAndroid Build Coastguard Worker# message is indeed delivered to `r1` and passed to host.
191*cfb92d14SAndroid Build Coastguard Worker
192*cfb92d14SAndroid Build Coastguard Workerr1_counter = r1.get_br_counter_unicast_outbound_packets()
193*cfb92d14SAndroid Build Coastguard Worker
194*cfb92d14SAndroid Build Coastguard Workerr2.ping('fd00:ee::1', verify_success=False)
195*cfb92d14SAndroid Build Coastguard Worker
196*cfb92d14SAndroid Build Coastguard Workerverify(r1_counter + 1 == r1.get_br_counter_unicast_outbound_packets())
197*cfb92d14SAndroid Build Coastguard Worker
198*cfb92d14SAndroid Build Coastguard Worker# Repeat the same process but now ping from `c2` which is an
199*cfb92d14SAndroid Build Coastguard Worker# MTD child. `c2` would send the message to its parent `r2` which
200*cfb92d14SAndroid Build Coastguard Worker# should be able to successfully do route look up for the deprecating
201*cfb92d14SAndroid Build Coastguard Worker# prefix. The message should be delivered to `r1` and passed to host.
202*cfb92d14SAndroid Build Coastguard Worker
203*cfb92d14SAndroid Build Coastguard Workerr1_counter = r1.get_br_counter_unicast_outbound_packets()
204*cfb92d14SAndroid Build Coastguard Worker
205*cfb92d14SAndroid Build Coastguard Workerc2.ping('fd00:ff::1', verify_success=False)
206*cfb92d14SAndroid Build Coastguard Worker
207*cfb92d14SAndroid Build Coastguard Workerverify(r1_counter + 1 == r1.get_br_counter_unicast_outbound_packets())
208*cfb92d14SAndroid Build Coastguard Worker
209*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
210*cfb92d14SAndroid Build Coastguard Worker# Before the address is expired, re-add ``fd00:11::/64` prefix
211*cfb92d14SAndroid Build Coastguard Worker# and check that the address is added back as preferred.
212*cfb92d14SAndroid Build Coastguard Worker
213*cfb92d14SAndroid Build Coastguard Workerr2.add_prefix("fd00:11:0:0::/64", "paors")
214*cfb92d14SAndroid Build Coastguard Workerr2.register_netdata()
215*cfb92d14SAndroid Build Coastguard Worker
216*cfb92d14SAndroid Build Coastguard Workerverify_within(check_num_netdata_prefixes, 100, 1)
217*cfb92d14SAndroid Build Coastguard Worker
218*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=True)
219*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:22:0:0:', preferred=False)
220*cfb92d14SAndroid Build Coastguard Worker
221*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
222*cfb92d14SAndroid Build Coastguard Worker# Make sure prefix 2 is expired and removed
223*cfb92d14SAndroid Build Coastguard Worker
224*cfb92d14SAndroid Build Coastguard Worker
225*cfb92d14SAndroid Build Coastguard Workerdef check_prefix_2_addr_expire():
226*cfb92d14SAndroid Build Coastguard Worker    verify_no_slaac_address_for_prefix('fd00:22:0:0:')
227*cfb92d14SAndroid Build Coastguard Worker
228*cfb92d14SAndroid Build Coastguard Worker
229*cfb92d14SAndroid Build Coastguard Workerverify_within(check_prefix_2_addr_expire, 100)
230*cfb92d14SAndroid Build Coastguard Worker
231*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=True)
232*cfb92d14SAndroid Build Coastguard Worker
233*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
234*cfb92d14SAndroid Build Coastguard Worker# Manually add an address for prefix `fd00:33::/64` on `r1`
235*cfb92d14SAndroid Build Coastguard Worker# and `r2` before adding  a related on-mesh prefix. Validate that
236*cfb92d14SAndroid Build Coastguard Worker# the SLAAC module does not add addresses.
237*cfb92d14SAndroid Build Coastguard Worker
238*cfb92d14SAndroid Build Coastguard Workerr1.add_ip_addr('fd00:33::1')
239*cfb92d14SAndroid Build Coastguard Workerr2.add_ip_addr('fd00:33::2')
240*cfb92d14SAndroid Build Coastguard Worker
241*cfb92d14SAndroid Build Coastguard Workerr1.add_prefix("fd00:33:0:0::/64", "paos")
242*cfb92d14SAndroid Build Coastguard Workerr1.register_netdata()
243*cfb92d14SAndroid Build Coastguard Worker
244*cfb92d14SAndroid Build Coastguard Workerverify_within(check_num_netdata_prefixes, 100, 2)
245*cfb92d14SAndroid Build Coastguard Worker
246*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=True)
247*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:33:0:0:', preferred=True, origin='manual')
248*cfb92d14SAndroid Build Coastguard Worker
249*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
250*cfb92d14SAndroid Build Coastguard Worker# Remove the manually added address on `r2` which should trigger
251*cfb92d14SAndroid Build Coastguard Worker# SLAAC module to add its own SLAAC address based on the prefix.
252*cfb92d14SAndroid Build Coastguard Worker
253*cfb92d14SAndroid Build Coastguard Workerr2.remove_ip_addr('fd00:33::2')
254*cfb92d14SAndroid Build Coastguard Workertime.sleep(0.1)
255*cfb92d14SAndroid Build Coastguard Worker
256*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=True)
257*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:33:0:0:', preferred=True, nodes=[r2], origin='slaac')
258*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:33:0:0:', preferred=True, nodes=[r1], origin='manual')
259*cfb92d14SAndroid Build Coastguard Worker
260*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
261*cfb92d14SAndroid Build Coastguard Worker# Remove the prefix and make sure the manually added address
262*cfb92d14SAndroid Build Coastguard Worker# is not impacted, but the one added by SLAAC on `r2` should
263*cfb92d14SAndroid Build Coastguard Worker# be deprecating.
264*cfb92d14SAndroid Build Coastguard Worker
265*cfb92d14SAndroid Build Coastguard Workerr1.remove_prefix("fd00:33:0:0::/64")
266*cfb92d14SAndroid Build Coastguard Workerr1.register_netdata()
267*cfb92d14SAndroid Build Coastguard Worker
268*cfb92d14SAndroid Build Coastguard Workerverify_within(check_num_netdata_prefixes, 100, 1)
269*cfb92d14SAndroid Build Coastguard Worker
270*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=True)
271*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:33:0:0:', preferred=False, nodes=[r2], origin='slaac')
272*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:33:0:0:', preferred=True, nodes=[r1], origin='manual')
273*cfb92d14SAndroid Build Coastguard Worker
274*cfb92d14SAndroid Build Coastguard Workerr1.remove_ip_addr('fd00:33::1')
275*cfb92d14SAndroid Build Coastguard Worker
276*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
277*cfb92d14SAndroid Build Coastguard Worker# Toranj config sets the max number of SLAAC addresses to 4
278*cfb92d14SAndroid Build Coastguard Worker# Check that the max limit is applied by adding 5 prefixes.
279*cfb92d14SAndroid Build Coastguard Worker
280*cfb92d14SAndroid Build Coastguard Workerr1.add_prefix("fd00:22:0:0::/64", "paos")
281*cfb92d14SAndroid Build Coastguard Workerr1.add_prefix("fd00:33:0:0::/64", "paos")
282*cfb92d14SAndroid Build Coastguard Workerr1.add_prefix("fd00:44:0:0::/64", "paos")
283*cfb92d14SAndroid Build Coastguard Workerr1.register_netdata()
284*cfb92d14SAndroid Build Coastguard Worker
285*cfb92d14SAndroid Build Coastguard Workerverify_within(check_num_netdata_prefixes, 100, 4)
286*cfb92d14SAndroid Build Coastguard Worker
287*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=True)
288*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:22:0:0:', preferred=True)
289*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:33:0:0:', preferred=True)
290*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:44:0:0:', preferred=True)
291*cfb92d14SAndroid Build Coastguard Worker
292*cfb92d14SAndroid Build Coastguard Workerr1.add_prefix("fd00:55:0:0::/64", "paos")
293*cfb92d14SAndroid Build Coastguard Workerr1.register_netdata()
294*cfb92d14SAndroid Build Coastguard Worker
295*cfb92d14SAndroid Build Coastguard Workerverify_within(check_num_netdata_prefixes, 100, 5)
296*cfb92d14SAndroid Build Coastguard Worker
297*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=True)
298*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:22:0:0:', preferred=True)
299*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:33:0:0:', preferred=True)
300*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:44:0:0:', preferred=True)
301*cfb92d14SAndroid Build Coastguard Workerverify_no_slaac_address_for_prefix('fd00:55:0:0::/64')
302*cfb92d14SAndroid Build Coastguard Worker
303*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
304*cfb92d14SAndroid Build Coastguard Worker# Remove one of the prefixes which should deprecate an
305*cfb92d14SAndroid Build Coastguard Worker# existing SLAAC address which should then be evicted to
306*cfb92d14SAndroid Build Coastguard Worker# add address for the new `fd00:55::/64` prefix.
307*cfb92d14SAndroid Build Coastguard Worker
308*cfb92d14SAndroid Build Coastguard Workerr1.remove_prefix("fd00:44:0:0::/64")
309*cfb92d14SAndroid Build Coastguard Workerr1.register_netdata()
310*cfb92d14SAndroid Build Coastguard Worker
311*cfb92d14SAndroid Build Coastguard Workerverify_within(check_num_netdata_prefixes, 100, 4)
312*cfb92d14SAndroid Build Coastguard Worker
313*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=True)
314*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:22:0:0:', preferred=True)
315*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:33:0:0:', preferred=True)
316*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:55:0:0:', preferred=True)
317*cfb92d14SAndroid Build Coastguard Workerverify_no_slaac_address_for_prefix('fd00:44:0:0::/64')
318*cfb92d14SAndroid Build Coastguard Worker
319*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
320*cfb92d14SAndroid Build Coastguard Worker# Validate oldest entry is evicted when multiple addresses are deprecating
321*cfb92d14SAndroid Build Coastguard Worker# and new prefix is added.
322*cfb92d14SAndroid Build Coastguard Worker
323*cfb92d14SAndroid Build Coastguard Workerr1.remove_prefix("fd00:33:0:0::/64")
324*cfb92d14SAndroid Build Coastguard Workerr1.register_netdata()
325*cfb92d14SAndroid Build Coastguard Workertime.sleep(0.05)
326*cfb92d14SAndroid Build Coastguard Workerr1.remove_prefix("fd00:22:0:0::/64")
327*cfb92d14SAndroid Build Coastguard Workerr1.register_netdata()
328*cfb92d14SAndroid Build Coastguard Workertime.sleep(0.05)
329*cfb92d14SAndroid Build Coastguard Workerr1.remove_prefix("fd00:55:0:0::/64")
330*cfb92d14SAndroid Build Coastguard Workerr1.register_netdata()
331*cfb92d14SAndroid Build Coastguard Workertime.sleep(0.05)
332*cfb92d14SAndroid Build Coastguard Worker
333*cfb92d14SAndroid Build Coastguard Workerverify_within(check_num_netdata_prefixes, 100, 1)
334*cfb92d14SAndroid Build Coastguard Worker
335*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=True)
336*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:22:0:0:', preferred=False)
337*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:33:0:0:', preferred=False)
338*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:55:0:0:', preferred=False)
339*cfb92d14SAndroid Build Coastguard Worker
340*cfb92d14SAndroid Build Coastguard Worker# Now add a new prefix `fd00:66::/64`, the `fd00:33::` address
341*cfb92d14SAndroid Build Coastguard Worker# which was removed first should be evicted to make room for
342*cfb92d14SAndroid Build Coastguard Worker# the SLAAC address for the new prefix.
343*cfb92d14SAndroid Build Coastguard Worker
344*cfb92d14SAndroid Build Coastguard Workerr1.add_prefix("fd00:66:0:0::/64", "paos")
345*cfb92d14SAndroid Build Coastguard Workerr1.register_netdata()
346*cfb92d14SAndroid Build Coastguard Worker
347*cfb92d14SAndroid Build Coastguard Workerverify_within(check_num_netdata_prefixes, 100, 2)
348*cfb92d14SAndroid Build Coastguard Worker
349*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=True)
350*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:22:0:0:', preferred=False)
351*cfb92d14SAndroid Build Coastguard Workerverify_no_slaac_address_for_prefix('fd00:33:0:0:')
352*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:55:0:0:', preferred=False)
353*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:66:0:0:', preferred=True)
354*cfb92d14SAndroid Build Coastguard Worker
355*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
356*cfb92d14SAndroid Build Coastguard Worker# Validate re-adding of a prefix before its address is deprecated.
357*cfb92d14SAndroid Build Coastguard Worker
358*cfb92d14SAndroid Build Coastguard Workerr1.add_prefix("fd00:22:0:0::/64", "paos")
359*cfb92d14SAndroid Build Coastguard Workerr1.register_netdata()
360*cfb92d14SAndroid Build Coastguard Worker
361*cfb92d14SAndroid Build Coastguard Workerverify_within(check_num_netdata_prefixes, 100, 3)
362*cfb92d14SAndroid Build Coastguard Worker
363*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:11:0:0:', preferred=True)
364*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:22:0:0:', preferred=True)
365*cfb92d14SAndroid Build Coastguard Workerverify_no_slaac_address_for_prefix('fd00:33:0:0:')
366*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:55:0:0:', preferred=False)
367*cfb92d14SAndroid Build Coastguard Workerverify_slaac_address_for_prefix('fd00:66:0:0:', preferred=True)
368*cfb92d14SAndroid Build Coastguard Worker
369*cfb92d14SAndroid Build Coastguard Worker
370*cfb92d14SAndroid Build Coastguard Workerdef check_prefix_5_addr_expire():
371*cfb92d14SAndroid Build Coastguard Worker    verify_no_slaac_address_for_prefix('fd00:55:0:0:')
372*cfb92d14SAndroid Build Coastguard Worker
373*cfb92d14SAndroid Build Coastguard Worker
374*cfb92d14SAndroid Build Coastguard Workerverify_within(check_prefix_5_addr_expire, 100)
375*cfb92d14SAndroid Build Coastguard Worker
376*cfb92d14SAndroid Build Coastguard Worker# -----------------------------------------------------------------------------------------------------------------------
377*cfb92d14SAndroid Build Coastguard Worker# Test finished
378*cfb92d14SAndroid Build Coastguard Worker
379*cfb92d14SAndroid Build Coastguard Workercli.Node.finalize_all_nodes()
380*cfb92d14SAndroid Build Coastguard Worker
381*cfb92d14SAndroid Build Coastguard Workerprint('\'{}\' passed.'.format(test_name))
382