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

add nf profile to notification data

parent a2b4161c
...@@ -584,7 +584,7 @@ void nrf_app::handle_nf_status_registered(const std::string &profile_id) { ...@@ -584,7 +584,7 @@ void nrf_app::handle_nf_status_registered(const std::string &profile_id) {
notification_uris); notification_uris);
// send notifications // send notifications
if (notification_uris.size() > 0) if (notification_uris.size() > 0)
nrf_client_inst->notify_subscribed_event(profile, notification_uris); nrf_client_inst->notify_subscribed_event(profile, NOTIFICATION_TYPE_NF_REGISTERED, notification_uris);
else else
Logger::nrf_app().debug("\tNo subscription found"); Logger::nrf_app().debug("\tNo subscription found");
...@@ -614,7 +614,7 @@ void nrf_app::handle_nf_status_deregistered(const std::string &profile_id) { ...@@ -614,7 +614,7 @@ void nrf_app::handle_nf_status_deregistered(const std::string &profile_id) {
get_subscription_list(profile_id, NOTIFICATION_TYPE_NF_DEREGISTERED, get_subscription_list(profile_id, NOTIFICATION_TYPE_NF_DEREGISTERED,
notification_uris); notification_uris);
// send notifications // send notifications
nrf_client_inst->notify_subscribed_event(profile, notification_uris); nrf_client_inst->notify_subscribed_event(profile, NOTIFICATION_TYPE_NF_DEREGISTERED, notification_uris);
} else { } else {
Logger::nrf_app().error("NF profile not found, profile id %s", Logger::nrf_app().error("NF profile not found, profile id %s",
...@@ -641,9 +641,9 @@ void nrf_app::handle_nf_status_profile_changed(const std::string &profile_id) { ...@@ -641,9 +641,9 @@ void nrf_app::handle_nf_status_profile_changed(const std::string &profile_id) {
std::vector<std::string> notification_uris = {}; std::vector<std::string> notification_uris = {};
get_subscription_list(profile_id, NOTIFICATION_TYPE_NF_PROFILE_CHANGED, get_subscription_list(profile_id, NOTIFICATION_TYPE_NF_PROFILE_CHANGED,
notification_uris); notification_uris);
//Notification data includes NF profile (other alternative, includes profile_changes)
// send notifications // send notifications
nrf_client_inst->notify_subscribed_event(profile, notification_uris); nrf_client_inst->notify_subscribed_event(profile, NOTIFICATION_TYPE_NF_PROFILE_CHANGED, notification_uris);
} else { } else {
Logger::nrf_app().error("NF profile not found, profile id %s", Logger::nrf_app().error("NF profile not found, profile id %s",
profile_id.c_str()); profile_id.c_str());
......
...@@ -84,7 +84,7 @@ CURL *nrf_client::curl_create_handle(const std::string &uri, ...@@ -84,7 +84,7 @@ CURL *nrf_client::curl_create_handle(const std::string &uri,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void nrf_client::notify_subscribed_event( void nrf_client::notify_subscribed_event(
const std::shared_ptr<nrf_profile> &profile, const std::shared_ptr<nrf_profile> &profile, const uint8_t &event_type,
const std::vector<std::string> &uris) { const std::vector<std::string> &uris) {
Logger::nrf_app().debug( Logger::nrf_app().debug(
"Send notification for the subscribed event to the subscriptions"); "Send notification for the subscribed event to the subscriptions");
...@@ -111,7 +111,7 @@ void nrf_client::notify_subscribed_event( ...@@ -111,7 +111,7 @@ void nrf_client::notify_subscribed_event(
// Fill the json part // Fill the json part
nlohmann::json json_data = {}; nlohmann::json json_data = {};
json_data["event"] = "NF_REGISTERED"; json_data["event"] = notification_event_type_e2str[event_type];
std::string instance_uri = std::string instance_uri =
std::string(inet_ntoa(*((struct in_addr *)&nrf_cfg.sbi.addr4))) + ":" + std::string(inet_ntoa(*((struct in_addr *)&nrf_cfg.sbi.addr4))) + ":" +
std::to_string(nrf_cfg.sbi.port) + NNRF_NFM_BASE + std::to_string(nrf_cfg.sbi.port) + NNRF_NFM_BASE +
...@@ -119,6 +119,25 @@ void nrf_client::notify_subscribed_event( ...@@ -119,6 +119,25 @@ void nrf_client::notify_subscribed_event(
profile.get()->get_nf_instance_id(); profile.get()->get_nf_instance_id();
Logger::nrf_app().debug("NF instance URI: %s", instance_uri.c_str()); Logger::nrf_app().debug("NF instance URI: %s", instance_uri.c_str());
json_data["nfInstanceUri"] = instance_uri; json_data["nfInstanceUri"] = instance_uri;
// NF profile
if ((event_type == NOTIFICATION_TYPE_NF_REGISTERED) or
(event_type == NOTIFICATION_TYPE_NF_PROFILE_CHANGED)) {
nlohmann::json json_profile = {};
switch (profile.get()->get_nf_type()) {
case NF_TYPE_AMF: {
std::static_pointer_cast<amf_profile>(profile).get()->to_json(
json_profile);
} break;
case NF_TYPE_SMF: {
std::static_pointer_cast<smf_profile>(profile).get()->to_json(
json_profile);
} break;
default: { profile.get()->to_json(json_profile); }
}
json_data["nfProfile"] = json_profile;
}
std::string body = json_data.dump(); std::string body = json_data.dump();
// create and add an easy handle to a multi curl request // create and add an easy handle to a multi curl request
...@@ -203,8 +222,8 @@ void nrf_client::notify_subscribed_event( ...@@ -203,8 +222,8 @@ void nrf_client::notify_subscribed_event(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void nrf_client::notify_subscribed_event( void nrf_client::notify_subscribed_event(
const std::shared_ptr<nrf_profile> &profile, const std::string &uri) { const std::shared_ptr<nrf_profile> &profile, const std::string &uri) {
Logger::nrf_app().debug( Logger::nrf_app().debug("Send notification to the subscribed NF (URI %s)",
"Send notification to the subscribed NF (URI %s)", uri.c_str()); uri.c_str());
// Fill the json part // Fill the json part
nlohmann::json json_data = {}; nlohmann::json json_data = {};
......
...@@ -58,10 +58,12 @@ class nrf_client { ...@@ -58,10 +58,12 @@ class nrf_client {
/* /*
* Send Notification for the associated event to the subscribers * Send Notification for the associated event to the subscribers
* @param [const std::shared_ptr<nrf_profile> &] profile: NF profile * @param [const std::shared_ptr<nrf_profile> &] profile: NF profile
* @param [const uint8_t &] event_type: notification type
* @param [const std::vector<std::string> &] uris: list of subscribed NFs' URI * @param [const std::vector<std::string> &] uris: list of subscribed NFs' URI
* @return void * @return void
*/ */
void notify_subscribed_event(const std::shared_ptr<nrf_profile> &profile, void notify_subscribed_event(const std::shared_ptr<nrf_profile> &profile,
const uint8_t &event_type,
const std::vector<std::string> &uris); const std::vector<std::string> &uris);
/* /*
......
...@@ -482,7 +482,6 @@ void nrf_profile::handle_heartbeart_timeout(uint64_t ms) { ...@@ -482,7 +482,6 @@ void nrf_profile::handle_heartbeart_timeout(uint64_t ms) {
set_nf_status("SUSPENDED"); set_nf_status("SUSPENDED");
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_profile::add_amf_info(const amf_info_t &info) { void amf_profile::add_amf_info(const amf_info_t &info) {
amf_info = info; amf_info = info;
...@@ -601,7 +600,6 @@ bool amf_profile::remove_profile_info( ...@@ -601,7 +600,6 @@ bool amf_profile::remove_profile_info(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_profile::to_json(nlohmann::json &data) const { void amf_profile::to_json(nlohmann::json &data) const {
nrf_profile::to_json(data); nrf_profile::to_json(data);
Logger::nrf_app().debug("[AMF] To Json");
//AMF Info //AMF Info
data["amfInfo"]["amfSetId"] = amf_info.amf_set_id; data["amfInfo"]["amfSetId"] = amf_info.amf_set_id;
data["amfInfo"]["amfRegionId"] = amf_info.amf_region_id; data["amfInfo"]["amfRegionId"] = amf_info.amf_region_id;
......
...@@ -354,6 +354,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> { ...@@ -354,6 +354,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
*/ */
void unsubscribe_task_tick(); void unsubscribe_task_tick();
protected: protected:
nrf_event &m_event_sub; nrf_event &m_event_sub;
bs2::connection task_connection; bs2::connection task_connection;
......
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