• 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_PARENT_REQUEST, MLE_CHILD_ID_REQUEST, MLE_CHILD_UPDATE_REQUEST, SOURCE_ADDRESS_TLV, LEADER_DATA_TLV, MODE_TLV
35from pktverify.packet_verifier import PacketVerifier
36
37LEADER = 1
38ROUTER = 2
39ED = 3
40
41
42class Cert_6_3_1_OrphanReattach(thread_cert.TestCase):
43    TOPOLOGY = {
44        LEADER: {
45            'name': 'LEADER',
46            'mode': 'rdn',
47            'allowlist': [ROUTER]
48        },
49        ROUTER: {
50            'name': 'ROUTER',
51            'mode': 'rdn',
52            'allowlist': [LEADER, ED]
53        },
54        ED: {
55            'name': 'ED',
56            'is_mtd': True,
57            'mode': 'rn',
58            'timeout': 10,
59            'allowlist': [ROUTER]
60        },
61    }
62
63    def test(self):
64        self.nodes[LEADER].start()
65        self.simulator.go(config.LEADER_STARTUP_DELAY)
66        self.assertEqual(self.nodes[LEADER].get_state(), 'leader')
67
68        self.nodes[ROUTER].start()
69        self.simulator.go(config.ROUTER_STARTUP_DELAY)
70        self.assertEqual(self.nodes[ROUTER].get_state(), 'router')
71
72        self.nodes[ED].start()
73        self.simulator.go(5)
74        self.assertEqual(self.nodes[ED].get_state(), 'child')
75
76        self.collect_ipaddrs()
77        self.nodes[ROUTER].stop()
78        self.nodes[LEADER].add_allowlist(self.nodes[ED].get_addr64())
79        self.nodes[ED].add_allowlist(self.nodes[LEADER].get_addr64())
80        self.simulator.go(20)
81
82        self.assertEqual(self.nodes[ED].get_state(), 'child')
83
84        addrs = self.nodes[ED].get_addrs()
85        for addr in addrs:
86            self.assertTrue(self.nodes[LEADER].ping(addr))
87
88    def verify(self, pv):
89        pkts = pv.pkts
90        pv.summary.show()
91
92        LEADER = pv.vars['LEADER']
93        ROUTER = pv.vars['ROUTER']
94        ED = pv.vars['ED']
95        _epkts = pkts.filter_wpan_src64(ED)
96
97        _epkts.filter_mle_cmd(MLE_CHILD_ID_REQUEST).must_next()
98
99        # Step 2: Remove Router from the network
100        # Step 3: The DUT MUST send three MLE Child Update Requests to its parent
101        for i in range(1, 3):
102            _epkts.filter_mle_cmd(MLE_CHILD_UPDATE_REQUEST).filter_wpan_dst64(ROUTER).must_next().must_verify(
103                lambda p: {SOURCE_ADDRESS_TLV, LEADER_DATA_TLV, MODE_TLV} <= set(p.mle.tlv.type))
104
105        # Step 5: The DUT MUST perform the attach procedure with the Leader
106        _epkts.filter_mle_cmd(MLE_PARENT_REQUEST).must_next()
107        _epkts.filter_mle_cmd(MLE_CHILD_ID_REQUEST).filter_wpan_dst64(LEADER).must_next()
108
109        # Step 6: The DUT MUST respond with ICMPv6 Echo Reply
110        _epkts.filter('ipv6.src == {ED_MLEID} and ipv6.dst == {LEADER_MLEID}',
111                      **pv.vars).filter_ping_reply().must_next()
112
113
114if __name__ == '__main__':
115    unittest.main()
116