• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#  Copyright (c) 2020, 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"""This test case verifies Thread 1.2 enhanced frame pending feature.
30
31Topology
32
33    Leader ----- SED_1
34
351. Set up topology a Leader and a SED.
362. SED pings leader so a data poll is just sent.
373. Leader sends a UDP packet to SED to put a pending frame in queue.
384. Wait for half polling period, verify no packet received by SED.
395. SED sends a UDP packet to Leader to solicit an ACK with frame pending set.
40   * Verify Leader receives a UDP packet
41   * Verify SED sends a data poll
42   * Verify SED receives a UDP packet
43"""
44
45import unittest
46import pexpect
47
48import thread_cert
49import config
50import common
51
52LEADER = 1
53SED_1 = 2
54
55CHILD_TIMEOUT = 30
56UDP_BYTES_COUNT = 73
57
58DEFAULT_POLL_PERIOD = CHILD_TIMEOUT - 4
59"""The default poll period calculated from child timeout."""
60
61
62class SED_EnhancedFramePending(thread_cert.TestCase):
63    TOPOLOGY = {
64        LEADER: {
65            'version': '1.2'
66        },
67        SED_1: {
68            'mode': '-',
69            'version': '1.2',
70        },
71    }
72
73    def test(self):
74        self.nodes[SED_1].set_timeout(CHILD_TIMEOUT)
75
76        # 1 - Set up topology
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[SED_1].start()
82        self.simulator.go(7)
83        self.assertEqual(self.nodes[SED_1].get_state(), 'child')
84
85        self.nodes[LEADER].udp_start('::', common.UDP_TEST_PORT)
86        self.nodes[SED_1].udp_start('::', common.UDP_TEST_PORT)
87
88        # 2 - Ping Leader
89        self.assertTrue(self.nodes[SED_1].ping(self.nodes[LEADER].get_rloc(), timeout=CHILD_TIMEOUT))
90
91        self.flush_all()
92
93        # 3 - Send to SED
94        self.nodes[LEADER].udp_send(UDP_BYTES_COUNT, self.nodes[SED_1].get_rloc(), common.UDP_TEST_PORT)
95
96        # 4 - Wait for half polling period
97        self.simulator.go(DEFAULT_POLL_PERIOD // 2)
98        with self.assertRaises(pexpect.TIMEOUT):
99            self.nodes[SED_1].udp_check_rx(UDP_BYTES_COUNT)
100
101        # 5 - Send to Leader
102        self.nodes[SED_1].udp_send(UDP_BYTES_COUNT, self.nodes[LEADER].get_rloc(), common.UDP_TEST_PORT)
103        self.simulator.go(1)
104        self.nodes[LEADER].udp_check_rx(UDP_BYTES_COUNT)
105        sed_messages = self.simulator.get_messages_sent_by(SED_1)
106        self.assertNotEqual(sed_messages.next_data_poll(), None)
107        self.nodes[SED_1].udp_check_rx(UDP_BYTES_COUNT)
108
109
110if __name__ == '__main__':
111    unittest.main()
112