Commit c0548a66 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Add API for provisioning UE info

parent 749f63c1
......@@ -31,38 +31,46 @@ using namespace oai::udr::config;
extern udr_config udr_cfg;
//------------------------------------------------------------------------------
cassandra_db::cassandra_db() : database_wrapper<cassandra_db>() {
// initialize();
}
cassandra_db::cassandra_db() : database_wrapper<cassandra_db>() {}
//------------------------------------------------------------------------------
cassandra_db::~cassandra_db() {}
//------------------------------------------------------------------------------
bool cassandra_db::initialize() {
Logger::udr_app().debug("Initialize CassandraDB");
Logger::udr_app().debug("CassandraDB is not supported!");
return false;
}
//------------------------------------------------------------------------------
bool cassandra_db::close_connection() {
return true;
}
//------------------------------------------------------------------------------
bool cassandra_db::insert_authentication_subscription(
const std::string& id, const nlohmann::json& json_data) {
const std::string& id,
const oai::udr::model::AuthenticationSubscription&
authentication_subscription,
nlohmann::json& json_data) {
return true;
}
//------------------------------------------------------------------------------
bool cassandra_db::query_authentication_subscription(
const std::string& id, nlohmann::json& json_data) {
Logger::udr_app().debug("CassandraDB is not supported!");
return true;
}
//------------------------------------------------------------------------------
bool cassandra_db::update_authentication_subscription(
const std::string& id, const nlohmann::json& json_data) {
return true;
}
//------------------------------------------------------------------------------
bool cassandra_db::delete_authentication_subscription(const std::string& id) {
return true;
}
......
......@@ -32,15 +32,21 @@ class cassandra_db : public database_wrapper<cassandra_db> {
virtual ~cassandra_db();
bool initialize();
bool close_connection();
bool insert_authentication_subscription(
const std::string& id, const nlohmann::json& json_data);
const std::string& id,
const oai::udr::model::AuthenticationSubscription&
authentication_subscription,
nlohmann::json& json_data);
bool query_authentication_subscription(
const std::string& id, nlohmann::json& json_data);
bool update_authentication_subscription(
const std::string& id, const nlohmann::json& json_data);
bool delete_authentication_subscription(const std::string& id);
bool query_am_data(
......
......@@ -57,7 +57,10 @@ class database_wrapper : public database_wrapper_abstraction {
}
bool insert_authentication_subscription(
const std::string& id, const nlohmann::json& json_data) override {
const std::string& id,
const oai::udr::model::AuthenticationSubscription&
authentication_subscription,
nlohmann::json& json_data) override {
return true;
}
......
......@@ -30,6 +30,7 @@
#include "PatchItem.h"
#include "SdmSubscription.h"
#include "SmfRegistration.h"
#include "AuthenticationSubscription.h"
#include <nlohmann/json.hpp>
......@@ -58,11 +59,16 @@ class database_wrapper_abstraction {
/*
* Insert a new item to the DB for the Authentication Subscription
* @param [const std::string&] id: UE Identity
* @param [const oai::udr::model::AuthenticationSubscription&]
* authentication_subscription: Authentication data
* @param [nlohmann::json&] json_data: Data in Json format
* @return true if successful, otherwise return false
*/
virtual bool insert_authentication_subscription(
const std::string& id, const nlohmann::json& json_data) = 0;
const std::string& id,
const oai::udr::model::AuthenticationSubscription&
authentication_subscription,
nlohmann::json& json_data) = 0;
/*
* Query an item from the DB for the Authentication Subscription
* @param [const std::string&] id: UE Identity
......
......@@ -68,7 +68,92 @@ bool mysql_db::close_connection() {
//------------------------------------------------------------------------------
bool mysql_db::insert_authentication_subscription(
const std::string& id, const nlohmann::json& json_data) {
const std::string& id,
const oai::udr::model::AuthenticationSubscription& auth_subscription,
nlohmann::json& json_data) {
MYSQL_RES* res = nullptr;
MYSQL_ROW row = {};
nlohmann::json json_tmp = {};
std::string query =
"SELECT * FROM AuthenticationSubscription WHERE ueid='" + id + "'";
Logger::udr_mysql().info("MySQL Query: %s", query.c_str());
if (mysql_real_query(
&mysql_connector, query.c_str(), (unsigned long) query.size()) != 0) {
Logger::udr_mysql().error(
"Failed when executing mysql_real_query with SQL Query: %s",
query.c_str());
return false;
}
res = mysql_store_result(&mysql_connector);
if (res == nullptr) {
Logger::udr_mysql().error(
"mysql_store_result failure! SQL Query: %s", query.c_str());
return false;
}
row = mysql_fetch_row(res);
if (row != nullptr) {
Logger::udr_mysql().error("AuthenticationSubscription existed!");
// Existed
return false;
}
mysql_free_result(res);
query =
"INSERT INTO AuthenticationSubscription SET ueid='" + id + "'" +
",authenticationMethod='" + auth_subscription.getAuthenticationMethod() +
"'" +
(auth_subscription.encPermanentKeyIsSet() ?
",encPermanentKey='" + auth_subscription.getEncPermanentKey() + "'" :
"") +
(auth_subscription.protectionParameterIdIsSet() ?
",protectionParameterId='" +
auth_subscription.getProtectionParameterId() + "'" :
"") +
(auth_subscription.authenticationManagementFieldIsSet() ?
",authenticationManagementField='" +
auth_subscription.getAuthenticationManagementField() + "'" :
"") +
(auth_subscription.algorithmIdIsSet() ?
",algorithmId='" + auth_subscription.getAlgorithmId() + "'" :
"") +
(auth_subscription.encOpcKeyIsSet() ?
",encOpcKey='" + auth_subscription.getEncOpcKey() + "'" :
"") +
(auth_subscription.encTopcKeyIsSet() ?
",encTopcKey='" + auth_subscription.getEncTopcKey() + "'" :
"") +
// (auth_subscription.vectorGenerationInHssIsSet() ?
// ",vectorGenerationInHss='" +
// auth_subscription.isVectorGenerationInHss() + "'" : "") +
(auth_subscription.n5gcAuthMethodIsSet() ?
",n5gcAuthMethod='" + auth_subscription.getN5gcAuthMethod() + "'" :
"") +
// auth_subscription.rgAuthenticationIndIsSet() ? ",rgAuthenticationInd='"
// + auth_subscription.() + "'" : "") +
(auth_subscription.supiIsSet() ?
",supi='" + auth_subscription.getSupi() + "'" :
"");
if (auth_subscription.sequenceNumberIsSet()) {
to_json(json_tmp, auth_subscription.getSequenceNumber());
query += ",sequenceNumber='" + json_tmp.dump() + "'";
}
if (mysql_real_query(
&mysql_connector, query.c_str(), (unsigned long) query.size())) {
Logger::udr_mysql().error(
"mysql_real_query failure! SQL Query %s", query.c_str());
return false;
}
to_json(json_data, auth_subscription);
Logger::udr_mysql().debug(
"AuthenticationSubscription POST: %s", json_data.dump().c_str());
return true;
}
......
......@@ -34,17 +34,23 @@ class mysql_db : public database_wrapper<mysql_db> {
virtual ~mysql_db();
bool initialize();
bool close_connection();
bool insert_authentication_subscription(
const std::string& id, const nlohmann::json& json_data);
const std::string& id,
const oai::udr::model::AuthenticationSubscription&
authentication_subscription,
nlohmann::json& json_data);
bool query_authentication_subscription(
const std::string& id, nlohmann::json& json_data);
bool update_authentication_subscription(
const std::string& id,
const std::vector<oai::udr::model::PatchItem>& patchItem,
nlohmann::json& json_data);
bool delete_authentication_subscription(const std::string& id);
bool query_am_data(
......
......@@ -28,14 +28,10 @@
*/
#include "udr_app.hpp"
#include <mysql/mysql.h>
//#include <unistd.h>
#include "3gpp_29.500.h"
#include "AccessAndMobilitySubscriptionData.h"
#include "AuthenticationSubscription.h"
//#include "ProblemDetails.h"
//#include "SequenceNumber.h"
#include "logger.hpp"
#include "udr_config.hpp"
#include "udr_nrf.hpp"
......@@ -190,8 +186,18 @@ void udr_app::handle_query_authentication_status(
void udr_app::handle_create_authentication_data(
const std::string& ue_id,
const AuthenticationSubscription& authentication_subscription,
nlohmann::json& response_data, long& http_code) {
// TODO
nlohmann::json& response_data, long& code) {
Logger::udr_app().info("Crate an authentication subscription data of a UE");
if (db_connector->insert_authentication_subscription(
ue_id, authentication_subscription, response_data)) {
code = HTTP_STATUS_CODE_201_CREATED;
Logger::udr_app().info(
"AuthenticationSubscription: %s", response_data.dump().c_str());
} else {
code = HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR; // TODO
}
return;
}
//------------------------------------------------------------------------------
......
......@@ -148,7 +148,7 @@ class udr_app {
void handle_create_authentication_data(
const std::string& ue_id,
const AuthenticationSubscription& authentication_subscription,
nlohmann::json& response_data, long& http_code);
nlohmann::json& response_data, long& code);
/*
* Handle a request to modify AuthenticationSubscription
......
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