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 behavior of MeshHeader messages (message sent over multi-hop) when the 36# underlying devices (in the path) support different radio types with different frame MTU length. 37# 38# r1 --------- r2 ---------- r3 39# (trel) (15.4+trel) (15.4) 40# | 41# | 42# c2 (15.4) 43# 44 45test_name = __file__[:-3] if __file__.endswith('.py') else __file__ 46print('-' * 120) 47print('Starting \'{}\''.format(test_name)) 48 49# ----------------------------------------------------------------------------------------------------------------------- 50# Creating `cli.Node` instances 51 52speedup = 10 53cli.Node.set_time_speedup_factor(speedup) 54 55r1 = cli.Node(cli.RADIO_TREL) 56r2 = cli.Node(cli.RADIO_15_4_TREL) 57r3 = cli.Node(cli.RADIO_15_4) 58c2 = cli.Node(cli.RADIO_15_4) 59 60# ----------------------------------------------------------------------------------------------------------------------- 61# Build network topology 62 63r1.allowlist_node(r2) 64 65r2.allowlist_node(r1) 66r2.allowlist_node(r3) 67r2.allowlist_node(c2) 68 69r3.allowlist_node(r2) 70 71c2.allowlist_node(r2) 72 73r1.form("mesh-header") 74 75r2.join(r1) 76r3.join(r2) 77c2.join(r2, cli.JOIN_TYPE_END_DEVICE) 78 79verify(r1.get_state() == 'leader') 80verify(r2.get_state() == 'router') 81verify(r3.get_state() == 'router') 82verify(c2.get_state() == 'child') 83 84# ----------------------------------------------------------------------------------------------------------------------- 85# Test Implementation 86 87verify(r1.multiradio_get_radios() == '[TREL]') 88verify(r2.multiradio_get_radios() == '[15.4, TREL]') 89verify(r3.multiradio_get_radios() == '[15.4]') 90 91r1_rloc = int(r1.get_rloc16(), 16) 92 93r1_ml_addr = r1.get_mleid_ip_addr() 94r3_ml_addr = r3.get_mleid_ip_addr() 95 96# Wait till routes are discovered. 97 98 99def check_r1_router_table(): 100 table = r1.get_router_table() 101 verify(len(table) == 3) 102 for entry in table: 103 verify(int(entry['RLOC16'], 0) == r1_rloc or int(entry['Link']) == 1 or int(entry['Next Hop']) != 63) 104 105 106verify_within(check_r1_router_table, 120) 107 108# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 109# Ping r3 from r2 using large message size. Such a message would be sent as a 110# Mesh Header message. Note that the origin r1 is a trel-only device 111# whereas the final destination r3 is a 15.4-only device. The originator 112# should use smaller MTU size (which then fragment the message into 113# multiple frames) otherwise the 15.4 link won't be able to handle it. 114 115r1.ping(r3_ml_addr, size=1000, count=2) 116 117# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 118# Ping r1 from c2 using large message size. 119 120c2.ping(r1_ml_addr, size=1000, count=2) 121 122# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 123# Ping r1 from r3 124 125r3.ping(r1_ml_addr, size=1000, count=2) 126 127# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 128# Finally ping r1 and r3 from r2. 129 130r2.ping(r1_ml_addr, size=1000, count=2) 131r2.ping(r3_ml_addr, size=1000, count=2) 132 133# ----------------------------------------------------------------------------------------------------------------------- 134# Test finished 135 136cli.Node.finalize_all_nodes() 137 138print('\'{}\' passed.'.format(test_name)) 139