Commit 4af36547 authored by chen2022's avatar chen2022

amf gnb,ue接口

parent 28def4c4
......@@ -17,8 +17,9 @@ void AMFApiServer::init(size_t thr) {
m_nonUEN2MessagesCollectionDocumentApiImpl->init();
m_nonUEN2MessagesSubscriptionsCollectionDocumentApiImpl->init();
m_subscriptionsCollectionDocumentApiImpl->init();
m_amfToDataApiImpl->init();
m_testSignallingApiImpl->init();
Logger::amf_server().debug("Initiate AMF server endpoints done!");
}
......@@ -59,7 +60,10 @@ void AMFApiServer::start() {
if (m_testSignallingApiImpl != nullptr)
Logger::amf_server().debug(
"AMF handler for TestSignallingApiImpl");
if (m_amfToDataApiImpl != nullptr)
Logger::amf_server().debug(
"AMF handler for AmfToDataApiImpl");
m_httpEndpoint->setHandler(m_router->handler());
m_httpEndpoint->serve();
}
......
......@@ -16,11 +16,16 @@
#include "NonUEN2MessagesCollectionDocumentApiImpl.h"
#include "NonUEN2MessagesSubscriptionsCollectionDocumentApiImpl.h"
#include "SubscriptionsCollectionDocumentApiImpl.h"
#include "AmfToDataApiImpl.h"
#include "TestSignallingApiImpl.h"
#define PISTACHE_SERVER_THREADS 2
#define PISTACHE_SERVER_MAX_PAYLOAD 32768
#define GNBS_NUM 20 //返回基站数
#define UES_NUM 20 //返回ue数
#include "amf_app.hpp"
......@@ -65,6 +70,10 @@ class AMFApiServer {
m_testSignallingApiImpl =
std::make_shared<TestSignallingApiImpl>(
m_router, amf_app_inst);
m_amfToDataApiImpl =
std::make_shared<AmfToDataApiImpl>(
m_router, amf_app_inst);
}
void init(size_t thr = 1);
......@@ -97,4 +106,7 @@ class AMFApiServer {
std::shared_ptr<TestSignallingApiImpl>
m_testSignallingApiImpl;
};
std::shared_ptr<AmfToDataApiImpl>
m_amfToDataApiImpl;
};
\ No newline at end of file
#include "AmfToDataApi.h"
#include "Helpers.h"
#include <nlohmann/json.hpp>
#include "logger.hpp"
namespace oai {
namespace amf {
namespace api {
using namespace org::openapitools::server::helpers;
AmfToDataApi::AmfToDataApi(
std::shared_ptr<Pistache::Rest::Router> rtr) {
router = rtr;
}
void AmfToDataApi::init() {
setupRoutes();
}
void AmfToDataApi::setupRoutes() {
using namespace Pistache::Rest;
//获取gnb数列表
Routes::Get(
*router, base + "/v1/query_connected_gnbs/",
Routes::bind(&AmfToDataApi::gnbs_get_am_data_handler, this));
router->addCustomHandler(Routes::bind(&AmfToDataApi::gnbs_default_handler, this));
//获取ue数列表
Routes::Get(
*router, base + "/v1/query_connected_ues/",
Routes::bind(&AmfToDataApi::ues_get_am_data_handler, this));
router->addCustomHandler(Routes::bind(&AmfToDataApi::ues_default_handler, this));
}
//获取gnb数列表
void AmfToDataApi::gnbs_get_am_data_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
//Logger::amf_server().info( "==============Api=======获取gnb数列表 =========");
this->gnbs_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 AmfToDataApi::gnbs_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
}
//获取ue数列表
void AmfToDataApi::ues_get_am_data_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
this->ues_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 AmfToDataApi::ues_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
#ifndef AmfToDataApi_H_
#define AmfToDataApi_H_
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/http_headers.h>
#include <pistache/optional.h>
#include <string>
namespace oai {
namespace amf {
namespace api {
class AmfToDataApi {
public:
AmfToDataApi(std::shared_ptr<Pistache::Rest::Router>);
virtual ~AmfToDataApi() {}
void init();
const std::string base = "/openxg-amf/";
private:
void setupRoutes();
std::shared_ptr<Pistache::Rest::Router> router;
//获取gnb数列表
void gnbs_get_am_data_handler(
const Pistache::Rest::Request &request,
Pistache::Http::ResponseWriter response);
void gnbs_default_handler(
const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
virtual void gnbs_get_am_data(
Pistache::Http::ResponseWriter &response)=0;
//获取ue数列表
void ues_get_am_data_handler(
const Pistache::Rest::Request &request,
Pistache::Http::ResponseWriter response);
void ues_default_handler(
const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
virtual void ues_get_am_data(
Pistache::Http::ResponseWriter &response)=0;
};
} // namespace api
} // namespace amf
} // namespace oai
#endif /* AmfToDataApi_H_ */
#include "AmfToDataApiImpl.h"
#include <nlohmann/json.hpp>
#include "AMFApiServer.hpp"
#include "amf_statistics.hpp"
#include <string>
#include <iostream>
using namespace std;
extern statistics stacs;
namespace oai {
namespace amf {
namespace api {
AmfToDataApiImpl::AmfToDataApiImpl(
std::shared_ptr<Pistache::Rest::Router> rtr,
amf_application::amf_app* amf_app_inst)
: AmfToDataApi(rtr), m_amf_app(amf_app_inst) {}
//获取gnb列表
void AmfToDataApiImpl::gnbs_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 (stacs.gnbs.size() > 0) {
for (int i = 0; i < stacs.gnbs.size(); i++) {
json_array[i]["gnb_name"] = stacs.gnbs[i].gnb_name.c_str();
json_array[i]["gnb_plmn"] = (stacs.gnbs[i].mcc + stacs.gnbs[i].mnc).c_str();
json_array[i]["gnb_tac"] = stacs.gnbs[i].tac;
if(GNBS_NUM==i+1){
break;
}
};
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;
}
}
//获取ues列表
void AmfToDataApiImpl::ues_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();
//Logger::amf_server().info("=====impl========ues==========");
if (stacs.ue_infos.size() > 0) {
response_data_json["code"] = 200;
response_data_json["msg"]= "success";
//ues
int j = 0;
for (auto const& ue : stacs.ue_infos) {
//原先
// Logger::amf_server().info(
// "-|%7d|%22s|%18s|%15s|%16d|%11d|%9s|%7d|", j + 1,
// ue.second.registerStatus.c_str(), ue.second.imsi.c_str(),
// ue.second.guti.c_str(), ue.second.ranid, ue.second.amfid,
// (ue.second.mcc + ue.second.mnc).c_str(), ue.second.cellId);
// j++;
//原先
json_array[j]["ue_Imsi"] = ue.second.imsi.c_str();
json_array[j]["ue_5GMM-state"] = ue.second.registerStatus.c_str();
j++;
if(GNBS_NUM==j){
break;
}
}
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 amf
} // namespace oai
#ifndef AMFTODATA_API_IMPL_H_
#define AMFTODATA_API_IMPL_H_
#include <pistache/endpoint.h>
#include <pistache/http.h>
#include <pistache/router.h>
#include <memory>
#include <pistache/optional.h>
#include <string>
#include <amf_app.hpp>
#include <AmfToDataApi.h>
#include <map>
namespace oai {
namespace amf {
namespace api {
class AmfToDataApiImpl
: public oai::amf::api::AmfToDataApi {
public:
AmfToDataApiImpl(
std::shared_ptr<Pistache::Rest::Router>,
amf_application::amf_app* amf_app_inst);
~AmfToDataApiImpl() {}
//获取gnb列表
void gnbs_get_am_data(
Pistache::Http::ResponseWriter &response);
//获取gnb列表
void ues_get_am_data(
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