Commit 56fc542d authored by Niuhaiwen's avatar Niuhaiwen

handover

parent 7e455aab
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under * 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 * the OAI Public License, Version 1.1 (the "License"); you may not use this
* except in compliance with the License. *file except in compliance with the License. You may obtain a copy of the
* You may obtain a copy of the License at *License at
* *
* http://www.openairinterface.org/?page_id=698 * http://www.openairinterface.org/?page_id=698
* *
...@@ -57,37 +57,38 @@ using namespace web::http; ...@@ -57,37 +57,38 @@ using namespace web::http;
using namespace web::http::client; using namespace web::http::client;
using namespace config; using namespace config;
using namespace amf_application; using namespace amf_application;
extern itti_mw *itti_inst; extern itti_mw* itti_inst;
extern amf_config amf_cfg; extern amf_config amf_cfg;
extern amf_n11 *amf_n11_inst; extern amf_n11* amf_n11_inst;
extern amf_n1 *amf_n1_inst; extern amf_n1* amf_n1_inst;
extern void msg_str_2_msg_hex(std::string msg, bstring &b); extern void msg_str_2_msg_hex(std::string msg, bstring& b);
extern void convert_string_2_hex(std::string &input, std::string &output); extern void convert_string_2_hex(std::string& input, std::string& output);
extern void print_buffer(const std::string app, const std::string commit, extern void print_buffer(
uint8_t *buf, int len); const std::string app, const std::string commit, uint8_t* buf, int len);
extern bool multipart_parser(std::string input, std::string &jsonData, extern bool multipart_parser(
std::string &n1sm, std::string &n2sm); std::string input, std::string& jsonData, std::string& n1sm,
std::string& n2sm);
extern unsigned char* format_string_as_hex(std::string str); extern unsigned char* format_string_as_hex(std::string str);
extern char* bstring2charString(bstring b); extern char* bstring2charString(bstring b);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
std::size_t callback(const char *in, std::size_t size, std::size_t num, std::size_t callback(
std::string *out) { const char* in, std::size_t size, std::size_t num, std::string* out) {
const std::size_t totalBytes(size * num); const std::size_t totalBytes(size * num);
out->append(in, totalBytes); out->append(in, totalBytes);
return totalBytes; return totalBytes;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void octet_stream_2_hex_stream(uint8_t *buf, int len, std::string &out) { void octet_stream_2_hex_stream(uint8_t* buf, int len, std::string& out) {
out = ""; out = "";
char *tmp = (char*) calloc(1, 2 * len * sizeof(uint8_t) + 1); char* tmp = (char*) calloc(1, 2 * len * sizeof(uint8_t) + 1);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
sprintf(tmp + 2 * i, "%02x", buf[i]); sprintf(tmp + 2 * i, "%02x", buf[i]);
} }
tmp[2 * len] = '\0'; tmp[2 * len] = '\0';
out = tmp; out = tmp;
printf("n1sm buffer: %s\n", out.c_str()); printf("n1sm buffer: %s\n", out.c_str());
} }
...@@ -102,34 +103,31 @@ void amf_n11_task(void*) { ...@@ -102,34 +103,31 @@ void amf_n11_task(void*) {
itti_inst->notify_task_ready(task_id); itti_inst->notify_task_ready(task_id);
do { do {
std::shared_ptr<itti_msg> shared_msg = itti_inst->receive_msg(task_id); std::shared_ptr<itti_msg> shared_msg = itti_inst->receive_msg(task_id);
auto *msg = shared_msg.get(); auto* msg = shared_msg.get();
switch (msg->msg_type) { switch (msg->msg_type) {
case SMF_SERVICES_CONSUMER: { case SMF_SERVICES_CONSUMER: {
Logger::amf_n11().info("Running SMF_SERVICES_CONSUMER"); Logger::amf_n11().info("Running SMF_SERVICES_CONSUMER");
itti_smf_services_consumer *m = itti_smf_services_consumer* m =
dynamic_cast<itti_smf_services_consumer*>(msg); dynamic_cast<itti_smf_services_consumer*>(msg);
amf_n11_inst->handle_itti_message(ref(*m)); amf_n11_inst->handle_itti_message(ref(*m));
} } break;
break;
case NSMF_PDU_SESSION_UPDATE_SM_CTX: { case NSMF_PDU_SESSION_UPDATE_SM_CTX: {
Logger::amf_n11().info( Logger::amf_n11().info(
"Receive Nsmf_PDUSessionUpdateSMContext, handling ..."); "Receive Nsmf_PDUSessionUpdateSMContext, handling ...");
itti_nsmf_pdusession_update_sm_context *m = itti_nsmf_pdusession_update_sm_context* m =
dynamic_cast<itti_nsmf_pdusession_update_sm_context*>(msg); dynamic_cast<itti_nsmf_pdusession_update_sm_context*>(msg);
amf_n11_inst->handle_itti_message(ref(*m)); amf_n11_inst->handle_itti_message(ref(*m));
} } break;
break;
case PDU_SESS_RES_SET_RESP: { case PDU_SESS_RES_SET_RESP: {
Logger::amf_n11().info( Logger::amf_n11().info(
"Receive PDU Session Resource Setup Response, handling ..."); "Receive PDU Session Resource Setup Response, handling ...");
itti_pdu_session_resource_setup_response *m = itti_pdu_session_resource_setup_response* m =
dynamic_cast<itti_pdu_session_resource_setup_response*>(msg); dynamic_cast<itti_pdu_session_resource_setup_response*>(msg);
amf_n11_inst->handle_itti_message(ref(*m)); amf_n11_inst->handle_itti_message(ref(*m));
} } break;
break;
default: { default: {
Logger::amf_n11().info("Receive unknown message type %d", Logger::amf_n11().info(
msg->msg_type); "Receive unknown message type %d", msg->msg_type);
} }
} }
} while (true); } while (true);
...@@ -146,21 +144,20 @@ amf_n11::amf_n11() { ...@@ -146,21 +144,20 @@ amf_n11::amf_n11() {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
amf_n11::~amf_n11() { amf_n11::~amf_n11() {}
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n11::handle_itti_message( void amf_n11::handle_itti_message(
itti_pdu_session_resource_setup_response &itti_msg) { itti_pdu_session_resource_setup_response& itti_msg) {}
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n11::handle_itti_message( void amf_n11::handle_itti_message(
itti_nsmf_pdusession_update_sm_context &itti_msg) { itti_nsmf_pdusession_update_sm_context& itti_msg) {
std::string supi = pduid2supi.at(itti_msg.pdu_session_id); std::string supi = pduid2supi.at(itti_msg.pdu_session_id);
Logger::amf_n11().debug( Logger::amf_n11().debug(
"Send PDU Session Update SM Context Request to SMF (SUPI %s, PDU Session ID %d)", "Send PDU Session Update SM Context Request to SMF (SUPI %s, PDU Session "
"ID %d)",
supi.c_str(), itti_msg.pdu_session_id); supi.c_str(), itti_msg.pdu_session_id);
std::shared_ptr<pdu_session_context> psc; std::shared_ptr<pdu_session_context> psc;
if (is_supi_to_pdu_ctx(supi)) { if (is_supi_to_pdu_ctx(supi)) {
...@@ -184,7 +181,7 @@ void amf_n11::handle_itti_message( ...@@ -184,7 +181,7 @@ void amf_n11::handle_itti_message(
std::string smf_ip_addr, remote_uri; std::string smf_ip_addr, remote_uri;
std::shared_ptr<pdu_session_context> context; std::shared_ptr<pdu_session_context> context;
context = supi_to_pdu_ctx(supi); context = supi_to_pdu_ctx(supi);
//remove http port from the URI if existed // remove http port from the URI if existed
std::size_t found_port = smf_addr.find(":"); std::size_t found_port = smf_addr.find(":");
if (found_port != std::string::npos) if (found_port != std::string::npos)
smf_ip_addr = smf_addr.substr(0, found_port - 1); smf_ip_addr = smf_addr.substr(0, found_port - 1);
...@@ -199,48 +196,48 @@ void amf_n11::handle_itti_message( ...@@ -199,48 +196,48 @@ void amf_n11::handle_itti_message(
Logger::amf_n11().debug("SMF URI: %s", remote_uri.c_str()); Logger::amf_n11().debug("SMF URI: %s", remote_uri.c_str());
nlohmann::json pdu_session_update_request = { }; nlohmann::json pdu_session_update_request = {};
//if (itti_msg.is_n2sm_set){ // if (itti_msg.is_n2sm_set){
pdu_session_update_request["n2SmInfoType"] = itti_msg.n2sm_info_type; pdu_session_update_request["n2SmInfoType"] = itti_msg.n2sm_info_type;
pdu_session_update_request["n2SmInfo"]["contentId"] = "n2SmMsg"; pdu_session_update_request["n2SmInfo"]["contentId"] = "n2SmMsg";
std::string json_part = pdu_session_update_request.dump(); std::string json_part = pdu_session_update_request.dump();
std::string n2SmMsg; std::string n2SmMsg;
octet_stream_2_hex_stream((uint8_t*) bdata(itti_msg.n2sm), octet_stream_2_hex_stream(
blength(itti_msg.n2sm), n2SmMsg); (uint8_t*) bdata(itti_msg.n2sm), blength(itti_msg.n2sm), n2SmMsg);
curl_http_client(remote_uri, json_part, "", n2SmMsg, supi, curl_http_client(
itti_msg.pdu_session_id); remote_uri, json_part, "", n2SmMsg, supi, itti_msg.pdu_session_id);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) { void amf_n11::handle_itti_message(itti_smf_services_consumer& smf) {
Logger::amf_n11().debug("Handle ITTI_SMF_SERVICES_CONSUMER"); Logger::amf_n11().debug("Handle ITTI_SMF_SERVICES_CONSUMER");
std::shared_ptr < nas_context > nc; std::shared_ptr<nas_context> nc;
nc = amf_n1_inst->amf_ue_id_2_nas_context(smf.amf_ue_ngap_id); nc = amf_n1_inst->amf_ue_id_2_nas_context(smf.amf_ue_ngap_id);
std::string supi = "imsi-" + nc.get()->imsi; std::string supi = "imsi-" + nc.get()->imsi;
std::shared_ptr<pdu_session_context> psc; std::shared_ptr<pdu_session_context> psc;
if (is_supi_to_pdu_ctx(supi)) { if (is_supi_to_pdu_ctx(supi)) {
psc = supi_to_pdu_ctx(supi); psc = supi_to_pdu_ctx(supi);
} else { } else {
psc = std::shared_ptr < pdu_session_context > (new pdu_session_context()); psc = std::shared_ptr<pdu_session_context>(new pdu_session_context());
set_supi_to_pdu_ctx(supi, psc); set_supi_to_pdu_ctx(supi, psc);
} }
pduid2supi[smf.pdu_sess_id] = supi; pduid2supi[smf.pdu_sess_id] = supi;
psc.get()->amf_ue_ngap_id = nc.get()->amf_ue_ngap_id; psc.get()->amf_ue_ngap_id = nc.get()->amf_ue_ngap_id;
psc.get()->ran_ue_ngap_id = nc.get()->ran_ue_ngap_id; psc.get()->ran_ue_ngap_id = nc.get()->ran_ue_ngap_id;
psc.get()->req_type = smf.req_type; psc.get()->req_type = smf.req_type;
psc.get()->pdu_session_id = smf.pdu_sess_id; psc.get()->pdu_session_id = smf.pdu_sess_id;
psc.get()->snssai.sST = smf.snssai.sST; psc.get()->snssai.sST = smf.snssai.sST;
psc.get()->snssai.sD = smf.snssai.sD; psc.get()->snssai.sD = smf.snssai.sD;
psc.get()->plmn.mcc = smf.plmn.mcc; psc.get()->plmn.mcc = smf.plmn.mcc;
psc.get()->plmn.mnc = smf.plmn.mnc; psc.get()->plmn.mnc = smf.plmn.mnc;
//parse binary dnn and store // parse binary dnn and store
std::string dnn = "default"; std::string dnn = "default";
if ((smf.dnn != nullptr) && (blength(smf.dnn) > 0)) { if ((smf.dnn != nullptr) && (blength(smf.dnn) > 0)) {
char *tmp = bstring2charString(smf.dnn); char* tmp = bstring2charString(smf.dnn);
dnn = tmp; dnn = tmp;
free_wrapper((void**) &tmp); free_wrapper((void**) &tmp);
} }
...@@ -259,28 +256,28 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) { ...@@ -259,28 +256,28 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) {
switch (smf.req_type & 0x07) { switch (smf.req_type & 0x07) {
case PDU_SESSION_INITIAL_REQUEST: { case PDU_SESSION_INITIAL_REQUEST: {
//get pti // get pti
uint8_t *sm_msg = (uint8_t*) bdata(smf.sm_msg); uint8_t* sm_msg = (uint8_t*) bdata(smf.sm_msg);
uint8_t pti = sm_msg[2]; uint8_t pti = sm_msg[2];
Logger::amf_n11().debug( Logger::amf_n11().debug(
"Decoded PTI for PDUSessionEstablishmentRequest(0x%x)", pti); "Decoded PTI for PDUSessionEstablishmentRequest(0x%x)", pti);
if (psc.get()->isn1sm_avaliable && psc.get()->isn2sm_avaliable) { if (psc.get()->isn1sm_avaliable && psc.get()->isn2sm_avaliable) {
itti_n1n2_message_transfer_request *itti_msg = itti_n1n2_message_transfer_request* itti_msg =
new itti_n1n2_message_transfer_request(TASK_AMF_N11, TASK_AMF_APP); new itti_n1n2_message_transfer_request(TASK_AMF_N11, TASK_AMF_APP);
itti_msg->supi = supi; itti_msg->supi = supi;
uint8_t accept_len = blength(psc.get()->n1sm); uint8_t accept_len = blength(psc.get()->n1sm);
uint8_t *accept = (uint8_t*) calloc(1, accept_len); uint8_t* accept = (uint8_t*) calloc(1, accept_len);
memcpy(accept, (uint8_t*) bdata(psc.get()->n1sm), accept_len); memcpy(accept, (uint8_t*) bdata(psc.get()->n1sm), accept_len);
accept[2] = pti; accept[2] = pti;
itti_msg->n1sm = blk2bstr(accept, accept_len); itti_msg->n1sm = blk2bstr(accept, accept_len);
free(accept); free(accept);
itti_msg->is_n1sm_set = true; itti_msg->is_n1sm_set = true;
itti_msg->n2sm = psc.get()->n2sm; itti_msg->n2sm = psc.get()->n2sm;
itti_msg->is_n2sm_set = true; itti_msg->is_n2sm_set = true;
itti_msg->pdu_session_id = psc.get()->pdu_session_id; itti_msg->pdu_session_id = psc.get()->pdu_session_id;
std::shared_ptr < itti_n1n2_message_transfer_request > i = std::shared_ptr<itti_n1n2_message_transfer_request> i =
std::shared_ptr < itti_n1n2_message_transfer_request > (itti_msg); std::shared_ptr<itti_n1n2_message_transfer_request>(itti_msg);
int ret = itti_inst->send_msg(i); int ret = itti_inst->send_msg(i);
if (0 != ret) { if (0 != ret) {
Logger::amf_n11().error( Logger::amf_n11().error(
...@@ -289,23 +286,21 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) { ...@@ -289,23 +286,21 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) {
} }
} else { } else {
psc.get()->isn2sm_avaliable = false; psc.get()->isn2sm_avaliable = false;
handle_pdu_session_initial_request(supi, psc, smf_addr, smf.sm_msg, handle_pdu_session_initial_request(
dnn); supi, psc, smf_addr, smf.sm_msg, dnn);
} }
} } break;
break;
case EXISTING_PDU_SESSION: { case EXISTING_PDU_SESSION: {
//TODO: // TODO:
} } break;
break;
case PDU_SESSION_TYPE_MODIFICATION_REQUEST: { case PDU_SESSION_TYPE_MODIFICATION_REQUEST: {
//TODO: // TODO:
} } break;
break;
default: { default: {
//send Nsmf_PDUSession_UpdateSM_Context to SMF e.g., for PDU Session release request // send Nsmf_PDUSession_UpdateSM_Context to SMF e.g., for PDU Session
send_pdu_session_update_sm_context_request(supi, psc, smf_addr, // release request
smf.sm_msg, dnn); send_pdu_session_update_sm_context_request(
supi, psc, smf_addr, smf.sm_msg, dnn);
} }
} }
} }
...@@ -315,11 +310,12 @@ void amf_n11::send_pdu_session_update_sm_context_request( ...@@ -315,11 +310,12 @@ void amf_n11::send_pdu_session_update_sm_context_request(
std::string supi, std::shared_ptr<pdu_session_context> psc, std::string supi, std::shared_ptr<pdu_session_context> psc,
std::string smf_addr, bstring sm_msg, std::string dnn) { std::string smf_addr, bstring sm_msg, std::string dnn) {
Logger::amf_n11().debug( Logger::amf_n11().debug(
"Send PDU Session Update SM Context Request to SMF (SUPI %s, PDU Session ID %d)", "Send PDU Session Update SM Context Request to SMF (SUPI %s, PDU Session "
"ID %d)",
supi.c_str(), psc.get()->pdu_session_id); supi.c_str(), psc.get()->pdu_session_id);
std::string smf_ip_addr, remote_uri; std::string smf_ip_addr, remote_uri;
//remove http port from the URI if existed // remove http port from the URI if existed
std::size_t found_port = smf_addr.find(":"); std::size_t found_port = smf_addr.find(":");
if (found_port != std::string::npos) if (found_port != std::string::npos)
smf_ip_addr = smf_addr.substr(0, found_port - 1); smf_ip_addr = smf_addr.substr(0, found_port - 1);
...@@ -334,14 +330,14 @@ void amf_n11::send_pdu_session_update_sm_context_request( ...@@ -334,14 +330,14 @@ void amf_n11::send_pdu_session_update_sm_context_request(
Logger::amf_n11().debug("SMF URI: %s", remote_uri.c_str()); Logger::amf_n11().debug("SMF URI: %s", remote_uri.c_str());
nlohmann::json pdu_session_update_request = { }; nlohmann::json pdu_session_update_request = {};
pdu_session_update_request["n1SmMsg"]["contentId"] = "n1SmMsg"; pdu_session_update_request["n1SmMsg"]["contentId"] = "n1SmMsg";
std::string json_part = pdu_session_update_request.dump(); std::string json_part = pdu_session_update_request.dump();
std::string n1SmMsg; std::string n1SmMsg;
octet_stream_2_hex_stream((uint8_t*) bdata(sm_msg), blength(sm_msg), n1SmMsg); octet_stream_2_hex_stream((uint8_t*) bdata(sm_msg), blength(sm_msg), n1SmMsg);
curl_http_client(remote_uri, json_part, n1SmMsg, "", supi, curl_http_client(
psc.get()->pdu_session_id); remote_uri, json_part, n1SmMsg, "", supi, psc.get()->pdu_session_id);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -352,45 +348,48 @@ void amf_n11::handle_pdu_session_initial_request( ...@@ -352,45 +348,48 @@ void amf_n11::handle_pdu_session_initial_request(
"Handle PDU Session Establishment Request (SUPI %s, PDU Session ID %d)", "Handle PDU Session Establishment Request (SUPI %s, PDU Session ID %d)",
supi.c_str(), psc.get()->pdu_session_id); supi.c_str(), psc.get()->pdu_session_id);
//TODO: Remove hardcoded values // TODO: Remove hardcoded values
std::string remote_uri = smf_addr + "/nsmf-pdusession/v2/sm-contexts"; //TODO std::string remote_uri = smf_addr + "/nsmf-pdusession/v2/sm-contexts"; // TODO
nlohmann::json pdu_session_establishment_request; nlohmann::json pdu_session_establishment_request;
pdu_session_establishment_request["supi"] = supi.c_str(); pdu_session_establishment_request["supi"] = supi.c_str();
pdu_session_establishment_request["pei"] = "imei-200000000000001"; pdu_session_establishment_request["pei"] = "imei-200000000000001";
pdu_session_establishment_request["gpsi"] = "msisdn-200000000001"; pdu_session_establishment_request["gpsi"] = "msisdn-200000000001";
pdu_session_establishment_request["dnn"] = dnn.c_str(); pdu_session_establishment_request["dnn"] = dnn.c_str();
//pdu_session_establishment_request["sNssai"]["sst"] = psc.get()->snssai.sST; // pdu_session_establishment_request["sNssai"]["sst"] = psc.get()->snssai.sST;
pdu_session_establishment_request["sNssai"]["sst"] = 1; pdu_session_establishment_request["sNssai"]["sst"] = 1;
pdu_session_establishment_request["sNssai"]["sd"] = "0"; pdu_session_establishment_request["sNssai"]["sd"] = "0";
//pdu_session_establishment_request["sNssai"]["sd"] = psc.get()->snssai.sD; // pdu_session_establishment_request["sNssai"]["sd"] = psc.get()->snssai.sD;
pdu_session_establishment_request["pduSessionId"] = psc.get()->pdu_session_id; pdu_session_establishment_request["pduSessionId"] = psc.get()->pdu_session_id;
pdu_session_establishment_request["requestType"] = "INITIAL_REQUEST"; //TODO: from SM_MSG pdu_session_establishment_request["requestType"] =
"INITIAL_REQUEST"; // TODO: from SM_MSG
pdu_session_establishment_request["servingNfId"] = "servingNfId"; pdu_session_establishment_request["servingNfId"] = "servingNfId";
//pdu_session_establishment_request["servingNetwork"]["mcc"] = psc.get()->plmn // pdu_session_establishment_request["servingNetwork"]["mcc"] =
// psc.get()->plmn
// .mcc; // .mcc;
//pdu_session_establishment_request["servingNetwork"]["mnc"] = psc.get()->plmn // pdu_session_establishment_request["servingNetwork"]["mnc"] =
// psc.get()->plmn
// .mnc; // .mnc;
pdu_session_establishment_request["servingNetwork"]["mcc"] = "110"; pdu_session_establishment_request["servingNetwork"]["mcc"] = "110";
pdu_session_establishment_request["servingNetwork"]["mnc"] = "011"; pdu_session_establishment_request["servingNetwork"]["mnc"] = "011";
pdu_session_establishment_request["anType"] = "3GPP_ACCESS"; //TODO pdu_session_establishment_request["anType"] = "3GPP_ACCESS"; // TODO
pdu_session_establishment_request["smContextStatusUri"] = pdu_session_establishment_request["smContextStatusUri"] =
"smContextStatusUri"; "smContextStatusUri";
pdu_session_establishment_request["n1MessageContainer"]["n1MessageClass"] = pdu_session_establishment_request["n1MessageContainer"]["n1MessageClass"] =
"SM"; "SM";
pdu_session_establishment_request["n1MessageContainer"]["n1MessageContent"]["contentId"] = pdu_session_establishment_request["n1MessageContainer"]["n1MessageContent"]
"n1SmMsg"; ["contentId"] = "n1SmMsg";
std::string json_part = pdu_session_establishment_request.dump(); std::string json_part = pdu_session_establishment_request.dump();
std::string n1SmMsg; std::string n1SmMsg;
octet_stream_2_hex_stream((uint8_t*) bdata(sm_msg), blength(sm_msg), n1SmMsg); octet_stream_2_hex_stream((uint8_t*) bdata(sm_msg), blength(sm_msg), n1SmMsg);
curl_http_client(remote_uri, json_part, n1SmMsg, "", supi, curl_http_client(
psc.get()->pdu_session_id); remote_uri, json_part, n1SmMsg, "", supi, psc.get()->pdu_session_id);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n11::handle_itti_message( void amf_n11::handle_itti_message(
itti_nsmf_pdusession_release_sm_context &itti_msg) { itti_nsmf_pdusession_release_sm_context& itti_msg) {
std::shared_ptr<pdu_session_context> psc = supi_to_pdu_ctx(itti_msg.supi); std::shared_ptr<pdu_session_context> psc = supi_to_pdu_ctx(itti_msg.supi);
string smf_addr; string smf_addr;
if (!psc.get()->smf_available) { if (!psc.get()->smf_available) {
...@@ -403,44 +402,45 @@ void amf_n11::handle_itti_message( ...@@ -403,44 +402,45 @@ void amf_n11::handle_itti_message(
} }
string remote_uri = psc.get()->location + "release"; string remote_uri = psc.get()->location + "release";
nlohmann::json pdu_session_release_request; nlohmann::json pdu_session_release_request;
pdu_session_release_request["supi"] = itti_msg.supi.c_str(); pdu_session_release_request["supi"] = itti_msg.supi.c_str();
pdu_session_release_request["dnn"] = psc.get()->dnn.c_str(); pdu_session_release_request["dnn"] = psc.get()->dnn.c_str();
pdu_session_release_request["sNssai"]["sst"] = 1; pdu_session_release_request["sNssai"]["sst"] = 1;
pdu_session_release_request["sNssai"]["sd"] = "0"; pdu_session_release_request["sNssai"]["sd"] = "0";
pdu_session_release_request["pduSessionId"] = psc.get()->pdu_session_id; pdu_session_release_request["pduSessionId"] = psc.get()->pdu_session_id;
pdu_session_release_request["cause"] = "REL_DUE_TO_REACTIVATION"; pdu_session_release_request["cause"] = "REL_DUE_TO_REACTIVATION";
pdu_session_release_request["ngApCause"] = "radioNetwork"; pdu_session_release_request["ngApCause"] = "radioNetwork";
std::string json_part = pdu_session_release_request.dump(); std::string json_part = pdu_session_release_request.dump();
curl_http_client(remote_uri, json_part, "", "", itti_msg.supi, curl_http_client(
psc.get()->pdu_session_id); remote_uri, json_part, "", "", itti_msg.supi, psc.get()->pdu_session_id);
} }
//Context management functions // Context management functions
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool amf_n11::is_supi_to_pdu_ctx(const std::string &supi) const { bool amf_n11::is_supi_to_pdu_ctx(const std::string& supi) const {
std::shared_lock lock(m_supi2pdu); std::shared_lock lock(m_supi2pdu);
return bool { supi2pdu.count(supi) > 0 }; return bool{supi2pdu.count(supi) > 0};
} }
std::shared_ptr<pdu_session_context> amf_n11::supi_to_pdu_ctx( std::shared_ptr<pdu_session_context> amf_n11::supi_to_pdu_ctx(
const std::string &supi) const { const std::string& supi) const {
std::shared_lock lock(m_supi2pdu); std::shared_lock lock(m_supi2pdu);
return supi2pdu.at(supi); return supi2pdu.at(supi);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n11::set_supi_to_pdu_ctx(const string &supi, void amf_n11::set_supi_to_pdu_ctx(
std::shared_ptr<pdu_session_context> psc) { const string& supi, std::shared_ptr<pdu_session_context> psc) {
std::shared_lock lock(m_supi2pdu); std::shared_lock lock(m_supi2pdu);
supi2pdu[supi] = psc; supi2pdu[supi] = psc;
} }
//SMF selection // SMF selection
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool amf_n11::smf_selection_from_configuration(std::string &smf_addr) { bool amf_n11::smf_selection_from_configuration(std::string& smf_addr) {
for (int i = 0; i < amf_cfg.smf_pool.size(); i++) { for (int i = 0; i < amf_cfg.smf_pool.size(); i++) {
if (amf_cfg.smf_pool[i].selected) { if (amf_cfg.smf_pool[i].selected) {
//smf_addr = "http://" + amf_cfg.smf_pool[i].ipv4 + ":" + amf_cfg.smf_pool[i].port; // smf_addr = "http://" + amf_cfg.smf_pool[i].ipv4 + ":" +
// amf_cfg.smf_pool[i].port;
smf_addr = amf_cfg.smf_pool[i].ipv4 + ":" + amf_cfg.smf_pool[i].port; smf_addr = amf_cfg.smf_pool[i].ipv4 + ":" + amf_cfg.smf_pool[i].port;
return true; return true;
} }
...@@ -449,30 +449,27 @@ bool amf_n11::smf_selection_from_configuration(std::string &smf_addr) { ...@@ -449,30 +449,27 @@ bool amf_n11::smf_selection_from_configuration(std::string &smf_addr) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool amf_n11::smf_selection_from_context(std::string &smf_addr) { bool amf_n11::smf_selection_from_context(std::string& smf_addr) {
//TODO: // TODO:
} }
// handlers for smf client response // handlers for smf client response
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n11::handle_post_sm_context_response_error_400() { void amf_n11::handle_post_sm_context_response_error_400() {}
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n11::handle_post_sm_context_response_error(long code, void amf_n11::handle_post_sm_context_response_error(
std::string cause, long code, std::string cause, bstring n1sm, std::string supi,
bstring n1sm, uint8_t pdu_session_id) {
std::string supi,
uint8_t pdu_session_id) {
print_buffer("amf_n11", "n1 sm", (uint8_t*) bdata(n1sm), blength(n1sm)); print_buffer("amf_n11", "n1 sm", (uint8_t*) bdata(n1sm), blength(n1sm));
itti_n1n2_message_transfer_request *itti_msg = itti_n1n2_message_transfer_request* itti_msg =
new itti_n1n2_message_transfer_request(TASK_AMF_N11, TASK_AMF_APP); new itti_n1n2_message_transfer_request(TASK_AMF_N11, TASK_AMF_APP);
itti_msg->n1sm = n1sm; itti_msg->n1sm = n1sm;
itti_msg->is_n2sm_set = false; itti_msg->is_n2sm_set = false;
itti_msg->supi = supi; itti_msg->supi = supi;
itti_msg->pdu_session_id = pdu_session_id; itti_msg->pdu_session_id = pdu_session_id;
std::shared_ptr < itti_n1n2_message_transfer_request > i = std::shared_ptr std::shared_ptr<itti_n1n2_message_transfer_request> i =
< itti_n1n2_message_transfer_request > (itti_msg); std::shared_ptr<itti_n1n2_message_transfer_request>(itti_msg);
int ret = itti_inst->send_msg(i); int ret = itti_inst->send_msg(i);
if (0 != ret) { if (0 != ret) {
Logger::amf_n11().error( Logger::amf_n11().error(
...@@ -482,57 +479,57 @@ void amf_n11::handle_post_sm_context_response_error(long code, ...@@ -482,57 +479,57 @@ void amf_n11::handle_post_sm_context_response_error(long code,
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, void amf_n11::curl_http_client(
std::string n1SmMsg, std::string n2SmMsg, std::string remoteUri, std::string jsonData, std::string n1SmMsg,
std::string supi, uint8_t pdu_session_id) { std::string n2SmMsg, std::string supi, uint8_t pdu_session_id) {
Logger::amf_n11().debug("Call SMF service: %s", remoteUri.c_str()); Logger::amf_n11().debug("Call SMF service: %s", remoteUri.c_str());
uint8_t number_parts = 0; uint8_t number_parts = 0;
mime_parser parser = { }; mime_parser parser = {};
std::string body; std::string body;
std::shared_ptr<pdu_session_context> psc; std::shared_ptr<pdu_session_context> psc;
if (is_supi_to_pdu_ctx(supi)) { if (is_supi_to_pdu_ctx(supi)) {
psc = supi_to_pdu_ctx(supi); psc = supi_to_pdu_ctx(supi);
} else { } else {
Logger::amf_n11().warn("PDU Session context for SUPI %s doesn't exit!", Logger::amf_n11().warn(
supi.c_str()); "PDU Session context for SUPI %s doesn't exit!", supi.c_str());
//TODO: // TODO:
} }
if ((n1SmMsg.size() > 0) and (n2SmMsg.size() > 0)) { if ((n1SmMsg.size() > 0) and (n2SmMsg.size() > 0)) {
//prepare the body content for Curl // prepare the body content for Curl
parser.create_multipart_related_content(body, jsonData, CURL_MIME_BOUNDARY, parser.create_multipart_related_content(
n1SmMsg, n2SmMsg); body, jsonData, CURL_MIME_BOUNDARY, n1SmMsg, n2SmMsg);
} else if (n1SmMsg.size() > 0) { //only N1 content } else if (n1SmMsg.size() > 0) { // only N1 content
//prepare the body content for Curl // prepare the body content for Curl
parser.create_multipart_related_content( parser.create_multipart_related_content(
body, jsonData, CURL_MIME_BOUNDARY, n1SmMsg, body, jsonData, CURL_MIME_BOUNDARY, n1SmMsg,
multipart_related_content_part_e::NAS); multipart_related_content_part_e::NAS);
} else if (n2SmMsg.size() > 0) { //only N2 content } else if (n2SmMsg.size() > 0) { // only N2 content
//prepare the body content for Curl // prepare the body content for Curl
parser.create_multipart_related_content( parser.create_multipart_related_content(
body, jsonData, CURL_MIME_BOUNDARY, n2SmMsg, body, jsonData, CURL_MIME_BOUNDARY, n2SmMsg,
multipart_related_content_part_e::NGAP); multipart_related_content_part_e::NGAP);
} }
Logger::amf_n11().debug("Send HTTP message to SMF with body %s", Logger::amf_n11().debug(
body.c_str()); "Send HTTP message to SMF with body %s", body.c_str());
uint32_t str_len = body.length(); uint32_t str_len = body.length();
char *body_data = (char*) malloc(str_len + 1); char* body_data = (char*) malloc(str_len + 1);
memset(body_data, 0, str_len + 1); memset(body_data, 0, str_len + 1);
memcpy((void*) body_data, (void*) body.c_str(), str_len); memcpy((void*) body_data, (void*) body.c_str(), str_len);
curl_global_init (CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);
CURL *curl = curl_easy_init(); CURL* curl = curl_easy_init();
if (curl) { if (curl) {
CURLcode res = { }; CURLcode res = {};
struct curl_slist *headers = nullptr; struct curl_slist* headers = nullptr;
std::string content_type = "content-type: multipart/related; boundary=" std::string content_type = "content-type: multipart/related; boundary=" +
+ std::string(CURL_MIME_BOUNDARY); std::string(CURL_MIME_BOUNDARY);
headers = curl_slist_append(headers, content_type.c_str()); headers = curl_slist_append(headers, content_type.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_URL, remoteUri.c_str()); curl_easy_setopt(curl, CURLOPT_URL, remoteUri.c_str());
...@@ -541,9 +538,9 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, ...@@ -541,9 +538,9 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData,
curl_easy_setopt(curl, CURLOPT_INTERFACE, amf_cfg.n11.if_name.c_str()); curl_easy_setopt(curl, CURLOPT_INTERFACE, amf_cfg.n11.if_name.c_str());
// Response information. // Response information.
long httpCode = { 0 }; long httpCode = {0};
std::unique_ptr < std::string > httpData(new std::string()); std::unique_ptr<std::string> httpData(new std::string());
std::unique_ptr < std::string > httpHeaderData(new std::string()); std::unique_ptr<std::string> httpHeaderData(new std::string());
// Hook up data handling function. // Hook up data handling function.
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &callback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &callback);
...@@ -556,20 +553,20 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, ...@@ -556,20 +553,20 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData,
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
//get cause from the response // get cause from the response
std::string response = *httpData.get(); std::string response = *httpData.get();
std::string json_data_response = ""; std::string json_data_response = "";
std::string n1sm = ""; std::string n1sm = "";
std::string n2sm = ""; std::string n2sm = "";
nlohmann::json response_data = { }; nlohmann::json response_data = {};
bstring n1sm_hex, n2sm_hex; bstring n1sm_hex, n2sm_hex;
Logger::amf_n11().debug("Get response with HTTP code (%d)", httpCode); Logger::amf_n11().debug("Get response with HTTP code (%d)", httpCode);
if (static_cast<http_response_codes_e>(httpCode) if (static_cast<http_response_codes_e>(httpCode) ==
== http_response_codes_e::HTTP_RESPONSE_CODE_0) { http_response_codes_e::HTTP_RESPONSE_CODE_0) {
Logger::amf_n11().error("Cannot get response when calling %s", Logger::amf_n11().error(
remoteUri.c_str()); "Cannot get response when calling %s", remoteUri.c_str());
//free curl before returning // free curl before returning
curl_slist_free_all(headers); curl_slist_free_all(headers);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
return; return;
...@@ -579,100 +576,106 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, ...@@ -579,100 +576,106 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData,
number_parts = multipart_parser(response, json_data_response, n1sm, n2sm); number_parts = multipart_parser(response, json_data_response, n1sm, n2sm);
} }
if ((static_cast<http_response_codes_e>(httpCode) if ((static_cast<http_response_codes_e>(httpCode) !=
!= http_response_codes_e::HTTP_RESPONSE_CODE_200_OK) http_response_codes_e::HTTP_RESPONSE_CODE_200_OK) &&
&& (static_cast<http_response_codes_e>(httpCode) (static_cast<http_response_codes_e>(httpCode) !=
!= http_response_codes_e::HTTP_RESPONSE_CODE_201_CREATED) http_response_codes_e::HTTP_RESPONSE_CODE_201_CREATED) &&
&& (static_cast<http_response_codes_e>(httpCode) (static_cast<http_response_codes_e>(httpCode) !=
!= http_response_codes_e::HTTP_RESPONSE_CODE_204_UPDATED)) { http_response_codes_e::HTTP_RESPONSE_CODE_204_UPDATED)) {
//ERROR // ERROR
if (response.size() < 1) { if (response.size() < 1) {
Logger::amf_n11().error("There's no content in the response"); Logger::amf_n11().error("There's no content in the response");
curl_slist_free_all(headers); curl_slist_free_all(headers);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
//TODO: send context response error // TODO: send context response error
return; return;
} }
try { try {
response_data = nlohmann::json::parse(json_data_response); response_data = nlohmann::json::parse(json_data_response);
} catch (nlohmann::json::exception &e) { } catch (nlohmann::json::exception& e) {
Logger::amf_n11().warn("Could not get Json content from the response"); Logger::amf_n11().warn("Could not get Json content from the response");
//Set the default Cause // Set the default Cause
response_data["error"]["cause"] = "504 Gateway Timeout"; response_data["error"]["cause"] = "504 Gateway Timeout";
} }
Logger::amf_n11().debug("Get response with jsonData: %s", Logger::amf_n11().debug(
json_data_response.c_str()); "Get response with jsonData: %s", json_data_response.c_str());
msg_str_2_msg_hex(n1sm.substr(0, n1sm.length() - 2), n1sm_hex); //TODO: pdu session establishment reject bugs from SMF msg_str_2_msg_hex(
print_buffer("amf_n11", "Get response with n1sm:", n1sm.substr(0, n1sm.length() - 2),
(uint8_t*) bdata(n1sm_hex), blength(n1sm_hex)); n1sm_hex); // TODO: pdu session establishment reject bugs from SMF
print_buffer(
"amf_n11", "Get response with n1sm:", (uint8_t*) bdata(n1sm_hex),
blength(n1sm_hex));
std::string cause = response_data["error"]["cause"]; std::string cause = response_data["error"]["cause"];
Logger::amf_n11().warn( Logger::amf_n11().warn(
"Call Network Function services failure (with cause %s)", "Call Network Function services failure (with cause %s)",
cause.c_str()); cause.c_str());
if (!cause.compare("DNN_DENIED")) if (!cause.compare("DNN_DENIED"))
handle_post_sm_context_response_error(httpCode, cause, n1sm_hex, supi, handle_post_sm_context_response_error(
pdu_session_id); httpCode, cause, n1sm_hex, supi, pdu_session_id);
} else { //Response with success code } else { // Response with success code
//Store location of the created context in case of PDU Session Establishment // Store location of the created context in case of PDU Session
// Establishment
std::string header_response = *httpHeaderData.get(); std::string header_response = *httpHeaderData.get();
std::string CRLF = "\r\n"; std::string CRLF = "\r\n";
std::size_t location_pos = header_response.find("Location"); std::size_t location_pos = header_response.find("Location");
if (location_pos != std::string::npos) { if (location_pos != std::string::npos) {
std::size_t crlf_pos = header_response.find(CRLF, location_pos); std::size_t crlf_pos = header_response.find(CRLF, location_pos);
if (crlf_pos != std::string::npos) { if (crlf_pos != std::string::npos) {
std::string location = header_response.substr( std::string location = header_response.substr(
location_pos + 10, crlf_pos - (location_pos + 10)); location_pos + 10, crlf_pos - (location_pos + 10));
Logger::amf_n11().info("Location of the created SMF context: %s", Logger::amf_n11().info(
location.c_str()); "Location of the created SMF context: %s", location.c_str());
psc.get()->smf_context_location = location; psc.get()->smf_context_location = location;
} }
} }
//Transfer N1/N2 to gNB/UE if available // Transfer N1/N2 to gNB/UE if available
/*if (number_parts > 1) { if (number_parts > 1) {
try { try {
response_data = nlohmann::json::parse(json_data_response); response_data = nlohmann::json::parse(json_data_response);
} catch (nlohmann::json::exception &e) { } catch (nlohmann::json::exception& e) {
Logger::amf_n11().warn( Logger::amf_n11().warn(
"Could not get Json content from the response"); "Could not get Json content from the response");
//TODO: // TODO:
} }
itti_n1n2_message_transfer_request *itti_msg = itti_n1n2_message_transfer_request* itti_msg =
new itti_n1n2_message_transfer_request(TASK_AMF_N11, TASK_AMF_APP); new itti_n1n2_message_transfer_request(TASK_AMF_N11, TASK_AMF_APP);
if (n1sm.size() > 0) { if (n1sm.size() > 0) {
msg_str_2_msg_hex(n1sm, n1sm_hex); msg_str_2_msg_hex(n1sm, n1sm_hex);
print_buffer("amf_n11", "Get response n1sm:", print_buffer(
(uint8_t*) bdata(n1sm_hex), blength(n1sm_hex)); "amf_n11", "Get response n1sm:", (uint8_t*) bdata(n1sm_hex),
itti_msg->n1sm = n1sm_hex; blength(n1sm_hex));
itti_msg->n1sm = n1sm_hex;
itti_msg->is_n1sm_set = true; itti_msg->is_n1sm_set = true;
} }
if (n2sm.size() > 0) { if (n2sm.size() > 0) {
msg_str_2_msg_hex(n2sm, n2sm_hex); msg_str_2_msg_hex(n2sm, n2sm_hex);
print_buffer("amf_n11", "Get response n2sm:", print_buffer(
(uint8_t*) bdata(n2sm_hex), blength(n2sm_hex)); "amf_n11", "Get response n2sm:", (uint8_t*) bdata(n2sm_hex),
itti_msg->n2sm = n2sm_hex; blength(n2sm_hex));
itti_msg->is_n2sm_set = true; itti_msg->n2sm = n2sm_hex;
itti_msg->n2sm_info_type = response_data["n2SmInfoType"]; //response_data["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapIeType"]; itti_msg->is_n2sm_set = true;
itti_msg->n2sm_info_type = response_data
["n2SmInfoType"]; // response_data["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapIeType"];
} }
itti_msg->supi = supi; itti_msg->supi = supi;
itti_msg->pdu_session_id = pdu_session_id; itti_msg->pdu_session_id = pdu_session_id;
std::shared_ptr < itti_n1n2_message_transfer_request > i = std::shared_ptr<itti_n1n2_message_transfer_request> i =
std::shared_ptr < itti_n1n2_message_transfer_request > (itti_msg); std::shared_ptr<itti_n1n2_message_transfer_request>(itti_msg);
int ret = itti_inst->send_msg(i); int ret = itti_inst->send_msg(i);
if (0 != ret) { if (0 != ret) {
Logger::amf_n11().error( Logger::amf_n11().error(
"Could not send ITTI message %s to task TASK_AMF_APP", "Could not send ITTI message %s to task TASK_AMF_APP",
i->get_msg_name()); i->get_msg_name());
} }
}*/ }
} }
curl_slist_free_all(headers); curl_slist_free_all(headers);
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under * 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 * the OAI Public License, Version 1.1 (the "License"); you may not use this
* except in compliance with the License. *file except in compliance with the License. You may obtain a copy of the
* You may obtain a copy of the License at *License at
* *
* http://www.openairinterface.org/?page_id=698 * http://www.openairinterface.org/?page_id=698
* *
...@@ -59,148 +59,134 @@ using namespace amf_application; ...@@ -59,148 +59,134 @@ using namespace amf_application;
using namespace config; using namespace config;
using namespace ngap; using namespace ngap;
using namespace std; using namespace std;
extern itti_mw *itti_inst; extern itti_mw* itti_inst;
extern amf_n2 *amf_n2_inst; extern amf_n2* amf_n2_inst;
extern amf_n1 *amf_n1_inst; extern amf_n1* amf_n1_inst;
extern amf_n11 *amf_n11_inst; extern amf_n11* amf_n11_inst;
extern amf_config amf_cfg; extern amf_config amf_cfg;
extern amf_app *amf_app_inst; extern amf_app* amf_app_inst;
extern statistics stacs; extern statistics stacs;
extern void print_buffer(const std::string app, const std::string commit, uint8_t *buf, int len); extern void print_buffer(
const std::string app, const std::string commit, uint8_t* buf, int len);
uint32_t ran_id_Global = 0; uint32_t ran_id_Global = 0;
uint32_t AMF_TARGET_ran_id_global = 0; uint32_t AMF_TARGET_ran_id_global = 0;
sctp_assoc_id_t downlink_sctp_assoc_id = 0; sctp_assoc_id_t downlink_sctp_assoc_id = 0;
sctp_assoc_id_t source_assoc_id = 0; sctp_assoc_id_t source_assoc_id = 0;
int ncc = 0;
void amf_n2_task(void*); void amf_n2_task(void*);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2_task(void *args_p) { void amf_n2_task(void* args_p) {
const task_id_t task_id = TASK_AMF_N2; const task_id_t task_id = TASK_AMF_N2;
itti_inst->notify_task_ready(task_id); itti_inst->notify_task_ready(task_id);
do { do {
std::shared_ptr<itti_msg> shared_msg = itti_inst->receive_msg(task_id); std::shared_ptr<itti_msg> shared_msg = itti_inst->receive_msg(task_id);
auto *msg = shared_msg.get(); auto* msg = shared_msg.get();
switch (msg->msg_type) { switch (msg->msg_type) {
case NEW_SCTP_ASSOCIATION: { case NEW_SCTP_ASSOCIATION: {
Logger::amf_n2().info("Received NEW_SCTP_ASSOCIATION"); Logger::amf_n2().info("Received NEW_SCTP_ASSOCIATION");
itti_new_sctp_association *m = itti_new_sctp_association* m =
dynamic_cast<itti_new_sctp_association*>(msg); dynamic_cast<itti_new_sctp_association*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} } break;
break;
case NG_SETUP_REQ: { case NG_SETUP_REQ: {
Logger::amf_n2().info("Received NGSetupRequest message, handling"); Logger::amf_n2().info("Received NGSetupRequest message, handling");
itti_ng_setup_request *m = dynamic_cast<itti_ng_setup_request*>(msg); itti_ng_setup_request* m = dynamic_cast<itti_ng_setup_request*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} } break;
break;
case INITIAL_UE_MSG: { case INITIAL_UE_MSG: {
Logger::amf_n2().info("Received INITIAL_UE_MESSAGE message, handling"); Logger::amf_n2().info("Received INITIAL_UE_MESSAGE message, handling");
itti_initial_ue_message *m = dynamic_cast<itti_initial_ue_message*>(msg); itti_initial_ue_message* m =
dynamic_cast<itti_initial_ue_message*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} } break;
break;
case ITTI_UL_NAS_TRANSPORT: { case ITTI_UL_NAS_TRANSPORT: {
Logger::amf_n2().info( Logger::amf_n2().info(
"Received UPLINK_NAS_TRANSPORT message, handling"); "Received UPLINK_NAS_TRANSPORT message, handling");
itti_ul_nas_transport *m = dynamic_cast<itti_ul_nas_transport*>(msg); itti_ul_nas_transport* m = dynamic_cast<itti_ul_nas_transport*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} } break;
break;
case ITTI_DL_NAS_TRANSPORT: { case ITTI_DL_NAS_TRANSPORT: {
Logger::amf_n2().info( Logger::amf_n2().info(
"Encoding DOWNLINK NAS TRANSPORT message, sending "); "Encoding DOWNLINK NAS TRANSPORT message, sending ");
itti_dl_nas_transport *m = dynamic_cast<itti_dl_nas_transport*>(msg); itti_dl_nas_transport* m = dynamic_cast<itti_dl_nas_transport*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} } break;
break;
case PDU_SESSION_RESOURCE_SETUP_REQUEST: { case PDU_SESSION_RESOURCE_SETUP_REQUEST: {
Logger::amf_n2().info( Logger::amf_n2().info(
"Encoding PDU SESSION RESOURCE SETUP REQUEST message, sending "); "Encoding PDU SESSION RESOURCE SETUP REQUEST message, sending ");
itti_pdu_session_resource_setup_request *m = itti_pdu_session_resource_setup_request* m =
dynamic_cast<itti_pdu_session_resource_setup_request*>(msg); dynamic_cast<itti_pdu_session_resource_setup_request*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} } break;
break;
case INITIAL_CONTEXT_SETUP_REQUEST: { case INITIAL_CONTEXT_SETUP_REQUEST: {
Logger::amf_n2().info( Logger::amf_n2().info(
"Encoding INITIAL CONTEXT SETUP REQUEST message, sending "); "Encoding INITIAL CONTEXT SETUP REQUEST message, sending ");
itti_initial_context_setup_request *m = itti_initial_context_setup_request* m =
dynamic_cast<itti_initial_context_setup_request*>(msg); dynamic_cast<itti_initial_context_setup_request*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} } break;
break;
case UE_CONTEXT_RELEASE_REQUEST: { case UE_CONTEXT_RELEASE_REQUEST: {
Logger::amf_n2().info( Logger::amf_n2().info(
"Received UE_CONTEXT_RELEASE_REQUEST message, handling"); "Received UE_CONTEXT_RELEASE_REQUEST message, handling");
itti_ue_context_release_request *m = itti_ue_context_release_request* m =
dynamic_cast<itti_ue_context_release_request*>(msg); dynamic_cast<itti_ue_context_release_request*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} } break;
break;
case UE_CONTEXT_RELEASE_COMMAND: { case UE_CONTEXT_RELEASE_COMMAND: {
Logger::task_amf_n2().info( Logger::task_amf_n2().info(
"Received UE_CONTEXT_RELEASE_COMMAND message, handling"); "Received UE_CONTEXT_RELEASE_COMMAND message, handling");
itti_ue_context_release_command *m = itti_ue_context_release_command* m =
dynamic_cast<itti_ue_context_release_command*>(msg); dynamic_cast<itti_ue_context_release_command*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} } break;
break;
case PDU_SESSION_RESOURCE_RELEASE_COMMAND: { case PDU_SESSION_RESOURCE_RELEASE_COMMAND: {
Logger::task_amf_n2().info( Logger::task_amf_n2().info(
"Received PDU_SESSION_RESOURCE_RELEASE_COMMAND message, handling"); "Received PDU_SESSION_RESOURCE_RELEASE_COMMAND message, handling");
itti_pdu_session_resource_release_command *m = itti_pdu_session_resource_release_command* m =
dynamic_cast<itti_pdu_session_resource_release_command*>(msg); dynamic_cast<itti_pdu_session_resource_release_command*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} } break;
break;
case UE_RADIO_CAP_IND: { case UE_RADIO_CAP_IND: {
Logger::amf_n2().info("Received UE_RADIO_CAP_IND message, handling"); Logger::amf_n2().info("Received UE_RADIO_CAP_IND message, handling");
itti_ue_radio_capability_indication *m = itti_ue_radio_capability_indication* m =
dynamic_cast<itti_ue_radio_capability_indication*>(msg); dynamic_cast<itti_ue_radio_capability_indication*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} } break;
break;
case HANDOVER_REQUIRED: { case HANDOVER_REQUIRED: {
Logger::amf_n2().info("Received HANDOVER_REQUIRED message,handling"); Logger::amf_n2().info("Received HANDOVER_REQUIRED message,handling");
itti_handover_required *m = dynamic_cast<itti_handover_required*>(msg); itti_handover_required* m = dynamic_cast<itti_handover_required*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} } break;
break;
case HANDOVER_REQUEST_ACK: { case HANDOVER_REQUEST_ACK: {
Logger::amf_n2().info("Received HANDOVER_REQUEST_ACK message,handling"); Logger::amf_n2().info("Received HANDOVER_REQUEST_ACK message,handling");
itti_handover_request_Ack *m = itti_handover_request_Ack* m =
dynamic_cast<itti_handover_request_Ack*>(msg); dynamic_cast<itti_handover_request_Ack*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} } break;
break;
case HANDOVER_NOTIFY: { case HANDOVER_NOTIFY: {
Logger::amf_n2().info("Received HANDOVER_NOTIFY message,handling"); Logger::amf_n2().info("Received HANDOVER_NOTIFY message,handling");
itti_handover_notify *m = dynamic_cast<itti_handover_notify*>(msg); itti_handover_notify* m = dynamic_cast<itti_handover_notify*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} } break;
break;
case UPLINKRANSTATUSTRANSFER: { case UPLINKRANSTATUSTRANSFER: {
Logger::amf_n2().info( Logger::amf_n2().info(
"Received UPLINKRANSTATUSTRANSFER message,handling"); "Received UPLINKRANSTATUSTRANSFER message,handling");
itti_uplinkranstatsutransfer *m = itti_uplinkranstatsutransfer* m =
dynamic_cast<itti_uplinkranstatsutransfer*>(msg); dynamic_cast<itti_uplinkranstatsutransfer*>(msg);
amf_n2_inst->handle_itti_message(ref(*m)); amf_n2_inst->handle_itti_message(ref(*m));
} } break;
break;
default: default:
Logger::amf_n2().info("No handler for msg type %d", msg->msg_type); Logger::amf_n2().info("No handler for msg type %d", msg->msg_type);
} }
} while (true); } while (true);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
amf_n2::amf_n2(const std::string &address, const uint16_t port_num) amf_n2::amf_n2(const std::string& address, const uint16_t port_num)
: : ngap_app(address, port_num) {
ngap_app(address, port_num) {
if (itti_inst->create_task(TASK_AMF_N2, amf_n2_task, nullptr)) { if (itti_inst->create_task(TASK_AMF_N2, amf_n2_task, nullptr)) {
Logger::amf_n2().error("Cannot create task TASK_AMF_N2"); Logger::amf_n2().error("Cannot create task TASK_AMF_N2");
throw std::runtime_error("Cannot create task TASK_AMF_N2"); throw std::runtime_error("Cannot create task TASK_AMF_N2");
...@@ -210,41 +196,41 @@ amf_n2::amf_n2(const std::string &address, const uint16_t port_num) ...@@ -210,41 +196,41 @@ amf_n2::amf_n2(const std::string &address, const uint16_t port_num)
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
amf_n2::~amf_n2() { amf_n2::~amf_n2() {}
}
//NGAP Messages Handlers // NGAP Messages Handlers
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_new_sctp_association &new_assoc) { void amf_n2::handle_itti_message(itti_new_sctp_association& new_assoc) {
} //handled in class ngap_app } // handled in class ngap_app
// NG_SETUP_REQUEST Handler // NG_SETUP_REQUEST Handler
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) { void amf_n2::handle_itti_message(itti_ng_setup_request& itti_msg) {
Logger::amf_n2().debug("Parameters: assoc_id %d, stream %d", Logger::amf_n2().debug(
itti_msg.assoc_id, itti_msg.stream); "Parameters: assoc_id %d, stream %d", itti_msg.assoc_id, itti_msg.stream);
std::shared_ptr < gnb_context > gc; std::shared_ptr<gnb_context> gc;
if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) { if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) {
Logger::amf_n2().error("No existed gNB context with assoc_id(%d)", Logger::amf_n2().error(
itti_msg.assoc_id); "No existed gNB context with assoc_id(%d)", itti_msg.assoc_id);
return; return;
} }
gc = assoc_id_2_gnb_context(itti_msg.assoc_id); gc = assoc_id_2_gnb_context(itti_msg.assoc_id);
if (gc.get()->ng_state == NGAP_RESETING if (gc.get()->ng_state == NGAP_RESETING ||
|| gc.get()->ng_state == NGAP_SHUTDOWN) { gc.get()->ng_state == NGAP_SHUTDOWN) {
Logger::amf_n2().warn( Logger::amf_n2().warn(
"Received new association request on an association that is being %s, ignoring", "Received new association request on an association that is being %s, "
"ignoring",
ng_gnb_state_str[gc.get()->ng_state]); ng_gnb_state_str[gc.get()->ng_state]);
} else { } else {
Logger::amf_n2().debug("Update gNB context with assoc id (%d)", Logger::amf_n2().debug(
itti_msg.assoc_id); "Update gNB context with assoc id (%d)", itti_msg.assoc_id);
} }
gnb_infos gnbItem; gnb_infos gnbItem;
//Get IE Global RAN Node ID // Get IE Global RAN Node ID
uint32_t gnb_id; uint32_t gnb_id;
std::string gnb_mcc; std::string gnb_mcc;
std::string gnb_mnc; std::string gnb_mnc;
...@@ -254,13 +240,13 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) { ...@@ -254,13 +240,13 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) {
} }
Logger::amf_n2().debug("IE GlobalGNBID: 0x%x", gnb_id); Logger::amf_n2().debug("IE GlobalGNBID: 0x%x", gnb_id);
gc->globalRanNodeId = gnb_id; gc->globalRanNodeId = gnb_id;
gnbItem.gnb_id = gnb_id; gnbItem.gnb_id = gnb_id;
std::string gnb_name; std::string gnb_name;
if (!itti_msg.ngSetupReq->getRanNodeName(gnb_name)) { if (!itti_msg.ngSetupReq->getRanNodeName(gnb_name)) {
Logger::amf_n2().warn("IE RanNodeName not existed"); Logger::amf_n2().warn("IE RanNodeName not existed");
} else { } else {
gc->gnb_name = gnb_name; gc->gnb_name = gnb_name;
gnbItem.gnb_name = gnb_name; gnbItem.gnb_name = gnb_name;
Logger::amf_n2().debug("IE RanNodeName: %s", gnb_name.c_str()); Logger::amf_n2().debug("IE RanNodeName: %s", gnb_name.c_str());
} }
...@@ -273,33 +259,36 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) { ...@@ -273,33 +259,36 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) {
Logger::amf_n2().debug("IE DefaultPagingDRX: %d", defPagingDrx); Logger::amf_n2().debug("IE DefaultPagingDRX: %d", defPagingDrx);
vector<SupportedItem_t> s_ta_list; vector<SupportedItem_t> s_ta_list;
if (!itti_msg.ngSetupReq->getSupportedTAList(s_ta_list)) { //getSupportedTAList if (!itti_msg.ngSetupReq->getSupportedTAList(
s_ta_list)) { // getSupportedTAList
return; return;
} }
//TODO: should be removed, since we stored list of common PLMNs // TODO: should be removed, since we stored list of common PLMNs
gnbItem.mcc = s_ta_list[0].b_plmn_list[0].mcc; gnbItem.mcc = s_ta_list[0].b_plmn_list[0].mcc;
gnbItem.mnc = s_ta_list[0].b_plmn_list[0].mnc; gnbItem.mnc = s_ta_list[0].b_plmn_list[0].mnc;
gnbItem.tac = s_ta_list[0].tac; gnbItem.tac = s_ta_list[0].tac;
//association GlobalRANNodeID with assoc_id // association GlobalRANNodeID with assoc_id
//store RAN Node Name in gNB context, if present // store RAN Node Name in gNB context, if present
//verify PLMN Identity and TAC with configuration and store supportedTAList in gNB context, if verified; else response NG SETUP FAILURE with cause "Unknown PLMN"(9.3.1.2, ts38413) // verify PLMN Identity and TAC with configuration and store supportedTAList
// in gNB context, if verified; else response NG SETUP FAILURE with cause
// "Unknown PLMN"(9.3.1.2, ts38413)
std::vector<SupportedItem_t> common_plmn_list = get_common_plmn(s_ta_list); std::vector<SupportedItem_t> common_plmn_list = get_common_plmn(s_ta_list);
if (common_plmn_list.size() == 0) { if (common_plmn_list.size() == 0) {
// if (!verifyPlmn(s_ta_list)) { // if (!verifyPlmn(s_ta_list)) {
//encode NG SETUP FAILURE MESSAGE and send back // encode NG SETUP FAILURE MESSAGE and send back
void *buffer = calloc(1, 1000); void* buffer = calloc(1, 1000);
NGSetupFailureMsg ngSetupFailure; NGSetupFailureMsg ngSetupFailure;
ngSetupFailure.setMessageType(); ngSetupFailure.setMessageType();
ngSetupFailure.setCauseRadioNetwork(Ngap_CauseRadioNetwork_unspecified, ngSetupFailure.setCauseRadioNetwork(
Ngap_TimeToWait_v5s); Ngap_CauseRadioNetwork_unspecified, Ngap_TimeToWait_v5s);
int encoded = ngSetupFailure.encode2buffer((uint8_t*) buffer, 1000); int encoded = ngSetupFailure.encode2buffer((uint8_t*) buffer, 1000);
bstring b = blk2bstr(buffer, encoded); bstring b = blk2bstr(buffer, encoded);
sctp_s_38412.sctp_send_msg(itti_msg.assoc_id, itti_msg.stream, &b); sctp_s_38412.sctp_send_msg(itti_msg.assoc_id, itti_msg.stream, &b);
Logger::amf_n2().error( Logger::amf_n2().error(
"No common PLMN, encoding NG_SETUP_FAILURE with cause (Unknown PLMN)"); "No common PLMN, encoding NG_SETUP_FAILURE with cause (Unknown PLMN)");
return; return;
} else { } else {
//store only the common PLMN // store only the common PLMN
gc->s_ta_list = common_plmn_list; gc->s_ta_list = common_plmn_list;
for (auto i : common_plmn_list) { for (auto i : common_plmn_list) {
gnbItem.plmn_list.push_back(i); gnbItem.plmn_list.push_back(i);
...@@ -307,11 +296,12 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) { ...@@ -307,11 +296,12 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) {
} }
set_gnb_id_2_gnb_context(gnb_id, gc); set_gnb_id_2_gnb_context(gnb_id, gc);
//store Paging DRX in gNB context // store Paging DRX in gNB context
Logger::amf_n2().debug("Encoding NG_SETUP_RESPONSE ..."); Logger::amf_n2().debug("Encoding NG_SETUP_RESPONSE ...");
//encode NG SETUP RESPONSE message with information stored in configuration file and send_msg // encode NG SETUP RESPONSE message with information stored in configuration
void *buffer = calloc(1, 1000); // file and send_msg
void* buffer = calloc(1, 1000);
NGSetupResponseMsg ngSetupResp; NGSetupResponseMsg ngSetupResp;
ngSetupResp.setMessageType(); ngSetupResp.setMessageType();
ngSetupResp.setAMFName(amf_cfg.AMF_Name); ngSetupResp.setAMFName(amf_cfg.AMF_Name);
...@@ -319,12 +309,12 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) { ...@@ -319,12 +309,12 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) {
std::vector<struct GuamiItem_s> guami_list; std::vector<struct GuamiItem_s> guami_list;
for (int i = 0; i < amf_cfg.guami_list.size(); i++) { for (int i = 0; i < amf_cfg.guami_list.size(); i++) {
struct GuamiItem_s tmp; struct GuamiItem_s tmp;
tmp.mcc = amf_cfg.guami_list[i].mcc; tmp.mcc = amf_cfg.guami_list[i].mcc;
tmp.mnc = amf_cfg.guami_list[i].mnc; tmp.mnc = amf_cfg.guami_list[i].mnc;
tmp.regionID = amf_cfg.guami_list[i].regionID; tmp.regionID = amf_cfg.guami_list[i].regionID;
tmp.AmfSetID = amf_cfg.guami_list[i].AmfSetID; tmp.AmfSetID = amf_cfg.guami_list[i].AmfSetID;
tmp.AmfPointer = amf_cfg.guami_list[i].AmfPointer; tmp.AmfPointer = amf_cfg.guami_list[i].AmfPointer;
//tmp.mcc = amf_cfg.guami_list[i].mcc; // tmp.mcc = amf_cfg.guami_list[i].mcc;
guami_list.push_back(tmp); guami_list.push_back(tmp);
} }
ngSetupResp.setGUAMIList(guami_list); ngSetupResp.setGUAMIList(guami_list);
...@@ -336,14 +326,14 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) { ...@@ -336,14 +326,14 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) {
for (int j = 0; j < amf_cfg.plmn_list[i].slice_list.size(); j++) { for (int j = 0; j < amf_cfg.plmn_list[i].slice_list.size(); j++) {
SliceSupportItem_t s_tmp; SliceSupportItem_t s_tmp;
s_tmp.sst = amf_cfg.plmn_list[i].slice_list[j].sST; s_tmp.sst = amf_cfg.plmn_list[i].slice_list[j].sST;
s_tmp.sd = amf_cfg.plmn_list[i].slice_list[j].sD; s_tmp.sd = amf_cfg.plmn_list[i].slice_list[j].sD;
tmp.slice_list.push_back(s_tmp); tmp.slice_list.push_back(s_tmp);
} }
plmn_list.push_back(tmp); plmn_list.push_back(tmp);
} }
ngSetupResp.setPlmnSupportList(plmn_list); ngSetupResp.setPlmnSupportList(plmn_list);
int encoded = ngSetupResp.encode2buffer((uint8_t*) buffer, 1000); int encoded = ngSetupResp.encode2buffer((uint8_t*) buffer, 1000);
bstring b = blk2bstr(buffer, encoded); bstring b = blk2bstr(buffer, encoded);
sctp_s_38412.sctp_send_msg(itti_msg.assoc_id, itti_msg.stream, &b); sctp_s_38412.sctp_send_msg(itti_msg.assoc_id, itti_msg.stream, &b);
Logger::amf_n2().debug("Sending NG_SETUP_RESPONSE Ok"); Logger::amf_n2().debug("Sending NG_SETUP_RESPONSE Ok");
gc.get()->ng_state = NGAP_READY; gc.get()->ng_state = NGAP_READY;
...@@ -356,46 +346,47 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) { ...@@ -356,46 +346,47 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
//INITIAL_UE_MESSAGE Handler // INITIAL_UE_MESSAGE Handler
void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_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 // create ngap-ue context and store in gNB context to store UE information in
//send NAS-PDU to NAS layer // gNB, for example, here RAN UE NGAP ID and location information and RRC
//Get INITIAL_UE_MESSAGE IEs // Establishment Cause send NAS-PDU to NAS layer Get INITIAL_UE_MESSAGE IEs
//check the gNB context on which this UE is attached with assoc_id // check the gNB context on which this UE is attached with assoc_id
itti_nas_signalling_establishment_request *itti_msg = itti_nas_signalling_establishment_request* itti_msg =
new itti_nas_signalling_establishment_request(TASK_AMF_N2, TASK_AMF_APP); new itti_nas_signalling_establishment_request(TASK_AMF_N2, TASK_AMF_APP);
if (!is_assoc_id_2_gnb_context(init_ue_msg.assoc_id)) { if (!is_assoc_id_2_gnb_context(init_ue_msg.assoc_id)) {
Logger::amf_n2().error("No existing gNG context with assoc_id (%d)", Logger::amf_n2().error(
init_ue_msg.assoc_id); "No existing gNG context with assoc_id (%d)", init_ue_msg.assoc_id);
return; return;
} }
std::shared_ptr < gnb_context > gc; std::shared_ptr<gnb_context> gc;
gc = assoc_id_2_gnb_context(init_ue_msg.assoc_id); gc = assoc_id_2_gnb_context(init_ue_msg.assoc_id);
if (gc.get()->ng_state == NGAP_RESETING if (gc.get()->ng_state == NGAP_RESETING ||
|| gc.get()->ng_state == NGAP_SHUTDOWN) { gc.get()->ng_state == NGAP_SHUTDOWN) {
Logger::amf_n2().warn( Logger::amf_n2().warn(
"Received new association request on an association that is being %s, ignoring", "Received new association request on an association that is being %s, "
"ignoring",
ng_gnb_state_str[gc.get()->ng_state]); ng_gnb_state_str[gc.get()->ng_state]);
} else if (gc.get()->ng_state != NGAP_READY) { } else if (gc.get()->ng_state != NGAP_READY) {
Logger::amf_n2().debug("gNB with assoc_id (%d) is illegal", Logger::amf_n2().debug(
init_ue_msg.assoc_id); "gNB with assoc_id (%d) is illegal", init_ue_msg.assoc_id);
return; return;
} }
//UE NGAP Context // UE NGAP Context
uint32_t ran_ue_ngap_id; uint32_t ran_ue_ngap_id;
if ((ran_ue_ngap_id = init_ue_msg.initUeMsg->getRanUENgapID()) == -1) { if ((ran_ue_ngap_id = init_ue_msg.initUeMsg->getRanUENgapID()) == -1) {
Logger::amf_n2().error("Missing Mandatory IE (RanUeNgapId)"); Logger::amf_n2().error("Missing Mandatory IE (RanUeNgapId)");
return; return;
} }
std::shared_ptr < ue_ngap_context > unc; std::shared_ptr<ue_ngap_context> unc;
if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) { if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) {
Logger::amf_n2().debug( Logger::amf_n2().debug(
"Create a new UE NGAP context with ran_ue_ngap_id 0x%x", "Create a new UE NGAP context with ran_ue_ngap_id 0x%x",
ran_ue_ngap_id); ran_ue_ngap_id);
unc = std::shared_ptr < ue_ngap_context > (new ue_ngap_context()); unc = std::shared_ptr<ue_ngap_context>(new ue_ngap_context());
set_ran_ue_ngap_id_2_ue_ngap_context(ran_ue_ngap_id, unc); set_ran_ue_ngap_id_2_ue_ngap_context(ran_ue_ngap_id, unc);
} else { } else {
unc = ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id); unc = ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id);
...@@ -404,8 +395,8 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) { ...@@ -404,8 +395,8 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) {
Logger::amf_n2().error( Logger::amf_n2().error(
"Failed to get UE NGAP context for ran_ue_ngap_id 0x%x", 21); "Failed to get UE NGAP context for ran_ue_ngap_id 0x%x", 21);
} else { } else {
//store information into UE NGAP context // store information into UE NGAP context
unc.get()->ran_ue_ngap_id = ran_ue_ngap_id; unc.get()->ran_ue_ngap_id = ran_ue_ngap_id;
unc.get()->sctp_stream_recv = init_ue_msg.stream; unc.get()->sctp_stream_recv = init_ue_msg.stream;
unc.get()->sctp_stream_send == gc.get()->next_sctp_stream; unc.get()->sctp_stream_send == gc.get()->next_sctp_stream;
gc.get()->next_sctp_stream += 1; gc.get()->next_sctp_stream += 1;
...@@ -423,7 +414,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) { ...@@ -423,7 +414,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) {
} }
if (init_ue_msg.initUeMsg->getRRCEstablishmentCause() == -1) { if (init_ue_msg.initUeMsg->getRRCEstablishmentCause() == -1) {
Logger::amf_n2().warn("IE RRCEstablishmentCause not present"); Logger::amf_n2().warn("IE RRCEstablishmentCause not present");
itti_msg->rrc_cause = -1; //not present itti_msg->rrc_cause = -1; // not present
} else { } else {
itti_msg->rrc_cause = init_ue_msg.initUeMsg->getRRCEstablishmentCause(); itti_msg->rrc_cause = init_ue_msg.initUeMsg->getRRCEstablishmentCause();
} }
...@@ -441,25 +432,24 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) { ...@@ -441,25 +432,24 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) {
Logger::amf_n2().debug("5g_s_tmsi not present"); Logger::amf_n2().debug("5g_s_tmsi not present");
} else { } else {
itti_msg->is_5g_s_tmsi_present = true; itti_msg->is_5g_s_tmsi_present = true;
itti_msg->_5g_s_tmsi = _5g_s_tmsi; itti_msg->_5g_s_tmsi = _5g_s_tmsi;
Logger::amf_n2().debug("5g_s_tmsi present"); Logger::amf_n2().debug("5g_s_tmsi present");
} }
uint8_t *nas_buf; uint8_t* nas_buf;
size_t nas_len = 0; size_t nas_len = 0;
if (init_ue_msg.initUeMsg->getNasPdu(nas_buf, nas_len)) { if (init_ue_msg.initUeMsg->getNasPdu(nas_buf, nas_len)) {
bstring nas = blk2bstr(nas_buf, nas_len); bstring nas = blk2bstr(nas_buf, nas_len);
itti_msg->nas_buf = nas; itti_msg->nas_buf = nas;
} else { } else {
Logger::amf_n2().error("Missing IE NAS-PDU"); Logger::amf_n2().error("Missing IE NAS-PDU");
return; return;
} }
} }
itti_msg->ran_ue_ngap_id = ran_ue_ngap_id; itti_msg->ran_ue_ngap_id = ran_ue_ngap_id;
itti_msg->amf_ue_ngap_id = -1; itti_msg->amf_ue_ngap_id = -1;
std::shared_ptr < itti_nas_signalling_establishment_request > i = std::shared_ptr<itti_nas_signalling_establishment_request> i =
std::shared_ptr < itti_nas_signalling_establishment_request > (itti_msg); std::shared_ptr<itti_nas_signalling_establishment_request>(itti_msg);
int ret = itti_inst->send_msg(i); int ret = itti_inst->send_msg(i);
if (0 != ret) { if (0 != ret) {
Logger::amf_n2().error( Logger::amf_n2().error(
...@@ -469,56 +459,59 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) { ...@@ -469,56 +459,59 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_ul_nas_transport &ul_nas_transport) { void amf_n2::handle_itti_message(itti_ul_nas_transport& ul_nas_transport) {
unsigned long amf_ue_ngap_id = ul_nas_transport.ulNas->getAmfUeNgapId(); unsigned long amf_ue_ngap_id = ul_nas_transport.ulNas->getAmfUeNgapId();
uint32_t ran_ue_ngap_id = ul_nas_transport.ulNas->getRanUeNgapId(); uint32_t ran_ue_ngap_id = ul_nas_transport.ulNas->getRanUeNgapId();
std::shared_ptr < gnb_context > gc; std::shared_ptr<gnb_context> gc;
if (!is_assoc_id_2_gnb_context(ul_nas_transport.assoc_id)) { if (!is_assoc_id_2_gnb_context(ul_nas_transport.assoc_id)) {
Logger::amf_n2().error("gNB with assoc_id(%d) is illegal", Logger::amf_n2().error(
ul_nas_transport.assoc_id); "gNB with assoc_id(%d) is illegal", ul_nas_transport.assoc_id);
return; return;
} }
gc = assoc_id_2_gnb_context(ul_nas_transport.assoc_id); gc = assoc_id_2_gnb_context(ul_nas_transport.assoc_id);
std::shared_ptr < ue_ngap_context > unc; std::shared_ptr<ue_ngap_context> unc;
if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) { if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) {
Logger::amf_n2().error( Logger::amf_n2().error(
"UE with ran_ue_ngap_id(0x%x) is not attached to gnb with assoc_id (%d)", "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); ran_ue_ngap_id, ul_nas_transport.assoc_id);
return; return;
} }
if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) { 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)", Logger::amf_n2().error(
ran_ue_ngap_id); "No UE NGAP context with ran_ue_ngap_id (%d)", ran_ue_ngap_id);
return; return;
} }
unc = ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id); unc = ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id);
if (unc.get()->amf_ue_ngap_id != amf_ue_ngap_id) { if (unc.get()->amf_ue_ngap_id != amf_ue_ngap_id) {
Logger::amf_n2().error( 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)", "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); amf_ue_ngap_id, unc.get()->amf_ue_ngap_id);
} }
if (unc.get()->ng_ue_state != NGAP_UE_CONNECTED) { if (unc.get()->ng_ue_state != NGAP_UE_CONNECTED) {
Logger::amf_n2().error( Logger::amf_n2().error(
"Received NGAP UPLINK_NAS_TRANSPORT while UE in state != NGAP_UE_CONNECTED"); "Received NGAP UPLINK_NAS_TRANSPORT while UE in state != "
//return; "NGAP_UE_CONNECTED");
// return;
} }
itti_uplink_nas_data_ind *itti_msg = new itti_uplink_nas_data_ind( itti_uplink_nas_data_ind* itti_msg =
TASK_AMF_N2, TASK_AMF_N1); new itti_uplink_nas_data_ind(TASK_AMF_N2, TASK_AMF_N1);
itti_msg->is_nas_signalling_estab_req = false; itti_msg->is_nas_signalling_estab_req = false;
itti_msg->amf_ue_ngap_id = amf_ue_ngap_id; itti_msg->amf_ue_ngap_id = amf_ue_ngap_id;
itti_msg->ran_ue_ngap_id = ran_ue_ngap_id; itti_msg->ran_ue_ngap_id = ran_ue_ngap_id;
itti_msg->is_guti_valid = false; itti_msg->is_guti_valid = false;
uint8_t *nas_buf = NULL; uint8_t* nas_buf = NULL;
size_t nas_len = 0; size_t nas_len = 0;
if (ul_nas_transport.ulNas->getNasPdu(nas_buf, nas_len)) { if (ul_nas_transport.ulNas->getNasPdu(nas_buf, nas_len)) {
itti_msg->nas_msg = blk2bstr(nas_buf, nas_len); itti_msg->nas_msg = blk2bstr(nas_buf, nas_len);
} else { } else {
Logger::amf_n2().error("Missing IE NAS-PDU"); Logger::amf_n2().error("Missing IE NAS-PDU");
return; return;
} }
//UserLocation // UserLocation
NrCgi_t cgi = { }; NrCgi_t cgi = {};
Tai_t tai = { }; Tai_t tai = {};
if (ul_nas_transport.ulNas->getUserLocationInfoNR(cgi, tai)) { if (ul_nas_transport.ulNas->getUserLocationInfoNR(cgi, tai)) {
itti_msg->mcc = cgi.mcc; itti_msg->mcc = cgi.mcc;
itti_msg->mnc = cgi.mnc; itti_msg->mnc = cgi.mnc;
...@@ -526,143 +519,147 @@ void amf_n2::handle_itti_message(itti_ul_nas_transport &ul_nas_transport) { ...@@ -526,143 +519,147 @@ void amf_n2::handle_itti_message(itti_ul_nas_transport &ul_nas_transport) {
Logger::amf_n2().debug("Missing IE UserLocationInformationNR"); Logger::amf_n2().debug("Missing IE UserLocationInformationNR");
} }
std::shared_ptr < itti_uplink_nas_data_ind > i = std::shared_ptr std::shared_ptr<itti_uplink_nas_data_ind> i =
< itti_uplink_nas_data_ind > (itti_msg); std::shared_ptr<itti_uplink_nas_data_ind>(itti_msg);
int ret = itti_inst->send_msg(i); int ret = itti_inst->send_msg(i);
if (0 != ret) { if (0 != ret) {
Logger::amf_n2().error("Could not send ITTI message %s to task TASK_AMF_N1", Logger::amf_n2().error(
i->get_msg_name()); "Could not send ITTI message %s to task TASK_AMF_N1",
i->get_msg_name());
} }
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_dl_nas_transport &dl_nas_transport) { void amf_n2::handle_itti_message(itti_dl_nas_transport& dl_nas_transport) {
std::shared_ptr < ue_ngap_context > unc; std::shared_ptr<ue_ngap_context> unc;
unc = ran_ue_id_2_ue_ngap_context(dl_nas_transport.ran_ue_ngap_id); unc = ran_ue_id_2_ue_ngap_context(dl_nas_transport.ran_ue_ngap_id);
if (unc.get() == nullptr) { if (unc.get() == nullptr) {
Logger::amf_n2().error("Illegal UE with ran_ue_ngap_id (0x%x)", Logger::amf_n2().error(
dl_nas_transport.ran_ue_ngap_id); "Illegal UE with ran_ue_ngap_id (0x%x)",
dl_nas_transport.ran_ue_ngap_id);
return; return;
} }
std::shared_ptr < gnb_context > gc; std::shared_ptr<gnb_context> gc;
gc = assoc_id_2_gnb_context(unc.get()->gnb_assoc_id); gc = assoc_id_2_gnb_context(unc.get()->gnb_assoc_id);
if (gc.get() == nullptr) { if (gc.get() == nullptr) {
Logger::amf_n2().error("Illegal gNB with assoc id (0x%x)", Logger::amf_n2().error(
unc.get()->gnb_assoc_id); "Illegal gNB with assoc id (0x%x)", unc.get()->gnb_assoc_id);
return; return;
} }
unc.get()->amf_ue_ngap_id = dl_nas_transport.amf_ue_ngap_id; unc.get()->amf_ue_ngap_id = dl_nas_transport.amf_ue_ngap_id;
unc.get()->ng_ue_state = NGAP_UE_CONNECTED; unc.get()->ng_ue_state = NGAP_UE_CONNECTED;
DownLinkNasTransportMsg *ngap_msg = new DownLinkNasTransportMsg(); DownLinkNasTransportMsg* ngap_msg = new DownLinkNasTransportMsg();
ngap_msg->setMessageType(); ngap_msg->setMessageType();
ngap_msg->setAmfUeNgapId(dl_nas_transport.amf_ue_ngap_id); ngap_msg->setAmfUeNgapId(dl_nas_transport.amf_ue_ngap_id);
ngap_msg->setRanUeNgapId(dl_nas_transport.ran_ue_ngap_id); ngap_msg->setRanUeNgapId(dl_nas_transport.ran_ue_ngap_id);
ngap_msg->setNasPdu((uint8_t*) bdata(dl_nas_transport.nas), ngap_msg->setNasPdu(
blength(dl_nas_transport.nas)); (uint8_t*) bdata(dl_nas_transport.nas), blength(dl_nas_transport.nas));
uint8_t buffer[1024]; uint8_t buffer[1024];
int encoded_size = ngap_msg->encode2buffer(buffer, 1024); int encoded_size = ngap_msg->encode2buffer(buffer, 1024);
bstring b = blk2bstr(buffer, encoded_size); bstring b = blk2bstr(buffer, encoded_size);
sctp_s_38412.sctp_send_msg(gc.get()->sctp_assoc_id, sctp_s_38412.sctp_send_msg(
unc.get()->sctp_stream_send, &b); gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_initial_context_setup_request &itti_msg) { void amf_n2::handle_itti_message(itti_initial_context_setup_request& itti_msg) {
std::shared_ptr < ue_ngap_context > unc; std::shared_ptr<ue_ngap_context> unc;
unc = ran_ue_id_2_ue_ngap_context(itti_msg.ran_ue_ngap_id); unc = ran_ue_id_2_ue_ngap_context(itti_msg.ran_ue_ngap_id);
if (unc.get() == nullptr) { if (unc.get() == nullptr) {
Logger::amf_n2().error("Illegal UE with ran_ue_ngap_id (0x%x)", Logger::amf_n2().error(
itti_msg.ran_ue_ngap_id); "Illegal UE with ran_ue_ngap_id (0x%x)", itti_msg.ran_ue_ngap_id);
return; return;
} }
std::shared_ptr < gnb_context > gc; std::shared_ptr<gnb_context> gc;
gc = assoc_id_2_gnb_context(unc.get()->gnb_assoc_id); gc = assoc_id_2_gnb_context(unc.get()->gnb_assoc_id);
if (gc.get() == nullptr) { if (gc.get() == nullptr) {
Logger::amf_n2().error("Illegal gNB with assoc id (0x%x)", Logger::amf_n2().error(
unc.get()->gnb_assoc_id); "Illegal gNB with assoc id (0x%x)", unc.get()->gnb_assoc_id);
return; return;
} }
InitialContextSetupRequestMsg *msg = new InitialContextSetupRequestMsg(); InitialContextSetupRequestMsg* msg = new InitialContextSetupRequestMsg();
msg->setMessageType(); msg->setMessageType();
msg->setAmfUeNgapId(itti_msg.amf_ue_ngap_id); msg->setAmfUeNgapId(itti_msg.amf_ue_ngap_id);
msg->setRanUeNgapId(itti_msg.ran_ue_ngap_id); msg->setRanUeNgapId(itti_msg.ran_ue_ngap_id);
Guami_t guami; Guami_t guami;
guami.mcc = amf_cfg.guami.mcc; guami.mcc = amf_cfg.guami.mcc;
guami.mnc = amf_cfg.guami.mnc; guami.mnc = amf_cfg.guami.mnc;
guami.regionID = amf_cfg.guami.regionID; guami.regionID = amf_cfg.guami.regionID;
guami.AmfSetID = amf_cfg.guami.AmfSetID; guami.AmfSetID = amf_cfg.guami.AmfSetID;
guami.AmfPointer = amf_cfg.guami.AmfPointer; guami.AmfPointer = amf_cfg.guami.AmfPointer;
msg->setGuami(guami); msg->setGuami(guami);
msg->setUESecurityCapability(0xe000, 0xe000, 0xe000, 0xe000); //TODO: remove hardcoded value msg->setUESecurityCapability(
0xe000, 0xe000, 0xe000, 0xe000); // TODO: remove hardcoded value
msg->setSecurityKey((uint8_t*) bdata(itti_msg.kgnb)); msg->setSecurityKey((uint8_t*) bdata(itti_msg.kgnb));
msg->setNasPdu((uint8_t*) bdata(itti_msg.nas), blength(itti_msg.nas)); msg->setNasPdu((uint8_t*) bdata(itti_msg.nas), blength(itti_msg.nas));
std::vector<S_Nssai> list; std::vector<S_Nssai> list;
S_Nssai item; S_Nssai item;
item.sst = "01"; item.sst = "01";
item.sd = "None"; item.sd = "None";
list.push_back(item); list.push_back(item);
msg->setAllowedNssai(list); msg->setAllowedNssai(list);
bdestroy(itti_msg.nas); bdestroy(itti_msg.nas);
bdestroy(itti_msg.kgnb); bdestroy(itti_msg.kgnb);
if (itti_msg.is_sr) { if (itti_msg.is_sr) {
bstring ueCapability = gc.get()->ue_radio_cap_ind; bstring ueCapability = gc.get()->ue_radio_cap_ind;
uint8_t *uecap = (uint8_t*) calloc(1, blength(ueCapability) + 1); uint8_t* uecap = (uint8_t*) calloc(1, blength(ueCapability) + 1);
memcpy(uecap, (uint8_t*) bdata(ueCapability), blength(ueCapability)); memcpy(uecap, (uint8_t*) bdata(ueCapability), blength(ueCapability));
uecap[blength(ueCapability)] = '\0'; uecap[blength(ueCapability)] = '\0';
msg->setUERadioCapability(uecap, (size_t)blength(ueCapability)); msg->setUERadioCapability(uecap, (size_t) blength(ueCapability));
free(uecap); free(uecap);
Logger::amf_n2().debug("Encoding parameters for Service Request"); Logger::amf_n2().debug("Encoding parameters for Service Request");
if (itti_msg.is_pdu_exist) { if (itti_msg.is_pdu_exist) {
std::vector < PDUSessionResourceSetupRequestItem_t > list; std::vector<PDUSessionResourceSetupRequestItem_t> list;
PDUSessionResourceSetupRequestItem_t item; PDUSessionResourceSetupRequestItem_t item;
item.pduSessionId = itti_msg.pdu_session_id; item.pduSessionId = itti_msg.pdu_session_id;
item.s_nssai.sst = "01"; item.s_nssai.sst = "01";
item.s_nssai.sd = ""; item.s_nssai.sd = "";
item.pduSessionNAS_PDU = NULL; item.pduSessionNAS_PDU = NULL;
if (itti_msg.isn2sm_avaliable) { if (itti_msg.isn2sm_avaliable) {
bstring n2sm = itti_msg.n2sm; bstring n2sm = itti_msg.n2sm;
if (blength(itti_msg.n2sm) != 0) { if (blength(itti_msg.n2sm) != 0) {
item.pduSessionResourceSetupRequestTransfer.buf = (uint8_t*) bdata( item.pduSessionResourceSetupRequestTransfer.buf =
itti_msg.n2sm); (uint8_t*) bdata(itti_msg.n2sm);
item.pduSessionResourceSetupRequestTransfer.size = blength( item.pduSessionResourceSetupRequestTransfer.size =
itti_msg.n2sm); blength(itti_msg.n2sm);
} else { } else {
Logger::amf_n2().error("n2sm empty!"); Logger::amf_n2().error("n2sm empty!");
} }
} }
list.push_back(item); list.push_back(item);
msg->setPduSessionResourceSetupRequestList(list); msg->setPduSessionResourceSetupRequestList(list);
msg->setUEAggregateMaxBitRate(0x08a7d8c0, 0x20989680); //TODO: remove hardcoded value msg->setUEAggregateMaxBitRate(
0x08a7d8c0, 0x20989680); // TODO: remove hardcoded value
} }
} }
uint8_t buffer[10000]; uint8_t buffer[10000];
int encoded_size = msg->encode2buffer(buffer, 10000); int encoded_size = msg->encode2buffer(buffer, 10000);
bstring b = blk2bstr(buffer, encoded_size); bstring b = blk2bstr(buffer, encoded_size);
sctp_s_38412.sctp_send_msg(gc.get()->sctp_assoc_id, sctp_s_38412.sctp_send_msg(
unc.get()->sctp_stream_send, &b); gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2::handle_itti_message( void amf_n2::handle_itti_message(
itti_pdu_session_resource_setup_request &itti_msg) { itti_pdu_session_resource_setup_request& itti_msg) {
std::shared_ptr < ue_ngap_context > unc; std::shared_ptr<ue_ngap_context> unc;
unc = ran_ue_id_2_ue_ngap_context(itti_msg.ran_ue_ngap_id); unc = ran_ue_id_2_ue_ngap_context(itti_msg.ran_ue_ngap_id);
if (unc.get() == nullptr) { if (unc.get() == nullptr) {
Logger::amf_n2().error("Illegal UE with ran_ue_ngap_id (0x%x)", Logger::amf_n2().error(
itti_msg.ran_ue_ngap_id); "Illegal UE with ran_ue_ngap_id (0x%x)", itti_msg.ran_ue_ngap_id);
return; return;
} }
std::shared_ptr < gnb_context > gc; std::shared_ptr<gnb_context> gc;
gc = assoc_id_2_gnb_context(unc.get()->gnb_assoc_id); gc = assoc_id_2_gnb_context(unc.get()->gnb_assoc_id);
if (gc.get() == nullptr) { if (gc.get() == nullptr) {
Logger::amf_n2().error("Illegal gNB with assoc id (0x%x)", Logger::amf_n2().error(
unc.get()->gnb_assoc_id); "Illegal gNB with assoc id (0x%x)", unc.get()->gnb_assoc_id);
return; return;
} }
PduSessionResourceSetupRequestMsg *psrsr = PduSessionResourceSetupRequestMsg* psrsr =
new PduSessionResourceSetupRequestMsg(); new PduSessionResourceSetupRequestMsg();
psrsr->setMessageType(); psrsr->setMessageType();
psrsr->setAmfUeNgapId(itti_msg.amf_ue_ngap_id); psrsr->setAmfUeNgapId(itti_msg.amf_ue_ngap_id);
...@@ -671,22 +668,23 @@ void amf_n2::handle_itti_message( ...@@ -671,22 +668,23 @@ void amf_n2::handle_itti_message(
std::vector<PDUSessionResourceSetupRequestItem_t> list; std::vector<PDUSessionResourceSetupRequestItem_t> list;
PDUSessionResourceSetupRequestItem_t item; PDUSessionResourceSetupRequestItem_t item;
item.pduSessionId = itti_msg.pdu_session_id; item.pduSessionId = itti_msg.pdu_session_id;
uint8_t *nas_pdu = (uint8_t*) calloc(1, blength(itti_msg.nas) + 1); uint8_t* nas_pdu = (uint8_t*) calloc(1, blength(itti_msg.nas) + 1);
memcpy(nas_pdu, (uint8_t*) bdata(itti_msg.nas), blength(itti_msg.nas)); memcpy(nas_pdu, (uint8_t*) bdata(itti_msg.nas), blength(itti_msg.nas));
nas_pdu[blength(itti_msg.nas)] = '\0'; nas_pdu[blength(itti_msg.nas)] = '\0';
item.pduSessionNAS_PDU = nas_pdu; item.pduSessionNAS_PDU = nas_pdu;
item.sizeofpduSessionNAS_PDU = blength(itti_msg.nas); item.sizeofpduSessionNAS_PDU = blength(itti_msg.nas);
item.s_nssai.sst = "01"; //TODO: get from N1N2msgTranferMsg item.s_nssai.sst = "01"; // TODO: get from N1N2msgTranferMsg
item.s_nssai.sd = ""; //TODO: get from N1N2msgTranferMsg item.s_nssai.sd = ""; // TODO: get from N1N2msgTranferMsg
//Get NSSAI from PDU Session Context // Get NSSAI from PDU Session Context
std::shared_ptr < nas_context > nc; std::shared_ptr<nas_context> nc;
if (amf_n1_inst->is_amf_ue_id_2_nas_context(itti_msg.amf_ue_ngap_id)) if (amf_n1_inst->is_amf_ue_id_2_nas_context(itti_msg.amf_ue_ngap_id))
nc = amf_n1_inst->amf_ue_id_2_nas_context(itti_msg.amf_ue_ngap_id); nc = amf_n1_inst->amf_ue_id_2_nas_context(itti_msg.amf_ue_ngap_id);
else { else {
Logger::amf_n2().warn("No existed nas_context with amf_ue_ngap_id(0x%x)", Logger::amf_n2().warn(
itti_msg.amf_ue_ngap_id); "No existed nas_context with amf_ue_ngap_id(0x%x)",
//TODO: itti_msg.amf_ue_ngap_id);
// TODO:
} }
string supi = "imsi-" + nc.get()->imsi; string supi = "imsi-" + nc.get()->imsi;
Logger::amf_n2().debug("SUPI (%s)", supi.c_str()); Logger::amf_n2().debug("SUPI (%s)", supi.c_str());
...@@ -694,63 +692,61 @@ void amf_n2::handle_itti_message( ...@@ -694,63 +692,61 @@ void amf_n2::handle_itti_message(
if (amf_n11_inst->is_supi_to_pdu_ctx(supi)) { if (amf_n11_inst->is_supi_to_pdu_ctx(supi)) {
psc = amf_n11_inst->supi_to_pdu_ctx(supi); psc = amf_n11_inst->supi_to_pdu_ctx(supi);
} else { } else {
Logger::amf_n2().warn("Cannot get pdu_session_context with SUPI (%s)", Logger::amf_n2().warn(
supi.c_str()); "Cannot get pdu_session_context with SUPI (%s)", supi.c_str());
} }
//item.s_nssai.sst = std::to_string(psc.get()->snssai.sST); // item.s_nssai.sst = std::to_string(psc.get()->snssai.sST);
//item.s_nssai.sd = psc.get()->snssai.sD; // item.s_nssai.sd = psc.get()->snssai.sD;
item.pduSessionResourceSetupRequestTransfer.buf = (uint8_t*) bdata( item.pduSessionResourceSetupRequestTransfer.buf =
itti_msg.n2sm); (uint8_t*) bdata(itti_msg.n2sm);
item.pduSessionResourceSetupRequestTransfer.size = blength(itti_msg.n2sm); item.pduSessionResourceSetupRequestTransfer.size = blength(itti_msg.n2sm);
list.push_back(item); list.push_back(item);
psrsr->setPduSessionResourceSetupRequestList(list); psrsr->setPduSessionResourceSetupRequestList(list);
size_t buffer_size = BUFFER_SIZE_512; size_t buffer_size = BUFFER_SIZE_512;
char *buffer = (char*) calloc(1, buffer_size); char* buffer = (char*) calloc(1, buffer_size);
int encoded_size = 0; int encoded_size = 0;
psrsr->encode2buffer_new(buffer, encoded_size); psrsr->encode2buffer_new(buffer, encoded_size);
#if DEBUG_IS_ON #if DEBUG_IS_ON
Logger::amf_n2().debug("N2 SM buffer data: "); Logger::amf_n2().debug("N2 SM buffer data: ");
for (int i = 0; i < encoded_size; i++) for (int i = 0; i < encoded_size; i++) printf("%02x ", (char) buffer[i]);
printf("%02x ", (char) buffer[i]);
#endif #endif
Logger::amf_n2().debug(" (%d bytes) \n", encoded_size); Logger::amf_n2().debug(" (%d bytes) \n", encoded_size);
bstring b = blk2bstr(buffer, encoded_size); bstring b = blk2bstr(buffer, encoded_size);
sctp_s_38412.sctp_send_msg(gc.get()->sctp_assoc_id, sctp_s_38412.sctp_send_msg(
unc.get()->sctp_stream_send, &b); gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b);
//free memory // free memory
free_wrapper((void**) &buffer); free_wrapper((void**) &buffer);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2::handle_itti_message( void amf_n2::handle_itti_message(
itti_pdu_session_resource_release_command &itti_msg) { itti_pdu_session_resource_release_command& itti_msg) {
std::shared_ptr<ue_ngap_context> unc;
std::shared_ptr < ue_ngap_context > unc;
unc = ran_ue_id_2_ue_ngap_context(itti_msg.ran_ue_ngap_id); unc = ran_ue_id_2_ue_ngap_context(itti_msg.ran_ue_ngap_id);
if (unc.get() == nullptr) { if (unc.get() == nullptr) {
Logger::amf_n2().error("Illegal UE with ran_ue_ngap_id (0x%x)", Logger::amf_n2().error(
itti_msg.ran_ue_ngap_id); "Illegal UE with ran_ue_ngap_id (0x%x)", itti_msg.ran_ue_ngap_id);
return; return;
} }
std::shared_ptr < gnb_context > gc; std::shared_ptr<gnb_context> gc;
gc = assoc_id_2_gnb_context(unc.get()->gnb_assoc_id); gc = assoc_id_2_gnb_context(unc.get()->gnb_assoc_id);
if (gc.get() == nullptr) { if (gc.get() == nullptr) {
Logger::amf_n2().error("Illegal gNB with assoc id (0x%x)", Logger::amf_n2().error(
unc.get()->gnb_assoc_id); "Illegal gNB with assoc id (0x%x)", unc.get()->gnb_assoc_id);
return; return;
} }
PduSessionResourceReleaseCommandMsg *release_cmd_msg = PduSessionResourceReleaseCommandMsg* release_cmd_msg =
new PduSessionResourceReleaseCommandMsg(); new PduSessionResourceReleaseCommandMsg();
release_cmd_msg->setMessageType(); release_cmd_msg->setMessageType();
release_cmd_msg->setAmfUeNgapId(itti_msg.amf_ue_ngap_id); release_cmd_msg->setAmfUeNgapId(itti_msg.amf_ue_ngap_id);
release_cmd_msg->setRanUeNgapId(itti_msg.ran_ue_ngap_id); release_cmd_msg->setRanUeNgapId(itti_msg.ran_ue_ngap_id);
uint8_t *nas_pdu = (uint8_t*) calloc(1, blength(itti_msg.nas) + 1); uint8_t* nas_pdu = (uint8_t*) calloc(1, blength(itti_msg.nas) + 1);
memcpy(nas_pdu, (uint8_t*) bdata(itti_msg.nas), blength(itti_msg.nas)); memcpy(nas_pdu, (uint8_t*) bdata(itti_msg.nas), blength(itti_msg.nas));
nas_pdu[blength(itti_msg.nas)] = '\0'; nas_pdu[blength(itti_msg.nas)] = '\0';
release_cmd_msg->setNasPdu(nas_pdu, blength(itti_msg.nas)); release_cmd_msg->setNasPdu(nas_pdu, blength(itti_msg.nas));
...@@ -759,72 +755,70 @@ void amf_n2::handle_itti_message( ...@@ -759,72 +755,70 @@ void amf_n2::handle_itti_message(
PDUSessionResourceToReleaseItem_t item; PDUSessionResourceToReleaseItem_t item;
item.pduSessionId = itti_msg.pdu_session_id; item.pduSessionId = itti_msg.pdu_session_id;
item.pduSessionResourceReleaseCommandTransfer.buf = (uint8_t*) bdata( item.pduSessionResourceReleaseCommandTransfer.buf =
itti_msg.n2sm); (uint8_t*) bdata(itti_msg.n2sm);
item.pduSessionResourceReleaseCommandTransfer.size = blength(itti_msg.n2sm); item.pduSessionResourceReleaseCommandTransfer.size = blength(itti_msg.n2sm);
list.push_back(item); list.push_back(item);
release_cmd_msg->setPduSessionResourceToReleaseList(list); release_cmd_msg->setPduSessionResourceToReleaseList(list);
size_t buffer_size = BUFFER_SIZE_512; size_t buffer_size = BUFFER_SIZE_512;
char *buffer = (char*) calloc(1, buffer_size); char* buffer = (char*) calloc(1, buffer_size);
int encoded_size = 0; int encoded_size = 0;
release_cmd_msg->encode2buffer_new(buffer, encoded_size); release_cmd_msg->encode2buffer_new(buffer, encoded_size);
#if DEBUG_IS_ON #if DEBUG_IS_ON
Logger::amf_n2().debug("N2 SM buffer data: "); Logger::amf_n2().debug("N2 SM buffer data: ");
for (int i = 0; i < encoded_size; i++) for (int i = 0; i < encoded_size; i++) printf("%02x ", (char) buffer[i]);
printf("%02x ", (char) buffer[i]);
#endif #endif
Logger::amf_n2().debug(" (%d bytes) \n", encoded_size); Logger::amf_n2().debug(" (%d bytes) \n", encoded_size);
bstring b = blk2bstr(buffer, encoded_size); bstring b = blk2bstr(buffer, encoded_size);
sctp_s_38412.sctp_send_msg(gc.get()->sctp_assoc_id, sctp_s_38412.sctp_send_msg(
unc.get()->sctp_stream_send, &b); gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b);
//free memory // free memory
free_wrapper((void**) &nas_pdu); free_wrapper((void**) &nas_pdu);
free_wrapper((void**) &buffer); free_wrapper((void**) &buffer);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_ue_context_release_request &itti_msg) { void amf_n2::handle_itti_message(itti_ue_context_release_request& itti_msg) {
Logger::amf_n2().debug("Handling UE context release request ..."); Logger::amf_n2().debug("Handling UE context release request ...");
unsigned long amf_ue_ngap_id = itti_msg.ueCtxRel->getAmfUeNgapId(); unsigned long amf_ue_ngap_id = itti_msg.ueCtxRel->getAmfUeNgapId();
uint32_t ran_ue_ngap_id = itti_msg.ueCtxRel->getRanUeNgapId(); uint32_t ran_ue_ngap_id = itti_msg.ueCtxRel->getRanUeNgapId();
e_Ngap_CauseRadioNetwork cause; e_Ngap_CauseRadioNetwork cause;
itti_msg.ueCtxRel->getCauseRadioNetwork(cause); itti_msg.ueCtxRel->getCauseRadioNetwork(cause);
UEContextReleaseCommandMsg *ueCtxRelCmd = new UEContextReleaseCommandMsg(); UEContextReleaseCommandMsg* ueCtxRelCmd = new UEContextReleaseCommandMsg();
ueCtxRelCmd->setMessageType(); ueCtxRelCmd->setMessageType();
ueCtxRelCmd->setUeNgapIdPair(amf_ue_ngap_id, ran_ue_ngap_id); ueCtxRelCmd->setUeNgapIdPair(amf_ue_ngap_id, ran_ue_ngap_id);
ueCtxRelCmd->setCauseRadioNetwork(cause); ueCtxRelCmd->setCauseRadioNetwork(cause);
uint8_t buffer[BUFFER_SIZE_512]; uint8_t buffer[BUFFER_SIZE_512];
int encoded_size = ueCtxRelCmd->encode2buffer(buffer, BUFFER_SIZE_512); int encoded_size = ueCtxRelCmd->encode2buffer(buffer, BUFFER_SIZE_512);
bstring b = blk2bstr(buffer, encoded_size); bstring b = blk2bstr(buffer, encoded_size);
sctp_s_38412.sctp_send_msg(itti_msg.assoc_id, itti_msg.stream, &b); sctp_s_38412.sctp_send_msg(itti_msg.assoc_id, itti_msg.stream, &b);
} }
void amf_n2::handle_itti_message(itti_ue_context_release_command &itti_msg) { void amf_n2::handle_itti_message(itti_ue_context_release_command& itti_msg) {
Logger::amf_n2().debug("handling ue context release command ..."); Logger::amf_n2().debug("handling ue context release command ...");
std::shared_ptr < ue_ngap_context > unc; std::shared_ptr<ue_ngap_context> unc;
unc = ran_ue_id_2_ue_ngap_context(itti_msg.ran_ue_ngap_id); unc = ran_ue_id_2_ue_ngap_context(itti_msg.ran_ue_ngap_id);
if (unc.get() == nullptr) { if (unc.get() == nullptr) {
Logger::amf_n2().error("Illegal ue with ran_ue_ngap_id(0x%x)", Logger::amf_n2().error(
itti_msg.ran_ue_ngap_id); "Illegal ue with ran_ue_ngap_id(0x%x)", itti_msg.ran_ue_ngap_id);
return; return;
} }
std::shared_ptr < gnb_context > gc; std::shared_ptr<gnb_context> gc;
gc = assoc_id_2_gnb_context(unc.get()->gnb_assoc_id); gc = assoc_id_2_gnb_context(unc.get()->gnb_assoc_id);
if (gc.get() == nullptr) { if (gc.get() == nullptr) {
Logger::amf_n2().error("Illegal gnb with assoc id(0x%x)", Logger::amf_n2().error(
unc.get()->gnb_assoc_id); "Illegal gnb with assoc id(0x%x)", unc.get()->gnb_assoc_id);
return; return;
} }
UEContextReleaseCommandMsg *ueCtxRelCmd = new UEContextReleaseCommandMsg(); UEContextReleaseCommandMsg* ueCtxRelCmd = new UEContextReleaseCommandMsg();
ueCtxRelCmd->setMessageType(); ueCtxRelCmd->setMessageType();
ueCtxRelCmd->setUeNgapIdPair(itti_msg.amf_ue_ngap_id, ueCtxRelCmd->setUeNgapIdPair(
itti_msg.ran_ue_ngap_id); itti_msg.amf_ue_ngap_id, itti_msg.ran_ue_ngap_id);
if (itti_msg.cause.getChoiceOfCause() == Ngap_Cause_PR_nas) { if (itti_msg.cause.getChoiceOfCause() == Ngap_Cause_PR_nas) {
ueCtxRelCmd->setCauseNas((e_Ngap_CauseNas) itti_msg.cause.getValue()); ueCtxRelCmd->setCauseNas((e_Ngap_CauseNas) itti_msg.cause.getValue());
} }
...@@ -836,17 +830,17 @@ void amf_n2::handle_itti_message(itti_ue_context_release_command &itti_msg) { ...@@ -836,17 +830,17 @@ void amf_n2::handle_itti_message(itti_ue_context_release_command &itti_msg) {
int encoded_size = ueCtxRelCmd->encode2buffer(buffer, 200); int encoded_size = ueCtxRelCmd->encode2buffer(buffer, 200);
delete ueCtxRelCmd; delete ueCtxRelCmd;
bstring b = blk2bstr(buffer, encoded_size); bstring b = blk2bstr(buffer, encoded_size);
sctp_s_38412.sctp_send_msg(gc.get()->sctp_assoc_id, sctp_s_38412.sctp_send_msg(
unc.get()->sctp_stream_send, &b); gc.get()->sctp_assoc_id, unc.get()->sctp_stream_send, &b);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2::handle_itti_message( void amf_n2::handle_itti_message(
itti_ue_radio_capability_indication &itti_msg) { itti_ue_radio_capability_indication& itti_msg) {
std::shared_ptr < gnb_context > gc; std::shared_ptr<gnb_context> gc;
if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) { if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) {
Logger::amf_n2().error("No existed gNB context with assoc_id (%d)", Logger::amf_n2().error(
itti_msg.assoc_id); "No existed gNB context with assoc_id (%d)", itti_msg.assoc_id);
return; return;
} }
gc = assoc_id_2_gnb_context(itti_msg.assoc_id); gc = assoc_id_2_gnb_context(itti_msg.assoc_id);
...@@ -854,7 +848,7 @@ void amf_n2::handle_itti_message( ...@@ -854,7 +848,7 @@ void amf_n2::handle_itti_message(
itti_msg.ueRadioCap->getAmfUeNgapId(amf_ue_ngap_id); itti_msg.ueRadioCap->getAmfUeNgapId(amf_ue_ngap_id);
uint32_t ran_ue_ngap_id; uint32_t ran_ue_ngap_id;
itti_msg.ueRadioCap->getRanUeNgapId(ran_ue_ngap_id); itti_msg.ueRadioCap->getRanUeNgapId(ran_ue_ngap_id);
uint8_t *ue_radio_cap; uint8_t* ue_radio_cap;
size_t size; size_t size;
if (!itti_msg.ueRadioCap->getUERadioCapability(ue_radio_cap, size)) { if (!itti_msg.ueRadioCap->getUERadioCapability(ue_radio_cap, size)) {
Logger::amf_n2().warn("No IE UERadioCapability"); Logger::amf_n2().warn("No IE UERadioCapability");
...@@ -863,88 +857,104 @@ void amf_n2::handle_itti_message( ...@@ -863,88 +857,104 @@ void amf_n2::handle_itti_message(
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_handover_required &itti_msg) void amf_n2::handle_itti_message(itti_handover_required& itti_msg) {
{ ncc++;
unsigned long amf_ue_ngap_id = itti_msg.handvoerRequ->getAmfUeNgapId(); unsigned long amf_ue_ngap_id = itti_msg.handvoerRequ->getAmfUeNgapId();
uint32_t ran_ue_ngap_id = itti_msg.handvoerRequ->getRanUeNgapId(); uint32_t ran_ue_ngap_id = itti_msg.handvoerRequ->getRanUeNgapId();
ran_id_Global = ran_ue_ngap_id; ran_id_Global = ran_ue_ngap_id;
source_assoc_id = itti_msg.assoc_id; source_assoc_id = itti_msg.assoc_id;
std::shared_ptr<gnb_context> gc; std::shared_ptr<gnb_context> gc;
if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) {
{ Logger::amf_n2().error(
Logger::amf_n2().error("gnb with assoc_id(%d) is illegal", itti_msg.assoc_id); "gnb with assoc_id(%d) is illegal", itti_msg.assoc_id);
return; return;
} }
gc = assoc_id_2_gnb_context(itti_msg.assoc_id); gc = assoc_id_2_gnb_context(itti_msg.assoc_id);
std::shared_ptr<ue_ngap_context> unc; std::shared_ptr<ue_ngap_context> unc;
if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) {
{ Logger::amf_n2().error(
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, itti_msg.assoc_id); "UE with ran_ue_ngap_id(0x%x) is not attached to gnb with assoc_id(%d)",
ran_ue_ngap_id, itti_msg.assoc_id);
return; return;
} }
if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) {
{ Logger::amf_n2().error(
Logger::amf_n2().error("no ue ngap context with ran_ue_ngap_id(%d)", ran_ue_ngap_id); "no ue ngap context with ran_ue_ngap_id(%d)", ran_ue_ngap_id);
return; return;
} }
unc = ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id); unc = ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id);
if (unc.get()->amf_ue_ngap_id != amf_ue_ngap_id) if (unc.get()->amf_ue_ngap_id != amf_ue_ngap_id) {
{ Logger::amf_n2().error(
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); "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 (itti_msg.handvoerRequ->getHandoverType() != Ngap_HandoverType_intra5gs) if (itti_msg.handvoerRequ->getHandoverType() != Ngap_HandoverType_intra5gs) {
{ Logger::amf_n2().error(
Logger::amf_n2().error("Received Handover Required message,but handover type is not Ngap_HandoverType_intra5gs"); "Received Handover Required message,but handover type is not "
"Ngap_HandoverType_intra5gs");
return; return;
} }
if (itti_msg.handvoerRequ->getChoiceOfCause() != Ngap_Cause_PR_radioNetwork) if (itti_msg.handvoerRequ->getChoiceOfCause() != Ngap_Cause_PR_radioNetwork) {
{ Logger::amf_n2().error(
Logger::amf_n2().error("Received Handover Required message,but Cause Of Choice is wrong"); "Received Handover Required message,but Cause Of Choice is wrong");
return; return;
} }
if (itti_msg.handvoerRequ->getCauseValue() != Ngap_CauseRadioNetwork_handover_desirable_for_radio_reason) if (itti_msg.handvoerRequ->getCauseValue() !=
{ Ngap_CauseRadioNetwork_handover_desirable_for_radio_reason) {
Logger::amf_n2().error("Received Handover Required message,but Value of Cause is wrong"); Logger::amf_n2().error(
"Received Handover Required message,but Value of Cause is wrong");
return; return;
} }
if (itti_msg.handvoerRequ->getDirectForwardingPathAvailability() != Ngap_DirectForwardingPathAvailability_direct_path_available) if (itti_msg.handvoerRequ->getDirectForwardingPathAvailability() !=
{ Ngap_DirectForwardingPathAvailability_direct_path_available) {
Logger::amf_n2().error("Received Handover Required message,but DirectForwardingPathAvailability is wrong"); Logger::amf_n2().error(
"Received Handover Required message,but "
"DirectForwardingPathAvailability is wrong");
return; return;
} }
GlobalgNBId *TargetGlobalgNBId = new GlobalgNBId(); GlobalgNBId* TargetGlobalgNBId = new GlobalgNBId();
itti_msg.handvoerRequ->getGlobalRanNodeId(TargetGlobalgNBId); itti_msg.handvoerRequ->getGlobalRanNodeId(TargetGlobalgNBId);
PlmnId *plmn = new PlmnId(); PlmnId* plmn = new PlmnId();
GNB_ID *gnbid = new GNB_ID(); GNB_ID* gnbid = new GNB_ID();
TargetGlobalgNBId->getGlobalgNBId(plmn, gnbid); TargetGlobalgNBId->getGlobalgNBId(plmn, gnbid);
string mcc, mnc; string mcc, mnc;
plmn->getMcc(mcc); plmn->getMcc(mcc);
plmn->getMnc(mnc); plmn->getMnc(mnc);
printf("handover required:Target ID GlobalRanNodeID PLmn=mcc%s mnc%s gnbid=%x\n", mcc.c_str(), mnc.c_str(), gnbid->getValue()); printf(
TAI *tai = new TAI(); "handover required:Target ID GlobalRanNodeID PLmn=mcc%s mnc%s "
"gnbid=%x\n",
mcc.c_str(), mnc.c_str(), gnbid->getValue());
TAI* tai = new TAI();
itti_msg.handvoerRequ->getTAI(tai); itti_msg.handvoerRequ->getTAI(tai);
PlmnId *plmnOfTAI = new PlmnId(); PlmnId* plmnOfTAI = new PlmnId();
TAC *tac = new TAC(); TAC* tac = new TAC();
tai->getTAI(plmnOfTAI, tac); tai->getTAI(plmnOfTAI, tac);
string mccOfselectTAI, mncOfselectTAI; string mccOfselectTAI, mncOfselectTAI;
plmn->getMcc(mccOfselectTAI); plmn->getMcc(mccOfselectTAI);
plmn->getMnc(mncOfselectTAI); plmn->getMnc(mncOfselectTAI);
printf("handover required:Target ID selectedTAI PLmn=mcc%s mnc%s tac=%x\n", mccOfselectTAI.c_str(), mncOfselectTAI.c_str(), tac->getTac()); printf(
"handover required:Target ID selectedTAI PLmn=mcc%s mnc%s tac=%x\n",
mccOfselectTAI.c_str(), mncOfselectTAI.c_str(), tac->getTac());
std::vector<PDUSessionResourceItem_t> List_HORqd; std::vector<PDUSessionResourceItem_t> List_HORqd;
if (!itti_msg.handvoerRequ->getPDUSessionResourceList(List_HORqd)) if (!itti_msg.handvoerRequ->getPDUSessionResourceList(List_HORqd)) {
{ Logger::ngap().error(
Logger::ngap().error("decoding HandoverRequiredMsg getPDUSessionResourceList IE error"); "decoding HandoverRequiredMsg getPDUSessionResourceList IE error");
return; return;
} }
OCTET_STRING_t sourceTotarget; OCTET_STRING_t sourceTotarget;
sourceTotarget = itti_msg.handvoerRequ->getSourceToTarget_TransparentContainer(); sourceTotarget =
itti_msg.handvoerRequ->getSourceToTarget_TransparentContainer();
/**********************send handover request to target gnb*******************************/ /**********************send handover request to target
HandoverRequest *handoverrequest = new HandoverRequest(); * gnb*******************************/
HandoverRequest* handoverrequest = new HandoverRequest();
handoverrequest->setMessageType(); handoverrequest->setMessageType();
handoverrequest->setAmfUeNgapId(amf_ue_ngap_id); handoverrequest->setAmfUeNgapId(amf_ue_ngap_id);
handoverrequest->setHandoverType(0); handoverrequest->setHandoverType(0);
handoverrequest->setCause(Ngap_Cause_PR_radioNetwork, Ngap_CauseRadioNetwork_handover_desirable_for_radio_reason); handoverrequest->setCause(
Ngap_Cause_PR_radioNetwork,
Ngap_CauseRadioNetwork_handover_desirable_for_radio_reason);
handoverrequest->setUEAggregateMaximumBitRate(300000000, 100000000); handoverrequest->setUEAggregateMaximumBitRate(300000000, 100000000);
handoverrequest->setUESecurityCapabilities(0xe000, 0xe000, 0xe000, 0xe000); handoverrequest->setUESecurityCapabilities(0xe000, 0xe000, 0xe000, 0xe000);
...@@ -952,73 +962,54 @@ void amf_n2::handle_itti_message(itti_handover_required &itti_msg) ...@@ -952,73 +962,54 @@ void amf_n2::handle_itti_message(itti_handover_required &itti_msg)
s_nssai.setSst("01"); s_nssai.setSst("01");
std::vector<S_NSSAI> Allowed_Nssai; std::vector<S_NSSAI> Allowed_Nssai;
Allowed_Nssai.push_back(s_nssai); Allowed_Nssai.push_back(s_nssai);
//handoverrequest->setAllowedNSSAI(Allowed_Nssai); // handoverrequest->setAllowedNSSAI(Allowed_Nssai);
Guami_t guami; Guami_t guami;
guami.mcc = amf_cfg.guami.mcc; guami.mcc = amf_cfg.guami.mcc;
guami.mnc = amf_cfg.guami.mnc; guami.mnc = amf_cfg.guami.mnc;
guami.regionID = amf_cfg.guami.regionID; guami.regionID = amf_cfg.guami.regionID;
guami.AmfSetID = amf_cfg.guami.AmfSetID; guami.AmfSetID = amf_cfg.guami.AmfSetID;
guami.AmfPointer = amf_cfg.guami.AmfPointer; guami.AmfPointer = amf_cfg.guami.AmfPointer;
PlmnId *m_plmnId = new PlmnId(); PlmnId* m_plmnId = new PlmnId();
AMFRegionID *m_aMFRegionID = new AMFRegionID(); AMFRegionID* m_aMFRegionID = new AMFRegionID();
AMFSetID *m_aMFSetID = new AMFSetID(); AMFSetID* m_aMFSetID = new AMFSetID();
AMFPointer *m_aMFPointer = new AMFPointer(); AMFPointer* m_aMFPointer = new AMFPointer();
m_plmnId->setMccMnc(guami.mcc, guami.mnc); m_plmnId->setMccMnc(guami.mcc, guami.mnc);
m_aMFRegionID->setAMFRegionID(guami.regionID); m_aMFRegionID->setAMFRegionID(guami.regionID);
m_aMFSetID->setAMFSetID(guami.AmfSetID); m_aMFSetID->setAMFSetID(guami.AmfSetID);
m_aMFPointer->setAMFPointer(guami.AmfPointer); m_aMFPointer->setAMFPointer(guami.AmfPointer);
//handoverrequest->setMobilityRestrictionList(m_plmnId); // handoverrequest->setMobilityRestrictionList(m_plmnId);
//handoverrequest->setGUAMI(m_plmnId, m_aMFRegionID, m_aMFSetID, m_aMFPointer); // handoverrequest->setGUAMI(m_plmnId, m_aMFRegionID, m_aMFSetID,
// m_aMFPointer);
std::shared_ptr<nas_context> nc = amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id);
nas_secu_ctx *secu = nc.get()->security_ctx; std::shared_ptr<nas_context> nc =
uint8_t *kamf = nc.get()->kamf[secu->vector_pointer]; amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id);
nas_secu_ctx* secu = nc.get()->security_ctx;
uint8_t* kamf = nc.get()->kamf[secu->vector_pointer];
uint8_t kgnb[32]; uint8_t kgnb[32];
uint32_t ulcount = secu->ul_count.seq_num | (secu->ul_count.overflow << 8); 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);
uint8_t knh[32]; uint8_t knh[32];
Authentication_5gaka::handover_ncc_derive_knh(ulcount, 0x01, kamf, kgnb, knh, 2); Authentication_5gaka::handover_ncc_derive_knh(
ulcount, 0x01, kamf, kgnb, knh, ncc);
/*Authentication_5gaka::derive_kgnb(ulcount, 0x01, kamf, kgnb);
print_buffer("amf_n1", "HO:kgnb", kgnb, 32);
//NCC = 1
uint8_t S[35], knh[32];
S[0] = 0x6f;
memcpy(S + 1, kgnb, 32);
S[33] = 0x00;
S[34] = 0x20;
print_buffer("amf_n1", "NCC=1: S", S, 35);
Authentication_5gaka::kdf(kamf, 32, S, 35, knh, 32);
//NCC = 2
uint8_t S2[35], knh2[32];
S2[0] = 0x6f;
memcpy(S2 + 1, knh, 32);
S2[33] = 0x00;
S2[34] = 0x20;
print_buffer("amf_n1", "NCC=2: S2", S2, 35);
Authentication_5gaka::kdf(kamf, 32, S2, 35, knh2, 32);
print_buffer("amf_n1", "Knh2", knh2, 32);
bstring knh_bs = blk2bstr(knh2, 32);*/
bstring knh_bs = blk2bstr(knh, 32); bstring knh_bs = blk2bstr(knh, 32);
handoverrequest->setSecurityContext(2 /*NCC count*/, (uint8_t *)bdata(knh_bs)); handoverrequest->setSecurityContext(
//handoverrequest->setSourceToTarget_TransparentContainer(sourceTotarget); ncc /*NCC count*/, (uint8_t*) bdata(knh_bs));
// handoverrequest->setSourceToTarget_TransparentContainer(sourceTotarget);
string supi = "imsi-" + nc.get()->imsi; string supi = "imsi-" + nc.get()->imsi;
std::shared_ptr<pdu_session_context> psc = amf_n11_inst->supi_to_pdu_ctx(supi); std::shared_ptr<pdu_session_context> psc =
amf_n11_inst->supi_to_pdu_ctx(supi);
std::vector<PDUSessionResourceSetupRequestItem_t> list; std::vector<PDUSessionResourceSetupRequestItem_t> list;
PDUSessionResourceSetupRequestItem_t item; PDUSessionResourceSetupRequestItem_t item;
item.pduSessionId = psc.get()->pdu_session_id; item.pduSessionId = psc.get()->pdu_session_id;
item.s_nssai.sst = "01"; item.s_nssai.sst = "01";
item.s_nssai.sd = ""; item.s_nssai.sd = "";
item.pduSessionNAS_PDU = NULL; item.pduSessionNAS_PDU = NULL;
bstring n2sm = psc.get()->n2sm; bstring n2sm = psc.get()->n2sm;
if (blength(psc.get()->n2sm) != 0) if (blength(psc.get()->n2sm) != 0) {
{ item.pduSessionResourceSetupRequestTransfer.buf =
(uint8_t*) bdata(psc.get()->n2sm);
item.pduSessionResourceSetupRequestTransfer.buf = (uint8_t *)bdata(psc.get()->n2sm);
item.pduSessionResourceSetupRequestTransfer.size = blength(psc.get()->n2sm); item.pduSessionResourceSetupRequestTransfer.size = blength(psc.get()->n2sm);
} } else {
else
{
Logger::amf_n2().error("n2sm empty!"); Logger::amf_n2().error("n2sm empty!");
} }
list.push_back(item); list.push_back(item);
...@@ -1029,200 +1020,236 @@ void amf_n2::handle_itti_message(itti_handover_required &itti_msg) ...@@ -1029,200 +1020,236 @@ void amf_n2::handle_itti_message(itti_handover_required &itti_msg)
handoverrequest->setGUAMI(m_plmnId, m_aMFRegionID, m_aMFSetID, m_aMFPointer); handoverrequest->setGUAMI(m_plmnId, m_aMFRegionID, m_aMFSetID, m_aMFPointer);
uint8_t buffer[20240]; uint8_t buffer[20240];
int encoded_size = handoverrequest->encode2buffer(buffer, 20240); int encoded_size = handoverrequest->encode2buffer(buffer, 20240);
delete handoverrequest;
bstring b = blk2bstr(buffer, encoded_size); bstring b = blk2bstr(buffer, encoded_size);
std::shared_ptr<gnb_context> gc_target; std::shared_ptr<gnb_context> gc_target;
gc_target = gnb_id_2_gnb_context(gnbid->getValue()); gc_target = gnb_id_2_gnb_context(gnbid->getValue());
downlink_sctp_assoc_id = gc_target.get()->sctp_assoc_id; downlink_sctp_assoc_id = gc_target.get()->sctp_assoc_id;
sctp_s_38412.sctp_send_msg(gc_target.get()->sctp_assoc_id, 0, &b); sctp_s_38412.sctp_send_msg(gc_target.get()->sctp_assoc_id, 0, &b);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_handover_request_Ack &itti_msg) void amf_n2::handle_itti_message(itti_handover_request_Ack& itti_msg) {
{
unsigned long amf_ue_ngap_id = itti_msg.handoverrequestAck->getAmfUeNgapId(); unsigned long amf_ue_ngap_id = itti_msg.handoverrequestAck->getAmfUeNgapId();
uint32_t ran_ue_ngap_id = itti_msg.handoverrequestAck->getRanUeNgapId(); uint32_t ran_ue_ngap_id = itti_msg.handoverrequestAck->getRanUeNgapId();
AMF_TARGET_ran_id_global = ran_ue_ngap_id; AMF_TARGET_ran_id_global = ran_ue_ngap_id;
Logger::amf_n2().error("handover request Ack ran_ue_ngap_id(0x%d) amf_ue_ngap_id(%d)", ran_ue_ngap_id, amf_ue_ngap_id); Logger::amf_n2().error(
"handover request Ack ran_ue_ngap_id(0x%d) amf_ue_ngap_id(%d)",
ran_ue_ngap_id, amf_ue_ngap_id);
std::shared_ptr<gnb_context> gc; std::shared_ptr<gnb_context> gc;
if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) {
{ Logger::amf_n2().error(
Logger::amf_n2().error("gnb with assoc_id(%d) is illegal", itti_msg.assoc_id); "gnb with assoc_id(%d) is illegal", itti_msg.assoc_id);
return; return;
} }
gc = assoc_id_2_gnb_context(itti_msg.assoc_id); gc = assoc_id_2_gnb_context(itti_msg.assoc_id);
std::vector<PDUSessionResourceAdmittedItem_t> list; std::vector<PDUSessionResourceAdmittedItem_t> list;
if (!itti_msg.handoverrequestAck->getPDUSessionResourceAdmittedList(list)) if (!itti_msg.handoverrequestAck->getPDUSessionResourceAdmittedList(list)) {
{ Logger::ngap().error(
Logger::ngap().error("decoding HandoverRequestACK getPDUSessionResourceList IE error"); "decoding HandoverRequestACK getPDUSessionResourceList IE error");
return; return;
} }
OCTET_STRING_t targetTosource; OCTET_STRING_t targetTosource;
targetTosource = itti_msg.handoverrequestAck->getTargetToSource_TransparentContainer(); targetTosource =
itti_msg.handoverrequestAck->getTargetToSource_TransparentContainer();
/**************************add-start**************************/ /**************************add-start**************************/
PDUSessionResourceHandoverRequestAckTransfer *PDUHandoverRequestAckTransfer = new PDUSessionResourceHandoverRequestAckTransfer(); PDUSessionResourceHandoverRequestAckTransfer* PDUHandoverRequestAckTransfer =
new PDUSessionResourceHandoverRequestAckTransfer();
uint8_t buf[1024]; uint8_t buf[1024];
cout << list[0].handoverRequestAcknowledgeTransfer.buf << endl; cout << list[0].handoverRequestAcknowledgeTransfer.buf << endl;
cout << list[0].handoverRequestAcknowledgeTransfer.size << endl; cout << list[0].handoverRequestAcknowledgeTransfer.size << endl;
memcpy(buf, list[0].handoverRequestAcknowledgeTransfer.buf, list[0].handoverRequestAcknowledgeTransfer.size); memcpy(
if (!PDUHandoverRequestAckTransfer->decodefromHandoverRequestAckTransfer(buf, list[0].handoverRequestAcknowledgeTransfer.size)) buf, list[0].handoverRequestAcknowledgeTransfer.buf,
{ list[0].handoverRequestAcknowledgeTransfer.size);
if (!PDUHandoverRequestAckTransfer->decodefromHandoverRequestAckTransfer(
buf, list[0].handoverRequestAcknowledgeTransfer.size)) {
cout << "decode handoverrequestacktransfer error" << endl; cout << "decode handoverrequestacktransfer error" << endl;
return; return;
} }
GtpTunnel_t *gtptunnel = new GtpTunnel_t(); GtpTunnel_t* gtptunnel = new GtpTunnel_t();
if (!PDUHandoverRequestAckTransfer->getUpTransportLayerInformation2(gtptunnel)) if (!PDUHandoverRequestAckTransfer->getUpTransportLayerInformation2(
{ gtptunnel)) {
cout << "decode GtpTunnel error" << endl; cout << "decode GtpTunnel error" << endl;
return; return;
} }
string n3_ip_address; string n3_ip_address;
uint32_t teid; uint32_t teid;
n3_ip_address = gtptunnel->ip_address; n3_ip_address = gtptunnel->ip_address;
teid = gtptunnel->gtp_teid; teid = gtptunnel->gtp_teid;
std::vector<QosFlowLItemWithDataForwarding_t> QosFlowWithDataForwardinglist; std::vector<QosFlowLItemWithDataForwarding_t> QosFlowWithDataForwardinglist;
PDUHandoverRequestAckTransfer->getqosFlowSetupResponseList(QosFlowWithDataForwardinglist); PDUHandoverRequestAckTransfer->getqosFlowSetupResponseList(
QosFlowWithDataForwardinglist);
long qosflowidentifiervalue; long qosflowidentifiervalue;
qosflowidentifiervalue = (long)QosFlowWithDataForwardinglist[0].qosFlowIdentifier; qosflowidentifiervalue =
(long) QosFlowWithDataForwardinglist[0].qosFlowIdentifier;
cout << "QFI get is " << qosflowidentifiervalue << endl; cout << "QFI get is " << qosflowidentifiervalue << endl;
/**************************add-end**************************/ /**************************add-end**************************/
/**************************send HandoverCommandMsg to Source gnb**************************/ /**************************send HandoverCommandMsg to Source
HandoverCommandMsg *handovercommand = new HandoverCommandMsg(); * gnb**************************/
HandoverCommandMsg* handovercommand = new HandoverCommandMsg();
handovercommand->setMessageType(); handovercommand->setMessageType();
handovercommand->setAmfUeNgapId(amf_ue_ngap_id); handovercommand->setAmfUeNgapId(amf_ue_ngap_id);
handovercommand->setRanUeNgapId(ran_id_Global); handovercommand->setRanUeNgapId(ran_id_Global);
handovercommand->setHandoverType(Ngap_HandoverType_intra5gs); handovercommand->setHandoverType(Ngap_HandoverType_intra5gs);
std::shared_ptr<nas_context> nc = amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id); std::shared_ptr<nas_context> nc =
amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id);
/**************************setPduSessionResourceHandoverList_PDYSessionID_handovercommandtransfer**************************/ /**************************setPduSessionResourceHandoverList_PDYSessionID_handovercommandtransfer**************************/
std::vector<PDUSessionResourceHandoverItem_t> handover_list; std::vector<PDUSessionResourceHandoverItem_t> handover_list;
PDUSessionResourceHandoverItem_t item; PDUSessionResourceHandoverItem_t item;
//set pdu id // set pdu id
item.pduSessionId = list[0].pduSessionId; item.pduSessionId = list[0].pduSessionId;
//set qosFLowtobeforwardedlist // set qosFLowtobeforwardedlist
std::vector<QosFlowToBeForwardedItem_t> forward_list; std::vector<QosFlowToBeForwardedItem_t> forward_list;
QosFlowToBeForwardedItem_t forward_item; QosFlowToBeForwardedItem_t forward_item;
forward_item.QFI = qosflowidentifiervalue; forward_item.QFI = qosflowidentifiervalue;
forward_list.push_back(forward_item); forward_list.push_back(forward_item);
//set dlforwardingup_tnlinformation // set dlforwardingup_tnlinformation
//TransportLayerAddress *transportlayeraddress = new TransportLayerAddress(); // TransportLayerAddress *transportlayeraddress = new TransportLayerAddress();
//transportlayeraddress->setTransportLayerAddress(n3_ip_address); // transportlayeraddress->setTransportLayerAddress(n3_ip_address);
//GtpTeid *gtpTeid = new GtpTeid(); // GtpTeid *gtpTeid = new GtpTeid();
//gtpTeid->setGtpTeid(teid); // gtpTeid->setGtpTeid(teid);
PDUSessionResourceHandoverCommandTransfer *handovercommandtransfer = new PDUSessionResourceHandoverCommandTransfer(); PDUSessionResourceHandoverCommandTransfer* handovercommandtransfer =
new PDUSessionResourceHandoverCommandTransfer();
handovercommandtransfer->setQosFlowToBeForwardedList(forward_list); handovercommandtransfer->setQosFlowToBeForwardedList(forward_list);
GtpTunnel_t uptlinfo; GtpTunnel_t uptlinfo;
uptlinfo.gtp_teid = teid; uptlinfo.gtp_teid = teid;
uptlinfo.ip_address = n3_ip_address; uptlinfo.ip_address = n3_ip_address;
handovercommandtransfer->setUPTransportLayerInformation(uptlinfo); handovercommandtransfer->setUPTransportLayerInformation(uptlinfo);
//handovercommand->setTargetToSource_TransparentContainer(targetTosource); // handovercommand->setTargetToSource_TransparentContainer(targetTosource);
uint8_t buffer2[500]; uint8_t buffer2[500];
int encoded_size2 = handovercommandtransfer->encodePDUSessionResourceHandoverCommandTransfer(buffer2, 500); int encoded_size2 =
handovercommandtransfer->encodePDUSessionResourceHandoverCommandTransfer(
buffer2, 500);
OCTET_STRING_t OCT_handovercommandtransfer; OCTET_STRING_t OCT_handovercommandtransfer;
OCT_handovercommandtransfer.buf = buffer2; OCT_handovercommandtransfer.buf = buffer2;
OCT_handovercommandtransfer.size = encoded_size2; OCT_handovercommandtransfer.size = encoded_size2;
item.HandoverCommandTransfer = OCT_handovercommandtransfer; item.HandoverCommandTransfer = OCT_handovercommandtransfer;
handover_list.push_back(item); handover_list.push_back(item);
handovercommand->setPduSessionResourceHandoverList(handover_list); handovercommand->setPduSessionResourceHandoverList(handover_list);
handovercommand->setTargetToSource_TransparentContainer(targetTosource); handovercommand->setTargetToSource_TransparentContainer(targetTosource);
/**************************setPduSessionResourceHandoverList_PDYSessionID_handovercommandtransfer-end**************************/ /**************************setPduSessionResourceHandoverList_PDYSessionID_handovercommandtransfer-end**************************/
uint8_t buffer[10240]; uint8_t buffer[10240];
int encoded_size = handovercommand->encode2buffer(buffer, 10240); int encoded_size = handovercommand->encode2buffer(buffer, 10240);
delete handovercommand;
bstring b = blk2bstr(buffer, encoded_size); bstring b = blk2bstr(buffer, encoded_size);
std::shared_ptr<ue_ngap_context> unc; std::shared_ptr<ue_ngap_context> unc;
if (!is_ran_ue_id_2_ue_ngap_context(ran_id_Global)) if (!is_ran_ue_id_2_ue_ngap_context(ran_id_Global)) {
{ Logger::amf_n2().debug(
Logger::amf_n2().debug("Create a new ue ngap context with ran_ue_ngap_id(0x%x)", ran_id_Global); "Create a new ue ngap context with ran_ue_ngap_id(0x%x)",
ran_id_Global);
unc = std::shared_ptr<ue_ngap_context>(new ue_ngap_context()); unc = std::shared_ptr<ue_ngap_context>(new ue_ngap_context());
set_ran_ue_ngap_id_2_ue_ngap_context(ran_id_Global, unc); set_ran_ue_ngap_id_2_ue_ngap_context(ran_id_Global, unc);
unc.get()->gnb_assoc_id = source_assoc_id; unc.get()->gnb_assoc_id = source_assoc_id;
} else {
unc = ran_ue_id_2_ue_ngap_context(ran_id_Global);
unc.get()->gnb_assoc_id = source_assoc_id;
} }
//std::shared_ptr<ue_ngap_context> ngc = ran_ue_id_2_ue_ngap_context(nc.get()->ran_ue_ngap_id);
//std::shared_ptr<ue_ngap_context> ngc = ran_ue_id_2_ue_ngap_context(ran_id_Global); // std::shared_ptr<ue_ngap_context> ngc =
//sctp_s_38412.sctp_send_msg(ngc.get()->gnb_assoc_id, 0, &b); // ran_ue_id_2_ue_ngap_context(nc.get()->ran_ue_ngap_id);
// std::shared_ptr<ue_ngap_context> ngc =
// ran_ue_id_2_ue_ngap_context(ran_id_Global);
// sctp_s_38412.sctp_send_msg(ngc.get()->gnb_assoc_id, 0, &b);
sctp_s_38412.sctp_send_msg(unc.get()->gnb_assoc_id, 0, &b); sctp_s_38412.sctp_send_msg(unc.get()->gnb_assoc_id, 0, &b);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_handover_notify &itti_msg) void amf_n2::handle_itti_message(itti_handover_notify& itti_msg) {
{
unsigned long amf_ue_ngap_id = itti_msg.handovernotify->getAmfUeNgapId(); unsigned long amf_ue_ngap_id = itti_msg.handovernotify->getAmfUeNgapId();
uint32_t ran_ue_ngap_id = itti_msg.handovernotify->getRanUeNgapId(); uint32_t ran_ue_ngap_id = itti_msg.handovernotify->getRanUeNgapId();
Logger::amf_n2().error("handover notify ran_ue_ngap_id(0x%d) amf_ue_ngap_id(%d)", ran_ue_ngap_id, amf_ue_ngap_id); Logger::amf_n2().error(
if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) "handover notify ran_ue_ngap_id(0x%d) amf_ue_ngap_id(%d)", ran_ue_ngap_id,
{ amf_ue_ngap_id);
Logger::amf_n2().error("gnb with assoc_id(%d) is illegal", itti_msg.assoc_id); if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) {
Logger::amf_n2().error(
"gnb with assoc_id(%d) is illegal", itti_msg.assoc_id);
return; return;
} }
NrCgi_t NR_CGI = {}; NrCgi_t NR_CGI = {};
Tai_t TAI = {}; Tai_t TAI = {};
if (!itti_msg.handovernotify->getUserLocationInfoNR(NR_CGI, TAI)) if (!itti_msg.handovernotify->getUserLocationInfoNR(NR_CGI, TAI)) {
{
Logger::amf_n2().debug("Missing IE UserLocationInformationNR"); Logger::amf_n2().debug("Missing IE UserLocationInformationNR");
return; return;
} }
UEContextReleaseCommandMsg *ueContextReleaseCommand = new UEContextReleaseCommandMsg(); UEContextReleaseCommandMsg* ueContextReleaseCommand =
new UEContextReleaseCommandMsg();
ueContextReleaseCommand->setMessageType(); ueContextReleaseCommand->setMessageType();
ueContextReleaseCommand->setUeNgapIdPair(amf_ue_ngap_id, ran_id_Global); ueContextReleaseCommand->setUeNgapIdPair(amf_ue_ngap_id, ran_id_Global);
ueContextReleaseCommand->setCauseRadioNetwork(Ngap_CauseRadioNetwork_successful_handover); ueContextReleaseCommand->setCauseRadioNetwork(
Ngap_CauseRadioNetwork_successful_handover);
uint8_t buffer[10240]; uint8_t buffer[10240];
int encoded_size = ueContextReleaseCommand->encode2buffer(buffer, 10240); int encoded_size = ueContextReleaseCommand->encode2buffer(buffer, 10240);
delete ueContextReleaseCommand;
bstring b = blk2bstr(buffer, encoded_size); bstring b = blk2bstr(buffer, encoded_size);
std::shared_ptr<nas_context> nc = amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id); std::shared_ptr<nas_context> nc =
std::shared_ptr<ue_ngap_context> ngc = ran_ue_id_2_ue_ngap_context(nc.get()->ran_ue_ngap_id); amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id);
sctp_s_38412.sctp_send_msg(ngc.get()->gnb_assoc_id, 0, &b); std::shared_ptr<ue_ngap_context> ngc =
/*std::shared_ptr<nas_context> nc = amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id); ran_ue_id_2_ue_ngap_context(nc.get()->ran_ue_ngap_id);
string supi = "imsi-" + nc.get()->imsi; sctp_s_38412.sctp_send_msg(source_assoc_id, 0, &b);
std::shared_ptr<pdu_session_context> psc = amf_n11_inst->supi_to_pdu_ctx(supi); /*std::shared_ptr<nas_context> nc =
itti_nsmf_pdusession_update_sm_context *itti_nsmf_msg = new itti_nsmf_pdusession_update_sm_context(TASK_AMF_N2, TASK_AMF_N11); amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id); string supi = "imsi-" +
itti_nsmf_msg->supi = supi; nc.get()->imsi; std::shared_ptr<pdu_session_context> psc =
itti_nsmf_msg->pdu_session_id = psc.get()->pdu_session_id; amf_n11_inst->supi_to_pdu_ctx(supi); itti_nsmf_pdusession_update_sm_context
itti_nsmf_msg->n2sm = psc.get()->n2sm; *itti_nsmf_msg = new itti_nsmf_pdusession_update_sm_context(TASK_AMF_N2,
std::shared_ptr<itti_nsmf_pdusession_update_sm_context> i = std::shared_ptr<itti_nsmf_pdusession_update_sm_context>(itti_nsmf_msg); TASK_AMF_N11); itti_nsmf_msg->supi = supi; itti_nsmf_msg->pdu_session_id =
psc.get()->pdu_session_id; itti_nsmf_msg->n2sm = psc.get()->n2sm;
std::shared_ptr<itti_nsmf_pdusession_update_sm_context> i =
std::shared_ptr<itti_nsmf_pdusession_update_sm_context>(itti_nsmf_msg);
//int ret = itti_inst->send_msg(i);*/ //int ret = itti_inst->send_msg(i);*/
std::shared_ptr<ue_ngap_context> unc; std::shared_ptr<ue_ngap_context> unc;
if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) {
{ Logger::amf_n2().debug(
Logger::amf_n2().debug("Create a new ue ngap context with ran_ue_ngap_id(0x%x)", ran_ue_ngap_id); "Create a new ue ngap context with ran_ue_ngap_id(0x%x)",
ran_ue_ngap_id);
unc = std::shared_ptr<ue_ngap_context>(new ue_ngap_context()); unc = std::shared_ptr<ue_ngap_context>(new ue_ngap_context());
set_ran_ue_ngap_id_2_ue_ngap_context(ran_ue_ngap_id, unc); set_ran_ue_ngap_id_2_ue_ngap_context(ran_ue_ngap_id, unc);
unc.get()->gnb_assoc_id = ngc.get()->gnb_assoc_id; unc.get()->gnb_assoc_id = ngc.get()->gnb_assoc_id;
} }
/*if (0 != ret) /*if (0 != ret)
{ {
Logger::ngap().error("Could not send ITTI message %s to task TASK_AMF_N11", i->get_msg_name()); Logger::ngap().error("Could not send ITTI message %s to task TASK_AMF_N11",
i->get_msg_name());
}*/ }*/
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_uplinkranstatsutransfer &itti_msg) void amf_n2::handle_itti_message(itti_uplinkranstatsutransfer& itti_msg) {
{
unsigned long amf_ue_ngap_id = itti_msg.uplinkrantransfer->getAmfUeNgapId(); unsigned long amf_ue_ngap_id = itti_msg.uplinkrantransfer->getAmfUeNgapId();
Logger::amf_n2().error("uplinkranstatustransfer amf_ue_ngap_id(%d)", amf_ue_ngap_id); Logger::amf_n2().error(
if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) "uplinkranstatustransfer amf_ue_ngap_id(%d)", amf_ue_ngap_id);
{ if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) {
Logger::amf_n2().error("gnb with assoc_id(%d) is illegal", itti_msg.assoc_id); Logger::amf_n2().error(
"gnb with assoc_id(%d) is illegal", itti_msg.assoc_id);
return; return;
} }
RANStatusTransferTransparentContainer *ran_status_transfer = (RANStatusTransferTransparentContainer *)calloc(1, sizeof(RANStatusTransferTransparentContainer)); RANStatusTransferTransparentContainer* ran_status_transfer =
itti_msg.uplinkrantransfer->getRANStatusTransfer_TransparentContainer(ran_status_transfer); (RANStatusTransferTransparentContainer*) calloc(
dRBSubjectList *amf_m_list = (dRBSubjectList *)calloc(1, sizeof(dRBSubjectList)); 1, sizeof(RANStatusTransferTransparentContainer));
itti_msg.uplinkrantransfer->getRANStatusTransfer_TransparentContainer(
ran_status_transfer);
dRBSubjectList* amf_m_list =
(dRBSubjectList*) calloc(1, sizeof(dRBSubjectList));
ran_status_transfer->getdRBSubject_list(amf_m_list); ran_status_transfer->getdRBSubject_list(amf_m_list);
dRBSubjectItem *amf_m_item = (dRBSubjectItem *)calloc(1, sizeof(dRBSubjectItem)); dRBSubjectItem* amf_m_item =
(dRBSubjectItem*) calloc(1, sizeof(dRBSubjectItem));
int numofitem = 0; int numofitem = 0;
amf_m_list->getdRBSubjectItem(amf_m_item, numofitem); amf_m_list->getdRBSubjectItem(amf_m_item, numofitem);
dRBStatusDL *amf_DL = (dRBStatusDL *)calloc(1, sizeof(dRBStatusDL)); dRBStatusDL* amf_DL = (dRBStatusDL*) calloc(1, sizeof(dRBStatusDL));
dRBStatusUL *amf_UL = (dRBStatusUL *)calloc(1, sizeof(dRBStatusUL)); dRBStatusUL* amf_UL = (dRBStatusUL*) calloc(1, sizeof(dRBStatusUL));
Ngap_DRB_ID_t *amf_dRB_id = (Ngap_DRB_ID_t *)calloc(1, sizeof(Ngap_DRB_ID_t)); Ngap_DRB_ID_t* amf_dRB_id = (Ngap_DRB_ID_t*) calloc(1, sizeof(Ngap_DRB_ID_t));
amf_m_item->getdRBSubjectItem(amf_dRB_id, amf_UL, amf_DL); amf_m_item->getdRBSubjectItem(amf_dRB_id, amf_UL, amf_DL);
dRBStatusUL18 *UL18 = (dRBStatusUL18 *)calloc(1, sizeof(dRBStatusUL18)); dRBStatusUL18* UL18 = (dRBStatusUL18*) calloc(1, sizeof(dRBStatusUL18));
DRBStatusDL18 *DL18 = (DRBStatusDL18 *)calloc(1, sizeof(DRBStatusDL18)); DRBStatusDL18* DL18 = (DRBStatusDL18*) calloc(1, sizeof(DRBStatusDL18));
amf_DL->getDRBStatusDL18(DL18); amf_DL->getDRBStatusDL18(DL18);
amf_UL->getdRBStatusUL(UL18); amf_UL->getdRBStatusUL(UL18);
COUNTValueForPDCP_SN18 *amf_UL_value = (COUNTValueForPDCP_SN18 *)calloc(1, sizeof(COUNTValueForPDCP_SN18)); COUNTValueForPDCP_SN18* amf_UL_value =
COUNTValueForPDCP_SN18 *amf_DL_value = (COUNTValueForPDCP_SN18 *)calloc(1, sizeof(COUNTValueForPDCP_SN18)); (COUNTValueForPDCP_SN18*) calloc(1, sizeof(COUNTValueForPDCP_SN18));
COUNTValueForPDCP_SN18* amf_DL_value =
(COUNTValueForPDCP_SN18*) calloc(1, sizeof(COUNTValueForPDCP_SN18));
UL18->getcountvalue(amf_UL_value); UL18->getcountvalue(amf_UL_value);
DL18->getcountvalue(amf_DL_value); DL18->getcountvalue(amf_DL_value);
long amf_ul_pdcp; long amf_ul_pdcp;
...@@ -1233,36 +1260,40 @@ void amf_n2::handle_itti_message(itti_uplinkranstatsutransfer &itti_msg) ...@@ -1233,36 +1260,40 @@ void amf_n2::handle_itti_message(itti_uplinkranstatsutransfer &itti_msg)
amf_DL_value->getvalue(amf_dl_pdcp, amf_hfn_dl_pdcp); amf_DL_value->getvalue(amf_dl_pdcp, amf_hfn_dl_pdcp);
long amf_drb_id; long amf_drb_id;
amf_drb_id = *amf_dRB_id; amf_drb_id = *amf_dRB_id;
DownlinkRANStatusTransfer *downLinkranstatustransfer = new DownlinkRANStatusTransfer(); DownlinkRANStatusTransfer* downLinkranstatustransfer =
new DownlinkRANStatusTransfer();
downLinkranstatustransfer->setmessagetype(); downLinkranstatustransfer->setmessagetype();
downLinkranstatustransfer->setAmfUeNgapId(amf_ue_ngap_id); downLinkranstatustransfer->setAmfUeNgapId(amf_ue_ngap_id);
downLinkranstatustransfer->setRanUeNgapId(AMF_TARGET_ran_id_global); downLinkranstatustransfer->setRanUeNgapId(AMF_TARGET_ran_id_global);
downLinkranstatustransfer->setRANStatusTransfer_TransparentContainer(amf_drb_id, amf_ul_pdcp, amf_hfn_ul_pdcp, amf_dl_pdcp, amf_hfn_dl_pdcp); downLinkranstatustransfer->setRANStatusTransfer_TransparentContainer(
amf_drb_id, amf_ul_pdcp, amf_hfn_ul_pdcp, amf_dl_pdcp, amf_hfn_dl_pdcp);
uint8_t buffer[1024]; uint8_t buffer[1024];
int encode_size = downLinkranstatustransfer->encodetobuffer(buffer, 1024); int encode_size = downLinkranstatustransfer->encodetobuffer(buffer, 1024);
delete downLinkranstatustransfer;
bstring b = blk2bstr(buffer, encode_size); bstring b = blk2bstr(buffer, encode_size);
//std::shared_ptr<ue_ngap_context> ngc = ran_ue_id_2_ue_ngap_context(AMF_TARGET_ran_id_global); // std::shared_ptr<ue_ngap_context> ngc =
// ran_ue_id_2_ue_ngap_context(AMF_TARGET_ran_id_global);
sctp_s_38412.sctp_send_msg(downlink_sctp_assoc_id, 0, &b); sctp_s_38412.sctp_send_msg(downlink_sctp_assoc_id, 0, &b);
} }
//Context management functions // Context management functions
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool amf_n2::is_ran_ue_id_2_ue_ngap_context( bool amf_n2::is_ran_ue_id_2_ue_ngap_context(
const uint32_t &ran_ue_ngap_id) const { const uint32_t& ran_ue_ngap_id) const {
std::shared_lock lock(m_ranid2uecontext); std::shared_lock lock(m_ranid2uecontext);
return bool { ranid2uecontext.count(ran_ue_ngap_id) > 0 }; return bool{ranid2uecontext.count(ran_ue_ngap_id) > 0};
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
std::shared_ptr<ue_ngap_context> amf_n2::ran_ue_id_2_ue_ngap_context( std::shared_ptr<ue_ngap_context> amf_n2::ran_ue_id_2_ue_ngap_context(
const uint32_t &ran_ue_ngap_id) const { const uint32_t& ran_ue_ngap_id) const {
std::shared_lock lock(m_ranid2uecontext); std::shared_lock lock(m_ranid2uecontext);
return ranid2uecontext.at(ran_ue_ngap_id); return ranid2uecontext.at(ran_ue_ngap_id);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2::set_ran_ue_ngap_id_2_ue_ngap_context( void amf_n2::set_ran_ue_ngap_id_2_ue_ngap_context(
const uint32_t &ran_ue_ngap_id, std::shared_ptr<ue_ngap_context> unc) { const uint32_t& ran_ue_ngap_id, std::shared_ptr<ue_ngap_context> unc) {
std::shared_lock lock(m_ranid2uecontext); std::shared_lock lock(m_ranid2uecontext);
ranid2uecontext[ran_ue_ngap_id] = unc; ranid2uecontext[ran_ue_ngap_id] = unc;
} }
...@@ -1272,14 +1303,15 @@ void amf_n2::set_ran_ue_ngap_id_2_ue_ngap_context( ...@@ -1272,14 +1303,15 @@ void amf_n2::set_ran_ue_ngap_id_2_ue_ngap_context(
bool amf_n2::verifyPlmn(vector<SupportedItem_t> list) { bool amf_n2::verifyPlmn(vector<SupportedItem_t> list) {
for (int i = 0; i < amf_cfg.plmn_list.size(); i++) { for (int i = 0; i < amf_cfg.plmn_list.size(); i++) {
for (int j = 0; j < list.size(); j++) { for (int j = 0; j < list.size(); j++) {
Logger::amf_n2().debug("TAC configured %d, TAC received %d", Logger::amf_n2().debug(
amf_cfg.plmn_list[i].tac, list[j].tac); "TAC configured %d, TAC received %d", amf_cfg.plmn_list[i].tac,
list[j].tac);
if (amf_cfg.plmn_list[i].tac != list[j].tac) { if (amf_cfg.plmn_list[i].tac != list[j].tac) {
continue; continue;
} }
for (int k = 0; k < list[j].b_plmn_list.size(); k++) { for (int k = 0; k < list[j].b_plmn_list.size(); k++) {
if (!(list[j].b_plmn_list[k].mcc.compare(amf_cfg.plmn_list[i].mcc)) if (!(list[j].b_plmn_list[k].mcc.compare(amf_cfg.plmn_list[i].mcc)) &&
&& !(list[j].b_plmn_list[k].mnc.compare(amf_cfg.plmn_list[i].mnc))) { !(list[j].b_plmn_list[k].mnc.compare(amf_cfg.plmn_list[i].mnc))) {
return true; return true;
} }
} }
...@@ -1291,18 +1323,19 @@ bool amf_n2::verifyPlmn(vector<SupportedItem_t> list) { ...@@ -1291,18 +1323,19 @@ bool amf_n2::verifyPlmn(vector<SupportedItem_t> list) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
std::vector<SupportedItem_t> amf_n2::get_common_plmn( std::vector<SupportedItem_t> amf_n2::get_common_plmn(
std::vector<SupportedItem_t> list) { std::vector<SupportedItem_t> list) {
std::vector<SupportedItem_t> plmn_list = { }; std::vector<SupportedItem_t> plmn_list = {};
for (int i = 0; i < amf_cfg.plmn_list.size(); i++) { for (int i = 0; i < amf_cfg.plmn_list.size(); i++) {
for (int j = 0; j < list.size(); j++) { for (int j = 0; j < list.size(); j++) {
Logger::amf_n2().debug("TAC configured %d, TAC received %d", Logger::amf_n2().debug(
amf_cfg.plmn_list[i].tac, list[j].tac); "TAC configured %d, TAC received %d", amf_cfg.plmn_list[i].tac,
list[j].tac);
if (amf_cfg.plmn_list[i].tac != list[j].tac) { if (amf_cfg.plmn_list[i].tac != list[j].tac) {
continue; continue;
} }
for (int k = 0; k < list[j].b_plmn_list.size(); k++) { for (int k = 0; k < list[j].b_plmn_list.size(); k++) {
if (!(list[j].b_plmn_list[k].mcc.compare(amf_cfg.plmn_list[i].mcc)) if (!(list[j].b_plmn_list[k].mcc.compare(amf_cfg.plmn_list[i].mcc)) &&
&& !(list[j].b_plmn_list[k].mnc.compare(amf_cfg.plmn_list[i].mnc))) { !(list[j].b_plmn_list[k].mnc.compare(amf_cfg.plmn_list[i].mnc))) {
plmn_list.push_back(list[j]); plmn_list.push_back(list[j]);
} }
} }
......
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