Commit baf935d2 authored by yangjian's avatar yangjian

Add the NWDAF data structure

parent 2d793f10
#include "ContextToNwdafApi.hpp"
namespace oai {
namespace udm {
namespace api {
ContextToNwdafApi::ContextToNwdafApi(
std::shared_ptr<Pistache::Rest::Router> rtr) {
router = rtr;
}
void ContextToNwdafApi::init() { setupRoutes(); }
void ContextToNwdafApi::setupRoutes() {
using namespace Pistache::Rest;
Routes::Get(
*router, base + "/udm-data",
Routes::bind(&ContextToNwdafApi::get_context_to_nwdaf_handler, this));
// Default handler, called when a route is not found
router->addCustomHandler(Routes::bind(
&ContextToNwdafApi::context_to_nwdaf_api_default_handler, this));
}
void ContextToNwdafApi::get_context_to_nwdaf_handler(
const Pistache::Rest::Request &request,
Pistache::Http::ResponseWriter response) {
try {
this->get_context_to_nwdaf(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 ContextToNwdafApi::context_to_nwdaf_api_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 udm
} // namespace oai
#ifndef _CONTEXTTONWDAFAPI_H_
#define _CONTEXTTONWDAFAPI_H_
#include <pistache/http.h>
#include <pistache/http_headers.h>
#include <pistache/optional.h>
#include <pistache/router.h>
#include <string>
namespace oai {
namespace udm {
namespace api {
class ContextToNwdafApi {
public:
ContextToNwdafApi(std::shared_ptr<Pistache::Rest::Router>);
virtual ~ContextToNwdafApi() {}
void init();
const std::string base = "/openxg";
private:
void setupRoutes();
void get_context_to_nwdaf_handler(const Pistache::Rest::Request &request,
Pistache::Http::ResponseWriter response);
void context_to_nwdaf_api_default_handler(
const Pistache::Rest::Request &request,
Pistache::Http::ResponseWriter response);
std::shared_ptr<Pistache::Rest::Router> router;
virtual void get_context_to_nwdaf( Pistache::Http::ResponseWriter &response) = 0;
};
} // namespace api
} // namespace udm
} // namespace oai
#endif /* GroupIdentifiersApi_H_ */
#include "ContextToNwdafApiImpl.hpp"
#include "context_udm.hpp"
namespace oai {
namespace udm {
namespace api {
using namespace context;
ContextToNwdafApiImpl::ContextToNwdafApiImpl(
std::shared_ptr<Pistache::Rest::Router> rtr)
: ContextToNwdafApi(rtr) {}
void ContextToNwdafApiImpl::get_context_to_nwdaf(Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
} // namespace api
} // namespace udm
} // namespace oai
#ifndef _CONTEXTTONWDAFAPIIMPL_H_
#define _CONTEXTTONWDAFAPIIMPL_H_
#include <memory>
#include <pistache/endpoint.h>
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/optional.h>
#include <string>
namespace oai {
namespace udm {
namespace api {
class ContextToNwdafApiImpl : public oai::udm::api::ContextToNwdafApi {
public:
ContextToNwdafApiImpl(std::shared_ptr<Pistache::Rest::Router>);
~ContextToNwdafApiImpl() {}
void get_context_to_nwdaf( Pistache::Http::ResponseWriter &response);
};
} // namespace api
} // namespace udm
} // namespace oai
#endif
......@@ -13,12 +13,16 @@
#include "GenerateAuthDataApiImpl.h"
#include "comUt.hpp"
#include "imsi_context.hpp"
#include <iomanip>
#include <sstream>
using namespace context;
using namespace config;
extern udm_config udm_cfg;
extern context_udm *udm_context;
using namespace org::openapitools::server::model;
namespace oai {
namespace udm {
......@@ -305,7 +309,7 @@ void GenerateAuthDataApiImpl::generate_auth_data(
// std::stringstream s1;
// s1 << std::hex << sqn_s;
// s1 >> sqn_value; // hex string to decimal value
uint64_t sqn_value = 0;
for (int i=0; i < 6; i++)
{
......@@ -352,6 +356,18 @@ void GenerateAuthDataApiImpl::generate_auth_data(
Curl::curl_http_client(remoteUri, Method, msgBody, Response);
Logger::udm_ueau().info("Update sqn in Database");
//context
imsi_context ic;
ic.setMessageFlag(true);
ic.setImsi(supiOrSuci);
ic.setOpType(response_data.at("encTopcKey"));
ic.setOp(response_data.at("encOpcKey"));
ic.setK(response_data.at("encPermanentKey"));
udm_context->set_imsi_2_udm_context(supiOrSuci, ic);
}
} // namespace api
......
#include "context_udm.hpp"
//using namespace context;
namespace context {
context_udm::context_udm(){}
context_udm::~context_udm(){}
//------------------------------------------------------------------------------
void context_udm::set_imsi_2_udm_context(std::string imsi, std::shared_ptr<imsi_context> ic) {
std::shared_lock lock(m_imsicontext);
imsicontext[imsi] = ic;
}
//------------------------------------------------------------------------------
std::shared_ptr<imsi_context> context_udm::imsi_2_udm_context(std::string imsi) {
std::shared_lock lock(m_imsicontext);
return imsicontext.at(imsi);;
}
//------------------------------------------------------------------------------
bool context_udm::get_udm_context(std::vector<imsi_context> &vec) {
std::shared_lock lock(m_imsicontext);
std::map<std::string, std::shared_ptr<imsi_context>>::reverse_iterator iter;
for(iter = imsicontext.rbegin(); iter != imsicontext.rend(); iter++)
{
vec.push_back(iter->second);
}
return true;
}
}
#ifndef _CONTEXT_H_
#define _CONTEXT_H_
#include <map>
#include <shared_mutex>
#include "imsi_context.hpp"
namespace context {
class context_udm{
public:
context_udm();
virtual ~context_udm();
set_imsi_2_udm_context(std::string imsi, std::shared_ptr<imsi_context> ic);
std::shared_ptr<imsi_context> imsi_2_udm_context(std::string imsi);
bool get_udm_context(std::vector<imsi_context> &vec);
private:
std::map<std::string, std::shared_ptr<imsi_context>> imsicontext;
mutable std::shared_mutex m_imsicontext;
};
}
#endif
\ No newline at end of file
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! file
brief
author Jian Yang
date 2021
email: contact@openairinterface.org
*/
#include "imsi_context.hpp"
namespace context {
imsi_context::imsi_context() {
m_messageFlag = false;
m_imsi = "";
m_imsiIsSet = false;
m_op = "";
m_opIsSet = false;
m_optype = "";
m_optypeIsSet = false;
m_k = "";
m_kIsSet = false;
}
imsi_context::~imsi_context() {}
void to_json(nlohmann::json& j, const imsi_context& o) {
j["messageflag"] = o.m_messageFlag;
if (o.imsiIsSet()) j["imsi"] = o.m_imsi;
if (o.opIsSet()) j["op"] = o.m_op;
if (o.opTypeIsSet()) j["optype"] = o.m_op;
if (o.kIsSet()) j["k"] = o.m_k;
}
void from_json(const nlohmann::json& j, imsi_context& o) {
j.at("messageflag").get_to(o.m_messageFlag);
if (j.find("imsi") != j.end()) {
j.at("imsi").get_to(o.m_imsi);
o.m_imsiIsSet = true;
}
if (j.find("op") != j.end()) {
j.at("op").get_to(o.m_op);
o.m_opIsSet = true;
}
if (j.find("optype") != j.end()) {
j.at("optype").get_to(o.m_optype);
o.m_optypeIsSet = true;
}
if (j.find("k") != j.end()) {
j.at("k").get_to(o.m_k);
o.m_kIsSet = true;
}
}
bool imsi_context::getMessageFlag() const { return m_messageFlag; }
void imsi_context::setMessageFlag(bool const& value){ m_messageFlag = value; }
std::string imsi_context::getImsi() const { return m_imsi; }
void imsi_context::setImsi(std::string const& value) {
m_imsi = value;
m_imsiIsSet = true;
}
bool imsi_context::imsiIsSet() const { return m_imsiIsSet; }
void imsi_context::unsetImsi() { m_imsiIsSet = false; }
std::string imsi_context::getOp() const { return m_op; }
void imsi_context::setOp(std::string const& value) {
m_op = value;
m_opIsSet = true;
}
bool imsi_context::opIsSet() const { return m_opIsSet; }
void imsi_context::unsetOp() { m_opIsSet = false; }
std::string imsi_context::getOpType() const { return m_optype; }
void imsi_context::setOpType(std::string const& value) {
m_optype = value;
m_optypeIsSet = true;
}
bool imsi_context::opTypeIsSet() const { return m_optypeIsSet; }
void imsi_context::unsetOpType() { m_optypeIsSet = false; }
std::string imsi_context::getK() const { return m_k; }
void imsi_context::setK(std::string const& value) {
m_k = value;
m_kIsSet = true;
}
bool imsi_context::kIsSet() const { return m_kIsSet; }
void imsi_context::unsetK() { m_kIsSet = false; }
} // namespace nf_msg
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! file
brief
author Jian Yang
date 2021
email: contact@openairinterface.org
*/
#ifndef _IMSI_CONTEXT_H_
#define _IMSI_CONTEXT_H_
#include <nlohmann/json.hpp>
#include <string>
namespace context {
// imsi、Opc、OpType、K、鉴权
class imsi_context {
public:
imsi_context();
virtual ~imsi_context();
bool getMessageFlag() const;
void setMessageFlag(bool const& value);
std::string getImsi() const;
void setImsi(std::string const& value);
bool imsiIsSet() const;
void unsetImsi();
std::string getOp() const;
void setOp(std::string const& value);
bool opIsSet() const;
void unsetOp();
std::string getOpType() const;
void setOpType(std::string const& value);
bool opTypeIsSet() const;
void unsetOpType();
std::string getK() const;
void setK(std::string const& value);
bool kIsSet() const;
void unsetK();
friend void to_json(nlohmann::json& j, const imsi_context& o);
friend void from_json(const nlohmann::json& j, imsi_context& o);
protected:
bool m_messageFlag;
std::string m_imsi;
bool m_imsiIsSet;
std::string m_op;
bool m_opIsSet;
std::string m_optype;
bool m_optypeIsSet;
std::string m_k;
bool m_kIsSet;
};
} // namespace nf_msg
#endif
\ No newline at end of file
......@@ -56,6 +56,8 @@
#include "options.hpp"
#include "udm_config.hpp"
#include "context_udm.hpp"
#define PISTACHE_SERVER_THREADS 2
#define PISTACHE_SERVER_MAX_PAYLOAD 32768
......@@ -93,12 +95,15 @@ static void setUpUnixSignals(std::vector<int> quitSignals) {
}
#endif
using namespace context;
using namespace oai::udm::api;
using namespace config;
using namespace org::openapitools::server::api;
udm_config udm_cfg;
context_udm *udm_context = nullptr;
int main(int argc, char **argv) {
#ifdef __linux__
std::vector<int> sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP};
......@@ -124,6 +129,9 @@ int main(int argc, char **argv) {
// Pistache::Address addr(std::string(inet_ntoa (*((struct in_addr
// *)&udm_cfg.sbi.addr4))), Pistache::Port(udm_cfg.sbi.port));
udm_context = new context_udm();
httpEndpoint = new Pistache::Http::Endpoint((addr));
auto router = std::make_shared<Pistache::Rest::Router>();
......@@ -200,7 +208,10 @@ int main(int argc, char **argv) {
AMFRegistrationFor3GPPAccessApiImpl AMFRegistrationFor3GPPAccessApiserver(router);
AMFRegistrationFor3GPPAccessApiserver.init();
ContextToNwdafApiImpl ContextToNwdafApiserver(router);
ContextToNwdafApiserver.init();
httpEndpoint->setHandler(router->handler());
httpEndpoint->serve();
......
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