Commit b7f40f51 authored by yangjian's avatar yangjian

add amf Subscriptions API

parent 76940b25
...@@ -33,6 +33,8 @@ email: contact@openairinterface.org ...@@ -33,6 +33,8 @@ email: contact@openairinterface.org
#include "curl.hpp" #include "curl.hpp"
#include "itti.hpp" #include "itti.hpp"
#include "amf_sbi.hpp"
using namespace amf_application; using namespace amf_application;
using namespace config; using namespace config;
...@@ -40,10 +42,12 @@ extern itti_mw* itti_inst; ...@@ -40,10 +42,12 @@ extern itti_mw* itti_inst;
extern amf_config amf_cfg; extern amf_config amf_cfg;
extern amf_app* nwdaf_app_inst; extern amf_app* nwdaf_app_inst;
void nwdaf_app_task(void*); amf_sbi *amf_exposure_inst = nullptr;
void amf_app_task(void*);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void nwdaf_app_task(void*) { void amf_app_task(void*) {
const task_id_t task_id = TASK_AMF_APP; const task_id_t task_id = TASK_AMF_APP;
itti_inst->notify_task_ready(task_id); itti_inst->notify_task_ready(task_id);
do { do {
...@@ -78,7 +82,7 @@ void nwdaf_app_task(void*) { ...@@ -78,7 +82,7 @@ void nwdaf_app_task(void*) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
amf_app::amf_app() { amf_app::amf_app() {
Logger::amf_app().startup("Creating AMF-AGENT application functionality layer"); Logger::amf_app().startup("Creating AMF-AGENT application functionality layer");
if (itti_inst->create_task(TASK_AMF_APP, nwdaf_app_task, nullptr)) { if (itti_inst->create_task(TASK_AMF_APP, amf_app_task, nullptr)) {
Logger::amf_app().error("Cannot create task TASK_AMF_APP"); Logger::amf_app().error("Cannot create task TASK_AMF_APP");
throw std::runtime_error("Cannot create task TASK_AMF_APP"); throw std::runtime_error("Cannot create task TASK_AMF_APP");
} }
...@@ -93,49 +97,14 @@ amf_app::amf_app() { ...@@ -93,49 +97,14 @@ amf_app::amf_app() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
//std::shared_ptr<nf_message> nwdaf_app::imsi_2_nf_context(const std::string &imsi) const uint32_t amf_app::generate_ev_subscription_id() {
//{ return evsub_id_generator.get_uid();
// std::shared_lock lock(m_nfcontext); }
// //------------------------------------------------------------------------------
// return nfcontext.at(imsi); void amf_app::free_ev_subscription_id(uint32_t uid) {
//} evsub_id_generator.free_uid(uid);
// }
////------------------------------------------------------------------------------
//bool nwdaf_app::is_imsi_2_nf_context(const std::string &imsi) const
//{
// std::shared_lock lock(m_nfcontext);
//
// return bool{nfcontext.count(imsi) > 0};
//}
//
////------------------------------------------------------------------------------
//void nwdaf_app::set_imsi_2_nf_context( const std::string &imsi, const nf_message &msgs)
//{
// std::unique_lock<std::shared_mutex> lock(m_nfcontext);
//
// std::shared_ptr<nf_message> nc;
// if (nfcontext.count(imsi) > 0) {
// nc = nfcontext.at(imsi);
// } else {
// nc = std::shared_ptr<nf_message>(new nf_message());
// }
//
// *(nc.get()) = msgs;
//
// nfcontext[imsi] = nc;
//}
//
////------------------------------------------------------------------------------
//bool nwdaf_app::get_nf_context(std::vector<nf_message> &vec)
//{
// std::shared_lock lock(m_nfcontext);
//
// std::map<std::string, std::shared_ptr<nf_message>>::reverse_iterator iter;
// for(iter = nfcontext.rbegin(); iter != nfcontext.rend(); iter++)
// {
// vec.push_back(*(iter->second.get()));
// }
//
// return true;
//}
...@@ -34,8 +34,14 @@ email: contact@openairinterface.org ...@@ -34,8 +34,14 @@ email: contact@openairinterface.org
#include "config.hpp" #include "config.hpp"
#include "itti_msg_amf_app.hpp" #include "itti_msg_amf_app.hpp"
#include "uint_generator.hpp"
#include "AmfCreatedEventSubscription.h"
using namespace config; using namespace config;
using namespace org::openapitools::server::model;
namespace amf_application { namespace amf_application {
...@@ -46,6 +52,10 @@ class amf_app { ...@@ -46,6 +52,10 @@ class amf_app {
amf_app(); amf_app();
~amf_app(); ~amf_app();
uint32_t generate_ev_subscription_id();
void free_ev_subscription_id(uint32_t uid);
// uint32_t handle_event_exposure_subscription(std::shared_ptr<itti_sbi_event_exposure_request> msg);
// context management // context management
// std::shared_ptr<nf_message> imsi_2_nf_context(const std::string &imsi) const; // std::shared_ptr<nf_message> imsi_2_nf_context(const std::string &imsi) const;
...@@ -56,8 +66,12 @@ class amf_app { ...@@ -56,8 +66,12 @@ class amf_app {
private: private:
// context variable // context variable
// std::map<std::string, std::shared_ptr<nf_message>> nfcontext;
// mutable std::shared_mutex m_nfcontext; util::uint_generator<uint32_t> evsub_id_generator;
std::map<uint32_t, std::shared_ptr<AmfCreatedEventSubscription>> amf_event_subscriptions;
mutable std::shared_mutex m_amf_event_subscriptions;
}; };
} // namespace nwdaf_application } // namespace nwdaf_application
......
#include "amf_sbi.hpp"
#ifndef _AMF_SBI_H_
#define _AMF_SBI_H_
namespace amf_application {
class amf_sbi{
//订阅列表 - subId\notifyURI\event
//上下文存储 - 存储订阅之前注册成功的UE信息
};
}
#endif
\ No newline at end of file
#ifndef _ITTI_MSG_SBI_H_
#define _ITTI_MSG_SBI_H_
#include "itti_msg.hpp"
class itti_sbi_msg : public itti_msg {
public:
itti_sbi_msg(const itti_msg_type_t msg_type, const task_id_t origin,
const task_id_t destination)
: itti_msg(msg_type, origin, destination) {}
itti_sbi_msg(const itti_sbi_msg& i) : itti_msg(i) {}
};
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
#include "NamfEventExposureBridgeApiImpl.h" #include "NamfEventExposureBridgeApiImpl.h"
#include "logger.hpp"
namespace org { namespace org {
namespace openapitools { namespace openapitools {
...@@ -13,7 +14,10 @@ NamfEventExposureBridgeApiImpl::NamfEventExposureBridgeApiImpl(const std::shared ...@@ -13,7 +14,10 @@ NamfEventExposureBridgeApiImpl::NamfEventExposureBridgeApiImpl(const std::shared
} }
void NamfEventExposureBridgeApiImpl::notify_bridge(const nlohmann::json &body, Pistache::Http::ResponseWriter &response) { void NamfEventExposureBridgeApiImpl::notify_bridge(const nlohmann::json &body, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "body");
std::string out = body.dump();
Logger::amf_server().info("notify_bridge : %s",out.c_str());
response.send(Pistache::Http::Code::Ok, body.dump());
} }
} }
......
File mode changed from 100755 to 100644
/** /**
* Namf_EventExposure * Namf_EventExposure
* AMF Event Exposure Service © 2021, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved. * AMF Event Exposure Service © 2021, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
* *
* The version of the OpenAPI document: 1.2.0-alpha.2 * The version of the OpenAPI document: 1.2.0-alpha.2
* *
* *
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech * https://openapi-generator.tech
...@@ -11,6 +11,18 @@ ...@@ -11,6 +11,18 @@
*/ */
#include "SubscriptionsCollectionDocumentApiImpl.h" #include "SubscriptionsCollectionDocumentApiImpl.h"
#include "logger.hpp"
#include "amf_app.hpp"
#include "config.hpp"
using namespace amf_application;
using namespace config;
extern amf_app* amf_app_inst;
extern amf_config amf_cfg;
namespace org { namespace org {
namespace openapitools { namespace openapitools {
...@@ -25,7 +37,32 @@ SubscriptionsCollectionDocumentApiImpl::SubscriptionsCollectionDocumentApiImpl(c ...@@ -25,7 +37,32 @@ SubscriptionsCollectionDocumentApiImpl::SubscriptionsCollectionDocumentApiImpl(c
} }
void SubscriptionsCollectionDocumentApiImpl::create_subscription(const AmfCreateEventSubscription &amfCreateEventSubscription, Pistache::Http::ResponseWriter &response) { void SubscriptionsCollectionDocumentApiImpl::create_subscription(const AmfCreateEventSubscription &amfCreateEventSubscription, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
Logger::amf_server().info("NotifyUri: %s",amfCreateEventSubscription.getSubscription().getEventNotifyUri().c_str());
//分配subId
uint32_t subId = amf_app_inst->generate_ev_subscription_id();
//处理event事件
// Send response
AmfCreatedEventSubscription amfCreatedEventSubscription;
amfCreatedEventSubscription.setSubscription(amfCreateEventSubscription.getSubscription());
if (subId != -1) {
amfCreatedEventSubscription.setSubscriptionId(std::to_string(subId));
response.headers().add<Pistache::Http::Header::Location>(
amf_cfg.sbi.addr4 + ":" + std::to_string(amf_cfg.sbi.port) + base + amf_cfg.api_version + "/subscriptions/" + std::to_string(subId)); // Location header
}
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType("application/json"));
nlohmann::json json_data = {};
to_json(json_data, amfCreatedEventSubscription);
response.send(Pistache::Http::Code(201), json_data.dump().c_str());
} }
} }
......
#ifndef _UINT_GENERATOR_H_
#define _UINT_GENERATOR_H_
#include <mutex>
#include <set>
namespace util {
template<class UINT>
class uint_generator {
private:
UINT uid_generator;
std::mutex m_uid_generator;
std::set<UINT> uid_generated;
std::mutex m_uid_generated;
public:
uint_generator() : m_uid_generator(), m_uid_generated() {
uid_generator = 0;
uid_generated = {};
};
uint_generator(uint_generator const&) = delete;
void operator=(uint_generator const&) = delete;
UINT get_uid() {
std::unique_lock<std::mutex> lr(m_uid_generator);
UINT uid = ++uid_generator;
while (true) {
// may happen race conditions here
std::unique_lock<std::mutex> ld(m_uid_generated);
if (uid_generated.count(uid) == 0) {
uid_generated.insert(uid);
ld.unlock();
lr.unlock();
return uid;
}
uid = ++uid_generator;
}
}
void free_uid(UINT uid) {
std::unique_lock<std::mutex> l(m_uid_generated);
uid_generated.erase(uid);
l.unlock();
}
};
}
#endif
\ No newline at end of file
...@@ -35,6 +35,7 @@ typedef enum { ...@@ -35,6 +35,7 @@ typedef enum {
TASK_FIRST = 0, TASK_FIRST = 0,
TASK_ITTI_TIMER = TASK_FIRST, TASK_ITTI_TIMER = TASK_FIRST,
TASK_AMF_APP, TASK_AMF_APP,
TASK_AMF_SBI,
TASK_MAX, TASK_MAX,
TASK_NONE, TASK_NONE,
TASK_ALL = 255 TASK_ALL = 255
...@@ -54,6 +55,8 @@ typedef enum { ...@@ -54,6 +55,8 @@ typedef enum {
ITTI_MSG_TYPE_NONE = -1, ITTI_MSG_TYPE_NONE = -1,
ITTI_MSG_TYPE_FIRST = 0, ITTI_MSG_TYPE_FIRST = 0,
POLLING_GET_INFO = ITTI_MSG_TYPE_FIRST, POLLING_GET_INFO = ITTI_MSG_TYPE_FIRST,
ITTI_SUBSCRIBE,
ITTI_UNSUBSCRIBE,
TIME_OUT, TIME_OUT,
HEALTH_PING, HEALTH_PING,
TERMINATE, TERMINATE,
......
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