[mle] simplify router/leader role restoration upon reset (#10798)

This commit introduces the `RouterRoleRestorer` class, nested within
`MleRouter`, to manage router/leader role restoration after an MLE
operation restart (e.g., a device reboot) by sending multicast Link
Requests. This class simplifies the code and centralizes role
restoration logic.

Specific changes:

- A new member variable `mLastSavedRole` is added to track the last
  attached role (saved in non-volatile memory). This is used by
  `RouterRoleRestorer` to determine the number of Link Request
  attempts. This variable replaces the previous `mWasLeader`, which
  was only updated after a reboot and would not account for role
  changes afterward.
- The `AttachTimer` is now used for role restoration instead of the
  retransmission timer, as role restoration always occurs while the
  device is detached and before any attach attempts.
- The `kLinkRequestTimeout` is used for the last attempt before
  considering restoration failure.
- The `mChallengeTimeout` mechanism is now removed (in earlier Thread
  specification versions, multicast Link Requests could be used while
  the device was attached, but this is no longer used or needed).
- `test-012-reset-recovery.py` is updated to validate the role
  restoration behavior. `test_detach` is also updated and fixed.
This commit is contained in:
Abtin Keshavarzian
2024-10-10 21:47:34 -07:00
committed by GitHub
parent 057b87fdd1
commit 19b2d6bbc4
9 changed files with 182 additions and 84 deletions
+1
View File
@@ -138,6 +138,7 @@ SECURITY_POLICY = [672, 'onrc']
LEADER_STARTUP_DELAY = 12
ROUTER_STARTUP_DELAY = 10
LEADER_REBOOT_DELAY = 40
ED_STARTUP_DELAY = 5
BORDER_ROUTER_STARTUP_DELAY = 20
MAX_NEIGHBOR_AGE = 100