• 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 command
33import config
34import copy
35import ipv6
36import mle
37import thread_cert
38from pktverify.consts import WIRESHARK_OVERRIDE_PREFS, MLE_ADVERTISEMENT, ADDR_QRY_URI, SOURCE_ADDRESS_TLV, ROUTE64_TLV, LEADER_DATA_TLV
39from pktverify.packet_verifier import PacketVerifier
40from pktverify.bytes import Bytes
41
42DUT_LEADER = 1
43BR = 2
44MED1 = 3
45MED2 = 4
46
47MTDS = [MED1, MED2]
48
49# Test Purpose and Description:
50# -----------------------------
51# The purpose of this test case is to validate that the DUT MTD Child Address Set
52# can hold at least 4 IPv6 non-link-local addresses.
53#
54# Test Topology:
55# -------------
56#           MED_1
57#            |
58#  BR - Leader(DUT) - MED_2
59#
60# DUT Types:
61# ----------
62#  Leader
63
64
65class Cert_5_3_8_ChildAddressSet(thread_cert.TestCase):
66    USE_MESSAGE_FACTORY = False
67
68    TOPOLOGY = {
69        DUT_LEADER: {
70            'name': 'LEADER',
71            'mode': 'rdn',
72            'allowlist': [BR, MED1, MED2]
73        },
74        BR: {
75            'mode': 'rdn',
76            'allowlist': [DUT_LEADER]
77        },
78        MED1: {
79            'name': 'MED_1',
80            'is_mtd': True,
81            'mode': 'rn',
82            'allowlist': [DUT_LEADER]
83        },
84        MED2: {
85            'name': 'MED_2',
86            'is_mtd': True,
87            'mode': 'rn',
88            'allowlist': [DUT_LEADER]
89        },
90    }
91    # override wireshark preferences with case needed parameters
92    CASE_WIRESHARK_PREFS = copy.deepcopy(WIRESHARK_OVERRIDE_PREFS)
93    CASE_WIRESHARK_PREFS['6lowpan.context1'] = '2001::/64'
94    CASE_WIRESHARK_PREFS['6lowpan.context2'] = '2002::/64'
95    CASE_WIRESHARK_PREFS['6lowpan.context3'] = '2003::/64'
96
97    def test(self):
98        self.nodes[DUT_LEADER].start()
99        self.simulator.go(config.LEADER_STARTUP_DELAY)
100        self.assertEqual(self.nodes[DUT_LEADER].get_state(), 'leader')
101
102        self.nodes[BR].start()
103        self.simulator.go(config.ROUTER_STARTUP_DELAY)
104        self.assertEqual(self.nodes[BR].get_state(), 'router')
105
106        # 1 BR: Configure BR to be a DHCPv6 server
107        self.nodes[BR].add_prefix('2001::/64', 'pdros')
108        self.nodes[BR].add_prefix('2002::/64', 'pdros')
109        self.nodes[BR].add_prefix('2003::/64', 'pdros')
110        self.nodes[BR].register_netdata()
111
112        # 3 MED1, MED2: MED1 and MED2 attach to DUT_LEADER
113        for i in MTDS:
114            self.nodes[i].start()
115            self.simulator.go(5)
116            self.assertEqual(self.nodes[i].get_state(), 'child')
117        self.collect_ipaddrs()
118
119        # 4 MED1: MED1 send an ICMPv6 Echo Request to the MED2 ML-EID
120        med2_ml_eid = self.nodes[MED2].get_ip6_address(config.ADDRESS_TYPE.ML_EID)
121        self.assertTrue(med2_ml_eid is not None)
122        self.assertTrue(self.nodes[MED1].ping(med2_ml_eid))
123
124        # Wait for sniffer got packets
125        self.simulator.go(1)
126
127        # 5 MED1: MED1 send an ICMPv6 Echo Request to the MED2 2001::GUA
128        addr = self.nodes[MED2].get_addr("2001::/64")
129        self.assertTrue(addr is not None)
130        self.assertTrue(self.nodes[MED1].ping(addr))
131        # Wait for sniffer got packets
132        self.simulator.go(1)
133
134        # 6 MED1: MED1 send an ICMPv6 Echo Request to the MED2 2002::GUA
135        addr = self.nodes[MED2].get_addr("2002::/64")
136        self.assertTrue(addr is not None)
137        self.assertTrue(self.nodes[MED1].ping(addr))
138
139        # Wait for sniffer got packets
140        self.simulator.go(1)
141
142        # 7 MED1: MED1 send an ICMPv6 Echo Request to the MED2 2003::GUA
143        addr = self.nodes[MED2].get_addr("2003::/64")
144        self.assertTrue(addr is not None)
145        self.assertTrue(self.nodes[MED1].ping(addr))
146
147        # Wait for sniffer got packets
148        self.simulator.go(1)
149
150    def verify(self, pv):
151        pkts = pv.pkts
152        pv.summary.show()
153
154        LEADER = pv.vars['LEADER']
155        MED_1 = pv.vars['MED_1']
156        MED_1_MLEID = pv.vars['MED_1_MLEID']
157        MED_2 = pv.vars['MED_2']
158        MED_2_MLEID = pv.vars['MED_2_MLEID']
159        MED_1_GUA = list()
160        MED_2_GUA = list()
161        MM = pv.vars['MM_PORT']
162        names = locals()
163
164        for i in (1, 2):
165            for addr in pv.vars['MED_%d_IPADDRS' % i]:
166                for j in range(1, 4):
167                    if addr.startswith(Bytes('200%d' % j)):
168                        names['MED_' + str(i) + '_GUA'].append(addr)
169
170        # Step 2: Leader is sending properly formatted MLE Advertisements.
171        #         Advertisements MUST be sent with an IP hop limit of 255 to
172        #         the Link-Local All Nodes multicast address (FF02::1).
173        #         The following TLVs MUST be present in the MLE Advertisements:
174        #             - Leader Data TLV
175        #             - Route64 TLV
176        #             - Source Address TLV
177
178        pkts.filter_wpan_src64(LEADER).\
179            filter_LLANMA().\
180            filter_mle_cmd(MLE_ADVERTISEMENT).\
181            filter(lambda p: {
182                              LEADER_DATA_TLV,
183                              ROUTE64_TLV,
184                              SOURCE_ADDRESS_TLV
185                              } <= set(p.mle.tlv.type) and\
186                   p.ipv6.hlim == 255).\
187            must_next()
188
189        # Step 3: Send a ICMPv6 Echo Request to the MED_2 ML-EID
190        #         The DUT MUST NOT send an Address Query Request
191        #         MED_2 MUST respond with an ICMPv6 Echo Reply
192
193        _pkt = pkts.filter_ipv6_src_dst(MED_1_MLEID, MED_2_MLEID).\
194                    filter_ping_request().\
195                    must_next()
196        pkts.filter_wpan_src64(LEADER).\
197            filter_RLARMA().\
198            filter_coap_request(ADDR_QRY_URI, port=MM).\
199            must_not_next()
200        pkts.filter_ipv6_src_dst(MED_2_MLEID, MED_1_MLEID).\
201            filter_ping_reply(identifier=_pkt.icmpv6.echo.identifier).\
202            must_next()
203
204        # Step 4-6: Send a ICMPv6 Echo Request to the MED_2 each GUA
205        #           The DUT MUST NOT send an Address Query Request
206        #           MED_2 MUST respond with an ICMPv6 Echo Reply
207
208        for med_1_addr, med_2_addr in zip(MED_1_GUA, MED_2_GUA):
209            _pkt = pkts.filter_ipv6_src_dst(med_1_addr, med_2_addr).\
210                        filter_ping_request().\
211                        must_next()
212            pkts.filter_wpan_src64(LEADER).\
213                filter_RLARMA().\
214                filter_coap_request(ADDR_QRY_URI, port=MM).\
215                must_not_next()
216            pkts.filter_ipv6_src_dst(med_2_addr, med_1_addr).\
217                filter_ping_reply(identifier=_pkt.icmpv6.echo.identifier).\
218                must_next()
219
220
221if __name__ == '__main__':
222    unittest.main()
223