• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#  Copyright (c) 2016, 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
34from pktverify.consts import MLE_CHILD_ID_REQUEST, MLE_PARENT_REQUEST, MODE_TLV, CHALLENGE_TLV, SCAN_MASK_TLV, VERSION_TLV, RESPONSE_TLV, LINK_LAYER_FRAME_COUNTER_TLV, MLE_FRAME_COUNTER_TLV, TIMEOUT_TLV, ADDRESS_REGISTRATION_TLV, TLV_REQUEST_TLV, LINK_LOCAL_ALL_ROUTERS_MULTICAST_ADDRESS
35from pktverify.packet_verifier import PacketVerifier
36
37LEADER = 1
38ROUTER1 = 2
39REED1 = 3
40REED2 = 4
41ED = 5
42
43
44class Cert_6_1_5_REEDAttachConnectivity(thread_cert.TestCase):
45    TOPOLOGY = {
46        LEADER: {
47            'name': 'LEADER',
48            'mode': 'rdn',
49            'allowlist': [ROUTER1, REED1, REED2]
50        },
51        ROUTER1: {
52            'name': 'ROUTER_1',
53            'mode': 'rdn',
54            'allowlist': [LEADER, REED2]
55        },
56        REED1: {
57            'name': 'REED_1',
58            'mode': 'rdn',
59            'router_upgrade_threshold': 0,
60            'allowlist': [LEADER, ROUTER1, ED]
61        },
62        REED2: {
63            'name': 'REED_2',
64            'mode': 'rdn',
65            'router_upgrade_threshold': 0,
66            'allowlist': [LEADER, (ED, -85)]
67        },
68        ED: {
69            'name': 'ED',
70            'is_mtd': True,
71            'mode': 'rn',
72            'allowlist': [REED1, REED2]
73        },
74    }
75
76    def test(self):
77        self.nodes[LEADER].start()
78        self.simulator.go(config.LEADER_STARTUP_DELAY)
79        self.assertEqual(self.nodes[LEADER].get_state(), 'leader')
80
81        self.nodes[ROUTER1].start()
82        self.simulator.go(config.ROUTER_STARTUP_DELAY)
83        self.assertEqual(self.nodes[ROUTER1].get_state(), 'router')
84
85        self.nodes[REED1].start()
86        self.simulator.go(5)
87        self.assertEqual(self.nodes[REED1].get_state(), 'child')
88
89        self.nodes[REED2].start()
90        self.simulator.go(5)
91        self.assertEqual(self.nodes[REED2].get_state(), 'child')
92
93        self.nodes[ED].start()
94        self.simulator.go(10)
95        self.assertEqual(self.nodes[ED].get_state(), 'child')
96        self.assertEqual(self.nodes[REED1].get_state(), 'router')
97
98        self.num_parent_requests = 1 if self.nodes[ED].version in ['1.1', '1.2'] else 2
99
100        self.collect_ipaddrs()
101        addrs = self.nodes[ED].get_addrs()
102        for addr in addrs:
103            self.assertTrue(self.nodes[REED1].ping(addr))
104
105    def verify(self, pv):
106        pkts = pv.pkts
107        pv.summary.show()
108
109        REED_1 = pv.vars['REED_1']
110        ED = pv.vars['ED']
111        _reed1_pkts = pkts.filter_wpan_src64(REED_1)
112        _ed_pkts = pkts.filter_wpan_src64(ED)
113
114        # Step 2: The DUT MUST send MLE Parent Requests to the
115        # All-Routers multicast address
116
117        for num in range(self.num_parent_requests):
118            _ed_pkts.filter_mle_cmd(MLE_PARENT_REQUEST).filter_ipv6_dst(
119                LINK_LOCAL_ALL_ROUTERS_MULTICAST_ADDRESS).must_next().must_verify(
120                    lambda p: {MODE_TLV, CHALLENGE_TLV, SCAN_MASK_TLV, VERSION_TLV} == set(
121                        p.mle.tlv.type) and p.mle.tlv.scan_mask.r == 1)
122
123        # Step 3: REED_1 and REED_2 No response to Parent Request
124        # Step 4: DUT Send MLE Parent Request with Scan Mask set to Routers AND REEDs
125        _ed_pkts.filter_mle_cmd(MLE_PARENT_REQUEST).must_next().must_verify(
126            lambda p: {MODE_TLV, CHALLENGE_TLV, SCAN_MASK_TLV, VERSION_TLV} == set(
127                p.mle.tlv.type) and p.mle.tlv.scan_mask.r == 1 and p.mle.tlv.scan_mask.e == 1)
128
129        # Step 5: The DUT MUST send a MLE Child ID Request
130        _ed_pkts.filter_wpan_dst64(REED_1).filter_mle_cmd(MLE_CHILD_ID_REQUEST).must_next().must_verify(
131            lambda p: {
132                RESPONSE_TLV, LINK_LAYER_FRAME_COUNTER_TLV, MLE_FRAME_COUNTER_TLV, MODE_TLV, TIMEOUT_TLV, VERSION_TLV,
133                ADDRESS_REGISTRATION_TLV, TLV_REQUEST_TLV
134            } <= set(p.mle.tlv.type))
135
136        # Step 8: The DUT MUST respond with ICMPv6 Echo Reply
137        ed_mleid = pv.vars['ED_MLEID']
138        reed1_mleid = pv.vars['REED_1_MLEID']
139        _pkt = _reed1_pkts.filter(
140            lambda p: p.ipv6.src == reed1_mleid and p.ipv6.dst == ed_mleid).filter_ping_request().must_next()
141        _ed_pkts.filter(lambda p: p.ipv6.src == ed_mleid and p.ipv6.dst == reed1_mleid).filter_ping_reply(
142            identifier=_pkt.icmpv6.echo.identifier).must_next()
143
144
145if __name__ == '__main__':
146    unittest.main()
147