Commit 7d160e83 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Fix issue with Create Subscription

parent 6f9f2097
......@@ -37,6 +37,10 @@ AMF_CONF[@SD_1@]='12'
AMF_CONF[@AMF_INTERFACE_NAME_FOR_NGAP@]='wlo1'
AMF_CONF[@AMF_INTERFACE_NAME_FOR_N11@]='wlo1'
AMF_CONF[@EXTERNAL_AUSF@]='no'
AMF_CONF[@EXTERNAL_UDM@]='no'
AMF_CONF[@USE_FQDN_DNS@]='no'
AMF_CONF[@NF_REGISTRATION@]='no'
AMF_CONF[@SMF_SELECTION@]='no'
......
......@@ -61,6 +61,7 @@ file(GLOB AMF_src_files
${CMAKE_CURRENT_SOURCE_DIR}/amf_statistics.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mysql_db.cpp
${CMAKE_CURRENT_SOURCE_DIR}/amf_msg.cpp
${CMAKE_CURRENT_SOURCE_DIR}/amf_subscription.cpp
${SRC_TOP_DIR}/nas/msgs/*.cpp
${SRC_TOP_DIR}/nas/ies/*.cpp
${SRC_TOP_DIR}/nas/utils/*.c
......
......@@ -403,27 +403,25 @@ evsub_id_t amf_app::handle_event_exposure_subscription(
// map (subscription id, info)
evsub_id_t evsub_id = generate_ev_subscription_id();
std::shared_ptr<amf_subscription> ss =
std::shared_ptr<amf_subscription>(new amf_subscription());
ss.get()->sub_id = evsub_id;
// TODO:
if (msg->event_exposure.is_supi_is_set()) {
supi64_t supi64 = amf_supi_to_u64(msg->event_exposure.get_supi());
ss.get()->supi = supi64;
}
ss.get()->notify_correlation_id =
msg->event_exposure.get_notify_correlation_id();
ss.get()->notify_uri = msg->event_exposure.get_notify_uri();
ss.get()->nf_id = msg->event_exposure.get_nf_id();
std::vector<amf_event_t> event_subscriptions =
msg->event_exposure.get_event_subs();
// store subscription
for (auto i : event_subscriptions) {
ss.get()->ev_type = i.type;
std::shared_ptr<amf_subscription> ss = std::make_shared<amf_subscription>();
ss.get()->sub_id = evsub_id;
// TODO:
if (msg->event_exposure.is_supi_is_set()) {
ss.get()->supi = msg->event_exposure.get_supi();
ss.get()->supi_is_set = true;
}
ss.get()->notify_correlation_id =
msg->event_exposure.get_notify_correlation_id();
ss.get()->notify_uri = msg->event_exposure.get_notify_uri();
ss.get()->nf_id = msg->event_exposure.get_nf_id();
ss.get()->ev_type = i.type;
add_event_subscription(evsub_id, i.type, ss);
ss.get()->display();
}
return evsub_id;
}
......@@ -587,7 +585,7 @@ void amf_app::get_ee_subscriptions(
//---------------------------------------------------------------------------------------------
void amf_app::get_ee_subscriptions(
amf_event_type_t ev, supi64_t supi,
amf_event_type_t ev, std::string& supi,
std::vector<std::shared_ptr<amf_subscription>>& subscriptions) {
for (auto const& i : amf_event_subscriptions) {
if ((i.first.second == ev) && (i.second->supi == supi)) {
......
......@@ -208,13 +208,13 @@ class amf_app {
/*
* Get a list of subscription associated with a particular event
* @param [amf_event_t] ev: Event type
* @param [supi64_t] supi: SUPI
* @param [std::string&] supi: SUPI
* @param [std::vector<std::shared_ptr<amf_subscription>>&] subscriptions:
* store the list of the subscription associated with this event type
* @return void
*/
void get_ee_subscriptions(
amf_event_type_t ev, supi64_t supi,
amf_event_type_t ev, std::string& supi,
std::vector<std::shared_ptr<amf_subscription>>& subscriptions);
/*
......
......@@ -35,12 +35,12 @@ using namespace amf_application;
*/
//-----------------------------------------------------------------------------
supi_t event_exposure_msg::get_supi() const {
std::string event_exposure_msg::get_supi() const {
return m_supi;
}
//-----------------------------------------------------------------------------
void event_exposure_msg::set_supi(const supi_t& value) {
void event_exposure_msg::set_supi(const std::string& value) {
m_supi = value;
m_supi_is_set = true;
}
......@@ -109,6 +109,10 @@ void event_exposure_msg::set_event_subs(std::vector<amf_event_t> const& value) {
}
}
//-----------------------------------------------------------------------------
void event_exposure_msg::add_event_sub(amf_event_t const& value) {
m_event_list.push_back(value);
}
//-----------------------------------------------------------------------------
void event_exposure_msg::set_any_ue(bool value) {
m_any_ue = value;
......
......@@ -37,8 +37,8 @@ namespace amf_application {
class event_exposure_msg {
public:
supi_t get_supi() const;
void set_supi(const supi_t& value);
std::string get_supi() const;
void set_supi(const std::string& value);
bool is_supi_is_set() const;
void set_sub_id(std::string const& value);
......@@ -56,6 +56,7 @@ class event_exposure_msg {
std::vector<amf_event_t> get_event_subs() const;
void set_event_subs(std::vector<amf_event_t> const& value);
void add_event_sub(amf_event_t const& value);
void set_any_ue(bool value);
......@@ -68,7 +69,8 @@ class event_exposure_msg {
std::string m_notify_correlation_id; // notifyCorrelationId, Mandatory
std::string m_nf_id; // nfId, Mandatory
supi_t m_supi; // Supi, Conditional
// supi_t m_supi; // Supi, Conditional
std::string m_supi;
bool m_supi_is_set;
bool m_any_ue; // anyUE, Conditional
......
......@@ -33,6 +33,7 @@
#include <nlohmann/json.hpp>
#include "3gpp_ts24501.hpp"
#include "3gpp_29.500.h"
#include "amf.hpp"
#include "amf_app.hpp"
#include "amf_config.hpp"
......
/*
* 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 amf_subscription.cpp
\brief
\author
\company
\date 2021
\email:
*/
#include "amf_subscription.hpp"
#include "logger.hpp"
#include "3gpp_conversions.hpp"
using namespace amf_application;
void amf_subscription::display() {
Logger::amf_app().debug("Subscription info");
Logger::amf_app().debug("\tSubscription ID: %d", (uint32_t) sub_id);
Logger::amf_app().debug(
"\tEvent type: %s", xgpp_conv::amf_event_type_to_string(ev_type).c_str());
if (supi_is_set) Logger::amf_app().debug("\tSUPI: %s", supi.c_str());
Logger::amf_app().debug(
"\tNotify Correlation ID: %s", notify_correlation_id.c_str());
Logger::amf_app().debug("\tNF ID: %s", nf_id.c_str());
};
......@@ -35,14 +35,25 @@ namespace amf_application {
/*
* Manage the Subscription Info
*/
class amf_subscription {
public:
amf_subscription() {}
amf_subscription()
: sub_id(),
ev_type(),
supi(),
notify_correlation_id(),
notify_uri(),
nf_id() {
supi_is_set = false;
}
void display();
public:
evsub_id_t sub_id;
amf_event_type_t ev_type;
supi64_t supi;
bool supi_is_set;
std::string supi;
std::string notify_correlation_id;
std::string notify_uri; // subsChangeNotifyUri ?
std::string nf_id;
......
......@@ -19,38 +19,34 @@
* contact@openairinterface.org
*/
#ifndef FILE_3GPP_29_500_SMF_SEEN
#define FILE_3GPP_29_500_SMF_SEEN
#ifndef FILE_3GPP_29_500_SEEN
#define FILE_3GPP_29_500_SEEN
enum http_status_code_e {
HTTP_STATUS_CODE_100_CONTINUE = 100,
HTTP_STATUS_CODE_200_OK = 200,
HTTP_STATUS_CODE_201_CREATED = 201,
HTTP_STATUS_CODE_202_ACCEPTED = 202,
HTTP_STATUS_CODE_204_NO_CONTENT = 204,
HTTP_STATUS_CODE_300_MULTIPLE_CHOICES = 300,
HTTP_STATUS_CODE_303_SEE_OTHER = 303,
HTTP_STATUS_CODE_307_TEMPORARY_REDIRECT = 307,
HTTP_STATUS_CODE_308_PERMANENT_REDIRECT = 308,
HTTP_STATUS_CODE_400_BAD_REQUEST = 400,
HTTP_STATUS_CODE_401_UNAUTHORIZED = 401,
HTTP_STATUS_CODE_403_FORBIDDEN = 403,
HTTP_STATUS_CODE_404_NOT_FOUND = 404,
HTTP_STATUS_CODE_405_METHOD_NOT_ALLOWED = 405,
HTTP_STATUS_CODE_406_NOT_ACCEPTABLE = 406,
HTTP_STATUS_CODE_408_REQUEST_TIMEOUT = 408,
HTTP_STATUS_CODE_409_CONFLICT = 409,
HTTP_STATUS_CODE_410_GONE = 410,
HTTP_STATUS_CODE_411_LENGTH_REQUIRED = 411,
HTTP_STATUS_CODE_412_PRECONDITION_FAILED = 412,
HTTP_STATUS_CODE_413_PAYLOAD_TOO_LARGE = 413,
HTTP_STATUS_CODE_414_URI_TOO_LONG = 414,
HTTP_STATUS_CODE_415_UNSUPPORTED_MEDIA_TYPE_NA = 415,
HTTP_STATUS_CODE_429_TOO_MANY_REQUESTS = 429,
HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR = 500,
HTTP_STATUS_CODE_501_NOT_IMPLEMENTED = 501,
HTTP_STATUS_CODE_503_SERVICE_UNAVAILABLE = 503,
HTTP_STATUS_CODE_504_GATEWAY_TIMEOUT = 504
// SMF + AMF + 3GPP TS 29.571 (Common data)
enum class http_response_codes_e {
HTTP_RESPONSE_CODE_0 = 0,
HTTP_RESPONSE_CODE_200_OK = 200,
HTTP_RESPONSE_CODE_201_CREATED = 201,
HTTP_RESPONSE_CODE_202_ACCEPTED = 202,
HTTP_RESPONSE_CODE_204_UPDATED = 204,
HTTP_RESPONSE_CODE_BAD_REQUEST = 400,
HTTP_RESPONSE_CODE_UNAUTHORIZED = 401,
HTTP_RESPONSE_CODE_FORBIDDEN = 403,
HTTP_RESPONSE_CODE_NOT_FOUND = 404,
HTTP_RESPONSE_CODE_METHOD_NOT_ALLOWED = 405,
HTTP_RESPONSE_CODE_REQUEST_TIMEOUT = 408,
HTTP_RESPONSE_CODE_406_NOT_ACCEPTED = 406,
HTTP_RESPONSE_CODE_CONFLICT = 409,
HTTP_RESPONSE_CODE_GONE = 410,
HTTP_RESPONSE_CODE_LENGTH_REQUIRED = 411,
HTTP_RESPONSE_CODE_PRECONDITION_FAILED = 412,
HTTP_RESPONSE_CODE_PAYLOAD_TOO_LARGE = 413,
HTTP_RESPONSE_CODE_URI_TOO_LONG = 414,
HTTP_RESPONSE_CODE_UNSUPPORTED_MEDIA_TYPE = 415,
HTTP_RESPONSE_CODE_TOO_MANY_REQUESTS = 429,
HTTP_RESPONSE_CODE_INTERNAL_SERVER_ERROR = 500,
HTTP_RESPONSE_CODE_NOT_IMPLEMENTED = 501,
HTTP_RESPONSE_CODE_SERVICE_UNAVAILABLE = 503,
HTTP_RESPONSE_CODE_GATEWAY_TIMEOUT = 504
};
#endif
......@@ -33,101 +33,6 @@
#include "inttypes.h"
#include "stdio.h"
typedef uint64_t supi64_t;
#define SUPI_64_FMT "%" SCNu64
#define SUPI_DIGITS_MAX 15
typedef struct {
uint32_t length;
char data[SUPI_DIGITS_MAX + 1];
} supi_t;
static void amf_string_to_supi(supi_t* const supi, char const* const supi_str) {
// strncpy(supi->data, supi_str, SUPI_DIGITS_MAX + 1);
memcpy((void*) supi->data, (void*) supi_str, SUPI_DIGITS_MAX + 1);
supi->length = strlen(supi->data);
return;
}
static std::string amf_supi_to_string(supi_t const supi) {
std::string supi_str;
supi_str.assign(supi.data, SUPI_DIGITS_MAX + 1);
return supi_str;
}
static uint64_t amf_supi_to_u64(supi_t supi) {
uint64_t uint_supi;
sscanf(supi.data, SUPI_64_FMT, &uint_supi);
return uint_supi;
}
/*
typedef struct {
std::string mcc;
std::string mnc;
uint32_t tac;
} plmn_t;
typedef struct s_nssai // section 28.4, TS23.003
{
uint8_t sST;
//uint32_t sD:24;
std::string sD;
s_nssai(const uint8_t &sst, const std::string sd)
:
sST(sst),
sD(sd) {
}
s_nssai()
:
sST(),
sD() {
}
s_nssai(const s_nssai &p)
:
sST(p.sST),
sD(p.sD) {
}
bool operator==(const struct s_nssai &s) const {
if ((s.sST == this->sST) && (s.sD.compare(this->sD) == 0)) {
return true;
} else {
return false;
}
}
} snssai_t;
*/
// SMF + AMF + 3GPP TS 29.571 (Common data)
enum class http_response_codes_e {
HTTP_RESPONSE_CODE_0 = 0,
HTTP_RESPONSE_CODE_200_OK = 200,
HTTP_RESPONSE_CODE_201_CREATED = 201,
HTTP_RESPONSE_CODE_202_ACCEPTED = 202,
HTTP_RESPONSE_CODE_204_UPDATED = 204,
HTTP_RESPONSE_CODE_BAD_REQUEST = 400,
HTTP_RESPONSE_CODE_UNAUTHORIZED = 401,
HTTP_RESPONSE_CODE_FORBIDDEN = 403,
HTTP_RESPONSE_CODE_NOT_FOUND = 404,
HTTP_RESPONSE_CODE_METHOD_NOT_ALLOWED = 405,
HTTP_RESPONSE_CODE_REQUEST_TIMEOUT = 408,
HTTP_RESPONSE_CODE_406_NOT_ACCEPTED = 406,
HTTP_RESPONSE_CODE_CONFLICT = 409,
HTTP_RESPONSE_CODE_GONE = 410,
HTTP_RESPONSE_CODE_LENGTH_REQUIRED = 411,
HTTP_RESPONSE_CODE_PRECONDITION_FAILED = 412,
HTTP_RESPONSE_CODE_PAYLOAD_TOO_LARGE = 413,
HTTP_RESPONSE_CODE_URI_TOO_LONG = 414,
HTTP_RESPONSE_CODE_UNSUPPORTED_MEDIA_TYPE = 415,
HTTP_RESPONSE_CODE_TOO_MANY_REQUESTS = 429,
HTTP_RESPONSE_CODE_INTERNAL_SERVER_ERROR = 500,
HTTP_RESPONSE_CODE_NOT_IMPLEMENTED = 501,
HTTP_RESPONSE_CODE_SERVICE_UNAVAILABLE = 503,
HTTP_RESPONSE_CODE_GATEWAY_TIMEOUT = 504
};
// for CURL
#define SMF_CURL_TIMEOUT_MS 100L
#define SMF_NUMBER_RETRIES 3
......
......@@ -13,6 +13,9 @@
#include "SubscriptionsCollectionDocumentApiEventExposure.h"
#include "Helpers.h"
#include "amf_config.hpp"
extern config::amf_config amf_cfg;
namespace oai::amf::api {
......@@ -32,7 +35,7 @@ void SubscriptionsCollectionDocumentApiEventExposure::setupRoutes() {
using namespace Pistache::Rest;
Routes::Post(
*router, base + "/subscriptions",
*router, base + amf_cfg.sbi_api_version + "/subscriptions",
Routes::bind(
&SubscriptionsCollectionDocumentApiEventExposure::
create_subscription_handler,
......
......@@ -42,7 +42,7 @@ void SubscriptionsCollectionDocumentApiImplEventExposure::create_subscription(
// Create a message and store the necessary information
Logger::amf_server().debug(
"Create a Event Exposure message and store the necessary information");
"Create an Event Exposure message and store the necessary information");
amf_application::event_exposure_msg event_exposure = {};
......
......@@ -66,12 +66,13 @@ void xgpp_conv::amf_event_subscription_from_openapi(
} else {
ev.type = amf_event_type_e::AMF_EVENT_UNKNOWN;
}
event_exposure.add_event_sub(ev);
}
if (event_subscription.getSubscription().supiIsSet()) {
supi_t supi = {};
std::string supi_str = event_subscription.getSubscription().getSupi();
amf_string_to_supi(&supi, supi_str.c_str());
// supi_t supi = {};
std::string supi = event_subscription.getSubscription().getSupi();
// amf_string_to_supi(&supi, supi_str.c_str());
event_exposure.set_supi(supi);
}
......@@ -83,3 +84,12 @@ void xgpp_conv::amf_event_subscription_from_openapi(
// TODO:
}
std::string xgpp_conv::amf_event_type_to_string(amf_event_type_t type) {
uint8_t t = (uint8_t) type;
if ((t > 0) and (t <= 12)) {
return amf_event_type_e2str.at(t);
} else {
return amf_event_type_e2str.at(0);
}
}
......@@ -31,6 +31,7 @@
#include "amf_msg.hpp"
#include "AmfCreateEventSubscription.h"
#include "3gpp_29.518.h"
using namespace amf_application;
using namespace oai::amf::model;
......@@ -48,6 +49,7 @@ void amf_event_subscription_from_openapi(
const oai::amf::model::AmfCreateEventSubscription& event_subscription,
amf_application::event_exposure_msg& event_exposure);
std::string amf_event_type_to_string(amf_event_type_t type);
} // namespace xgpp_conv
#endif /* FILE_3GPP_CONVERSIONS_HPP_SEEN */
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