-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mle] remove redundant checks in otThreadBecomeRouter #11107
Conversation
The MleRouter::BecomeRouter already checks the device role and the API claims only return OT_ERROR_INVALID_STATE when the role is disabled. This commit consolidates the device role check in MleRouter::BecomeRouter.
Size Report of OpenThread
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #11107 +/- ##
==========================================
+ Coverage 74.82% 75.41% +0.59%
==========================================
Files 619 620 +1
Lines 84846 93742 +8896
==========================================
+ Hits 63483 70693 +7210
- Misses 21363 23049 +1686
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/core/thread/mle_router.cpp
Outdated
@@ -238,7 +238,7 @@ Error MleRouter::BecomeRouter(ThreadStatusTlv::Status aStatus) | |||
Error error = kErrorNone; | |||
|
|||
VerifyOrExit(!IsDisabled(), error = kErrorInvalidState); | |||
VerifyOrExit(!IsRouter(), error = kErrorNone); | |||
VerifyOrExit(!IsRouter() && !IsLeader(), error = kErrorNone); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use !IsRouterOrLeader()
?
src/core/thread/mle_router.cpp
Outdated
@@ -238,7 +238,7 @@ Error MleRouter::BecomeRouter(ThreadStatusTlv::Status aStatus) | |||
Error error = kErrorNone; | |||
|
|||
VerifyOrExit(!IsDisabled(), error = kErrorInvalidState); | |||
VerifyOrExit(!IsRouter(), error = kErrorNone); | |||
VerifyOrExit(!IsRouter() && !IsLeader(), error = kErrorNone); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be good to check that adding IsLeader()
is safe/fine here, i.e. we do not call BecomeRouter()
anywhere in the code when the current role may be "leader".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did go through all places in the OT core code where BecomeRouter()
is called, seems to be okay to add IsLeader()
check.
We also expose this as a public API, but it is intended for testing, so changing its behavior should be fine.
The MleRouter::BecomeRouter already checks the device role and the API claims only return OT_ERROR_INVALID_STATE when the role is disabled.
This commit consolidates the device role check in
MleRouter::BecomeRouter.