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

Send Notificatio to subscribed NFs

parent 5df62e5d
...@@ -139,6 +139,16 @@ std::string event_notification::get_subs_change_notify_correlation_id() const { ...@@ -139,6 +139,16 @@ std::string event_notification::get_subs_change_notify_correlation_id() const {
return m_subs_change_notify_correlation_id; return m_subs_change_notify_correlation_id;
} }
//-----------------------------------------------------------------------------
void event_notification::add_report(const amf_event_report_t& report) {
m_report_list.push_back(report);
}
//-----------------------------------------------------------------------------
std::vector<amf_event_report_t> event_notification::get_reports() const {
return m_report_list;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void data_notification_msg::set_notification_event_type( void data_notification_msg::set_notification_event_type(
const std::string& type) { const std::string& type) {
......
...@@ -86,6 +86,8 @@ class event_notification { ...@@ -86,6 +86,8 @@ class event_notification {
std::string get_notify_correlation_id() const; std::string get_notify_correlation_id() const;
void set_subs_change_notify_correlation_id(std::string const& value); void set_subs_change_notify_correlation_id(std::string const& value);
std::string get_subs_change_notify_correlation_id() const; std::string get_subs_change_notify_correlation_id() const;
void add_report(const amf_event_report_t& report);
std::vector<amf_event_report_t> get_reports() const;
private: private:
std::string m_notify_correlation_id; // notifyCorrelationId std::string m_notify_correlation_id; // notifyCorrelationId
...@@ -93,7 +95,7 @@ class event_notification { ...@@ -93,7 +95,7 @@ class event_notification {
std::string std::string
m_subs_change_notify_correlation_id; // SubsChangeNotifyCorrelationId; m_subs_change_notify_correlation_id; // SubsChangeNotifyCorrelationId;
bool m_subs_change_notify_correlation_id_is_set; bool m_subs_change_notify_correlation_id_is_set;
// std::vector<AmfEventReport> m_report_list; //Report List std::vector<amf_event_report_t> m_report_list; // Report List
bool m_report_list_is_set; bool m_report_list_is_set;
}; };
......
...@@ -2811,23 +2811,41 @@ void amf_n1::get_5gmm_state( ...@@ -2811,23 +2811,41 @@ void amf_n1::get_5gmm_state(
void amf_n1::handle_ue_reachability_status_change( void amf_n1::handle_ue_reachability_status_change(
std::string supi, uint8_t http_version) { std::string supi, uint8_t http_version) {
Logger::amf_n1().debug( Logger::amf_n1().debug(
"Send request to SBI to triger UE Reachability Status Notification (SUPI " "Send request to SBI to triger UE Reachability Report (SUPI "
"%s )", "%s )",
supi.c_str()); supi.c_str());
std::vector<std::shared_ptr<amf_subscription>> subscriptions = {};
amf_app_inst->get_ee_subscriptions(
amf_event_type_t::REACHABILITY_REPORT, subscriptions);
if (subscriptions.size() > 0) {
// Send request to SBI to trigger the notification to the subscribed event
Logger::amf_app().debug(
"Send ITTI msg to AMF SBI to trigger the event notification");
std::shared_ptr<itti_sbi_notify_subscribed_event> itti_msg = std::shared_ptr<itti_sbi_notify_subscribed_event> itti_msg =
std::make_shared<itti_sbi_notify_subscribed_event>( std::make_shared<itti_sbi_notify_subscribed_event>(
TASK_AMF_N1, TASK_AMF_N11); TASK_AMF_N1, TASK_AMF_N11);
// TODO: // TODO:
itti_msg->notif_id = ""; // itti_msg->notif_id = "";
itti_msg->http_version = 1; itti_msg->http_version = 1;
// std::vector<amf_application::event_notification> event_notifs; for (auto i : subscriptions) {
event_notification ev_notif = {};
ev_notif.set_notify_correlation_id(i.get()->notify_correlation_id);
// ev_notif.set_subs_change_notify_correlation_id(i.get()->notify_uri);
amf_event_report_t report = {};
ev_notif.add_report(report);
itti_msg->event_notifs.push_back(ev_notif);
}
int ret = itti_inst->send_msg(itti_msg); int ret = itti_inst->send_msg(itti_msg);
if (0 != ret) { if (0 != ret) {
Logger::amf_n1().error( Logger::amf_n1().error(
"Could not send ITTI message %s to task TASK_AMF_N11", "Could not send ITTI message %s to task TASK_AMF_N11",
itti_msg->get_msg_name()); itti_msg->get_msg_name());
} }
}
} }
...@@ -132,7 +132,13 @@ void amf_n11_task(void*) { ...@@ -132,7 +132,13 @@ void amf_n11_task(void*) {
dynamic_cast<itti_n11_register_nf_instance_request*>(msg); dynamic_cast<itti_n11_register_nf_instance_request*>(msg);
// TODO: Handle ITTI // TODO: Handle ITTI
} break; } break;
case SBI_NOTIFY_SUBSCRIBED_EVENT: {
Logger::amf_n11().info(
"Receive Notify Subscribed Event Request, handling ...");
itti_sbi_notify_subscribed_event* m =
dynamic_cast<itti_sbi_notify_subscribed_event*>(msg);
amf_n11_inst->handle_itti_message(ref(*m));
} break;
default: { default: {
Logger::amf_n11().info( Logger::amf_n11().info(
"Receive unknown message type %d", msg->msg_type); "Receive unknown message type %d", msg->msg_type);
...@@ -448,7 +454,45 @@ void amf_n11::handle_itti_message( ...@@ -448,7 +454,45 @@ void amf_n11::handle_itti_message(
remote_uri, json_part, "", "", itti_msg.supi, psc.get()->pdu_session_id); remote_uri, json_part, "", "", itti_msg.supi, psc.get()->pdu_session_id);
} }
// SMF selection //------------------------------------------------------------------------------
void amf_n11::handle_itti_message(itti_sbi_notify_subscribed_event& itti_msg) {
Logger::amf_n11().debug(
"Send notification for the subscribed event to the subscription");
for (auto i : itti_msg.event_notifs) {
// Fill the json part
nlohmann::json json_data = {};
json_data["notifyCorrelationId"] = i.get_notify_correlation_id();
auto report_lists = nlohmann::json::array();
nlohmann::json report = {};
std::vector<amf_event_report_t> reports = i.get_reports();
for (auto r : reports) {
report["type"] = amf_event_type_e2str.at(static_cast<uint8_t>(r.m_type));
report["state"]["active"] = "TRUE";
if (r.m_supi_is_set) {
report["supi"] = r.m_supi; // TODO
}
// timestamp
std::time_t time_epoch_ntp = std::time(nullptr);
uint64_t tv_ntp = time_epoch_ntp + SECONDS_SINCE_FIRST_EPOCH;
report["timeStamp"] = std::to_string(tv_ntp);
report_lists.push_back(report);
}
json_data["reportList"] = report_lists;
std::string body = json_data.dump();
std::string response_data;
std::string url = i.get_notify_correlation_id();
curl_http_client(url, "POST", body, response_data);
// TODO: process the response
}
return;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool amf_n11::smf_selection_from_configuration( bool amf_n11::smf_selection_from_configuration(
std::string& smf_addr, std::string& smf_api_version) { std::string& smf_addr, std::string& smf_api_version) {
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "AuthenticationInfo.h" #include "AuthenticationInfo.h"
#include "UEAuthenticationCtx.h" #include "UEAuthenticationCtx.h"
#include "itti_msg_n11.hpp" #include "itti_msg_n11.hpp"
#include "itti_msg_sbi.hpp"
#include "pdu_session_context.hpp" #include "pdu_session_context.hpp"
namespace amf_application { namespace amf_application {
...@@ -53,6 +54,8 @@ class amf_n11 { ...@@ -53,6 +54,8 @@ class amf_n11 {
void handle_itti_message(itti_nsmf_pdusession_update_sm_context& itti_msg); void handle_itti_message(itti_nsmf_pdusession_update_sm_context& itti_msg);
void handle_itti_message(itti_nsmf_pdusession_release_sm_context& itti_msg); void handle_itti_message(itti_nsmf_pdusession_release_sm_context& itti_msg);
void handle_itti_message(itti_pdu_session_resource_setup_response& itti_msg); void handle_itti_message(itti_pdu_session_resource_setup_response& itti_msg);
void handle_itti_message(itti_sbi_notify_subscribed_event& itti_msg);
void send_pdu_session_update_sm_context_request( void send_pdu_session_update_sm_context_request(
std::string supi, std::shared_ptr<pdu_session_context> psc, std::string supi, std::shared_ptr<pdu_session_context> psc,
std::string smf_addr, bstring sm_msg, std::string dnn); std::string smf_addr, bstring sm_msg, std::string dnn);
......
...@@ -44,7 +44,7 @@ class amf_subscription { ...@@ -44,7 +44,7 @@ class amf_subscription {
amf_event_type_t ev_type; amf_event_type_t ev_type;
supi64_t supi; supi64_t supi;
std::string notify_correlation_id; std::string notify_correlation_id;
std::string notify_uri; std::string notify_uri; // subsChangeNotifyUri ?
std::string nf_id; std::string nf_id;
}; };
......
...@@ -74,4 +74,59 @@ typedef struct amf_event_s { ...@@ -74,4 +74,59 @@ typedef struct amf_event_s {
// refId: // refId:
} amf_event_t; } amf_event_t;
typedef struct amf_event_state_s {
bool m_active;
int32_t m_remain_reports;
bool m_remain_reports_is_set;
int32_t m_remain_duration;
bool m_remain_duration_is_set;
} amf_event_state_t;
typedef enum ue_reachability_e {
UNREACHABLE = 1,
REACHABLE = 2,
REGULATORY_ONLY = 3
} ue_reachability_t;
typedef struct amf_event_report_s {
amf_event_type_t m_type; // Mandatory
amf_event_state_t m_state; // Mandatory
std::string m_TimeStamp; // Mandatory
ue_reachability_t m_reachability;
bool m_reachability_is_set;
std::string m_supi;
bool m_supi_is_set;
std::string m_subscription_id;
bool m_subscription_id_is_set;
bool m_any_ue;
bool m_any_ue_is_set;
/*
std::vector<AmfEventArea> m_AreaList;
bool m_AreaListIsSet;
int32_t m_RefId;
bool m_RefIdIsSet;
std::string m_Gpsi;
bool m_GpsiIsSet;
std::string m_Pei;
bool m_PeiIsSet;
UserLocation m_Location;
bool m_LocationIsSet;
std::string m_Timezone;
bool m_TimezoneIsSet;
std::vector<AccessType> m_AccessTypeList;
bool m_AccessTypeListIsSet;
std::vector<RmInfo> m_RmInfoList;
bool m_RmInfoListIsSet;
std::vector<CmInfo> m_CmInfoList;
bool m_CmInfoListIsSet;
//CommunicationFailure m_CommFailure;
// bool m_CommFailureIsSet;
// int32_t m_NumberOfUes;
// bool m_NumberOfUesIsSet;
// std::vector<_5GsUserStateInfo> m_r_5gsUserStateList;
// bool m_r_5gsUserStateListIsSet;
*/
} amf_event_report_t;
#endif #endif
...@@ -150,4 +150,6 @@ typedef uint32_t evsub_id_t; ...@@ -150,4 +150,6 @@ typedef uint32_t evsub_id_t;
#define INVALID_EVSUB_ID ((evsub_id_t) 0x00000000) #define INVALID_EVSUB_ID ((evsub_id_t) 0x00000000)
#define UNASSIGNED_EVSUB_ID ((evsub_id_t) 0x00000000) #define UNASSIGNED_EVSUB_ID ((evsub_id_t) 0x00000000)
constexpr uint64_t SECONDS_SINCE_FIRST_EPOCH = 2208988800;
#endif #endif
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