Skip to content

Commit

Permalink
[rest] added endpoint for getting mleid ip address
Browse files Browse the repository at this point in the history
  • Loading branch information
OmegaRelay committed Mar 11, 2025
1 parent 861d722 commit 1a202a4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/rest/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,21 @@ paths:
type: string
description: Coprocessor version string
example: "OPENTHREAD/thread-reference-20200818-1740-g33cc75ed3; NRF52840; Jun 2 2022 14:25:49"
/node/ip-address/mleid:
get:
tags:
- node
summary: Get the MLEID ip address
description: Retrieves the border router mesh-local EID IP address.
responses:
"200":
description: Successful operation.
content:
application/json:
schema:
type: string
description: mleid ip address
example: "fd06:1488:f31:d0f9:f4f4:3594:e17c:4882"

components:
schemas:
Expand Down
31 changes: 31 additions & 0 deletions src/rest/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
#define OT_REST_RESOURCE_PATH_NETWORK_CURRENT "/networks/current"
#define OT_REST_RESOURCE_PATH_NETWORK_CURRENT_COMMISSION "/networks/commission"
#define OT_REST_RESOURCE_PATH_NETWORK_CURRENT_PREFIX "/networks/current/prefix"
#define OT_REST_RESOURCE_PATH_NODE_IPADDRESS "/node/ip-address"
#define OT_REST_RESOURCE_PATH_NODE_IPADDRESS_MLEID "/node/ip-address/mleid"

#define OT_REST_HTTP_STATUS_200 "200 OK"
#define OT_REST_HTTP_STATUS_201 "201 Created"
Expand Down Expand Up @@ -148,6 +150,7 @@ Resource::Resource(RcpHost *aHost)
mResourceMap.emplace(OT_REST_RESOURCE_PATH_NODE_RLOC, &Resource::Rloc);
mResourceMap.emplace(OT_REST_RESOURCE_PATH_NODE_DATASET_ACTIVE, &Resource::DatasetActive);
mResourceMap.emplace(OT_REST_RESOURCE_PATH_NODE_DATASET_PENDING, &Resource::DatasetPending);
mResourceMap.emplace(OT_REST_RESOURCE_PATH_NODE_IPADDRESS_MLEID, &Resource::IpAddrMleid);
mResourceMap.emplace(OT_REST_RESOURCE_PATH_NODE_COMMISSIONER_STATE, &Resource::CommissionerState);
mResourceMap.emplace(OT_REST_RESOURCE_PATH_NODE_COMMISSIONER_JOINER, &Resource::CommissionerJoiner);
mResourceMap.emplace(OT_REST_RESOURCE_PATH_NODE_COPROCESSOR_VERSION, &Resource::CoprocessorVersion);
Expand Down Expand Up @@ -1086,6 +1089,34 @@ void Resource::CoprocessorVersion(const Request &aRequest, Response &aResponse)
}
}

void Resource::GetIpAddrMleid(Response &aResponse) const
{
std::string errorCode;
std::string mleidJsonString;
const otIp6Address *mleid;

mleid = otThreadGetMeshLocalEid(mInstance);

mleidJsonString = Json::IpAddr2JsonString(*mleid);
aResponse.SetBody(mleidJsonString);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
}

void Resource::IpAddrMleid(const Request &aRequest, Response &aResponse) const
{
std::string errorCode;

if (aRequest.GetMethod() == HttpMethod::kGet)
{
GetIpAddrMleid(aResponse);
}
else
{
ErrorHandler(aResponse, HttpStatusCode::kStatusMethodNotAllowed);
}
}

void Resource::DeleteOutDatedDiagnostic(void)
{
auto eraseIt = mDiagSet.begin();
Expand Down
2 changes: 2 additions & 0 deletions src/rest/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class Resource
void Diagnostic(const Request &aRequest, Response &aResponse) const;
void HandleDiagnosticCallback(const Request &aRequest, Response &aResponse);
void CoprocessorVersion(const Request &aRequest, Response &aResponse) const;
void IpAddrMleid(const Request &aRequest, Response &aResponse) const;

void GetNodeInfo(Response &aResponse) const;
void DeleteNodeInfo(Response &aResponse) const;
Expand All @@ -151,6 +152,7 @@ class Resource
void AddJoiner(const Request &aRequest, Response &aResponse) const;
void RemoveJoiner(const Request &aRequest, Response &aResponse) const;
void GetCoprocessorVersion(Response &aResponse) const;
void GetIpAddrMleid(Response &aResponse) const;

void DeleteOutDatedDiagnostic(void);
void UpdateDiag(std::string aKey, std::vector<otNetworkDiagTlv> &aDiag);
Expand Down

0 comments on commit 1a202a4

Please sign in to comment.