• 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_CHILD_ID_RESPONSE, MLE_CHILD_UPDATE_REQUEST, MLE_CHILD_UPDATE_RESPONSE, MODE_TLV
35from pktverify.packet_verifier import PacketVerifier
36
37LEADER = 1
38ED = 2
39
40
41class Cert_6_5_3_ChildResetSynchronize(thread_cert.TestCase):
42    TOPOLOGY = {
43        LEADER: {
44            'name': 'LEADER',
45            'mode': 'rdn',
46            'allowlist': [ED]
47        },
48        ED: {
49            'name': 'ED',
50            'is_mtd': True,
51            'mode': 'rn',
52            'timeout': config.DEFAULT_CHILD_TIMEOUT,
53            'allowlist': [LEADER]
54        },
55    }
56
57    def _setUpEd(self):
58        self.nodes[ED].add_allowlist(self.nodes[LEADER].get_addr64())
59        self.nodes[ED].enable_allowlist()
60
61    def test(self):
62        self.nodes[LEADER].start()
63        self.simulator.go(config.LEADER_STARTUP_DELAY)
64        self.assertEqual(self.nodes[LEADER].get_state(), 'leader')
65
66        self.nodes[ED].start()
67        self.simulator.go(5)
68        self.assertEqual(self.nodes[ED].get_state(), 'child')
69
70        self.nodes[ED].reset()
71        self._setUpEd()
72        self.simulator.go(1)
73
74        self.nodes[ED].start()
75        self.simulator.go(1)
76        self.assertEqual(self.nodes[ED].get_state(), 'child')
77
78        addrs = self.nodes[ED].get_addrs()
79        for addr in addrs:
80            if addr[0:4] == 'fe80':
81                self.assertTrue(self.nodes[LEADER].ping(addr))
82
83    def verify(self, pv):
84        pkts = pv.pkts
85        pv.summary.show()
86
87        LEADER = pv.vars['LEADER']
88        ED = pv.vars['ED']
89        _leader_pkts = pkts.filter_wpan_src64(LEADER)
90        _ed_pkts = pkts.filter_wpan_src64(ED)
91
92        # Step 2: Reset the DUT for a time shorter than
93        # the Child Timeout Duration.
94        # Step 3: Send MLE Child Update Request to Leader
95        _ed_pkts.filter_mle_cmd(MLE_CHILD_ID_REQUEST).must_next()
96        _leader_pkts.range(_ed_pkts.index).filter_mle_cmd(MLE_CHILD_ID_RESPONSE).must_next()
97        _ed_pkts.filter_mle_cmd(MLE_CHILD_UPDATE_REQUEST).must_next().must_verify(
98            lambda p: {MODE_TLV} <= set(p.mle.tlv.type))
99
100        # Step 4: Leader send an MLE Child Update Response
101        _leader_pkts.range(_ed_pkts.index).filter_mle_cmd(MLE_CHILD_UPDATE_RESPONSE).must_next()
102        _ed_pkts.range(_leader_pkts.index).filter_mle_cmd(MLE_CHILD_ID_REQUEST).must_not_next()
103
104        # Step 5: The DUT MUST respond with ICMPv6 Echo Reply
105        _ed_pkts.filter_ping_reply().filter(lambda p: p.wpan.src64 == ED and p.wpan.dst64 == LEADER).must_next()
106
107
108if __name__ == '__main__':
109    unittest.main()
110