Commit e524ce7b authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

send notifications to subscribed NF

parent e4b232e3
......@@ -30,7 +30,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_e {
enum subscr_condition_type_e { //TODO: use enum class
UNKNOWN_CONDITION = 0,
NF_INSTANCE_ID_COND = 1,
NF_TYPE_COND = 2,
......
......@@ -233,8 +233,9 @@ 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["NfInstanceIdCond"]["nfInstanceId"]
.get<std::string>();
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());
......@@ -251,7 +252,9 @@ 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["ServiceNameCond"]["serviceName"].get<std::string>();
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());
......@@ -278,8 +281,15 @@ bool api_conv::subscription_api_to_nrf_subscription(
"Subscription condition type: %s",
subscription_condition_type_e2str[sub_condition.type].c_str());
sub.get()->set_sub_condition(sub_condition);
if (sub_condition.type != UNKNOWN_CONDITION) {
sub.get()->set_sub_condition(sub_condition);
return true;
} else {
return false;
}
}
// TODO:
return true;
}
......
......@@ -34,6 +34,7 @@
#include "api_conversions.hpp"
#include "common_defs.h"
#include "logger.hpp"
#include "nrf_client.hpp"
#include "nrf_config.hpp"
using namespace oai::nrf::app;
......@@ -42,14 +43,24 @@ using namespace std::chrono;
extern nrf_app *nrf_app_inst;
extern nrf_config nrf_cfg;
nrf_client *nrf_client_inst = nullptr;
//------------------------------------------------------------------------------
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
try {
nrf_client_inst = new nrf_client();
} catch (std::exception &e) {
Logger::nrf_app().error("Cannot create NRF_APP: %s", e.what());
throw;
}
// subscribe to NF status
subscribe_nf_status();
Logger::nrf_app().startup("Started");
}
//------------------------------------------------------------------------------
......@@ -313,7 +324,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
......@@ -550,9 +561,21 @@ void nrf_app::subscribe_nf_status_registered() {
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);
std::shared_ptr<nrf_profile> profile = {};
find_nf_profile(profile_id, profile);
if (profile != nullptr) {
std::vector<std::string> notification_uris = {};
get_subscription_list(profile_id, NOTIFICATION_TYPE_NF_REGISTERED,
notification_uris);
// send notifications
nrf_client_inst->notify_subscribed_event(profile, notification_uris);
} else {
Logger::nrf_app().error("NF profile not found, profile id %s",
profile_id.c_str());
}
// TODO:
}
......@@ -672,7 +695,6 @@ void nrf_app::get_subscription_list(const std::string &profile_id,
// TODO:
}
}
}
// TODO:
}
......@@ -35,12 +35,10 @@
#include <nlohmann/json.hpp>
#include "logger.hpp"
#include "nrf_client.hpp"
using namespace Pistache::Http;
using namespace Pistache::Http::Mime;
using namespace oai::nrf::app;
using json = nlohmann::json;
......
......@@ -37,7 +37,6 @@ using namespace util;
using namespace std;
nrf_app *nrf_app_inst = nullptr;
nrf_client *nrf_client_inst = nullptr;
nrf_config nrf_cfg;
NRFApiServer *api_server = nullptr;
......@@ -94,9 +93,6 @@ if ( !Options::parse( argc, argv ) )
// NRF application layer
nrf_app_inst = new nrf_app(Options::getlibconfigConfig(), ev);
// NRF client
nrf_client_inst = new nrf_client();
//Task Manager
task_manager tm(ev);
std::thread task_manager_thread(&task_manager::run, &tm);
......
......@@ -3,5 +3,5 @@ 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", "subscrCond": {"nfType": "AMF"} }'
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": {"NfTypeCond": {"nfType":"AMF"} } }'
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": {"NfInstanceIdCond": {"nfInstanceId":"AMF"} } }'
\ No newline at end of file
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