Commit 32a2dbae authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

First version with AUSF

parent 25ad7ce7
......@@ -34,8 +34,8 @@ AMF_CONF[@SD_0@]='123'
AMF_CONF[@SST_1@]='1'
AMF_CONF[@SD_1@]='12'
AMF_CONF[@AMF_INTERFACE_NAME_FOR_NGAP@]='wlo1'
AMF_CONF[@AMF_INTERFACE_NAME_FOR_N11@]='wlo1'
AMF_CONF[@AMF_INTERFACE_NAME_FOR_NGAP@]='enx0050b6f4ba5b'
AMF_CONF[@AMF_INTERFACE_NAME_FOR_N11@]='enx0050b6f4ba5b'
AMF_CONF[@SMF_INSTANCE_ID_0@]='1'
AMF_CONF[@SMF_IPV4_ADDR_0@]='192.168.122.1'
......@@ -48,6 +48,10 @@ AMF_CONF[@NRF_IPV4_ADDRESS@]='192.168.1.23'
AMF_CONF[@NRF_PORT@]='80'
AMF_CONF[@NRF_API_VERSION@]='v1'
AMF_CONF[@AUSF_IPV4_ADDRESS@]='192.168.1.23'
AMF_CONF[@AUSF_PORT@]='80'
AMF_CONF[@AUSF_API_VERSION@]='v1'
AMF_CONF[@MYSQL_SERVER@]='127.0.0.1'
AMF_CONF[@MYSQL_USER@]='root'
AMF_CONF[@MYSQL_PASS@]='linux'
......
......@@ -66,6 +66,14 @@ AMF =
PPID = 60; # YOUR NETWORK CONFIG HERE
};
# AMF binded interface for Nausf interface
NAUSF:
{
INTERFACE_NAME = "ens33"; # YOUR NETWORK CONFIG HERE
IPV4_ADDRESS = "read";
PORT = 8383; # YOUR NETWORK CONFIG HERE
};
# AMF binded interface for N11
N11:
{
......@@ -84,15 +92,24 @@ 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
};
};
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
};
};
SUPPORT_FEATURES:
{
#Register to NRF
NF_REGISTRATION = "yes"; # STRING, {"yes", "no"}, set to yes if AMF resgisters to an NRF
NF_REGISTRATION = "no"; # STRING, {"yes", "no"}, set to yes if AMF resgisters to an NRF
SMF_SELECTION = "no"; # STRING, {"yes", "no"}, set to yes to enable SMF discovery and selection
EXTERNAL_AUTH = "yes"; # STRING, {"yes", "no"}, set to yes if AMF works with an external AUSF/UDM
EXTERNAL_AUSF = "yes"; # STRING, {"yes", "no"}, set to yes if AMF works with an external AUSF
EXTERNAL_UDM = "no"; # STRING, {"yes", "no"}, set to yes if AMF works with an external UDM
}
AUTHENTICATION:
......
......@@ -62,7 +62,8 @@ amf_config::amf_config() {
nrf_addr.api_version = "v1";
enable_nf_registration = false;
enable_smf_selection = false;
enable_external_auth = false;
enable_external_ausf = false;
enable_external_udm = false;
// TODO:
is_Nausf = true;
}
......@@ -241,6 +242,30 @@ int amf_config::load(const std::string& config_file) {
}
nrf_addr.api_version = nrf_api_version;
// 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;
ausf_cfg.lookupValue(AMF_CONFIG_STRING_IPV4_ADDRESS, address);
IPV4_STR_ADDR_TO_INADDR(
util::trim(address).c_str(), ausf_ipv4_addr,
"BAD IPv4 ADDRESS FORMAT FOR AUSF !");
ausf_addr.ipv4_addr = ausf_ipv4_addr;
if (!(ausf_cfg.lookupValue(AMF_CONFIG_STRING_PORT, ausf_port))) {
Logger::amf_app().error(AMF_CONFIG_STRING_PORT "failed");
throw(AMF_CONFIG_STRING_PORT "failed");
}
ausf_addr.port = ausf_port;
if (!(ausf_cfg.lookupValue(
AMF_CONFIG_STRING_API_VERSION, ausf_api_version))) {
Logger::amf_app().error(AMF_CONFIG_STRING_API_VERSION "failed");
throw(AMF_CONFIG_STRING_API_VERSION "failed");
}
ausf_addr.api_version = ausf_api_version;
} catch (const SettingNotFoundException& nfex) {
Logger::amf_app().error(
"%s : %s, using defaults", nfex.what(), nfex.getPath());
......@@ -331,11 +356,19 @@ int amf_config::load(const std::string& config_file) {
}
support_features.lookupValue(
AMF_CONFIG_STRING_SUPPORT_FEATURES_EXTERNAL_AUTH, opt);
AMF_CONFIG_STRING_SUPPORT_FEATURES_EXTERNAL_AUSF, opt);
if (boost::iequals(opt, "yes")) {
enable_external_auth = true;
enable_external_ausf = true;
} else {
enable_external_auth = false;
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) {
......@@ -422,24 +455,24 @@ void amf_config::display() {
" ip ....................: %s", inet_ntoa(n11.addr4));
Logger::config().info(" port ..................: %d", n11.port);
if (is_Nausf) {
Logger::config().info("- Nausf Networking:");
Logger::config().info(
" iface ................: %s", nausf.if_name.c_str());
Logger::config().info(
" ip ...................: %s", inet_ntoa(nausf.addr4));
Logger::config().info(" port .................: %d", nausf.port);
} else {
Logger::config().warn(
"- Not using ausf: Please remove [--no-ausf] using it.");
if (enable_nf_registration or enable_smf_selection) {
Logger::config().info("- NRF:");
Logger::config().info(
" 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());
}
if (enable_external_ausf) {
Logger::config().info("- AUSF:");
Logger::config().info(
" 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());
}
Logger::config().info("- NRF:");
Logger::config().info(
" 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());
// Logger::config().info(" HTTP2 port ............: %d", n11_http2_port);
......@@ -462,7 +495,9 @@ void amf_config::display() {
Logger::config().info(
" SMF Selection..........: %s", enable_smf_selection ? "Yes" : "No");
Logger::config().info(
" External Authentication: %s", enable_external_auth ? "Yes" : "No");
" External AUSF..........: %s", enable_external_ausf ? "Yes" : "No");
Logger::config().info(
" External UDM..........: %s", enable_external_udm ? "Yes" : "No");
}
//------------------------------------------------------------------------------
......
......@@ -64,6 +64,8 @@
#define AMF_CONFIG_STRING_NRF_PORT "PORT"
#define AMF_CONFIG_STRING_API_VERSION "API_VERSION"
#define AMF_CONFIG_STRING_AUSF "AUSF"
#define AMF_CONFIG_STRING_SCHED_PARAMS "SCHED_PARAMS"
#define AMF_CONFIG_STRING_THREAD_RD_CPU_ID "CPU_ID"
#define AMF_CONFIG_STRING_THREAD_RD_SCHED_POLICY "SCHED_POLICY"
......@@ -100,7 +102,8 @@
#define AMF_CONFIG_STRING_SUPPORT_FEATURES "SUPPORT_FEATURES"
#define AMF_CONFIG_STRING_SUPPORT_FEATURES_NF_REGISTRATION "NF_REGISTRATION"
#define AMF_CONFIG_STRING_SUPPORT_FEATURES_SMF_SELECTION "SMF_SELECTION"
#define AMF_CONFIG_STRING_SUPPORT_FEATURES_EXTERNAL_AUTH "EXTERNAL_AUTH"
#define AMF_CONFIG_STRING_SUPPORT_FEATURES_EXTERNAL_AUSF "EXTERNAL_AUSF"
#define AMF_CONFIG_STRING_SUPPORT_FEATURES_EXTERNAL_UDM "EXTERNAL_UDM"
using namespace libconfig;
......@@ -192,13 +195,21 @@ class amf_config {
std::vector<smf_inst_t> smf_pool;
bool enable_nf_registration;
bool enable_smf_selection;
bool enable_external_auth;
bool enable_external_ausf;
bool enable_external_udm;
struct {
struct in_addr ipv4_addr;
unsigned int port;
std::string api_version;
} nrf_addr;
struct {
struct in_addr ipv4_addr;
unsigned int port;
std::string api_version;
} ausf_addr;
bool is_Nausf;
};
......
......@@ -1315,6 +1315,7 @@ void amf_n1::curl_http_client(
bool amf_n1::authentication_vectors_from_ausf(
std::shared_ptr<nas_context>& nc) {
Logger::amf_n1().debug("authentication_vectors_from_ausf");
/*
std::string ausf_ip =
std::string(inet_ntoa(*((struct in_addr*) &amf_cfg.nausf.addr4)));
std::string ausf_port = std::to_string(amf_cfg.nausf.port);
......@@ -1322,21 +1323,21 @@ bool amf_n1::authentication_vectors_from_ausf(
ausf_ip + ":" + ausf_port + "/nausf-auth/v1/ue-authentications";
std::string msgBody;
std::string Response;
nlohmann::json authenticationinfo_j;
*/
UEAuthenticationCtx ueauthenticationctx;
// nlohmann::json authenticationinfo_j;
AuthenticationInfo authenticationinfo;
authenticationinfo.setSupiOrSuci(nc.get()->imsi);
authenticationinfo.setServingNetworkName(nc.get()->serving_network);
to_json(authenticationinfo_j, authenticationinfo);
msgBody = authenticationinfo_j.dump();
curl_http_client(remoteUri, "POST", msgBody, Response);
Logger::amf_n1().info("POST response : %s", Response.c_str());
// to_json(authenticationinfo_j, authenticationinfo);
// msgBody = authenticationinfo_j.dump();
try {
UEAuthenticationCtx ueauthenticationctx;
nlohmann::json::parse(Response.c_str()).get_to(ueauthenticationctx);
// TODO: Move to N11 (SBI)
// curl_http_client(remoteUri, "POST", msgBody, Response);
if (amf_n11_inst->send_ue_authentication_request(
authenticationinfo, ueauthenticationctx, 1)) {
unsigned char* r5gauthdata_rand =
format_string_as_hex(ueauthenticationctx.getR5gAuthData().getRand());
memcpy(nc.get()->_5g_av[0].rand, r5gauthdata_rand, 16);
......@@ -1363,11 +1364,50 @@ bool amf_n1::authentication_vectors_from_ausf(
} else {
Logger::amf_n1().error("Not found 5G_AKA");
}
} catch (nlohmann::json::exception& e) {
Logger::amf_n1().info("Could not get Json content from AUSF response");
} else {
Logger::amf_n1().info("Could not get expected response from AUSF");
// TODO: error handling
return false;
}
// Logger::amf_n1().info("POST response : %s", Response.c_str());
/*
try {
nlohmann::json::parse(Response.c_str()).get_to(ueauthenticationctx);
unsigned char* r5gauthdata_rand =
format_string_as_hex(ueauthenticationctx.getR5gAuthData().getRand());
memcpy(nc.get()->_5g_av[0].rand, r5gauthdata_rand, 16);
print_buffer("amf_n1", "5G AV: rand", nc.get()->_5g_av[0].rand, 16);
free_wrapper((void**) &r5gauthdata_rand);
unsigned char* r5gauthdata_autn =
format_string_as_hex(ueauthenticationctx.getR5gAuthData().getAutn());
memcpy(nc.get()->_5g_av[0].autn, r5gauthdata_autn, 16);
print_buffer("amf_n1", "5G AV: autn", nc.get()->_5g_av[0].autn, 16);
free_wrapper((void**) &r5gauthdata_autn);
unsigned char* r5gauthdata_hxresstar = format_string_as_hex(
ueauthenticationctx.getR5gAuthData().getHxresStar());
memcpy(nc.get()->_5g_av[0].hxresStar, r5gauthdata_hxresstar, 16);
print_buffer("amf_n1", "5G AV: hxres*", nc.get()->_5g_av[0].hxresStar,
16); free_wrapper((void**) &r5gauthdata_hxresstar);
std::map<std::string, LinksValueSchema>::iterator iter;
iter = ueauthenticationctx.getLinks().find("5G_AKA");
if (iter != ueauthenticationctx.getLinks().end()) {
nc.get()->Href = iter->second.getHref();
Logger::amf_n1().info("Links is: ", nc.get()->Href);
} else {
Logger::amf_n1().error("Not found 5G_AKA");
}
} catch (nlohmann::json::exception& e) {
Logger::amf_n1().info("Could not get Json content from AUSF response");
// TODO: error handling
return false;
}
*/
return true;
}
......@@ -1388,8 +1428,9 @@ bool amf_n1::_5g_aka_confirmation_from_ausf(
to_json(confirmationdata_j, confirmationdata);
msgBody = confirmationdata_j.dump();
curl_http_client(remoteUri, "PUT", msgBody, Response);
// TODO: Move curl to N11(SBI)
curl_http_client(remoteUri, "PUT", msgBody, Response);
// free(resStar_string.c_str());
try {
......
......@@ -861,3 +861,86 @@ bool amf_n11::discover_smf(
curl_global_cleanup();
return result;
}
//-----------------------------------------------------------------------------------------------------
bool amf_n11::send_ue_authentication_request(
oai::amf::model::AuthenticationInfo& auth_info,
oai::amf::model::UEAuthenticationCtx& ue_auth_ctx, uint8_t http_version) {
Logger::amf_n11().debug(
"Send UE Authentication Request to AUSF (HTTP version %d)", http_version);
nlohmann::json json_data = {};
to_json(json_data, auth_info);
std::string url =
std::string(
inet_ntoa(*((struct in_addr*) &amf_cfg.ausf_addr.ipv4_addr))) +
":" + std::to_string(amf_cfg.ausf_addr.port) + "/nausf-auth/" +
amf_cfg.ausf_addr.api_version + "ue-authentications";
Logger::amf_n11().debug(
"Send UE Authentication Request to AUSF, URL %s", url.c_str());
std::string body = json_data.dump();
Logger::amf_n11().debug(
"Send UE Authentication Request to AUSF, msg body: \n %s", body.c_str());
curl_global_init(CURL_GLOBAL_ALL);
CURL* curl = curl = curl_easy_init();
if (curl) {
CURLcode res = {};
struct curl_slist* headers = nullptr;
// headers = curl_slist_append(headers, "charsets: utf-8");
headers = curl_slist_append(headers, "content-type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, AUSF_CURL_TIMEOUT_MS);
if (http_version == 2) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
// we use a self-signed test server, skip verification during debugging
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(
curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE);
}
// Response information.
long httpCode = {0};
std::unique_ptr<std::string> httpData(new std::string());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, httpData.get());
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, body.length());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
res = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
Logger::amf_n11().debug(
"UE Authentication, response from AUSF, HTTP Code: %d", httpCode);
if ((httpCode == 200) or
(httpCode == 201)) { // TODO: remove hardcoded value
try {
nlohmann::json::parse(*httpData.get()).get_to(ue_auth_ctx);
} catch (nlohmann::json::exception& e) {
Logger::amf_n11().warn(
"UE Authentication, could not parse json from the AUSF "
"response");
// TODO: error handling
return false;
}
} else {
Logger::amf_n11().warn(
"NF Instance Registration, could not get response from NRF");
return false;
}
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return true;
}
......@@ -35,6 +35,8 @@
#include "itti_msg_n11.hpp"
#include "pdu_session_context.hpp"
#include "AuthenticationInfo.h"
#include "UEAuthenticationCtx.h"
namespace amf_application {
......@@ -81,6 +83,10 @@ class amf_n11 {
bool discover_smf(
std::string& smf_addr, std::string& smf_api_version,
const snssai_t snssai, const plmn_t plmn, const std::string dnn);
bool send_ue_authentication_request(
oai::amf::model::AuthenticationInfo& auth_info,
oai::amf::model::UEAuthenticationCtx& ue_auth_ctx, uint8_t http_version);
};
} // namespace amf_application
......
......@@ -100,6 +100,7 @@ enum class http_response_codes_e {
#define SMF_NUMBER_RETRIES 3
constexpr auto CURL_MIME_BOUNDARY = "----Boundary";
#define NRF_CURL_TIMEOUT_MS 100L
#define AUSF_CURL_TIMEOUT_MS 100L
#define BUFFER_SIZE_1024 1024
#define BUFFER_SIZE_512 512
......
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