1#!/usr/bin/env python3 2# 3# Copyright (c) 2021, 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# 29 30import unittest 31 32import config 33import thread_cert 34 35# Test description: 36# The purpose of this test case is to verify that BR can manually configure addresses and comply 37# with the manual address configuration rules. 38# 39# Topology: 40# BR_1 (Leader) 41# | 42# | 43# ROUTER 44# 45 46BR_1 = 1 47ROUTER = 2 48 49PREFIX = '2002::/64' 50GUA_1 = '2002::a:b:c:d' 51GUA_2 = '2002::a:b:c:e' 52 53 54class ManualAddressConfig(thread_cert.TestCase): 55 USE_MESSAGE_FACTORY = False 56 57 TOPOLOGY = { 58 BR_1: { 59 'name': 'BR_1', 60 'is_otbr': True, 61 'version': '1.2', 62 }, 63 ROUTER: { 64 'name': 'ROUTER', 65 'version': '1.2', 66 }, 67 } 68 69 def test(self): 70 br1 = self.nodes[BR_1] 71 router = self.nodes[ROUTER] 72 73 br1.start() 74 self.simulator.go(config.LEADER_STARTUP_DELAY) 75 self.assertEqual('leader', br1.get_state()) 76 self.assertTrue(br1.is_primary_backbone_router) 77 78 router.start() 79 self.simulator.go(config.ROUTER_STARTUP_DELAY) 80 self.assertEqual('router', router.get_state()) 81 82 # Add prefix 83 br1.add_prefix(PREFIX, flags='po', prf='med') 84 br1.register_netdata() 85 self.simulator.go(5) 86 87 # Configure GUA addresses 88 br1.add_ipaddr(GUA_1) 89 router.add_ipaddr(GUA_2) 90 91 # BR_1 sends a ping packet to the GUA_2 address. Router should respond to the ping request. 92 self.assertTrue(br1.ping(GUA_2)) 93 self.simulator.go(5) 94 95 # Router sends a ping packet to the GUA_1 address. BR_1 should respond to the ping request. 96 self.assertTrue(router.ping(GUA_1)) 97 self.simulator.go(5) 98 99 100if __name__ == '__main__': 101 unittest.main() 102