Commit cf408440 authored by Chenyu's avatar Chenyu

amf3GppAccessRegistration tested ok

parent 4c919467
build/UDM/
.vscode/
...@@ -79,6 +79,8 @@ void Logger::_init(const char *app, const bool log_stdout, ...@@ -79,6 +79,8 @@ void Logger::_init(const char *app, const bool log_stdout,
// m_amf_server = new _Logger("amf_server", m_sinks, ss.str().c_str()); // m_amf_server = new _Logger("amf_server", m_sinks, ss.str().c_str());
// m_task_amf_n2 = new _Logger("task_amf_n2", m_sinks, ss.str().c_str()); // m_task_amf_n2 = new _Logger("task_amf_n2", m_sinks, ss.str().c_str());
m_udm_ueau = new _Logger("udm_ueau", m_sinks, ss.str().c_str()); m_udm_ueau = new _Logger("udm_ueau", m_sinks, ss.str().c_str());
m_udm_uecm = new _Logger("udm_uecm", m_sinks, ss.str().c_str());
m_udm_sdm = new _Logger("udm_sdm", m_sinks, ss.str().c_str());
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
...@@ -95,6 +95,8 @@ public: ...@@ -95,6 +95,8 @@ public:
// static _Logger &amf_server() { return *singleton().m_amf_server; } // static _Logger &amf_server() { return *singleton().m_amf_server; }
// static _Logger &task_amf_n2() { return *singleton().m_task_amf_n2; } // static _Logger &task_amf_n2() { return *singleton().m_task_amf_n2; }
static _Logger &udm_ueau() { return *singleton().m_udm_ueau; } static _Logger &udm_ueau() { return *singleton().m_udm_ueau; }
static _Logger &udm_uecm() { return *singleton().m_udm_uecm; }
static _Logger &udm_sdm() { return *singleton().m_udm_sdm; }
private: private:
static Logger *m_singleton; static Logger *m_singleton;
...@@ -127,6 +129,8 @@ private: ...@@ -127,6 +129,8 @@ private:
// _Logger *m_amf_server; // _Logger *m_amf_server;
// _Logger *m_task_amf_n2; // _Logger *m_task_amf_n2;
_Logger *m_udm_ueau; _Logger *m_udm_ueau;
_Logger *m_udm_uecm;
_Logger *m_udm_sdm;
}; };
#endif #endif
...@@ -11,6 +11,12 @@ ...@@ -11,6 +11,12 @@
*/ */
#include "AMFRegistrationFor3GPPAccessApiImpl.h" #include "AMFRegistrationFor3GPPAccessApiImpl.h"
#include "udm_config.hpp"
#include "logger.hpp"
#include "curl.hpp"
using namespace config;
extern config::udm_config udm_cfg;
namespace org { namespace org {
namespace openapitools { namespace openapitools {
...@@ -23,8 +29,48 @@ AMFRegistrationFor3GPPAccessApiImpl::AMFRegistrationFor3GPPAccessApiImpl(std::sh ...@@ -23,8 +29,48 @@ AMFRegistrationFor3GPPAccessApiImpl::AMFRegistrationFor3GPPAccessApiImpl(std::sh
: AMFRegistrationFor3GPPAccessApi(rtr) : AMFRegistrationFor3GPPAccessApi(rtr)
{ } { }
void AMFRegistrationFor3GPPAccessApiImpl::_3_gpp_registration(const std::string &ueId, const Amf3GppAccessRegistration &amf3GppAccessRegistration, Pistache::Http::ResponseWriter &response) { void AMFRegistrationFor3GPPAccessApiImpl::xg_3gpp_registration(const std::string &ueId, const Amf3GppAccessRegistration &amf3GppAccessRegistration, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
std::string udr_ip =
std::string(inet_ntoa(*((struct in_addr *)&udm_cfg.nudr.addr4)));
std::string udr_port = std::to_string(udm_cfg.nudr.port);
std::string remoteUri;
std::string Method;
std::string msgBody;
std::string Response;
nlohmann::json j_ProblemDetails;
ProblemDetails m_ProblemDetails;
// UDR GET interface ----- get authentication related info--------------------
remoteUri = udr_ip + ":" + udr_port + "/nudr-dr/v2/subscription-data/" + ueId + "/context-data/amf-3gpp-access";
Logger::udm_uecm().debug("PUT Request:" + remoteUri);
Method = "PUT";
nlohmann::json amf3GppAccessRegistration_j;
to_json(amf3GppAccessRegistration_j, amf3GppAccessRegistration);
long http_code;
http_code = Curl::curl_http_client(remoteUri, Method, amf3GppAccessRegistration_j.dump(), Response);
nlohmann::json response_data = {};
try {
Logger::udm_uecm().debug("PUT Reponse:" + Response);
response_data = nlohmann::json::parse(Response.c_str());
} catch (nlohmann::json::exception &e) { // error handling
Logger::udm_uecm().info("Could not get Json content from UDR response");
m_ProblemDetails.setCause("USER_NOT_FOUND");
m_ProblemDetails.setStatus(404);
m_ProblemDetails.setDetail("User " + ueId + " not found in Database");
to_json(j_ProblemDetails, m_ProblemDetails);
Logger::udm_uecm().error("User " + ueId + " not found in Database");
Logger::udm_uecm().info("Send 404 Not_Found response to client");
response.send(Pistache::Http::Code::Not_Found, j_ProblemDetails.dump());
return;
}
Logger::udm_uecm().debug("http reponse code %d. \n",http_code);
response.send(static_cast<Pistache::Http::Code>(http_code), amf3GppAccessRegistration_j.dump());
} }
} }
......
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
AMFRegistrationFor3GPPAccessApiImpl(std::shared_ptr<Pistache::Rest::Router>); AMFRegistrationFor3GPPAccessApiImpl(std::shared_ptr<Pistache::Rest::Router>);
~AMFRegistrationFor3GPPAccessApiImpl() {} ~AMFRegistrationFor3GPPAccessApiImpl() {}
void _3_gpp_registration(const std::string &ueId, const Amf3GppAccessRegistration &amf3GppAccessRegistration, Pistache::Http::ResponseWriter &response); void xg_3gpp_registration(const std::string &ueId, const Amf3GppAccessRegistration &amf3GppAccessRegistration, Pistache::Http::ResponseWriter &response);
}; };
......
...@@ -50,6 +50,9 @@ ...@@ -50,6 +50,9 @@
#include "DeleteAuthApiImpl.h" #include "DeleteAuthApiImpl.h"
#include "GenerateAuthDataApiImpl.h" #include "GenerateAuthDataApiImpl.h"
#include "SMFSmfRegistrationApiImpl.h"
#include "AMFRegistrationFor3GPPAccessApiImpl.h"
#include "options.hpp" #include "options.hpp"
#include "udm_config.hpp" #include "udm_config.hpp"
...@@ -92,6 +95,7 @@ static void setUpUnixSignals(std::vector<int> quitSignals) { ...@@ -92,6 +95,7 @@ static void setUpUnixSignals(std::vector<int> quitSignals) {
using namespace oai::udm::api; using namespace oai::udm::api;
using namespace config; using namespace config;
using namespace org::openapitools::server::api;
udm_config udm_cfg; udm_config udm_cfg;
...@@ -189,6 +193,12 @@ int main(int argc, char **argv) { ...@@ -189,6 +193,12 @@ int main(int argc, char **argv) {
GenerateAuthDataApiImpl GenerateAuthDataApiserver(router); GenerateAuthDataApiImpl GenerateAuthDataApiserver(router);
GenerateAuthDataApiserver.init(); GenerateAuthDataApiserver.init();
SMFSmfRegistrationApiImpl SMFSmfRegistrationApiserver(router);
SMFSmfRegistrationApiserver.init();
AMFRegistrationFor3GPPAccessApiImpl AMFRegistrationFor3GPPAccessApiserver(router);
AMFRegistrationFor3GPPAccessApiserver.init();
httpEndpoint->setHandler(router->handler()); httpEndpoint->setHandler(router->handler());
httpEndpoint->serve(); httpEndpoint->serve();
......
...@@ -38,7 +38,7 @@ std::size_t callback(const char *in, std::size_t size, std::size_t num, ...@@ -38,7 +38,7 @@ std::size_t callback(const char *in, std::size_t size, std::size_t num,
return totalBytes; return totalBytes;
} }
void Curl::curl_http_client(std::string remoteUri, std::string Method, long Curl::curl_http_client(std::string remoteUri, std::string Method,
std::string msgBody, std::string &Response) { std::string msgBody, std::string &Response) {
Logger::udm_ueau().info("Send HTTP message with body %s", msgBody.c_str()); Logger::udm_ueau().info("Send HTTP message with body %s", msgBody.c_str());
...@@ -50,6 +50,7 @@ void Curl::curl_http_client(std::string remoteUri, std::string Method, ...@@ -50,6 +50,7 @@ void Curl::curl_http_client(std::string remoteUri, std::string Method,
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
long httpCode = {0};
if (curl) { if (curl) {
CURLcode res = {}; CURLcode res = {};
...@@ -78,7 +79,6 @@ void Curl::curl_http_client(std::string remoteUri, std::string Method, ...@@ -78,7 +79,6 @@ void Curl::curl_http_client(std::string remoteUri, std::string Method,
udm_cfg.nudr.if_name); udm_cfg.nudr.if_name);
// Response information. // Response information.
long httpCode = {0};
std::unique_ptr<std::string> httpData(new std::string()); std::unique_ptr<std::string> httpData(new std::string());
std::unique_ptr<std::string> httpHeaderData(new std::string()); std::unique_ptr<std::string> httpHeaderData(new std::string());
...@@ -107,7 +107,7 @@ void Curl::curl_http_client(std::string remoteUri, std::string Method, ...@@ -107,7 +107,7 @@ void Curl::curl_http_client(std::string remoteUri, std::string Method,
// free curl before returning // free curl before returning
curl_slist_free_all(headers); curl_slist_free_all(headers);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
return; return httpCode;
} }
nlohmann::json response_data = {}; nlohmann::json response_data = {};
...@@ -117,11 +117,11 @@ void Curl::curl_http_client(std::string remoteUri, std::string Method, ...@@ -117,11 +117,11 @@ void Curl::curl_http_client(std::string remoteUri, std::string Method,
if (response.size() < 1) { if (response.size() < 1) {
Logger::udm_ueau().info("There's no content in the response"); Logger::udm_ueau().info("There's no content in the response");
// TODO: send context response error // TODO: send context response error
return; return httpCode;
} }
Logger::udm_ueau().info("Wrong response code"); Logger::udm_ueau().info("Wrong response code");
return; return httpCode;
} }
else { // httpCode = 200 || httpCode = 201 || httpCode = 204 else { // httpCode = 200 || httpCode = 201 || httpCode = 204
...@@ -184,4 +184,6 @@ void Curl::curl_http_client(std::string remoteUri, std::string Method, ...@@ -184,4 +184,6 @@ void Curl::curl_http_client(std::string remoteUri, std::string Method,
body_data = NULL; body_data = NULL;
} }
fflush(stdout); fflush(stdout);
return httpCode;
} }
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
class Curl { class Curl {
public: public:
/****** curl function ********/ /****** curl function ********/
static void curl_http_client(std::string remoteUri, std::string Method, static long curl_http_client(std::string remoteUri, std::string Method,
std::string msgBody, std::string &Response); std::string msgBody, std::string &Response);
private: private:
......
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