1*cfb92d14SAndroid Build Coastguard Worker#!/usr/bin/env python3 2*cfb92d14SAndroid Build Coastguard Worker# 3*cfb92d14SAndroid Build Coastguard Worker# Copyright (c) 2019, 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 Workerimport time 30*cfb92d14SAndroid Build Coastguard Workerimport wpan 31*cfb92d14SAndroid Build Coastguard Workerfrom wpan import verify 32*cfb92d14SAndroid Build Coastguard Worker 33*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 34*cfb92d14SAndroid Build Coastguard Worker# Test description: SLAAC address 35*cfb92d14SAndroid Build Coastguard Worker# 36*cfb92d14SAndroid Build Coastguard Worker# This test covers the behavior of SLAAC module in OpenThread (NCP): 37*cfb92d14SAndroid Build Coastguard Worker# 38*cfb92d14SAndroid Build Coastguard Worker# - Verify that adding prefix (with SLAAC flag) causes a corresponding SLAAC IPv6 address to be added. 39*cfb92d14SAndroid Build Coastguard Worker# - Verify that removing the prefix, would remove the SLAAC address. 40*cfb92d14SAndroid Build Coastguard Worker# - Verify behavior when same prefix is added/removed on multiple nodes (with or without SLAAC flag). 41*cfb92d14SAndroid Build Coastguard Worker# - Check behavior when a user-added address with the same prefix already exists. 42*cfb92d14SAndroid Build Coastguard Worker# - Check behavior when a user-added address with same prefix is removed (SLAAC module should add a SLAAC address). 43*cfb92d14SAndroid Build Coastguard Worker# - Ensure removal of prefix does not remove user-added address with same prefix. 44*cfb92d14SAndroid Build Coastguard Worker# - Ensure disabling SLAAC module removes previously added SLAAC addresses, and re-enabling it adds them back. 45*cfb92d14SAndroid Build Coastguard Worker# - Check behavior when prefix is added while SLAAC module is disabled and then enabled later. 46*cfb92d14SAndroid Build Coastguard Worker 47*cfb92d14SAndroid Build Coastguard Workertest_name = __file__[:-3] if __file__.endswith('.py') else __file__ 48*cfb92d14SAndroid Build Coastguard Workerprint('-' * 120) 49*cfb92d14SAndroid Build Coastguard Workerprint('Starting \'{}\''.format(test_name)) 50*cfb92d14SAndroid Build Coastguard Worker 51*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 52*cfb92d14SAndroid Build Coastguard Worker# Utility functions 53*cfb92d14SAndroid Build Coastguard Worker 54*cfb92d14SAndroid Build Coastguard Worker 55*cfb92d14SAndroid Build Coastguard Workerdef verify_address(node_list, prefix): 56*cfb92d14SAndroid Build Coastguard Worker """ 57*cfb92d14SAndroid Build Coastguard Worker This function verifies that all nodes in the `node_list` contain an IPv6 address with the given `prefix`. 58*cfb92d14SAndroid Build Coastguard Worker """ 59*cfb92d14SAndroid Build Coastguard Worker for node in node_list: 60*cfb92d14SAndroid Build Coastguard Worker all_addrs = wpan.parse_list(node.get(wpan.WPAN_IP6_ALL_ADDRESSES)) 61*cfb92d14SAndroid Build Coastguard Worker verify(any([addr.startswith(prefix[:-1]) for addr in all_addrs])) 62*cfb92d14SAndroid Build Coastguard Worker 63*cfb92d14SAndroid Build Coastguard Worker 64*cfb92d14SAndroid Build Coastguard Workerdef verify_no_address(node_list, prefix): 65*cfb92d14SAndroid Build Coastguard Worker """ 66*cfb92d14SAndroid Build Coastguard Worker This function verifies that none of nodes in the `node_list` contain an IPv6 address with the given `prefix`. 67*cfb92d14SAndroid Build Coastguard Worker """ 68*cfb92d14SAndroid Build Coastguard Worker for node in node_list: 69*cfb92d14SAndroid Build Coastguard Worker all_addrs = wpan.parse_list(node.get(wpan.WPAN_IP6_ALL_ADDRESSES)) 70*cfb92d14SAndroid Build Coastguard Worker verify(all([not addr.startswith(prefix[:-1]) for addr in all_addrs])) 71*cfb92d14SAndroid Build Coastguard Worker 72*cfb92d14SAndroid Build Coastguard Worker 73*cfb92d14SAndroid Build Coastguard Workerdef verify_prefix( 74*cfb92d14SAndroid Build Coastguard Worker node_list, 75*cfb92d14SAndroid Build Coastguard Worker prefix, 76*cfb92d14SAndroid Build Coastguard Worker prefix_len=64, 77*cfb92d14SAndroid Build Coastguard Worker stable=True, 78*cfb92d14SAndroid Build Coastguard Worker priority='med', 79*cfb92d14SAndroid Build Coastguard Worker on_mesh=False, 80*cfb92d14SAndroid Build Coastguard Worker slaac=False, 81*cfb92d14SAndroid Build Coastguard Worker dhcp=False, 82*cfb92d14SAndroid Build Coastguard Worker configure=False, 83*cfb92d14SAndroid Build Coastguard Worker default_route=False, 84*cfb92d14SAndroid Build Coastguard Worker preferred=False, 85*cfb92d14SAndroid Build Coastguard Worker): 86*cfb92d14SAndroid Build Coastguard Worker """ 87*cfb92d14SAndroid Build Coastguard Worker This function verifies that the `prefix` is present on all nodes in the `node_list`. 88*cfb92d14SAndroid Build Coastguard Worker """ 89*cfb92d14SAndroid Build Coastguard Worker for node in node_list: 90*cfb92d14SAndroid Build Coastguard Worker prefixes = wpan.parse_on_mesh_prefix_result(node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES)) 91*cfb92d14SAndroid Build Coastguard Worker for p in prefixes: 92*cfb92d14SAndroid Build Coastguard Worker if p.prefix == prefix: 93*cfb92d14SAndroid Build Coastguard Worker if (int(p.prefix_len) == prefix_len and p.is_stable() == stable and p.is_on_mesh() == on_mesh and 94*cfb92d14SAndroid Build Coastguard Worker p.is_def_route() == default_route and p.is_slaac() == slaac and p.is_dhcp() == dhcp and 95*cfb92d14SAndroid Build Coastguard Worker p.is_config() == configure and p.is_preferred() == preferred and p.priority == priority): 96*cfb92d14SAndroid Build Coastguard Worker break 97*cfb92d14SAndroid Build Coastguard Worker else: 98*cfb92d14SAndroid Build Coastguard Worker raise wpan.VerifyError("Did not find prefix {} on node {}".format(prefix, node)) 99*cfb92d14SAndroid Build Coastguard Worker 100*cfb92d14SAndroid Build Coastguard Worker 101*cfb92d14SAndroid Build Coastguard Workerdef verify_no_prefix(node_list, prefix): 102*cfb92d14SAndroid Build Coastguard Worker """ 103*cfb92d14SAndroid Build Coastguard Worker This function verifies that the `prefix` is NOT present on any node in the `node_list`. 104*cfb92d14SAndroid Build Coastguard Worker """ 105*cfb92d14SAndroid Build Coastguard Worker for node in node_list: 106*cfb92d14SAndroid Build Coastguard Worker prefixes = wpan.parse_on_mesh_prefix_result(node.get(wpan.WPAN_THREAD_ON_MESH_PREFIXES)) 107*cfb92d14SAndroid Build Coastguard Worker for p in prefixes: 108*cfb92d14SAndroid Build Coastguard Worker verify(not p.prefix == prefix) 109*cfb92d14SAndroid Build Coastguard Worker 110*cfb92d14SAndroid Build Coastguard Worker 111*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 112*cfb92d14SAndroid Build Coastguard Worker# Creating `wpan.Nodes` instances 113*cfb92d14SAndroid Build Coastguard Worker 114*cfb92d14SAndroid Build Coastguard Workerspeedup = 4 115*cfb92d14SAndroid Build Coastguard Workerwpan.Node.set_time_speedup_factor(speedup) 116*cfb92d14SAndroid Build Coastguard Worker 117*cfb92d14SAndroid Build Coastguard Workerr1 = wpan.Node() 118*cfb92d14SAndroid Build Coastguard Workerr2 = wpan.Node() 119*cfb92d14SAndroid Build Coastguard Workerc2 = wpan.Node() 120*cfb92d14SAndroid Build Coastguard Worker 121*cfb92d14SAndroid Build Coastguard Workerall_nodes = [r1, r2, c2] 122*cfb92d14SAndroid Build Coastguard Worker 123*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 124*cfb92d14SAndroid Build Coastguard Worker# Init all nodes 125*cfb92d14SAndroid Build Coastguard Worker 126*cfb92d14SAndroid Build Coastguard Workerwpan.Node.init_all_nodes() 127*cfb92d14SAndroid Build Coastguard Worker 128*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 129*cfb92d14SAndroid Build Coastguard Worker# Build network topology 130*cfb92d14SAndroid Build Coastguard Worker 131*cfb92d14SAndroid Build Coastguard Workerr1.form('slaac-ncp') 132*cfb92d14SAndroid Build Coastguard Worker 133*cfb92d14SAndroid Build Coastguard Workerr1.allowlist_node(r2) 134*cfb92d14SAndroid Build Coastguard Workerr2.allowlist_node(r1) 135*cfb92d14SAndroid Build Coastguard Worker 136*cfb92d14SAndroid Build Coastguard Workerr2.join_node(r1, node_type=wpan.JOIN_TYPE_ROUTER) 137*cfb92d14SAndroid Build Coastguard Worker 138*cfb92d14SAndroid Build Coastguard Workerc2.allowlist_node(r2) 139*cfb92d14SAndroid Build Coastguard Workerr2.allowlist_node(c2) 140*cfb92d14SAndroid Build Coastguard Worker 141*cfb92d14SAndroid Build Coastguard Workerc2.join_node(r2, node_type=wpan.JOIN_TYPE_END_DEVICE) 142*cfb92d14SAndroid Build Coastguard Worker 143*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 144*cfb92d14SAndroid Build Coastguard Worker# Test implementation 145*cfb92d14SAndroid Build Coastguard Worker 146*cfb92d14SAndroid Build Coastguard Worker# This test covers the SLAAC address management by NCP. So before starting the test we ensure that SLAAC module 147*cfb92d14SAndroid Build Coastguard Worker# on NCP is enabled on all nodes, and disable it on wpantund. 148*cfb92d14SAndroid Build Coastguard Worker 149*cfb92d14SAndroid Build Coastguard Workerfor node in all_nodes: 150*cfb92d14SAndroid Build Coastguard Worker verify(node.get(wpan.WPAN_OT_SLAAC_ENABLED) == 'true') 151*cfb92d14SAndroid Build Coastguard Worker node.set("Daemon:IPv6:AutoAddSLAACAddress", 'false') 152*cfb92d14SAndroid Build Coastguard Worker verify(node.get("Daemon:IPv6:AutoAddSLAACAddress") == 'false') 153*cfb92d14SAndroid Build Coastguard Worker 154*cfb92d14SAndroid Build Coastguard WorkerWAIT_INTERVAL = 5 155*cfb92d14SAndroid Build Coastguard Worker 156*cfb92d14SAndroid Build Coastguard WorkerPREFIX = 'fd00:1234::' 157*cfb92d14SAndroid Build Coastguard Worker 158*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 159*cfb92d14SAndroid Build Coastguard Worker# Add prefix and check all nodes get the prefix and add a corresponding 160*cfb92d14SAndroid Build Coastguard Worker# SLAAC address. 161*cfb92d14SAndroid Build Coastguard Worker 162*cfb92d14SAndroid Build Coastguard Workerr1.add_prefix(PREFIX, stable=True, on_mesh=True, slaac=True) 163*cfb92d14SAndroid Build Coastguard Worker 164*cfb92d14SAndroid Build Coastguard Worker 165*cfb92d14SAndroid Build Coastguard Workerdef check_prefix_and_slaac_address_are_added(): 166*cfb92d14SAndroid Build Coastguard Worker verify_prefix(all_nodes, PREFIX, stable=True, on_mesh=True, slaac=True) 167*cfb92d14SAndroid Build Coastguard Worker verify_address(all_nodes, PREFIX) 168*cfb92d14SAndroid Build Coastguard Worker 169*cfb92d14SAndroid Build Coastguard Worker 170*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) 171*cfb92d14SAndroid Build Coastguard Worker 172*cfb92d14SAndroid Build Coastguard Worker# Save the assigned SLAAC addresses. 173*cfb92d14SAndroid Build Coastguard Workerslaac_addrs = [node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] 174*cfb92d14SAndroid Build Coastguard Worker 175*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 176*cfb92d14SAndroid Build Coastguard Worker# Check recovery after resetting r1 and c1 (same SLAAC address to be added) 177*cfb92d14SAndroid Build Coastguard Worker 178*cfb92d14SAndroid Build Coastguard Workerr1.reset() 179*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) 180*cfb92d14SAndroid Build Coastguard Workerverify([node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] == slaac_addrs) 181*cfb92d14SAndroid Build Coastguard Worker 182*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 183*cfb92d14SAndroid Build Coastguard Worker# Remove the prefix on r1 and verify that the address and prefix are 184*cfb92d14SAndroid Build Coastguard Worker# removed on all nodes. 185*cfb92d14SAndroid Build Coastguard Worker 186*cfb92d14SAndroid Build Coastguard Workerr1.remove_prefix(PREFIX) 187*cfb92d14SAndroid Build Coastguard Worker 188*cfb92d14SAndroid Build Coastguard Worker 189*cfb92d14SAndroid Build Coastguard Workerdef check_prefix_and_slaac_address_are_removed(): 190*cfb92d14SAndroid Build Coastguard Worker verify_no_prefix(all_nodes, PREFIX) 191*cfb92d14SAndroid Build Coastguard Worker verify_no_address(all_nodes, PREFIX) 192*cfb92d14SAndroid Build Coastguard Worker 193*cfb92d14SAndroid Build Coastguard Worker 194*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_prefix_and_slaac_address_are_removed, WAIT_INTERVAL) 195*cfb92d14SAndroid Build Coastguard Worker 196*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 197*cfb92d14SAndroid Build Coastguard Worker# Add the prefix on both r1 and r2, then remove from r1 and ensure SLAAC 198*cfb92d14SAndroid Build Coastguard Worker# addresses are assigned on all nodes. 199*cfb92d14SAndroid Build Coastguard Worker 200*cfb92d14SAndroid Build Coastguard Worker# Add prefix on r2 201*cfb92d14SAndroid Build Coastguard Workerr2.add_prefix(PREFIX, stable=True, on_mesh=True, slaac=True) 202*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) 203*cfb92d14SAndroid Build Coastguard Workerverify([node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] == slaac_addrs) 204*cfb92d14SAndroid Build Coastguard Worker 205*cfb92d14SAndroid Build Coastguard Worker# Add same prefix on r1 and verify prefix and addresses stay as before 206*cfb92d14SAndroid Build Coastguard Workerr1.add_prefix(PREFIX, stable=True, on_mesh=True, slaac=True) 207*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) 208*cfb92d14SAndroid Build Coastguard Workerverify([node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] == slaac_addrs) 209*cfb92d14SAndroid Build Coastguard Worker 210*cfb92d14SAndroid Build Coastguard Worker# Remove on r1, addresses and prefixes should stay as before (r2 still has 211*cfb92d14SAndroid Build Coastguard Worker# the same prefix) 212*cfb92d14SAndroid Build Coastguard Workerr1.remove_prefix(PREFIX) 213*cfb92d14SAndroid Build Coastguard Workertime.sleep(0.5) 214*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) 215*cfb92d14SAndroid Build Coastguard Workerverify([node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] == slaac_addrs) 216*cfb92d14SAndroid Build Coastguard Worker 217*cfb92d14SAndroid Build Coastguard Worker# Remove the prefix on r2 and verify that the address and prefix are now 218*cfb92d14SAndroid Build Coastguard Worker# removed on all nodes. 219*cfb92d14SAndroid Build Coastguard Workerr2.remove_prefix(PREFIX) 220*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_prefix_and_slaac_address_are_removed, WAIT_INTERVAL) 221*cfb92d14SAndroid Build Coastguard Worker 222*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 223*cfb92d14SAndroid Build Coastguard Worker# Add the prefix on r1 (without SLAAC flag) and r2 (with SLAAC flag) 224*cfb92d14SAndroid Build Coastguard Worker 225*cfb92d14SAndroid Build Coastguard Worker# Add prefix on r1 without SLAAC flag, and on r2 with SLAAC flag 226*cfb92d14SAndroid Build Coastguard Workerr1.add_prefix(PREFIX, stable=True, on_mesh=True, slaac=False) 227*cfb92d14SAndroid Build Coastguard Workerr2.add_prefix(PREFIX, stable=True, on_mesh=True, slaac=True) 228*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) 229*cfb92d14SAndroid Build Coastguard Workerverify([node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] == slaac_addrs) 230*cfb92d14SAndroid Build Coastguard Worker 231*cfb92d14SAndroid Build Coastguard Worker# Now remove the prefix on r2 and verify that SLAAC address is removed 232*cfb92d14SAndroid Build Coastguard Workerr2.remove_prefix(PREFIX) 233*cfb92d14SAndroid Build Coastguard Worker 234*cfb92d14SAndroid Build Coastguard Worker 235*cfb92d14SAndroid Build Coastguard Workerdef check_slaac_address_is_removed(): 236*cfb92d14SAndroid Build Coastguard Worker verify_no_address(all_nodes, PREFIX) 237*cfb92d14SAndroid Build Coastguard Worker 238*cfb92d14SAndroid Build Coastguard Worker 239*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_slaac_address_is_removed, WAIT_INTERVAL) 240*cfb92d14SAndroid Build Coastguard Worker 241*cfb92d14SAndroid Build Coastguard Workerr1.remove_prefix(PREFIX) 242*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_prefix_and_slaac_address_are_removed, WAIT_INTERVAL) 243*cfb92d14SAndroid Build Coastguard Worker 244*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 245*cfb92d14SAndroid Build Coastguard Worker# Check behavior when a user-added address with same prefix already exists. 246*cfb92d14SAndroid Build Coastguard Worker 247*cfb92d14SAndroid Build Coastguard WorkerIP_ADDRESS = PREFIX + "1234" 248*cfb92d14SAndroid Build Coastguard Worker 249*cfb92d14SAndroid Build Coastguard Worker# Explicitly add an address with the prefix on r1 250*cfb92d14SAndroid Build Coastguard Workerr1.add_ip6_address_on_interface(IP_ADDRESS) 251*cfb92d14SAndroid Build Coastguard Worker 252*cfb92d14SAndroid Build Coastguard Worker# Afterwards, add the prefix on r2 (with SLAAC flag) 253*cfb92d14SAndroid Build Coastguard Workerr2.add_prefix(PREFIX, stable=True, on_mesh=True, slaac=True) 254*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) 255*cfb92d14SAndroid Build Coastguard Worker 256*cfb92d14SAndroid Build Coastguard Worker# Verify that on r1 we do see the user-added address 257*cfb92d14SAndroid Build Coastguard Workerr1_addrs = wpan.parse_list(r1.get(wpan.WPAN_IP6_ALL_ADDRESSES)) 258*cfb92d14SAndroid Build Coastguard Workerverify(IP_ADDRESS in r1_addrs) 259*cfb92d14SAndroid Build Coastguard Worker 260*cfb92d14SAndroid Build Coastguard Worker# Also verify that adding the prefix did not add a SLAAC address for same 261*cfb92d14SAndroid Build Coastguard Worker# prefix on r1 262*cfb92d14SAndroid Build Coastguard Workerr1_addrs.remove(IP_ADDRESS) 263*cfb92d14SAndroid Build Coastguard Workerverify(all([not addr.startswith(PREFIX[:-1]) for addr in r1_addrs])) 264*cfb92d14SAndroid Build Coastguard Worker 265*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 266*cfb92d14SAndroid Build Coastguard Worker# Check behavior when a user-added address with same prefix is removed 267*cfb92d14SAndroid Build Coastguard Worker# (SLAAC module should add a SLAAC address). 268*cfb92d14SAndroid Build Coastguard Worker 269*cfb92d14SAndroid Build Coastguard Workerr1.remove_ip6_address_on_interface(IP_ADDRESS) 270*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) 271*cfb92d14SAndroid Build Coastguard Workerverify([node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] == slaac_addrs) 272*cfb92d14SAndroid Build Coastguard Worker 273*cfb92d14SAndroid Build Coastguard Worker# Re-add the address 274*cfb92d14SAndroid Build Coastguard Workerr1.add_ip6_address_on_interface(IP_ADDRESS) 275*cfb92d14SAndroid Build Coastguard Worker 276*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 277*cfb92d14SAndroid Build Coastguard Worker# Ensure removal of prefix does not remove user-added address with same prefix. 278*cfb92d14SAndroid Build Coastguard Worker 279*cfb92d14SAndroid Build Coastguard Workerr2.remove_prefix(PREFIX) 280*cfb92d14SAndroid Build Coastguard Worker 281*cfb92d14SAndroid Build Coastguard Worker 282*cfb92d14SAndroid Build Coastguard Workerdef check_ip6_addresses(): 283*cfb92d14SAndroid Build Coastguard Worker # Verify that SLAAC addresses are removed on r2 and c2 284*cfb92d14SAndroid Build Coastguard Worker verify_no_address([r2, c2], PREFIX) 285*cfb92d14SAndroid Build Coastguard Worker # And that user-added address matching the prefix is not removed on r1 286*cfb92d14SAndroid Build Coastguard Worker r1_addrs = wpan.parse_list(r1.get(wpan.WPAN_IP6_ALL_ADDRESSES)) 287*cfb92d14SAndroid Build Coastguard Worker verify(IP_ADDRESS in r1_addrs) 288*cfb92d14SAndroid Build Coastguard Worker 289*cfb92d14SAndroid Build Coastguard Worker 290*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_ip6_addresses, WAIT_INTERVAL) 291*cfb92d14SAndroid Build Coastguard Worker 292*cfb92d14SAndroid Build Coastguard Workerr1.remove_ip6_address_on_interface(IP_ADDRESS) 293*cfb92d14SAndroid Build Coastguard Worker 294*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 295*cfb92d14SAndroid Build Coastguard Worker# Ensure disabling SLAAC module removes previously added SLAAC addresses, 296*cfb92d14SAndroid Build Coastguard Worker# and re-enabling it adds them back. 297*cfb92d14SAndroid Build Coastguard Worker 298*cfb92d14SAndroid Build Coastguard Workerr1.add_prefix(PREFIX, stable=True, on_mesh=True, slaac=True) 299*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) 300*cfb92d14SAndroid Build Coastguard Workerverify([node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] == slaac_addrs) 301*cfb92d14SAndroid Build Coastguard Worker 302*cfb92d14SAndroid Build Coastguard Workerfor node in all_nodes: 303*cfb92d14SAndroid Build Coastguard Worker node.set(wpan.WPAN_OT_SLAAC_ENABLED, 'false') 304*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_slaac_address_is_removed, WAIT_INTERVAL) 305*cfb92d14SAndroid Build Coastguard Worker 306*cfb92d14SAndroid Build Coastguard Worker# Re-enable SLAAC support on NCP and verify addresses are re-added back. 307*cfb92d14SAndroid Build Coastguard Workerfor node in all_nodes: 308*cfb92d14SAndroid Build Coastguard Worker node.set(wpan.WPAN_OT_SLAAC_ENABLED, 'true') 309*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) 310*cfb92d14SAndroid Build Coastguard Workerverify([node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] == slaac_addrs) 311*cfb92d14SAndroid Build Coastguard Worker 312*cfb92d14SAndroid Build Coastguard Workerr1.remove_prefix(PREFIX) 313*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_prefix_and_slaac_address_are_removed, WAIT_INTERVAL) 314*cfb92d14SAndroid Build Coastguard Worker 315*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 316*cfb92d14SAndroid Build Coastguard Worker# Check behavior when prefix is added while SLAAC is disabled and then 317*cfb92d14SAndroid Build Coastguard Worker# enabled later. 318*cfb92d14SAndroid Build Coastguard Worker 319*cfb92d14SAndroid Build Coastguard Workerfor node in all_nodes: 320*cfb92d14SAndroid Build Coastguard Worker node.set(wpan.WPAN_OT_SLAAC_ENABLED, 'false') 321*cfb92d14SAndroid Build Coastguard Worker 322*cfb92d14SAndroid Build Coastguard Worker# Add prefix and verify that there is no address added 323*cfb92d14SAndroid Build Coastguard Workerr1.add_prefix(PREFIX, stable=True, on_mesh=True, slaac=True) 324*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_slaac_address_is_removed, WAIT_INTERVAL) 325*cfb92d14SAndroid Build Coastguard Worker 326*cfb92d14SAndroid Build Coastguard Workerfor node in all_nodes: 327*cfb92d14SAndroid Build Coastguard Worker node.set(wpan.WPAN_OT_SLAAC_ENABLED, 'true') 328*cfb92d14SAndroid Build Coastguard Workerwpan.verify_within(check_prefix_and_slaac_address_are_added, WAIT_INTERVAL) 329*cfb92d14SAndroid Build Coastguard Workerverify([node.find_ip6_address_with_prefix(PREFIX) for node in all_nodes] == slaac_addrs) 330*cfb92d14SAndroid Build Coastguard Worker 331*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 332*cfb92d14SAndroid Build Coastguard Worker# Test finished 333*cfb92d14SAndroid Build Coastguard Worker 334*cfb92d14SAndroid Build Coastguard Workerwpan.Node.finalize_all_nodes() 335*cfb92d14SAndroid Build Coastguard Worker 336*cfb92d14SAndroid Build Coastguard Workerprint('\'{}\' passed.'.format(test_name)) 337