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

Create a new subscription

parent 5507552f
/**
* NRF NFManagement Service
* NRF NFManagement Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
* 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.
* 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 "3gpp_29.500.h"
#include "ProblemDetails.h"
#include "logger.hpp"
#include "nrf_app.hpp"
#include "nrf_config.hpp"
#include "nrf_profile.hpp"
#include "ProblemDetails.h"
#include "3gpp_29.500.h"
extern oai::nrf::app::nrf_config nrf_cfg;
......@@ -31,11 +32,9 @@ 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) {
}
: NFInstanceIDDocumentApi(rtr),
m_nrf_app(nrf_app_inst),
m_address(address) {}
//------------------------------------------------------------------------------
void NFInstanceIDDocumentApiImpl::deregister_nf_instance(
......@@ -45,43 +44,43 @@ void NFInstanceIDDocumentApiImpl::deregister_nf_instance(
nfInstanceID.c_str());
int http_code = 0;
ProblemDetails problem_details = { };
ProblemDetails problem_details = {};
m_nrf_app->handle_deregister_nf_instance(nfInstanceID, http_code, 1,
problem_details);
nlohmann::json json_data = { };
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));
// 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());
return;
} else {
response.headers().add < Pistache::Http::Header::ContentType
> (Pistache::Http::Mime::MediaType(content_type));
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType(content_type));
response.send(Pistache::Http::Code(http_code));
}
}
//------------------------------------------------------------------------------
void NFInstanceIDDocumentApiImpl::get_nf_instance(
const std::string &nfInstanceID, Pistache::Http::ResponseWriter &response) {
Logger::nrf_sbi().info(
"Got a request to retrieve the profile of a given NF Instance, Instance ID: %s",
"Got a request to retrieve the profile of a given NF Instance, Instance "
"ID: %s",
nfInstanceID.c_str());
int http_code = 0;
std::shared_ptr<nrf_profile> profile = { };
ProblemDetails problem_details = { };
std::shared_ptr<nrf_profile> profile = {};
ProblemDetails problem_details = {};
m_nrf_app->handle_get_nf_instance(nfInstanceID, profile, http_code, 1,
problem_details);
nlohmann::json json_data = { };
nlohmann::json json_data = {};
std::string content_type = "application/json";
if (http_code != HTTP_STATUS_CODE_200_OK) {
......@@ -91,11 +90,10 @@ void NFInstanceIDDocumentApiImpl::get_nf_instance(
profile.get()->to_json(json_data);
}
//content type
response.headers().add < Pistache::Http::Header::ContentType
> (Pistache::Http::Mime::MediaType(content_type));
// 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());
}
//------------------------------------------------------------------------------
......@@ -104,34 +102,34 @@ void NFInstanceIDDocumentApiImpl::register_nf_instance(
const Pistache::Optional<Pistache::Http::Header::Raw> &contentEncoding,
Pistache::Http::ResponseWriter &response) {
Logger::nrf_sbi().info(
"Got a request to register an NF instance/Update an NF instance, Instance ID: %s",
"Got a request to register an NF instance/Update an NF instance, "
"Instance ID: %s",
nfInstanceID.c_str());
NFProfile nf_profile = nFProfile;
int http_code = 0;
ProblemDetails problem_details = { };
ProblemDetails problem_details = {};
m_nrf_app->handle_register_nf_instance(nfInstanceID, nFProfile, http_code, 1,
problem_details);
nlohmann::json json_data = { };
nlohmann::json json_data = {};
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)) {
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);
to_json(json_data, nFProfile);
// Location header
response.headers().add<Pistache::Http::Header::Location>(
m_address + base + nrf_cfg.sbi_api_version + "/nf-instances/" +
nfInstanceID);
}
//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/"
+ nfInstanceID);
// 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());
}
......@@ -144,37 +142,36 @@ void NFInstanceIDDocumentApiImpl::update_nf_instance(
nfInstanceID.c_str());
int http_code = 0;
ProblemDetails problem_details = { };
ProblemDetails problem_details = {};
m_nrf_app->handle_update_nf_instance(nfInstanceID, patchItem, http_code, 1,
problem_details);
nlohmann::json json_data = { };
nlohmann::json json_data = {};
std::string content_type = "application/json";
std::shared_ptr<nrf_profile> profile = m_nrf_app->find_nf_profile(
nfInstanceID);
std::shared_ptr<nrf_profile> profile =
m_nrf_app->find_nf_profile(nfInstanceID);
if ((http_code != HTTP_STATUS_CODE_200_OK)
and (http_code != HTTP_STATUS_CODE_204_NO_CONTENT)) {
if ((http_code != HTTP_STATUS_CODE_200_OK) and
(http_code != HTTP_STATUS_CODE_204_NO_CONTENT)) {
to_json(json_data, problem_details);
content_type = "application/problem+json";
} else if (http_code == HTTP_STATUS_CODE_200_OK) {
//convert the profile to Json
// convert the profile to Json
profile.get()->to_json(json_data);
}
Logger::nrf_sbi().debug("Json data: %s", json_data.dump().c_str());
//content type
response.headers().add < Pistache::Http::Header::ContentType
> (Pistache::Http::Mime::MediaType(content_type));
// content type
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType(content_type));
if (http_code != HTTP_STATUS_CODE_204_NO_CONTENT)
response.send(Pistache::Http::Code(http_code), json_data.dump().c_str());
else
response.send(Pistache::Http::Code(http_code));
}
}
}
}
} // namespace api
} // namespace nrf
} // namespace oai
/**
* NRF NFManagement Service
* NRF NFManagement Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
* 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.
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
#include "SubscriptionsCollectionApiImpl.h"
#include "3gpp_29.500.h"
#include "ProblemDetails.h"
#include "logger.hpp"
#include "nrf_app.hpp"
#include "nrf_config.hpp"
extern oai::nrf::app::nrf_config nrf_cfg;
namespace oai {
namespace nrf {
......@@ -22,19 +30,42 @@ using namespace oai::nrf::app;
SubscriptionsCollectionApiImpl::SubscriptionsCollectionApiImpl(
std::shared_ptr<Pistache::Rest::Router> rtr, nrf_app *nrf_app_inst,
std::string address)
:
SubscriptionsCollectionApi(rtr),
m_nrf_app(nrf_app_inst),
m_address(address) {
}
: SubscriptionsCollectionApi(rtr),
m_nrf_app(nrf_app_inst),
m_address(address) {}
void SubscriptionsCollectionApiImpl::create_subscription(
const SubscriptionData &subscriptionData,
Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
Logger::nrf_sbi().info("Got a request to create a new subscription");
}
}
int http_code = 0;
ProblemDetails problem_details = {};
std::string sub_id;
m_nrf_app->handle_create_subscription(subscriptionData, sub_id, http_code, 1,
problem_details);
nlohmann::json json_data = {};
std::string content_type = "application/json";
if (http_code != HTTP_STATUS_CODE_201_CREATED) {
to_json(json_data, problem_details);
content_type = "application/problem+json";
} else {
to_json(json_data, subscriptionData);
json_data["subscriptionId"] = sub_id;
// Location header
response.headers().add<Pistache::Http::Header::Location>(
m_address + base + nrf_cfg.sbi_api_version + "/subscriptions/" +
sub_id);
}
// 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());
}
} // namespace api
} // namespace nrf
} // namespace oai
......@@ -126,4 +126,12 @@ typedef struct smf_info_s {
std::vector<snssai_smf_info_item_t> snssai_smf_info_list;
} smf_info_t;
// Event Subscription IDs)
typedef uint32_t evsub_id_t;
#define EVSUB_ID_FMT "0x%" PRIx32
#define EVSUB_ID_SCAN_FMT SCNx32
#define INVALID_EVSUB_ID ((evsub_id_t)0x00000000)
#define UNASSIGNED_EVSUB_ID ((evsub_id_t)0x00000000)
#endif
......@@ -32,10 +32,10 @@
#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 <regex>
#include "AmfInfo.h"
#include "api_conversions.hpp"
......@@ -48,9 +48,8 @@ using namespace oai::nrf::app;
using namespace oai::nrf;
//------------------------------------------------------------------------------
bool api_conv::profile_api_to_amf_profile(
bool api_conv::profile_api_to_nrf_profile(
const NFProfile &api_profile, std::shared_ptr<nrf_profile> &profile) {
Logger::nrf_app().debug(
"Convert a json-type profile a NF profile (profile ID: %s)",
api_profile.getNfInstanceId().c_str());
......@@ -72,10 +71,10 @@ bool api_conv::profile_api_to_amf_profile(
profile.get()->set_nf_capacity(api_profile.getCapacity());
Logger::nrf_app().debug("............Capacity: %d",
profile.get()->get_nf_capacity());
//SNSSAIs
// SNSSAIs
std::vector<Snssai> snssai = api_profile.getSNssais();
for (auto s : snssai) {
snssai_t sn = { };
snssai_t sn = {};
sn.sD = s.getSd();
sn.sST = s.getSst();
profile.get()->add_snssai(sn);
......@@ -83,9 +82,9 @@ bool api_conv::profile_api_to_amf_profile(
sn.sD.c_str());
}
std::vector < std::string > ipv4_addr_str = api_profile.getIpv4Addresses();
std::vector<std::string> ipv4_addr_str = api_profile.getIpv4Addresses();
for (auto address : ipv4_addr_str) {
struct in_addr addr4 = { };
struct in_addr addr4 = {};
unsigned char buf_in_addr[sizeof(struct in_addr)];
if (inet_pton(AF_INET, util::trim(address).c_str(), buf_in_addr) == 1) {
memcpy(&addr4, buf_in_addr, sizeof(struct in_addr));
......@@ -104,7 +103,7 @@ bool api_conv::profile_api_to_amf_profile(
case NF_TYPE_AMF: {
Logger::nrf_app().debug("............AMF profile, AMF Info");
profile.get()->set_nf_type(NF_TYPE_AMF);
amf_info_t info = { };
amf_info_t info = {};
AmfInfo amf_info_api = api_profile.getAmfInfo();
info.amf_region_id = amf_info_api.getAmfRegionId();
info.amf_set_id = amf_info_api.getAmfSetId();
......@@ -114,7 +113,7 @@ bool api_conv::profile_api_to_amf_profile(
info.amf_region_id.c_str());
for (auto g : amf_info_api.getGuamiList()) {
guami_t guami = { };
guami_t guami = {};
guami.amf_id = g.getAmfId();
guami.plmn.mcc = g.getPlmnId().getMcc();
guami.plmn.mnc = g.getPlmnId().getMnc();
......@@ -124,20 +123,19 @@ bool api_conv::profile_api_to_amf_profile(
Logger::nrf_app().debug(
"....................., PLMN (MCC: %s, MNC: %s)",
guami.plmn.mcc.c_str(), guami.plmn.mnc.c_str());
}
(std::static_pointer_cast < amf_profile > (profile)).get()->add_amf_info(
info);
}
break;
(std::static_pointer_cast<amf_profile>(profile))
.get()
->add_amf_info(info);
} break;
case NF_TYPE_SMF: {
Logger::nrf_app().debug("............SMF profile, SMF Info");
profile.get()->set_nf_type(NF_TYPE_SMF);
smf_info_t info = { };
smf_info_t info = {};
SmfInfo smf_info_api = api_profile.getSmfInfo();
for (auto s : smf_info_api.getSNssaiSmfInfoList()) {
snssai_smf_info_item_t snssai = { };
snssai_smf_info_item_t snssai = {};
snssai.snssai.sD = s.getSNssai().getSd();
snssai.snssai.sST = s.getSNssai().getSst();
Logger::nrf_app().debug(".......................NSSAI SD: %s, SST: %d",
......@@ -152,86 +150,66 @@ bool api_conv::profile_api_to_amf_profile(
info.snssai_smf_info_list.push_back(snssai);
}
(std::static_pointer_cast < smf_profile > (profile)).get()->add_smf_info(
info);
}
break;
default: {
}
(std::static_pointer_cast<smf_profile>(profile))
.get()
->add_smf_info(info);
} break;
default: {}
}
return true;
}
//------------------------------------------------------------------------------
bool api_conv::subscription_api_to_nrf_subscription(
const SubscriptionData &api_sub, std::shared_ptr<nrf_subscription> &sub) {
Logger::nrf_app().debug(
"Convert a json-type Subscription data a NRF subscription data");
sub.get()->set_notification_uri(api_sub.getNfStatusNotificationUri());
//TODO:
}
//------------------------------------------------------------------------------
nf_type_t api_conv::string_to_nf_type(const std::string &str) {
if (str.compare("NRF") == 0)
return NF_TYPE_NRF;
if (str.compare("AMF") == 0)
return NF_TYPE_AMF;
if (str.compare("SMF") == 0)
return NF_TYPE_SMF;
if (str.compare("AUSF") == 0)
return NF_TYPE_AUSF;
if (str.compare("NEF") == 0)
return NF_TYPE_NEF;
if (str.compare("PCP") == 0)
return NF_TYPE_PCF;
if (str.compare("SMSF") == 0)
return NF_TYPE_SMSF;
if (str.compare("NSSF") == 0)
return NF_TYPE_NSSF;
if (str.compare("UDR") == 0)
return NF_TYPE_UDR;
if (str.compare("LMF") == 0)
return NF_TYPE_LMF;
if (str.compare("GMLC") == 0)
return NF_TYPE_GMLC;
if (str.compare("5G_EIR") == 0)
return NF_TYPE_5G_EIR;
if (str.compare("SEPP") == 0)
return NF_TYPE_SEPP;
if (str.compare("UPF") == 0)
return NF_TYPE_UPF;
if (str.compare("N3IWF") == 0)
return NF_TYPE_N3IWF;
if (str.compare("AF") == 0)
return NF_TYPE_AF;
if (str.compare("UDSF") == 0)
return NF_TYPE_UDSF;
if (str.compare("BSF") == 0)
return NF_TYPE_BSF;
if (str.compare("CHF") == 0)
return NF_TYPE_CHF;
if (str.compare("NWDAF") == 0)
return NF_TYPE_NWDAF;
//default
if (str.compare("NRF") == 0) return NF_TYPE_NRF;
if (str.compare("AMF") == 0) return NF_TYPE_AMF;
if (str.compare("SMF") == 0) return NF_TYPE_SMF;
if (str.compare("AUSF") == 0) return NF_TYPE_AUSF;
if (str.compare("NEF") == 0) return NF_TYPE_NEF;
if (str.compare("PCP") == 0) return NF_TYPE_PCF;
if (str.compare("SMSF") == 0) return NF_TYPE_SMSF;
if (str.compare("NSSF") == 0) return NF_TYPE_NSSF;
if (str.compare("UDR") == 0) return NF_TYPE_UDR;
if (str.compare("LMF") == 0) return NF_TYPE_LMF;
if (str.compare("GMLC") == 0) return NF_TYPE_GMLC;
if (str.compare("5G_EIR") == 0) return NF_TYPE_5G_EIR;
if (str.compare("SEPP") == 0) return NF_TYPE_SEPP;
if (str.compare("UPF") == 0) return NF_TYPE_UPF;
if (str.compare("N3IWF") == 0) return NF_TYPE_N3IWF;
if (str.compare("AF") == 0) return NF_TYPE_AF;
if (str.compare("UDSF") == 0) return NF_TYPE_UDSF;
if (str.compare("BSF") == 0) return NF_TYPE_BSF;
if (str.compare("CHF") == 0) return NF_TYPE_CHF;
if (str.compare("NWDAF") == 0) return NF_TYPE_NWDAF;
// default
return NF_TYPE_UNKNOWN;
}
//------------------------------------------------------------------------------
patch_op_type_t api_conv::string_to_patch_operation(const std::string &str) {
if (str.compare("add") == 0)
return PATCH_OP_ADD;
if (str.compare("copy") == 0)
return PATCH_OP_COPY;
if (str.compare("move") == 0)
return PATCH_OP_MOVE;
if (str.compare("remove") == 0)
return PATCH_OP_REMOVE;
if (str.compare("replace") == 0)
return PATCH_OP_REPLACE;
if (str.compare("test") == 0)
return PATCH_OP_TEST;
//default
if (str.compare("add") == 0) return PATCH_OP_ADD;
if (str.compare("copy") == 0) return PATCH_OP_COPY;
if (str.compare("move") == 0) return PATCH_OP_MOVE;
if (str.compare("remove") == 0) return PATCH_OP_REMOVE;
if (str.compare("replace") == 0) return PATCH_OP_REPLACE;
if (str.compare("test") == 0) return PATCH_OP_TEST;
// default
return PATCH_OP_UNKNOWN;
}
bool api_conv::validate_uuid(const std::string &str) {
//should be verified with Capital letter
// 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);
......
......@@ -32,6 +32,8 @@
#include "NFProfile.h"
#include "nrf_profile.hpp"
#include "nrf_subscription.hpp"
#include "SubscriptionData.h"
#include "nrf.h"
using namespace oai::nrf::model;
......@@ -47,9 +49,19 @@ namespace api_conv {
* @param [std::shared_ptr<nrf_profile> &] profile: NF profile
* @return true if successful, otherwise, return false
*/
bool profile_api_to_amf_profile(const NFProfile &api_profile,
bool profile_api_to_nrf_profile(const NFProfile &api_profile,
std::shared_ptr<nrf_profile> &profile);
/*
* Convert a json-type profile to a subscription profile
* @param [const SubscriptionData &] subData: Json-type subscription data from
* OpenAPITool
* @param [std::shared_ptr<nrf_subscription> &] sub: NRF Subscription
* @return true if successful, otherwise, return false
*/
bool subscription_api_to_nrf_subscription(
const SubscriptionData &api_sub, std::shared_ptr<nrf_subscription> &sub);
/*
* Convert a string to nf type
* @param [const std::string &] str: string input
......@@ -64,11 +76,10 @@ 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
}
}
} // namespace nrf
} // namespace oai
#endif /* FILE_API_CONVERSIONS_HPP_SEEN */
......@@ -30,9 +30,9 @@ add_library (NRF STATIC
nrf_app.cpp
nrf_config.cpp
nrf_profile.cpp
nrf_subscription.cpp
task_manager.cpp
nrf_event.cpp
)
......@@ -3,9 +3,9 @@
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
*
* http://www.openairinterface.org/?page_id=698