Commit 9ffb4d78 authored by yangjian's avatar yangjian

fix BUG: NWDAF data structure

parent baf935d2
#include "ContextToNwdafApi.hpp"
#include <nlohmann/json.hpp>
namespace oai {
namespace udm {
namespace api {
......
......@@ -2,18 +2,47 @@
#include "context_udm.hpp"
#include <vector>
#include <nlohmann/json.hpp>
using namespace context;
extern context_udm *udm_context;
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");
//response.send(Pistache::Http::Code::Ok, "Do some magic\n");
std::vector < imsi_context > list;
udm_context->get_udm_context(list);
nlohmann::json j, tmp_j;
if(list.size() > 0)
{
for(int i=0;i<list.size();i++)
{
to_json(tmp_j, list[i]);
j += tmp_j;
}
response.send(Pistache::Http::Code::Ok, j.dump());
}
else
{
response.send(Pistache::Http::Code::Ok, "[]");
}
// std::string out = j.dump();
// Logger::udr_server().debug("AuthenticationSubscription PATCH - json:\n\"%s\"",out.c_str());
}
} // namespace api
......
......@@ -8,7 +8,9 @@
#include <pistache/optional.h>
#include <string>
#include "ContextToNwdafApi.hpp"
namespace oai {
namespace udm {
namespace api {
......
......@@ -13,7 +13,7 @@
#include "GenerateAuthDataApiImpl.h"
#include "comUt.hpp"
#include "imsi_context.hpp"
#include "context_udm.hpp"
#include <iomanip>
#include <sstream>
......@@ -360,14 +360,22 @@ void GenerateAuthDataApiImpl::generate_auth_data(
//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"));
std::shared_ptr<imsi_context> ic;
if (!udm_context->is_imsi_2_udm_context(supiOrSuci)) {
Logger::udm_ueau().debug(
"Create a new context with supiOrSuci 0x%x",
supiOrSuci);
ic = std::shared_ptr<imsi_context>(new imsi_context());
udm_context->set_imsi_2_udm_context(supiOrSuci, ic);
} else {
ic = udm_context->imsi_2_udm_context(supiOrSuci);
}
ic.get()->setMessageFlag(true);
ic.get()->setImsi(supiOrSuci);
ic.get()->setOpType(response_data.at("encTopcKey"));
ic.get()->setOp(response_data.at("encOpcKey"));
ic.get()->setK(response_data.at("encPermanentKey"));
}
} // namespace api
......
......@@ -3,9 +3,9 @@ cmake_minimum_required (VERSION 3.2)
project(udm)
if (CMAKE_OPENXGUDM_BUILD_TYPE STREQUAL Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -DDEBUG_IS_ON=1 -DINFO_IS_ON=1 -DTRACE_IS_ON=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -DDEBUG_IS_ON=1 -DINFO_IS_ON=1 -DTRACE_IS_ON=1")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
endif()
set(SRC_DIR ${CMAKE_OPENXGUDM_DIR}/src)
......@@ -22,7 +22,7 @@ include_directories(${SRC_DIR}/5gaka)
include_directories(${SRC_DIR}/common)
include_directories(${SRC_DIR}/utils)
include_directories(${SRC_DIR}/asnlib)
#include_directories(${SRC_DIR}/udm_app)
include_directories(${SRC_DIR}/udm_app)
##############################################
find_package(PkgConfig REQUIRED)
......@@ -59,7 +59,7 @@ add_definitions("-DNETTLE_VERSION_MAJOR=${NETTLE_VERSION_MAJOR}")
add_definitions("-DNETTLE_VERSION_MINOR=${NETTLE_VERSION_MINOR}")
##############################################
### for log
### for log
add_library( LOG STATIC
${SRC_DIR}/common/logger.cpp)
add_library( OPTIONS STATIC
......@@ -80,4 +80,4 @@ file(GLOB SRCS
)
add_executable(${PROJECT_NAME} ${SRCS} )
target_link_libraries(${PROJECT_NAME} LOG OPTIONS pistache pthread gmp config++ ${NETTLE_LIBRARIES} curl)
target_link_libraries(${PROJECT_NAME} -Wl,--start-group LOG OPTIONS pistache pthread gmp config++ ${NETTLE_LIBRARIES} curl)
#include "context_udm.hpp"
//using namespace context;
namespace context {
......@@ -8,16 +7,22 @@ namespace context {
context_udm::context_udm(){}
context_udm::~context_udm(){}
//------------------------------------------------------------------------------
bool context_udm::is_imsi_2_udm_context( const std::string &imsi) const {
std::shared_lock lock(m_imsicontext);
return bool{imsicontext.count(imsi) > 0};
}
//------------------------------------------------------------------------------
void context_udm::set_imsi_2_udm_context(std::string imsi, std::shared_ptr<imsi_context> ic) {
void context_udm::set_imsi_2_udm_context(const 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_ptr<imsi_context> context_udm::imsi_2_udm_context(const std::string &imsi) {
std::shared_lock lock(m_imsicontext);
return imsicontext.at(imsi);;
......@@ -30,7 +35,7 @@ bool context_udm::get_udm_context(std::vector<imsi_context> &vec) {
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);
vec.push_back(*(iter->second.get()));
}
return true;
......
#ifndef _CONTEXT_H_
#define _CONTEXT_H_
#ifndef _CONTEXT_UDM_H_
#define _CONTEXT_UDM_H_
#include <map>
#include <memory>
#include <shared_mutex>
#include "imsi_context.hpp"
namespace context {
......@@ -12,8 +14,10 @@ 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 is_imsi_2_udm_context(const std::string &imsi) const;
void set_imsi_2_udm_context(const std::string &imsi, std::shared_ptr<imsi_context> ic);
std::shared_ptr<imsi_context> imsi_2_udm_context(const std::string &imsi);
bool get_udm_context(std::vector<imsi_context> &vec);
private:
......
......@@ -47,7 +47,7 @@ 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.opTypeIsSet()) j["optype"] = o.m_optype;
if (o.kIsSet()) j["k"] = o.m_k;
}
void from_json(const nlohmann::json& j, imsi_context& o) {
......
......@@ -53,6 +53,8 @@
#include "SMFSmfRegistrationApiImpl.h"
#include "AMFRegistrationFor3GPPAccessApiImpl.h"
#include "ContextToNwdafApiImpl.hpp"
#include "options.hpp"
#include "udm_config.hpp"
......
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