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

Add function to send NF register/update to NRF

parent ed7b3bb2
......@@ -100,5 +100,12 @@ SPGW-U =
SPGW-C_LIST = (
{IPV4_ADDRESS="@SPGWC0_IP_ADDRESS@" ;}
);
NRF :
{
IPV4_ADDRESS = "@NRF_IPV4_ADDRESS@"; # YOUR NRF CONFIG HERE
PORT = @NRF_PORT@; # YOUR NRF CONFIG HERE (default: 80)
API_VERSION = "@NRF_API_VERSION@"; # YOUR NRF API VERSION FOR SBI CONFIG HERE
};
};
......@@ -23,6 +23,7 @@
#define FILE_3GPP_29_510_NRF_SEEN
#include <vector>
#include <nlohmann/json.hpp>
typedef struct s_nssai // section 28.4, TS23.003
{
......@@ -59,7 +60,23 @@ typedef struct upf_info_s {
std::vector<snssai_upf_info_item_t> snssai_upf_info_list;
} upf_info_t;
typedef struct patch_item_s {
std::string op;
std::string path;
// std::string from;
std::string value;
nlohmann::json to_json() const {
nlohmann::json json_data = {};
json_data["op"] = op;
json_data["path"] = path;
json_data["value"] = value;
return json_data;
}
} patch_item_t;
#define NRF_CURL_TIMEOUT_MS 100L
#define NNRF_NFM_BASE "/nnrf-nfm/"
#define NNRF_NF_REGISTER_URL "/nf-instances/"
#endif
......@@ -35,6 +35,8 @@
#include "spgwu_sx.hpp"
#include "spgwu_nrf.hpp"
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <stdexcept>
using namespace pfcp;
......@@ -271,3 +273,5 @@ void spgwu_app::handle_itti_msg(
Logger::spgwu_app().info(
"Received SXAB_SESSION_REPORT_RESPONSE seid " SEID_FMT " ", m->seid);
}
......@@ -80,6 +80,7 @@ class spgwu_app {
// void handle_itti_msg (itti_sxab_session_deletion_response& m);
// void handle_itti_msg (itti_sxab_session_report_request& m);
void handle_itti_msg(std::shared_ptr<itti_sxab_session_report_response> m);
};
} // namespace spgwu
#endif /* FILE_SPGWU_APP_HPP_SEEN */
......@@ -453,6 +453,31 @@ int spgwu_config::load(const string& config_file) {
SPGWU_CONFIG_STRING_SPGWC_LIST, i, config_file.c_str());
}
}
// NRF
const Setting &nrf_cfg = spgwu_cfg[SPGWU_CONFIG_STRING_NRF];
struct in_addr nrf_ipv4_addr;
unsigned int nrf_port = 0;
std::string nrf_api_version;
string nrf_address = {};
nrf_cfg.lookupValue(SPGWU_CONFIG_STRING_NRF_IPV4_ADDRESS, nrf_address);
IPV4_STR_ADDR_TO_INADDR(util::trim(nrf_address).c_str(), nrf_ipv4_addr,
"BAD IPv4 ADDRESS FORMAT FOR NRF !");
nrf_addr.ipv4_addr = nrf_ipv4_addr;
if (!(nrf_cfg.lookupValue(SPGWU_CONFIG_STRING_NRF_PORT, nrf_port))) {
Logger::spgwu_app().error(SPGWU_CONFIG_STRING_NRF_PORT "failed");
throw(SPGWU_CONFIG_STRING_NRF_PORT "failed");
}
nrf_addr.port = nrf_port;
if (!(nrf_cfg.lookupValue(SPGWU_CONFIG_STRING_API_VERSION,
nrf_api_version))) {
Logger::spgwu_app().error(SPGWU_CONFIG_STRING_API_VERSION "failed");
throw(SPGWU_CONFIG_STRING_API_VERSION "failed");
}
nrf_addr.api_version = nrf_api_version;
} catch (const SettingNotFoundException& nfex) {
Logger::spgwu_app().error("%s : %s", nfex.what(), nfex.getPath());
return RETURNerror;
......
......@@ -63,6 +63,10 @@ namespace spgwu {
#define SPGWU_CONFIG_STRING_SNAT "SNAT"
#define SPGWU_CONFIG_STRING_MAX_PFCP_SESSIONS "MAX_PFCP_SESSIONS"
#define SPGWU_CONFIG_STRING_SPGWC_LIST "SPGW-C_LIST"
#define SPGWU_CONFIG_STRING_NRF "NRF"
#define SPGWU_CONFIG_STRING_NRF_IPV4_ADDRESS "IPV4_ADDRESS"
#define SPGWU_CONFIG_STRING_NRF_PORT "PORT"
#define SPGWU_CONFIG_STRING_API_VERSION "API_VERSION"
#define SPGWU_CONFIG_STRING_ITTI_TASKS "ITTI_TASKS"
#define SPGWU_CONFIG_STRING_ITTI_TIMER_SCHED_PARAMS "ITTI_TIMER_SCHED_PARAMS"
#define SPGWU_CONFIG_STRING_S1U_SCHED_PARAMS "S1U_SCHED_PARAMS"
......@@ -124,6 +128,12 @@ class spgwu_config {
std::vector<pdn_cfg_t> pdns;
std::vector<pfcp::node_id_t> spgwcs;
struct {
struct in_addr ipv4_addr;
unsigned int port;
std::string api_version;
} nrf_addr;
spgwu_config()
: m_rw_lock(),
pid_dir(),
......@@ -149,6 +159,10 @@ class spgwu_config {
sx.thread_rd_sched_params.sched_priority = 95;
sx.port = pfcp::default_port;
nrf_addr.ipv4_addr.s_addr = INADDR_ANY;
nrf_addr.port = 80;
nrf_addr.api_version = "v1";
};
void lock() { m_rw_lock.lock(); };
void unlock() { m_rw_lock.unlock(); };
......
This diff is collapsed.
......@@ -32,19 +32,27 @@
#include <map>
#include <thread>
#include "itti.hpp"
#include <curl/curl.h>
#include "3gpp_29.510.h"
#include "itti_msg_nrf.hpp"
#include "spgwu_profile.hpp"
namespace spgwu {
#define TASK_SPGWU_NRF_TIMEOUT_NRF_HEARTBEAT_REQUEST 1
#define TASK_SPGWU_NRF_TIMEOUT_NRF_HEARTBEAT (1)
#define TASK_SPGWU_NRF_TIMEOUT_NRF_DEREGISTRATION (2)
class spgwu_nrf {
private:
std::thread::id thread_id;
std::thread thread;
spgwu_profile upf_profile; // UPF profile
std::string upf_instance_id; // UPF instance id
timer_id_t timer_nrf_heartbeat;
public:
spgwu_nrf();
spgwu_nrf(spgwu_nrf const &) = delete;
......@@ -59,14 +67,18 @@ class spgwu_nrf {
void register_nf_instance(
std::shared_ptr<itti_nrf_register_nf_instance_request> msg);
void send_register_nf_instance(std::string &url);
void send_update_nf_instance(std::string &url, nlohmann::json &data);
/*
* Send NF instance update to NRF
* @param [std::shared_ptr<itti_nrf_update_nf_instance_request>] msg: Content
* of message to be sent
* @return void
*/
void update_nf_instance(
std::shared_ptr<itti_nrf_update_nf_instance_request> msg);
/*
* Send NF deregister to NRF
......@@ -76,6 +88,52 @@ class spgwu_nrf {
*/
void deregister_nf_instance(
std::shared_ptr<itti_nrf_deregister_nf_instance> msg);
/*
* Trigger NF instance registration to NRF
* @param [void]
* @return void
*/
void register_to_nrf();
/*
* Generate a random UUID for SMF instance
* @param [void]
* @return void
*/
void generate_uuid();
/*
* Generate a SMF profile for this instance
* @param [void]
* @return void
*/
void generate_upf_profile();
/*
* Send request to N11 task to trigger NF instance registration to NRF
* @param [void]
* @return void
*/
void trigger_nf_registration_request();
/*
* Send request to N11 task to trigger NF instance deregistration to NRF
* @param [void]
* @return void
*/
void trigger_nf_deregistration();
/*
* will be executed when NRF Heartbeat timer expires
* @param [timer_id_t] timer_id
* @param [uint64_t] arg2_user
* @return void
*/
void timer_nrf_heartbeat_timeout(timer_id_t timer_id, uint64_t arg2_user);
void timer_nrf_deregistration(timer_id_t timer_id, uint64_t arg2_user);
};
} // namespace smf
#endif /* FILE_SPGWU_NRF_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