xref: /aosp_15_r20/external/openthread/tests/toranj/ncp/test-033-mesh-local-prefix-change.py (revision cfb92d1480a9e65faed56933e9c12405f45898b4)
1#!/usr/bin/env python3
2#
3#  Copyright (c) 2019, The OpenThread Authors.
4#  All rights reserved.
5#
6#  Redistribution and use in source and binary forms, with or without
7#  modification, are permitted provided that the following conditions are met:
8#  1. Redistributions of source code must retain the above copyright
9#     notice, this list of conditions and the following disclaimer.
10#  2. Redistributions in binary form must reproduce the above copyright
11#     notice, this list of conditions and the following disclaimer in the
12#     documentation and/or other materials provided with the distribution.
13#  3. Neither the name of the copyright holder nor the
14#     names of its contributors may be used to endorse or promote products
15#     derived from this software without specific prior written permission.
16#
17#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27#  POSSIBILITY OF SUCH DAMAGE.
28
29import wpan
30from wpan import verify
31
32# -----------------------------------------------------------------------------------------------------------------------
33# Test description:
34#
35# This test covers the situation where a node attached to a parent with a different mesh-local prefix. It verifies
36# that the attaching node adopts the parent's mesh-local prefix and the RLOC addresses on the node are correctly
37# filtered (by wpantund).
38
39test_name = __file__[:-3] if __file__.endswith('.py') else __file__
40print('-' * 120)
41print('Starting \'{}\''.format(test_name))
42
43# -----------------------------------------------------------------------------------------------------------------------
44# Creating `wpan.Nodes` instances
45
46speedup = 4
47wpan.Node.set_time_speedup_factor(speedup)
48
49node1 = wpan.Node()
50node2 = wpan.Node()
51
52# -----------------------------------------------------------------------------------------------------------------------
53# Init all nodes
54
55wpan.Node.init_all_nodes()
56
57# -----------------------------------------------------------------------------------------------------------------------
58# Test implementation
59
60NET_NAME = 'ml-change'
61CHANNEL = 11
62PANID = '0x1977'
63XPANID = '1020031510006016'
64KEY = '0123456789abcdeffecdba9876543210'
65
66ML_PREFIX_1 = 'fd00:1::'
67ML_PREFIX_2 = 'fd00:2::'
68
69# Form a network on node1
70node1.form(
71    NET_NAME,
72    channel=CHANNEL,
73    panid=PANID,
74    xpanid=XPANID,
75    key=KEY,
76    mesh_local_prefix=ML_PREFIX_1,
77)
78
79# On node2, form a network with same parameters but a different mesh-local
80# prefix
81node2.form(
82    NET_NAME,
83    channel=CHANNEL,
84    panid=PANID,
85    xpanid=XPANID,
86    key=KEY,
87    mesh_local_prefix=ML_PREFIX_2,
88)
89
90# Node 2 is expected to attach to node1 and adopt the mesh-local prefix
91# from node1
92
93verify(node2.is_associated())
94verify(node2.get(wpan.WPAN_IP6_MESH_LOCAL_PREFIX) == node1.get(wpan.WPAN_IP6_MESH_LOCAL_PREFIX))
95
96# Ensure that there are only two addresses on the node2 (link-local and mesh-local address) and that RLOC
97# address is correctly filtered (by wpantund).
98verify(len(wpan.parse_list(node2.get(wpan.WPAN_IP6_ALL_ADDRESSES))) == 2)
99
100# -----------------------------------------------------------------------------------------------------------------------
101# Test finished
102
103wpan.Node.finalize_all_nodes()
104
105print('\'{}\' passed.'.format(test_name))
106