3 # Copyright (c) 2016, The OpenThread Authors.
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.
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.
33 from pktverify.consts import MLE_CHILD_ID_RESPONSE, MLE_LINK_REQUEST, MLE_LINK_ACCEPT, CHALLENGE_TLV, LEADER_DATA_TLV, SOURCE_ADDRESS_TLV, VERSION_TLV
34 from pktverify.packet_verifier import PacketVerifier
43 class Cert_6_1_9_EDSynchronization(thread_cert.TestCase):
49 'whitelist': [ROUTER1, ED, ROUTER2]
55 'router_selection_jitter': 1,
56 'whitelist': [LEADER, ED, ROUTER3]
61 'router_upgrade_threshold': 0,
68 'router_selection_jitter': 1,
69 'whitelist': [LEADER, ED, ROUTER3]
75 'router_selection_jitter': 1,
76 'whitelist': [ED, ROUTER1, ROUTER2]
81 self.nodes[LEADER].start()
83 self.assertEqual(self.nodes[LEADER].get_state(), 'leader')
85 self.nodes[ROUTER1].start()
87 self.assertEqual(self.nodes[ROUTER1].get_state(), 'router')
89 self.nodes[ROUTER2].start()
91 self.assertEqual(self.nodes[ROUTER2].get_state(), 'router')
93 self.nodes[ROUTER3].start()
95 self.assertEqual(self.nodes[ROUTER3].get_state(), 'router')
97 self.nodes[ED].start()
99 self.assertEqual(self.nodes[ED].get_state(), 'child')
101 self.nodes[ED].add_whitelist(self.nodes[ROUTER1].get_addr64())
102 self.nodes[ED].add_whitelist(self.nodes[ROUTER2].get_addr64())
103 self.nodes[ED].add_whitelist(self.nodes[ROUTER3].get_addr64())
104 self.nodes[ED].enable_whitelist()
105 self.simulator.go(10)
107 def verify(self, pv):
111 LEADER = pv.vars['LEADER']
114 # Step 3: The DUT MUST send a unicast Link Request
115 # to Router 1, Router 2 & Router 3
116 pkts.filter_wpan_src64(LEADER).filter_wpan_dst64(ED).filter_mle_cmd(MLE_CHILD_ID_RESPONSE).must_next()
117 for i in range(1, 3):
119 _pkts.filter_wpan_src64(ED).filter_wpan_dst64(
120 pv.vars['ROUTER_%d' % i]).filter_mle_cmd(MLE_LINK_REQUEST).must_next().must_verify(
121 lambda p: {CHALLENGE_TLV, LEADER_DATA_TLV, SOURCE_ADDRESS_TLV, VERSION_TLV} <= set(p.mle.tlv.type))
123 # Step 4: Router_1, Router_2 & Router_3 MUST all send a
124 # Link Accept message to the DUT
125 _pkts.filter_wpan_src64(pv.vars['ROUTER_%d' %
126 i]).filter_wpan_dst64(ED).filter_mle_cmd(MLE_LINK_ACCEPT).must_next()
129 if __name__ == '__main__':