• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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#
29import re
30import unittest
31
32import config
33import thread_cert
34from config import MESH_LOCAL_PREFIX_REGEX_PATTERN, ROUTING_LOCATOR_REGEX_PATTERN
35from pktverify.packet_verifier import PacketVerifier
36
37# Test description:
38# The purpose of this test is to verify ALOC connectivity.
39#
40# Topology:
41#
42#
43#  PBBR ----- LEADER ---- ROUTER
44#
45#
46
47LEADER = 1
48PBBR = 2
49ROUTER = 3
50
51
52class TestPing(thread_cert.TestCase):
53    USE_MESSAGE_FACTORY = False
54    SUPPORT_NCP = False
55    SUPPORT_THREAD_1_1 = False
56
57    TOPOLOGY = {
58        LEADER: {
59            'name': 'Router_1',
60            'allowlist': [PBBR, ROUTER],
61        },
62        PBBR: {
63            'name': 'Router_2',
64            'allowlist': [LEADER],
65            'is_bbr': True,
66        },
67        ROUTER: {
68            'name': 'Router_3',
69            'allowlist': [LEADER],
70        },
71    }
72
73    def test(self):
74        leader = self.nodes[LEADER]
75        pbbr = self.nodes[PBBR]
76        router = self.nodes[ROUTER]
77
78        leader.start()
79        self.simulator.go(config.LEADER_STARTUP_DELAY)
80        self.assertEqual('leader', leader.get_state())
81
82        pbbr.enable_backbone_router()
83        pbbr.start()
84        self.simulator.go(config.ROUTER_STARTUP_DELAY)
85        self.assertEqual('router', pbbr.get_state())
86        self.assertTrue(pbbr.is_primary_backbone_router)
87
88        router.start()
89        self.simulator.go(config.ROUTER_STARTUP_DELAY)
90        self.assertEqual('router', router.get_state())
91
92        for node in (leader, pbbr):
93            for addr in self.get_alocs(node):
94                self.assertTrue(router.ping(addr))
95
96    def verify(self, pv: PacketVerifier):
97        pkts = pv.pkts
98        # Must sure no ADDR_QUERY.qry is ever sent
99        pkts.filter_coap_request('/a/aq').must_not_next()
100
101    def get_alocs(self, node):
102        mleid = node.get_mleid()
103        for ip in node.get_addrs():
104            if not re.match(MESH_LOCAL_PREFIX_REGEX_PATTERN, ip):
105                continue
106
107            if ip == mleid:
108                continue
109
110            self.assertIsNotNone(re.match(ROUTING_LOCATOR_REGEX_PATTERN, ip), ip)
111            locator = int(ip.split(':')[-1], 16)
112            if locator >= 0xfc00:
113                yield ip
114
115
116if __name__ == '__main__':
117    unittest.main()
118