Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/rest/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,19 @@ paths:
description: Invalid request body.
"500":
$ref: "#/components/responses/InternalServerError"
delete:
tags:
- node
summary: Delete the pending operational dataset
description: |-
Clears the pending operational dataset, canceling any scheduled network
configuration changes (e.g. a pending channel migration) before they
take effect.
responses:
"200":
description: Successfully deleted the pending operational dataset.
"500":
$ref: "#/components/responses/InternalServerError"
/node/commissioner/state:
get:
tags:
Expand Down
33 changes: 33 additions & 0 deletions src/rest/rest_web_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ RestWebServer::RestWebServer(Host::RcpHost &aHost)
mServer.Options(OT_REST_RESOURCE_PATH_NODE_DATASET_ACTIVE, MakeHandler(&RestWebServer::DatasetActive));
mServer.Get(OT_REST_RESOURCE_PATH_NODE_DATASET_PENDING, MakeHandler(&RestWebServer::DatasetPending));
mServer.Put(OT_REST_RESOURCE_PATH_NODE_DATASET_PENDING, MakeHandler(&RestWebServer::DatasetPending));
mServer.Delete(OT_REST_RESOURCE_PATH_NODE_DATASET_PENDING, MakeHandler(&RestWebServer::DatasetPending));
mServer.Options(OT_REST_RESOURCE_PATH_NODE_DATASET_PENDING, MakeHandler(&RestWebServer::DatasetPending));
mServer.Get(OT_REST_RESOURCE_PATH_NODE_COMMISSIONER_STATE, MakeHandler(&RestWebServer::CommissionerState));
mServer.Put(OT_REST_RESOURCE_PATH_NODE_COMMISSIONER_STATE, MakeHandler(&RestWebServer::CommissionerState));
Expand Down Expand Up @@ -756,6 +757,28 @@ void RestWebServer::SetDataset(DatasetType aDatasetType, const Request &aRequest
}
}

void RestWebServer::DeletePendingDataset(Response &aResponse) const
{
otbrError error = OTBR_ERROR_NONE;

SuccessOrExit(error = RunInMainLoop([this]() {
otOperationalDatasetTlvs datasetTlvs;

datasetTlvs.mLength = 0;
VerifyOrReturn(otDatasetSetPendingTlvs(GetInstance(), &datasetTlvs) == OT_ERROR_NONE,
OTBR_ERROR_REST);
return OTBR_ERROR_NONE;
}));

aResponse.status = StatusCode::OK_200;

exit:
if (error != OTBR_ERROR_NONE)
{
ErrorHandler(aResponse, StatusCode::InternalServerError_500);
}
}

void RestWebServer::Dataset(DatasetType aDatasetType, const Request &aRequest, Response &aResponse) const
{
switch (GetMethod(aRequest))
Expand All @@ -766,6 +789,16 @@ void RestWebServer::Dataset(DatasetType aDatasetType, const Request &aRequest, R
case HttpMethod::kPut:
SetDataset(aDatasetType, aRequest, aResponse);
break;
case HttpMethod::kDelete:
if (aDatasetType == DatasetType::kPending)
{
DeletePendingDataset(aResponse);
}
else
{
ErrorHandler(aResponse, StatusCode::MethodNotAllowed_405);
}
break;
case HttpMethod::kOptions:
aResponse.status = StatusCode::OK_200;
break;
Expand Down
1 change: 1 addition & 0 deletions src/rest/rest_web_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class RestWebServer : public std::enable_shared_from_this<RestWebServer>
void GetDataRloc(Response &aResponse) const;
void GetDataset(DatasetType aDatasetType, const Request &aRequest, Response &aResponse) const;
void SetDataset(DatasetType aDatasetType, const Request &aRequest, Response &aResponse) const;
void DeletePendingDataset(Response &aResponse) const;
void GetCommissionerState(Response &aResponse) const;
void SetCommissionerState(const Request &aRequest, Response &aResponse) const;
void GetJoiners(Response &aResponse) const;
Expand Down
Loading