Commit 2b3bf0a0 authored by Raphael Defosseux's avatar Raphael Defosseux
Browse files

Merge branch 'upf_profile_update' into 'develop'

added optional filed up_interface from upfinfo

See merge request !16
parents 1d093799 d178816d
Pipeline #26778 passed with stage
in 0 seconds
......@@ -63,10 +63,10 @@ void from_json(const nlohmann::json& j, InterfaceUpfInfoItem& o) {
}
}
UPInterfaceType InterfaceUpfInfoItem::getInterfaceType() const {
std::string InterfaceUpfInfoItem::getInterfaceType() const {
return m_InterfaceType;
}
void InterfaceUpfInfoItem::setInterfaceType(UPInterfaceType const& value) {
void InterfaceUpfInfoItem::setInterfaceType(std::string const& value) {
m_InterfaceType = value;
}
std::vector<std::string>& InterfaceUpfInfoItem::getIpv4EndpointAddresses() {
......
......@@ -45,8 +45,14 @@ class InterfaceUpfInfoItem {
/// <summary>
///
/// </summary>
UPInterfaceType getInterfaceType() const;
void setInterfaceType(UPInterfaceType const& value);
// UPInterfaceType getInterfaceType() const;
// void setInterfaceType(UPInterfaceType const& value);
std::string getInterfaceType() const;
void setInterfaceType(std::string const& value);
bool InterfaceTypeIsSet() const;
void unsetInterfaceType();
/// <summary>
///
/// </summary>
......@@ -80,7 +86,8 @@ class InterfaceUpfInfoItem {
friend void from_json(const nlohmann::json& j, InterfaceUpfInfoItem& o);
protected:
UPInterfaceType m_InterfaceType;
// UPInterfaceType m_InterfaceType;
std::string m_InterfaceType;
std::vector<std::string> m_Ipv4EndpointAddresses;
bool m_Ipv4EndpointAddressesIsSet;
......
......@@ -30,6 +30,17 @@ enum class nf_status_e { REGISTERED = 0, SUSPENDED = 1, UNDISCOVERABLE = 2 };
static const std::vector<std::string> nf_status_e2str = {
"REGISTERED", "SUSPENDED", "UNDISCOVERABLE"};
typedef enum nf_up_interface_type_s {
N3 = 0,
N6 = 1,
N9 = 2,
DATA_FORWARDING = 3,
TYPE_UNKNOWN = 4
} nf_up_interface_type_t;
static const std::vector<std::string> up_interface_type_e2str = {
"N3", "N6", "N9", "DATA_FORWARDING", "UNKNOWN"};
typedef struct amf_info_s {
std::string amf_set_id;
std::string amf_region_id;
......@@ -61,8 +72,17 @@ typedef struct snssai_upf_info_item_s {
std::vector<dnn_upf_info_item_t> dnn_upf_info_list;
} snssai_upf_info_item_t;
typedef struct interface_upf_info_item_s {
std::string interface_type;
std::vector<struct in_addr> ipv4_addresses;
std::vector<struct in6_addr> ipv6_addresses;
std::string endpoint_fqdn;
std::string network_instance;
} interface_upf_info_item_t;
typedef struct upf_info_s {
std::vector<snssai_upf_info_item_t> snssai_upf_info_list;
std::vector<interface_upf_info_item_t> interface_upf_info_list;
} upf_info_t;
typedef struct supi_range_ausf_info_item_s {
......
......@@ -216,10 +216,81 @@ bool api_conv::profile_api_to_nrf_profile(
info.snssai_upf_info_list.push_back(snssai);
}
if (upf_info_api.interfaceUpfInfoListIsSet()) {
for (auto s : upf_info_api.getInterfaceUpfInfoList()) {
interface_upf_info_item_t interface = {};
nf_up_interface_type_t up_interface_type =
string_to_up_interface_type(s.getInterfaceType());
switch (up_interface_type) {
case N3: {
interface.interface_type = "N3";
} break;
case N6: {
interface.interface_type = "N6";
} break;
case N9: {
interface.interface_type = "N9";
} break;
case DATA_FORWARDING: {
interface.interface_type = "DATA_FORWARDING";
} break;
default: {
interface.interface_type = "UNKNOWN";
}
}
if (s.endpointFqdnIsSet())
interface.endpoint_fqdn = s.getEndpointFqdn();
if (s.networkInstanceIsSet())
interface.network_instance = s.getNetworkInstance();
if (s.ipv4EndpointAddressesIsSet()) {
std::vector<std::string> ipv4_addr_str =
s.getIpv4EndpointAddresses();
for (auto address : ipv4_addr_str) {
struct in_addr addr4 = {};
unsigned char buf_in_addr[sizeof(struct in_addr)];
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(
"Address conversion: Bad value %s",
util::trim(address).c_str());
}
Logger::nrf_app().debug(
"\t\tEndpoint: %s, IPv4 Addr: %s, FQDN: %s, NWI: %s",
interface.interface_type.c_str(), address.c_str(),
interface.endpoint_fqdn.c_str(),
interface.network_instance.c_str());
interface.ipv4_addresses.push_back(addr4);
}
}
// ToDo for ipv6
// if (s.ipv6EndpointAddressesIsSet()) {
// std::vector<Ipv6Addr> ipv6_addr_str =
// s.getIpv6EndpointAddresses();
// for (auto address : ipv6_addr_str) {
// struct in6_addr addr6 = {};
// unsigned char buf_in_addr[sizeof(struct in6_addr)];
// if (inet_pton(
// AF_INET, 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("\tIPv4 Addr: %s", address.c_str());
// interface.ipv6_addresses.push_back(addr6);
// }
// }
info.interface_upf_info_list.push_back(interface);
}
}
(std::static_pointer_cast<upf_profile>(profile))
.get()
->add_upf_info(info);
} break;
case NF_TYPE_AUSF: {
Logger::nrf_app().debug("\tAUSF profile, AUSFF Info");
......@@ -443,6 +514,16 @@ nf_type_t api_conv::string_to_nf_type(const std::string& str) {
return NF_TYPE_UNKNOWN;
}
//------------------------------------------------------------------------------
nf_up_interface_type_t api_conv::string_to_up_interface_type(
const std::string& str) {
if (str.compare("N3") == 0) return N3;
if (str.compare("N6") == 0) return N6;
if (str.compare("N9") == 0) return N9;
if (str.compare("DATA_FORWARDING") == 0) return DATA_FORWARDING;
// default
return TYPE_UNKNOWN;
}
//------------------------------------------------------------------------------
patch_op_type_t api_conv::string_to_patch_operation(const std::string& str) {
if (str.compare("add") == 0) return PATCH_OP_ADD;
......
......@@ -69,6 +69,13 @@ bool subscription_api_to_nrf_subscription(
*/
nf_type_t string_to_nf_type(const std::string& str);
/*
* Convert a string to nf type
* @param [const std::string &] str: string input
* @return the corresponding up_interface_type
*/
nf_up_interface_type_t string_to_up_interface_type(const std::string& str);
/*
* Convert a string to Patch operation
* @param [const std::string &] str: string input
......
......@@ -1001,6 +1001,14 @@ void upf_profile::display() {
"\t\tSNSSAI UPF Info List, DNN List: %s", d.dnn.c_str());
}
}
if (!upf_info.interface_upf_info_list.empty()) {
for (auto s : upf_info.interface_upf_info_list) {
Logger::nrf_app().debug(
"\t\tInterface UPF Info List, Interface Type : %s, Network Instance "
"%s",
s.interface_type.c_str(), s.network_instance.c_str());
}
}
}
//------------------------------------------------------------------------------
......@@ -1102,6 +1110,25 @@ void upf_profile::to_json(nlohmann::json& data) const {
}
data["upfInfo"]["sNssaiUpfInfoList"].push_back(tmp);
}
if (!upf_info.interface_upf_info_list.empty()) {
data["upfInfo"]["interfaceUpfInfoList"] = nlohmann::json::array();
for (auto s : upf_info.interface_upf_info_list) {
nlohmann::json tmp = {};
tmp["interfaceType"] = s.interface_type;
if (!s.endpoint_fqdn.empty()) tmp["endpointFqdn"] = s.endpoint_fqdn;
if (!s.network_instance.empty())
tmp["networkInstance"] = s.network_instance;
if (!s.ipv4_addresses.empty()) {
tmp["ipv4EndpointAddresses"] = nlohmann::json::array();
for (auto address : s.ipv4_addresses) {
nlohmann::json addr = inet_ntoa(address);
tmp["ipv4EndpointAddresses"].push_back(addr);
}
}
// ToDo for ipv6
data["upfInfo"]["interfaceUpfInfoList"].push_back(tmp);
}
}
}
//------------------------------------------------------------------------------
......
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