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 32 33# ----------------------------------------------------------------------------------------------------------------------- 34# Test description: 35# 36# Traffic between router to end-device (link-local and mesh-local IPv6 addresses). 37 38test_name = __file__[:-3] if __file__.endswith('.py') else __file__ 39print('-' * 120) 40print('Starting \'{}\''.format(test_name)) 41 42# ----------------------------------------------------------------------------------------------------------------------- 43# Creating `cli.Nodes` instances 44 45speedup = 10 46cli.Node.set_time_speedup_factor(speedup) 47 48node1 = cli.Node() 49node2 = cli.Node() 50node3 = cli.Node() 51 52# ----------------------------------------------------------------------------------------------------------------------- 53# Test implementation 54 55node1.form('net') 56node2.join(node1, cli.JOIN_TYPE_END_DEVICE) 57node3.join(node1, cli.JOIN_TYPE_SLEEPY_END_DEVICE) 58 59verify(node1.get_state() == 'leader') 60verify(node2.get_state() == 'child') 61verify(node3.get_state() == 'child') 62 63ll1 = node1.get_linklocal_ip_addr() 64ll2 = node2.get_linklocal_ip_addr() 65ll3 = node2.get_linklocal_ip_addr() 66 67ml1 = node1.get_mleid_ip_addr() 68ml2 = node2.get_mleid_ip_addr() 69ml3 = node2.get_mleid_ip_addr() 70 71sizes = [0, 80, 500, 1000] 72count = 2 73 74for size in sizes: 75 node1.ping(ll2, size=size, count=count) 76 node2.ping(ll1, size=size, count=count) 77 node1.ping(ml2, size=size, count=count) 78 node2.ping(ml1, size=size, count=count) 79 80poll_periods = [10, 100, 300] 81 82for period in poll_periods: 83 node3.set_pollperiod(period) 84 verify(int(node3.get_pollperiod()) == period) 85 86 for size in sizes: 87 node1.ping(ll3, size=size, count=count) 88 node3.ping(ll1, size=size, count=count) 89 node1.ping(ml3, size=size, count=count) 90 node3.ping(ml1, size=size, count=count) 91 92# ----------------------------------------------------------------------------------------------------------------------- 93# Test finished 94 95cli.Node.finalize_all_nodes() 96 97print('\'{}\' passed.'.format(test_name)) 98