Commit 72da7c18 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Re-organize the code for NRF/SMF selection

parent b45472b2
......@@ -120,10 +120,11 @@ AMF =
# STRING, {"yes", "no"},
NF_REGISTRATION = "@NF_REGISTRATION@"; # Set to yes if AMF resgisters to an NRF
NRF_SELECTION = "@NRF_SELECTION@"; # Set to yes to enable NRF discovery and selection
EXTERNAL_NRF = "@EXTERNAL_NRF@"; # Set to yes if AMF works with an external NRF
SMF_SELECTION = "@SMF_SELECTION@"; # Set to yes to enable SMF discovery and selection
EXTERNAL_AUSF = "@EXTERNAL_AUSF@"; # Set to yes if AMF works with an external AUSF
EXTERNAL_UDM = "@EXTERNAL_UDM@"; # Set to yes if AMF works with an external UDM
EXTERNAL_NSSF = "no"; # Set to yes if AMF works with an external NSSF
EXTERNAL_NSSF = "@EXTERNAL_NSSF"; # Set to yes if AMF works with an external NSSF
USE_FQDN_DNS = "@USE_FQDN_DNS@"; # Set to yes if AMF relies on a DNS to resolve NRF/SMF/UDM/AUSF's FQDN
USE_HTTP2 = "no"; # Set to yes to enable HTTP2 for AMF server
}
......
......@@ -7,7 +7,9 @@ CONFIG_DIR="/openair-amf/etc"
# Default values
EXTERNAL_AUSF=${EXTERNAL_AUSF:-no}
EXTERNAL_UDM=${EXTERNAL_UDM:-no}
EXTERNAL_NRF=${EXTERNAL_NRF:-no}
NRF_SELECTION=${NRF_SELECTION:-no}
EXTERNAL_NSSF=${EXTERNAL_NSSF:-no}
NSSF_IPV4_ADDRESS=${NSSF_IPV4_ADDRESS:-0.0.0.0}
NSSF_PORT=${NSSF_PORT:-80}
NSSF_API_VERSION=${NSSF_API_VERSION:-v2}
......
......@@ -91,7 +91,9 @@ amf_app::amf_app(const amf_config& amf_cfg)
generate_amf_profile();
// Register to NRF if needed
if (amf_cfg.support_features.enable_nf_registration) register_to_nrf();
if (amf_cfg.support_features.enable_nf_registration and
amf_cfg.support_features.enable_external_nrf)
register_to_nrf();
timer_id_t tid = itti_inst->timer_setup(
amf_cfg.statistics_interval, 0, TASK_AMF_APP,
......
......@@ -719,8 +719,7 @@ void amf_config::display() {
Logger::config().info(
" API version............: %s", sbi_api_version.c_str());
if (support_features.enable_nf_registration or
support_features.enable_smf_selection) {
if (support_features.enable_external_nrf) {
Logger::config().info("- NRF:");
Logger::config().info(
" IP Addr ...............: %s", inet_ntoa(nrf_addr.ipv4_addr));
......
......@@ -355,26 +355,50 @@ void amf_n11::handle_itti_message(itti_nsmf_pdusession_create_sm_context& smf) {
std::string smf_addr = {};
std::string smf_api_version = {};
if (!psc.get()->smf_available) {
if (amf_cfg.support_features.enable_nrf_selection) {
if (!discover_smf_from_nsi_info(
smf_addr, smf_api_version, psc.get()->snssai, psc.get()->plmn,
psc.get()->dnn)) {
Logger::amf_n11().error("NRF Selection, no NRF candidate is available");
if (amf_cfg.support_features.enable_smf_selection) {
// Get NRF URI
std::string nrf_uri = {};
if (!amf_n11::get_nrf_uri(
psc.get()->snssai, psc.get()->plmn, psc.get()->dnn, nrf_uri)) {
Logger::amf_n11().error("No NRF is available");
return;
}
} else if (amf_cfg.support_features.enable_smf_selection) {
// use NRF to find suitable SMF based on snssai, plmn and dnn
if (!discover_smf(
smf_addr, smf_api_version, psc.get()->snssai, psc.get()->plmn,
psc.get()->dnn)) {
psc.get()->dnn, nrf_uri)) {
Logger::amf_n11().error("SMF Selection, no SMF candidate is available");
return;
}
} else if (!smf_selection_from_configuration(smf_addr, smf_api_version)) {
Logger::amf_n11().error(
"No SMF candidate is available (from configuration file)");
return;
}
/*
if (amf_cfg.support_features.enable_nrf_selection) {
if (!discover_smf_from_nsi_info(
smf_addr, smf_api_version, psc.get()->snssai, psc.get()->plmn,
psc.get()->dnn)) {
Logger::amf_n11().error("NRF Selection, no NRF candidate is
available"); return;
}
} else if (amf_cfg.support_features.enable_smf_selection) {
// use NRF to find suitable SMF based on snssai, plmn and dnn
if (!discover_smf(
smf_addr, smf_api_version, psc.get()->snssai, psc.get()->plmn,
psc.get()->dnn)) {
Logger::amf_n11().error("SMF Selection, no SMF candidate is
available"); return;
}
} else if (!smf_selection_from_configuration(smf_addr, smf_api_version))
{ Logger::amf_n11().error( "No SMF candidate is available (from
configuration file)"); return;
}
*/
// store smf info to be used with this PDU session
psc.get()->smf_available = true;
psc->smf_addr = smf_addr;
......@@ -1577,15 +1601,85 @@ void amf_n11::curl_http_client(
}
//------------------------------------------------------------------------------
void amf_n11::get_nrf_uri(std::string& nrf_uri) {
bool amf_n11::get_nrf_uri(
const snssai_t& snssai, const plmn_t& plmn, const std::string& dnn,
std::string& nrf_uri) {
if (!amf_cfg.support_features.enable_nrf_selection) {
// Get NRF info from configuration file
nrf_uri = std::string(
inet_ntoa(*((struct in_addr*) &amf_cfg.nrf_addr.ipv4_addr))) +
":" + std::to_string(amf_cfg.nrf_addr.port) + "/nnrf-disc/" +
amf_cfg.nrf_addr.api_version + "/nf-instances";
return true;
} else { // Get NRF info from NSSF
// TODO:
Logger::amf_n11().debug(
"Send NS Selection to NSSF to discover the appropriate NRF");
bool result = false;
uint8_t http_version = 1;
if (amf_cfg.support_features.use_http2) http_version = 2;
// Get NSI information from NSSF
nlohmann::json slice_info = {};
nlohmann::json snssai_info = {};
snssai_info["sst"] = snssai.sST;
if (!snssai.sD.empty()) snssai_info["sd"] = snssai.sD;
slice_info["sNssai"] = snssai_info;
slice_info["roamingIndication"] = "NON_ROAMING";
// ToDo Add TAI
std::string nssf_url =
amf_cfg.get_nssf_network_slice_selection_information_uri();
std::string parameters = {};
parameters = "?nf-type=AMF&nf-id=" + amf_app_inst->get_nf_instance() +
"&slice-info-request-for-pdu-session=" + slice_info.dump();
nssf_url += parameters;
Logger::amf_n11().debug(
"Send Network Slice Information Retrieval during PDU session "
"establishment procedure, URL %s",
nssf_url.c_str());
nlohmann::json response_data = {};
uint32_t response_code = 0;
curl_http_client(nssf_url, "GET", "", response_data, response_code);
Logger::amf_n11().debug(
"NFDiscovery, response from NRF, json data: \n %s",
response_data.dump().c_str());
std::string nrf_uri = {};
if (response_code != 200) {
Logger::amf_n11().warn("NS Selection, could not get response from NSSF");
result = false;
} else {
Logger::amf_n11().debug(
"NS Selection, got successful response from NSSF");
Logger::amf_n11().debug(
"NS Selection, response from NSSF, json data: \n %s",
response_data.dump().c_str());
// Process data to obtain NRF info
if (response_data.find("nsiInformation") != response_data.end()) {
if (response_data["nsiInformation"].count("nrfId") > 0) {
nrf_uri = response_data["nsiInformation"]["nrfId"].get<std::string>();
Logger::amf_n11().debug(
"NSI Information is successfully retrieved from NSSF");
Logger::amf_n11().debug(
"NS Selection, NRF's URI: %s", nrf_uri.c_str());
result = true;
}
std::string nsi_id = {};
if (response_data["nsiInformation"].count("nsi_id") > 0)
nsi_id = response_data["nsiInformation"]["nsiId"].get<std::string>();
}
}
return result;
}
}
......@@ -107,7 +107,9 @@ class amf_n11 {
oai::amf::model::AuthenticationInfo& auth_info,
oai::amf::model::UEAuthenticationCtx& ue_auth_ctx, uint8_t http_version);
void get_nrf_uri(std::string& nrf_uri);
bool get_nrf_uri(
const snssai_t& snssai, const plmn_t& plmn, const std::string& dnn,
std::string& nrf_uri);
};
} // namespace amf_application
......
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