• 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
30import unittest
31
32import mle
33import thread_cert
34import config
35
36LEADER = 1
37SSED_1 = 2
38
39CSL_PERIOD = 500 * 1000  # 0.5 in usec
40CSL_TIMEOUT = 30  # 30s
41
42
43class SSED_SingleProbe(thread_cert.TestCase):
44    TOPOLOGY = {
45        LEADER: {
46            'version': '1.2',
47        },
48        SSED_1: {
49            'version': '1.2',
50            'mode': '-',
51        },
52    }
53    """All nodes are created with default configurations"""
54
55    def test(self):
56
57        self.nodes[SSED_1].set_csl_period(CSL_PERIOD)
58        self.nodes[SSED_1].set_csl_timeout(CSL_TIMEOUT)
59
60        self.nodes[LEADER].start()
61        self.simulator.go(config.LEADER_STARTUP_DELAY)
62        self.assertEqual(self.nodes[LEADER].get_state(), 'leader')
63
64        self.nodes[SSED_1].start()
65        self.simulator.go(7)
66        self.assertEqual(self.nodes[SSED_1].get_state(), 'child')
67
68        leader_addr = self.nodes[LEADER].get_linklocal()
69
70        leader_messages = self.simulator.get_messages_sent_by(LEADER)
71
72        # SSED_1 sends a Single Probe Link Metrics for L2 PDU count using MLE Data Request
73        result = self.nodes[SSED_1].link_metrics_request_single_probe(leader_addr, 'p')
74        self.assertIn('PDU Counter', result)
75        self.assertEqual(len(result), 1)
76
77        leader_messages = self.simulator.get_messages_sent_by(LEADER)
78        msg = leader_messages.next_mle_message(mle.CommandType.DATA_RESPONSE)
79        msg.assertMleMessageContainsTlv(mle.LinkMetricsReport)
80
81        # SSED_1 sends a Single Probe Link Metrics for L2 LQI using MLE Data Request
82        result = self.nodes[SSED_1].link_metrics_request_single_probe(leader_addr, 'q')
83        self.assertIn('LQI', result)
84        self.assertEqual(len(result), 1)
85
86        leader_messages = self.simulator.get_messages_sent_by(LEADER)
87        msg = leader_messages.next_mle_message(mle.CommandType.DATA_RESPONSE)
88        msg.assertMleMessageContainsTlv(mle.LinkMetricsReport)
89
90        # SSED_1 sends a Single Probe Link Metrics for Link Margin using MLE Data Request
91        result = self.nodes[SSED_1].link_metrics_request_single_probe(leader_addr, 'm')
92        self.assertIn('Margin', result)
93        self.assertEqual(len(result), 1)
94
95        leader_messages = self.simulator.get_messages_sent_by(LEADER)
96        msg = leader_messages.next_mle_message(mle.CommandType.DATA_RESPONSE)
97        msg.assertMleMessageContainsTlv(mle.LinkMetricsReport)
98
99        # SSED_1 sends a Single Probe Link Metrics for Link Margin using MLE Data Request
100        result = self.nodes[SSED_1].link_metrics_request_single_probe(leader_addr, 'r')
101        self.assertIn('RSSI', result)
102        self.assertEqual(len(result), 1)
103
104        leader_messages = self.simulator.get_messages_sent_by(LEADER)
105        msg = leader_messages.next_mle_message(mle.CommandType.DATA_RESPONSE)
106        msg.assertMleMessageContainsTlv(mle.LinkMetricsReport)
107
108        # SSED_1 sends a Single Probe Link Metrics for all metrics using MLE Data Request
109        result = self.nodes[SSED_1].link_metrics_request_single_probe(leader_addr, 'pqmr')
110        self.assertIn('PDU Counter', result)
111        self.assertIn('LQI', result)
112        self.assertIn('Margin', result)
113        self.assertIn('RSSI', result)
114        self.assertEqual(len(result), 4)
115
116        leader_messages = self.simulator.get_messages_sent_by(LEADER)
117        msg = leader_messages.next_mle_message(mle.CommandType.DATA_RESPONSE)
118        msg.assertMleMessageContainsTlv(mle.LinkMetricsReport)
119
120        self.assertTrue(self.nodes[LEADER].ping(self.nodes[SSED_1].get_rloc()))
121
122
123if __name__ == '__main__':
124    unittest.main()
125