1#!/usr/bin/env python3 2# 3# Copyright (c) 2022, 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 29from cli import verify 30from cli import verify_within 31import cli 32import time 33 34# ----------------------------------------------------------------------------------------------------------------------- 35# Test description: This test covers joining of nodes with different radio links 36# 37# Parent node with trel and 15.4 with 3 children. 38# 39# parent 40# (trel + 15.4) 41# / | \ 42# / | \ 43# / | \ 44# c1 c2 c3 45# (15.4) (trel) (trel+15.4) 46 47test_name = __file__[:-3] if __file__.endswith('.py') else __file__ 48print('-' * 120) 49print('Starting \'{}\''.format(test_name)) 50 51# ----------------------------------------------------------------------------------------------------------------------- 52# Creating `cli.Node` instances 53 54speedup = 10 55cli.Node.set_time_speedup_factor(speedup) 56 57parent = cli.Node(cli.RADIO_15_4_TREL) 58c1 = cli.Node(cli.RADIO_15_4) 59c2 = cli.Node(cli.RADIO_TREL) 60c3 = cli.Node(cli.RADIO_15_4_TREL) 61 62# ----------------------------------------------------------------------------------------------------------------------- 63# Test Implementation 64 65# Verify that each node supports the correct radio links. 66 67verify(parent.multiradio_get_radios() == '[15.4, TREL]') 68verify(c1.multiradio_get_radios() == '[15.4]') 69verify(c2.multiradio_get_radios() == '[TREL]') 70verify(c3.multiradio_get_radios() == '[15.4, TREL]') 71 72parent.form("multi-radio") 73 74c1.join(parent, cli.JOIN_TYPE_END_DEVICE) 75c2.join(parent, cli.JOIN_TYPE_END_DEVICE) 76c3.join(parent, cli.JOIN_TYPE_END_DEVICE) 77 78# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 79# Verify that parent correctly learns about all the children and their 80# supported radio links. 81 82c1_ext_addr = c1.get_ext_addr() 83c2_ext_addr = c2.get_ext_addr() 84c3_ext_addr = c3.get_ext_addr() 85 86neighbor_radios = parent.multiradio_get_neighbor_list() 87verify(len(neighbor_radios) == 3) 88for entry in neighbor_radios: 89 info = cli.Node.parse_multiradio_neighbor_entry(entry) 90 radios = info['Radios'] 91 if info['ExtAddr'] == c1_ext_addr: 92 verify(int(info['RLOC16'], 16) == int(c1.get_rloc16(), 16)) 93 verify(len(radios) == 1) 94 verify('15.4' in radios) 95 elif info['ExtAddr'] == c2_ext_addr: 96 verify(int(info['RLOC16'], 16) == int(c2.get_rloc16(), 16)) 97 verify(len(radios) == 1) 98 verify('TREL' in radios) 99 elif info['ExtAddr'] == c3_ext_addr: 100 verify(int(info['RLOC16'], 16) == int(c3.get_rloc16(), 16)) 101 verify(len(radios) == 2) 102 verify('15.4' in radios) 103 verify('TREL' in radios) 104 else: 105 verify(False) 106 107# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 108# Reset the parent and check that all children are attached back successfully 109 110del parent 111parent = cli.Node(cli.RADIO_15_4_TREL, index=1) 112parent.interface_up() 113parent.thread_start() 114 115 116def check_all_children_are_attached(): 117 verify(len(parent.get_child_table()) == 3) 118 119 120verify_within(check_all_children_are_attached, 10) 121 122# ----------------------------------------------------------------------------------------------------------------------- 123# Test finished 124 125cli.Node.finalize_all_nodes() 126 127print('\'{}\' passed.'.format(test_name)) 128