Commit b67b2482 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

code cleanup

parent 96352e3c
......@@ -21,7 +21,7 @@
/*! \file amf_n1.cpp
\brief
\author Keliang DU, BUPT
\author Keliang DU, BUPT, Tien-Thinh NGUYEN, EURECOM
\date 2020
\email: contact@openairinterface.org
*/
......@@ -86,7 +86,7 @@ void amf_n1_task(void*) {
}
break;
default:
Logger::amf_n1().error("no handler for msg type %d", msg->msg_type);
Logger::amf_n1().error("No handler for msg type %d", msg->msg_type);
}
} while (true);
}
......@@ -98,7 +98,7 @@ amf_n1::amf_n1() {
throw std::runtime_error("Cannot create task TASK_AMF_N1");
}
Logger::amf_n1().startup("Started");
Logger::amf_n1().debug("construct amf_n1 successfully");
Logger::amf_n1().debug("Construct amf_n1 successfully");
}
amf_n1::~amf_n1() {
}
......@@ -236,12 +236,12 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind &nas_data_ind) {
break;
}
if (nas_data_ind.is_nas_signalling_estab_req) {
Logger::amf_n1().debug("Received NAS signalling establishment request ...");
Logger::amf_n1().debug("Received NAS signalling establishment request...");
//dump_nas_message((uint8_t*)bdata(decoded_plain_msg), blength(decoded_plain_msg));
print_buffer("amf_n1", "Decoded plain NAS Message buffer", (uint8_t*) bdata(decoded_plain_msg), blength(decoded_plain_msg));
nas_signalling_establishment_request_handle(type, nc, nas_data_ind.ran_ue_ngap_id, nas_data_ind.amf_ue_ngap_id, decoded_plain_msg, snn, ulCount);
} else {
Logger::amf_n1().debug("Received uplink NAS message ...");
Logger::amf_n1().debug("Received uplink NAS message...");
print_buffer("amf_n1", "Decoded NAS message buffer", (uint8_t*) bdata(decoded_plain_msg), blength(decoded_plain_msg));
uplink_nas_msg_handle(nas_data_ind.ran_ue_ngap_id, nas_data_ind.amf_ue_ngap_id, decoded_plain_msg, plmn);
}
......@@ -317,7 +317,7 @@ void amf_n1::uplink_nas_msg_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id,
}
break;
case UL_NAS_TRANSPORT: {
Logger::amf_n1().debug("Received ul NAS transport message, handling...");
Logger::amf_n1().debug("Received UL NAS transport message, handling...");
ul_nas_transport_handle(ran_ue_ngap_id, amf_ue_ngap_id, plain_msg);
}
break;
......@@ -381,9 +381,7 @@ void amf_n1::uplink_nas_msg_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id,
default: {
//TODO:
}
}
}
// nas message decode
......@@ -434,7 +432,7 @@ void amf_n1::service_request_handle(bool isNasSig, std::shared_ptr<nas_context>
uint8_t *kamf = nc.get()->kamf[secu->vector_pointer];
uint8_t kgnb[32];
uint32_t ulcount = secu->ul_count.seq_num | (secu->ul_count.overflow << 8);
Logger::amf_n1().debug("Uplink count(%d)", secu->ul_count.seq_num);
Logger::amf_n1().debug("Uplink count (%d)", secu->ul_count.seq_num);
print_buffer("amf_n1", "kamf", kamf, 32);
Authentication_5gaka::derive_kgnb(ulcount, 0x01, kamf, kgnb);
bstring kgnb_bs = blk2bstr(kgnb, 32);
......@@ -565,7 +563,7 @@ void amf_n1::registration_request_handle(bool isNasSig, std::shared_ptr<nas_cont
uint8_t reg_type;
bool is_follow_on_req_pending;
if (!regReq->get5GSRegistrationType(is_follow_on_req_pending, reg_type)) {
Logger::amf_n1().error("Missing Mandatory IE 5GS Registration type ...");
Logger::amf_n1().error("Missing Mandatory IE 5GS Registration type...");
response_registration_reject_msg(_5GMM_CAUSE_INVALID_MANDATORY_INFO, ran_ue_ngap_id, amf_ue_ngap_id);
return;
}
......@@ -575,7 +573,7 @@ void amf_n1::registration_request_handle(bool isNasSig, std::shared_ptr<nas_cont
//Check ngKSI (Mandatory IE)
uint8_t ngKSI = regReq->getngKSI();
if (ngKSI == -1) {
Logger::amf_n1().error("Missing Mandatory IE ngKSI ...");
Logger::amf_n1().error("Missing Mandatory IE ngKSI...");
response_registration_reject_msg(_5GMM_CAUSE_INVALID_MANDATORY_INFO, ran_ue_ngap_id, amf_ue_ngap_id);
return;
}
......@@ -704,9 +702,9 @@ void amf_n1::response_registration_reject_msg(uint8_t cause_value, uint32_t ran_
uint8_t buffer[1024] = { 0 };
int encoded_size = registrationRej->encode2buffer(buffer, 1024);
//dump_nas_message(buffer, encoded_size);
print_buffer("amf_n1", "Registration-Reject Message Buffer", buffer, encoded_size);
print_buffer("amf_n1", "Registration-Reject message buffer", buffer, encoded_size);
if (!encoded_size) {
Logger::nas_mm().error("Encode RegistrationRej message error");
Logger::nas_mm().error("Encode Registration-Reject message error");
return;
} else {
delete registrationRej;
......@@ -744,7 +742,7 @@ void amf_n1::run_registration_procedure(std::shared_ptr<nas_context> &nc) {
ngksi_t ngksi = 0;
if (nc.get()->security_ctx && nc.get()->ngKsi != NAS_KEY_SET_IDENTIFIER_NOT_AVAILABLE) {
ngksi = (nc.get()->ngKsi + 1) % (NGKSI_MAX_VALUE + 1);
Logger::amf_n1().debug("New ngKsi(%d)", ngksi);
Logger::amf_n1().debug("New ngKsi (%d)", ngksi);
// ... how to handle?
}
nc.get()->ngKsi = ngksi;
......@@ -1083,7 +1081,7 @@ void amf_n1::authentication_response_handle(uint32_t ran_ue_ngap_id, long amf_ue
bool isAuthOk = true;
//Get response RES*
if (!auth->getAuthenticationResponseParameter(resStar)) {
Logger::amf_n1().warn("Cannot receive AuthenticationResponseParameter(RES*)");
Logger::amf_n1().warn("Cannot receive AuthenticationResponseParameter (RES*)");
} else {
//Get stored XRES*
int secu_index = nc.get()->security_ctx->vector_pointer;
......@@ -1150,10 +1148,10 @@ void amf_n1::authentication_failure_handle(uint32_t ran_ue_ngap_id, long amf_ue_
Logger::amf_n1().debug("Initial new authentication procedure");
bstring auts;
if (!authFail->getAutsInAuthFailPara(auts)) {
Logger::amf_n1().warn("IE Authentication Failure Parameter(auts) not received");
Logger::amf_n1().warn("IE Authentication Failure Parameter (auts) not received");
}
nc.get()->auts = auts;
printf("received auts: 0x ");
printf("Received auts: 0x ");
for (int i = 0; i < blength(auts); i++)
printf("%x ", ((uint8_t*) bdata(auts))[i]);
printf("\n");
......@@ -1720,12 +1718,12 @@ void amf_n1::run_mobility_registration_update_procedure(std::shared_ptr<nas_cont
encode_nas_message_protected(secu, false, INTEGRITY_PROTECTED_AND_CIPHERED, NAS_MESSAGE_DOWNLINK, buffer, encoded_size, protectedNas);
string supi = "imsi-" + nc.get()->imsi;
Logger::amf_n1().debug("Key for pdu session context: supi(%s)", supi.c_str());
Logger::amf_n1().debug("Key for pdu session context SUPI (%s)", supi.c_str());
std::shared_ptr<pdu_session_context> psc;
if (amf_n11_inst->is_supi_to_pdu_ctx(supi)) {
psc = amf_n11_inst->supi_to_pdu_ctx(supi);
} else {
Logger::amf_n1().error("Cannot get pdu_session_context with supi(%s)", supi.c_str());
Logger::amf_n1().error("Cannot get pdu_session_context with SUPI (%s)", supi.c_str());
}
uint8_t *kamf = nc.get()->kamf[secu->vector_pointer];
......
......@@ -21,7 +21,7 @@
/*! \file amf_n11.cpp
\brief
\author Keliang DU, BUPT
\author Keliang DU, BUPT, Tien-Thinh NGUYEN, EURECOM
\date 2020
\email: contact@openairinterface.org
*/
......@@ -32,6 +32,7 @@
#include "itti_msg_amf_app.hpp"
#include "amf_config.hpp"
#include "nas_context.hpp"
#include "amf.hpp"
#include <curl/curl.h>
#include <nlohmann/json.hpp>
......@@ -105,13 +106,13 @@ void amf_n11_task(void*) {
}
break;
case NSMF_PDU_SESS_UPDATE_SMCTX: {
Logger::amf_n1().info("Receive NSMF_PDU_SESS_UPDATE_SMCTX, handling ...");
Logger::amf_n1().info("Receive Nsmf_PDUSessionUpdateSMContext, handling ...");
itti_nsmf_pdusession_update_sm_context *m = dynamic_cast<itti_nsmf_pdusession_update_sm_context*>(msg);
amf_n11_inst->handle_itti_message(ref(*m));
}
break;
case PDU_SESS_RES_SET_RESP: {
Logger::amf_n1().info("Receive PDU_SESS_RES_SET_RESP, handling ...");
Logger::amf_n1().info("Receive PDU Session Resource Setup Response, handling ...");
itti_pdu_session_resource_setup_response *m = dynamic_cast<itti_pdu_session_resource_setup_response*>(msg);
amf_n11_inst->handle_itti_message(ref(*m));
}
......@@ -142,27 +143,26 @@ void amf_n11::handle_itti_message(itti_pdu_session_resource_setup_response &itti
//------------------------------------------------------------------------------
void amf_n11::handle_itti_message(itti_nsmf_pdusession_update_sm_context &itti_msg) {
std::string supi = pduid2supi.at(itti_msg.pdu_session_id);
Logger::amf_n11().debug("Try to find supi(%s) from pdusession_id(%d)", supi.c_str(), itti_msg.pdu_session_id);
Logger::amf_n11().debug("Found SUPI %s with PDU Session ID %d", supi.c_str(), itti_msg.pdu_session_id);
std::shared_ptr<pdu_session_context> psc;
if (is_supi_to_pdu_ctx(supi)) {
psc = supi_to_pdu_ctx(supi);
} else {
Logger::amf_n11().error("Trying to find psu_session_context with supi(%s), Failed", supi.c_str());
Logger::amf_n11().error("Could not find psu_session_context with SUPI %s, Failed", supi.c_str());
return;
}
std::string smf_addr;
if (!psc.get()->smf_available) {
if (!smf_selection_from_configuration(smf_addr)) {
Logger::amf_n11().error("No candidate SMF is available");
Logger::amf_n11().error("No SMF candidate is available");
return;
}
} else {
smf_selection_from_context(smf_addr);
}
//TODO:Remove hardcoded value (1 - SCID)
//std::string remote_uri = smf_addr + "/nsmf-pdusession/v1/sm-contexts/" + "imsi-208950000000031-1" + "/modify"; //scid
std::string remote_uri = smf_addr + psc.get()->smf_context_location + "/modify"; //scid
nlohmann::json pdu_session_update_request;
pdu_session_update_request["n2SmInfoType"] = "PDU_RES_SETUP_RSP";
pdu_session_update_request["n2SmInfo"]["contentId"] = "n2SmMsg";
......@@ -225,9 +225,11 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) {
}
break;
case EXISTING_PDU_SESSION: {
//TODO:
}
break;
case PDU_SESSION_MODIFICATION_REQUEST: {
//TODO:
}
break;
}
......@@ -368,7 +370,6 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, std:
}
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
//res = curl_easy_perform(curl);
// Response information.
long httpCode(0);
......@@ -392,7 +393,10 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, std:
Logger::amf_n11().debug("Get response with httpcode (%d)", httpCode);
if (httpCode == 0) {
Logger::amf_n11().error("Cannot get response when calling %s", remoteUri.c_str());
//TODO: free curl before returning
//free curl before returning
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
curl_mime_free(mime);
return;
}
if (httpCode != 200 && httpCode != 201 && httpCode != 204) {
......@@ -402,15 +406,14 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, std:
Logger::amf_n11().error("Could not get the cause from the response");
}
} else {
//TODO: store location of created context
//store location of created context
std::string header_response = *httpHeaderData.get();
std::string CRLF = "\r\n";
std::size_t location_pos = header_response.find("Location");
std::size_t crlf_pos = header_response.find(CRLF, location_pos);
std::string location = header_response.substr(location_pos + 10, crlf_pos - (location_pos + 10));
Logger::amf_n11().info("Location: %s", location.c_str());
Logger::amf_n11().info("Location of the SMF context created: %s", location.c_str());
psc.get()->smf_context_location = location;
}
nlohmann::json response_data;
bstring n1sm_hex;
......@@ -422,7 +425,7 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, std:
print_buffer("amf_n11", "Get response with n1sm:", (uint8_t*) bdata(n1sm_hex), blength(n1sm_hex));
std::string cause = response_data["error"]["cause"];
Logger::amf_n11().error("Call Network Function services failure ");
Logger::amf_n11().error("Call Network Function services failure");
Logger::amf_n11().info("Cause value: %s", cause.c_str());
if (!cause.compare("DNN_DENIED"))
handle_post_sm_context_response_error(httpCode, cause, n1sm_hex, supi, pdu_session_id);
......
......@@ -276,7 +276,7 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) {
void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) {
//create ngap-ue context and store in gNB context to store UE information in gNB, for example, here RAN UE NGAP ID and location information and RRC Establishment Cause
//send NAS-PDU to NAS layer
/*get INITIAL_UE_MESSAGE IEs*/
//Get INITIAL_UE_MESSAGE IEs
//check the gNB context on which this UE is attached with assoc_id
itti_nas_signalling_establishment_request *itti_msg = new itti_nas_signalling_establishment_request(TASK_AMF_N2, TASK_AMF_APP);
......@@ -384,16 +384,16 @@ void amf_n2::handle_itti_message(itti_ul_nas_transport &ul_nas_transport) {
gc = assoc_id_2_gnb_context(ul_nas_transport.assoc_id);
std::shared_ptr<ue_ngap_context> unc;
if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) {
Logger::amf_n2().error("UE with ran_ue_ngap_id(0x%x) is not attached to gnb with assoc_id(%d)", ran_ue_ngap_id, ul_nas_transport.assoc_id);
Logger::amf_n2().error("UE with ran_ue_ngap_id(0x%x) is not attached to gnb with assoc_id (%d)", ran_ue_ngap_id, ul_nas_transport.assoc_id);
return;
}
if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) {
Logger::amf_n2().error("No UE NGAP context with ran_ue_ngap_id(%d)", ran_ue_ngap_id);
Logger::amf_n2().error("No UE NGAP context with ran_ue_ngap_id (%d)", ran_ue_ngap_id);
return;
}
unc = ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id);
if (unc.get()->amf_ue_ngap_id != amf_ue_ngap_id) {
Logger::amf_n2().error("The requested UE(amf_ue_ngap_id:0x%x) is not valid, existed UE which's amf_ue_ngap_id(0x%x)", amf_ue_ngap_id, unc.get()->amf_ue_ngap_id);
Logger::amf_n2().error("The requested UE (amf_ue_ngap_id: 0x%x) is not valid, existed UE which's amf_ue_ngap_id (0x%x)", amf_ue_ngap_id, unc.get()->amf_ue_ngap_id);
}
if (unc.get()->ng_ue_state != NGAP_UE_CONNECTED) {
Logger::amf_n2().error("Received NGAP UPLINK_NAS_TRANSPORT while UE in state != NGAP_UE_CONNECTED");
......@@ -461,13 +461,13 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request &itti_msg) {
std::shared_ptr<ue_ngap_context> unc;
unc = ran_ue_id_2_ue_ngap_context(itti_msg.ran_ue_ngap_id);
if (unc.get() == nullptr) {
Logger::amf_n2().error("Illegal UE with ran_ue_ngap_id(0x%x)", itti_msg.ran_ue_ngap_id);
Logger::amf_n2().error("Illegal UE with ran_ue_ngap_id (0x%x)", itti_msg.ran_ue_ngap_id);
return;
}
std::shared_ptr<gnb_context> gc;
gc = assoc_id_2_gnb_context(unc.get()->gnb_assoc_id);
if (gc.get() == nullptr) {
Logger::amf_n2().error("Illegal gNB with assoc id(0x%x)", unc.get()->gnb_assoc_id);
Logger::amf_n2().error("Illegal gNB with assoc id (0x%x)", unc.get()->gnb_assoc_id);
return;
}
InitialContextSetupRequestMsg *msg = new InitialContextSetupRequestMsg();
......@@ -521,13 +521,13 @@ void amf_n2::handle_itti_message(itti_pdu_session_resource_setup_request &itti_m
std::shared_ptr<ue_ngap_context> unc;
unc = ran_ue_id_2_ue_ngap_context(itti_msg.ran_ue_ngap_id);
if (unc.get() == nullptr) {
Logger::amf_n2().error("Illegal UE with ran_ue_ngap_id(0x%x)", itti_msg.ran_ue_ngap_id);
Logger::amf_n2().error("Illegal UE with ran_ue_ngap_id (0x%x)", itti_msg.ran_ue_ngap_id);
return;
}
std::shared_ptr<gnb_context> gc;
gc = assoc_id_2_gnb_context(unc.get()->gnb_assoc_id);
if (gc.get() == nullptr) {
Logger::amf_n2().error("Illegal gNB with assoc id(0x%x)", unc.get()->gnb_assoc_id);
Logger::amf_n2().error("Illegal gNB with assoc id (0x%x)", unc.get()->gnb_assoc_id);
return;
}
PduSessionResourceSetupRequestMsg *psrsr = new PduSessionResourceSetupRequestMsg();
......@@ -577,7 +577,7 @@ void amf_n2::handle_itti_message(itti_ue_context_release_request &itti_msg) {
void amf_n2::handle_itti_message(itti_ue_radio_capability_indication &itti_msg) {
std::shared_ptr<gnb_context> gc;
if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) {
Logger::amf_n2().error("No existed gNB context with assoc_id(%d)", itti_msg.assoc_id);
Logger::amf_n2().error("No existed gNB context with assoc_id (%d)", itti_msg.assoc_id);
return;
}
gc = assoc_id_2_gnb_context(itti_msg.assoc_id);
......
......@@ -66,6 +66,34 @@ typedef struct s_nssai // section 28.4, TS23.003
} snssai_t;
//SMF + AMF + 3GPP TS 29.571 (Common data)
enum class http_response_codes_e {
HTTP_RESPONSE_CODE_200_OK = 200,
HTTP_RESPONSE_CODE_201_CREATED = 201,
HTTP_RESPONSE_CODE_202_ACCEPTED = 202,
HTTP_RESPONSE_CODE_204_UPDATED = 204,
HTTP_RESPONSE_CODE_BAD_REQUEST = 400,
HTTP_RESPONSE_CODE_UNAUTHORIZED = 401,
HTTP_RESPONSE_CODE_FORBIDDEN = 403,
HTTP_RESPONSE_CODE_NOT_FOUND = 404,
HTTP_RESPONSE_CODE_METHOD_NOT_ALLOWED = 405,
HTTP_RESPONSE_CODE_REQUEST_TIMEOUT = 408,
HTTP_RESPONSE_CODE_406_NOT_ACCEPTED = 406,
HTTP_RESPONSE_CODE_CONFLICT = 409,
HTTP_RESPONSE_CODE_GONE = 410,
HTTP_RESPONSE_CODE_LENGTH_REQUIRED = 411,
HTTP_RESPONSE_CODE_PRECONDITION_FAILED = 412,
HTTP_RESPONSE_CODE_PAYLOAD_TOO_LARGE = 413,
HTTP_RESPONSE_CODE_URI_TOO_LONG = 414,
HTTP_RESPONSE_CODE_UNSUPPORTED_MEDIA_TYPE = 415,
HTTP_RESPONSE_CODE_TOO_MANY_REQUESTS = 429,
HTTP_RESPONSE_CODE_INTERNAL_SERVER_ERROR = 500,
HTTP_RESPONSE_CODE_NOT_IMPLEMENTED = 501,
HTTP_RESPONSE_CODE_SERVICE_UNAVAILABLE = 503,
HTTP_RESPONSE_CODE_GATEWAY_TIMEOUT = 504
};
#endif
......
......@@ -3,6 +3,7 @@
#include <iostream>
#include <string>
#include <unistd.h>
#include "amf.hpp"
/*
* To read content of the response from UDM
*/
......
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