Commit c8356911 authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

First version for Update AMF conf API

parent 50653056
......@@ -749,7 +749,8 @@ void amf_app::handle_itti_message(itti_sbi_update_amf_configuration& itti_msg) {
// Process the request and trigger the response from AMF API Server
nlohmann::json response_data = {};
response_data["content"] = {};
response_data["content"] = itti_msg.configuration;
if (update_amf_configuration(response_data["content"])) {
Logger::amf_app().debug(
"AMF configuration:\n %s", response_data["content"].dump().c_str());
......
......@@ -78,7 +78,7 @@ amf_config::amf_config() {
statistics_interval = 0;
guami = {};
guami_list = {};
relativeAMFCapacity = 0;
relative_amf_capacity = 0;
plmn_list = {};
auth_conf auth_para = {};
nas_cfg = {};
......@@ -158,7 +158,7 @@ int amf_config::load(const std::string& config_file) {
// AMF Name
try {
amf_cfg.lookupValue(AMF_CONFIG_STRING_AMF_NAME, AMF_Name);
amf_cfg.lookupValue(AMF_CONFIG_STRING_AMF_NAME, amf_name);
} catch (const SettingNotFoundException& nfex) {
Logger::amf_app().error(
"%s : %s, using defaults", nfex.what(), nfex.getPath());
......@@ -200,7 +200,7 @@ int amf_config::load(const std::string& config_file) {
// AMF Capacity
try {
amf_cfg.lookupValue(
AMF_CONFIG_STRING_RELATIVE_AMF_CAPACITY, relativeAMFCapacity);
AMF_CONFIG_STRING_RELATIVE_AMF_CAPACITY, relative_amf_capacity);
} catch (const SettingNotFoundException& nfex) {
Logger::amf_app().error(
"%s : %s, using defaults", nfex.what(), nfex.getPath());
......@@ -375,6 +375,9 @@ int amf_config::load(const std::string& config_file) {
std::string smf_api_version = {};
std::string selected = {};
// Store FQDN
smf_addr_item.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, smf_inst.fqdn);
smf_addr_item.lookupValue(AMF_CONFIG_STRING_SMF_INSTANCE_ID, smf_inst.id);
if (!support_features.use_fqdn_dns) {
smf_addr_item.lookupValue(
......@@ -401,9 +404,7 @@ int amf_config::load(const std::string& config_file) {
throw(AMF_CONFIG_STRING_SMF_INSTANCE_VERSION "failed");
}
} else {
std::string smf_fqdn = {};
smf_addr_item.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, smf_fqdn);
smf_inst.fqdn = smf_fqdn;
smf_addr_item.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, smf_inst.fqdn);
}
smf_addr_item.lookupValue(
......@@ -423,6 +424,9 @@ int amf_config::load(const std::string& config_file) {
string address = {};
if (!support_features.use_fqdn_dns) {
// Store FQDN
nrf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, nrf_addr.fqdn);
nrf_cfg.lookupValue(AMF_CONFIG_STRING_NRF_IPV4_ADDRESS, address);
IPV4_STR_ADDR_TO_INADDR(
util::trim(address).c_str(), nrf_ipv4_addr,
......@@ -440,10 +444,9 @@ int amf_config::load(const std::string& config_file) {
}
nrf_addr.api_version = nrf_api_version;
} else {
std::string nrf_fqdn = {};
nrf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, nrf_fqdn);
nrf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, nrf_addr.fqdn);
uint8_t addr_type = {};
fqdn::resolve(nrf_fqdn, address, nrf_port, addr_type);
fqdn::resolve(nrf_addr.fqdn, address, nrf_port, addr_type);
if (addr_type != 0) { // IPv6: TODO
throw("DO NOT SUPPORT IPV6 ADDR FOR NRF!");
} else { // IPv4
......@@ -472,6 +475,9 @@ int amf_config::load(const std::string& config_file) {
std::string ausf_api_version = {};
if (!support_features.use_fqdn_dns) {
// Store FQDN
ausf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, ausf_addr.fqdn);
ausf_cfg.lookupValue(AMF_CONFIG_STRING_IPV4_ADDRESS, address);
IPV4_STR_ADDR_TO_INADDR(
util::trim(address).c_str(), ausf_ipv4_addr,
......@@ -490,10 +496,9 @@ int amf_config::load(const std::string& config_file) {
}
ausf_addr.api_version = ausf_api_version;
} else {
std::string ausf_fqdn = {};
ausf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, ausf_fqdn);
ausf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, ausf_addr.fqdn);
uint8_t addr_type = {};
fqdn::resolve(ausf_fqdn, address, ausf_port, addr_type);
fqdn::resolve(ausf_addr.fqdn, address, ausf_port, addr_type);
if (addr_type != 0) { // IPv6: TODO
throw("DO NOT SUPPORT IPV6 ADDR FOR AUSF!");
} else { // IPv4
......@@ -520,6 +525,9 @@ int amf_config::load(const std::string& config_file) {
std::string udm_api_version = {};
if (!support_features.use_fqdn_dns) {
// Store FQDN
udm_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, udm_addr.fqdn);
udm_cfg.lookupValue(AMF_CONFIG_STRING_IPV4_ADDRESS, address);
IPV4_STR_ADDR_TO_INADDR(
util::trim(address).c_str(), udm_ipv4_addr,
......@@ -538,10 +546,9 @@ int amf_config::load(const std::string& config_file) {
}
udm_addr.api_version = udm_api_version;
} else {
std::string udm_fqdn = {};
udm_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, udm_fqdn);
udm_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, udm_addr.fqdn);
uint8_t addr_type = {};
fqdn::resolve(udm_fqdn, address, udm_port, addr_type);
fqdn::resolve(udm_addr.fqdn, address, udm_port, addr_type);
if (addr_type != 0) { // IPv6: TODO
throw("DO NOT SUPPORT IPV6 ADDR FOR UDM!");
} else { // IPv4
......@@ -563,6 +570,8 @@ int amf_config::load(const std::string& config_file) {
std::string nssf_api_version = {};
if (!support_features.use_fqdn_dns) {
// Store FQDN
nssf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, nssf_addr.fqdn);
nssf_cfg.lookupValue(AMF_CONFIG_STRING_IPV4_ADDRESS, address);
IPV4_STR_ADDR_TO_INADDR(
util::trim(address).c_str(), nssf_ipv4_addr,
......@@ -581,10 +590,9 @@ int amf_config::load(const std::string& config_file) {
}
nssf_addr.api_version = nssf_api_version;
} else {
std::string nssf_fqdn = {};
nssf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, nssf_fqdn);
nssf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, nssf_addr.fqdn);
uint8_t addr_type = {};
fqdn::resolve(nssf_fqdn, address, nssf_port, addr_type);
fqdn::resolve(nssf_addr.fqdn, address, nssf_port, addr_type);
if (addr_type != 0) { // IPv6: TODO
throw("DO NOT SUPPORT IPV6 ADDR FOR NSSF!");
} else { // IPv4
......@@ -682,7 +690,7 @@ void amf_config::display() {
Logger::config().info("Configuration AMF:");
Logger::config().info("- Instance ................: %d", instance);
Logger::config().info("- PID dir .................: %s", pid_dir.c_str());
Logger::config().info("- AMF NAME.................: %s", AMF_Name.c_str());
Logger::config().info("- AMF NAME.................: %s", amf_name.c_str());
Logger::config().info(
"- GUAMI (MCC, MNC, Region ID, AMF Set ID, AMF pointer): ");
Logger::config().info(
......@@ -695,7 +703,8 @@ void amf_config::display() {
guami_list[i].mnc.c_str(), guami_list[i].regionID.c_str(),
guami_list[i].AmfSetID.c_str(), guami_list[i].AmfPointer.c_str());
}
Logger::config().info("- Relative Capacity .......: %d", relativeAMFCapacity);
Logger::config().info(
"- Relative Capacity .......: %d", relative_amf_capacity);
Logger::config().info("- PLMN Support: ");
for (int i = 0; i < plmn_list.size(); i++) {
Logger::config().info(
......@@ -725,7 +734,7 @@ void amf_config::display() {
Logger::config().info(
"- Emergency Support .......: %s", is_emergency_support.c_str());
Logger::config().info("- Database : ");
Logger::config().info("- Database: ");
Logger::config().info(
" MySQL Server Addr .....: %s", auth_para.mysql_server.c_str());
Logger::config().info(
......@@ -735,6 +744,19 @@ void amf_config::display() {
Logger::config().info(
" MySQL DB ..............: %s", auth_para.mysql_db.c_str());
// TODO:
/*
Logger::config().info("- Supported NAS Algorithm: ");
Logger::config().info(
" Integrity Algorithm ...: %s","");
Logger::config().info(
" Ciphering Algorithm ...: %s", "");
st::string nas_itegrity_algorithm_list = {};
for(auto s: nas_cfg.prefered_integrity_algorithm){
}
*/
Logger::config().info("- N2 Networking:");
Logger::config().info(" Iface .................: %s", n2.if_name.c_str());
Logger::config().info(" IP Addr ...............: %s", inet_ntoa(n2.addr4));
......@@ -875,6 +897,26 @@ int amf_config::load_interface(
return RETURNok;
}
//------------------------------------------------------------------------------
bool amf_config::resolve_fqdn(
const std::string& fqdn, struct in_addr& ipv4_addr) {
uint8_t addr_type = {};
unsigned int port = 0;
string address = {};
fqdn::resolve(fqdn, address, port, addr_type);
if (addr_type != 0) { // IPv6: TODO
Logger::amf_app().error("DO NOT SUPPORT IPV6 ADDR FOR THIS NF");
return false;
} else { // IPv4
if (inet_aton(util::trim(address).c_str(), &ipv4_addr) <= 0) return false;
// IPV4_STR_ADDR_TO_INADDR(
// util::trim(address).c_str(), ipv4_addr,
// "BAD IPv4 ADDRESS FORMAT FOR NF !");
}
return true;
}
//------------------------------------------------------------------------------
std::string amf_config::get_amf_n1n2_message_subscribe_uri(
const std::string& ue_cxt_id) {
......@@ -930,14 +972,14 @@ std::string amf_config::get_ausf_ue_authentications_uri() {
void amf_config::to_json(nlohmann::json& json_data) const {
json_data["instance"] = instance;
json_data["pid_dir"] = pid_dir;
json_data["amf_name"] = AMF_Name; // TODO: amf_name
json_data["amf_name"] = amf_name;
json_data["guami"] = guami.to_json();
json_data["guami_list"] = nlohmann::json::array();
for (auto s : guami_list) {
json_data["guami_list"].push_back(s.to_json());
}
json_data["relativeAMFCapacity"] = relativeAMFCapacity;
json_data["relative_amf_capacity"] = relative_amf_capacity;
json_data["plmn_list"] = nlohmann::json::array();
for (auto s : plmn_list) {
......@@ -985,13 +1027,14 @@ bool amf_config::from_json(nlohmann::json& json_data) {
pid_dir = json_data["pid_dir"].get<std::string>();
}
if (json_data.find("amf_name") != json_data.end()) {
AMF_Name = json_data["amf_name"].get<std::string>();
amf_name = json_data["amf_name"].get<std::string>();
}
if (json_data.find("guami") != json_data.end()) {
guami.from_json(json_data["guami"]);
}
if (json_data.find("guami_list") != json_data.end()) {
guami_list.clear();
for (auto s : json_data["guami_list"]) {
guami_t g = {};
g.from_json(s);
......@@ -999,11 +1042,12 @@ bool amf_config::from_json(nlohmann::json& json_data) {
}
}
if (json_data.find("relativeAMFCapacity") != json_data.end()) {
relativeAMFCapacity = json_data["relativeAMFCapacity"].get<int>();
if (json_data.find("relative_amf_capacity") != json_data.end()) {
relative_amf_capacity = json_data["relative_amf_capacity"].get<int>();
}
if (json_data.find("plmn_list") != json_data.end()) {
plmn_list.clear();
for (auto s : json_data["plmn_list"]) {
plmn_item_t p = {};
p.from_json(s);
......@@ -1016,7 +1060,7 @@ bool amf_config::from_json(nlohmann::json& json_data) {
json_data["is_emergency_support"].get<std::string>();
}
if (json_data.find("is_emergency_support") != json_data.end()) {
if (json_data.find("auth_para") != json_data.end()) {
auth_para.from_json(json_data["auth_para"]);
}
......@@ -1024,7 +1068,7 @@ bool amf_config::from_json(nlohmann::json& json_data) {
n2.from_json(json_data["n2"]);
}
if (json_data.find("n11") != json_data.end()) {
n2.from_json(json_data["n11"]);
n11.from_json(json_data["n11"]);
}
if (json_data.find("sbi_http2_port") != json_data.end()) {
......@@ -1038,31 +1082,54 @@ bool amf_config::from_json(nlohmann::json& json_data) {
if (support_features.enable_external_nrf) {
if (json_data.find("nrf") != json_data.end()) {
nrf_addr.from_json(json_data["nrf"]);
// if use FQDN -> update IP addr accordingly
if (support_features.use_fqdn_dns) {
resolve_fqdn(nrf_addr.fqdn, nrf_addr.ipv4_addr);
}
}
}
if (support_features.enable_external_nssf) {
if (json_data.find("nssf") != json_data.end()) {
nssf_addr.from_json(json_data["nssf"]);
// if use FQDN -> update IP addr accordingly
if (support_features.use_fqdn_dns) {
resolve_fqdn(nssf_addr.fqdn, nssf_addr.ipv4_addr);
}
}
}
if (support_features.enable_external_ausf) {
if (json_data.find("ausf") != json_data.end()) {
ausf_addr.from_json(json_data["ausf"]);
// if use FQDN -> update IP addr accordingly
if (support_features.use_fqdn_dns) {
resolve_fqdn(ausf_addr.fqdn, ausf_addr.ipv4_addr);
}
}
}
if (support_features.enable_external_udm) {
if (json_data.find("udm") != json_data.end()) {
udm_addr.from_json(json_data["udm"]);
// if use FQDN -> update IP addr accordingly
if (support_features.use_fqdn_dns) {
resolve_fqdn(udm_addr.fqdn, udm_addr.ipv4_addr);
}
}
}
if (json_data.find("smf_pool") != json_data.end()) {
smf_pool.clear();
for (auto s : json_data["smf_pool"]) {
smf_inst_t smf_item = {};
smf_inst_t smf_item = {};
struct in_addr ipv4_addr = {};
smf_item.from_json(s);
// if use FQDN -> update IP addr accordingly
if (support_features.use_fqdn_dns) {
resolve_fqdn(smf_item.fqdn, ipv4_addr);
smf_item.ipv4 = inet_ntoa(ipv4_addr);
}
smf_pool.push_back(smf_item);
}
}
......
......@@ -288,7 +288,6 @@ typedef struct plmn_support_item_s {
this->mnc = json_data["mnc"].get<std::string>();
this->tac = json_data["tac"].get<int>();
json_data["slice_list"] = nlohmann::json::array();
for (auto s : json_data["slice_list"]) {
slice_t sl = {};
sl.from_json(s);
......@@ -314,6 +313,21 @@ typedef struct {
}
return json_data;
}
/*
void from_json(nlohmann::json& json_data) {
uint8_t i = 0;
for (auto s : json_data["prefered_integrity_algorithm"]) {
uint8_t integ_alg = s.get<int>();
prefered_integrity_algorithm[i] = integ_alg;
++i;
}
i = 0;
for (auto s : json_data["prefered_ciphering_algorithm"]) {
uint8_t cipher_alg = s.get<int>();
prefered_ciphering_algorithm[i] = cipher_alg;
++i;
}
}*/
} nas_conf_t;
typedef struct {
......@@ -354,12 +368,14 @@ typedef struct nf_addr_s {
struct in_addr ipv4_addr;
unsigned int port;
std::string api_version;
std::string fqdn;
nlohmann::json to_json() const {
nlohmann::json json_data = {};
json_data["ipv4_addr"] = inet_ntoa(this->ipv4_addr);
json_data["port"] = this->port;
json_data["api_version"] = this->api_version;
json_data["fqdn"] = this->fqdn;
return json_data;
}
......@@ -370,6 +386,7 @@ typedef struct nf_addr_s {
"BAD IPv4 ADDRESS FORMAT FOR INTERFACE !");
this->port = json_data["port"].get<int>();
this->api_version = json_data["api_version"].get<std::string>();
this->fqdn = json_data["fqdn"].get<std::string>();
}
} nf_addr_t;
......@@ -394,6 +411,8 @@ class amf_config {
*/
int load_interface(const Setting& if_cfg, interface_cfg_t& cfg);
bool resolve_fqdn(const std::string& fqdn, struct in_addr& ipv4_addr);
/*
* Get the URI of AMF N1N2MessageSubscribe
* @param [const std::string&] ue_cxt_id: UE Context Id
......@@ -467,10 +486,10 @@ class amf_config {
unsigned int sbi_http2_port;
unsigned int statistics_interval;
std::string AMF_Name;
std::string amf_name;
guami_t guami;
std::vector<guami_t> guami_list;
unsigned int relativeAMFCapacity;
unsigned int relative_amf_capacity;
std::vector<plmn_item_t> plmn_list;
std::string is_emergency_support;
auth_conf auth_para;
......
......@@ -420,7 +420,7 @@ void amf_n2::handle_itti_message(itti_ng_setup_request& itti_msg) {
// file and send_msg
uint8_t* buffer = (uint8_t*) calloc(1, BUFFER_SIZE_1024);
NGSetupResponseMsg ngSetupResp;
ngSetupResp.setAMFName(amf_cfg.AMF_Name);
ngSetupResp.setAMFName(amf_cfg.amf_name);
std::vector<struct GuamiItem_s> guami_list;
for (int i = 0; i < amf_cfg.guami_list.size(); i++) {
struct GuamiItem_s tmp;
......@@ -433,7 +433,7 @@ void amf_n2::handle_itti_message(itti_ng_setup_request& itti_msg) {
}
ngSetupResp.setGUAMIList(guami_list);
ngSetupResp.setRelativeAmfCapacity(amf_cfg.relativeAMFCapacity);
ngSetupResp.setRelativeAmfCapacity(amf_cfg.relative_amf_capacity);
std::vector<PlmnSliceSupport_t> plmn_list;
for (int i = 0; i < amf_cfg.plmn_list.size(); i++) {
PlmnSliceSupport_t tmp;
......
......@@ -29,6 +29,9 @@
#ifndef _3GPP_TS_24501_H_
#define _3GPP_TS_24501_H_
#include <string>
#include <vector>
/********** epd type **************/
#define EPD_5GS_MM_MSG 0b01111110
......@@ -129,6 +132,10 @@
#define EA1_128_5G 0b001
#define EA2_128_5G 0b010
static const std::vector<std::string> nas_itegrity_algorithm_list_e2str = {
"NIA0", "NIA1", "NIA2"};
static const std::vector<std::string> nas_ciphering_algorithm_list_e2str = {
"NEA0", "NEA1", "NEA2"};
/************************** cause value for 5g mobility management(Annex A)
* ********************************/
#define _5GMM_CAUSE_ILLEGAL_UE 3
......
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