Skip to content

Commit 31e9155

Browse files
committed
[rest] added endpoint for getting mleid ip address
1 parent 7d4282b commit 31e9155

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/rest/openapi.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,21 @@ paths:
404404
type: string
405405
description: Coprocessor version string
406406
example: "OPENTHREAD/thread-reference-20200818-1740-g33cc75ed3; NRF52840; Jun 2 2022 14:25:49"
407+
/node/ip-address/mleid:
408+
get:
409+
tags:
410+
- node
411+
summary: Get the MLEID ip address
412+
description: Retrieves the border router mesh-local EID IP address.
413+
responses:
414+
"200":
415+
description: Successful operation.
416+
content:
417+
application/json:
418+
schema:
419+
type: string
420+
description: mleid ip address
421+
example: "fd06:1488:f31:d0f9:f4f4:3594:e17c:4882"
407422

408423
components:
409424
schemas:

src/rest/resource.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
#define OT_REST_RESOURCE_PATH_NETWORK_CURRENT "/networks/current"
5656
#define OT_REST_RESOURCE_PATH_NETWORK_CURRENT_COMMISSION "/networks/commission"
5757
#define OT_REST_RESOURCE_PATH_NETWORK_CURRENT_PREFIX "/networks/current/prefix"
58+
#define OT_REST_RESOURCE_PATH_NODE_IPADDRESS "/node/ip-address"
59+
#define OT_REST_RESOURCE_PATH_NODE_IPADDRESS_MLEID "/node/ip-address/mleid"
5860

5961
#define OT_REST_HTTP_STATUS_200 "200 OK"
6062
#define OT_REST_HTTP_STATUS_201 "201 Created"
@@ -148,6 +150,7 @@ Resource::Resource(RcpHost *aHost)
148150
mResourceMap.emplace(OT_REST_RESOURCE_PATH_NODE_RLOC, &Resource::Rloc);
149151
mResourceMap.emplace(OT_REST_RESOURCE_PATH_NODE_DATASET_ACTIVE, &Resource::DatasetActive);
150152
mResourceMap.emplace(OT_REST_RESOURCE_PATH_NODE_DATASET_PENDING, &Resource::DatasetPending);
153+
mResourceMap.emplace(OT_REST_RESOURCE_PATH_NODE_IPADDRESS_MLEID, &Resource::IpAddrMleid);
151154
mResourceMap.emplace(OT_REST_RESOURCE_PATH_NODE_COMMISSIONER_STATE, &Resource::CommissionerState);
152155
mResourceMap.emplace(OT_REST_RESOURCE_PATH_NODE_COMMISSIONER_JOINER, &Resource::CommissionerJoiner);
153156
mResourceMap.emplace(OT_REST_RESOURCE_PATH_NODE_COPROCESSOR_VERSION, &Resource::CoprocessorVersion);
@@ -1086,6 +1089,34 @@ void Resource::CoprocessorVersion(const Request &aRequest, Response &aResponse)
10861089
}
10871090
}
10881091

1092+
void Resource::GetIpAddrMleid(Response &aResponse) const
1093+
{
1094+
std::string errorCode;
1095+
std::string mleidJsonString;
1096+
const otIp6Address *mleid;
1097+
1098+
mleid = otThreadGetMeshLocalEid(mInstance);
1099+
1100+
mleidJsonString = Json::IpAddr2JsonString(*mleid);
1101+
aResponse.SetBody(mleidJsonString);
1102+
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
1103+
aResponse.SetResponsCode(errorCode);
1104+
}
1105+
1106+
void Resource::IpAddrMleid(const Request &aRequest, Response &aResponse) const
1107+
{
1108+
std::string errorCode;
1109+
1110+
if (aRequest.GetMethod() == HttpMethod::kGet)
1111+
{
1112+
GetIpAddrMleid(aResponse);
1113+
}
1114+
else
1115+
{
1116+
ErrorHandler(aResponse, HttpStatusCode::kStatusMethodNotAllowed);
1117+
}
1118+
}
1119+
10891120
void Resource::DeleteOutDatedDiagnostic(void)
10901121
{
10911122
auto eraseIt = mDiagSet.begin();

src/rest/resource.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class Resource
130130
void Diagnostic(const Request &aRequest, Response &aResponse) const;
131131
void HandleDiagnosticCallback(const Request &aRequest, Response &aResponse);
132132
void CoprocessorVersion(const Request &aRequest, Response &aResponse) const;
133+
void IpAddrMleid(const Request &aRequest, Response &aResponse) const;
133134

134135
void GetNodeInfo(Response &aResponse) const;
135136
void DeleteNodeInfo(Response &aResponse) const;
@@ -151,6 +152,7 @@ class Resource
151152
void AddJoiner(const Request &aRequest, Response &aResponse) const;
152153
void RemoveJoiner(const Request &aRequest, Response &aResponse) const;
153154
void GetCoprocessorVersion(Response &aResponse) const;
155+
void GetIpAddrMleid(Response &aResponse) const;
154156

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

0 commit comments

Comments
 (0)