Skip to content
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

Merged
merged 2 commits into from
Jan 4, 2025

Conversation

bukepo
Copy link
Member

@bukepo bukepo commented Jan 2, 2025

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.

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.
Copy link

size-report bot commented Jan 2, 2025

Size Report of OpenThread

Merging #11107 into main(1024a1f).

name branch text data bss total
ot-cli-ftd main 472520 856 66100 539476
#11107 472488 856 66100 539444
+/- -32 0 0 -32
ot-ncp-ftd main 441228 760 61328 503316
#11107 441196 760 61328 503284
+/- -32 0 0 -32
libopenthread-ftd.a main 239635 95 39886 279616
#11107 239617 95 39886 279598
+/- -18 0 0 -18
libopenthread-cli-ftd.a main 58922 0 8075 66997
#11107 58922 0 8075 66997
+/- 0 0 0 0
libopenthread-ncp-ftd.a main 32787 0 5924 38711
#11107 32787 0 5924 38711
+/- 0 0 0 0
ot-cli-mtd main 367976 760 50748 419484
#11107 367976 760 50748 419484
+/- 0 0 0 0
ot-ncp-mtd main 350668 760 45992 397420
#11107 350668 760 45992 397420
+/- 0 0 0 0
libopenthread-mtd.a main 160073 0 24550 184623
#11107 160073 0 24550 184623
+/- 0 0 0 0
libopenthread-cli-mtd.a main 40125 0 8059 48184
#11107 40125 0 8059 48184
+/- 0 0 0 0
libopenthread-ncp-mtd.a main 25561 0 5924 31485
#11107 25561 0 5924 31485
+/- 0 0 0 0
ot-cli-ftd-br main 559256 864 130980 691100
#11107 559240 864 130980 691084
+/- -16 0 0 -16
libopenthread-ftd-br.a main 331196 100 104734 436030
#11107 331176 100 104734 436010
+/- -20 0 0 -20
libopenthread-cli-ftd-br.a main 73119 0 8107 81226
#11107 73119 0 8107 81226
+/- 0 0 0 0
ot-rcp main 63072 564 20804 84440
#11107 63072 564 20804 84440
+/- 0 0 0 0
libopenthread-rcp.a main 9920 0 5060 14980
#11107 9920 0 5060 14980
+/- 0 0 0 0
libopenthread-radio.a main 19102 0 238 19340
#11107 19102 0 238 19340
+/- 0 0 0 0

Copy link

codecov bot commented Jan 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.41%. Comparing base (d539ad3) to head (5beba5f).
Report is 31 commits behind head on main.

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     
Files with missing lines Coverage Δ
src/core/api/thread_ftd_api.cpp 59.35% <100.00%> (-16.58%) ⬇️
src/core/thread/mle_router.cpp 83.15% <100.00%> (+1.43%) ⬆️

... and 386 files with indirect coverage changes

@bukepo bukepo marked this pull request as ready for review January 2, 2025 21:35
Copy link
Member

@abtink abtink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use !IsRouterOrLeader()?

@@ -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);
Copy link
Member

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".

Copy link
Member

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.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@bukepo bukepo requested a review from jwhui January 3, 2025 02:18
@jwhui jwhui added the comp: mle label Jan 4, 2025
@jwhui jwhui changed the title [mle] no redundant checks in otThreadBecomeRouter [mle] remove redundant checks in otThreadBecomeRouter Jan 4, 2025
@jwhui jwhui merged commit 0e70395 into openthread:main Jan 4, 2025
97 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants