Commit 7ca69347 authored by chen2022's avatar chen2022

核心网smf openxg-smf/v1/uemsg

parent befb9620
#include "SmfToDataApi.h"
#include "Helpers.h"
#include "smf_config.hpp"
extern smf::smf_config smf_cfg;
namespace oai {
namespace smf_server {
namespace api {
using namespace oai::smf_server::helpers;
SmfToDataApi::SmfToDataApi(
std::shared_ptr<Pistache::Rest::Router> rtr) {
router = rtr;
}
void SmfToDataApi::init() {
setupRoutes();
}
void SmfToDataApi::setupRoutes() {
using namespace Pistache::Rest;
//获取uemsg
Routes::Get(
*router, base + "/v1/uemsg/",
Routes::bind(&SmfToDataApi::uemsg_get_am_data_handler, this));
router->addCustomHandler(Routes::bind(&SmfToDataApi::uemsg_default_handler, this));
}
//获取uemsg
void SmfToDataApi::uemsg_get_am_data_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
this->uemsg_get_am_data(response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
} catch (std::exception &e) {
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void SmfToDataApi::uemsg_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 smf_server
} // namespace oai
#ifndef SmfToDataApi_H_
#define SmfToDataApi_H_
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/http_headers.h>
#include <pistache/optional.h>
namespace oai {
namespace smf_server {
namespace api {
class SmfToDataApi {
public:
SmfToDataApi(std::shared_ptr<Pistache::Rest::Router>);
virtual ~SmfToDataApi() {}
void init();
const std::string base = "/openxg-smf/";
private:
void setupRoutes();
std::shared_ptr<Pistache::Rest::Router> router;
//获取uemsg
void uemsg_get_am_data_handler(
const Pistache::Rest::Request &request,
Pistache::Http::ResponseWriter response);
void uemsg_default_handler(
const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
virtual void uemsg_get_am_data(
Pistache::Http::ResponseWriter &response)=0;
};
} // namespace api
} // namespace smf_server
} // namespace oai
#endif /* SmfToDataApi_H_ */
#include "SmfToDataApiImpl.h"
#include "logger.hpp"
#include <nlohmann/json.hpp>
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#include <vector>
#include <algorithm> //标准算法头文件
#include "smf_procedure.hpp"
#include "smf.h"
// extern smf::smf_procedure proc;
extern smf::smf_config smf_cfg;
extern std::list<UeMsg> UeMsgList;
namespace oai {
namespace smf_server {
namespace api {
SmfToDataApiImpl::SmfToDataApiImpl(
std::shared_ptr<Pistache::Rest::Router> rtr, smf::smf_app* smf_app_inst,
std::string address)
: SmfToDataApi(rtr),
m_smf_app(smf_app_inst),
m_address(address) {}
void SmfToDataApiImpl::uemsg_get_am_data(
Pistache::Http::ResponseWriter& response) {
response.headers().add<Pistache::Http::Header::AccessControlAllowOrigin>("*");
nlohmann::json response_data_json = {};
nlohmann::json json_array = nlohmann::json::array();
if (UeMsgList.size()> 0) {
//if(!UeMsgList.empty())
int i=0;
for (std::list<UeMsg>::iterator it = UeMsgList.begin(); it != UeMsgList.end(); it++)
{
//std::cout << "ueip " << (*it).ueip << " imsi " << it->imsi << " timestamp: " << it->timestamp << std::endl;
json_array[i]["imsi"] = (*it).ueip;
json_array[i]["ueip"] = it->imsi;
json_array[i]["timestamp"] = it->timestamp;
i++;
}
response_data_json["code"] = 200;
response_data_json["msg"]= "success";
response_data_json["data"]= json_array;
}else{
response_data_json["code"] = 201;
response_data_json["msg"]= "没有此数据";
response_data_json["data"]= NULL;
}
try {
response.send(Pistache::Http::Code::Ok, response_data_json.dump());
return;
} catch (nlohmann::json::exception &e) {
response.send(Pistache::Http::Code::Not_Found, response_data_json.dump());
return;
}
}
} // namespace api
} // namespace smf_server
} // namespace oai
#ifndef SMF_TO_DATA_API_IMPL_H_
#define SMF_TO_DATA_API_IMPL_H_
#include <pistache/endpoint.h>
#include <pistache/http.h>
#include <pistache/router.h>
#include <memory>
#include <pistache/optional.h>
#include "smf_app.hpp"
#include "conversions.hpp"
#include <SmfToDataApi.h>
namespace oai {
namespace smf_server {
namespace api {
class SmfToDataApiImpl
: public oai::smf_server::api::SmfToDataApi {
public:
SmfToDataApiImpl(
std::shared_ptr<Pistache::Rest::Router>, smf::smf_app* smf_app_inst,
std::string address);
~SmfToDataApiImpl() {}
//获取uemsg
void uemsg_get_am_data(
Pistache::Http::ResponseWriter& response);
void set_supi(const supi_t& s);
supi_t get_supi() const;
bool ipv4;
struct in_addr
ipv4_address;
private:
smf::smf_app* m_smf_app;
std::string m_address;
supi_t supi;
protected:
};
} // namespace api
} // namespace smf_server
} // namespace oai
#endif
...@@ -83,6 +83,8 @@ void SMFApiServer::init(size_t thr) { ...@@ -83,6 +83,8 @@ void SMFApiServer::init(size_t thr) {
m_individualSubscriptionDocumentApiImpl->init(); m_individualSubscriptionDocumentApiImpl->init();
m_subscriptionsCollectionApiImpl->init(); m_subscriptionsCollectionApiImpl->init();
m_nfStatusNotifyApiImpl->init(); m_nfStatusNotifyApiImpl->init();
m_smfToDataApiImpl->init();
} }
void SMFApiServer::start() { void SMFApiServer::start() {
Logger::smf_api_server().info("HTTP1 server started"); Logger::smf_api_server().info("HTTP1 server started");
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include "IndividualSubscriptionDocumentApiImpl.h" #include "IndividualSubscriptionDocumentApiImpl.h"
#include "SubscriptionsCollectionApiImpl.h" #include "SubscriptionsCollectionApiImpl.h"
#include "NFStatusNotifyApiImpl.h" #include "NFStatusNotifyApiImpl.h"
#include "SmfToDataApiImpl.h"
#include "smf_app.hpp" #include "smf_app.hpp"
...@@ -79,6 +80,8 @@ class SMFApiServer { ...@@ -79,6 +80,8 @@ class SMFApiServer {
m_router, smf_app_inst, m_address); m_router, smf_app_inst, m_address);
m_nfStatusNotifyApiImpl = std::make_shared<NFStatusNotifyApiImpl>( m_nfStatusNotifyApiImpl = std::make_shared<NFStatusNotifyApiImpl>(
m_router, smf_app_inst, m_address); m_router, smf_app_inst, m_address);
m_smfToDataApiImpl = std::make_shared<SmfToDataApiImpl>(
m_router, smf_app_inst, m_address);
} }
void init(size_t thr = 1); void init(size_t thr = 1);
void start(); void start();
...@@ -97,6 +100,8 @@ class SMFApiServer { ...@@ -97,6 +100,8 @@ class SMFApiServer {
std::shared_ptr<SubscriptionsCollectionApiImpl> std::shared_ptr<SubscriptionsCollectionApiImpl>
m_subscriptionsCollectionApiImpl; m_subscriptionsCollectionApiImpl;
std::shared_ptr<NFStatusNotifyApiImpl> m_nfStatusNotifyApiImpl; std::shared_ptr<NFStatusNotifyApiImpl> m_nfStatusNotifyApiImpl;
std::shared_ptr<SmfToDataApiImpl> m_smfToDataApiImpl;
std::string m_address; std::string m_address;
}; };
......
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