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

Implement Unsubscribe operation

parent a4d4a12e
...@@ -407,24 +407,43 @@ evsub_id_t amf_app::handle_event_exposure_subscription( ...@@ -407,24 +407,43 @@ evsub_id_t amf_app::handle_event_exposure_subscription(
std::shared_ptr<amf_subscription> ss = std::shared_ptr<amf_subscription> ss =
std::shared_ptr<amf_subscription>(new amf_subscription()); std::shared_ptr<amf_subscription>(new amf_subscription());
ss.get()->sub_id = evsub_id; ss.get()->sub_id = evsub_id;
// TODO: // TODO:
// if (msg->event_exposure.is_supi_is_set()) { if (msg->event_exposure.is_supi_is_set()) {
// supi64_t supi64 = amf_supi_to_u64(msg->event_exposure.get_supi()); supi64_t supi64 = amf_supi_to_u64(msg->event_exposure.get_supi());
// ss.get()->supi = supi64; ss.get()->supi = supi64;
//} }
// ss.get()->notif_id = msg->event_exposure.get_notif_id(); ss.get()->notify_correlation_id =
// ss.get()->notif_uri = msg->event_exposure.get_notif_uri(); msg->event_exposure.get_notify_correlation_id();
ss.get()->notify_uri = msg->event_exposure.get_notify_uri();
// std::vector<event_subscription_t> event_subscriptions = ss.get()->nf_id = msg->event_exposure.get_nf_id();
// msg->event_exposure.get_event_subs();
std::vector<amf_event_t> event_subscriptions =
msg->event_exposure.get_event_subs();
// store subscription // store subscription
// for (auto i : event_subscriptions) { for (auto i : event_subscriptions) {
// ss.get()->ev_type = i.amf_event; ss.get()->ev_type = i.type;
// add_event_subscription(evsub_id, i.amf_event, ss); add_event_subscription(evsub_id, i.type, ss);
//} }
return evsub_id; return evsub_id;
} }
bool amf_app::handle_event_exposure_delete(const std::string& subscription_id) {
// verify Subscription ID
evsub_id_t sub_id = {};
try {
sub_id = std::stoi(subscription_id);
} catch (const std::exception& err) {
Logger::amf_app().warn(
"Received a Unsubscribe Request, couldn't find the corresponding "
"subscription");
return false;
}
return remove_event_subscription(sub_id);
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool amf_app::handle_nf_status_notification( bool amf_app::handle_nf_status_notification(
std::shared_ptr<itti_sbi_notification_data>& msg, std::shared_ptr<itti_sbi_notification_data>& msg,
...@@ -522,6 +541,26 @@ void amf_app::add_event_subscription( ...@@ -522,6 +541,26 @@ void amf_app::add_event_subscription(
amf_event_subscriptions.emplace(std::make_pair(sub_id, ev), ss); amf_event_subscriptions.emplace(std::make_pair(sub_id, ev), ss);
} }
//---------------------------------------------------------------------------------------------
bool amf_app::remove_event_subscription(evsub_id_t sub_id) {
Logger::amf_app().debug("Remove an Event subscription (Sub ID %d)", sub_id);
std::unique_lock lock(m_amf_event_subscriptions);
for (auto it = amf_event_subscriptions.cbegin();
it != amf_event_subscriptions.cend();) {
if ((uint8_t) std::get<0>(it->first) == (uint32_t) sub_id) {
Logger::amf_app().debug(
"Found an event subscription (Event ID %d)",
(uint8_t) std::get<0>(it->first));
amf_event_subscriptions.erase(it++);
// it = amf_event_subscriptions.erase(it)
return true;
} else {
++it;
}
}
return false;
}
//--------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------
void amf_app::get_ee_subscriptions( void amf_app::get_ee_subscriptions(
amf_event_type_t ev, amf_event_type_t ev,
......
...@@ -140,6 +140,14 @@ class amf_app { ...@@ -140,6 +140,14 @@ class amf_app {
evsub_id_t handle_event_exposure_subscription( evsub_id_t handle_event_exposure_subscription(
std::shared_ptr<itti_sbi_event_exposure_request> msg); std::shared_ptr<itti_sbi_event_exposure_request> msg);
/*
* Handle Unsubscribe Request from an NF
* @param [const std::string&] subscription_id: Subscription ID
* @return true if the subscription is unsubscribed successfully, otherwise
* return false
*/
bool handle_event_exposure_delete(const std::string& subscription_id);
/* /*
* Handle NF status notification (e.g., when an UPF becomes available) * Handle NF status notification (e.g., when an UPF becomes available)
* @param [std::shared_ptr<itti_sbi_notification_data>& ] msg: message * @param [std::shared_ptr<itti_sbi_notification_data>& ] msg: message
...@@ -170,6 +178,13 @@ class amf_app { ...@@ -170,6 +178,13 @@ class amf_app {
evsub_id_t sub_id, amf_event_type_t ev, evsub_id_t sub_id, amf_event_type_t ev,
std::shared_ptr<amf_subscription> ss); std::shared_ptr<amf_subscription> ss);
/*
* Remove an Event Subscription from the list
* @param [const evsub_id_t&] sub_id: Subscription ID
* @return bool
*/
bool remove_event_subscription(evsub_id_t sub_id);
/* /*
* Get a list of subscription associated with a particular event * Get a list of subscription associated with a particular event
* @param [amf_event_t] ev: Event type * @param [amf_event_t] ev: Event type
......
...@@ -43,8 +43,9 @@ class amf_subscription { ...@@ -43,8 +43,9 @@ class amf_subscription {
evsub_id_t sub_id; evsub_id_t sub_id;
amf_event_type_t ev_type; amf_event_type_t ev_type;
supi64_t supi; supi64_t supi;
std::string notif_id; std::string notify_correlation_id;
std::string notif_uri; std::string notify_uri;
std::string nf_id;
}; };
} // namespace amf } // namespace amf
...@@ -29,9 +29,26 @@ IndividualSubscriptionDocumentApiImplEventExposure:: ...@@ -29,9 +29,26 @@ IndividualSubscriptionDocumentApiImplEventExposure::
void IndividualSubscriptionDocumentApiImplEventExposure::delete_subscription( void IndividualSubscriptionDocumentApiImplEventExposure::delete_subscription(
const std::string& subscriptionId, const std::string& subscriptionId,
Pistache::Http::ResponseWriter& response) { Pistache::Http::ResponseWriter& response) {
response.send( Logger::amf_server().info(
Pistache::Http::Code::Ok, "This API has not been implemented yet!\n"); "SubscriptionsCollectionDocumentApiImplEventExposure::delete_"
"subscription");
// Create a message and store the necessary information
Logger::amf_server().debug(
"Delete a subscription with ID %s", subscriptionId.c_str());
if (m_amf_app->handle_event_exposure_delete(subscriptionId)) {
response.send(Pistache::Http::Code::No_Content);
} else {
// Send response
nlohmann::json json_data = {};
oai::amf::model::ProblemDetails problem_details = {};
problem_details.setCause("SUBSCRIPTION_NOT_FOUND");
to_json(json_data, problem_details);
response.send(Pistache::Http::Code::Not_Found, json_data.dump().c_str());
}
} }
void IndividualSubscriptionDocumentApiImplEventExposure::modify_subscription( void IndividualSubscriptionDocumentApiImplEventExposure::modify_subscription(
const std::string& subscriptionId, const std::string& subscriptionId,
const AmfUpdateEventOptionItem& amfUpdateEventOptionItem, const AmfUpdateEventOptionItem& amfUpdateEventOptionItem,
......
...@@ -77,7 +77,7 @@ void SubscriptionsCollectionDocumentApiImplEventExposure::create_subscription( ...@@ -77,7 +77,7 @@ void SubscriptionsCollectionDocumentApiImplEventExposure::create_subscription(
response.headers().add<Pistache::Http::Header::ContentType>( response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType("application/json")); Pistache::Http::Mime::MediaType("application/json"));
response.send(Pistache::Http::Code(201), json_data.dump().c_str()); response.send(Pistache::Http::Code::Created, json_data.dump().c_str());
} }
} // namespace api } // namespace api
......
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