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_ADVERTISEMENT, MLE_CHILD_UPDATE_REQUEST, SOURCE_ADDRESS_TLV, MODE_TLV, LEADER_DATA_TLV 35from pktverify.packet_verifier import PacketVerifier 36 37LEADER = 1 38ROUTER1 = 2 39ROUTER2 = 3 40ED = 4 41 42 43class Cert_6_2_2_NewPartition(thread_cert.TestCase): 44 TOPOLOGY = { 45 LEADER: { 46 'name': 'LEADER', 47 'mode': 'rdn', 48 'allowlist': [ROUTER1, ROUTER2] 49 }, 50 ROUTER1: { 51 'name': 'ROUTER_1', 52 'mode': 'rdn', 53 'allowlist': [LEADER, ROUTER2, ED] 54 }, 55 ROUTER2: { 56 'name': 'ROUTER_2', 57 'mode': 'rdn', 58 'network_id_timeout': 110, 59 'allowlist': [LEADER, ROUTER1] 60 }, 61 ED: { 62 'name': 'ED', 63 'is_mtd': True, 64 'mode': 'rn', 65 'allowlist': [ROUTER1] 66 }, 67 } 68 69 def test(self): 70 self.nodes[LEADER].start() 71 self.simulator.go(config.LEADER_STARTUP_DELAY) 72 self.assertEqual(self.nodes[LEADER].get_state(), 'leader') 73 74 self.nodes[ROUTER1].start() 75 self.simulator.go(config.ROUTER_STARTUP_DELAY) 76 self.assertEqual(self.nodes[ROUTER1].get_state(), 'router') 77 78 self.nodes[ROUTER2].start() 79 self.simulator.go(config.ROUTER_STARTUP_DELAY) 80 self.assertEqual(self.nodes[ROUTER2].get_state(), 'router') 81 82 self.nodes[ED].start() 83 self.simulator.go(5) 84 self.assertEqual(self.nodes[ED].get_state(), 'child') 85 86 self.nodes[LEADER].stop() 87 self.simulator.go(140) 88 self.assertEqual(self.nodes[ROUTER2].get_state(), 'leader') 89 self.assertEqual(self.nodes[ROUTER1].get_state(), 'router') 90 self.assertEqual(self.nodes[ED].get_state(), 'child') 91 92 self.collect_ipaddrs() 93 addrs = self.nodes[ED].get_addrs() 94 for addr in addrs: 95 self.assertTrue(self.nodes[ROUTER1].ping(addr)) 96 97 def verify(self, pv): 98 pkts = pv.pkts 99 pv.summary.show() 100 101 ROUTER_1 = pv.vars['ROUTER_1'] 102 ED = pv.vars['ED'] 103 _router1_pkts = pkts.filter_wpan_src64(ROUTER_1) 104 _ed_pkts = pkts.filter_wpan_src64(ED) 105 106 # Step 1: Ensure that the DUT successfully attached to Router_1 107 _ed_pkts.filter_mle_cmd(MLE_CHILD_ID_REQUEST).filter_wpan_dst64(ROUTER_1).must_next() 108 109 # Step 2-6 : remove Leader and make ROUTER_2 as new Leader 110 # Step 7: The DUT MUST send a MLE Child Update Request to Router_1 111 _ed_pkts.filter_mle_cmd(MLE_ADVERTISEMENT).must_not_next() 112 _ed_pkts.filter_mle_cmd(MLE_CHILD_ID_REQUEST).must_not_next() 113 _ed_pkts.filter_wpan_dst64(ROUTER_1).filter_mle_cmd(MLE_CHILD_UPDATE_REQUEST).must_next().must_verify( 114 lambda p: {MODE_TLV, SOURCE_ADDRESS_TLV, LEADER_DATA_TLV} <= set(p.mle.tlv.type)) 115 116 # Step 8: The DUT MUST respond with ICMPv6 Echo Reply 117 _ed_pkts.filter('ipv6.dst == {ROUTER_1_MLEID} and ipv6.src == {ED_MLEID}', 118 **pv.vars).filter_ping_reply().must_next() 119 120 121if __name__ == '__main__': 122 unittest.main() 123