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

First working version for NFStatusNotify

parent f4e86ad1
......@@ -43,7 +43,7 @@ void SubscriptionsCollectionApiImpl::create_subscription(
ProblemDetails problem_details = {};
std::string sub_id;
nlohmann::json json_sub = {};
to_json(json_sub,subscriptionData);
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,
......@@ -61,7 +61,7 @@ void SubscriptionsCollectionApiImpl::create_subscription(
// Location header
response.headers().add<Pistache::Http::Header::Location>(
m_address + base + nrf_cfg.sbi_api_version + "/subscriptions/" +
sub_id);
sub_id);
}
// content type
......
......@@ -22,6 +22,7 @@
#ifndef FILE_3GPP_29_510_NRF_SEEN
#define FILE_3GPP_29_510_NRF_SEEN
#include <string>
#include "3gpp_23.003.h"
enum class nf_status_e { REGISTERED = 0, SUSPENDED = 1, UNDISCOVERABLE = 2 };
......@@ -74,11 +75,12 @@ typedef struct subscription_condition_s {
nf_group_cond_t nf_group;
};
subscription_condition_s() : type(0) {}
subscription_condition_s() : type(0), nf_instance_id() {}
subscription_condition_s(uint8_t t) : type(t) {}
subscription_condition_s(const subscription_condition_s &s) {
subscription_condition_s(const subscription_condition_s &s)
: subscription_condition_s() {
type = s.type;
switch (s.type) {
case NF_INSTANCE_ID_COND: {
......
......@@ -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
*
......@@ -49,12 +49,10 @@ typedef enum nf_type_s {
NF_TYPE_UNKNOWN = 20
} nf_type_t;
static const std::vector<std::string> nf_type_e2str = { "NF_TYPE_NRF",
"NF_TYPE_AMF", "NF_TYPE_SMF", "NF_TYPE_AUSF", "NF_TYPE_NEF", "NF_TYPE_PCF",
"NF_TYPE_SMSF", "NF_TYPE_NSSF", "NF_TYPE_UDR", "NF_TYPE_LMF",
"NF_TYPE_GMLC", "NF_TYPE_5G_EIR", "NF_TYPE_SEPP", "NF_TYPE_UPF",
"NF_TYPE_N3IWF", "NF_TYPE_AF", "NF_TYPE_UDSF", "NF_TYPE_BSF", "NF_TYPE_CHF",
"NF_TYPE_NWDAF", "NF_TYPE_UNKNOWN" };
static const std::vector<std::string> nf_type_e2str = {
"NRF", "AMF", "SMF", "AUSF", "NEF", "PCF", "SMSF",
"NSSF", "UDR", "LMF", "GMLC", "5G_EIR", "SEPP", "UPF",
"N3IWF", "AF", "UDSF", "BSF", "CHF", "NWDAF", "UNKNOWN"};
typedef enum patch_op_type_s {
PATCH_OP_ADD = 0,
......@@ -67,8 +65,8 @@ typedef enum patch_op_type_s {
} patch_op_type_t;
static const std::vector<std::string> patch_op_type_e2str = { "ADD", "REMOVE",
"REPLACE", "MOVE", "COPY", "TEST", "UNKNOWN" };
static const std::vector<std::string> patch_op_type_e2str = {
"ADD", "REMOVE", "REPLACE", "MOVE", "COPY", "TEST", "UNKNOWN"};
typedef struct amf_info_s {
std::string amf_set_id;
......@@ -92,9 +90,9 @@ typedef struct smf_info_s {
// 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)
#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
......@@ -233,10 +233,8 @@ bool api_conv::subscription_api_to_nrf_subscription(
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();
sub_condition.nf_instance_id = sub_condition_api["NfInstanceIdCond"]["nfInstanceId"]
.get<std::string>();
Logger::nrf_app().debug(
"Subscription condition type: NfInstanceIdCond, nfInstanceId: %s",
sub_condition.nf_instance_id.c_str());
......@@ -245,7 +243,7 @@ bool api_conv::subscription_api_to_nrf_subscription(
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();
sub_condition_api["NfTypeCond"]["nfType"].get<std::string>();
Logger::nrf_app().debug(
"Subscription condition type: NfTypeCond, nf_type: %s",
sub_condition.nf_type.c_str());
......@@ -253,10 +251,7 @@ bool api_conv::subscription_api_to_nrf_subscription(
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();
sub_condition.service_name = sub_condition_api["ServiceNameCond"]["serviceName"].get<std::string>();
Logger::nrf_app().debug(
"Subscription condition type: ServiceNameCond, serviceName: %s",
sub_condition.service_name.c_str());
......@@ -264,9 +259,9 @@ bool api_conv::subscription_api_to_nrf_subscription(
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_api["AmfCond"]["amfSetId"].get<std::string>();
sub_condition.amf_info.amf_region_id =
sub_condition_api.at("AmfCond").at("amfRegionId").dump().c_str();
sub_condition_api["AmfCond"]["amfRegionId"].get<std::string>();
Logger::nrf_app().debug(
"Subscription condition type: AmfCond, amfSetId: %s, amfRegionId: "
"%s ",
......
......@@ -48,6 +48,8 @@ nrf_app::nrf_app(const std::string &config_file, nrf_event &ev)
: m_event_sub(ev) {
Logger::nrf_app().startup("Starting...");
Logger::nrf_app().startup("Started");
//subscribe to NF status
subscribe_nf_status();
}
//------------------------------------------------------------------------------
......@@ -100,6 +102,18 @@ void nrf_app::handle_register_nf_instance(
// add to the DB
add_nf_profile(nf_instance_id, sn);
Logger::nrf_app().debug("Added/Updated NF Profile to the DB");
// heartbeart management for this NF profile
// get current time
uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
sn.get()->subscribe_task_tick(ms);
// Notify NF status change event
// m_event_sub.nf_status_change(p); //from subscription
m_event_sub.nf_status_registered(nf_instance_id); // from nrf_app
// display the info
sn.get()->display();
} else {
......@@ -299,7 +313,7 @@ void nrf_app::handle_create_subscription(
ss.get()->set_subscription_id(evsub_id);
// subscribe to NF status registered
subscribe_nf_status(evsub_id); // from nrf_app
// 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
......@@ -331,7 +345,6 @@ void nrf_app::handle_create_subscription(
//------------------------------------------------------------------------------
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, update
if (instance_id2nrf_profile.count(profile_id) > 0) {
......@@ -346,20 +359,11 @@ bool nrf_app::add_nf_profile(const std::string &profile_id,
profile_id.c_str());
instance_id2nrf_profile.emplace(profile_id, p);
}*/
// Create or update if profile exist
std::unique_lock lock(m_instance_id2nrf_profile);
instance_id2nrf_profile[profile_id] = p;
// heartbeart management for this NF profile
// get current time
uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
p.get()->subscribe_task_tick(ms);
// 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;
}
......@@ -404,7 +408,7 @@ bool nrf_app::find_nf_profile(const std::string &profile_id,
p = instance_id2nrf_profile.at(profile_id);
return true;
} else {
Logger::nrf_app().info("NF profile (ID %d) not found", profile_id.c_str());
Logger::nrf_app().info("NF profile (ID %s) not found", profile_id.c_str());
return false;
}
}
......@@ -527,7 +531,7 @@ evsub_id_t nrf_app::generate_ev_subscription_id() {
}
//------------------------------------------------------------------------------
void nrf_app::subscribe_nf_status(const std::string &sub_id) {
void nrf_app::subscribe_nf_status() {
// depending on the type of subscription, subscribe to the corresponding event
// for now subscribe to all events
subscribe_nf_status_registered();
......@@ -589,6 +593,86 @@ void nrf_app::handle_nf_status_profile_changed(const std::string &profile_id) {
void nrf_app::get_subscription_list(const std::string &profile_id,
uint8_t notification_type,
std::vector<std::string> &uris) {
Logger::nrf_app().debug(
"Get the list of subscriptions related to this profile, profile id %s",
profile_id.c_str());
std::shared_ptr<nrf_profile> profile = {};
find_nf_profile(profile_id, profile);
if (profile.get() == nullptr) {
// error
return;
}
for (auto s : instance_id2nrf_subscription) {
// Logger::nrf_app().debug("Subscription id %s", s.first.c_str());
std::string uri;
s.second.get()->get_notification_uri(uri);
// Logger::nrf_app().debug("Uri %s", uri.c_str());
subscription_condition_t condition = {};
s.second.get()->get_sub_condition(condition);
switch (condition.type) {
case NF_INSTANCE_ID_COND: {
if (profile_id.compare(condition.nf_instance_id) == 0) {
uris.push_back(uri);
Logger::nrf_app().debug("Subscription id %s, uri %s", s.first.c_str(),
uri.c_str());
}
} break;
case NF_TYPE_COND: {
std::string nf_type = nf_type_e2str[profile.get()->get_nf_type()];
if (nf_type.compare(condition.nf_type) == 0) {
uris.push_back(uri);
Logger::nrf_app().debug("Subscription id %s, uri %s", s.first.c_str(),
uri.c_str());
}
} break;
case SERVICE_NAME_COND: {
std::string service_name;
profile.get()->get_nf_instance_name(service_name);
if (service_name.compare(condition.service_name) == 0) {
uris.push_back(uri);
Logger::nrf_app().debug("Subscription id %s, uri %s", s.first.c_str(),
uri.c_str());
}
} break;
case AMF_COND: {
std::string nf_type = nf_type_e2str[profile.get()->get_nf_type()];
if (nf_type.compare("AMF") == 0) {
amf_info_t info = {};
std::static_pointer_cast<amf_profile>(profile).get()->get_amf_info(
info);
if ((info.amf_region_id.compare(condition.amf_info.amf_region_id) ==
0) and
(info.amf_set_id.compare(condition.amf_info.amf_set_id) == 0)) {
uris.push_back(uri);
Logger::nrf_app().debug("Subscription id %s, uri %s",
s.first.c_str(), uri.c_str());
}
}
} break;
case GUAMI_LIST_COND: {
// TODO:
} break;
case NETWOTK_SLICE_COND: {
// TODO:
} break;
case NF_GROUP_COND: {
// TODO:
} break;
default: {
// TODO:
}
}
}
// TODO:
}
......@@ -212,7 +212,7 @@ 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 subscribe_nf_status();
void subscribe_nf_status_registered();
void handle_nf_status_registered(const std::string &profile_id);
void subscribe_nf_status_deregistered();
......
......@@ -488,8 +488,8 @@ void amf_profile::add_amf_info(const amf_info_t &info) {
}
//------------------------------------------------------------------------------
void amf_profile::get_amf_info(amf_info_t &infos) const {
infos = amf_info;
void amf_profile::get_amf_info(amf_info_t &info) const {
info = amf_info;
}
//------------------------------------------------------------------------------
......
......@@ -471,7 +471,7 @@ class amf_profile : public nrf_profile {
* @param [const amf_info_t &] info: AMF info
* @return void
*/
void get_amf_info(amf_info_t &infos) const;
void get_amf_info(amf_info_t &info) const;
/*
* Print related-information for an AMF profile
......
......@@ -28,8 +28,8 @@
*/
#include "nrf_subscription.hpp"
#include "logger.hpp"
#include <nlohmann/json.hpp>
#include "logger.hpp"
using namespace oai::nrf::app;
......@@ -62,11 +62,12 @@ void nrf_subscription::get_notification_uri(
//------------------------------------------------------------------------------
void nrf_subscription::set_sub_condition(const subscription_condition_t &c) {
sub_condition = c;
sub_condition = c;
}
//------------------------------------------------------------------------------
void nrf_subscription::get_sub_condition(subscription_condition_t &c) const {
c = sub_condition;
c = sub_condition;
}
/*
//------------------------------------------------------------------------------
......@@ -82,30 +83,26 @@ void nrf_subscription::display() {
nf_status_notification_uri.c_str());
}
//------------------------------------------------------------------------------
void nrf_subscription::subscribe_nf_status_change() {
Logger::nrf_app().debug("Subscribe to NF status change event");
ev_connection = m_event_sub.subscribe_nf_status_change(
boost::bind(&nrf_subscription::handle_nf_status_change, this, _1));
}
//------------------------------------------------------------------------------
void nrf_subscription::handle_nf_status_change(const std::shared_ptr<nrf_profile> &profile) {
std::string nf_instance_id;
profile.get()->get_nf_instance_id(nf_instance_id);
Logger::nrf_app().info("Handle NF status change (subscription ID %s), profile ID %s", subscription_id.c_str(), nf_instance_id.c_str());
//TODO:
void nrf_subscription::handle_nf_status_change(
const std::shared_ptr<nrf_profile> &profile) {
std::string nf_instance_id;
profile.get()->get_nf_instance_id(nf_instance_id);
Logger::nrf_app().info(
"Handle NF status change (subscription ID %s), profile ID %s",
subscription_id.c_str(), nf_instance_id.c_str());
// TODO:
nlohmann::json notification_data = {};
notification_data["event"] = "NF_REGISTERED";
notification_data["nfInstanceUri"] = "";
//get NF profile based on profile_id
//NFStatusNotify
//curl...
// get NF profile based on profile_id
// NFStatusNotify
// curl...
}
......@@ -43,7 +43,9 @@ using namespace std;
class nrf_subscription {
public:
nrf_subscription(nrf_event &ev):m_event_sub(ev){};
nrf_subscription(nrf_event &ev):m_event_sub(ev){
};
nrf_subscription(nrf_subscription const &) = delete;
virtual ~nrf_subscription() {
Logger::nrf_app().debug("Delete instance...");
......
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