[low-power] add csl feature for Thread 1.2 (#4557)

This commit implements the CSL feature in Thread 1.2.

- Add macro definitions for low power to control the compiling of
  source code.

- Add data and methods for running CSL in Mac and SubMac. This mainly
  includes setting CSL parameters, starting/stopping CSL, and the
  timer handling process.

- Add otPlatTimeGetAPI and implementation.

- Add CSL transmission implementation. CSL transmission is a new kind
  of transmission, the related definition and implementaion for the
  whole transmitting process is added.

- Add calling of start/stop CSL in certain cases.

- Implement CSL synchronization maintainence. If a CSL cordinator
  didn't get a frame containing CSL IE for CSLTimeout, the CSL
  receiver is regarded as de-synchronized.

- Add Cli interface for using CSL.

- Implement enhanced Ack with IE. The original code can only generate
  auto ack for Imm-Ack. As CSL requires CSL IE included in enhanced
  ack. This PR implements it.

- Add basic functional test for CSL transmission. More tests
  corresponding to test plan would be added later.
This commit is contained in:
Li Cao
2020-08-18 10:55:33 -07:00
committed by GitHub
parent 5b7f3b9acf
commit 7db8c6815c
41 changed files with 2012 additions and 50 deletions
+1
View File
@@ -229,6 +229,7 @@ def create_default_mle_tlvs_factories():
mle.TlvType.PANID: mle.PanIdFactory(),
mle.TlvType.ACTIVE_TIMESTAMP: mle.ActiveTimestampFactory(),
mle.TlvType.PENDING_TIMESTAMP: mle.PendingTimestampFactory(),
mle.TlvType.CSL_SYNCHRONIZED_TIMEOUT: mle.CslSynchronizedTimeoutFactory(),
mle.TlvType.ACTIVE_OPERATIONAL_DATASET: mle.ActiveOperationalDatasetFactory(),
mle.TlvType.PENDING_OPERATIONAL_DATASET: mle.PendingOperationalDatasetFactory(),
mle.TlvType.TIME_REQUEST: mle.TimeRequestFactory(),
+1
View File
@@ -76,6 +76,7 @@ class TlvType(IntEnum):
PERIOD = 55
SCAN_DURATION = 56
ENERGY_LIST = 57
CSL_SYNCHRONIZED_TIMEOUT = 85
DISCOVERY_REQUEST = 128
DISCOVERY_RESPONSE = 129
+14
View File
@@ -87,6 +87,7 @@ class TlvType(IntEnum):
ACTIVE_OPERATIONAL_DATASET = 24
PENDING_OPERATIONAL_DATASET = 25
THREAD_DISCOVERY = 26
CSL_SYNCHRONIZED_TIMEOUT = 85
TIME_REQUEST = 252
TIME_PARAMETER = 253
@@ -1047,6 +1048,19 @@ class ThreadDiscoveryFactory:
return ThreadDiscovery(tlvs)
class CslSynchronizedTimeout:
# TODO: Not implemented yet
def __init__(self):
print("CslSynchronizedTimeout is not implemented yet.")
class CslSynchronizedTimeoutFactory:
def parse(self, data, message_info):
return CslSynchronizedTimeout()
class TimeRequest:
# TODO: Not implemented yet
+16
View File
@@ -660,6 +660,22 @@ class Node:
self.send_command('pollperiod %d' % pollperiod)
self._expect('Done')
def get_csl_info(self):
self.send_command('csl')
self._expect('Done')
def set_csl_channel(self, csl_channel):
self.send_command('csl channel %d' % csl_channel)
self._expect('Done')
def set_csl_period(self, csl_period):
self.send_command('csl period %d' % csl_period)
self._expect('Done')
def set_csl_timeout(self, csl_timeout):
self.send_command('csl timeout %d' % csl_timeout)
self._expect('Done')
def set_router_upgrade_threshold(self, threshold):
cmd = 'routerupgradethreshold %d' % threshold
self.send_command(cmd)
+85
View File
@@ -0,0 +1,85 @@
#!/usr/bin/env python3
#
# Copyright (c) 2020, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
import unittest
import thread_cert
LEADER = 1
SSED_1 = 2
CSL_PERIOD = 500 * 6.25 # 500ms
CSL_TIMEOUT = 30 # 30s
CSL_CHANNEL = 12
class SSED_CslTransmission(thread_cert.TestCase):
TOPOLOGY = {
LEADER: {
'version': '1.2',
},
SSED_1: {
'version': '1.2',
'mode': 's',
},
}
"""All nodes are created with default configurations"""
def test(self):
self.nodes[SSED_1].set_csl_period(CSL_PERIOD)
self.nodes[SSED_1].set_csl_timeout(CSL_TIMEOUT)
self.nodes[SSED_1].set_csl_channel(CSL_CHANNEL)
self.nodes[SSED_1].get_csl_info()
self.nodes[LEADER].start()
self.simulator.go(5)
self.assertEqual(self.nodes[LEADER].get_state(), 'leader')
self.nodes[SSED_1].start()
self.simulator.go(7)
self.assertEqual(self.nodes[SSED_1].get_state(), 'child')
print('SSED rloc:%s' % self.nodes[SSED_1].get_rloc())
self.assertTrue(self.nodes[LEADER].ping(self.nodes[SSED_1].get_rloc()))
self.simulator.go(5)
self.nodes[SSED_1].set_csl_period(0)
self.assertFalse(self.nodes[LEADER].ping(self.nodes[SSED_1].get_rloc()))
self.simulator.go(2)
self.nodes[SSED_1].set_pollperiod(1000)
self.simulator.go(2)
self.nodes[SSED_1].set_pollperiod(0)
self.simulator.go(5)
if __name__ == '__main__':
unittest.main()