From 025405645e176d42d0d94fa7a4ae5eedea621829 Mon Sep 17 00:00:00 2001 From: Simon Lin Date: Mon, 25 Oct 2021 23:34:49 +0800 Subject: [PATCH] [otci] support MLE Discovery (#7073) --- tools/otci/otci/command_handlers.py | 2 +- tools/otci/otci/otci.py | 8 +++++++- tools/otci/tests/test_otci.py | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/otci/otci/command_handlers.py b/tools/otci/otci/command_handlers.py index 31a3ab00b..3c50ddd89 100644 --- a/tools/otci/otci/command_handlers.py +++ b/tools/otci/otci/command_handlers.py @@ -86,7 +86,7 @@ class OtCliCommandRunner(OTCommandHandler): r')') """regex used to filter logs""" - __ASYNC_COMMANDS = {'scan', 'ping'} + __ASYNC_COMMANDS = {'scan', 'ping', 'discover'} def __init__(self, otcli: OtCliHandler, is_spinel_cli=False): self.__otcli: OtCliHandler = otcli diff --git a/tools/otci/otci/otci.py b/tools/otci/otci/otci.py index aeb7fb0e6..b93bbc2fc 100644 --- a/tools/otci/otci/otci.py +++ b/tools/otci/otci/otci.py @@ -225,9 +225,15 @@ class OTCI(object): """Stop sending ICMPv6 Echo Requests.""" self.execute_command('ping stop') + def discover(self, channel: int = None) -> List[Dict[str, Any]]: + """Perform an MLE Discovery operation.""" + return self.__scan_networks('discover', channel) + def scan(self, channel: int = None) -> List[Dict[str, Any]]: """Perform an IEEE 802.15.4 Active Scan.""" - cmd = 'scan' + return self.__scan_networks('scan', channel) + + def __scan_networks(self, cmd: str, channel: int = None) -> List[Dict[str, Any]]: if channel is not None: cmd += f' {channel}' diff --git a/tools/otci/tests/test_otci.py b/tools/otci/tests/test_otci.py index 84dd88435..c1eacefb5 100644 --- a/tools/otci/tests/test_otci.py +++ b/tools/otci/tests/test_otci.py @@ -270,6 +270,7 @@ class TestOTCI(unittest.TestCase): logging.info("Leader router table: %r", leader.get_router_table()) self.assertFalse(list(leader.get_router_table().values())[0].is_link_established) + logging.info('discover: %r', leader.discover()) logging.info('scan: %r', leader.scan()) logging.info('scan energy: %r', leader.scan_energy()) @@ -613,6 +614,7 @@ class TestOTCI(unittest.TestCase): child1.ifconfig_up() + logging.info("child1 discover: %r", child1.discover()) logging.info("child1 scan: %r", child1.scan()) logging.info("child1 scan energy: %r", child1.scan_energy())