1#!/usr/bin/env python3 2# 3# Copyright (c) 2023, 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: 36# 37# Validate changes to `IntervalMax` for MLE Advertisement Trickle Timer based on number of 38# router neighbors of the device. 39# 40 41test_name = __file__[:-3] if __file__.endswith('.py') else __file__ 42print('-' * 120) 43print('Starting \'{}\''.format(test_name)) 44 45# ----------------------------------------------------------------------------------------------------------------------- 46# Creating `cli.Node` instances 47 48speedup = 20 49cli.Node.set_time_speedup_factor(speedup) 50 51leader = cli.Node() 52 53# ----------------------------------------------------------------------------------------------------------------------- 54# Test Implementation 55 56leader.form('ba-ephemeral') 57 58verify(leader.get_state() == 'leader') 59 60verify(leader.ba_is_ephemeral_key_active() == 'inactive') 61 62port = int(leader.ba_get_port()) 63 64leader.ba_set_ephemeral_key('password', 10000, 1234) 65 66time.sleep(0.1) 67 68verify(leader.ba_is_ephemeral_key_active() == 'active') 69verify(int(leader.ba_get_port()) == 1234) 70 71leader.ba_set_ephemeral_key('password2', 200, 45678) 72 73time.sleep(0.100 / speedup) 74verify(leader.ba_is_ephemeral_key_active() == 'active') 75verify(int(leader.ba_get_port()) == 45678) 76 77time.sleep(0.150 / speedup) 78verify(leader.ba_is_ephemeral_key_active() == 'inactive') 79verify(int(leader.ba_get_port()) == port) 80 81leader.ba_set_ephemeral_key('newkey') 82verify(leader.ba_is_ephemeral_key_active() == 'active') 83 84time.sleep(0.1) 85verify(leader.ba_is_ephemeral_key_active() == 'active') 86 87leader.ba_clear_ephemeral_key() 88verify(leader.ba_is_ephemeral_key_active() == 'inactive') 89verify(int(leader.ba_get_port()) == port) 90 91# ----------------------------------------------------------------------------------------------------------------------- 92# Test finished 93 94cli.Node.finalize_all_nodes() 95 96print('\'{}\' passed.'.format(test_name)) 97