1#!/usr/bin/env python3 2# 3# Copyright (c) 2020, 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_UPDATE_REQUEST, RESPONSE_TLV, LINK_LAYER_FRAME_COUNTER_TLV, MLE_FRAME_COUNTER_TLV, MODE_TLV, TIMEOUT_TLV, VERSION_TLV, ADDRESS_REGISTRATION_TLV, TLV_REQUEST_TLV 35from pktverify.packet_verifier import PacketVerifier 36 37LEADER = 1 38ED = 2 39 40 41class Cert_6_5_1_ChildResetReattach(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 'allowlist': [LEADER] 53 }, 54 } 55 56 def _setUpEd(self): 57 self.nodes[ED].add_allowlist(self.nodes[LEADER].get_addr64()) 58 self.nodes[ED].enable_allowlist() 59 60 def test(self): 61 self.nodes[LEADER].start() 62 self.simulator.go(config.LEADER_STARTUP_DELAY) 63 self.assertEqual(self.nodes[LEADER].get_state(), 'leader') 64 65 self.nodes[ED].start() 66 self.simulator.go(5) 67 self.assertEqual(self.nodes[ED].get_state(), 'child') 68 69 self.nodes[LEADER].remove_allowlist(self.nodes[ED].get_addr64()) 70 self.nodes[ED].remove_allowlist(self.nodes[LEADER].get_addr64()) 71 72 self.nodes[ED].reset() 73 self._setUpEd() 74 self.simulator.go(5) 75 self.nodes[ED].start() 76 77 self.simulator.go(5) 78 self.nodes[LEADER].add_allowlist(self.nodes[ED].get_addr64()) 79 self.simulator.go(5) 80 self.assertEqual(self.nodes[ED].get_state(), 'child') 81 82 addrs = self.nodes[ED].get_addrs() 83 for addr in addrs: 84 if addr[0:4] == 'fe80': 85 self.assertTrue(self.nodes[LEADER].ping(addr)) 86 87 def verify(self, pv): 88 pkts = pv.pkts 89 pv.summary.show() 90 91 LEADER = pv.vars['LEADER'] 92 ED = pv.vars['ED'] 93 _ed_pkts = pkts.filter_wpan_src64(ED) 94 95 # Step 2: Reset the DUT for a time greater than 96 # the Child Timeout Duration. 97 # Step 3: Send MLE Child Update Request to Leader 98 _ed_pkts.filter_mle_cmd(MLE_CHILD_ID_REQUEST).must_next() 99 _ed_pkts.filter_mle_cmd(MLE_CHILD_UPDATE_REQUEST).must_next().must_verify( 100 lambda p: {MODE_TLV} < set(p.mle.tlv.type)) 101 102 # Step 5: DUT reattaches to Leader 103 _ed_pkts.filter_mle_cmd(MLE_CHILD_ID_REQUEST).must_next().must_verify( 104 lambda p: { 105 RESPONSE_TLV, LINK_LAYER_FRAME_COUNTER_TLV, MLE_FRAME_COUNTER_TLV, MODE_TLV, TIMEOUT_TLV, VERSION_TLV, 106 ADDRESS_REGISTRATION_TLV, TLV_REQUEST_TLV 107 } <= set(p.mle.tlv.type)) 108 109 # Step 6: The DUT MUST respond with ICMPv6 Echo Reply 110 _ed_pkts.filter_ping_reply().filter(lambda p: p.wpan.src64 == ED and p.wpan.dst64 == LEADER).must_next() 111 112 113if __name__ == '__main__': 114 unittest.main() 115