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

Finish NFRegister operation

parent 7d9ce68b
......@@ -14,6 +14,8 @@
#include "logger.hpp"
#include "nrf_app.hpp"
#include "nrf_config.hpp"
#include "ProblemDetails.h"
#include "3gpp_29.500.h"
extern oai::nrf::app::nrf_config nrf_cfg;
......@@ -52,10 +54,25 @@ void NFInstanceIDDocumentApiImpl::register_nf_instance(
NFProfile nf_profile = nFProfile;
int http_code = 0;
m_nrf_app->handle_register_nf_instance(nfInstanceID, nFProfile, http_code, 1);
ProblemDetails problem_details = { };
m_nrf_app->handle_register_nf_instance(nfInstanceID, nFProfile, http_code, 1,
problem_details);
nlohmann::json json_data = { };
to_json(json_data, nf_profile);
std::string content_type = "application/json";
if ((http_code != HTTP_STATUS_CODE_200_OK)
and (http_code != HTTP_STATUS_CODE_201_CREATED)
and (http_code != HTTP_STATUS_CODE_202_ACCEPTED)) {
to_json(json_data, problem_details);
content_type = "application/problem+json";
} else {
to_json(json_data, nf_profile);
}
//content type
response.headers().add < Pistache::Http::Header::ContentType
> (Pistache::Http::Mime::MediaType(content_type));
//Location header
response.headers().add < Pistache::Http::Header::Location
> (m_address + base + nrf_cfg.sbi_api_version + "/nf-instances/"
......
......@@ -53,5 +53,38 @@ enum http_status_code_e {
HTTP_STATUS_CODE_504_GATEWAY_TIMEOUT = 504
};
enum protocol_application_error_e {
INVALID_API = 0, //400 Bad Request
INVALID_MSG_FORMAT = 1, //400 Bad Request
INVALID_QUERY_PARAM = 2, //400 Bad Request
MANDATORY_QUERY_PARAM_INCORRECT = 3, //400 Bad Request
OPTIONAL_QUERY_PARAM_INCORRECT = 4, //400 Bad Request
MANDATORY_QUERY_PARAM_MISSING = 5, //400 Bad Request
MANDATORY_IE_INCORRECT = 6, //400 Bad Request
OPTIONAL_IE_INCORRECT = 7, //400 Bad Request
MANDATORY_IE_MISSING = 8, //400 Bad Request
UNSPECIFIED_MSG_FAILURE = 9, //400 Bad Request
MODIFICATION_NOT_ALLOWED = 10, //403 Forbidden
SUBSCRIPTION_NOT_FOUND = 11, //404 Not Found
RESOURCE_URI_STRUCTURE_NOT_FOUND = 12, //404 Not Found
INCORRECT_LENGTH = 13, //411 Length Required
NF_CONGESTION_RISK = 14, //429 Too Many Requests
INSUFFICIENT_RESOURCES = 15, //500 Internal Server Error
UNSPECIFIED_NF_FAILURE = 16, //500 Internal Server Error
SYSTEM_FAILURE = 17, //500 Internal Server Error
NF_CONGESTION = 18, //503 Service Unavailable
};
static const std::vector<std::string> protocol_application_error_e2str {
"INVALID_API", "INVALID_MSG_FORMAT", "INVALID_QUERY_PARAM",
"MANDATORY_QUERY_PARAM_INCORRECT", "OPTIONAL_QUERY_PARAM_INCORRECT",
"MANDATORY_QUERY_PARAM_MISSING", "MANDATORY_IE_INCORRECT",
"OPTIONAL_IE_INCORRECT", "MANDATORY_IE_MISSING", "UNSPECIFIED_MSG_FAILURE",
"MODIFICATION_NOT_ALLOWED", "SUBSCRIPTION_NOT_FOUND",
"RESOURCE_URI_STRUCTURE_NOT_FOUND", "INCORRECT_LENGTH ",
"NF_CONGESTION_RISK", "INSUFFICIENT_RESOURCES", "UNSPECIFIED_NF_FAILURE",
"SYSTEM_FAILURE", "NF_CONGESTION" };
#endif
......@@ -32,11 +32,12 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <regex>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include "AmfInfo.h"
#include "AmfInfo.h"
#include "api_conversions.hpp"
#include "logger.hpp"
#include "nrf.h"
......@@ -205,3 +206,10 @@ patch_op_type_t api_conv::string_to_patch_operation(const std::string &str) {
//default
return PATCH_OP_UNKNOWN;
}
bool api_conv::validate_uuid(const std::string &str) {
//should be verified with Capital letter
static const std::regex e("[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}");
return regex_match(str, e);
}
......@@ -64,6 +64,9 @@ nf_type_t string_to_nf_type(const std::string &str);
*/
patch_op_type_t string_to_patch_operation(const std::string &str);
bool validate_uuid(const std::string &str);
} // namespace api_conv
}
}
......
......@@ -50,10 +50,19 @@ nrf_app::nrf_app(const std::string &config_file) {
void nrf_app::handle_register_nf_instance(
const std::string &nf_instance_id,
const oai::nrf::model::NFProfile &nf_profile, int &http_code,
const uint8_t http_version) {
const uint8_t http_version, oai::nrf::model::ProblemDetails &problem_details) {
Logger::nrf_app().info("Handle NF Instance Registration (HTTP version %d)",
http_version);
if (!api_conv::validate_uuid(nf_instance_id)) {
http_code = HTTP_STATUS_CODE_400_BAD_REQUEST;
Logger::nrf_app().debug("Bad UUID format for NF Instance ID (%s)",
nf_instance_id.c_str());
problem_details.setCause(
protocol_application_error_e2str[MANDATORY_QUERY_PARAM_INCORRECT]);
return;
}
//Check if nfInstanceID is a valid UUID (version 4)
//TODO
......@@ -166,7 +175,7 @@ void nrf_app::handle_get_nf_instances(const std::string &nf_type,
find_nf_profiles(type, profiles);
if (profiles.size() == 0) {
Logger::nrf_app().debug("No profile found with type %s", nf_type.c_str());
Logger::nrf_app().debug("No profile found (NF type: %s)", nf_type.c_str());
}
for (auto profile : profiles) {
......
......@@ -34,6 +34,7 @@
#include "NFProfile.h"
#include "nrf_profile.hpp"
#include "PatchItem.h"
#include "ProblemDetails.h"
namespace oai {
namespace nrf {
......@@ -56,9 +57,11 @@ class nrf_app {
* @param [const uint8_t] http_version: HTTP version
* @return void
*/
void handle_register_nf_instance(const std::string &nf_instance_id,
const oai::nrf::model::NFProfile &nf_profile,
int &http_code, const uint8_t http_version);
void handle_register_nf_instance(
const std::string &nf_instance_id,
const oai::nrf::model::NFProfile &nf_profile, int &http_code,
const uint8_t http_version,
oai::nrf::model::ProblemDetails &problem_details);
/*
* Handle a Get NF Instance Information
......
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