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

Update NFRegister operation

parent 5c5a381f
......@@ -12,7 +12,7 @@ NRF_CONF[@INSTANCE@]=$INSTANCE
NRF_CONF[@PREFIX@]=$PREFIX
NRF_CONF[@PID_DIRECTORY@]='/var/run'
NRF_CONF[@NRF_INTERFACE_NAME_FOR_SBI@]='wlp2s0'
NRF_CONF[@NRF_INTERFACE_NAME_FOR_SBI@]='enx0050b6f4b8f0'
NRF_CONF[@NRF_INTERFACE_PORT_FOR_SBI@]='80'
NRF_CONF[@NRF_INTERFACE_HTTP2_PORT_FOR_SBI@]='9090'
......
/**
* NRF NFManagement Service
* NRF NFManagement Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
* NRF NFManagement Service
* NRF NFManagement Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "NFInstanceIDDocumentApiImpl.h"
#include "logger.hpp"
......@@ -22,32 +22,54 @@ using namespace oai::nrf::model;
using namespace oai::nrf::app;
using namespace oai::nrf;
NFInstanceIDDocumentApiImpl::NFInstanceIDDocumentApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr,
nrf_app *nrf_app_inst,
std::string address)
: NFInstanceIDDocumentApi(rtr), m_nrf_app(nrf_app_inst),
m_address(address)
{ }
NFInstanceIDDocumentApiImpl::NFInstanceIDDocumentApiImpl(
std::shared_ptr<Pistache::Rest::Router> rtr, nrf_app *nrf_app_inst,
std::string address) :
NFInstanceIDDocumentApi(rtr), m_nrf_app(nrf_app_inst), m_address(
address) {
}
void NFInstanceIDDocumentApiImpl::deregister_nf_instance(const std::string &nfInstanceID, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
void NFInstanceIDDocumentApiImpl::deregister_nf_instance(
const std::string &nfInstanceID,
Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void NFInstanceIDDocumentApiImpl::get_nf_instance(const std::string &nfInstanceID, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
void NFInstanceIDDocumentApiImpl::get_nf_instance(
const std::string &nfInstanceID,
Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void NFInstanceIDDocumentApiImpl::register_nf_instance(const std::string &nfInstanceID, const NFProfile &nFProfile, const Pistache::Optional<Pistache::Http::Header::Raw> &contentEncoding, Pistache::Http::ResponseWriter &response) {
Logger::nrf_sbi().info("Got a request to register an NF instance, Instance ID: %s", nfInstanceID.c_str());
void NFInstanceIDDocumentApiImpl::register_nf_instance(
const std::string &nfInstanceID, const NFProfile &nFProfile,
const Pistache::Optional<Pistache::Http::Header::Raw> &contentEncoding,
Pistache::Http::ResponseWriter &response) {
Logger::nrf_sbi().info(
"Got a request to register an NF instance, Instance ID: %s",
nfInstanceID.c_str());
NFProfile nf_profile = nFProfile;
int http_code = 0;
m_nrf_app->handle_nf_instance_registration_request(nfInstanceID, nFProfile, http_code, 1);
NFProfile nf_profile = nFProfile;
int http_code = 0;
m_nrf_app->handle_register_nf_instance(nfInstanceID, nFProfile,
http_code, 1);
nlohmann::json json_data = { };
to_json(json_data, nf_profile);
response.send(Pistache::Http::Code::Ok, json_data.dump().c_str());
nlohmann::json json_data = { };
to_json(json_data, nf_profile);
response.send(Pistache::Http::Code::Ok, json_data.dump().c_str());
}
void NFInstanceIDDocumentApiImpl::update_nf_instance(const std::string &nfInstanceID, const std::vector<PatchItem> &patchItem, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
void NFInstanceIDDocumentApiImpl::update_nf_instance(
const std::string &nfInstanceID,
const std::vector<PatchItem> &patchItem,
Pistache::Http::ResponseWriter &response) {
Logger::nrf_sbi().info(
"Got a request to register an NF instance, Instance ID: %s",
nfInstanceID.c_str());
int http_code = 0;
m_nrf_app->handle_update_nf_instance(nfInstanceID, patchItem, http_code, 1);
nlohmann::json json_data = { };
//to_json(json_data, nf_profile);
response.send(Pistache::Http::Code::Ok, json_data.dump().c_str());
}
}
......
......@@ -46,8 +46,7 @@ nrf_app::nrf_app(const std::string &config_file) {
}
//------------------------------------------------------------------------------
void nrf_app::handle_nf_instance_registration_request(
const std::string &nf_instance_id,
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) {
......@@ -58,34 +57,100 @@ void nrf_app::handle_nf_instance_registration_request(
//TODO
//Create NF and store
//std::shared_ptr<nrf_profile> sn = { };
//sn = find_nf_profile(nf_instance_id);
//if (sn.get() != nullptr) {
if (is_profile_exist(nf_instance_id)) {
/*
std::shared_ptr<nrf_profile> sn = { };
sn = find_nf_profile(nf_instance_id);
if (sn.get() != nullptr) {
if (sn.get()->get_nf_type() == NF_TYPE_AMF) {
std::shared_ptr<amf_profile> sa = std::static_pointer_cast
< amf_profile > (sn);
if (!api_conv::profile_api_to_amf_profile(nf_profile, sa)) {
//error, TODO
Logger::nrf_app().warn(
"Cannot convert a NF profile generated from OpenAPI to an AMF profile (profile ID %s)",
nf_instance_id.c_str());
}
update_nf_profile(nf_instance_id, sa);
}
//if (is_profile_exist(nf_instance_id)) {
//if (find_nf_profile(nf_instance_id, sn)) {
//if a profile exist with this ID, return error
//sa = std::static_pointer_cast <amf_profile> (sn);
//update_nf_profile(nf_instance_id, sa);
} else {
//create a new NF profile
Logger::nrf_app().debug("NF Profile with (ID %s, NF type %s)",
nf_instance_id.c_str(), nf_profile.getNfType().c_str());
std::shared_ptr<amf_profile> sa = { };
if (nf_profile.getNfType().compare("AMF") == 0) {
sa = std::shared_ptr < amf_profile
> (new amf_profile(nf_instance_id));
if (!api_conv::profile_api_to_amf_profile(nf_profile, sa)) {
//error, TODO
}
}
add_nf_profile(nf_instance_id, sa);
}
*/
//create/Update NF profile
Logger::nrf_app().debug("NF Profile with (ID %s, NF type %s)",
nf_instance_id.c_str(), nf_profile.getNfType().c_str());
if (nf_profile.getNfType().compare("AMF") == 0) {
std::shared_ptr<amf_profile> sa = { };
sa = std::shared_ptr < amf_profile > (new amf_profile(nf_instance_id));
if (!api_conv::profile_api_to_amf_profile(nf_profile, sa)) {
//error, TODO
Logger::nrf_app().warn(
"Cannot convert a NF profile generated from OpenAPI to an AMF profile (profile ID %s)",
nf_instance_id.c_str());
http_code = 412; //Precondition Failed
} else {
add_nf_profile(nf_instance_id, sa);
http_code = 200;
}
}
//location header - URI of created resource: can be used with ID - UUID
}
void nrf_app::handle_update_nf_instance(const std::string &nf_instance_id,
const std::vector<PatchItem> &patchItem, int &http_code,
const uint8_t http_version) {
Logger::nrf_app().info(
"Handle Update NF Instance request (HTTP version %d)",
http_version);
//Find the profile corresponding to the instance ID
std::shared_ptr<nrf_profile> sn = { };
sn = find_nf_profile(nf_instance_id);
if (sn.get() != nullptr) {
//if (find_nf_profile(nf_instance_id, sn)) {
//if a profile exist with this ID, return error
//sa = std::static_pointer_cast <amf_profile> (sn);
//update_nf_profile(nf_instance_id, sa);
} else {
//create a new NF profile
Logger::nrf_app().debug("NF Profile with (ID %s, NF type %s)",
nf_instance_id.c_str(), nf_profile.getNfType().c_str());
std::shared_ptr<amf_profile> sa = { };
if (nf_profile.getNfType().compare("AMF") == 0) {
sa = std::shared_ptr < amf_profile
> (new amf_profile(nf_instance_id));
if (!api_conv::profile_api_to_amf_profile(nf_profile, sa)) {
//error, TODO
}
//std::shared_ptr<amf_profile> sa = { };
if (sn.get()->get_nf_type() == NF_TYPE_AMF) {
std::shared_ptr<amf_profile> sa = std::static_pointer_cast
< amf_profile > (sn);
update_nf_profile(nf_instance_id, sa);
}
add_nf_profile(nf_instance_id, sa);
//add_nf_profile(nf_instance_id, sa);
} else {
Logger::nrf_app().debug("NF Profile with ID %s does not exit",
nf_instance_id.c_str());
}
//location header - URI of created resource: can be used with ID - UUID
}
//------------------------------------------------------------------------------
void nrf_app::handle_get_nf_instances(const std::string &nf_type,
const uint32_t limit_item, int &http_code, const uint8_t http_version) {
......@@ -94,11 +159,9 @@ void nrf_app::handle_get_nf_instances(const std::string &nf_type,
http_version);
std::vector < std::shared_ptr < nrf_profile >> profiles = { };
find_nf_profiles(nf_type, profiles);
for (auto profile : profiles) {
Logger::nrf_app().debug("AMF profile, instance name %s",
profile.get()->get_nf_instance_name().c_str());
Logger::nrf_app().debug("AMF profile, status %s",
......@@ -130,13 +193,22 @@ void nrf_app::handle_get_nf_instances(const std::string &nf_type,
bool nrf_app::add_nf_profile(const std::string &profile_id,
const std::shared_ptr<nrf_profile> &p) {
std::unique_lock lock(m_instance_id2nrf_profile);
//if profile with this id exist, return false
if (instance_id2nrf_profile.count(profile_id) > 0)
return false;
//if not, add to the list
Logger::nrf_app().info("Insert a NF profile to the list (profile ID %s)",
profile_id.c_str());
instance_id2nrf_profile.emplace(profile_id, p);
/*
//if profile with this id exist, update
if (instance_id2nrf_profile.count(profile_id) > 0) {
Logger::nrf_app().info(
"Update a NF profile to the list (profile ID %s)",
profile_id.c_str());
instance_id2nrf_profile.at(profile_id) = p;
} else {
//if not, add to the list
Logger::nrf_app().info(
"Insert a NF profile to the list (profile ID %s)",
profile_id.c_str());
instance_id2nrf_profile.emplace(profile_id, p);
}*/
//Create or update if profile exist
instance_id2nrf_profile[profile_id] = p;
return true;
}
......
......@@ -33,10 +33,13 @@
#include <string>
#include "NFProfile.h"
#include "nrf_profile.hpp"
#include "PatchItem.h"
namespace oai {
namespace nrf {
namespace app {
using namespace oai::nrf::model;
class nrf_config;
class nrf_app {
......@@ -45,7 +48,7 @@ public:
nrf_app(nrf_app const&) = delete;
void operator=(nrf_app const&) = delete;
void handle_nf_instance_registration_request(
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);
......@@ -53,6 +56,8 @@ public:
void handle_get_nf_instances(const std::string &nf_type,
const uint32_t limit_item, int &http_code,
const uint8_t http_version);
void handle_update_nf_instance(const std::string & nf_instance_id,const std::vector<PatchItem> &patchItem, int &http_code, const uint8_t http_version);
/*
* Insert a nrf profile
* @param [const std::string &] profile_id: Profile ID
......
......@@ -3,7 +3,7 @@
"nfInstanceId" : "343a924e-6494-4927-860b-d45692c95c2d",
"nfType" : "AMF",
"nfStatus" : "REGISTERED",
"nfInstanceName": "OAI-AMF",
"nfInstanceName": "OAI-AMF-NEW",
"heartBeatTimer": 10,
"sNssais": [
{ "sst": 100,
......
curl -X PUT -H "Content-Type: application/json" -d @amf_registration.json http://192.168.1.88/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d
curl -X GET "http://192.168.1.23/nnrf-nfm/v1/nf-instances?nf-type="serviceId1"&limit=100"
curl -X PATCH -H "Content-Type: application/json" http://192.168.1.88/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d -d '[{"op":"replace","path":"...", "from":"", "value": "value" }]'
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