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

[rest] commissioner api #2515

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

OmegaRelay
Copy link

@OmegaRelay OmegaRelay commented Sep 30, 2024

Added endpoints to the REST server to expose commissioner functionality over the REST API

These changes intend to implement commissioner functionality in the same style as the current rest API offering.

  • The /node/commissioner/state endpoint allows the user to get/set the commissioner state using GET and PUT requests respectively.
  • The /node/commissioner/joiner allows the user to manage joiners accepted by the commissioner, supporting POST, GET and DELETE request methods to add, get and remove a joiner respectively.

All added endpoints and their usage have been documented in the openapi.yaml

Example usage:
image

Please give me feedback and let me know of any required changes 😄

@marijnacht
Copy link

Will this PR be picked up as we kind of need this functionality. I also see another PR #2514 but that is really large change.

Copy link

codecov bot commented Oct 5, 2024

Codecov Report

Attention: Patch coverage is 0.79365% with 250 lines in your changes missing coverage. Please review.

Project coverage is 44.50%. Comparing base (2b41187) to head (97631a1).
Report is 817 commits behind head on main.

Files with missing lines Patch % Lines
src/rest/resource.cpp 1.41% 139 Missing ⚠️
src/rest/json.cpp 0.00% 94 Missing ⚠️
src/common/api_strings.cpp 0.00% 10 Missing ⚠️
src/utils/hex.cpp 0.00% 7 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2515       +/-   ##
===========================================
- Coverage   55.77%   44.50%   -11.28%     
===========================================
  Files          87      100       +13     
  Lines        6890    12145     +5255     
  Branches        0      894      +894     
===========================================
+ Hits         3843     5405     +1562     
- Misses       3047     6449     +3402     
- Partials        0      291      +291     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@OmegaRelay OmegaRelay changed the title Rest commissioner api [rest] commissioner api Oct 7, 2024
Copy link
Member

@wgtdkp wgtdkp left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Overall loooks good to me, a few suggestions below:

schema:
type: string
description: Eui64 address or discerner of joiner to remove
example: "0xabc/12"
Copy link
Member

Choose a reason for hiding this comment

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

Could you add document explains the format 0xabc/12? What does "/12" mean?

Comment on lines +834 to +835
VerifyOrExit(otCommissionerGetState(mInstance) == OT_COMMISSIONER_STATE_DISABLED,
error = OTBR_ERROR_DUPLICATED);
Copy link
Member

Choose a reason for hiding this comment

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

What about accepting it in this case so that the REST API is idempotent?

Comment on lines +841 to +842
VerifyOrExit(otCommissionerGetState(mInstance) != OT_COMMISSIONER_STATE_DISABLED,
error = OTBR_ERROR_DUPLICATED);
Copy link
Member

Choose a reason for hiding this comment

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

Ditto, it's better to make the REST API idempotent.

else if (error != OTBR_ERROR_NONE)
{
ErrorHandler(aResponse, HttpStatusCode::kStatusInternalServerError);
}
Copy link
Member

Choose a reason for hiding this comment

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

It's probably safer to have an else {} to capture any error which may be missed from the if () statements.

{
ErrorHandler(aResponse, HttpStatusCode::kStatusBadRequest);
}
else if (error == OTBR_ERROR_OPENTHREAD)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using OTBR_ERROR_OPENTHREAD for InsufficientStorage, it's probably better to just use OT error directly, instead of casting OT error to OTBR error.


if (discerner.mLength == 0)
{
VerifyOrExit(otCommissionerRemoveJoiner(mInstance, addrPtr) == OT_ERROR_NONE, error = OTBR_ERROR_NOT_FOUND);
Copy link
Member

Choose a reason for hiding this comment

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

Can we consider it success if the joiner to be removed has already been removed? This will make the API idempotent.

}
else
{
VerifyOrExit(otCommissionerRemoveJoinerWithDiscerner(mInstance, &discerner) == OT_ERROR_NONE,
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

@@ -92,6 +92,24 @@ int Hex2Bytes(const char *aHex, uint8_t *aBytes, uint16_t aBytesLength)
return static_cast<int>(cur - aBytes);
}

size_t Uint2Hex(const uint64_t aUint, const uint8_t aUintLength, char *aHex)
Copy link
Member

@wgtdkp wgtdkp Oct 8, 2024

Choose a reason for hiding this comment

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

Can Long2Hex() in this file fulfill your requirements?

Copy link
Author

Choose a reason for hiding this comment

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

The issue with long2Hex is that the string in in little endian. I could write a string reversal if that would be preferable

Copy link
Member

Choose a reason for hiding this comment

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

Okay, it looks like Long2Hex is never used. What about reusing the method name but change the implementation to big-endian?

BTW, I think the implementation can be simplified for big-endian:

snprintf("%08X", aUint64);

Copy link
Author

@OmegaRelay OmegaRelay Oct 8, 2024

Choose a reason for hiding this comment

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

using snprint("%016x", aUint64) for direct conversion gives compiler warnings that %016lx must be used for unsigned long but this then breaks 32bit architecture compatibility where it needs to be %016llx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants