1*cfb92d14SAndroid Build Coastguard Worker#!/usr/bin/env python3 2*cfb92d14SAndroid Build Coastguard Worker# 3*cfb92d14SAndroid Build Coastguard Worker# Copyright (c) 2024, 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: 36*cfb92d14SAndroid Build Coastguard Worker# 37*cfb92d14SAndroid Build Coastguard Worker# BR sending ICMPv6 Unreachable error. 38*cfb92d14SAndroid Build Coastguard Worker# 39*cfb92d14SAndroid Build Coastguard Worker# - - - AIL- - - 40*cfb92d14SAndroid Build Coastguard Worker# | | 41*cfb92d14SAndroid Build Coastguard Worker# BR1 BR2 42*cfb92d14SAndroid Build Coastguard Worker# | 43*cfb92d14SAndroid Build Coastguard Worker# router2 44*cfb92d14SAndroid Build Coastguard Worker# 45*cfb92d14SAndroid Build Coastguard Worker 46*cfb92d14SAndroid Build Coastguard Workertest_name = __file__[:-3] if __file__.endswith('.py') else __file__ 47*cfb92d14SAndroid Build Coastguard Workerprint('-' * 120) 48*cfb92d14SAndroid Build Coastguard Workerprint('Starting \'{}\''.format(test_name)) 49*cfb92d14SAndroid Build Coastguard Worker 50*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 51*cfb92d14SAndroid Build Coastguard Worker# Creating `cli.Nodes` instances 52*cfb92d14SAndroid Build Coastguard Worker 53*cfb92d14SAndroid Build Coastguard Workerspeedup = 20 54*cfb92d14SAndroid Build Coastguard Workercli.Node.set_time_speedup_factor(speedup) 55*cfb92d14SAndroid Build Coastguard Worker 56*cfb92d14SAndroid Build Coastguard Workerbr1 = cli.Node() 57*cfb92d14SAndroid Build Coastguard Workerbr2 = cli.Node() 58*cfb92d14SAndroid Build Coastguard Workerrouter2 = cli.Node() 59*cfb92d14SAndroid Build Coastguard Worker 60*cfb92d14SAndroid Build Coastguard WorkerIF_INDEX = 1 61*cfb92d14SAndroid Build Coastguard Worker 62*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 63*cfb92d14SAndroid Build Coastguard Worker# Test implementation 64*cfb92d14SAndroid Build Coastguard Worker 65*cfb92d14SAndroid Build Coastguard Worker# Start `br1` on its own Thread network with a custom OMR 66*cfb92d14SAndroid Build Coastguard Worker# prefix and a custom on-link prefix. Both prefixes are 67*cfb92d14SAndroid Build Coastguard Worker# non-ULA. 68*cfb92d14SAndroid Build Coastguard Worker 69*cfb92d14SAndroid Build Coastguard Workerbr1.form('net1') 70*cfb92d14SAndroid Build Coastguard Workerverify(br1.get_state() == 'leader') 71*cfb92d14SAndroid Build Coastguard Worker 72*cfb92d14SAndroid Build Coastguard Workerbr1.add_prefix('1000::/64', 'paors') 73*cfb92d14SAndroid Build Coastguard Workerbr1.register_netdata() 74*cfb92d14SAndroid Build Coastguard Worker 75*cfb92d14SAndroid Build Coastguard Workerbr1.br_init(IF_INDEX, 1) 76*cfb92d14SAndroid Build Coastguard Workerbr1.br_enable() 77*cfb92d14SAndroid Build Coastguard Worker 78*cfb92d14SAndroid Build Coastguard Workerbr1.br_set_test_local_onlinkprefix('2000::/64') 79*cfb92d14SAndroid Build Coastguard Worker 80*cfb92d14SAndroid Build Coastguard Workertime.sleep(2) 81*cfb92d14SAndroid Build Coastguard Workerverify(br1.br_get_state() == 'running') 82*cfb92d14SAndroid Build Coastguard Worker 83*cfb92d14SAndroid Build Coastguard Workerbr1_local_onlink = br1.br_get_local_onlinkprefix() 84*cfb92d14SAndroid Build Coastguard Workerbr1_favored_onlink = br1.br_get_favored_onlinkprefix().split()[0] 85*cfb92d14SAndroid Build Coastguard Workerverify(br1_local_onlink == br1_favored_onlink) 86*cfb92d14SAndroid Build Coastguard Workerverify(br1_local_onlink == '2000:0:0:0::/64') 87*cfb92d14SAndroid Build Coastguard Worker 88*cfb92d14SAndroid Build Coastguard Workerbr1_local_omr = br1.br_get_local_omrprefix() 89*cfb92d14SAndroid Build Coastguard Workerbr1_favored_omr = br1.br_get_favored_omrprefix().split()[0] 90*cfb92d14SAndroid Build Coastguard Workerverify(br1_favored_omr == '1000:0:0:0::/64') 91*cfb92d14SAndroid Build Coastguard Worker 92*cfb92d14SAndroid Build Coastguard Worker#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 93*cfb92d14SAndroid Build Coastguard Worker# Start `br2` on its own Thread network. 94*cfb92d14SAndroid Build Coastguard Worker 95*cfb92d14SAndroid Build Coastguard Workerbr2.form('net2') 96*cfb92d14SAndroid Build Coastguard Workerrouter2.join(br2) 97*cfb92d14SAndroid Build Coastguard Workerverify(br2.get_state() == 'leader') 98*cfb92d14SAndroid Build Coastguard Workerverify(router2.get_state() == 'router') 99*cfb92d14SAndroid Build Coastguard Worker 100*cfb92d14SAndroid Build Coastguard Workerbr2.br_init(IF_INDEX, 1) 101*cfb92d14SAndroid Build Coastguard Workerbr2.br_enable() 102*cfb92d14SAndroid Build Coastguard Worker 103*cfb92d14SAndroid Build Coastguard Workertime.sleep(2) 104*cfb92d14SAndroid Build Coastguard Workerverify(br2.br_get_state() == 'running') 105*cfb92d14SAndroid Build Coastguard Worker 106*cfb92d14SAndroid Build Coastguard Workerbr2_local_omr = br2.br_get_local_omrprefix() 107*cfb92d14SAndroid Build Coastguard Workerbr2_favored_omr = br2.br_get_favored_omrprefix().split()[0] 108*cfb92d14SAndroid Build Coastguard Workerverify(br2_local_omr == br2_favored_omr) 109*cfb92d14SAndroid Build Coastguard Worker 110*cfb92d14SAndroid Build Coastguard Workerbr2_local_onlink = br2.br_get_local_onlinkprefix() 111*cfb92d14SAndroid Build Coastguard Workerbr2_favored_onlink = br2.br_get_favored_onlinkprefix().split()[0] 112*cfb92d14SAndroid Build Coastguard Workerverify(br2_local_onlink != br2_favored_onlink) 113*cfb92d14SAndroid Build Coastguard Workerverify(br2_favored_onlink == '2000:0:0:0::/64') 114*cfb92d14SAndroid Build Coastguard Worker 115*cfb92d14SAndroid Build Coastguard Worker#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 116*cfb92d14SAndroid Build Coastguard Worker# Validate that the `br2` published '::/0' route due to 117*cfb92d14SAndroid Build Coastguard Worker# discovery of a non-ULA on-link prefix. 118*cfb92d14SAndroid Build Coastguard Worker 119*cfb92d14SAndroid Build Coastguard Workerfor node in [br2, router2]: 120*cfb92d14SAndroid Build Coastguard Worker routes = node.get_netdata_routes() 121*cfb92d14SAndroid Build Coastguard Worker verify(len(routes) == 1) 122*cfb92d14SAndroid Build Coastguard Worker verify(routes[0].startswith('::/0 s')) 123*cfb92d14SAndroid Build Coastguard Worker 124*cfb92d14SAndroid Build Coastguard Worker#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 125*cfb92d14SAndroid Build Coastguard Worker# Send a ping from `router2` to an AIL address (derived from the 126*cfb92d14SAndroid Build Coastguard Worker# advertised on-link prefix). Verify that, BR2 receives and 127*cfb92d14SAndroid Build Coastguard Worker# forwards the message, and BR2 does not send an ICMPv6 error, as 128*cfb92d14SAndroid Build Coastguard Worker# the destination is within the AIL. 129*cfb92d14SAndroid Build Coastguard Worker 130*cfb92d14SAndroid Build Coastguard Workerrouter2.ping('2000::1', verify_success=False) 131*cfb92d14SAndroid Build Coastguard Worker 132*cfb92d14SAndroid Build Coastguard Workerverify(br2.get_br_counter_unicast_outbound_packets() == 1) 133*cfb92d14SAndroid Build Coastguard Worker 134*cfb92d14SAndroid Build Coastguard Workerrx_history = router2.cli('history rx list') 135*cfb92d14SAndroid Build Coastguard Workerverify(len(rx_history) == 0) 136*cfb92d14SAndroid Build Coastguard Worker 137*cfb92d14SAndroid Build Coastguard Worker#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 138*cfb92d14SAndroid Build Coastguard Worker# Send a ping from `router2` to an address on BR1 mesh network 139*cfb92d14SAndroid Build Coastguard Worker# (derived from its OMR prefix). Verify that again it is 140*cfb92d14SAndroid Build Coastguard Worker# received and forwarded by BR2 and again no ICMPv6 error is 141*cfb92d14SAndroid Build Coastguard Worker# sent. 142*cfb92d14SAndroid Build Coastguard Worker 143*cfb92d14SAndroid Build Coastguard Workerrouter2.ping('1000::1', verify_success=False) 144*cfb92d14SAndroid Build Coastguard Worker 145*cfb92d14SAndroid Build Coastguard Workerverify(br2.get_br_counter_unicast_outbound_packets() == 2) 146*cfb92d14SAndroid Build Coastguard Worker 147*cfb92d14SAndroid Build Coastguard Workerrx_history = router2.cli('history rx list') 148*cfb92d14SAndroid Build Coastguard Workerverify(len(rx_history) == 0) 149*cfb92d14SAndroid Build Coastguard Worker 150*cfb92d14SAndroid Build Coastguard Worker#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 151*cfb92d14SAndroid Build Coastguard Worker# Send a ping to an outside AIL address, make sure BR2 152*cfb92d14SAndroid Build Coastguard Worker# does receive and forward it and now also sends an ICMPv6 153*cfb92d14SAndroid Build Coastguard Worker# error 154*cfb92d14SAndroid Build Coastguard Worker 155*cfb92d14SAndroid Build Coastguard Workerrouter2.ping('3000::', verify_success=False) 156*cfb92d14SAndroid Build Coastguard Worker 157*cfb92d14SAndroid Build Coastguard Workerverify(br2.get_br_counter_unicast_outbound_packets() == 3) 158*cfb92d14SAndroid Build Coastguard Worker 159*cfb92d14SAndroid Build Coastguard Workerrx_history = router2.cli('history rx list') 160*cfb92d14SAndroid Build Coastguard Workerverify(rx_history[1].strip().startswith('type:ICMP6(Unreach)')) 161*cfb92d14SAndroid Build Coastguard Worker 162*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 163*cfb92d14SAndroid Build Coastguard Worker# Test finished 164*cfb92d14SAndroid Build Coastguard Worker 165*cfb92d14SAndroid Build Coastguard Workercli.Node.finalize_all_nodes() 166*cfb92d14SAndroid Build Coastguard Worker 167*cfb92d14SAndroid Build Coastguard Workerprint('\'{}\' passed.'.format(test_name)) 168