Commit 52ed32fc authored by Raphael Defosseux's avatar Raphael Defosseux

Merge branch 'nf_profile_update' into 'develop'

fqdn added in NFProfile

See merge request oai/cn5g/oai-cn5g-nrf!7
parents 2f1e8ef3 53b348bd
......@@ -83,7 +83,11 @@ bool api_conv::profile_api_to_nrf_profile(
Logger::nrf_app().debug(
"\tSNSSAI (SD, SST): %d, %s", sn.sST, sn.sD.c_str());
}
if (api_profile.fqdnIsSet()) {
profile.get()->set_fqdn(api_profile.getFqdn());
Logger::nrf_app().debug("\tFQDN: %s", api_profile.getFqdn().c_str());
}
if (api_profile.ipv4AddressesIsSet()) {
std::vector<std::string> ipv4_addr_str = api_profile.getIpv4Addresses();
for (auto address : ipv4_addr_str) {
struct in_addr addr4 = {};
......@@ -98,6 +102,25 @@ bool api_conv::profile_api_to_nrf_profile(
Logger::nrf_app().debug("\tIPv4 Addr: %s", address.c_str());
profile.get()->add_nf_ipv4_addresses(addr4);
}
}
// ToDo: For ipv6
// if (api_profile.ipv6AddressesIsSet()) {
// std::vector<Ipv6Addr> ipv6_addr = api_profile.getIpv6Addresses();
// for (auto address : ipv6_addr) {
// struct in6_addr addr6 = {};
// unsigned char buf_in_addr[sizeof(struct in6_addr)];
// if (inet_pton(AF_INET6, util::trim(address).c_str(), buf_in_addr) == 1)
// {
// memcpy(&addr6, buf_in_addr, sizeof(struct in6_addr));
// } else {
// Logger::nrf_app().warn(
// "Address conversion: Bad value %s", util::trim(address).c_str());
// }
// Logger::nrf_app().debug("\tIPv6 Addr: %s", address.c_str());
// profile.get()->add_nf_ipv6_addresses(addr6);
// }
// }
nf_type_t nf_type = string_to_nf_type(api_profile.getNfType());
......
......@@ -157,6 +157,15 @@ void nrf_profile::add_snssai(const snssai_t& s) {
snssais.push_back(s);
}
//------------------------------------------------------------------------------
void nrf_profile::set_fqdn(const std::string& fqdN) {
fqdn = fqdN;
}
//------------------------------------------------------------------------------
std::string nrf_profile::get_fqdn() const {
return fqdn;
}
//------------------------------------------------------------------------------
void nrf_profile::set_nf_ipv4_addresses(const std::vector<struct in_addr>& a) {
ipv4_addresses = a;
......@@ -167,6 +176,15 @@ void nrf_profile::add_nf_ipv4_addresses(const struct in_addr& a) {
ipv4_addresses.push_back(a);
}
//------------------------------------------------------------------------------
void nrf_profile::set_nf_ipv6_addresses(const std::vector<struct in6_addr>& a) {
ipv6_addresses = a;
}
//------------------------------------------------------------------------------
void nrf_profile::add_nf_ipv6_addresses(const struct in6_addr& a) {
ipv6_addresses.push_back(a);
}
//------------------------------------------------------------------------------
void nrf_profile::get_nf_ipv4_addresses(std::vector<struct in_addr>& a) const {
a = ipv4_addresses;
}
......@@ -211,12 +229,14 @@ void nrf_profile::display() {
for (auto s : snssais) {
Logger::nrf_app().debug("\tNNSSAI(SST, SD): %d, %s", s.sST, s.sD.c_str());
}
if (!fqdn.empty()) {
Logger::nrf_app().debug("\tFQDN: %s", fqdn.c_str());
}
// IPv4 Addresses
for (auto address : ipv4_addresses) {
Logger::nrf_app().debug("\tIPv4 Addr: %s", inet_ntoa(address));
}
// ToDo : For ipv6 addresses
if (!json_data.empty()) {
Logger::nrf_app().debug("\tJson Data: %s", json_data.dump().c_str());
}
......@@ -277,12 +297,22 @@ bool nrf_profile::replace_profile_info(
}
}
if (path.compare("fqdn") == 0) {
fqdn = value;
return true;
}
// Replace an array
if (path.compare("ipv4Addresses") == 0) {
Logger::nrf_app().info("Does not support this operation for ipv4Addresses");
return false;
}
if (path.compare("ipv6Addresses") == 0) {
Logger::nrf_app().info("Does not support this operation for ipv6Addresses");
return false;
}
if (path.compare("sNssais") == 0) {
Logger::nrf_app().info("Does not support this operation for sNssais");
return false;
......@@ -350,6 +380,11 @@ bool nrf_profile::add_profile_info(
}
}
if (path.compare("fqdn") == 0) {
fqdn = value;
return true;
}
// add an element to a list
if (path.compare("ipv4Addresses") == 0) {
std::string address = value;
......@@ -367,6 +402,23 @@ bool nrf_profile::add_profile_info(
return true;
}
// add an element to a list
if (path.compare("ipv6Addresses") == 0) {
std::string address = value;
struct in6_addr addr6 = {};
unsigned char buf_in_addr[sizeof(struct in6_addr)];
if (inet_pton(AF_INET6, util::trim(address).c_str(), buf_in_addr) == 1) {
memcpy(&addr6, buf_in_addr, sizeof(struct in6_addr));
} else {
Logger::nrf_app().warn(
"Address conversion: Bad value %s", util::trim(address).c_str());
return false;
}
Logger::nrf_app().debug("Added IPv6 Addr: %s", address.c_str());
ipv6_addresses.push_back(addr6);
return true;
}
// add an element to a list of json object
if (path.compare("sNssais") == 0) {
Logger::nrf_app().info("Does not support this operation for sNssais");
......@@ -415,6 +467,11 @@ bool nrf_profile::remove_profile_info(const std::string& path) {
return true;
}
if (path.compare("fqdn") == 0) {
fqdn = "";
return true;
}
// path: e.g., /ipv4Addresses/4
if (path.find("ipv4Addresses") != std::string::npos) {
std::vector<std::string> parts;
......@@ -473,12 +530,21 @@ void nrf_profile::to_json(nlohmann::json& data) const {
;
data["sNssais"].push_back(tmp);
}
if (!fqdn.empty()) {
data["fqdn"] = fqdn;
}
// ipv4_addresses
data["ipv4Addresses"] = nlohmann::json::array();
for (auto address : ipv4_addresses) {
nlohmann::json tmp = inet_ntoa(address);
data["ipv4Addresses"].push_back(tmp);
}
// // ipv6_addresses
// data["ipv6Addresses"] = nlohmann::json::array();
// for (auto address : ipv6_addresses) {
// nlohmann::json tmp = inet_ntoa(address);
// data["ipv6Addresses"].push_back(tmp);
// }
data["priority"] = priority;
data["capacity"] = capacity;
// NF services
......
......@@ -57,7 +57,9 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
nf_type(NF_TYPE_UNKNOWN),
heartBeat_timer(0),
snssais(),
fqdn(),
ipv4_addresses(),
ipv6_addresses(),
priority(0),
capacity(0),
nf_services(),
......@@ -73,7 +75,9 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
nf_type(type),
heartBeat_timer(0),
snssais(),
fqdn(),
ipv4_addresses(),
ipv6_addresses(),
priority(0),
capacity(0),
nf_services(),
......@@ -90,7 +94,9 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
nf_instance_id(id),
heartBeat_timer(0),
snssais(),
fqdn(),
ipv4_addresses(),
ipv6_addresses(),
priority(0),
capacity(0),
nf_services(),
......@@ -272,6 +278,20 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
*/
void get_nf_snssais(std::vector<snssai_t>& s) const;
/*
* Get NF fqdn
* @param
* @return [std::string] nf fqdn
*/
std::string get_fqdn() const;
/*
* Set NF fqdn
* @param [const fqdn_t &] fqdn: nf fqdn
* @return void
*/
void set_fqdn(const std::string& fqdn);
/*
* Set NF instance ipv4_addresses
* @param [std::vector<struct in_addr> &] a: ipv4_addresses
......@@ -286,6 +306,20 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
*/
void add_nf_ipv4_addresses(const struct in_addr& a);
/*
* Set NF instance ipv6_addresses
* @param [std::vector<struct in6_addr> &] a: ipv6_addresses
* @return void
*/
void set_nf_ipv6_addresses(const std::vector<struct in6_addr>& a);
/*
* Add an IPv6 address to the list of addresses
* @param [const struct in_addr &] a: ipv6_address
* @return void
*/
void add_nf_ipv6_addresses(const struct in6_addr& a);
/*
* Get NF instance ipv4_addresses
* @param [std::vector<struct in_addr> &] a: store instance's ipv4_addresses
......@@ -441,7 +475,9 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
std::string nf_status;
int32_t heartBeat_timer;
std::vector<snssai_t> snssais;
std::string fqdn;
std::vector<struct in_addr> ipv4_addresses;
std::vector<struct in6_addr> ipv6_addresses;
uint16_t priority;
uint16_t capacity;
nlohmann::json json_data; // store extra json data
......
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