mirror of
https://github.com/espressif/openthread.git
synced 2026-07-29 15:17:47 +00:00
[mlr] add Commissioner API to register Multicast Listeners (#5346)
This commit is contained in:
@@ -281,6 +281,37 @@ class Node:
|
||||
|
||||
return results
|
||||
|
||||
def _expect_command_output(self, cmd: str):
|
||||
lines = []
|
||||
cmd_output_started = False
|
||||
|
||||
while True:
|
||||
self._expect(r"[^\n]+")
|
||||
line = self.pexpect.match.group(0).decode('utf8').strip()
|
||||
|
||||
if line.startswith('> '):
|
||||
line = line[2:]
|
||||
|
||||
if line == '':
|
||||
continue
|
||||
|
||||
if line == cmd:
|
||||
cmd_output_started = True
|
||||
continue
|
||||
|
||||
if not cmd_output_started:
|
||||
continue
|
||||
|
||||
if line == 'Done':
|
||||
break
|
||||
elif line.startswith('Error '):
|
||||
raise Exception(line)
|
||||
else:
|
||||
lines.append(line)
|
||||
|
||||
print(f'_expect_command_output({cmd!r}) returns {lines!r}')
|
||||
return lines
|
||||
|
||||
def __init_soc(self, nodeid):
|
||||
""" Initialize a System-on-a-chip node connected via UART. """
|
||||
import fdpexpect
|
||||
@@ -564,6 +595,24 @@ class Node:
|
||||
self.send_command(cmd)
|
||||
self._expect('Done')
|
||||
|
||||
def register_multicast_listener(self, *ipaddrs: Union[ipaddress.IPv6Address, str], timeout=None):
|
||||
assert len(ipaddrs) > 0, ipaddrs
|
||||
|
||||
cmd = f'mlr reg {" ".join(ipaddrs)}'
|
||||
if timeout is not None:
|
||||
cmd += f' {int(timeout)}'
|
||||
self.send_command(cmd)
|
||||
self.simulator.go(3)
|
||||
lines = self._expect_command_output(cmd)
|
||||
m = re.match(r'status (\d+), (\d+) failed', lines[0])
|
||||
assert m is not None, lines
|
||||
status = int(m.group(1))
|
||||
failed_num = int(m.group(2))
|
||||
assert failed_num == len(lines) - 1
|
||||
failed_ips = list(map(ipaddress.IPv6Address, lines[1:]))
|
||||
print(f"register_multicast_listener {ipaddrs} => status: {status}, failed ips: {failed_ips}")
|
||||
return status, failed_ips
|
||||
|
||||
def set_link_quality(self, addr, lqi):
|
||||
cmd = 'macfilter rss add-lqi %s %s' % (addr, lqi)
|
||||
self.send_command(cmd)
|
||||
|
||||
Reference in New Issue
Block a user