[mle] add API to detach gracefully (#7666)

This commit adds an API `otThreadDetachGracefully` to notify other
nodes in the network (if any) and then stop Thread protocol
operation. It sends an Address Release if it's a router, or sets its
child timeout to 0 if it's a child.
This commit is contained in:
jinran-google
2022-06-02 09:04:14 -07:00
committed by GitHub
parent 8f92d2dc81
commit 9bb09e74e2
12 changed files with 423 additions and 7 deletions
+24
View File
@@ -815,6 +815,30 @@ class NodeImpl:
self.send_command('thread stop')
self._expect_done()
def detach(self, is_async=False):
cmd = 'detach'
if is_async:
cmd += ' async'
self.send_command(cmd)
if is_async:
self._expect_done()
return
end = self.simulator.now() + 4
while True:
self.simulator.go(1)
try:
self._expect_done(timeout=0.1)
return
except (pexpect.TIMEOUT, socket.timeout):
if self.simulator.now() > end:
raise
def expect_finished_detaching(self):
self._expect('Finished detaching')
def commissioner_start(self):
cmd = 'commissioner start'
self.send_command(cmd)