Commit 2575d720 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

add deregistered/profile_change events/notif_events

parent 15640015
...@@ -172,11 +172,15 @@ bool SubscriptionData::validityTimeIsSet() const { ...@@ -172,11 +172,15 @@ bool SubscriptionData::validityTimeIsSet() const {
void SubscriptionData::unsetValidityTime() { void SubscriptionData::unsetValidityTime() {
m_ValidityTimeIsSet = false; m_ValidityTimeIsSet = false;
} }
std::vector<NotificationEventType>& SubscriptionData::getReqNotifEvents() { std::vector<std::string> SubscriptionData::getReqNotifEvents() const {
return m_ReqNotifEvents; return m_ReqNotifEvents;
} }
void SubscriptionData::getReqNotifEvents(std::vector<std::string> &value) const {
value = m_ReqNotifEvents;
}
void SubscriptionData::setReqNotifEvents( void SubscriptionData::setReqNotifEvents(
std::vector<NotificationEventType> const &value) { std::vector<std::string> const &value) {
m_ReqNotifEvents = value; m_ReqNotifEvents = value;
m_ReqNotifEventsIsSet = true; m_ReqNotifEventsIsSet = true;
} }
......
...@@ -210,8 +210,9 @@ class SubscriptionData { ...@@ -210,8 +210,9 @@ class SubscriptionData {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
std::vector<NotificationEventType> &getReqNotifEvents(); std::vector<std::string> getReqNotifEvents() const;
void setReqNotifEvents(std::vector<NotificationEventType> const &value); void getReqNotifEvents(std::vector<std::string> &value) const;
void setReqNotifEvents(std::vector<std::string> const &value);
bool reqNotifEventsIsSet() const; bool reqNotifEventsIsSet() const;
void unsetReqNotifEvents(); void unsetReqNotifEvents();
/// <summary> /// <summary>
...@@ -266,7 +267,7 @@ class SubscriptionData { ...@@ -266,7 +267,7 @@ class SubscriptionData {
std::string m_ValidityTime; std::string m_ValidityTime;
bool m_ValidityTimeIsSet; bool m_ValidityTimeIsSet;
std::vector<NotificationEventType> m_ReqNotifEvents; std::vector<std::string> m_ReqNotifEvents;
bool m_ReqNotifEventsIsSet; bool m_ReqNotifEventsIsSet;
PlmnId m_PlmnId; PlmnId m_PlmnId;
bool m_PlmnIdIsSet; bool m_PlmnIdIsSet;
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#define FILE_3GPP_23_003_SEEN #define FILE_3GPP_23_003_SEEN
#include <stdint.h> #include <stdint.h>
#include <string>
/* /*
typedef struct plmn_s { typedef struct plmn_s {
uint8_t mcc_digit2 :4; uint8_t mcc_digit2 :4;
......
...@@ -22,15 +22,38 @@ ...@@ -22,15 +22,38 @@
#ifndef FILE_3GPP_29_510_NRF_SEEN #ifndef FILE_3GPP_29_510_NRF_SEEN
#define FILE_3GPP_29_510_NRF_SEEN #define FILE_3GPP_29_510_NRF_SEEN
#include <string>
#include "3gpp_23.003.h" #include "3gpp_23.003.h"
#include <vector>
enum class nf_status_e { REGISTERED = 0, SUSPENDED = 1, UNDISCOVERABLE = 2 }; enum class nf_status_e { REGISTERED = 0, SUSPENDED = 1, UNDISCOVERABLE = 2 };
static const std::vector<std::string> nf_status_e2str = { static const std::vector<std::string> nf_status_e2str = {
"REGISTERED", "SUSPENDED", "UNDISCOVERABLE"}; "REGISTERED", "SUSPENDED", "UNDISCOVERABLE"};
enum subscr_condition_type_e { //TODO: use enum class
typedef struct amf_info_s {
std::string amf_set_id;
std::string amf_region_id;
std::vector<guami_t> guami_list;
} amf_info_t;
typedef struct dnn_smf_info_item_s {
std::string dnn;
} dnn_smf_info_item_t;
typedef struct snssai_smf_info_item_s {
snssai_t snssai;
std::vector<dnn_smf_info_item_t> dnn_smf_info_list;
} snssai_smf_info_item_t;
typedef struct smf_info_s {
std::vector<snssai_smf_info_item_t> snssai_smf_info_list;
} smf_info_t;
enum subscr_condition_type_e { // TODO: use enum class
UNKNOWN_CONDITION = 0, UNKNOWN_CONDITION = 0,
NF_INSTANCE_ID_COND = 1, NF_INSTANCE_ID_COND = 1,
NF_TYPE_COND = 2, NF_TYPE_COND = 2,
...@@ -161,12 +184,59 @@ typedef struct subscription_condition_s { ...@@ -161,12 +184,59 @@ typedef struct subscription_condition_s {
virtual ~subscription_condition_s(){}; virtual ~subscription_condition_s(){};
std::string to_string() const {
std::string s = {};
s.append("Type: ");
s.append(subscription_condition_type_e2str[type]);
s.append(", condition: ");
switch (type) {
case NF_INSTANCE_ID_COND: {
s.append(nf_instance_id);
} break;
case NF_TYPE_COND: {
s.append(nf_type);
} break;
case SERVICE_NAME_COND: {
s.append(service_name);
} break;
case AMF_COND: {
s.append(", AMF_Set_ID: ");
s.append(amf_info.amf_set_id);
s.append(", AMF_Region_ID: ");
s.append(amf_info.amf_region_id);
} break;
case GUAMI_LIST_COND: {
// TODO:
} break;
case NETWOTK_SLICE_COND: {
// TODO:
} break;
case NF_GROUP_COND: {
// TODO:
} break;
default: {
// TODO:
}
}
// TODO:
return s;
}
} subscription_condition_t; } subscription_condition_t;
enum notification_event_type_t { enum notification_event_type_t {
NOTIFICATION_TYPE_NF_REGISTERED = 0, NOTIFICATION_TYPE_UNKNOWN_EVENT = 0,
NOTIFICATION_TYPE_NF_DEREGISTERED = 1, NOTIFICATION_TYPE_NF_REGISTERED = 1,
NOTIFICATION_TYPE_NF_PROFILE_CHANGED = 2 NOTIFICATION_TYPE_NF_DEREGISTERED = 2,
NOTIFICATION_TYPE_NF_PROFILE_CHANGED = 3
}; };
static const std::vector<std::string> notification_event_type_e2str = {
"UNKNOWN EVENT", "NF_REGISTERED", "NF_DEREGISTERED", "NF_PROFILE_CHANGED"};
#endif #endif
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#ifndef FILE_NRF_SEEN #ifndef FILE_NRF_SEEN
#define FILE_NRF_SEEN #define FILE_NRF_SEEN
#include "3gpp_23.003.h"
#define HEART_BEAT_TIMER 10 #define HEART_BEAT_TIMER 10
...@@ -68,26 +67,6 @@ typedef enum patch_op_type_s { ...@@ -68,26 +67,6 @@ typedef enum patch_op_type_s {
static const std::vector<std::string> patch_op_type_e2str = { static const std::vector<std::string> patch_op_type_e2str = {
"ADD", "REMOVE", "REPLACE", "MOVE", "COPY", "TEST", "UNKNOWN"}; "ADD", "REMOVE", "REPLACE", "MOVE", "COPY", "TEST", "UNKNOWN"};
typedef struct amf_info_s {
std::string amf_set_id;
std::string amf_region_id;
std::vector<guami_t> guami_list;
} amf_info_t;
typedef struct dnn_smf_info_item_s {
std::string dnn;
} dnn_smf_info_item_t;
typedef struct snssai_smf_info_item_s {
snssai_t snssai;
std::vector<dnn_smf_info_item_t> dnn_smf_info_list;
} snssai_smf_info_item_t;
typedef struct smf_info_s {
std::vector<snssai_smf_info_item_t> snssai_smf_info_list;
} smf_info_t;
// Event Subscription IDs) // Event Subscription IDs)
typedef uint32_t evsub_id_t; typedef uint32_t evsub_id_t;
#define EVSUB_ID_FMT "0x%" PRIx32 #define EVSUB_ID_FMT "0x%" PRIx32
...@@ -95,4 +74,7 @@ typedef uint32_t evsub_id_t; ...@@ -95,4 +74,7 @@ typedef uint32_t evsub_id_t;
#define INVALID_EVSUB_ID ((evsub_id_t)0x00000000) #define INVALID_EVSUB_ID ((evsub_id_t)0x00000000)
#define UNASSIGNED_EVSUB_ID ((evsub_id_t)0x00000000) #define UNASSIGNED_EVSUB_ID ((evsub_id_t)0x00000000)
#define NNRF_NFM_BASE "/nnrf-nfm/"
#define NNRF_NFM_NF_INSTANCE "/nf-instances/"
#endif #endif
...@@ -282,14 +282,29 @@ bool api_conv::subscription_api_to_nrf_subscription( ...@@ -282,14 +282,29 @@ bool api_conv::subscription_api_to_nrf_subscription(
subscription_condition_type_e2str[sub_condition.type].c_str()); subscription_condition_type_e2str[sub_condition.type].c_str());
if (sub_condition.type != UNKNOWN_CONDITION) { if (sub_condition.type != UNKNOWN_CONDITION) {
sub.get()->set_sub_condition(sub_condition); sub.get()->set_sub_condition(sub_condition);
return true;
} else {
return false;
} }
} }
// NotificationEventType
if (api_sub.reqNotifEventsIsSet()) {
for (auto n : api_sub.getReqNotifEvents()) {
if (n.compare("NF_REGISTERED") == 0) {
sub.get()->add_notif_event(NOTIFICATION_TYPE_NF_REGISTERED);
Logger::nrf_app().debug("ReqNotifEvents: %s", n.c_str());
} else if (n.compare("NF_DEREGISTERED") == 0) {
sub.get()->add_notif_event(NOTIFICATION_TYPE_NF_DEREGISTERED);
Logger::nrf_app().debug("ReqNotifEvents: %s", n.c_str());
} else if (n.compare("NF_PROFILE_CHANGED") == 0) {
sub.get()->add_notif_event(NOTIFICATION_TYPE_NF_PROFILE_CHANGED);
} else {
sub.get()->add_notif_event(NOTIFICATION_TYPE_UNKNOWN_EVENT);
}
//Logger::nrf_app().debug("ReqNotifEvents: %s", n.c_str());
}
}
// TODO: // TODO:
return true; return true;
} }
......
/*
* 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
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <inttypes.h>
#include "backtrace.h"
#ifndef ASSERTIONS_H_
#define ASSERTIONS_H_
#define _Assert_Exit_ \
{ \
fprintf(stderr, "\nExiting execution\n"); \
display_backtrace(); \
fflush(stdout); \
fflush(stderr); \
exit(EXIT_FAILURE); \
}
#define _Assert_SegFault_ \
{ \
fprintf(stderr, "\n Will Intentionaly raise SEGFAULT to be catched by GDB!\n"); \
display_backtrace(); \
fflush(stdout); \
fflush(stderr); \
*(int*)0=0; \
exit(EXIT_FAILURE); \
}
#define _Assert_(cOND, aCTION, fORMAT, aRGS...) \
do { \
if (!(cOND)) { \
fprintf(stderr, "\nAssertion ("#cOND") failed!\n" \
"In %s() %s:%d\n" fORMAT, \
__FUNCTION__, __FILE__, __LINE__, ##aRGS); \
aCTION; \
} \
} while(0)
#if DEBUG_IS_ON
#define _ASSERT_FINAL_ _Assert_SegFault_
#else
#define _ASSERT_FINAL_ _Assert_Exit_
#endif
#define AssertFatal(cOND, ...) _Assert_(cOND, _ASSERT_FINAL_ , ##__VA_ARGS__)
#define DevCheck(cOND, vALUE1, vALUE2, vALUE3) \
_Assert_(cOND, _ASSERT_FINAL_, #vALUE1 ": %" PRIdMAX "\n" #vALUE2 ": %" PRIdMAX "\n" #vALUE3 ": %" PRIdMAX "\n\n", \
(intmax_t)vALUE1, (intmax_t)vALUE2, (intmax_t)vALUE3)
#define DevCheck4(cOND, vALUE1, vALUE2, vALUE3, vALUE4) \
_Assert_(cOND, _ASSERT_FINAL_, #vALUE1": %"PRIdMAX"\n"#vALUE2": %"PRIdMAX"\n"#vALUE3": %"PRIdMAX"\n"#vALUE4": %"PRIdMAX"\n\n", \
(intmax_t)vALUE1, (intmax_t)vALUE2, (intmax_t)vALUE3, (intmax_t)vALUE4)
#define DevAssert(cOND) _Assert_(cOND, _ASSERT_FINAL_, "")
#define DevMessage(mESSAGE) _Assert_(0, _ASSERT_FINAL_, #mESSAGE)
#define CHECK_INIT_RETURN(fCT) \
do { \
int fct_ret; \
if ((fct_ret = (fCT)) != 0) { \
fprintf(stderr, "Function "#fCT" has failed\n" \
"returning %d\n", fct_ret); \
fflush(stdout); \
fflush(stderr); \
exit(EXIT_FAILURE); \
} \
} while(0)
#define AssertError(cOND, aCTION, fORMAT, aRGS...) _Assert_(cOND, aCTION, fORMAT, ##aRGS)
#define DevParam(vALUE1, vALUE2, vALUE3) DevCheck(0, vALUE1, vALUE2, vALUE3)
#endif /* ASSERTIONS_H_ */
...@@ -125,7 +125,6 @@ void nrf_app::handle_register_nf_instance( ...@@ -125,7 +125,6 @@ void nrf_app::handle_register_nf_instance(
// Notify NF status change event // Notify NF status change event
m_event_sub.nf_status_registered(nf_instance_id); // from nrf_app m_event_sub.nf_status_registered(nf_instance_id); // from nrf_app
//m_event_sub.nf_status_change(sn); // from nrf_app
// display the info // display the info
sn.get()->display(); sn.get()->display();
...@@ -202,6 +201,7 @@ void nrf_app::handle_update_nf_instance( ...@@ -202,6 +201,7 @@ void nrf_app::handle_update_nf_instance(
default: { default: {
Logger::nrf_app().warn("Requested operation is not valid!"); Logger::nrf_app().warn("Requested operation is not valid!");
op_success = false;
} }
} }
...@@ -209,6 +209,10 @@ void nrf_app::handle_update_nf_instance( ...@@ -209,6 +209,10 @@ void nrf_app::handle_update_nf_instance(
http_code = HTTP_STATUS_CODE_400_BAD_REQUEST; http_code = HTTP_STATUS_CODE_400_BAD_REQUEST;
problem_details.setCause( problem_details.setCause(
protocol_application_error_e2str[MANDATORY_IE_INCORRECT]); protocol_application_error_e2str[MANDATORY_IE_INCORRECT]);
} else {
// update successful,
// Notify NF status change event
m_event_sub.nf_status_profile_changed(nf_instance_id); // from nrf_app
} }
} }
...@@ -289,6 +293,8 @@ void nrf_app::handle_deregister_nf_instance(const std::string &nf_instance_id, ...@@ -289,6 +293,8 @@ void nrf_app::handle_deregister_nf_instance(const std::string &nf_instance_id,
Logger::nrf_app().debug("Removed NF profile with profile ID %s", Logger::nrf_app().debug("Removed NF profile with profile ID %s",
nf_instance_id.c_str()); nf_instance_id.c_str());
http_code = HTTP_STATUS_CODE_204_NO_CONTENT; http_code = HTTP_STATUS_CODE_204_NO_CONTENT;
// Notify NF status change event
m_event_sub.nf_status_deregistered(nf_instance_id); // from nrf_app
return; return;
} else { } else {
http_code = HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR; http_code = HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR;
...@@ -327,8 +333,8 @@ void nrf_app::handle_create_subscription( ...@@ -327,8 +333,8 @@ void nrf_app::handle_create_subscription(
// subscribe to NF status registered // subscribe to NF status registered
// subscribe_nf_status(evsub_id); // from nrf_app // subscribe_nf_status(evsub_id); // from nrf_app
// subscribe to NF status change // subscribe to NF status
ss.get()->subscribe_nf_status_registered(); //from subscription // ss.get()->subscribe_nf_status_registered(); //from subscription
// add to the DB // add to the DB
add_subscription(evsub_id, ss); add_subscription(evsub_id, ss);
Logger::nrf_app().debug("Added a subscription to the DB"); Logger::nrf_app().debug("Added a subscription to the DB");
...@@ -578,8 +584,6 @@ void nrf_app::handle_nf_status_registered(const std::string &profile_id) { ...@@ -578,8 +584,6 @@ void nrf_app::handle_nf_status_registered(const std::string &profile_id) {
Logger::nrf_app().error("NF profile not found, profile id %s", Logger::nrf_app().error("NF profile not found, profile id %s",
profile_id.c_str()); profile_id.c_str());
} }
// TODO:
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -594,10 +598,21 @@ void nrf_app::subscribe_nf_status_deregistered() { ...@@ -594,10 +598,21 @@ void nrf_app::subscribe_nf_status_deregistered() {
void nrf_app::handle_nf_status_deregistered(const std::string &profile_id) { void nrf_app::handle_nf_status_deregistered(const std::string &profile_id) {
Logger::nrf_app().info("Handle NF status deregistered, profile id %s", Logger::nrf_app().info("Handle NF status deregistered, profile id %s",
profile_id.c_str()); profile_id.c_str());
std::vector<std::string> notification_uris = {};
get_subscription_list(profile_id, NOTIFICATION_TYPE_NF_DEREGISTERED, std::shared_ptr<nrf_profile> profile = {};
notification_uris); find_nf_profile(profile_id, profile);
// TODO: if (profile != nullptr) {
std::vector<std::string> notification_uris = {};
get_subscription_list(profile_id, NOTIFICATION_TYPE_NF_DEREGISTERED,
notification_uris);
// send notifications
nrf_client_inst->notify_subscribed_event(profile, notification_uris);
} else {
Logger::nrf_app().error("NF profile not found, profile id %s",
profile_id.c_str());
}
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -612,12 +627,23 @@ void nrf_app::subscribe_nf_status_profile_changed() { ...@@ -612,12 +627,23 @@ void nrf_app::subscribe_nf_status_profile_changed() {
void nrf_app::handle_nf_status_profile_changed(const std::string &profile_id) { void nrf_app::handle_nf_status_profile_changed(const std::string &profile_id) {
Logger::nrf_app().info("Handle NF status profile changed, profile id %s", Logger::nrf_app().info("Handle NF status profile changed, profile id %s",
profile_id.c_str()); profile_id.c_str());
std::vector<std::string> notification_uris = {}; std::shared_ptr<nrf_profile> profile = {};
get_subscription_list(profile_id, NOTIFICATION_TYPE_NF_PROFILE_CHANGED, find_nf_profile(profile_id, profile);
notification_uris); if (profile != nullptr) {
// TODO: std::vector<std::string> notification_uris = {};
get_subscription_list(profile_id, NOTIFICATION_TYPE_NF_PROFILE_CHANGED,
notification_uris);
// send notifications
nrf_client_inst->notify_subscribed_event(profile, notification_uris);
} else {
Logger::nrf_app().error("NF profile not found, profile id %s",
profile_id.c_str());
}
} }
//------------------------------------------------------------------------------
void nrf_app::get_subscription_list(const std::string &profile_id, void nrf_app::get_subscription_list(const std::string &profile_id,
uint8_t notification_type, uint8_t notification_type,
std::vector<std::string> &uris) { std::vector<std::string> &uris) {
...@@ -632,11 +658,9 @@ void nrf_app::get_subscription_list(const std::string &profile_id, ...@@ -632,11 +658,9 @@ void nrf_app::get_subscription_list(const std::string &profile_id,
} }
for (auto s : instance_id2nrf_subscription) { for (auto s : instance_id2nrf_subscription) {
// Logger::nrf_app().debug("Subscription id %s", s.first.c_str());
std::string uri; std::string uri;
s.second.get()->get_notification_uri(uri); s.second.get()->get_notification_uri(uri);
// Logger::nrf_app().debug("Uri %s", uri.c_str());
subscription_condition_t condition = {}; subscription_condition_t condition = {};
s.second.get()->get_sub_condition(condition); s.second.get()->get_sub_condition(condition);
...@@ -700,6 +724,9 @@ void nrf_app::get_subscription_list(const std::string &profile_id, ...@@ -700,6 +724,9 @@ void nrf_app::get_subscription_list(const std::string &profile_id,
// TODO: // TODO:
} }
} }
//TODO: reqNotifEvents
} }
// TODO: // TODO:
} }
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under * 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 * the OAI Public License, Version 1.1 (the "License"); you may not use this
* except in compliance with the License. *file except in compliance with the License. You may obtain a copy of the
* You may obtain a copy of the License at *License at
* *
* http://www.openairinterface.org/?page_id=698 * http://www.openairinterface.org/?page_id=698
* *
...@@ -32,12 +32,12 @@ ...@@ -32,12 +32,12 @@
#include <string> #include <string>
#include "NFProfile.h" #include "NFProfile.h"
#include "nrf_profile.hpp"
#include "nrf_subscription.hpp"
#include "nrf_event.hpp"
#include "PatchItem.h" #include "PatchItem.h"
#include "ProblemDetails.h" #include "ProblemDetails.h"
#include "SubscriptionData.h" #include "SubscriptionData.h"
#include "nrf_event.hpp"
#include "nrf_profile.hpp"
#include "nrf_subscription.hpp"
#include "uint_generator.hpp" #include "uint_generator.hpp"
namespace oai { namespace oai {
...@@ -47,20 +47,18 @@ namespace app { ...@@ -47,20 +47,18 @@ namespace app {
using namespace oai::nrf::model; using namespace oai::nrf::model;
class nrf_config; class nrf_config;
class nrf_app { class nrf_app {
public: public:
explicit nrf_app(const std::string &config_file, nrf_event& ev); explicit nrf_app(const std::string &config_file, nrf_event &ev);
nrf_app(nrf_app const&) = delete; nrf_app(nrf_app const &) = delete;
void operator=(nrf_app const&) = delete; void operator=(nrf_app const &) = delete;
virtual ~nrf_app() { virtual ~nrf_app() {
Logger::nrf_app().debug("Delete NRF_APP instance..."); Logger::nrf_app().debug("Delete NRF_APP instance...");
for (auto i: connections) { for (auto i : connections) {
if (i.connected()) i.disconnect(); if (i.connected()) i.disconnect();
} }
} }
/* /*
* Handle a Register NF Instance request * Handle a Register NF Instance request
* @param [const std::string &] nf_instance_id: Instance ID * @param [const std::string &] nf_instance_id: Instance ID
...@@ -70,11 +68,10 @@ class nrf_app { ...@@ -70,11 +68,10 @@ class nrf_app {
* @param [ProblemDetails &] problem_details: Store details of the error * @param [ProblemDetails &] problem_details: Store details of the error
* @return void * @return void
*/ */
void handle_register_nf_instance( void handle_register_nf_instance(const std::string &nf_instance_id,
const std::string &nf_instance_id, const NFProfile &nf_profile, int &http_code,
const NFProfile &nf_profile, int &http_code, const uint8_t http_version,
const uint8_t http_version, ProblemDetails &problem_details);
ProblemDetails &problem_details);
/* /*
* Handle a Get NF Instance Information * Handle a Get NF Instance Information
...@@ -91,17 +88,17 @@ class nrf_app { ...@@ -91,17 +88,17 @@ class nrf_app {
/* /*
* Handle a Update NF Instance request * Handle a Update NF Instance request
* @param [const std::string &] nf_instance_id: Instance ID * @param [const std::string &] nf_instance_id: Instance ID
* @param [const std::vector<PatchItem> &] patchItem: List of modifications need to be applied * @param [const std::vector<PatchItem> &] patchItem: List of modifications
* need to be applied
* @param [int &] http_code: HTTP code used to return to the consumer * @param [int &] http_code: HTTP code used to return to the consumer
* @param [const uint8_t] http_version: HTTP version * @param [const uint8_t] http_version: HTTP version
* @param [ProblemDetails &] problem_details: Store details of the error * @param [ProblemDetails &] problem_details: Store details of the error
* @return void * @return void
*/ */
void handle_update_nf_instance( void handle_update_nf_instance(const std::string &nf_instance_id,
const std::string &nf_instance_id, const std::vector<PatchItem> &patchItem,
const std::vector<PatchItem> &patchItem, int &http_code, int &http_code, const uint8_t http_version,
const uint8_t http_version, ProblemDetails &problem_details);
ProblemDetails &problem_details);
/* /*
* Handle a Get NF Instance request * Handle a Get NF Instance request
...@@ -112,11 +109,10 @@ class nrf_app { ...@@ -112,11 +109,10 @@ class nrf_app {
* @param [ProblemDetails &] problem_details: Store details of the error * @param [ProblemDetails &] problem_details: Store details of the error
* @return void * @return void
*/ */
void handle_get_nf_instance( void handle_get_nf_instance(const std::string &nf_instance_id,
const std::string &nf_instance_id, std::shared_ptr<nrf_profile> &profile,
std::shared_ptr < nrf_profile > &profile, int &http_code, int &http_code, const uint8_t http_version,
const uint8_t http_version, ProblemDetails &problem_details);
ProblemDetails &problem_details);
/* /*
* Handle De-register a given NF Instance * Handle De-register a given NF Instance
...@@ -126,11 +122,9 @@ class nrf_app { ...@@ -126,11 +122,9 @@ class nrf_app {
* @param [ProblemDetails &] problem_details: Store details of the error * @param [ProblemDetails &] problem_details: Store details of the error
* @return void * @return void
*/ */
void handle_deregister_nf_instance( void handle_deregister_nf_instance(const std::string &nf_instance_id,
const std::string &nf_instance_id, int &http_code, const uint8_t http_version,
int &http_code, ProblemDetails &problem_details);
const uint8_t http_version,
ProblemDetails &problem_details);
/* /*
* Handle a Register NF Instance request * Handle a Register NF Instance request
...@@ -140,10 +134,10 @@ class nrf_app { ...@@ -140,10 +134,10 @@ class nrf_app {
* @param [ProblemDetails &] problem_details: Store details of the error * @param [ProblemDetails &] problem_details: Store details of the error
* @return void * @return void
*/ */
void handle_create_subscription( void handle_create_subscription(const SubscriptionData &subscription_data,
const SubscriptionData &subscription_data, std::string &sub_id, int &http_code, std::string &sub_id, int &http_code,
const uint8_t http_version, const uint8_t http_version,
ProblemDetails &problem_details); ProblemDetails &problem_details);
/* /*
* Insert a nrf profile * Insert a nrf profile
...@@ -182,7 +176,8 @@ class nrf_app { ...@@ -182,7 +176,8 @@ class nrf_app {
/* /*
* Find a list of nf profiles with a type * Find a list of nf profiles with a type
* @param [const nf_type_t &] nf_type: Type of NF profile * @param [const nf_type_t &] nf_type: Type of NF profile
* @param [std::vector<std::shared_ptr<nrf_profile>> &] profiles: Store list of corresponding profiles * @param [std::vector<std::shared_ptr<nrf_profile>> &] profiles: Store list
* of corresponding profiles
* @return shared pointer to the profile if found * @return shared pointer to the profile if found
*/ */
void find_nf_profiles( void find_nf_profiles(
...@@ -211,9 +206,9 @@ class nrf_app { ...@@ -211,9 +206,9 @@ class nrf_app {
bool remove_nf_profile(const std::string &profile_id); bool remove_nf_profile(const std::string &profile_id);
bool add_subscription(const std::string &sub_id, bool add_subscription(const std::string &sub_id,
const std::shared_ptr<nrf_subscription> &s); const std::shared_ptr<nrf_subscription> &s);
void subscribe_task_tick (uint64_t ms); void subscribe_task_tick(uint64_t ms);
void handle_heartbeart_timeout(uint64_t ms); void handle_heartbeart_timeout(uint64_t ms);
bool authorize_subscription(const std::shared_ptr<nrf_subscription> &s) const; bool authorize_subscription(const std::shared_ptr<nrf_subscription> &s) const;
...@@ -228,21 +223,24 @@ class nrf_app { ...@@ -228,21 +223,24 @@ class nrf_app {
void subscribe_nf_status_profile_changed(); void subscribe_nf_status_profile_changed();
void handle_nf_status_profile_changed(const std::string &profile_id); void handle_nf_status_profile_changed(const std::string &profile_id);
void get_subscription_list(const std::string &profile_id, uint8_t notification_type, std::vector<std::string> &uris); void get_subscription_list(const std::string &profile_id,
uint8_t notification_type,
std::vector<std::string> &uris);
private: private:
std::map<std::string, std::shared_ptr<nrf_profile>> instance_id2nrf_profile; std::map<std::string, std::shared_ptr<nrf_profile>> instance_id2nrf_profile;
mutable std::shared_mutex m_instance_id2nrf_profile; mutable std::shared_mutex m_instance_id2nrf_profile;
std::map<std::string, std::shared_ptr<nrf_subscription>> instance_id2nrf_subscription; std::map<std::string, std::shared_ptr<nrf_subscription>>
instance_id2nrf_subscription;
mutable std::shared_mutex m_instance_id2nrf_subscription; mutable std::shared_mutex m_instance_id2nrf_subscription;
nrf_event& m_event_sub; nrf_event &m_event_sub;
util::uint_generator<uint32_t> evsub_id_generator; util::uint_generator<uint32_t> evsub_id_generator;
std::vector<bs2::connection> connections; std::vector<bs2::connection> connections;
}; };
} } // namespace app
} } // namespace nrf
} } // namespace oai
#include "nrf_config.hpp" #include "nrf_config.hpp"
#endif /* FILE_SMF_APP_HPP_SEEN */ #endif /* FILE_SMF_APP_HPP_SEEN */
...@@ -27,15 +27,17 @@ ...@@ -27,15 +27,17 @@
\email: Tien-Thinh.Nguyen@eurecom.fr \email: Tien-Thinh.Nguyen@eurecom.fr
*/ */
#include <stdexcept> #include "nrf_client.hpp"
#include <curl/curl.h> #include <curl/curl.h>
#include <pistache/http.h> #include <pistache/http.h>
#include <pistache/mime.h> #include <pistache/mime.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <stdexcept>
#include "3gpp_29.500.h"
#include "logger.hpp" #include "logger.hpp"
#include "nrf_client.hpp" #include "nrf_config.hpp"
using namespace Pistache::Http; using namespace Pistache::Http;
using namespace Pistache::Http::Mime; using namespace Pistache::Http::Mime;
...@@ -43,6 +45,7 @@ using namespace oai::nrf::app; ...@@ -43,6 +45,7 @@ using namespace oai::nrf::app;
using json = nlohmann::json; using json = nlohmann::json;
extern nrf_client *nrf_client_inst; extern nrf_client *nrf_client_inst;
extern nrf_config nrf_cfg;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// To read content of the response from NF // To read content of the response from NF
...@@ -109,7 +112,13 @@ void nrf_client::notify_subscribed_event( ...@@ -109,7 +112,13 @@ void nrf_client::notify_subscribed_event(
// Fill the json part // Fill the json part
nlohmann::json json_data = {}; nlohmann::json json_data = {};
json_data["event"] = "NF_REGISTERED"; json_data["event"] = "NF_REGISTERED";
json_data["nfInstanceUri"] = profile.get()->get_nf_instance_id(); std::string instance_uri =
std::string(inet_ntoa(*((struct in_addr *)&nrf_cfg.sbi.addr4))) + ":" +
std::to_string(nrf_cfg.sbi.port) + NNRF_NFM_BASE +
nrf_cfg.sbi_api_version + NNRF_NFM_NF_INSTANCE +
profile.get()->get_nf_instance_id();
Logger::nrf_app().debug("NF instance URI: %s", instance_uri.c_str());
json_data["nfInstanceUri"] = instance_uri;
std::string body = json_data.dump(); std::string body = json_data.dump();
// create and add an easy handle to a multi curl request // create and add an easy handle to a multi curl request
...@@ -195,21 +204,26 @@ void nrf_client::notify_subscribed_event( ...@@ -195,21 +204,26 @@ void nrf_client::notify_subscribed_event(
void nrf_client::notify_subscribed_event( void nrf_client::notify_subscribed_event(
const std::shared_ptr<nrf_profile> &profile, const std::string &uri) { const std::shared_ptr<nrf_profile> &profile, const std::string &uri) {
Logger::nrf_app().debug( Logger::nrf_app().debug(
"Send notification for the subscribed event to the subscription"); "Send notification to the subscribed NF (URI %s)", uri.c_str());
Logger::nrf_app().debug("NF URI: %s", uri.c_str());
// Fill the json part // Fill the json part
nlohmann::json json_data = {}; nlohmann::json json_data = {};
json_data["event"] = "NF_REGISTERED"; json_data["event"] = "NF_REGISTERED";
json_data["nfInstanceUri"] = profile.get()->get_nf_instance_id(); std::string instance_uri =
std::string(inet_ntoa(*((struct in_addr *)&nrf_cfg.sbi.addr4))) + ":" +
std::to_string(nrf_cfg.sbi.port) + NNRF_NFM_BASE +
nrf_cfg.sbi_api_version + NNRF_NFM_NF_INSTANCE +
profile.get()->get_nf_instance_id();
Logger::nrf_app().debug("NF instance URI: %s", instance_uri.c_str());
json_data["nfInstanceUri"] = instance_uri;
std::string body = json_data.dump(); std::string body = json_data.dump();
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);
CURL *curl = curl = curl_easy_init(); CURL *curl = curl = curl_easy_init();
struct curl_slist *headers = nullptr;
if (curl) { if (curl) {
CURLcode res = {}; CURLcode res = {};
struct curl_slist *headers = nullptr;
// headers = curl_slist_append(headers, "charsets: utf-8"); // headers = curl_slist_append(headers, "charsets: utf-8");
headers = curl_slist_append(headers, "content-type: application/json"); headers = curl_slist_append(headers, "content-type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
...@@ -229,9 +243,23 @@ void nrf_client::notify_subscribed_event( ...@@ -229,9 +243,23 @@ void nrf_client::notify_subscribed_event(
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
Logger::nrf_app().debug("Response from NF, Http Code: %d", httpCode); Logger::nrf_app().debug("Response from NF, Http Code: %d", httpCode);
// TODO: in case of "307 temporary redirect" if (httpCode == HTTP_STATUS_CODE_204_NO_CONTENT) {
} else {
// get cause from the response
json response_data = {};
try {
response_data = json::parse(*httpData.get());
} catch (json::exception &e) {
Logger::nrf_app().warn("Could not get the cause from the response");
}
Logger::nrf_app().debug(
"Response from NF, Http Code: %d, problem details %s", httpCode,
response_data.dump().c_str());
}
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
} }
curl_slist_free_all(headers);
curl_global_cleanup(); curl_global_cleanup();
} }
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under * 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 * the OAI Public License, Version 1.1 (the "License"); you may not use this
* except in compliance with the License. * file except in compliance with the License. You may obtain a copy of the
* You may obtain a copy of the License at * License at
* *
* http://www.openairinterface.org/?page_id=698 * http://www.openairinterface.org/?page_id=698
* *
...@@ -31,22 +31,22 @@ ...@@ -31,22 +31,22 @@
#define FILE_NRF_CONFIG_HPP_SEEN #define FILE_NRF_CONFIG_HPP_SEEN
#include <arpa/inet.h> #include <arpa/inet.h>
#include <libconfig.h++>
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <libconfig.h++>
#include <mutex> #include <mutex>
#include <vector> #include <vector>
#define NRF_CONFIG_STRING_NRF_CONFIG "NRF" #define NRF_CONFIG_STRING_NRF_CONFIG "NRF"
#define NRF_CONFIG_STRING_PID_DIRECTORY "PID_DIRECTORY" #define NRF_CONFIG_STRING_PID_DIRECTORY "PID_DIRECTORY"
#define NRF_CONFIG_STRING_INSTANCE "INSTANCE" #define NRF_CONFIG_STRING_INSTANCE "INSTANCE"
#define NRF_CONFIG_STRING_INTERFACE_SBI "SBI_INTERFACE" #define NRF_CONFIG_STRING_INTERFACE_SBI "SBI_INTERFACE"
#define NRF_CONFIG_STRING_INTERFACE_NAME "INTERFACE_NAME" #define NRF_CONFIG_STRING_INTERFACE_NAME "INTERFACE_NAME"
#define NRF_CONFIG_STRING_IPV4_ADDRESS "IPV4_ADDRESS" #define NRF_CONFIG_STRING_IPV4_ADDRESS "IPV4_ADDRESS"
#define NRF_CONFIG_STRING_PORT "PORT" #define NRF_CONFIG_STRING_PORT "PORT"
#define NRF_CONFIG_STRING_SBI_HTTP2_PORT "HTTP2_PORT" #define NRF_CONFIG_STRING_SBI_HTTP2_PORT "HTTP2_PORT"
#define NRF_CONFIG_STRING_API_VERSION "API_VERSION" #define NRF_CONFIG_STRING_API_VERSION "API_VERSION"
namespace oai { namespace oai {
namespace nrf { namespace nrf {
...@@ -74,37 +74,23 @@ class nrf_config { ...@@ -74,37 +74,23 @@ class nrf_config {
interface_cfg_t sbi; interface_cfg_t sbi;
unsigned int sbi_http2_port; unsigned int sbi_http2_port;
std::string sbi_api_version; std::string sbi_api_version;
//Local configuration // Local configuration
bool local_configuration; bool local_configuration;
nrf_config() nrf_config() : m_rw_lock(), pid_dir(), instance(0), sbi() {
:
m_rw_lock(),
pid_dir(),
instance(0),
sbi() {
sbi.port = 80; sbi.port = 80;
sbi_http2_port = 8080; sbi_http2_port = 8080;
sbi_api_version = "v1"; sbi_api_version = "v1";
};
}
;
~nrf_config(); ~nrf_config();
void lock() { void lock() { m_rw_lock.lock(); };
m_rw_lock.lock(); void unlock() { m_rw_lock.unlock(); };
}
;
void unlock() {
m_rw_lock.unlock();
}
;
int load(const std::string &config_file); int load(const std::string &config_file);
void display(); void display();
}; };
} } // namespace app
} // namespace nrf } // namespace nrf
} } // namespace oai
#endif /* FILE_NRF_CONFIG_HPP_SEEN */ #endif /* FILE_NRF_CONFIG_HPP_SEEN */
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under * 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 * the OAI Public License, Version 1.1 (the "License"); you may not use this
* except in compliance with the License. *file except in compliance with the License. You may obtain a copy of the
* You may obtain a copy of the License at *License at
* *
* http://www.openairinterface.org/?page_id=698 * http://www.openairinterface.org/?page_id=698
* *
...@@ -42,18 +42,15 @@ namespace nrf { ...@@ -42,18 +42,15 @@ namespace nrf {
namespace app { namespace app {
class task_manager; class task_manager;
//class nrf_profile; // class nrf_profile;
class nrf_event { class nrf_event {
public: public:
nrf_event() { nrf_event(){};
} nrf_event(nrf_event const &) = delete;
; void operator=(nrf_event const &) = delete;
nrf_event(nrf_event const&) = delete;
void operator=(nrf_event const&) = delete;
static nrf_event& get_instance() { static nrf_event &get_instance() {
static nrf_event instance; static nrf_event instance;
return instance; return instance;
} }
...@@ -66,24 +63,28 @@ class nrf_event { ...@@ -66,24 +63,28 @@ class nrf_event {
bs2::connection subscribe_task_tick(const task_sig_t::slot_type &sig, bs2::connection subscribe_task_tick(const task_sig_t::slot_type &sig,
uint64_t period, uint64_t start = 0); uint64_t period, uint64_t start = 0);
bs2::connection subscribe_task_tick_extended(const task_sig_t::extended_slot_type &sig, bs2::connection subscribe_task_tick_extended(
uint64_t period, uint64_t start = 0); const task_sig_t::extended_slot_type &sig, uint64_t period,
uint64_t start = 0);
bs2::connection subscribe_nf_status_change(
const nf_status_change_sig_t::slot_type &sig);
bs2::connection subscribe_nf_status_registered(
const nf_status_sig_t::slot_type &sig);
bs2::connection subscribe_nf_status_deregistered(
const nf_status_sig_t::slot_type &sig);
bs2::connection subscribe_nf_status_profile_changed(
const nf_status_sig_t::slot_type &sig);
bs2::connection subscribe_nf_status_change(const nf_status_change_sig_t::slot_type &sig);
bs2::connection subscribe_nf_status_registered(const nf_status_sig_t::slot_type &sig);
bs2::connection subscribe_nf_status_deregistered(const nf_status_sig_t::slot_type &sig);
bs2::connection subscribe_nf_status_profile_changed(const nf_status_sig_t::slot_type &sig);
private: private:
task_sig_t task_tick; task_sig_t task_tick;
nf_status_change_sig_t nf_status_change; nf_status_change_sig_t nf_status_change;
nf_status_sig_t nf_status_registered; nf_status_sig_t nf_status_registered;
nf_status_sig_t nf_status_deregistered; nf_status_sig_t nf_status_deregistered;
nf_status_sig_t nf_status_profile_changed; nf_status_sig_t nf_status_profile_changed;
}; };
} } // namespace app
} } // namespace nrf
} } // namespace oai
#endif /* FILE_NRF_EVENT_HPP_SEEN */ #endif /* FILE_NRF_EVENT_HPP_SEEN */
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under * The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this * 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 * file except in compliance with the License. You may obtain a copy of the
*License at * License at
* *
* http://www.openairinterface.org/?page_id=698 * http://www.openairinterface.org/?page_id=698
* *
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
namespace bs2 = boost::signals2; namespace bs2 = boost::signals2;
namespace oai { namespace oai {
namespace nrf { namespace nrf {
namespace app { namespace app {
...@@ -48,7 +47,7 @@ typedef bs2::signal_type<void(uint64_t), ...@@ -48,7 +47,7 @@ typedef bs2::signal_type<void(uint64_t),
// Signal for NF Status // Signal for NF Status
// Subscription ID, NF Status // Subscription ID, NF Status
typedef bs2::signal_type<void(const std::string &), typedef bs2::signal_type<void(const std::string &),
bs2::keywords::mutex_type<bs2::dummy_mutex>>::type bs2::keywords::mutex_type<bs2::dummy_mutex>>::type
nf_status_sig_t; nf_status_sig_t;
typedef bs2::signal_type<void(const std::shared_ptr<nrf_profile> &p), typedef bs2::signal_type<void(const std::shared_ptr<nrf_profile> &p),
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under * 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 * the OAI Public License, Version 1.1 (the "License"); you may not use this
* except in compliance with the License. * file except in compliance with the License. You may obtain a copy of the
* You may obtain a copy of the License at * License at
* *
* http://www.openairinterface.org/?page_id=698 * http://www.openairinterface.org/?page_id=698
* *
...@@ -33,15 +33,16 @@ ...@@ -33,15 +33,16 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <map> #include <map>
#include <shared_mutex>
#include <memory> #include <memory>
#include <nlohmann/json.hpp>
#include <shared_mutex>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <nlohmann/json.hpp>
#include "3gpp_29.510.h"
#include "logger.hpp"
#include "nrf.h" #include "nrf.h"
#include "nrf_event.hpp" #include "nrf_event.hpp"
#include "logger.hpp"
namespace oai { namespace oai {
namespace nrf { namespace nrf {
...@@ -50,48 +51,44 @@ namespace app { ...@@ -50,48 +51,44 @@ namespace app {
using namespace std; using namespace std;
class nrf_profile : public std::enable_shared_from_this<nrf_profile> { class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
public: public:
nrf_profile(nrf_event &ev) nrf_profile(nrf_event &ev)
: : m_event_sub(ev),
m_event_sub(ev), nf_type(NF_TYPE_UNKNOWN),
nf_type(NF_TYPE_UNKNOWN), heartBeat_timer(0),
heartBeat_timer(0), snssais(),
snssais(), ipv4_addresses(),
ipv4_addresses(), priority(0),
priority(0), capacity(0) {
capacity(0) {
nf_instance_name = ""; nf_instance_name = "";
nf_status = ""; nf_status = "";
json_data = { }; json_data = {};
} }
nrf_profile(nrf_event &ev, const nf_type_t type) nrf_profile(nrf_event &ev, const nf_type_t type)
: : m_event_sub(ev),
m_event_sub(ev), nf_type(type),
nf_type(type), heartBeat_timer(0),
heartBeat_timer(0), snssais(),
snssais(), ipv4_addresses(),
ipv4_addresses(), priority(0),
priority(0), capacity(0) {
capacity(0) {
nf_instance_name = ""; nf_instance_name = "";
nf_status = ""; nf_status = "";
json_data = { }; json_data = {};
} }
nrf_profile(nrf_event &ev, const std::string &id) nrf_profile(nrf_event &ev, const std::string &id)
: : m_event_sub(ev),
m_event_sub(ev), nf_instance_id(id),
nf_instance_id(id), heartBeat_timer(0),
heartBeat_timer(0), snssais(),
snssais(), ipv4_addresses(),
ipv4_addresses(), priority(0),
priority(0), capacity(0),
capacity(0), nf_type(NF_TYPE_UNKNOWN) {
nf_type(NF_TYPE_UNKNOWN) {
nf_instance_name = ""; nf_instance_name = "";
nf_status = ""; nf_status = "";
json_data = { }; json_data = {};
} }
nrf_profile(nrf_profile &b) = delete; nrf_profile(nrf_profile &b) = delete;
...@@ -341,7 +338,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> { ...@@ -341,7 +338,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
* @param [uint64_t] ms: current time * @param [uint64_t] ms: current time
* @return void * @return void
*/ */
void subscribe_task_tick (uint64_t ms); void subscribe_task_tick(uint64_t ms);
/* /*
* Handle heartbeart timeout event * Handle heartbeart timeout event
...@@ -360,7 +357,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> { ...@@ -360,7 +357,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
protected: protected:
nrf_event &m_event_sub; nrf_event &m_event_sub;
bs2::connection task_connection; bs2::connection task_connection;
//From NFProfile (Section 6.1.6.2.2@3GPP TS 29.510 V16.0.0 (2019-06)) // From NFProfile (Section 6.1.6.2.2@3GPP TS 29.510 V16.0.0 (2019-06))
std::string nf_instance_id; std::string nf_instance_id;
std::string nf_instance_name; std::string nf_instance_name;
nf_type_t nf_type; nf_type_t nf_type;
...@@ -370,7 +367,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> { ...@@ -370,7 +367,7 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
std::vector<struct in_addr> ipv4_addresses; std::vector<struct in_addr> ipv4_addresses;
uint16_t priority; uint16_t priority;
uint16_t capacity; uint16_t capacity;
nlohmann::json json_data; //store extra json data nlohmann::json json_data; // store extra json data
/* /*
std::vector<PlmnId> m_PlmnList; std::vector<PlmnId> m_PlmnList;
...@@ -433,32 +430,24 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> { ...@@ -433,32 +430,24 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
bool m_NfServicePersistenceIsSet; bool m_NfServicePersistenceIsSet;
std::vector<NFService> m_NfServices; std::vector<NFService> m_NfServices;
bool m_NfServicesIsSet; bool m_NfServicesIsSet;
std::vector<DefaultNotificationSubscription> m_DefaultNotificationSubscriptions; std::vector<DefaultNotificationSubscription>
bool m_DefaultNotificationSubscriptionsIsSet; m_DefaultNotificationSubscriptions; bool
m_DefaultNotificationSubscriptionsIsSet;
*/ */
}; };
class amf_profile : public nrf_profile { class amf_profile : public nrf_profile {
public: public:
amf_profile(nrf_event &ev) amf_profile(nrf_event &ev) : nrf_profile(ev, NF_TYPE_AMF) { amf_info = {}; }
:
nrf_profile(ev, NF_TYPE_AMF) {
amf_info = { };
}
amf_profile(nrf_event &ev, const std::string &id) amf_profile(nrf_event &ev, const std::string &id) : nrf_profile(ev, id) {
:
nrf_profile(ev, id) {
nf_type = NF_TYPE_AMF; nf_type = NF_TYPE_AMF;
amf_info = { }; amf_info = {};
} }
amf_profile(amf_profile &b) = delete; amf_profile(amf_profile &b) = delete;
~amf_profile() { ~amf_profile() {}
}
/* /*
* Add an AMF info * Add an AMF info
* @param [const amf_info_t &] info: AMF info * @param [const amf_info_t &] info: AMF info
...@@ -516,19 +505,12 @@ class amf_profile : public nrf_profile { ...@@ -516,19 +505,12 @@ class amf_profile : public nrf_profile {
}; };
class smf_profile : public nrf_profile { class smf_profile : public nrf_profile {
public: public:
smf_profile(nrf_event &ev) smf_profile(nrf_event &ev) : nrf_profile(ev, NF_TYPE_SMF) { smf_info = {}; }
:
nrf_profile(ev, NF_TYPE_SMF) {
smf_info = { };
}
smf_profile(nrf_event &ev, const std::string &id) smf_profile(nrf_event &ev, const std::string &id) : nrf_profile(ev, id) {
:
nrf_profile(ev, id) {
nf_type = NF_TYPE_SMF; nf_type = NF_TYPE_SMF;
smf_info = { }; smf_info = {};
} }
smf_profile(smf_profile &b) = delete; smf_profile(smf_profile &b) = delete;
...@@ -588,8 +570,8 @@ class smf_profile : public nrf_profile { ...@@ -588,8 +570,8 @@ class smf_profile : public nrf_profile {
private: private:
smf_info_t smf_info; smf_info_t smf_info;
}; };
} } // namespace app
} } // namespace nrf
} } // namespace oai
#endif #endif
...@@ -69,25 +69,62 @@ void nrf_subscription::set_sub_condition(const subscription_condition_t &c) { ...@@ -69,25 +69,62 @@ void nrf_subscription::set_sub_condition(const subscription_condition_t &c) {
void nrf_subscription::get_sub_condition(subscription_condition_t &c) const { void nrf_subscription::get_sub_condition(subscription_condition_t &c) const {
c = sub_condition; c = sub_condition;
} }
/*
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/*
subscription_condition_t nrf_subscription::get_sub_condition() const { subscription_condition_t nrf_subscription::get_sub_condition() const {
return sub_condition; return sub_condition;
} }
*/ */
//------------------------------------------------------------------------------
void nrf_subscription::set_notif_events(const std::vector<uint8_t> &ev_types) {
notif_events = ev_types;
}
//------------------------------------------------------------------------------
void nrf_subscription::add_notif_event(const uint8_t &ev_type) {
notif_events.push_back(ev_type);
}
//------------------------------------------------------------------------------
void nrf_subscription::get_notif_events(std::vector<uint8_t> &ev_types) const {
ev_types = notif_events;
}
//------------------------------------------------------------------------------
std::vector<uint8_t> nrf_subscription::get_notif_events() const {
return notif_events;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void nrf_subscription::display() { void nrf_subscription::display() {
Logger::nrf_app().debug("Subscription ID: %s", subscription_id.c_str()); Logger::nrf_app().debug("Subscription information");
Logger::nrf_app().debug(".............Sub ID: %s", subscription_id.c_str());
Logger::nrf_app().debug("Notification URI: %s", Logger::nrf_app().debug(".............Notification URI: %s",
nf_status_notification_uri.c_str()); nf_status_notification_uri.c_str());
Logger::nrf_app().debug(".............Subscription condition: %s",
sub_condition.to_string().c_str());
std::string notif_events_str = {};
for (auto n: notif_events){
notif_events_str.append(notification_event_type_e2str[n]);
notif_events_str.append(", ");
}
Logger::nrf_app().debug(".............Notification Events: %s",
notif_events_str.c_str());
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void nrf_subscription::subscribe_nf_status_registered() { void nrf_subscription::subscribe_nf_status_registered() {
Logger::nrf_app().debug("Subscribe to NF status change event"); Logger::nrf_app().debug("Subscribe to NF status change event");
ev_connection = m_event_sub.subscribe_nf_status_change( //TODO: To be updated ev_connection =
boost::bind(&nrf_subscription::handle_nf_status_registered, this, _1)); m_event_sub.subscribe_nf_status_change( // TODO: To be updated
boost::bind(&nrf_subscription::handle_nf_status_registered, this,
_1));
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
...@@ -30,11 +30,10 @@ ...@@ -30,11 +30,10 @@
#ifndef FILE_NRF_SUBSCRIPTION_HPP_SEEN #ifndef FILE_NRF_SUBSCRIPTION_HPP_SEEN
#define FILE_NRF_SUBSCRIPTION_HPP_SEEN #define FILE_NRF_SUBSCRIPTION_HPP_SEEN
#include <string> #include "3gpp_29.510.h"
#include "logger.hpp"
#include "nrf_event.hpp" #include "nrf_event.hpp"
#include "nrf_profile.hpp" #include "nrf_profile.hpp"
#include "logger.hpp"
#include "3gpp_29.510.h"
namespace oai { namespace oai {
namespace nrf { namespace nrf {
...@@ -43,14 +42,17 @@ using namespace std; ...@@ -43,14 +42,17 @@ using namespace std;
class nrf_subscription { class nrf_subscription {
public: public:
nrf_subscription(nrf_event &ev):m_event_sub(ev){ nrf_subscription(nrf_event &ev)
: m_event_sub(ev){
};
};
nrf_subscription(nrf_subscription const &) = delete; nrf_subscription(nrf_subscription const &) = delete;
virtual ~nrf_subscription() { virtual ~nrf_subscription() {
Logger::nrf_app().debug("Delete NRF Subscription instance..."); Logger::nrf_app().debug("Delete NRF Subscription instance...");
if (ev_connection.connected()) ev_connection.disconnect(); if (ev_connection.connected()) ev_connection.disconnect();
} }
void operator=(nrf_subscription const &) = delete; void operator=(nrf_subscription const &) = delete;
void set_subscription_id(const std::string &sub_id); void set_subscription_id(const std::string &sub_id);
...@@ -61,14 +63,21 @@ class nrf_subscription { ...@@ -61,14 +63,21 @@ class nrf_subscription {
void display(); void display();
void set_sub_condition(const subscription_condition_t &c); void set_sub_condition(const subscription_condition_t &c);
void get_sub_condition(subscription_condition_t &c) const; void get_sub_condition(subscription_condition_t &c) const;
// subscription_condition_t get_sub_condition() const; // subscription_condition_t get_sub_condition() const;
void set_notif_events(const std::vector<uint8_t> &ev_types);
void add_notif_event(const uint8_t &ev_type);
void get_notif_events(std::vector<uint8_t> &ev_types) const;
std::vector<uint8_t> get_notif_events() const;
void subscribe_nf_status_registered(); void subscribe_nf_status_registered();
void handle_nf_status_registered(const std::shared_ptr<nrf_profile> &profile); void handle_nf_status_registered(const std::shared_ptr<nrf_profile> &profile);
private: private:
std::string nf_status_notification_uri; std::string nf_status_notification_uri;
std::string subscription_id; std::string subscription_id;
subscription_condition_t sub_condition; subscription_condition_t sub_condition;
std::vector<uint8_t> notif_events;
nrf_event &m_event_sub; nrf_event &m_event_sub;
bs2::connection ev_connection; bs2::connection ev_connection;
}; };
......
...@@ -4,4 +4,9 @@ curl -X GET "http://192.168.1.23/nnrf-nfm/v1/nf-instances?nf-type="serviceId1"& ...@@ -4,4 +4,9 @@ curl -X GET "http://192.168.1.23/nnrf-nfm/v1/nf-instances?nf-type="serviceId1"&
curl -X PATCH -H "Content-Type: application/json" http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d -d '[{"op":"replace","path":"/nfInstanceName", "value": "NEW NAME"}]' curl -X PATCH -H "Content-Type: application/json" http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d -d '[{"op":"replace","path":"/nfInstanceName", "value": "NEW NAME"}]'
curl -X POST http://192.168.1.23/nnrf-nfm/v1/subscriptions -d '{"nfStatusNotificationUri":"http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d", "subscrCond": {"NfTypeCond": {"nfType":"AMF"} } }' curl -X POST http://192.168.1.23/nnrf-nfm/v1/subscriptions -d '{"nfStatusNotificationUri":"http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d", "subscrCond": {"NfTypeCond": {"nfType":"AMF"} } }'
curl -X POST http://192.168.1.23/nnrf-nfm/v1/subscriptions -d '{"nfStatusNotificationUri":"http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d", "subscrCond": {"NfInstanceIdCond": {"nfInstanceId":"AMF"} } }' curl -X POST http://192.168.1.23/nnrf-nfm/v1/subscriptions -d '{"nfStatusNotificationUri":"http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d", "subscrCond": {"NfInstanceIdCond": {"nfInstanceId":"AMF"} } }'
\ No newline at end of file
curl -X POST http://192.168.1.23/nnrf-nfm/v1/subscriptions -d '{"nfStatusNotificationUri":"http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d", "subscrCond": {"NfTypeCond": {"nfType":"AMF"} } }'
curl -X POST -H "Content-Type: application/json" "http://192.168.1.23/nnrf-nfm/v1/subscriptions" -d '{"nfStatusNotificationUri":"http://192.168.1.23/nnrf-nfm/v1/nf-instances/343a924e-6494-4927-860b-d45692c95c2d", "subscrCond": {"NfTypeCond": {"nfType":"AMF"}}, "reqNotifEvents":["NF_REGISTERED", "NF_DEREGISTERED"] }'
\ No newline at end of file
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