Commit 03bba035 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Support FQDN for SMF

parent 129bc937
......@@ -72,28 +72,27 @@ AMF =
INTERFACE_NAME = "@AMF_INTERFACE_NAME_FOR_N11@"; # YOUR NETWORK CONFIG HERE
IPV4_ADDRESS = "read";
PORT = 80; # YOUR NETWORK CONFIG HERE
API_VERSION = "v1"; # YOUR AMF API VERSION CONFIG HERE
API_VERSION = "v1"; # YOUR AMF API VERSION CONFIG HERE
SMF_INSTANCES_POOL = (
{SMF_INSTANCE_ID = @SMF_INSTANCE_ID_0@; IPV4_ADDRESS = "@SMF_IPV4_ADDR_0@"; PORT = "80"; VERSION = "@SMF_HTTP_VERSION_0@"; SELECTED = "true"}, # YOUR SMF CONFIG HERE
{SMF_INSTANCE_ID = @SMF_INSTANCE_ID_1@; IPV4_ADDRESS = "@SMF_IPV4_ADDR_1@"; PORT = "80"; VERSION = "@SMF_HTTP_VERSION_1@"; SELECTED = "false"} # YOUR SMF CONFIG HERE
{SMF_INSTANCE_ID = @SMF_INSTANCE_ID_0@; IPV4_ADDRESS = "@SMF_IPV4_ADDR_0@"; PORT = "80"; VERSION = "@SMF_HTTP_VERSION_0@"; FQDN = "@SMF_FQDN_0@", SELECTED = "true"}, # YOUR SMF CONFIG HERE
{SMF_INSTANCE_ID = @SMF_INSTANCE_ID_1@; IPV4_ADDRESS = "@SMF_IPV4_ADDR_1@"; PORT = "80"; VERSION = "@SMF_HTTP_VERSION_1@"; FQDN = "@SMF_FQDN_1@", SELECTED = "false"} # YOUR SMF CONFIG HERE
);
};
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
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
FQDN = "@NRF_FQDN@"
};
AUSF :
{
IPV4_ADDRESS = "@AUSF_IPV4_ADDRESS@"; # YOUR AUSF CONFIG HERE
PORT = @AUSF_PORT@; # YOUR AUSF CONFIG HERE (default: 80)
API_VERSION = "@AUSF_API_VERSION@"; # YOUR AUSF API VERSION FOR SBI CONFIG HERE
IPV4_ADDRESS = "@AUSF_IPV4_ADDRESS@"; # YOUR AUSF CONFIG HERE
PORT = @AUSF_PORT@; # YOUR AUSF CONFIG HERE (default: 80)
API_VERSION = "@AUSF_API_VERSION@"; # YOUR AUSF API VERSION FOR SBI CONFIG HERE
};
};
......@@ -102,10 +101,10 @@ AMF =
{
# STRING, {"yes", "no"},
NF_REGISTRATION = "@NF_REGISTRATION@"; # Set to yes if AMF resgisters to an NRF
SMF_SELECTION = "@SMF_SELECTION@"; # Set to yes to enable SMF discovery and selection
SMF_SELECTION = "@SMF_SELECTION@"; # Set to yes to enable SMF discovery and selection
EXTERNAL_AUSF = "no"; # Set to yes if AMF works with an external AUSF
EXTERNAL_UDM = "no"; # Set to yes if AMF works with an external UDM
USE_FQDN_DNS = "no"; # Set to yes if AMF relies on a DNS to resolve SMF/UDM/NRF/UPF's FQDN
USE_FQDN_DNS = "no"; # Set to yes if AMF relies on a DNS to resolve SMF/UDM/NRF/UPF's FQDN
}
AUTHENTICATION:
......
......@@ -106,6 +106,8 @@ int amf_config::load(const std::string& config_file) {
"\nLoad AMF system configuration file(%s)", config_file.c_str());
Config cfg;
unsigned char buf_in6_addr[sizeof(struct in6_addr)];
// Config file
try {
cfg.readFile(config_file.c_str());
} catch (const FileIOException& fioex) {
......@@ -119,13 +121,18 @@ int amf_config::load(const std::string& config_file) {
pex.getError());
throw;
}
const Setting& root = cfg.getRoot();
// AMF config
try {
const Setting& amf_cfg = root[AMF_CONFIG_STRING_AMF_CONFIG];
} catch (const SettingNotFoundException& nfex) {
Logger::amf_app().error("%s : %s", nfex.what(), nfex.getPath());
return -1;
}
// Instance
const Setting& amf_cfg = root[AMF_CONFIG_STRING_AMF_CONFIG];
try {
amf_cfg.lookupValue(AMF_CONFIG_STRING_INSTANCE_ID, instance);
......@@ -133,6 +140,8 @@ int amf_config::load(const std::string& config_file) {
Logger::amf_app().error(
"%s : %s, using defaults", nfex.what(), nfex.getPath());
}
// Statistic Timer interval
try {
amf_cfg.lookupValue(
AMF_CONFIG_STRING_STATISTICS_TIMER_INTERVAL, statistics_interval);
......@@ -140,18 +149,24 @@ int amf_config::load(const std::string& config_file) {
Logger::amf_app().error(
"%s : %s, using defaults", nfex.what(), nfex.getPath());
}
// PID Dir
try {
amf_cfg.lookupValue(AMF_CONFIG_STRING_PID_DIRECTORY, pid_dir);
} catch (const SettingNotFoundException& nfex) {
Logger::amf_app().error(
"%s : %s, using defaults", nfex.what(), nfex.getPath());
}
// AMF Name
try {
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());
}
// GUAMI
try {
const Setting& guami_cfg = amf_cfg[AMF_CONFIG_STRING_GUAMI];
guami_cfg.lookupValue(AMF_CONFIG_STRING_MCC, guami.mcc);
......@@ -163,6 +178,8 @@ int amf_config::load(const std::string& config_file) {
Logger::amf_app().error(
"%s : %s, using defaults", nfex.what(), nfex.getPath());
}
// GUAMI List
try {
const Setting& guami_list_cfg =
amf_cfg[AMF_CONFIG_STRING_SERVED_GUAMI_LIST];
......@@ -181,6 +198,8 @@ int amf_config::load(const std::string& config_file) {
Logger::amf_app().error(
"%s : %s, using defaults", nfex.what(), nfex.getPath());
}
// AMF Capacity
try {
amf_cfg.lookupValue(
AMF_CONFIG_STRING_RELATIVE_AMF_CAPACITY, relativeAMFCapacity);
......@@ -188,6 +207,8 @@ int amf_config::load(const std::string& config_file) {
Logger::amf_app().error(
"%s : %s, using defaults", nfex.what(), nfex.getPath());
}
// PLMN List
try {
const Setting& plmn_list_cfg = amf_cfg[AMF_CONFIG_STRING_PLMN_SUPPORT_LIST];
int count = plmn_list_cfg.getLength();
......@@ -214,6 +235,7 @@ int amf_config::load(const std::string& config_file) {
"%s : %s, using defaults", nfex.what(), nfex.getPath());
}
// Supported features
try {
const Setting& support_features =
amf_cfg[AMF_CONFIG_STRING_SUPPORT_FEATURES];
......@@ -249,6 +271,7 @@ int amf_config::load(const std::string& config_file) {
} else {
enable_external_udm = false;
}
support_features.lookupValue(
AMF_CONFIG_STRING_SUPPORT_FEATURES_USE_FQDN_DNS, opt);
if (boost::iequals(opt, "yes")) {
......@@ -263,13 +286,20 @@ int amf_config::load(const std::string& config_file) {
return -1;
}
// Network interfaces
// TODO: should move SMF/NRF/AUSF out of this section
try {
const Setting& new_if_cfg = amf_cfg[AMF_CONFIG_STRING_INTERFACES];
// N2
const Setting& n2_amf_cfg =
new_if_cfg[AMF_CONFIG_STRING_INTERFACE_NGAP_AMF];
load_interface(n2_amf_cfg, n2);
// N11
const Setting& n11_cfg = new_if_cfg[AMF_CONFIG_STRING_INTERFACE_N11];
load_interface(n11_cfg, n11);
// SBI API VERSION
if (!(n11_cfg.lookupValue(
AMF_CONFIG_STRING_API_VERSION, sbi_api_version))) {
......@@ -277,22 +307,57 @@ int amf_config::load(const std::string& config_file) {
throw(AMF_CONFIG_STRING_API_VERSION "failed");
}
// SMF
const Setting& smf_addr_pool =
n11_cfg[AMF_CONFIG_STRING_SMF_INSTANCES_POOL];
int count = smf_addr_pool.getLength();
for (int i = 0; i < count; i++) {
const Setting& smf_addr_item = smf_addr_pool[i];
smf_inst_t smf_inst;
std::string selected;
smf_inst_t smf_inst = {};
struct in_addr smf_ipv4_addr = {};
unsigned int smf_port = {};
std::string smf_api_version = {};
std::string selected = {};
smf_addr_item.lookupValue(AMF_CONFIG_STRING_SMF_INSTANCE_ID, smf_inst.id);
smf_addr_item.lookupValue(AMF_CONFIG_STRING_IPV4_ADDRESS, smf_inst.ipv4);
smf_addr_item.lookupValue(
AMF_CONFIG_STRING_SMF_INSTANCE_PORT, smf_inst.port);
smf_addr_item.lookupValue(
AMF_CONFIG_STRING_SMF_INSTANCE_VERSION, smf_inst.version);
if (!use_fqdn_dns) {
smf_addr_item.lookupValue(
AMF_CONFIG_STRING_IPV4_ADDRESS, smf_inst.ipv4);
IPV4_STR_ADDR_TO_INADDR(
util::trim(smf_inst.ipv4).c_str(), smf_ipv4_addr,
"BAD IPv4 ADDRESS FORMAT FOR SMF !");
if (!(smf_addr_item.lookupValue(
AMF_CONFIG_STRING_SMF_INSTANCE_PORT, smf_inst.port))) {
Logger::amf_app().error(AMF_CONFIG_STRING_SMF_INSTANCE_PORT "failed");
throw(AMF_CONFIG_STRING_SMF_INSTANCE_PORT "failed");
}
smf_addr_item.lookupValue(
AMF_CONFIG_STRING_SMF_INSTANCE_VERSION, smf_inst.version);
if (!(smf_addr_item.lookupValue(
AMF_CONFIG_STRING_SMF_INSTANCE_VERSION, smf_inst.version))) {
Logger::amf_app().error(AMF_CONFIG_STRING_SMF_INSTANCE_VERSION
"failed");
throw(AMF_CONFIG_STRING_SMF_INSTANCE_VERSION "failed");
}
} else {
std::string smf_fqdn = {};
smf_addr_item.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, smf_fqdn);
uint8_t addr_type = 0;
fqdn::resolve(smf_fqdn, smf_inst.ipv4, smf_port, addr_type);
if (addr_type != 0) { // IPv6: TODO
throw("DO NOT SUPPORT IPV6 ADDR FOR SMF!");
} else { // IPv4
IPV4_STR_ADDR_TO_INADDR(
util::trim(smf_inst.ipv4).c_str(), smf_ipv4_addr,
"BAD IPv4 ADDRESS FORMAT FOR SMF !");
smf_inst.port = std::to_string(smf_port);
smf_inst.version = "v1"; // TODO: get API version
}
}
smf_addr_item.lookupValue(
AMF_CONFIG_STRING_SMF_INSTANCE_SELECTED, selected);
if (!selected.compare("true"))
if (boost::iequals(selected, "true"))
smf_inst.selected = true;
else
smf_inst.selected = false;
......@@ -300,11 +365,12 @@ int amf_config::load(const std::string& config_file) {
}
// NRF
const Setting& nrf_cfg = new_if_cfg[AMF_CONFIG_STRING_NRF];
struct in_addr nrf_ipv4_addr;
unsigned int nrf_port = 0;
std::string nrf_api_version;
string address;
const Setting& nrf_cfg = new_if_cfg[AMF_CONFIG_STRING_NRF];
struct in_addr nrf_ipv4_addr = {};
unsigned int nrf_port = 0;
std::string nrf_api_version = {};
string address = {};
if (!use_fqdn_dns) {
nrf_cfg.lookupValue(AMF_CONFIG_STRING_NRF_IPV4_ADDRESS, address);
IPV4_STR_ADDR_TO_INADDR(
......@@ -316,7 +382,6 @@ int amf_config::load(const std::string& config_file) {
throw(AMF_CONFIG_STRING_NRF_PORT "failed");
}
nrf_addr.port = nrf_port;
if (!(nrf_cfg.lookupValue(
AMF_CONFIG_STRING_API_VERSION, nrf_api_version))) {
Logger::amf_app().error(AMF_CONFIG_STRING_API_VERSION "failed");
......@@ -326,30 +391,26 @@ int amf_config::load(const std::string& config_file) {
} else {
std::string nrf_fqdn = {};
nrf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, nrf_fqdn);
uint8_t addr_type = 0;
uint8_t addr_type = {};
fqdn::resolve(nrf_fqdn, address, nrf_port, addr_type);
if (addr_type != 0) {
// IPv6
// TODO:
throw(
"DO NOT SUPPORT IPV6 ADDR FOR NRF"
"failed");
} else {
// IPv4
if (addr_type != 0) { // IPv6: TODO
throw("DO NOT SUPPORT IPV6 ADDR FOR NRF!");
} else { // IPv4
IPV4_STR_ADDR_TO_INADDR(
util::trim(address).c_str(), nrf_ipv4_addr,
"BAD IPv4 ADDRESS FORMAT FOR NRF !");
nrf_addr.ipv4_addr = nrf_ipv4_addr;
nrf_addr.port = nrf_port;
nrf_addr.ipv4_addr = nrf_ipv4_addr;
nrf_addr.port = nrf_port;
nrf_addr.api_version = "v1"; // TODO: get API version
}
// TODO: How to get API version from DNS
}
// AUSF
const Setting& ausf_cfg = new_if_cfg[AMF_CONFIG_STRING_AUSF];
struct in_addr ausf_ipv4_addr;
unsigned int ausf_port = 0;
std::string ausf_api_version;
// string address;
const Setting& ausf_cfg = new_if_cfg[AMF_CONFIG_STRING_AUSF];
struct in_addr ausf_ipv4_addr = {};
unsigned int ausf_port = {};
std::string ausf_api_version = {};
ausf_cfg.lookupValue(AMF_CONFIG_STRING_IPV4_ADDRESS, address);
IPV4_STR_ADDR_TO_INADDR(
util::trim(address).c_str(), ausf_ipv4_addr,
......@@ -373,6 +434,8 @@ int amf_config::load(const std::string& config_file) {
"%s : %s, using defaults", nfex.what(), nfex.getPath());
return -1;
}
// Emergency support
try {
const Setting& core_config = amf_cfg[AMF_CONFIG_STRING_CORE_CONFIGURATION];
core_config.lookupValue(
......@@ -382,6 +445,9 @@ int amf_config::load(const std::string& config_file) {
"%s : %s, using defaults", nfex.what(), nfex.getPath());
return -1;
}
// Authentication Info
// TODO: remove operator_key, random
try {
const Setting& auth = amf_cfg[AMF_CONFIG_STRING_AUTHENTICATION];
auth.lookupValue(
......@@ -397,6 +463,8 @@ int amf_config::load(const std::string& config_file) {
"%s : %s, using defaults", nfex.what(), nfex.getPath());
return -1;
}
// Integrity/Ciphering algorithms (NAS)
try {
const Setting& nas = amf_cfg[AMF_CONFIG_STRING_NAS];
const Setting& intAlg =
......@@ -485,40 +553,42 @@ void amf_config::display() {
"- MySQL pass ..............: %s", auth_para.mysql_pass.c_str());
Logger::config().info(
"- MySQL DB ................: %s", auth_para.mysql_db.c_str());
Logger::config().info(
"- operator key ............: %s", auth_para.operator_key.c_str());
Logger::config().info(
"- random ..................: %s", auth_para.random.c_str());
/* Logger::config().info(
"- operator key ............: %s", auth_para.operator_key.c_str());
Logger::config().info(
"- random ..................: %s", auth_para.random.c_str());
*/
Logger::config().info("- N2 Networking:");
Logger::config().info(" iface .................: %s", n2.if_name.c_str());
Logger::config().info(" ip ....................: %s", inet_ntoa(n2.addr4));
Logger::config().info(" port ..................: %d", n2.port);
Logger::config().info(" Iface .................: %s", n2.if_name.c_str());
Logger::config().info(" IP Addr ...............: %s", inet_ntoa(n2.addr4));
Logger::config().info(" Port ..................: %d", n2.port);
Logger::config().info("- SBI Networking:");
Logger::config().info(" iface .................: %s", n11.if_name.c_str());
Logger::config().info(" Iface .................: %s", n11.if_name.c_str());
Logger::config().info(
" ip ....................: %s", inet_ntoa(n11.addr4));
Logger::config().info(" port ..................: %d", n11.port);
" IP Addr ...............: %s", inet_ntoa(n11.addr4));
Logger::config().info(" Port ..................: %d", n11.port);
Logger::config().info(
" API version............: %s", sbi_api_version.c_str());
if (enable_nf_registration or enable_smf_selection) {
Logger::config().info("- NRF:");
Logger::config().info(
" IP addr ...............: %s", inet_ntoa(nrf_addr.ipv4_addr));
" IP Addr ...............: %s", inet_ntoa(nrf_addr.ipv4_addr));
Logger::config().info(" Port ..................: %d", nrf_addr.port);
Logger::config().info(
" Api version ...........: %s", nrf_addr.api_version.c_str());
" API version ...........: %s", nrf_addr.api_version.c_str());
}
if (enable_external_ausf) {
Logger::config().info("- AUSF:");
Logger::config().info(
" IP addr ...............: %s", inet_ntoa(ausf_addr.ipv4_addr));
" IP Addr ...............: %s", inet_ntoa(ausf_addr.ipv4_addr));
Logger::config().info(" Port ..................: %d", ausf_addr.port);
Logger::config().info(
" Api version ...........: %s", ausf_addr.api_version.c_str());
" API version ...........: %s", ausf_addr.api_version.c_str());
}
Logger::config().info("- Remote SMF Pool.........: ");
......@@ -543,6 +613,8 @@ void amf_config::display() {
" External AUSF .........: %s", enable_external_ausf ? "Yes" : "No");
Logger::config().info(
" External UDM ..........: %s", enable_external_udm ? "Yes" : "No");
Logger::config().info(
" Use FQDN ..............: %s", use_fqdn_dns ? "Yes" : "No");
}
//------------------------------------------------------------------------------
......
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