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 31import copy 32 33import config 34import thread_cert 35from pktverify.consts import MLE_PARENT_REQUEST 36from pktverify.packet_verifier import PacketVerifier 37 38LEADER = 1 39ROUTER1 = 2 40MTD = 3 41 42# Test Purpose and Description: 43# ----------------------------- 44# The purpose of this test case is to show that the DUT upholds connectivity, or 45# reattaches with its parent, when the Leader is removed and the Router creates a 46# new partition 47# 48# Test Topology: 49# ------------- 50# Leader 51# | 52# Router 53# | 54# DUT 55# 56# DUT Types: 57# ---------- 58# ED 59# SED 60 61 62class Cert_6_2_1_NewPartition_Base(thread_cert.TestCase): 63 USE_MESSAGE_FACTORY = False 64 65 TOPOLOGY = { 66 LEADER: { 67 'name': 'LEADER', 68 'mode': 'rdn', 69 'allowlist': [ROUTER1] 70 }, 71 ROUTER1: { 72 'name': 'ROUTER', 73 'mode': 'rdn', 74 'allowlist': [LEADER, MTD] 75 }, 76 MTD: { 77 'name': 'DUT', 78 'is_mtd': True, 79 'timeout': config.DEFAULT_CHILD_TIMEOUT, 80 'allowlist': [ROUTER1] 81 }, 82 } 83 84 def test(self): 85 self.nodes[LEADER].start() 86 self.simulator.go(config.LEADER_STARTUP_DELAY) 87 self.assertEqual(self.nodes[LEADER].get_state(), 'leader') 88 89 self.nodes[ROUTER1].start() 90 self.simulator.go(config.ROUTER_STARTUP_DELAY) 91 self.assertEqual(self.nodes[ROUTER1].get_state(), 'router') 92 93 self.nodes[MTD].start() 94 self.simulator.go(5) 95 self.assertEqual(self.nodes[MTD].get_state(), 'child') 96 97 self.nodes[LEADER].stop() 98 self.simulator.go(150) 99 self.assertEqual(self.nodes[ROUTER1].get_state(), 'leader') 100 self.assertEqual(self.nodes[MTD].get_state(), 'child') 101 102 self.collect_ipaddrs() 103 104 dut_addr = self.nodes[MTD].get_ip6_address(config.ADDRESS_TYPE.LINK_LOCAL) 105 self.assertTrue(self.nodes[ROUTER1].ping(dut_addr)) 106 107 def verify(self, pv): 108 pkts = pv.pkts 109 pv.summary.show() 110 111 LEADER = pv.vars['LEADER'] 112 ROUTER = pv.vars['ROUTER'] 113 ROUTER_LLA = pv.vars['ROUTER_LLA'] 114 DUT = pv.vars['DUT'] 115 DUT_LLA = pv.vars['DUT_LLA'] 116 117 # Step 1: Ensure topology is formed correctly 118 pkts.filter_wpan_src64(LEADER).\ 119 filter_mle_advertisement('Leader').\ 120 must_next() 121 122 pv.verify_attached('ROUTER', 'LEADER') 123 pv.verify_attached('DUT', 'ROUTER', 'MTD') 124 125 # Step 3: Router automatically creates new partition and begins transmitting 126 # MLE Advertisements 127 pkts.filter_wpan_src64(ROUTER).\ 128 filter_LLARMA().\ 129 filter_mle_cmd(MLE_PARENT_REQUEST).\ 130 must_next() 131 pkts.filter_wpan_src64(ROUTER).\ 132 filter_mle_advertisement('Router').\ 133 must_next() 134 135 # Step 5: Router verifies connectivity by sending an ICMPv6 Echo Request 136 # to the DUT link local address 137 # DUT responds with ICMPv6 Echo Reply 138 _pkt = pkts.filter_ping_request().\ 139 filter_ipv6_src_dst(ROUTER_LLA, DUT_LLA).\ 140 must_next() 141 pkts.filter_ping_reply(identifier=_pkt.icmpv6.echo.identifier).\ 142 filter_ipv6_src_dst(DUT_LLA, ROUTER_LLA).\ 143 must_next() 144 145 146class Cert_6_2_1_NewPartition_ED(Cert_6_2_1_NewPartition_Base): 147 TOPOLOGY = copy.deepcopy(Cert_6_2_1_NewPartition_Base.TOPOLOGY) 148 TOPOLOGY[MTD]['mode'] = 'rn' 149 150 151class Cert_6_2_1_NewPartition_SED(Cert_6_2_1_NewPartition_Base): 152 TOPOLOGY = copy.deepcopy(Cert_6_2_1_NewPartition_Base.TOPOLOGY) 153 TOPOLOGY[MTD]['mode'] = '-' 154 155 156del (Cert_6_2_1_NewPartition_Base) 157 158if __name__ == '__main__': 159 unittest.main() 160