Commit 129bc937 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Support FQDN for NRF

parent 99a5200c
......@@ -86,6 +86,7 @@ AMF =
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 :
......@@ -104,6 +105,7 @@ AMF =
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
}
AUTHENTICATION:
......
......@@ -40,6 +40,7 @@
#include "logger.hpp"
#include "string.hpp"
#include "thread_sched.hpp"
#include "fqdn.hpp"
extern "C" {
#include <arpa/inet.h>
......@@ -79,6 +80,7 @@ amf_config::amf_config() {
enable_smf_selection = false;
enable_external_ausf = false;
enable_external_udm = false;
use_fqdn_dns = false;
struct {
struct in_addr ipv4_addr;
......@@ -211,6 +213,56 @@ int amf_config::load(const std::string& config_file) {
Logger::amf_app().error(
"%s : %s, using defaults", nfex.what(), nfex.getPath());
}
try {
const Setting& support_features =
amf_cfg[AMF_CONFIG_STRING_SUPPORT_FEATURES];
string opt;
support_features.lookupValue(
AMF_CONFIG_STRING_SUPPORT_FEATURES_NF_REGISTRATION, opt);
if (boost::iequals(opt, "yes")) {
enable_nf_registration = true;
} else {
enable_nf_registration = false;
}
support_features.lookupValue(
AMF_CONFIG_STRING_SUPPORT_FEATURES_SMF_SELECTION, opt);
if (boost::iequals(opt, "yes")) {
enable_smf_selection = true;
} else {
enable_smf_selection = false;
}
support_features.lookupValue(
AMF_CONFIG_STRING_SUPPORT_FEATURES_EXTERNAL_AUSF, opt);
if (boost::iequals(opt, "yes")) {
enable_external_ausf = true;
} else {
enable_external_ausf = false;
}
support_features.lookupValue(
AMF_CONFIG_STRING_SUPPORT_FEATURES_EXTERNAL_UDM, opt);
if (boost::iequals(opt, "yes")) {
enable_external_udm = true;
} else {
enable_external_udm = false;
}
support_features.lookupValue(
AMF_CONFIG_STRING_SUPPORT_FEATURES_USE_FQDN_DNS, opt);
if (boost::iequals(opt, "yes")) {
use_fqdn_dns = true;
} else {
use_fqdn_dns = false;
}
} catch (const SettingNotFoundException& nfex) {
Logger::amf_app().error(
"%s : %s, using defaults", nfex.what(), nfex.getPath());
return -1;
}
try {
const Setting& new_if_cfg = amf_cfg[AMF_CONFIG_STRING_INTERFACES];
const Setting& n2_amf_cfg =
......@@ -253,6 +305,7 @@ int amf_config::load(const std::string& config_file) {
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(
util::trim(address).c_str(), nrf_ipv4_addr,
......@@ -270,7 +323,27 @@ int amf_config::load(const std::string& config_file) {
throw(AMF_CONFIG_STRING_API_VERSION "failed");
}
nrf_addr.api_version = nrf_api_version;
} else {
std::string nrf_fqdn = {};
nrf_cfg.lookupValue(AMF_CONFIG_STRING_FQDN_DNS, nrf_fqdn);
uint8_t addr_type = 0;
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
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;
}
// 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;
......@@ -364,47 +437,6 @@ int amf_config::load(const std::string& config_file) {
return -1;
}
try {
const Setting& support_features =
amf_cfg[AMF_CONFIG_STRING_SUPPORT_FEATURES];
string opt;
support_features.lookupValue(
AMF_CONFIG_STRING_SUPPORT_FEATURES_NF_REGISTRATION, opt);
if (boost::iequals(opt, "yes")) {
enable_nf_registration = true;
} else {
enable_nf_registration = false;
}
support_features.lookupValue(
AMF_CONFIG_STRING_SUPPORT_FEATURES_SMF_SELECTION, opt);
if (boost::iequals(opt, "yes")) {
enable_smf_selection = true;
} else {
enable_smf_selection = false;
}
support_features.lookupValue(
AMF_CONFIG_STRING_SUPPORT_FEATURES_EXTERNAL_AUSF, opt);
if (boost::iequals(opt, "yes")) {
enable_external_ausf = true;
} else {
enable_external_ausf = false;
}
support_features.lookupValue(
AMF_CONFIG_STRING_SUPPORT_FEATURES_EXTERNAL_UDM, opt);
if (boost::iequals(opt, "yes")) {
enable_external_udm = true;
} else {
enable_external_udm = false;
}
} catch (const SettingNotFoundException& nfex) {
Logger::amf_app().error(
"%s : %s, using defaults", nfex.what(), nfex.getPath());
return -1;
}
return 1;
}
......
......@@ -104,6 +104,8 @@
#define AMF_CONFIG_STRING_SUPPORT_FEATURES_SMF_SELECTION "SMF_SELECTION"
#define AMF_CONFIG_STRING_SUPPORT_FEATURES_EXTERNAL_AUSF "EXTERNAL_AUSF"
#define AMF_CONFIG_STRING_SUPPORT_FEATURES_EXTERNAL_UDM "EXTERNAL_UDM"
#define AMF_CONFIG_STRING_SUPPORT_FEATURES_USE_FQDN_DNS "USE_FQDN_DNS"
#define AMF_CONFIG_STRING_FQDN_DNS "FQDN"
using namespace libconfig;
......@@ -196,6 +198,7 @@ class amf_config {
bool enable_smf_selection;
bool enable_external_ausf;
bool enable_external_udm;
bool use_fqdn_dns;
struct {
struct in_addr ipv4_addr;
......
......@@ -127,17 +127,13 @@ void amf_n11_task(void*) {
dynamic_cast<itti_pdu_session_resource_setup_response*>(msg);
amf_n11_inst->handle_itti_message(ref(*m));
} break;
/*
case N11_REGISTER_NF_INSTANCE_REQUEST: {
Logger::amf_n11().info(
"Receive PDU Session Resource Setup Response, handling
..."); itti_n11_register_nf_instance_request* m =
"Receive Register NF Instance Request, handling ...");
itti_n11_register_nf_instance_request* m =
dynamic_cast<itti_n11_register_nf_instance_request*>(msg);
amf_n11_inst->register_nf_instance(
std::static_pointer_cast<itti_n11_register_nf_instance_request>(
shared_msg));
// TODO: Handle ITTI
} break;
*/
default: {
Logger::amf_n11().info(
......@@ -863,6 +859,7 @@ void amf_n11::register_nf_instance(
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, NRF_CURL_TIMEOUT_MS);
curl_easy_setopt(curl, CURLOPT_INTERFACE, amf_cfg.n11.if_name.c_str());
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
// Response information.
long httpCode = {0};
......
......@@ -35,5 +35,6 @@ add_library (AMF_UTILS STATIC
${CMAKE_CURRENT_SOURCE_DIR}/string.cpp
${CMAKE_CURRENT_SOURCE_DIR}/thread_sched.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mime_parser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fqdn.cpp
)
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "fqdn.hpp"
#include "logger.hpp"
#include <boost/asio.hpp>
#include <iostream>
bool fqdn::resolve(
const std::string& host_name, std::string& address, uint32_t& port,
uint8_t& addr_type, const std::string& protocol) {
try {
boost::asio::io_context io_context = {};
boost::asio::ip::tcp::resolver resolver{io_context};
boost::asio::ip::tcp::resolver::results_type endpoints =
resolver.resolve(host_name, protocol);
addr_type = 0; // IPv4 by default
for (auto it = endpoints.cbegin(); it != endpoints.cend(); it++) {
// get the first Endpoint
boost::asio::ip::tcp::endpoint endpoint = *it;
address = endpoint.address().to_string();
port = endpoint.port();
Logger::amf_app().debug(
"Resolve a DNS (name %s, protocol %s): Ip Addr %s, port %u",
host_name.c_str(), protocol.c_str(), address.c_str(), port);
if (endpoint.address().is_v4())
addr_type = 0;
else
addr_type = 1;
return true;
}
} catch (std::exception& e) {
throw std::runtime_error(
"Cannot resolve a DNS name " + std::string(e.what()));
return false;
}
return false;
}
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file fqdn.hpp
\brief
\author
\company Eurecom
\email:
*/
#ifndef FILE_FQDN_HPP_SEEN
#define FILE_FQDN_HPP_SEEN
#include <string>
class fqdn {
public:
/*
* Resolve a DNS name to get host's IP Addr
* @param [const std::string &] host_name: host's name/url
* @param [const std::string &] protocol: protocol
* @param [uint8_t &] addr_type: addr_type (Ipv4/v6)
* @return void
*/
static bool resolve(
const std::string& host_name, std::string& address, uint32_t& port,
uint8_t& addr_type, const std::string& protocol = "http");
};
#endif /* FILE_FQDN_HPP_SEEN */
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