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

Add skeleton for N1 Message Notify API (for AMF Re-allocation procedure)

parent 7a5ee444
......@@ -491,6 +491,18 @@ bool amf_app::handle_nf_status_notification(
return true;
}
//------------------------------------------------------------------------------
bool amf_app::handle_n1_message_notification(
std::shared_ptr<itti_sbi_n1_message_notification>& msg,
oai::amf::model::ProblemDetails& problem_details, uint32_t& http_code) {
Logger::amf_app().info(
"Handle a NF status notification from NRF (HTTP version "
"%d)",
msg->http_version);
// TODO
return true;
}
//------------------------------------------------------------------------------
void amf_app::generate_uuid() {
amf_instance_id = to_string(boost::uuids::random_generator()());
......
......@@ -161,6 +161,17 @@ class amf_app {
std::shared_ptr<itti_sbi_notification_data>& msg,
oai::amf::model::ProblemDetails& problem_details, uint8_t& http_code);
/*
* Handle N1 Message Notification
* @param [std::shared_ptr<itti_sbi_n1_message_notification>& ] msg: message
* @param [oai::amf::model::ProblemDetails& ] problem_details
* @param [uint8_t&] http_code
* @return true if handle sucessfully, otherwise return false
*/
bool handle_n1_message_notification(
std::shared_ptr<itti_sbi_n1_message_notification>& msg,
oai::amf::model::ProblemDetails& problem_details, uint32_t& http_code);
/*
* Generate a random UUID for SMF instance
* @param [void]
......
......@@ -89,6 +89,7 @@ typedef enum {
SBI_EVENT_EXPOSURE_REQUEST,
SBI_NOTIFICATION_DATA,
SBI_NOTIFY_SUBSCRIBED_EVENT,
SBI_N1_MESSAGE_NOTIFICATION,
UE_CONTEXT_RELEASE_COMMAND,
NSMF_PDU_SESSION_RELEASE_SM_CTX,
HANDOVER_REQUIRED,
......
......@@ -33,6 +33,7 @@
#include "itti_msg.hpp"
#include "pistache/http.h"
#include "amf_msg.hpp"
#include "N1MessageNotification.h"
using namespace amf_application;
......@@ -115,4 +116,31 @@ class itti_sbi_notify_subscribed_event : public itti_sbi_msg {
std::vector<amf_application::event_notification> event_notifs;
uint8_t http_version;
};
//-----------------------------------------------------------------------------
class itti_sbi_n1_message_notification : public itti_sbi_msg {
public:
itti_sbi_n1_message_notification(const task_id_t orig, const task_id_t dest)
: itti_sbi_msg(SBI_N1_MESSAGE_NOTIFICATION, orig, dest),
notification_msg(),
ue_id(),
http_version(1) {}
itti_sbi_n1_message_notification(const itti_sbi_n1_message_notification& i)
: itti_sbi_msg(i),
notification_msg(i.notification_msg),
ue_id(i.ue_id),
http_version(1) {}
itti_sbi_n1_message_notification(
const itti_sbi_n1_message_notification& i, const task_id_t orig,
const task_id_t dest)
: itti_sbi_msg(i, orig, dest),
notification_msg(i.notification_msg),
ue_id(i.ue_id),
http_version(i.http_version) {}
const char* get_msg_name() { return "SBI_N1_MESSAGE_NOTIFICATION"; };
oai::amf::model::N1MessageNotification notification_msg;
std::string ue_id;
uint8_t http_version;
};
#endif /* ITTI_MSG_SBI_HPP_INCLUDED_ */
......@@ -19,6 +19,7 @@ void AMFApiServer::init(size_t thr) {
m_nonUEN2MessagesSubscriptionsCollectionDocumentApiImpl->init();
m_subscriptionsCollectionDocumentApiImpl->init();
m_subscriptionsCollectionDocumentApiImplEventExposure->init();
m_n1MessageNotifyApiImpl->init();
Logger::amf_server().debug("Initiate AMF Server Endpoints done!");
}
......@@ -63,6 +64,9 @@ void AMFApiServer::start() {
Logger::amf_server().debug(
"AMF handler for SubscriptionsCollectionDocumentApiImplEventExposure");
if (m_n1MessageNotifyApiImpl != nullptr)
Logger::amf_server().debug("AMF handler for N1MessageNotifyApiImpl");
m_httpEndpoint->setHandler(m_router->handler());
m_httpEndpoint->serveThreaded();
}
......
......@@ -18,6 +18,7 @@
#include "NonUEN2MessagesSubscriptionsCollectionDocumentApiImpl.h"
#include "SubscriptionsCollectionDocumentApiImpl.h"
#include "SubscriptionsCollectionDocumentApiImplEventExposure.h"
#include "N1MessageNotifyApiImpl.h"
#define PISTACHE_SERVER_THREADS 2
#define PISTACHE_SERVER_MAX_PAYLOAD 32768
......@@ -68,6 +69,8 @@ class AMFApiServer {
m_subscriptionsCollectionDocumentApiImplEventExposure =
std::make_shared<SubscriptionsCollectionDocumentApiImplEventExposure>(
m_router, amf_app_inst);
m_n1MessageNotifyApiImpl =
std::make_shared<N1MessageNotifyApiImpl>(m_router, amf_app_inst);
}
void init(size_t thr = 1);
......@@ -101,6 +104,7 @@ class AMFApiServer {
m_subscriptionsCollectionDocumentApiImpl;
std::shared_ptr<SubscriptionsCollectionDocumentApiImplEventExposure>
m_subscriptionsCollectionDocumentApiImplEventExposure;
std::shared_ptr<N1MessageNotifyApiImpl> m_n1MessageNotifyApiImpl;
std::string m_address;
};
/**
* Namf_Communication
* AMF Communication Service © 2019, 3GPP Organizational Partners (ARIB, ATIS,
* CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
#include "N1MessageNotifyApi.h"
#include "Helpers.h"
#include "mime_parser.hpp"
#include "logger.hpp"
#include "amf_config.hpp"
extern config::amf_config amf_cfg;
namespace oai {
namespace amf {
namespace api {
using namespace oai::amf::helpers;
using namespace oai::amf::model;
N1MessageNotifyApi::N1MessageNotifyApi(
std::shared_ptr<Pistache::Rest::Router> rtr) {
router = rtr;
}
void N1MessageNotifyApi::init() {
setupRoutes();
}
void N1MessageNotifyApi::setupRoutes() {
using namespace Pistache::Rest;
Routes::Post(
*router,
base + amf_cfg.sbi_api_version +
"/ue-contexts/:ueContextId/n1-message-notify",
Routes::bind(&N1MessageNotifyApi::n1_message_notify_handler, this));
// Default handler, called when a route is not found
router->addCustomHandler(Routes::bind(
&N1MessageNotifyApi::n1_message_notify_default_handler, this));
}
void N1MessageNotifyApi::n1_message_notify_handler(
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response) {
// Getting the path params
auto ueContextId = request.param(":ueContextId").as<std::string>();
Logger::amf_server().debug(
"Received a N1MessageNotification with ue_ctx_id %s",
ueContextId.c_str());
N1MessageNotification n1MessageNotification;
try {
nlohmann::json::parse(request.body()).get_to(n1MessageNotification);
this->receive_n1_message_notification(
ueContextId, n1MessageNotification, response);
} catch (nlohmann::detail::exception& e) {
// send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::exception& e) {
// send a 500 error
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void N1MessageNotifyApi::n1_message_notify_default_handler(
const Pistache::Rest::Request&, Pistache::Http::ResponseWriter response) {
response.send(
Pistache::Http::Code::Not_Found, "The requested method does not exist");
}
} // namespace api
} // namespace amf
} // namespace oai
/**
* Namf_Communication
* AMF Communication Service © 2019, 3GPP Organizational Partners (ARIB, ATIS,
* CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
/*
* N1MessageNotifyApi.h
*
*
*/
#ifndef N1MessageNotifyApi_H_
#define N1MessageNotifyApi_H_
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/http_headers.h>
#include <pistache/optional.h>
#include "N1MessageNotification.h"
#include "ProblemDetails.h"
#include <string>
namespace oai {
namespace amf {
namespace api {
using namespace oai::amf::model;
class N1MessageNotifyApi {
public:
N1MessageNotifyApi(std::shared_ptr<Pistache::Rest::Router>);
virtual ~N1MessageNotifyApi() {}
void init();
const std::string base = "/namf-comm/";
private:
void setupRoutes();
void n1_message_notify_handler(
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response);
void n1_message_notify_default_handler(
const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response);
std::shared_ptr<Pistache::Rest::Router> router;
virtual void receive_n1_message_notification(
const std::string& ueContextId,
const N1MessageNotification& notificationData,
Pistache::Http::ResponseWriter& response) = 0;
};
} // namespace api
} // namespace amf
} // namespace oai
#endif /* N1MessageNotifyApi_H_ */
/**
* Namf_Communication
* AMF Communication Service © 2019, 3GPP Organizational Partners (ARIB, ATIS,
* CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
#include "N1MessageNotifyApiImpl.h"
#include "itti_msg_sbi.hpp"
using namespace amf_application;
namespace oai {
namespace amf {
namespace api {
using namespace oai::amf::model;
N1MessageNotifyApiImpl::N1MessageNotifyApiImpl(
std::shared_ptr<Pistache::Rest::Router> rtr,
amf_application::amf_app* amf_app_inst)
: N1MessageNotifyApi(rtr), m_amf_app(amf_app_inst) {}
void N1MessageNotifyApiImpl::receive_n1_message_notification(
const std::string& ueContextId,
const N1MessageNotification& notificationData,
Pistache::Http::ResponseWriter& response) {
Logger::amf_server().debug("Receive N1MessageNotify, handling...");
Pistache::Http::Code code = Pistache::Http::Code::Ok;
std::string supi = ueContextId;
Logger::amf_server().debug("SUPI (%s)", supi.c_str());
// Handle the message in amf_app
std::shared_ptr<itti_sbi_n1_message_notification> itti_msg =
std::make_shared<itti_sbi_n1_message_notification>(
TASK_AMF_SBI, TASK_AMF_APP);
itti_msg->notification_msg = notificationData;
itti_msg->ue_id = supi;
itti_msg->http_version = 1;
oai::amf::model::ProblemDetails problem_details = {};
uint32_t http_code = {0};
if (m_amf_app->handle_n1_message_notification(
itti_msg, problem_details, http_code)) {
response.send(Pistache::Http::Code(204));
} else {
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType("application/problem+json"));
nlohmann::json json_data = {};
to_json(json_data, problem_details);
response.send(Pistache::Http::Code(http_code), json_data.dump().c_str());
}
}
} // namespace api
} // namespace amf
} // namespace oai
/**
* Namf_Communication
* AMF Communication Service © 2019, 3GPP Organizational Partners (ARIB, ATIS,
* CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator
* (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
/*
* N1MessageNotifyApiImpl.h
*
*
*/
#ifndef N1_MESSAGE_NOTIFY_API_IMPL_H_
#define N1_MESSAGE_NOTIFY_API_IMPL_H_
#include <pistache/endpoint.h>
#include <pistache/http.h>
#include <pistache/router.h>
#include <memory>
#include <N1MessageNotifyApi.h>
#include <pistache/optional.h>
#include "ProblemDetails.h"
#include "amf_app.hpp"
namespace oai {
namespace amf {
namespace api {
using namespace oai::amf::model;
using namespace oai::amf::api;
class N1MessageNotifyApiImpl : public N1MessageNotifyApi {
public:
N1MessageNotifyApiImpl(
std::shared_ptr<Pistache::Rest::Router>,
amf_application::amf_app* amf_app_inst);
~N1MessageNotifyApiImpl() {}
void receive_n1_message_notification(
const std::string& ueContextId,
const N1MessageNotification& notificationData,
Pistache::Http::ResponseWriter& response);
private:
amf_application::amf_app* m_amf_app;
};
} // namespace api
} // namespace amf
} // namespace oai
#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