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 LINK_LOCAL_All_THREAD_NODES_MULTICAST_ADDRESS 36from pktverify.packet_verifier import PacketVerifier 37 38LEADER = 1 39MTD = 2 40FRAGMENTED_DATA_LEN = 256 41 42# Test Purpose and Description: 43# ----------------------------- 44# The purpose of this test case is to validate the Link-Local addresses 45# that the DUT auto-configures. 46# 47# Test Topology: 48# ------------- 49# Leader 50# | 51# DUT 52# 53# DUT Types: 54# ---------- 55# ED 56# SED 57 58 59class Cert_6_4_1_LinkLocal_Base(thread_cert.TestCase): 60 USE_MESSAGE_FACTORY = False 61 62 TOPOLOGY = { 63 LEADER: { 64 'name': 'LEADER', 65 'mode': 'rdn', 66 'allowlist': [MTD] 67 }, 68 MTD: { 69 'name': 'DUT', 70 'is_mtd': True, 71 'timeout': config.DEFAULT_CHILD_TIMEOUT, 72 'allowlist': [LEADER] 73 }, 74 } 75 76 def test(self): 77 self.nodes[LEADER].start() 78 self.simulator.go(config.LEADER_STARTUP_DELAY) 79 self.assertEqual(self.nodes[LEADER].get_state(), 'leader') 80 81 self.nodes[MTD].start() 82 self.simulator.go(5) 83 self.assertEqual(self.nodes[MTD].get_state(), 'child') 84 85 self.collect_ipaddrs() 86 87 dut_addr = self.nodes[MTD].get_ip6_address(config.ADDRESS_TYPE.LINK_LOCAL) 88 self.assertTrue(self.nodes[LEADER].ping(dut_addr, size=FRAGMENTED_DATA_LEN)) 89 self.simulator.go(1) 90 self.assertTrue(self.nodes[LEADER].ping(dut_addr)) 91 self.simulator.go(1) 92 93 self.assertTrue(self.nodes[LEADER].ping(config.LINK_LOCAL_All_THREAD_NODES_MULTICAST_ADDRESS, 94 size=FRAGMENTED_DATA_LEN)) 95 self.simulator.go(1) 96 self.assertTrue(self.nodes[LEADER].ping(config.LINK_LOCAL_All_THREAD_NODES_MULTICAST_ADDRESS)) 97 self.simulator.go(1) 98 99 if self.TOPOLOGY[MTD]['mode'] == 'rn': 100 self.assertTrue(self.nodes[LEADER].ping(config.LINK_LOCAL_ALL_NODES_ADDRESS, size=FRAGMENTED_DATA_LEN)) 101 self.simulator.go(1) 102 self.assertTrue(self.nodes[LEADER].ping(config.LINK_LOCAL_ALL_NODES_ADDRESS)) 103 104 def verify(self, pv): 105 pkts = pv.pkts 106 pv.summary.show() 107 108 LEADER = pv.vars['LEADER'] 109 LEADER_LLA = pv.vars['LEADER_LLA'] 110 DUT_LLA = pv.vars['DUT_LLA'] 111 112 # Step 1: Ensure topology is formed correctly 113 pv.verify_attached('DUT', 'LEADER', 'MTD') 114 115 # Step 2: Leader sends a Fragmented ICMPv6 Echo Request to DUT’s 116 # MAC extended address based Link-Local address 117 # The DUT MUST respond with an ICMPv6 Echo Reply 118 119 _pkt = pkts.filter_ping_request().\ 120 filter_ipv6_src_dst(LEADER_LLA, DUT_LLA).\ 121 filter(lambda p: p.icmpv6.data.len == FRAGMENTED_DATA_LEN).\ 122 must_next() 123 pkts.filter_ping_reply(identifier=_pkt.icmpv6.echo.identifier).\ 124 filter_ipv6_src_dst(DUT_LLA, LEADER_LLA).\ 125 filter(lambda p: p.icmpv6.data.len == FRAGMENTED_DATA_LEN).\ 126 must_next() 127 128 # Step 3: Leader sends an Unfragmented ICMPv6 Echo Request to DUT’s 129 # MAC extended address based Link-Local address 130 # The DUT MUST respond with an ICMPv6 Echo Reply 131 132 _pkt = pkts.filter_ping_request().\ 133 filter_ipv6_src_dst(LEADER_LLA, DUT_LLA).\ 134 must_next() 135 pkts.filter_ping_reply(identifier=_pkt.icmpv6.echo.identifier).\ 136 filter_ipv6_src_dst(DUT_LLA, LEADER_LLA).\ 137 must_next() 138 139 # Step 4: Leader sends a Fragmented ICMPv6 Echo Request to the 140 # Link-Local All thread nodes multicast address 141 # The DUT MUST respond with an ICMPv6 Echo Reply 142 143 _pkt = pkts.filter_ping_request().\ 144 filter_wpan_src64(LEADER).\ 145 filter_LLATNMA().\ 146 filter(lambda p: p.icmpv6.data.len == FRAGMENTED_DATA_LEN).\ 147 must_next() 148 pkts.filter_ping_reply(identifier=_pkt.icmpv6.echo.identifier).\ 149 filter_ipv6_src_dst(DUT_LLA, LEADER_LLA).\ 150 filter(lambda p: p.icmpv6.data.len == FRAGMENTED_DATA_LEN).\ 151 must_next() 152 153 # Step 5: Leader sends an Unfragmented ICMPv6 Echo Request to the 154 # Link-Local All thread nodes multicast address 155 # The DUT MUST respond with an ICMPv6 Echo Reply 156 157 _pkt = pkts.filter_ping_request().\ 158 filter_wpan_src64(LEADER).\ 159 filter_LLATNMA().\ 160 must_next() 161 pkts.filter_ping_reply(identifier=_pkt.icmpv6.echo.identifier).\ 162 filter_ipv6_src_dst(DUT_LLA, LEADER_LLA).\ 163 must_next() 164 165 if self.TOPOLOGY[MTD]['mode'] == 'rn': 166 # Step 6: Leader sends a Fragmented ICMPv6 Echo Request to the 167 # Link-Local All Nodes multicast address (FF02::1) 168 # The DUT MUST respond with an ICMPv6 Echo Reply 169 170 _pkt = pkts.filter_ping_request().\ 171 filter_wpan_src64(LEADER).\ 172 filter_LLANMA().\ 173 filter(lambda p: p.icmpv6.data.len == FRAGMENTED_DATA_LEN).\ 174 must_next() 175 pkts.filter_ping_reply(identifier=_pkt.icmpv6.echo.identifier).\ 176 filter_ipv6_src_dst(DUT_LLA, LEADER_LLA).\ 177 filter(lambda p: p.icmpv6.data.len == FRAGMENTED_DATA_LEN).\ 178 must_next() 179 180 # Step 7: Leader sends an Unfragmented ICMPv6 Echo Request to the 181 # Link-Local All Nodes multicast address (FF02::1) 182 # The DUT MUST respond with an ICMPv6 Echo Reply 183 184 _pkt = pkts.filter_ping_request().\ 185 filter_wpan_src64(LEADER).\ 186 filter_LLANMA().\ 187 must_next() 188 pkts.filter_ping_reply(identifier=_pkt.icmpv6.echo.identifier).\ 189 filter_ipv6_src_dst(DUT_LLA, LEADER_LLA).\ 190 must_next() 191 192 193class Cert_6_4_1_LinkLocal_ED(Cert_6_4_1_LinkLocal_Base): 194 TOPOLOGY = copy.deepcopy(Cert_6_4_1_LinkLocal_Base.TOPOLOGY) 195 TOPOLOGY[MTD]['mode'] = 'rn' 196 197 198class Cert_6_4_1_LinkLocal_SED(Cert_6_4_1_LinkLocal_Base): 199 TOPOLOGY = copy.deepcopy(Cert_6_4_1_LinkLocal_Base.TOPOLOGY) 200 TOPOLOGY[MTD]['mode'] = '-' 201 202 203del (Cert_6_4_1_LinkLocal_Base) 204 205if __name__ == '__main__': 206 unittest.main() 207