[channel-manager] add local csl channel selection on SSED (#9641)

This commit enables channel manager on SSED, together with channel monitor,
auto-selecting a better CSL channel for the link between child and its parent.

It also fixes tracking of CcaSuccessRate on CslChannel and adds toranj tests
for auto-channel selection and thread_cert test for autocsl-channel selection.
This commit is contained in:
Martin Zimmermann
2024-03-25 14:06:29 -07:00
committed by GitHub
parent 09aa9630aa
commit 4db6520d17
17 changed files with 818 additions and 76 deletions
@@ -0,0 +1,143 @@
#!/usr/bin/env python3
#
# Copyright (c) 2023, 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 config
import mle
import thread_cert
from pktverify import consts
LEADER = 1
ED = 2
SSED = 3
class SSED_CslChannelManager(thread_cert.TestCase):
TOPOLOGY = {
LEADER: {
'version': '1.2',
},
ED: {
'version': '1.2',
'is_mtd': False,
'mode': 'rn',
},
SSED: {
'version': '1.2',
'is_mtd': True,
'mode': '-',
},
}
"""All nodes are created with default configurations"""
def test(self):
self.nodes[SSED].set_csl_period(consts.CSL_DEFAULT_PERIOD)
self.nodes[SSED].set_csl_timeout(consts.CSL_DEFAULT_TIMEOUT)
self.nodes[SSED].get_csl_info()
self.nodes[LEADER].start()
self.simulator.go(config.LEADER_STARTUP_DELAY)
self.assertEqual(self.nodes[LEADER].get_state(), 'leader')
channel = self.nodes[LEADER].get_channel()
self.nodes[SSED].start()
self.simulator.go(7)
self.assertEqual(self.nodes[SSED].get_state(), 'child')
csl_channel = 0
csl_config = self.nodes[SSED].get_csl_info()
self.assertTrue(int(csl_config['channel']) == csl_channel)
self.assertTrue(csl_config['period'] == '500000us')
print('SSED rloc:%s' % self.nodes[SSED].get_rloc())
self.assertTrue(self.nodes[LEADER].ping(self.nodes[SSED].get_rloc()))
# let channel monitor collect >970 sample counts
self.simulator.go(980 * 41)
results = self.nodes[SSED].get_channel_monitor_info()
self.assertTrue(int(results['count']) > 970)
# Configure channel manager channel masks
# Set cca threshold to 0 as we cannot change cca assessment in simulation.
# and shorten interval to speedup test
all_channels_mask = int('0x7fff800', 0)
chan_12_to_15_mask = int('0x000f000', 0)
interval = 30
self.nodes[SSED].set_channel_manager_supported(all_channels_mask)
self.nodes[SSED].set_channel_manager_favored(chan_12_to_15_mask)
self.nodes[SSED].set_channel_manager_cca_threshold('0x0000')
self.nodes[SSED].set_channel_manager_interval(interval)
# enable channel manager auto-select and check
# network channel is not changed by channel manager on SSED
# and also csl_channel is unchanged
self.nodes[SSED].set_channel_manager_auto_enable(True)
self.simulator.go(interval + 1)
results = self.nodes[SSED].get_channel_manager_config()
self.assertTrue(int(results['auto']) == 1)
self.assertTrue(results['cca threshold'] == '0x0000')
self.assertTrue(int(results['interval']) == interval)
self.assertTrue('11-26' in results['supported'])
self.simulator.go(1)
self.assertTrue(self.nodes[SSED].get_channel() == channel)
csl_config = self.nodes[SSED].get_csl_info()
self.assertTrue(int(csl_config['channel']) == csl_channel)
# check SSED can change csl channel
csl_channel = 25
self.flush_all()
self.nodes[SSED].set_csl_channel(csl_channel)
self.simulator.go(1)
ssed_messages = self.simulator.get_messages_sent_by(SSED)
self.assertIsNotNone(ssed_messages.next_mle_message(mle.CommandType.CHILD_UPDATE_REQUEST))
self.simulator.go(1)
csl_config = self.nodes[SSED].get_csl_info()
self.assertTrue(int(csl_config['channel']) == csl_channel)
self.simulator.go(1)
self.assertTrue(self.nodes[LEADER].ping(self.nodes[SSED].get_rloc()))
# enable channel manager autocsl-select in addition
# and check csl channel changed to best favored channel 12
csl_channel = 12
self.nodes[SSED].set_channel_manager_autocsl_enable(True)
self.simulator.go(interval + 1)
results = self.nodes[SSED].get_channel_manager_config()
self.assertTrue(int(results['autocsl']) == 1)
self.assertTrue(int(results['channel']) == csl_channel)
csl_config = self.nodes[SSED].get_csl_info()
self.assertTrue(int(csl_config['channel']) == csl_channel)
self.simulator.go(1)
self.assertTrue(self.nodes[LEADER].ping(self.nodes[SSED].get_rloc()))
if __name__ == '__main__':
unittest.main()
+88 -1
View File
@@ -807,6 +807,18 @@ class NodeImpl:
results = [line for line in output if self._match_pattern(line, pattern)]
return results
def _expect_key_value_pairs(self, pattern, separator=': '):
"""Expect 'key: value' in multiple lines.
Returns:
Dictionary of the key:value pairs.
"""
result = {}
for line in self._expect_results(pattern):
key, val = line.split(separator)
result.update({key: val})
return result
@staticmethod
def _match_pattern(line, pattern):
if isinstance(pattern, str):
@@ -1799,7 +1811,7 @@ class NodeImpl:
def get_csl_info(self):
self.send_command('csl')
self._expect_done()
return self._expect_key_value_pairs(r'\S+')
def set_csl_channel(self, csl_channel):
self.send_command('csl channel %d' % csl_channel)
@@ -3598,6 +3610,81 @@ class NodeImpl:
line = self._expect_command_output()[0]
return [int(item) for item in line.split()]
def get_channel_monitor_info(self) -> Dict:
"""
Returns:
Dict of channel monitor info, e.g.
{'enabled': '1',
'interval': '41000',
'threshold': '-75',
'window': '960',
'count': '985',
'occupancies': {
'11': '0.00%',
'12': '3.50%',
'13': '9.89%',
'14': '15.36%',
'15': '20.02%',
'16': '21.95%',
'17': '32.71%',
'18': '35.76%',
'19': '37.97%',
'20': '43.68%',
'21': '48.95%',
'22': '54.05%',
'23': '58.65%',
'24': '68.26%',
'25': '66.73%',
'26': '73.12%'
}
}
"""
config = {}
self.send_command('channel monitor')
for line in self._expect_results(r'\S+'):
if re.match(r'.*:\s.*', line):
key, val = line.split(':')
config.update({key: val.strip()})
elif re.match(r'.*:', line): # occupancy
occ_key, val = line.split(':')
val = {}
config.update({occ_key: val})
elif 'busy' in line:
# channel occupancies
key = line.split()[1]
val = line.split()[3]
config[occ_key].update({key: val})
return config
def set_channel_manager_auto_enable(self, enable: bool):
self.send_command(f'channel manager auto {int(enable)}')
self._expect_done()
def set_channel_manager_autocsl_enable(self, enable: bool):
self.send_command(f'channel manager autocsl {int(enable)}')
self._expect_done()
def set_channel_manager_supported(self, channel_mask: int):
self.send_command(f'channel manager supported {int(channel_mask)}')
self._expect_done()
def set_channel_manager_favored(self, channel_mask: int):
self.send_command(f'channel manager favored {int(channel_mask)}')
self._expect_done()
def set_channel_manager_interval(self, interval: int):
self.send_command(f'channel manager interval {interval}')
self._expect_done()
def set_channel_manager_cca_threshold(self, hex_value: str):
self.send_command(f'channel manager threshold {hex_value}')
self._expect_done()
def get_channel_manager_config(self):
self.send_command('channel manager')
return self._expect_key_value_pairs(r'\S+')
class Node(NodeImpl, OtCli):
pass