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: BR published route preference. 36*cfb92d14SAndroid Build Coastguard Worker# 37*cfb92d14SAndroid Build Coastguard Worker# 38*cfb92d14SAndroid Build Coastguard Worker 39*cfb92d14SAndroid Build Coastguard Workertest_name = __file__[:-3] if __file__.endswith('.py') else __file__ 40*cfb92d14SAndroid Build Coastguard Workerprint('-' * 120) 41*cfb92d14SAndroid Build Coastguard Workerprint('Starting \'{}\''.format(test_name)) 42*cfb92d14SAndroid Build Coastguard Worker 43*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 44*cfb92d14SAndroid Build Coastguard Worker# Creating `cli.Node` instances 45*cfb92d14SAndroid Build Coastguard Worker 46*cfb92d14SAndroid Build Coastguard Workerspeedup = 40 47*cfb92d14SAndroid Build Coastguard Workercli.Node.set_time_speedup_factor(speedup) 48*cfb92d14SAndroid Build Coastguard Worker 49*cfb92d14SAndroid Build Coastguard Workerleader = cli.Node() 50*cfb92d14SAndroid Build Coastguard Workerbr = cli.Node() 51*cfb92d14SAndroid Build Coastguard Worker 52*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 53*cfb92d14SAndroid Build Coastguard Worker# Form topology 54*cfb92d14SAndroid Build Coastguard Worker 55*cfb92d14SAndroid Build Coastguard Workerleader.set_macfilter_lqi_to_node(br, 2) 56*cfb92d14SAndroid Build Coastguard Workerbr.set_macfilter_lqi_to_node(leader, 2) 57*cfb92d14SAndroid Build Coastguard Worker 58*cfb92d14SAndroid Build Coastguard Workerleader.form('br-route-prf') 59*cfb92d14SAndroid Build Coastguard Workerbr.join(leader) 60*cfb92d14SAndroid Build Coastguard Worker 61*cfb92d14SAndroid Build Coastguard Workerverify(leader.get_state() == 'leader') 62*cfb92d14SAndroid Build Coastguard Workerverify(br.get_state() == 'router') 63*cfb92d14SAndroid Build Coastguard Worker 64*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 65*cfb92d14SAndroid Build Coastguard Worker# Test Implementation 66*cfb92d14SAndroid Build Coastguard Worker 67*cfb92d14SAndroid Build Coastguard Workerverify(br.br_get_state() == 'uninitialized') 68*cfb92d14SAndroid Build Coastguard Worker 69*cfb92d14SAndroid Build Coastguard Workerbr.br_init(1, 1) 70*cfb92d14SAndroid Build Coastguard Worker 71*cfb92d14SAndroid Build Coastguard Workerverify(br.br_get_state() == 'disabled') 72*cfb92d14SAndroid Build Coastguard Worker 73*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 74*cfb92d14SAndroid Build Coastguard Worker# Check the default route preference while BR is disabled 75*cfb92d14SAndroid Build Coastguard Worker 76*cfb92d14SAndroid Build Coastguard Workerverify(br.br_get_routeprf() == 'med') 77*cfb92d14SAndroid Build Coastguard Worker 78*cfb92d14SAndroid Build Coastguard Workerbr.br_set_routeprf('low') 79*cfb92d14SAndroid Build Coastguard Workerverify(br.br_get_routeprf() == 'low') 80*cfb92d14SAndroid Build Coastguard Worker 81*cfb92d14SAndroid Build Coastguard Workerbr.br_set_routeprf('med') 82*cfb92d14SAndroid Build Coastguard Workerverify(br.br_get_routeprf() == 'med') 83*cfb92d14SAndroid Build Coastguard Worker 84*cfb92d14SAndroid Build Coastguard Workerbr.br_set_routeprf('high') 85*cfb92d14SAndroid Build Coastguard Workerverify(br.br_get_routeprf() == 'high') 86*cfb92d14SAndroid Build Coastguard Worker 87*cfb92d14SAndroid Build Coastguard Workerbr.br_clear_routeprf() 88*cfb92d14SAndroid Build Coastguard Workerverify(br.br_get_routeprf() == 'med') 89*cfb92d14SAndroid Build Coastguard Worker 90*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 91*cfb92d14SAndroid Build Coastguard Worker# Enable BR and check the published route and its preference 92*cfb92d14SAndroid Build Coastguard Worker 93*cfb92d14SAndroid Build Coastguard Workerbr.br_enable() 94*cfb92d14SAndroid Build Coastguard Worker 95*cfb92d14SAndroid Build Coastguard Worker 96*cfb92d14SAndroid Build Coastguard Workerdef check_published_route_1(): 97*cfb92d14SAndroid Build Coastguard Worker verify(br.br_get_state() == 'running') 98*cfb92d14SAndroid Build Coastguard Worker routes = br.get_netdata_routes() 99*cfb92d14SAndroid Build Coastguard Worker verify(len(routes) == 1) 100*cfb92d14SAndroid Build Coastguard Worker verify(routes[0].startswith('fc00::/7 sa med')) 101*cfb92d14SAndroid Build Coastguard Worker verify(br.br_get_routeprf() == 'med') 102*cfb92d14SAndroid Build Coastguard Worker 103*cfb92d14SAndroid Build Coastguard Worker 104*cfb92d14SAndroid Build Coastguard Workerverify_within(check_published_route_1, 5) 105*cfb92d14SAndroid Build Coastguard Worker 106*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 107*cfb92d14SAndroid Build Coastguard Worker# Force `br` to become an end-device. Check that the published 108*cfb92d14SAndroid Build Coastguard Worker# route is now using `low` (since link quality to parent is 109*cfb92d14SAndroid Build Coastguard Worker# configured as 2) 110*cfb92d14SAndroid Build Coastguard Worker 111*cfb92d14SAndroid Build Coastguard Workerbr.set_router_eligible('disable') 112*cfb92d14SAndroid Build Coastguard Worker 113*cfb92d14SAndroid Build Coastguard Workerparent_info = br.get_parent_info() 114*cfb92d14SAndroid Build Coastguard Workerverify(parent_info['Link Quality In'] == '2') 115*cfb92d14SAndroid Build Coastguard Worker 116*cfb92d14SAndroid Build Coastguard Worker 117*cfb92d14SAndroid Build Coastguard Workerdef check_published_route_2(): 118*cfb92d14SAndroid Build Coastguard Worker verify(br.get_state() == 'child') 119*cfb92d14SAndroid Build Coastguard Worker routes = br.get_netdata_routes() 120*cfb92d14SAndroid Build Coastguard Worker verify(len(routes) == 1) 121*cfb92d14SAndroid Build Coastguard Worker verify(routes[0].startswith('fc00::/7 sa low')) 122*cfb92d14SAndroid Build Coastguard Worker verify(br.br_get_routeprf() == 'low') 123*cfb92d14SAndroid Build Coastguard Worker 124*cfb92d14SAndroid Build Coastguard Worker 125*cfb92d14SAndroid Build Coastguard Workerverify_within(check_published_route_2, 5) 126*cfb92d14SAndroid Build Coastguard Worker 127*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 128*cfb92d14SAndroid Build Coastguard Worker# Manually set the route prf to 'high` and validated that network 129*cfb92d14SAndroid Build Coastguard Worker# data gets updated. Repeat setting route prf to `med`. 130*cfb92d14SAndroid Build Coastguard Worker 131*cfb92d14SAndroid Build Coastguard Workerbr.br_set_routeprf('high') 132*cfb92d14SAndroid Build Coastguard Worker 133*cfb92d14SAndroid Build Coastguard Worker 134*cfb92d14SAndroid Build Coastguard Workerdef check_published_route_3(): 135*cfb92d14SAndroid Build Coastguard Worker verify(br.get_state() == 'child') 136*cfb92d14SAndroid Build Coastguard Worker routes = br.get_netdata_routes() 137*cfb92d14SAndroid Build Coastguard Worker verify(len(routes) == 1) 138*cfb92d14SAndroid Build Coastguard Worker verify(routes[0].startswith('fc00::/7 sa high')) 139*cfb92d14SAndroid Build Coastguard Worker verify(br.br_get_routeprf() == 'high') 140*cfb92d14SAndroid Build Coastguard Worker 141*cfb92d14SAndroid Build Coastguard Worker 142*cfb92d14SAndroid Build Coastguard Workerverify_within(check_published_route_3, 5) 143*cfb92d14SAndroid Build Coastguard Worker 144*cfb92d14SAndroid Build Coastguard Workerbr.br_set_routeprf('med') 145*cfb92d14SAndroid Build Coastguard Worker 146*cfb92d14SAndroid Build Coastguard Worker 147*cfb92d14SAndroid Build Coastguard Workerdef check_published_route_4(): 148*cfb92d14SAndroid Build Coastguard Worker verify(br.get_state() == 'child') 149*cfb92d14SAndroid Build Coastguard Worker routes = br.get_netdata_routes() 150*cfb92d14SAndroid Build Coastguard Worker verify(len(routes) == 1) 151*cfb92d14SAndroid Build Coastguard Worker verify(routes[0].startswith('fc00::/7 sa med')) 152*cfb92d14SAndroid Build Coastguard Worker verify(br.br_get_routeprf() == 'med') 153*cfb92d14SAndroid Build Coastguard Worker 154*cfb92d14SAndroid Build Coastguard Worker 155*cfb92d14SAndroid Build Coastguard Workerverify_within(check_published_route_4, 5) 156*cfb92d14SAndroid Build Coastguard Worker 157*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 158*cfb92d14SAndroid Build Coastguard Worker# Clear the manually set route prf and validate that we go back 159*cfb92d14SAndroid Build Coastguard Worker# to `low`. 160*cfb92d14SAndroid Build Coastguard Worker 161*cfb92d14SAndroid Build Coastguard Workerbr.br_clear_routeprf() 162*cfb92d14SAndroid Build Coastguard Workerverify(br.br_get_routeprf() == 'low') 163*cfb92d14SAndroid Build Coastguard Worker 164*cfb92d14SAndroid Build Coastguard Worker 165*cfb92d14SAndroid Build Coastguard Workerdef check_published_route_5(): 166*cfb92d14SAndroid Build Coastguard Worker verify(br.get_state() == 'child') 167*cfb92d14SAndroid Build Coastguard Worker routes = br.get_netdata_routes() 168*cfb92d14SAndroid Build Coastguard Worker verify(len(routes) == 1) 169*cfb92d14SAndroid Build Coastguard Worker verify(routes[0].startswith('fc00::/7 sa low')) 170*cfb92d14SAndroid Build Coastguard Worker verify(br.br_get_routeprf() == 'low') 171*cfb92d14SAndroid Build Coastguard Worker 172*cfb92d14SAndroid Build Coastguard Worker 173*cfb92d14SAndroid Build Coastguard Workerverify_within(check_published_route_5, 5) 174*cfb92d14SAndroid Build Coastguard Worker 175*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 176*cfb92d14SAndroid Build Coastguard Worker# Allow `br` to take `router` role, validate that the route 177*cfb92d14SAndroid Build Coastguard Worker# prf of `med` is used. 178*cfb92d14SAndroid Build Coastguard Worker 179*cfb92d14SAndroid Build Coastguard Workerbr.set_router_eligible('enable') 180*cfb92d14SAndroid Build Coastguard Worker 181*cfb92d14SAndroid Build Coastguard Worker 182*cfb92d14SAndroid Build Coastguard Workerdef check_published_route_6(): 183*cfb92d14SAndroid Build Coastguard Worker verify(br.get_state() == 'router') 184*cfb92d14SAndroid Build Coastguard Worker routes = br.get_netdata_routes() 185*cfb92d14SAndroid Build Coastguard Worker verify(len(routes) == 1) 186*cfb92d14SAndroid Build Coastguard Worker verify(routes[0].startswith('fc00::/7 sa med')) 187*cfb92d14SAndroid Build Coastguard Worker verify(br.br_get_routeprf() == 'med') 188*cfb92d14SAndroid Build Coastguard Worker 189*cfb92d14SAndroid Build Coastguard Worker 190*cfb92d14SAndroid Build Coastguard Workerverify_within(check_published_route_6, 15) 191*cfb92d14SAndroid Build Coastguard Worker 192*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 193*cfb92d14SAndroid Build Coastguard Worker# Update RSS MAC filter to use link quality 3 between `br` and 194*cfb92d14SAndroid Build Coastguard Worker# `leader`. Again force `br` to become `child` and validate 195*cfb92d14SAndroid Build Coastguard Worker# that now it still continues to use `med` prf. 196*cfb92d14SAndroid Build Coastguard Worker 197*cfb92d14SAndroid Build Coastguard Workerleader.set_macfilter_lqi_to_node(br, 3) 198*cfb92d14SAndroid Build Coastguard Workerbr.set_macfilter_lqi_to_node(leader, 3) 199*cfb92d14SAndroid Build Coastguard Worker 200*cfb92d14SAndroid Build Coastguard Workerbr.set_router_eligible('disable') 201*cfb92d14SAndroid Build Coastguard Worker 202*cfb92d14SAndroid Build Coastguard Worker 203*cfb92d14SAndroid Build Coastguard Workerdef check_published_route_7(): 204*cfb92d14SAndroid Build Coastguard Worker verify(br.get_state() == 'child') 205*cfb92d14SAndroid Build Coastguard Worker routes = br.get_netdata_routes() 206*cfb92d14SAndroid Build Coastguard Worker verify(len(routes) == 1) 207*cfb92d14SAndroid Build Coastguard Worker verify(routes[0].startswith('fc00::/7 sa med')) 208*cfb92d14SAndroid Build Coastguard Worker verify(br.br_get_routeprf() == 'med') 209*cfb92d14SAndroid Build Coastguard Worker 210*cfb92d14SAndroid Build Coastguard Worker 211*cfb92d14SAndroid Build Coastguard Workerverify_within(check_published_route_7, 5) 212*cfb92d14SAndroid Build Coastguard Worker 213*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 214*cfb92d14SAndroid Build Coastguard Worker# Update RSS MAC filter to use link quality 1 between `br` and 215*cfb92d14SAndroid Build Coastguard Worker# `leader`. Validate that route prf is updated quickly to `low`. 216*cfb92d14SAndroid Build Coastguard Worker 217*cfb92d14SAndroid Build Coastguard Workerbr.set_macfilter_lqi_to_node(leader, 1) 218*cfb92d14SAndroid Build Coastguard Workerbr.ping(leader.get_mleid_ip_addr()) 219*cfb92d14SAndroid Build Coastguard Workerparent_info = br.get_parent_info() 220*cfb92d14SAndroid Build Coastguard Workerverify(parent_info['Link Quality In'] == '1') 221*cfb92d14SAndroid Build Coastguard Worker 222*cfb92d14SAndroid Build Coastguard Worker 223*cfb92d14SAndroid Build Coastguard Workerdef check_published_route_8(): 224*cfb92d14SAndroid Build Coastguard Worker verify(br.get_state() == 'child') 225*cfb92d14SAndroid Build Coastguard Worker routes = br.get_netdata_routes() 226*cfb92d14SAndroid Build Coastguard Worker verify(len(routes) == 1) 227*cfb92d14SAndroid Build Coastguard Worker verify(routes[0].startswith('fc00::/7 sa low')) 228*cfb92d14SAndroid Build Coastguard Worker verify(br.br_get_routeprf() == 'low') 229*cfb92d14SAndroid Build Coastguard Worker 230*cfb92d14SAndroid Build Coastguard Worker 231*cfb92d14SAndroid Build Coastguard Workerverify_within(check_published_route_8, 15) 232*cfb92d14SAndroid Build Coastguard Worker 233*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 234*cfb92d14SAndroid Build Coastguard Worker# Update RSS MAC filter to go back to link quality 3. 235*cfb92d14SAndroid Build Coastguard Worker# Make sure the published route prf is not immediately 236*cfb92d14SAndroid Build Coastguard Worker# updated and only updated after ~5 minutes. 237*cfb92d14SAndroid Build Coastguard Worker 238*cfb92d14SAndroid Build Coastguard Workerbr.set_macfilter_lqi_to_node(leader, 3) 239*cfb92d14SAndroid Build Coastguard Workerbr.ping(leader.get_mleid_ip_addr()) 240*cfb92d14SAndroid Build Coastguard Workerparent_info = br.get_parent_info() 241*cfb92d14SAndroid Build Coastguard Workerverify(parent_info['Link Quality In'] == '3') 242*cfb92d14SAndroid Build Coastguard Worker 243*cfb92d14SAndroid Build Coastguard Workerverify(br.br_get_routeprf() == 'low') 244*cfb92d14SAndroid Build Coastguard Worker 245*cfb92d14SAndroid Build Coastguard Worker 246*cfb92d14SAndroid Build Coastguard Workerdef check_published_route_9(): 247*cfb92d14SAndroid Build Coastguard Worker verify(br.get_state() == 'child') 248*cfb92d14SAndroid Build Coastguard Worker routes = br.get_netdata_routes() 249*cfb92d14SAndroid Build Coastguard Worker verify(len(routes) == 1) 250*cfb92d14SAndroid Build Coastguard Worker verify(routes[0].startswith('fc00::/7 sa med')) 251*cfb92d14SAndroid Build Coastguard Worker verify(br.br_get_routeprf() == 'med') 252*cfb92d14SAndroid Build Coastguard Worker 253*cfb92d14SAndroid Build Coastguard Worker 254*cfb92d14SAndroid Build Coastguard Worker# Wait for 5 minutes 255*cfb92d14SAndroid Build Coastguard Worker 256*cfb92d14SAndroid Build Coastguard Workerverify_within(check_published_route_9, (5 * 60 / speedup) + 5) 257*cfb92d14SAndroid Build Coastguard Worker 258*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 259*cfb92d14SAndroid Build Coastguard Worker# Test finished 260*cfb92d14SAndroid Build Coastguard Worker 261*cfb92d14SAndroid Build Coastguard Workercli.Node.finalize_all_nodes() 262*cfb92d14SAndroid Build Coastguard Worker 263*cfb92d14SAndroid Build Coastguard Workerprint('\'{}\' passed.'.format(test_name)) 264