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

Update AMF info

parent 33ae125f
......@@ -12,7 +12,7 @@ NRF_CONF[@INSTANCE@]=$INSTANCE
NRF_CONF[@PREFIX@]=$PREFIX
NRF_CONF[@PID_DIRECTORY@]='/var/run'
NRF_CONF[@NRF_INTERFACE_NAME_FOR_SBI@]='enx0050b6f4b8f0'
NRF_CONF[@NRF_INTERFACE_NAME_FOR_SBI@]='wlo1'
NRF_CONF[@NRF_INTERFACE_PORT_FOR_SBI@]='80'
NRF_CONF[@NRF_INTERFACE_HTTP2_PORT_FOR_SBI@]='9090'
......
......@@ -13,6 +13,9 @@
#include "NFInstanceIDDocumentApiImpl.h"
#include "logger.hpp"
#include "nrf_app.hpp"
#include "nrf_config.hpp"
extern oai::nrf::app::nrf_config nrf_cfg;
namespace oai {
namespace nrf {
......
......@@ -41,7 +41,7 @@ void NFInstancesStoreApiImpl::get_nf_instances(
if (!nfType.isEmpty()) {
nf_type = nfType.get();
Logger::nrf_sbi().debug(
"Retrieve a collection of NF Instances, NF type: %s",
".........................................NF type: %s",
nf_type.c_str());
}
......@@ -49,9 +49,8 @@ void NFInstancesStoreApiImpl::get_nf_instances(
if (!limit.isEmpty()) {
limit_item = limit.get();
Logger::nrf_sbi().debug(
"Retrieve a collection of NF Instances, limit number of items: %d",
".........................................Limit number of items: %d",
limit_item);
}
int http_code = 0;
......
......@@ -29,7 +29,7 @@
#define FILE_3GPP_23_003_SEEN
#include <stdint.h>
/*
typedef struct plmn_s {
uint8_t mcc_digit2 :4;
uint8_t mcc_digit1 :4;
......@@ -38,6 +38,13 @@ typedef struct plmn_s {
uint8_t mnc_digit2 :4;
uint8_t mnc_digit1 :4;
} plmn_t;
*/
typedef struct plmn_s {
std::string mcc;
std::string mnc;
} plmn_t;
#define INVALID_TAC_0000 (uint16_t)0x0000
#define INVALID_TAC_FFFE (uint16_t)0xFFFE
......
......@@ -38,13 +38,13 @@
#include "api_conversions.hpp"
#include "string.hpp"
#include "nrf.h"
//#include "api_conversions.hpp"
#include "AmfInfo.h"
#include "logger.hpp"
using namespace oai::nrf::model;
using namespace oai::nrf::app;
using namespace oai::nrf;
//------------------------------------------------------------------------------
/*
bool api_conv::profile_api_to_amf_profile(const NFProfile &api_profile,
......@@ -99,26 +99,30 @@ using namespace oai::nrf;
}
*/
//------------------------------------------------------------------------------
bool api_conv::profile_api_to_amf_profile(
const NFProfile &api_profile, std::shared_ptr<nrf_profile> &profile) {
Logger::nrf_app().debug(
"Convert a NF profile generated from OpenAPI to an AMF profile (profile name %s)",
api_profile.getNfInstanceName().c_str());
"Convert a json-type profile a NF profile (profile ID: %s)",
api_profile.getNfInstanceId().c_str());
profile.get()->set_nf_instance_id(api_profile.getNfInstanceId());
profile.get()->set_nf_instance_name(api_profile.getNfInstanceName());
Logger::nrf_app().debug("NF profile, instance name %s",
Logger::nrf_app().debug("............Instance name: %s",
profile.get()->get_nf_instance_name().c_str());
profile.get()->set_nf_status(api_profile.getNfStatus());
Logger::nrf_app().debug("NF profile, status %s",
Logger::nrf_app().debug("............Status: %s",
profile.get()->get_nf_status().c_str());
profile.get()->set_nf_heartBeat_timer(api_profile.getHeartBeatTimer());
Logger::nrf_app().debug("NF profile, status %d",
profile.get()->get_nf_hertBeat_timer());
Logger::nrf_app().debug("............HeartBeart timer: %d",
profile.get()->get_nf_heartBeat_timer());
profile.get()->set_nf_priority(api_profile.getPriority());
Logger::nrf_app().debug("NF profile, priority %d",
Logger::nrf_app().debug("............Priority: %d",
profile.get()->get_nf_priority());
profile.get()->set_nf_capacity(api_profile.getCapacity());
Logger::nrf_app().debug("NF profile, capacity %d",
Logger::nrf_app().debug("............Capacity: %d",
profile.get()->get_nf_capacity());
//SNSSAIs
std::vector<Snssai> snssai = api_profile.getSNssais();
......@@ -127,7 +131,7 @@ bool api_conv::profile_api_to_amf_profile(
sn.sD = s.getSd();
sn.sST = s.getSst();
profile.get()->add_snssai(sn);
Logger::nrf_app().debug("NF profile, SNSSAI SD %d, SST %s", sn.sST,
Logger::nrf_app().debug("............SNSSAI (SD, SST): %d, %s", sn.sST,
sn.sD.c_str());
}
......@@ -138,22 +142,129 @@ bool api_conv::profile_api_to_amf_profile(
if (inet_pton(AF_INET, util::trim(address).c_str(), buf_in_addr) == 1) {
memcpy(&addr4, buf_in_addr, sizeof(struct in_addr));
} else {
Logger::nrf_app().warn("NF IPv4, address conversion: Bad value %s",
Logger::nrf_app().warn("Address conversion: Bad value %s",
util::trim(address).c_str());
}
Logger::nrf_app().debug("NF profile, IPv4 Addr %s", address.c_str());
Logger::nrf_app().debug("............IPv4 Addr: %s", address.c_str());
profile.get()->add_nf_ipv4_addresses(addr4);
}
if (api_profile.getNfType().compare("AMF") == 0) {
Logger::nrf_app().debug("AMF profile, AMF Info");
amf_info_t info = { };
info.amf_region_id = "AMF_REGION_ID";
info.amf_set_id = "AMF_SET_ID";
(std::static_pointer_cast < amf_profile > (profile)).get()->add_amf_info(
info);
nf_type_t nf_type = string_to_nf_type(api_profile.getNfType());
switch (nf_type) {
case NF_TYPE_AMF: {
Logger::nrf_app().debug("............AMF profile, AMF Info");
profile.get()->set_nf_type(NF_TYPE_AMF);
amf_info_t info = { };
AmfInfo amf_info_api = api_profile.getAmfInfo();
info.amf_region_id = amf_info_api.getAmfRegionId();
info.amf_set_id = amf_info_api.getAmfSetId();
Logger::nrf_app().debug("............AMF Set ID: %s, AMF Region ID: %s",
info.amf_set_id.c_str(),
info.amf_region_id.c_str());
for (auto g : amf_info_api.getGuamiList()) {
guami_t guami = { };
guami.amf_id = g.getAmfId();
guami.plmn.mcc = g.getPlmnId().getMcc();
guami.plmn.mnc = g.getPlmnId().getMnc();
info.guami_list.push_back(guami);
Logger::nrf_app().debug("............AMF GUAMI, AMF_ID: %s",
guami.amf_id.c_str());
Logger::nrf_app().debug(
"....................., PLMN (MCC: %s, MNC: %s)",
guami.plmn.mcc.c_str(), guami.plmn.mnc.c_str());
}
(std::static_pointer_cast < amf_profile > (profile)).get()->add_amf_info(
info);
}
break;
case NF_TYPE_SMF: {
}
break;
default: {
}
}
/*
if (api_profile.getNfType().compare("AMF") == 0) {
Logger::nrf_app().debug("............AMF profile, AMF Info");
profile.get()->set_nf_type("AMF");
amf_info_t info = { };
AmfInfo amf_info_api = api_profile.getAmfInfo();
info.amf_region_id = amf_info_api.getAmfRegionId();
info.amf_set_id = amf_info_api.getAmfSetId();
Logger::nrf_app().debug("............AMF Set ID: %s, AMF Region ID: %s",
info.amf_set_id.c_str(),
info.amf_region_id.c_str());
for (auto g : amf_info_api.getGuamiList()) {
guami_t guami = { };
guami.amf_id = g.getAmfId();
guami.plmn.mcc = g.getPlmnId().getMcc();
guami.plmn.mnc = g.getPlmnId().getMnc();
info.guami_list.push_back(guami);
Logger::nrf_app().debug("............AMF GUAMI, AMF_ID: %s",
guami.amf_id.c_str());
Logger::nrf_app().debug("....................., PLMN (MCC: %s, MNC: %s)",
guami.plmn.mcc.c_str(), guami.plmn.mnc.c_str());
}
(std::static_pointer_cast < amf_profile > (profile)).get()->add_amf_info(
info);
}
*/
return true;
}
//------------------------------------------------------------------------------
nf_type_t api_conv::string_to_nf_type(const std::string &str) {
if (str.compare("NRF") == 0)
return NF_TYPE_NRF;
if (str.compare("AMF") == 0)
return NF_TYPE_AMF;
if (str.compare("SMF") == 0)
return NF_TYPE_SMF;
if (str.compare("AUSF") == 0)
return NF_TYPE_AUSF;
if (str.compare("NEF") == 0)
return NF_TYPE_NEF;
if (str.compare("PCP") == 0)
return NF_TYPE_PCF;
if (str.compare("SMSF") == 0)
return NF_TYPE_SMSF;
if (str.compare("NSSF") == 0)
return NF_TYPE_NSSF;
if (str.compare("UDR") == 0)
return NF_TYPE_UDR;
if (str.compare("LMF") == 0)
return NF_TYPE_LMF;
if (str.compare("GMLC") == 0)
return NF_TYPE_GMLC;
if (str.compare("5G_EIR") == 0)
return NF_TYPE_5G_EIR;
if (str.compare("SEPP") == 0)
return NF_TYPE_SEPP;
if (str.compare("UPF") == 0)
return NF_TYPE_UPF;
if (str.compare("N3IWF") == 0)
return NF_TYPE_N3IWF;
if (str.compare("AF") == 0)
return NF_TYPE_AF;
if (str.compare("UDSF") == 0)
return NF_TYPE_UDSF;
if (str.compare("BSF") == 0)
return NF_TYPE_BSF;
if (str.compare("CHF") == 0)
return NF_TYPE_CHF;
if (str.compare("NWDAF") == 0)
return NF_TYPE_NWDAF;
//default
return NF_TYPE_UNKNOWN;
}
......@@ -32,6 +32,7 @@
#include "NFProfile.h"
#include "nrf_profile.hpp"
#include "nrf.h"
using namespace oai::nrf::model;
using namespace oai::nrf::app;
......@@ -43,10 +44,8 @@ namespace api_conv {
bool profile_api_to_amf_profile(const NFProfile &api_profile,
std::shared_ptr<nrf_profile> &profile);
//bool profile_api_to_amf_profile(const NFProfile &api_profile,
// std::shared_ptr<amf_profile> &profile);
}// namespace api_conv
nf_type_t string_to_nf_type(const std::string &str);
} // namespace api_conv
}
}
......
......@@ -32,6 +32,7 @@
#include "nrf_config.hpp"
#include "logger.hpp"
#include "api_conversions.hpp"
#include "3gpp_29.500.h"
using namespace oai::nrf::app;
using namespace oai::nrf::model;
......@@ -51,7 +52,7 @@ void nrf_app::handle_register_nf_instance(
const oai::nrf::model::NFProfile &nf_profile, int &http_code,
const uint8_t http_version) {
Logger::nrf_app().info("Handle NF Instance Registration(HTTP version %d)",
Logger::nrf_app().info("Handle NF Instance Registration (HTTP version %d)",
http_version);
//Check if nfInstanceID is a valid UUID (version 4)
//TODO
......@@ -116,21 +117,45 @@ void nrf_app::handle_register_nf_instance(
}
*/
nf_type_t type = api_conv::string_to_nf_type(nf_profile.getNfType());
//Create a new NF profile or Update an existing NF profile
Logger::nrf_app().debug("NF Profile with (ID %s, NF type %s)",
nf_instance_id.c_str(),
nf_profile.getNfType().c_str());
std::shared_ptr<nrf_profile> sn = { };
switch (type) {
case NF_TYPE_AMF:
sn = std::make_shared<amf_profile>();
break;
case NF_TYPE_SMF:
//TODO
break;
default:
sn = std::make_shared<nrf_profile>();
}
/*
if (nf_profile.getNfType().compare("AMF") == 0) {
sn = std::make_shared<amf_profile>();
}
} else if (nf_profile.getNfType().compare("SMF") == 0) {
//TODO:
} else {
//default
sn = std::make_shared<nrf_profile>();
}
*/
//convert to nrf_profile
if (api_conv::profile_api_to_amf_profile(nf_profile, sn)) {
add_nf_profile(nf_instance_id, sn);
http_code = HTTP_STATUS_CODE_201_CREATED;
Logger::nrf_app().debug("Added NF Profile to the DB");
if (nf_profile.getNfType().compare("AMF") == 0)
std::static_pointer_cast < amf_profile > (sn).get()->display();
} else {
//error
Logger::nrf_app().warn(
......@@ -140,12 +165,12 @@ void nrf_app::handle_register_nf_instance(
}
//For Debug purpose
std::vector < std::shared_ptr < nrf_profile >> profiles = { };
find_nf_profiles("AMF", profiles);
for (auto profile : profiles) {
(std::static_pointer_cast < amf_profile > (profile)).get()->display();
}
/* std::vector < std::shared_ptr < nrf_profile >> profiles = { };
find_nf_profiles("AMF", profiles);
for (auto profile : profiles) {
(std::static_pointer_cast < amf_profile > (profile)).get()->display();
}
*/
}
......@@ -190,7 +215,11 @@ void nrf_app::handle_get_nf_instances(const std::string &nf_type,
http_version);
std::vector < std::shared_ptr < nrf_profile >> profiles = { };
find_nf_profiles("AMF", profiles);
nf_type_t type = api_conv::string_to_nf_type(nf_type);
find_nf_profiles(type, profiles);
if (profiles.size() == 0) {
Logger::nrf_app().debug("No profile found with type %s", nf_type.c_str());
}
for (auto profile : profiles) {
(std::static_pointer_cast < amf_profile > (profile)).get()->display();
}
......@@ -271,15 +300,16 @@ bool nrf_app::find_nf_profile(const std::string &profile_id,
}
//------------------------------------------------------------------------------
bool nrf_app::find_nf_profiles(
const std::string &nf_type,
void nrf_app::find_nf_profiles(
const nf_type_t &nf_type,
std::vector<std::shared_ptr<nrf_profile>> &profiles) const {
for (auto profile : instance_id2nrf_profile) {
nf_type_t type = profile.second.get()->get_nf_type();
//if (type == NF_TYPE_AMF)
profiles.push_back(profile.second);
//std::string type = profile.second.get()->get_nf_type();
if (profile.second.get()->get_nf_type() == nf_type) {
profiles.push_back(profile.second);
}
}
return true;
//return true;
}
//------------------------------------------------------------------------------
......
......@@ -93,8 +93,8 @@ class nrf_app {
bool find_nf_profile(const std::string &profile_id,
std::shared_ptr<nrf_profile> &p) const;
bool find_nf_profiles(
const std::string &nf_type,
void find_nf_profiles(
const nf_type_t &nf_type,
std::vector<std::shared_ptr<nrf_profile>> &profiles) const;
bool is_profile_exist(const std::string &profile_id) const;
......
......@@ -58,6 +58,11 @@ std::string nrf_profile::get_nf_instance_name() const {
return nf_instance_name;
}
//------------------------------------------------------------------------------
void nrf_profile::set_nf_type(const nf_type_t &type) {
nf_type = type;
}
//------------------------------------------------------------------------------
nf_type_t nrf_profile::get_nf_type() const {
return nf_type;
......@@ -83,12 +88,12 @@ void nrf_profile::set_nf_heartBeat_timer(const int32_t &timer) {
}
//------------------------------------------------------------------------------
void nrf_profile::get_nf_hertBeat_timer(int32_t &timer) const {
void nrf_profile::get_nf_heartBeat_timer(int32_t &timer) const {
timer = heartBeat_timer;
}
//------------------------------------------------------------------------------
int32_t nrf_profile::get_nf_hertBeat_timer() const {
int32_t nrf_profile::get_nf_heartBeat_timer() const {
return heartBeat_timer;
}
......@@ -153,24 +158,26 @@ void nrf_profile::get_nf_ipv4_addresses(std::vector<struct in_addr> &a) const {
//------------------------------------------------------------------------------
void nrf_profile::display() {
Logger::nrf_app().debug("NF profile, instance ID %s", nf_instance_id.c_str());
Logger::nrf_app().debug("............Instance ID: %s",
nf_instance_id.c_str());
Logger::nrf_app().debug("NF profile, instance name %s",
Logger::nrf_app().debug("............Instance name: %s",
nf_instance_name.c_str());
Logger::nrf_app().debug("NF profile, instance type %s",
Logger::nrf_app().debug("............Instance type: %s",
nf_type_e2str[nf_type].c_str());
Logger::nrf_app().debug("NF profile, status %s", nf_status.c_str());
Logger::nrf_app().debug("NF profile, status %d", heartBeat_timer);
Logger::nrf_app().debug("NF profile, priority %d", priority);
Logger::nrf_app().debug("NF profile, capacity %d", capacity);
Logger::nrf_app().debug("............Status: %s", nf_status.c_str());
Logger::nrf_app().debug("............HeartBeat timer: %d", heartBeat_timer);
Logger::nrf_app().debug("............Priority: %d", priority);
Logger::nrf_app().debug("............Capacity: %d", capacity);
//SNSSAIs
for (auto s : snssais) {
Logger::nrf_app().debug("NF profile, SNSSAI %d, %s", s.sST, s.sD.c_str());
Logger::nrf_app().debug("............NNSSAI(SST, SD): %d, %s", s.sST,
s.sD.c_str());
}
//IPv4 Addresses
for (auto address : ipv4_addresses) {
Logger::nrf_app().debug("NF profile, IPv4 Addr %s", inet_ntoa(address));
Logger::nrf_app().debug("............IPv4 Addr: %s", inet_ntoa(address));
}
}
......@@ -188,8 +195,16 @@ void amf_profile::get_amf_info(amf_info_t &infos) const {
void amf_profile::display() {
nrf_profile::display();
Logger::nrf_app().debug("AMF Info: AMF Set ID %s, AMF Region ID %s",
Logger::nrf_app().debug("............AMF Set ID: %s, AMF Region ID: %s",
amf_info.amf_set_id.c_str(),
amf_info.amf_region_id.c_str());
for (auto g : amf_info.guami_list) {
Logger::nrf_app().debug("............AMF GUAMI, AMF_ID: %s",
g.amf_id.c_str());
Logger::nrf_app().debug("....................., PLMN (MCC: %s, MNC: %s)",
g.plmn.mcc.c_str(), g.plmn.mnc.c_str());
}
}
......@@ -50,15 +50,24 @@ using namespace std;
class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
public:
nrf_profile() = delete;
nrf_profile(const nf_type_t type)
nrf_profile()
:
nf_type(NF_TYPE_UNKNOWN),
heartBeat_timer(0),
snssais(),
ipv4_addresses(),
priority(0),
capacity(0) {
nf_instance_name = "";
nf_status = "";
}
nrf_profile(const nf_type_t type)
:nf_type(type),
heartBeat_timer(0),
snssais(),
ipv4_addresses(),
priority(0),
capacity(0) {
nf_type = type;
nf_instance_name = "";
nf_status = "";
}
......@@ -70,10 +79,10 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
snssais(),
ipv4_addresses(),
priority(0),
capacity(0) {
capacity(0),
nf_type(NF_TYPE_UNKNOWN){
nf_instance_name = "";
nf_status = "";
nf_type = NF_TYPE_UNKNOWN;
}
nrf_profile(nrf_profile &b) = delete;
......@@ -136,10 +145,17 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
/*
* Get NF type
* @param
* @return [nf_type_t] nf type
* @return [std::string] nf type
*/
nf_type_t get_nf_type() const;
/*
* Set NF type
* @param [const nf_type_t &] type: nf type
* @return void
*/
void set_nf_type(const nf_type_t &type);
/*
* Set NF instance heartBeat_timer
* @param [const std::string &] timer: heartBeat_timer
......@@ -152,14 +168,14 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
* @param [std::string &] timer: store heartBeat_timer
* @return void:
*/
void get_nf_hertBeat_timer(int32_t &timer) const;
void get_nf_heartBeat_timer(int32_t &timer) const;
/*
* Get NF heartBeat_timer
* @param void
* @return heartBeat_timer
*/
int32_t get_nf_hertBeat_timer() const;
int32_t get_nf_heartBeat_timer() const;
/*
* Set NF instance priority
......
......@@ -57,7 +57,7 @@ void my_app_signal_handler(int s) {
delete nrf_app_inst;
nrf_app_inst = nullptr;
std::cout << "NRF APP memory done." << std::endl;
std::cout << "Freeing Allocated memory done" << std::endl;
std::cout << "Freeing allocated memory done" << std::endl;
exit(0);
}
......
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