Commit 89656255 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen
Browse files

Add Update of Subscription to NF Instances

parent bef804bd
......@@ -37,7 +37,8 @@ void SubscriptionIDDocumentApiImpl::remove_subscription(
int http_code = 0;
ProblemDetails problem_details = {};
m_nrf_app->handle_remove_subscription(subscriptionID, http_code, 1, problem_details);
m_nrf_app->handle_remove_subscription(subscriptionID, http_code, 1,
problem_details);
nlohmann::json json_data = {};
std::string content_type = "application/json";
......@@ -59,9 +60,39 @@ void SubscriptionIDDocumentApiImpl::remove_subscription(
void SubscriptionIDDocumentApiImpl::update_subscription(
const std::string &subscriptionID, const std::vector<PatchItem> &patchItem,
Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
Logger::nrf_sbi().info(
"Got a request to update of subscription to NF instances, subscription "
"ID %s",
subscriptionID.c_str());
int http_code = 0;
ProblemDetails problem_details = {};
m_nrf_app->handle_update_subscription(subscriptionID, patchItem, http_code, 1,
problem_details);
// TODO: (section 5.2.2.5.6, Update of Subscription to NF Instances,
// 3GPP TS 29.510 V16.0.0 (2019-06)) if the NRF accepts the extension
// of the lifetime of the subscription, but it assigns a validity time
// different than the value suggested by the NF Service Consumer, a
// "200 OK" response code shall be returned
nlohmann::json json_data = {};
std::string content_type = "application/json";
if (http_code != HTTP_STATUS_CODE_204_NO_CONTENT) {
to_json(json_data, problem_details);
content_type = "application/problem+json";
// content type
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType(content_type));
response.send(Pistache::Http::Code(http_code), json_data.dump().c_str());
} else {
// content type
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType(content_type));
response.send(Pistache::Http::Code(http_code));
}
}
} // namespace api
} // namespace nrf
} // namespace oai
......@@ -383,6 +383,85 @@ void nrf_app::handle_remove_subscription(const std::string &sub_id,
protocol_application_error_e2str[SUBSCRIPTION_NOT_FOUND]);
}
}
//------------------------------------------------------------------------------
void nrf_app::handle_update_subscription(
const std::string &sub_id, const std::vector<PatchItem> &patchItem,
int &http_code, const uint8_t http_version,
ProblemDetails &problem_details) {
Logger::nrf_app().info(
"Handle an Update of subscription to NF Instance (HTTP version %d)",
http_version);
// Find the existing subscription
std::shared_ptr<nrf_subscription> ss = {};
ss = find_subscription(sub_id);
bool op_success = false;
if (ss.get() != nullptr) {
// patchItem should contain only 1 element
for (auto p : patchItem) {
patch_op_type_t op = api_conv::string_to_patch_operation(p.getOp());
// Verify Path
if ((p.getPath().substr(0, 1).compare("/") != 0) or
(p.getPath().length() < 2)) {
Logger::nrf_app().warn("Bad value for operation path: %s ",
p.getPath().c_str());
http_code = HTTP_STATUS_CODE_400_BAD_REQUEST;
problem_details.setCause(
protocol_application_error_e2str[MANDATORY_IE_INCORRECT]);
return;
}
std::string path = p.getPath().substr(1);
switch (op) {
case PATCH_OP_REPLACE: {
if (path.compare("validityTime") == 0) {
try {
// TODO: (section 5.2.2.5.6, Update of Subscription to NF
// Instances, 3GPP TS 29.510 V16.0.0 (2019-06)) if the NRF accepts
// the extension of the lifetime of the subscription, but it
// assigns a validity time different than the value suggested by
// the NF Service Consumer, a "200 OK" response code shall be
// returned
boost::posix_time::ptime pt(
boost::posix_time::from_iso_string(p.getValue()));
ss.get()->set_validity_time(pt);
Logger::nrf_app().debug("New validity time: %s",
p.getValue().c_str());
Logger::nrf_app().debug("Updated a subscription to the DB");
// display the info
ss.get()->display();
http_code = HTTP_STATUS_CODE_204_NO_CONTENT;
op_success = true;
} catch (std::exception &e) {
std::cout << " Exception: " << e.what() << std::endl;
}
}
} break;
default: {
Logger::nrf_app().warn("Requested operation is not valid!");
}
}
if (!op_success) {
http_code = HTTP_STATUS_CODE_400_BAD_REQUEST;
problem_details.setCause(
protocol_application_error_e2str[MANDATORY_IE_INCORRECT]);
}
}
} else {
Logger::nrf_app().debug("Subscription with ID %s does not exit",
sub_id.c_str());
http_code = HTTP_STATUS_CODE_404_NOT_FOUND;
problem_details.setCause(
protocol_application_error_e2str[SUBSCRIPTION_NOT_FOUND]);
}
}
//------------------------------------------------------------------------------
bool nrf_app::add_nf_profile(const std::string &profile_id,
const std::shared_ptr<nrf_profile> &p) {
......@@ -547,6 +626,20 @@ bool nrf_app::remove_subscription(const std::string &sub_id) {
}
}
//------------------------------------------------------------------------------
std::shared_ptr<nrf_subscription> nrf_app::find_subscription(
const std::string &sub_id) const {
// Logger::nrf_app().info("Find a subscription with ID %s", sub_id.c_str());
std::shared_lock lock(m_instance_id2nrf_subscription);
if (instance_id2nrf_subscription.count(sub_id) > 0) {
return instance_id2nrf_subscription.at(sub_id);
} else {
Logger::nrf_app().info("Subscription (ID %s) not found", sub_id.c_str());
return nullptr;
}
}
//------------------------------------------------------------------------------
void nrf_app::subscribe_task_tick(uint64_t ms) {
struct itimerspec its;
......
......@@ -151,6 +151,22 @@ class nrf_app {
void handle_remove_subscription(const std::string &sub_id, int &http_code,
const uint8_t http_version,
ProblemDetails &problem_details);
/*
* Handle a Update of Subscription to NF Instances
* @param [const std::string &] sub_id: Subscription ID
* @param [const std::vector<PatchItem> &] patchItem: List of modifications
* need to be applied
* @param [int &] http_code: HTTP code used to return to the consumer
* @param [const uint8_t] http_version: HTTP version
* @param [ProblemDetails &] problem_details: Store details of the error
* @return void
*/
void handle_update_subscription(const std::string &sub_id,
const std::vector<PatchItem> &patchItem,
int &http_code, const uint8_t http_version,
ProblemDetails &problem_details);
/*
* Insert a nrf profile
* @param [const std::string &] profile_id: Profile ID
......@@ -232,6 +248,15 @@ class nrf_app {
* @return true if successful, otherwise, return false
*/
bool remove_subscription(const std::string &sub_id);
/*
* Find a subscription with its ID
* @param [const std::string &] sub_id: Subscription ID
* @return shared pointer to the subscription if found, otherwise nullptr
*/
std::shared_ptr<nrf_subscription> find_subscription(
const std::string &sub_id) const;
/*
* Subscribe to the task tick event
* @param [uint64_t &] ms: Current time in ms
......
......@@ -7,6 +7,9 @@ curl -X POST http://192.168.1.23/nnrf-nfm/v1/subscriptions -d '{"nfStatusNotific
curl -X POST http://192.168.1.23/nnrf-nfm/v1/subscriptions -d '{"nfStatusNotificationUri":"http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d", "subscrCond": {"NfInstanceIdCond": {"nfInstanceId":"AMF"} } }'
curl -X POST http://192.168.1.23/nnrf-nfm/v1/subscriptions -d '{"nfStatusNotificationUri":"http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d", "subscrCond": {"NfTypeCond": {"nfType":"AMF"} } }'
curl -X POST -H "Content-Type: application/json" "http://192.168.1.23/nnrf-nfm/v1/subscriptions" -d '{"nfStatusNotificationUri":"http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d", "subscrCond": {"NfTypeCond": {"nfType":"AMF"}}, "reqNotifEvents":["NF_REGISTERED", "NF_DEREGISTERED"], "validityTime":"20020131T235959" }'
\ No newline at end of file
curl -X POST -H "Content-Type: application/json" "http://192.168.1.23/nnrf-nfm/v1/subscriptions" -d '{"nfStatusNotificationUri":"http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d", "subscrCond": {"NfTypeCond": {"nfType":"AMF"}}, "reqNotifEvents":["NF_REGISTERED", "NF_DEREGISTERED"], "validityTime":"20020131T235959" }'
curl -X PATCH -H "Content-Type: application/json" http://192.168.1.23/nnrf-nfm/v1/subscriptions/1 -d '[{"op":"replace","path":"/validityTime", "value": "20201231T235959"}]'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment