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

Merge branch 'fix_event_exposure_registration_report' into 'develop'

Fix bug for event exposure

See merge request oai/cn5g/oai-cn5g-amf!83
parents 8813b399 2e3e9ee2
...@@ -124,7 +124,8 @@ void event_exposure_msg::set_any_ue(bool value) { ...@@ -124,7 +124,8 @@ void event_exposure_msg::set_any_ue(bool value) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void event_notification::set_notify_correlation_id(std::string const& value) { void event_notification::set_notify_correlation_id(std::string const& value) {
m_notify_correlation_id = value; m_notify_correlation_id = value;
m_notify_correlation_is_set = true;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -132,6 +133,15 @@ std::string event_notification::get_notify_correlation_id() const { ...@@ -132,6 +133,15 @@ std::string event_notification::get_notify_correlation_id() const {
return m_notify_correlation_id; return m_notify_correlation_id;
} }
void event_notification::set_notify_uri(std::string const& value) {
m_notify_uri = value;
m_notify_uri_is_set = true;
}
std::string event_notification::get_notify_uri() const {
return m_notify_uri;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void event_notification::set_subs_change_notify_correlation_id( void event_notification::set_subs_change_notify_correlation_id(
std::string const& value) { std::string const& value) {
......
...@@ -87,6 +87,10 @@ class event_notification { ...@@ -87,6 +87,10 @@ class event_notification {
public: public:
void set_notify_correlation_id(std::string const& value); void set_notify_correlation_id(std::string const& value);
std::string get_notify_correlation_id() const; std::string get_notify_correlation_id() const;
void set_notify_uri(std::string const& value);
std::string get_notify_uri() 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 oai::amf::model::AmfEventReport& report); void add_report(const oai::amf::model::AmfEventReport& report);
...@@ -95,6 +99,10 @@ class event_notification { ...@@ -95,6 +99,10 @@ class event_notification {
private: private:
std::string m_notify_correlation_id; // notifyCorrelationId std::string m_notify_correlation_id; // notifyCorrelationId
bool m_notify_correlation_is_set; bool m_notify_correlation_is_set;
std::string m_notify_uri; // notifyUri
bool m_notify_uri_is_set;
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;
......
...@@ -3176,13 +3176,12 @@ void amf_n1::handle_ue_location_change( ...@@ -3176,13 +3176,12 @@ void amf_n1::handle_ue_location_change(
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:
// itti_msg->notif_id = "";
itti_msg->http_version = 1; itti_msg->http_version = 1;
for (auto i : subscriptions) { for (auto i : subscriptions) {
event_notification ev_notif = {}; event_notification ev_notif = {};
ev_notif.set_notify_correlation_id(i.get()->notify_correlation_id); ev_notif.set_notify_correlation_id(i.get()->notify_correlation_id);
ev_notif.set_notify_uri(i.get()->notify_uri); // Direct subscription
// ev_notif.set_subs_change_notify_correlation_id(i.get()->notify_uri); // ev_notif.set_subs_change_notify_correlation_id(i.get()->notify_uri);
oai::amf::model::AmfEventReport event_report = {}; oai::amf::model::AmfEventReport event_report = {};
...@@ -3232,13 +3231,12 @@ void amf_n1::handle_ue_reachability_status_change( ...@@ -3232,13 +3231,12 @@ void amf_n1::handle_ue_reachability_status_change(
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:
// itti_msg->notif_id = "";
itti_msg->http_version = 1; itti_msg->http_version = 1;
for (auto i : subscriptions) { for (auto i : subscriptions) {
event_notification ev_notif = {}; event_notification ev_notif = {};
ev_notif.set_notify_correlation_id(i.get()->notify_correlation_id); ev_notif.set_notify_correlation_id(i.get()->notify_correlation_id);
ev_notif.set_notify_uri(i.get()->notify_uri); // Direct subscription
// ev_notif.set_subs_change_notify_correlation_id(i.get()->notify_uri); // ev_notif.set_subs_change_notify_correlation_id(i.get()->notify_uri);
oai::amf::model::AmfEventReport event_report = {}; oai::amf::model::AmfEventReport event_report = {};
...@@ -3293,13 +3291,12 @@ void amf_n1::handle_ue_registration_state_change( ...@@ -3293,13 +3291,12 @@ void amf_n1::handle_ue_registration_state_change(
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:
// itti_msg->notif_id = "";
itti_msg->http_version = 1; itti_msg->http_version = 1;
for (auto i : subscriptions) { for (auto i : subscriptions) {
event_notification ev_notif = {}; event_notification ev_notif = {};
ev_notif.set_notify_correlation_id(i.get()->notify_correlation_id); ev_notif.set_notify_correlation_id(i.get()->notify_correlation_id);
ev_notif.set_notify_uri(i.get()->notify_uri); // Direct subscription
// ev_notif.set_subs_change_notify_correlation_id(i.get()->notify_uri); // ev_notif.set_subs_change_notify_correlation_id(i.get()->notify_uri);
oai::amf::model::AmfEventReport event_report = {}; oai::amf::model::AmfEventReport event_report = {};
...@@ -3361,13 +3358,12 @@ void amf_n1::handle_ue_connectivity_state_change( ...@@ -3361,13 +3358,12 @@ void amf_n1::handle_ue_connectivity_state_change(
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:
// itti_msg->notif_id = "";
itti_msg->http_version = 1; itti_msg->http_version = 1;
for (auto i : subscriptions) { for (auto i : subscriptions) {
event_notification ev_notif = {}; event_notification ev_notif = {};
ev_notif.set_notify_correlation_id(i.get()->notify_correlation_id); ev_notif.set_notify_correlation_id(i.get()->notify_correlation_id);
ev_notif.set_notify_uri(i.get()->notify_uri); // Direct subscription
// ev_notif.set_subs_change_notify_correlation_id(i.get()->notify_uri); // ev_notif.set_subs_change_notify_correlation_id(i.get()->notify_uri);
oai::amf::model::AmfEventReport event_report = {}; oai::amf::model::AmfEventReport event_report = {};
......
...@@ -530,8 +530,7 @@ void amf_n11::handle_itti_message( ...@@ -530,8 +530,7 @@ void amf_n11::handle_itti_message(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n11::handle_itti_message(itti_sbi_notify_subscribed_event& itti_msg) { void amf_n11::handle_itti_message(itti_sbi_notify_subscribed_event& itti_msg) {
Logger::amf_n11().debug( Logger::amf_n11().debug("Send notification for the subscribed events");
"Send notification for the subscribed event to the subscription");
for (auto i : itti_msg.event_notifs) { for (auto i : itti_msg.event_notifs) {
// Fill the json part // Fill the json part
...@@ -564,7 +563,7 @@ void amf_n11::handle_itti_message(itti_sbi_notify_subscribed_event& itti_msg) { ...@@ -564,7 +563,7 @@ void amf_n11::handle_itti_message(itti_sbi_notify_subscribed_event& itti_msg) {
std::string body = json_data.dump(); std::string body = json_data.dump();
std::string response_data; std::string response_data;
std::string url = i.get_notify_correlation_id(); std::string url = i.get_notify_uri();
curl_http_client(url, "POST", body, response_data); curl_http_client(url, "POST", body, response_data);
// TODO: process the response // TODO: process the response
} }
...@@ -636,10 +635,10 @@ void amf_n11::handle_post_sm_context_response_error( ...@@ -636,10 +635,10 @@ void amf_n11::handle_post_sm_context_response_error(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n11::curl_http_client( void amf_n11::curl_http_client(
std::string remoteUri, std::string jsonData, std::string n1SmMsg, std::string remote_uri, std::string jsonData, std::string n1SmMsg,
std::string n2SmMsg, std::string supi, uint8_t pdu_session_id, std::string n2SmMsg, std::string supi, uint8_t pdu_session_id,
uint8_t http_version, uint32_t promise_id) { uint8_t http_version, uint32_t promise_id) {
Logger::amf_n11().debug("Call SMF service: %s", remoteUri.c_str()); Logger::amf_n11().debug("Call SMF service: %s", remote_uri.c_str());
uint8_t number_parts = 0; uint8_t number_parts = 0;
mime_parser parser = {}; mime_parser parser = {};
...@@ -696,7 +695,7 @@ void amf_n11::curl_http_client( ...@@ -696,7 +695,7 @@ void amf_n11::curl_http_client(
} }
headers = curl_slist_append(headers, content_type.c_str()); headers = curl_slist_append(headers, content_type.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_URL, remoteUri.c_str()); curl_easy_setopt(curl, CURLOPT_URL, remote_uri.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT_MS); curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT_MS);
curl_easy_setopt(curl, CURLOPT_INTERFACE, amf_cfg.n11.if_name.c_str()); curl_easy_setopt(curl, CURLOPT_INTERFACE, amf_cfg.n11.if_name.c_str());
...@@ -741,7 +740,7 @@ void amf_n11::curl_http_client( ...@@ -741,7 +740,7 @@ void amf_n11::curl_http_client(
http_response_codes_e::HTTP_RESPONSE_CODE_0) { http_response_codes_e::HTTP_RESPONSE_CODE_0) {
// TODO: should be removed // TODO: should be removed
Logger::amf_n11().error( Logger::amf_n11().error(
"Cannot get response when calling %s", remoteUri.c_str()); "Cannot get response when calling %s", remote_uri.c_str());
// free curl before returning // free curl before returning
curl_slist_free_all(headers); curl_slist_free_all(headers);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
...@@ -758,7 +757,7 @@ void amf_n11::curl_http_client( ...@@ -758,7 +757,7 @@ void amf_n11::curl_http_client(
json_data_response = response; json_data_response = response;
} }
Logger::amf_n11().info("Json part %s", json_data_response.c_str()); Logger::amf_n11().info("JSON part %s", json_data_response.c_str());
if ((static_cast<http_response_codes_e>(httpCode) != if ((static_cast<http_response_codes_e>(httpCode) !=
http_response_codes_e::HTTP_RESPONSE_CODE_200_OK) && http_response_codes_e::HTTP_RESPONSE_CODE_200_OK) &&
...@@ -784,7 +783,7 @@ void amf_n11::curl_http_client( ...@@ -784,7 +783,7 @@ void amf_n11::curl_http_client(
response_data = nlohmann::json::parse(json_data_response); response_data = nlohmann::json::parse(json_data_response);
} catch (nlohmann::json::exception& e) { } catch (nlohmann::json::exception& e) {
Logger::amf_n11().warn( Logger::amf_n11().warn(
"Could not get Json content from the response"); "Could not get JSON content from the response");
// Set the default Cause // Set the default Cause
response_data["error"]["cause"] = "504 Gateway Timeout"; response_data["error"]["cause"] = "504 Gateway Timeout";
} }
...@@ -827,7 +826,7 @@ void amf_n11::curl_http_client( ...@@ -827,7 +826,7 @@ void amf_n11::curl_http_client(
try { try {
response_data = nlohmann::json::parse(json_data_response); response_data = nlohmann::json::parse(json_data_response);
} catch (nlohmann::json::exception& e) { } catch (nlohmann::json::exception& e) {
Logger::amf_n11().warn("Could not get Json content from the response"); Logger::amf_n11().warn("Could not get JSON content from the response");
curl_slist_free_all(headers); curl_slist_free_all(headers);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
curl_global_cleanup(); curl_global_cleanup();
...@@ -1333,7 +1332,7 @@ bool amf_n11::send_ue_authentication_request( ...@@ -1333,7 +1332,7 @@ bool amf_n11::send_ue_authentication_request(
"UE Authentication, response from AUSF\n, %s ", tmp.c_str()); "UE Authentication, response from AUSF\n, %s ", tmp.c_str());
} catch (nlohmann::json::exception& e) { } catch (nlohmann::json::exception& e) {
Logger::amf_n11().warn( Logger::amf_n11().warn(
"UE Authentication, could not parse Json from the AUSF " "UE Authentication, could not parse JSON from the AUSF "
"response"); "response");
// TODO: error handling // TODO: error handling
return false; return false;
...@@ -1355,14 +1354,15 @@ bool amf_n11::send_ue_authentication_request( ...@@ -1355,14 +1354,15 @@ bool amf_n11::send_ue_authentication_request(
//----------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------
// From AMF_N1, need to be reworked // From AMF_N1, need to be reworked
void amf_n11::curl_http_client( void amf_n11::curl_http_client(
std::string remoteUri, std::string Method, std::string msgBody, std::string remote_uri, std::string method, std::string msg_body,
std::string& response, uint8_t http_version) { std::string& response, uint8_t http_version) {
Logger::amf_n11().info("Send HTTP message with body %s", msgBody.c_str()); Logger::amf_n11().info("Send HTTP message to %s", remote_uri.c_str());
Logger::amf_n11().info("HTTP message Body: %s", msg_body.c_str());
uint32_t str_len = msgBody.length(); uint32_t str_len = msg_body.length();
char* body_data = (char*) malloc(str_len + 1); char* body_data = (char*) malloc(str_len + 1);
memset(body_data, 0, str_len + 1); memset(body_data, 0, str_len + 1);
memcpy((void*) body_data, (void*) msgBody.c_str(), str_len); memcpy((void*) body_data, (void*) msg_body.c_str(), str_len);
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);
CURL* curl = curl_easy_init(); CURL* curl = curl_easy_init();
...@@ -1370,21 +1370,22 @@ void amf_n11::curl_http_client( ...@@ -1370,21 +1370,22 @@ void amf_n11::curl_http_client(
if (curl) { if (curl) {
CURLcode res = {}; CURLcode res = {};
struct curl_slist* headers = nullptr; struct curl_slist* headers = nullptr;
if (!Method.compare("POST") || !Method.compare("PATCH") || if ((method.compare("POST") == 0) or (method.compare("PATCH") == 0) or
!Method.compare("PUT")) { (method.compare("PUT") == 0)) {
std::string content_type = "Content-Type: application/json"; std::string content_type = "Content-Type: application/json";
headers = curl_slist_append(headers, content_type.c_str()); headers = curl_slist_append(headers, content_type.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
} }
curl_easy_setopt(curl, CURLOPT_URL, remoteUri.c_str()); curl_easy_setopt(curl, CURLOPT_URL, remote_uri.c_str());
if (!Method.compare("POST")) if (method.compare("POST") == 0)
curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1); curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1);
else if (!Method.compare("PATCH")) else if (method.compare("PATCH") == 0)
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PATCH"); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PATCH");
else if (!Method.compare("PUT")) { else if (method.compare("PUT") == 0) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
} else } else
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT_MS); curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT_MS);
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1); curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1);
curl_easy_setopt(curl, CURLOPT_INTERFACE, amf_cfg.n11.if_name.c_str()); curl_easy_setopt(curl, CURLOPT_INTERFACE, amf_cfg.n11.if_name.c_str());
...@@ -1407,9 +1408,9 @@ void amf_n11::curl_http_client( ...@@ -1407,9 +1408,9 @@ void amf_n11::curl_http_client(
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &callback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, httpData.get()); curl_easy_setopt(curl, CURLOPT_WRITEDATA, httpData.get());
curl_easy_setopt(curl, CURLOPT_HEADERDATA, httpHeaderData.get()); curl_easy_setopt(curl, CURLOPT_HEADERDATA, httpHeaderData.get());
if (!Method.compare("POST") || !Method.compare("PATCH") || if ((method.compare("POST") == 0) or (method.compare("PATCH") == 0) or
!Method.compare("PUT")) { (method.compare("PUT") == 0)) {
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, msgBody.length()); curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, msg_body.length());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body_data); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body_data);
} }
...@@ -1421,11 +1422,11 @@ void amf_n11::curl_http_client( ...@@ -1421,11 +1422,11 @@ void amf_n11::curl_http_client(
std::string json_data_response = {}; std::string json_data_response = {};
std::string resMsg = {}; std::string resMsg = {};
bool is_response_ok = true; bool is_response_ok = true;
Logger::amf_n11().info("Get response with httpcode (%d)", httpCode); Logger::amf_n11().info("Get response with HTTP code (%d)", httpCode);
if (httpCode == 0) { if (httpCode == 0) {
Logger::amf_n11().info( Logger::amf_n11().info(
"Cannot get response when calling %s", remoteUri.c_str()); "Cannot get response when calling %s", remote_uri.c_str());
// free curl before returning // free curl before returning
curl_slist_free_all(headers); curl_slist_free_all(headers);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
...@@ -1449,7 +1450,7 @@ void amf_n11::curl_http_client( ...@@ -1449,7 +1450,7 @@ void amf_n11::curl_http_client(
try { try {
response_data = nlohmann::json::parse(json_data_response); response_data = nlohmann::json::parse(json_data_response);
} catch (nlohmann::json::exception& e) { } catch (nlohmann::json::exception& e) {
Logger::amf_n11().info("Could not get Json content from the response"); Logger::amf_n11().info("Could not get JSON content from the response");
// Set the default Cause // Set the default Cause
response_data["error"]["cause"] = "504 Gateway Timeout"; response_data["error"]["cause"] = "504 Gateway Timeout";
} }
......
...@@ -41,5 +41,6 @@ void amf_subscription::display() { ...@@ -41,5 +41,6 @@ void amf_subscription::display() {
if (supi_is_set) Logger::amf_app().debug("\tSUPI: %s", supi.c_str()); if (supi_is_set) Logger::amf_app().debug("\tSUPI: %s", supi.c_str());
Logger::amf_app().debug( Logger::amf_app().debug(
"\tNotify Correlation ID: %s", notify_correlation_id.c_str()); "\tNotify Correlation ID: %s", notify_correlation_id.c_str());
Logger::amf_app().debug("\tNotify URI: %s", notify_uri.c_str());
Logger::amf_app().debug("\tNF ID: %s", nf_id.c_str()); Logger::amf_app().debug("\tNF ID: %s", nf_id.c_str());
}; };
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