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

Handle notification event type

parent cf3c819d
......@@ -42,6 +42,10 @@ void SubscriptionsCollectionApiImpl::create_subscription(
int http_code = 0;
ProblemDetails problem_details = {};
std::string sub_id;
nlohmann::json json_sub = {};
to_json(json_sub,subscriptionData);
Logger::nrf_sbi().debug("Subscription data %s", json_sub.dump().c_str());
m_nrf_app->handle_create_subscription(subscriptionData, sub_id, http_code, 1,
problem_details);
......
/**
* 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 "NfTypeCond.h"
#include <iostream>
namespace oai {
namespace nrf {
namespace model {
NfTypeCond::NfTypeCond() {
NfTypeCond::NfTypeCond() {}
}
NfTypeCond::~NfTypeCond() {
}
NfTypeCond::~NfTypeCond() {}
void NfTypeCond::validate() {
// TODO: implement validation
......@@ -36,14 +35,9 @@ void from_json(const nlohmann::json &j, NfTypeCond &o) {
j.at("nfType").get_to(o.m_NfType);
}
std::string NfTypeCond::getNfType() const {
return m_NfType;
}
void NfTypeCond::setNfType(std::string const &value) {
m_NfType = value;
}
}
}
}
std::string NfTypeCond::getNfType() const { return m_NfType; }
void NfTypeCond::setNfType(std::string const &value) { m_NfType = value; }
} // namespace model
} // namespace nrf
} // namespace oai
......@@ -31,7 +31,7 @@ SubscriptionData::SubscriptionData() {
m_ReqNfFqdn = "";
m_ReqNfFqdnIsSet = false;
m_ReqSnssaisIsSet = false;
//m_SubscrCond;
m_SubscrCond = {};
}
......@@ -74,7 +74,8 @@ void from_json(const nlohmann::json &j, SubscriptionData &o) {
}
if(j.find("subscrCond") != j.end())
{
j.at("subscrCond").get_to(o.m_SubscrCond);
//j.at("subscrCond").get_to(o.m_SubscrCond);
o.m_SubscrCond = j.at("subscrCond");
o.m_SubscrCondIsSet = true;
}
......@@ -134,13 +135,12 @@ void SubscriptionData::unsetReqNfInstanceId() {
m_ReqNfInstanceIdIsSet = false;
}
subscription_condition_api_t SubscriptionData::getSubscrCond() const
void SubscriptionData::getSubscrCond(nlohmann::json &s) const
{
return m_SubscrCond;
s = m_SubscrCond;
}
void SubscriptionData::setSubscrCond(subscription_condition_api_t const& value)
void SubscriptionData::setSubscrCond(nlohmann::json const& value)
{
m_SubscrCond = value;
m_SubscrCondIsSet = true;
......
......@@ -21,6 +21,7 @@
//#include
//"OneOfNfInstanceIdCondNfTypeCondServiceNameCondAmfCondGuamiListCondNetworkSliceCondNfGroupCond.h"
#include <iostream>
#include <nlohmann/json.hpp>
#include <string>
#include <vector>
......@@ -54,18 +55,11 @@ typedef struct subscription_condition_api_s {
};
subscription_condition_api_s() : type(0) {
nfInstanceIdCond = {};
nfTypeCond = {};
serviceNameCond = {};
amfCond = {};
guamiListCond = {};
networkSliceCond = {};
nfGroupCond = {};
// TODO
}
subscription_condition_api_s(subscription_condition_api_s const &s) {
nfInstanceIdCond = s.nfInstanceIdCond;
// nfInstanceIdCond.setNfInstanceId(s.nfInstanceIdCond.getNfInstanceId());
nfTypeCond = s.nfTypeCond;
serviceNameCond = s.serviceNameCond;
amfCond = s.amfCond;
......@@ -91,15 +85,7 @@ typedef struct subscription_condition_api_s {
bool operator==(const uint8_t &t) const { return (t == type); }
subscription_condition_api_s &operator=(subscription_condition_api_s s) {
nfInstanceIdCond = s.nfInstanceIdCond;
// nfInstanceIdCond.setNfInstanceId(s.nfInstanceIdCond.getNfInstanceId());
nfTypeCond = s.nfTypeCond;
serviceNameCond = s.serviceNameCond;
amfCond = s.amfCond;
guamiListCond = s.guamiListCond;
networkSliceCond = s.networkSliceCond;
nfGroupCond = s.nfGroupCond;
return *this;
// TODO:
}
friend void to_json(nlohmann::json &j,
......@@ -140,6 +126,8 @@ typedef struct subscription_condition_api_s {
o.type = 1;
}
if (j.find("NfTypeCond") != j.end()) {
o.nfTypeCond = {};
j.at("NfTypeCond").get_to(o.nfTypeCond);
o.type = 2;
}
......@@ -202,9 +190,9 @@ class SubscriptionData {
// OneOfNfInstanceIdCondNfTypeCondServiceNameCondAmfCondGuamiListCondNetworkSliceCondNfGroupCond
// getSubscrCond() const;
subscription_condition_api_t getSubscrCond() const;
void getSubscrCond(nlohmann::json &s) const;
void setSubscrCond(subscription_condition_api_t const &value);
void setSubscrCond(nlohmann::json const &value);
bool subscrCondIsSet() const;
void unsetSubscrCond();
/// <summary>
......@@ -272,7 +260,7 @@ class SubscriptionData {
bool m_ReqNfInstanceIdIsSet;
// OneOfNfInstanceIdCondNfTypeCondServiceNameCondAmfCondGuamiListCondNetworkSliceCondNfGroupCond
// m_SubscrCond;
subscription_condition_api_t m_SubscrCond;
nlohmann::json m_SubscrCond;
bool m_SubscrCondIsSet;
std::string m_SubscriptionId;
......
......@@ -29,7 +29,7 @@ enum class nf_status_e { REGISTERED = 0, SUSPENDED = 1, UNDISCOVERABLE = 2 };
static const std::vector<std::string> nf_status_e2str = {
"REGISTERED", "SUSPENDED", "UNDISCOVERABLE"};
enum subscription_condition_type {
enum subscription_condition_type_e {
UNKNOWN_CONDITION = 0,
NF_INSTANCE_ID_COND = 1,
NF_TYPE_COND = 2,
......@@ -40,6 +40,12 @@ enum subscription_condition_type {
NF_GROUP_COND = 7
};
static const std::vector<std::string> subscription_condition_type_e2str = {
"UNKNOWN_CONDITION", "NF_INSTANCE_ID_COND",
"NF_TYPE_COND", "SERVICE_NAME_COND",
"AMF_COND", "GUAMI_LIST_COND",
"NETWOTK_SLICE_COND", "NF_GROUP_COND"};
typedef struct amf_cond_s {
std::string amf_set_id;
std::string amf_region_id;
......@@ -82,4 +88,10 @@ typedef struct subscription_condition_s {
} subscription_condition_t;
enum notification_event_type_t {
NOTIFICATION_TYPE_NF_REGISTERED = 0,
NOTIFICATION_TYPE_NF_DEREGISTERED = 1,
NOTIFICATION_TYPE_NF_PROFILE_CHANGED = 2
};
#endif
......@@ -35,6 +35,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <nlohmann/json.hpp>
#include <regex>
#include "3gpp_29.510.h"
......@@ -170,24 +171,32 @@ bool api_conv::subscription_api_to_nrf_subscription(
sub.get()->set_notification_uri(api_sub.getNfStatusNotificationUri());
subscription_condition_t sub_condition = {};
/*
if (api_sub.subscrCondIsSet()) {
subscription_condition_api_t sub_condition_api = api_sub.getSubscrCond();
subscription_condition_api_t sub_condition_api = {};
api_sub.getSubscrCond(sub_condition_api);
switch (sub_condition_api.type) {
case NF_INSTANCE_ID_COND: {
Logger::nrf_app().debug(
"Subscription condition type: NF_INSTANCE_ID_COND");
sub_condition.type = NF_INSTANCE_ID_COND;
sub_condition.nf_instance_id =
sub_condition_api.nfInstanceIdCond.getNfInstanceId();
} break;
case NF_TYPE_COND: {
Logger::nrf_app().debug("Subscription condition type: NF_TYPE_COND");
sub_condition.type = NF_TYPE_COND;
sub_condition.nf_type = sub_condition_api.nfTypeCond.getNfType();
} break;
case SERVICE_NAME_COND: {
Logger::nrf_app().debug(
"Subscription condition type: SERVICE_NAME_COND");
sub_condition.type = SERVICE_NAME_COND;
sub_condition.service_name =
sub_condition_api.serviceNameCond.getServiceName();
} break;
case AMF_COND: {
Logger::nrf_app().debug("Subscription condition type: AMF_COND");
sub_condition.type = AMF_COND;
sub_condition.amf_info.amf_set_id =
sub_condition_api.amfCond.getAmfSetId();
......@@ -195,23 +204,85 @@ bool api_conv::subscription_api_to_nrf_subscription(
sub_condition_api.amfCond.getAmfRegionId();
} break;
case GUAMI_LIST_COND: {
Logger::nrf_app().debug("Subscription condition type: GUAMI_LIST_COND");
sub_condition.type = GUAMI_LIST_COND;
// TODO:
} break;
case NETWOTK_SLICE_COND: {
Logger::nrf_app().debug(
"Subscription condition type: NETWOTK_SLICE_COND");
sub_condition.type = NETWOTK_SLICE_COND;
// TODO:
} break;
case NF_GROUP_COND: {
Logger::nrf_app().debug("Subscription condition type: NF_GROUP_COND");
sub_condition.type = NF_GROUP_COND;
// TODO:
} break;
default: {
return false;
Logger::nrf_app().debug("Subscription condition type: Unknown");
return false;
}
}
}
*/
if (api_sub.subscrCondIsSet()) {
nlohmann::json sub_condition_api = {};
api_sub.getSubscrCond(sub_condition_api);
if (sub_condition_api.find("NfInstanceIdCond") != sub_condition_api.end()) {
sub_condition.type = NF_INSTANCE_ID_COND;
sub_condition.nf_instance_id = sub_condition_api.at("NfInstanceIdCond")
.at("nfInstanceId")
.dump()
.c_str();
Logger::nrf_app().debug(
"Subscription condition type: NfInstanceIdCond, nfInstanceId: %s",
sub_condition.nf_instance_id.c_str());
}
if (sub_condition_api.find("NfTypeCond") != sub_condition_api.end()) {
sub_condition.type = NF_TYPE_COND;
sub_condition.nf_type =
sub_condition_api.at("NfTypeCond").at("nfType").dump().c_str();
Logger::nrf_app().debug(
"Subscription condition type: NfTypeCond, nf_type: %s",
sub_condition.nf_type.c_str());
}
if (sub_condition_api.find("ServiceNameCond") != sub_condition_api.end()) {
sub_condition.type = SERVICE_NAME_COND;
sub_condition.service_name = sub_condition_api.at("ServiceNameCond")
.at("serviceName")
.dump()
.c_str();
Logger::nrf_app().debug(
"Subscription condition type: ServiceNameCond, serviceName: %s",
sub_condition.service_name.c_str());
}
if (sub_condition_api.find("AmfCond") != sub_condition_api.end()) {
sub_condition.type = AMF_COND;
sub_condition.amf_info.amf_set_id =
sub_condition_api.at("AmfCond").at("amfSetId").dump().c_str();
sub_condition.amf_info.amf_region_id =
sub_condition_api.at("AmfCond").at("amfRegionId").dump().c_str();
Logger::nrf_app().debug(
"Subscription condition type: AmfCond, amfSetId: %s, amfRegionId: "
"%s ",
sub_condition.amf_info.amf_set_id.c_str(),
sub_condition.amf_info.amf_region_id.c_str());
}
if (sub_condition_api.find("GuamiListCond") != sub_condition_api.end()) {
sub_condition.type = GUAMI_LIST_COND;
// TODO
}
Logger::nrf_app().debug(
"Subscription condition type: %s",
subscription_condition_type_e2str[sub_condition.type].c_str());
}
// TODO:
return true;
}
......
......@@ -30,6 +30,7 @@
#include "nrf_app.hpp"
#include <chrono>
#include "3gpp_29.500.h"
#include "3gpp_29.510.h"
#include "api_conversions.hpp"
#include "common_defs.h"
#include "logger.hpp"
......@@ -280,35 +281,40 @@ void nrf_app::handle_deregister_nf_instance(const std::string &nf_instance_id,
//------------------------------------------------------------------------------
void nrf_app::handle_create_subscription(
const SubscriptionData &subscription_data, std::string &sub_id, int &http_code,
const uint8_t http_version, ProblemDetails &problem_details) {
const SubscriptionData &subscription_data, std::string &sub_id,
int &http_code, const uint8_t http_version,
ProblemDetails &problem_details) {
std::string evsub_id;
Logger::nrf_app().info("Handle Create a new subscription (HTTP version %d)",
http_version);
std::shared_ptr<nrf_subscription> ss = std::make_shared<nrf_subscription>(m_event_sub);
std::shared_ptr<nrf_subscription> ss =
std::make_shared<nrf_subscription>(m_event_sub);
// convert to nrf_subscription
if (api_conv::subscription_api_to_nrf_subscription(subscription_data, ss)) {
if (authorize_subscription(ss)) {
// generate a subscription ID
generate_ev_subscription_id(evsub_id);
ss.get()->set_subscription_id(evsub_id);
//subscribe to NF status change
ss.get()->subscribe_nf_status_change();
// add to the DB
add_subscription(evsub_id, ss);
Logger::nrf_app().debug("Added a subscription to the DB");
// display the info
ss.get()->display();
//assign info for API server
http_code = HTTP_STATUS_CODE_201_CREATED;
sub_id = evsub_id;
return;
// generate a subscription ID
generate_ev_subscription_id(evsub_id);
ss.get()->set_subscription_id(evsub_id);
// subscribe to NF status registered
subscribe_nf_status(evsub_id); // from nrf_app
// subscribe to NF status change
// ss.get()->subscribe_nf_status_change(); //from subscription
// add to the DB
add_subscription(evsub_id, ss);
Logger::nrf_app().debug("Added a subscription to the DB");
// display the info
ss.get()->display();
// assign info for API server
http_code = HTTP_STATUS_CODE_201_CREATED;
sub_id = evsub_id;
return;
} else {
Logger::nrf_app().debug("Subscription is not authorized!");
http_code = HTTP_STATUS_CODE_401_UNAUTHORIZED;
return;
Logger::nrf_app().debug("Subscription is not authorized!");
http_code = HTTP_STATUS_CODE_401_UNAUTHORIZED;
return;
}
} else {
......@@ -350,8 +356,9 @@ bool nrf_app::add_nf_profile(const std::string &profile_id,
.count();
p.get()->subscribe_task_tick(ms);
//Notify NF status change event
m_event_sub.nf_status_change(p);
// Notify NF status change event
// m_event_sub.nf_status_change(p); //from subscription
m_event_sub.nf_status_registered(profile_id); // from nrf_app
return true;
}
......@@ -502,10 +509,13 @@ void nrf_app::handle_heartbeart_timeout(uint64_t ms) {
Logger::nrf_app().info("handle_heartbeart_timeout %d", ms);
}
bool nrf_app::authorize_subscription(const std::shared_ptr<nrf_subscription> &s) const {
//TODO:
return true;
//------------------------------------------------------------------------------
bool nrf_app::authorize_subscription(
const std::shared_ptr<nrf_subscription> &s) const {
// TODO:
return true;
}
//------------------------------------------------------------------------------
void nrf_app::generate_ev_subscription_id(std::string &sub_id) {
sub_id = std::to_string(evsub_id_generator.get_uid());
......@@ -515,3 +525,79 @@ void nrf_app::generate_ev_subscription_id(std::string &sub_id) {
evsub_id_t nrf_app::generate_ev_subscription_id() {
return evsub_id_generator.get_uid();
}
//------------------------------------------------------------------------------
void nrf_app::subscribe_nf_status(const std::string &sub_id) {
// depending on the type of subscription, subscribe to the corresponding event
// for now subscribe to all events
subscribe_nf_status_registered();
subscribe_nf_status_deregistered();
subscribe_nf_status_profile_changed();
}
/*
//------------------------------------------------------------------------------
void nrf_app::handle_nf_status(const std::string &profile_id) {
Logger::nrf_app().info("Handle NF status, profile id %s",
profile_id.c_str()); std::vector<std::string> notification_uris = {};
get_subscription_list(profile_id, notification_uris);
}
*/
//------------------------------------------------------------------------------
void nrf_app::subscribe_nf_status_registered() {
Logger::nrf_app().debug("Subscribe to NF status registered");
m_event_sub.subscribe_nf_status_registered(
boost::bind(&nrf_app::handle_nf_status_registered, this, _1));
}
//------------------------------------------------------------------------------
void nrf_app::handle_nf_status_registered(const std::string &profile_id) {
Logger::nrf_app().info("Handle NF status registered, profile id %s",
profile_id.c_str());
std::vector<std::string> notification_uris = {};
get_subscription_list(profile_id, NOTIFICATION_TYPE_NF_REGISTERED,
notification_uris);
// TODO:
}
//------------------------------------------------------------------------------
void nrf_app::subscribe_nf_status_deregistered() {
Logger::nrf_app().debug("Subscribe to NF status deregistered");
m_event_sub.subscribe_nf_status_deregistered(
boost::bind(&nrf_app::handle_nf_status_deregistered, this, _1));
}
//------------------------------------------------------------------------------
void nrf_app::handle_nf_status_deregistered(const std::string &profile_id) {
Logger::nrf_app().info("Handle NF status deregistered, profile id %s",
profile_id.c_str());
std::vector<std::string> notification_uris = {};
get_subscription_list(profile_id, NOTIFICATION_TYPE_NF_DEREGISTERED,
notification_uris);
// TODO:
}
//------------------------------------------------------------------------------
void nrf_app::subscribe_nf_status_profile_changed() {
Logger::nrf_app().debug("Subscribe to NF status profile changed");
m_event_sub.subscribe_nf_status_profile_changed(
boost::bind(&nrf_app::handle_nf_status_profile_changed, this, _1));
}
//------------------------------------------------------------------------------
void nrf_app::handle_nf_status_profile_changed(const std::string &profile_id) {
Logger::nrf_app().info("Handle NF status profile changed, profile id %s",
profile_id.c_str());
std::vector<std::string> notification_uris = {};
get_subscription_list(profile_id, NOTIFICATION_TYPE_NF_PROFILE_CHANGED,
notification_uris);
// TODO:
}
void nrf_app::get_subscription_list(const std::string &profile_id,
uint8_t notification_type,
std::vector<std::string> &uris) {
// TODO:
}
......@@ -212,6 +212,17 @@ class nrf_app {
void generate_ev_subscription_id(std::string &sub_id);
evsub_id_t generate_ev_subscription_id();
void subscribe_nf_status(const std::string &sub_id);
// void handle_nf_status(const std::string &profile_id);
void subscribe_nf_status_registered();
void handle_nf_status_registered(const std::string &profile_id);
void subscribe_nf_status_deregistered();
void handle_nf_status_deregistered(const std::string &profile_id);
void subscribe_nf_status_profile_changed();
void handle_nf_status_profile_changed(const std::string &profile_id);
void get_subscription_list(const std::string &profile_id, uint8_t notification_type, std::vector<std::string> &uris);
private:
std::map<std::string, std::shared_ptr<nrf_profile>> instance_id2nrf_profile;
mutable std::shared_mutex m_instance_id2nrf_profile;
......
......@@ -67,9 +67,30 @@ bs2::connection nrf_event::subscribe_task_tick_extended(
//------------------------------------------------------------------------------
bs2::connection nrf_event::subscribe_nf_status_change(
const nf_status_sig_t::slot_type &sig) {
const nf_status_change_sig_t::slot_type &sig) {
return nf_status_change.connect(sig);
}
//------------------------------------------------------------------------------
bs2::connection nrf_event::subscribe_nf_status_registered(
const nf_status_sig_t::slot_type &sig) {
return nf_status_registered.connect(sig);
}
//------------------------------------------------------------------------------
bs2::connection nrf_event::subscribe_nf_status_deregistered(
const nf_status_sig_t::slot_type &sig) {
return nf_status_deregistered.connect(sig);
}
//------------------------------------------------------------------------------
bs2::connection nrf_event::subscribe_nf_status_profile_changed(
const nf_status_sig_t::slot_type &sig) {
return nf_status_profile_changed.connect(sig);
}
......@@ -70,11 +70,16 @@ class nrf_event {
uint64_t period, uint64_t start = 0);
bs2::connection subscribe_nf_status_change(const nf_status_sig_t::slot_type &sig);
bs2::connection subscribe_nf_status_change(const nf_status_change_sig_t::slot_type &sig);
bs2::connection subscribe_nf_status_registered(const nf_status_sig_t::slot_type &sig);
bs2::connection subscribe_nf_status_deregistered(const nf_status_sig_t::slot_type &sig);
bs2::connection subscribe_nf_status_profile_changed(const nf_status_sig_t::slot_type &sig);
private:
task_sig_t task_tick;
nf_status_sig_t nf_status_change;
nf_status_change_sig_t nf_status_change;
nf_status_sig_t nf_status_registered;
nf_status_sig_t nf_status_deregistered;
nf_status_sig_t nf_status_profile_changed;
};
}
......
......@@ -47,13 +47,13 @@ typedef bs2::signal_type<void(uint64_t),
// Signal for NF Status
// Subscription ID, NF Status
//typedef bs2::signal_type<void(std::string),
// bs2::keywords::mutex_type<bs2::dummy_mutex>>::type
// nf_status_sig_t;
typedef bs2::signal_type<void(const std::string &),
bs2::keywords::mutex_type<bs2::dummy_mutex>>::type
nf_status_sig_t;
typedef bs2::signal_type<void(const std::shared_ptr<nrf_profile> &p),
bs2::keywords::mutex_type<bs2::dummy_mutex>>::type
nf_status_sig_t;
nf_status_change_sig_t;
} // namespace app
} // namespace nrf
......
......@@ -4,4 +4,4 @@ curl -X GET "http://192.168.1.23/nnrf-nfm/v1/nf-instances?nf-type="serviceId1"&
curl -X PATCH -H "Content-Type: application/json" http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d -d '[{"op":"replace","path":"/nfInstanceName", "value": "NEW NAME"}]'
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"}'
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": {"nfType": "AMF"} }'