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

Apply google style format for amf-app

parent b35240b5
...@@ -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
* *
...@@ -28,18 +28,18 @@ ...@@ -28,18 +28,18 @@
#include "amf_app.hpp" #include "amf_app.hpp"
#include <stdexcept>
#include <iostream>
#include <cstdlib> #include <cstdlib>
#include <iostream>
#include <stdexcept>
#include "itti.hpp" #include "itti.hpp"
#include "ngap_app.hpp" #include "DLNASTransport.hpp"
#include "amf_config.hpp" #include "amf_config.hpp"
#include "amf_n2.hpp"
#include "amf_n1.hpp" #include "amf_n1.hpp"
#include "amf_n11.hpp" #include "amf_n11.hpp"
#include "amf_n2.hpp"
#include "amf_statistics.hpp" #include "amf_statistics.hpp"
#include "DLNASTransport.hpp" #include "ngap_app.hpp"
using namespace ngap; using namespace ngap;
using namespace nas; using namespace nas;
...@@ -56,7 +56,7 @@ amf_n11 *amf_n11_inst = nullptr; ...@@ -56,7 +56,7 @@ amf_n11 *amf_n11_inst = nullptr;
extern amf_config amf_cfg; extern amf_config amf_cfg;
extern statistics stacs; extern statistics stacs;
void amf_app_task(void*); void amf_app_task(void *);
uint32_t golbal_tmsi = 1; uint32_t golbal_tmsi = 1;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -69,18 +69,17 @@ amf_app::amf_app(const amf_config &amf_cfg) { ...@@ -69,18 +69,17 @@ amf_app::amf_app(const amf_config &amf_cfg) {
try { try {
amf_n1_inst = new amf_n1(); amf_n1_inst = new amf_n1();
amf_n2_inst = new amf_n2(std::string(inet_ntoa(amf_cfg.n2.addr4)), amf_n2_inst =
amf_cfg.n2.port); new amf_n2(std::string(inet_ntoa(amf_cfg.n2.addr4)), amf_cfg.n2.port);
amf_n11_inst = new amf_n11(); amf_n11_inst = new amf_n11();
} catch (std::exception &e) { } catch (std::exception &e) {
Logger::amf_app().error("Cannot create AMF APP: %s", e.what()); Logger::amf_app().error("Cannot create AMF APP: %s", e.what());
throw; throw;
} }
timer_id_t tid = itti_inst->timer_setup(amf_cfg.statistics_interval, 0, timer_id_t tid =
TASK_AMF_APP, itti_inst->timer_setup(amf_cfg.statistics_interval, 0, TASK_AMF_APP,
TASK_AMF_APP_PERIODIC_STATISTICS, TASK_AMF_APP_PERIODIC_STATISTICS, 0);
0);
Logger::amf_app().startup("Started timer(%d)", tid); Logger::amf_app().startup("Started timer(%d)", tid);
} }
...@@ -90,7 +89,7 @@ void amf_app::allRegistredModulesInit(const amf_modules &modules) { ...@@ -90,7 +89,7 @@ void amf_app::allRegistredModulesInit(const amf_modules &modules) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_app_task(void*) { void amf_app_task(void *) {
const task_id_t task_id = TASK_AMF_APP; const task_id_t task_id = TASK_AMF_APP;
itti_inst->notify_task_ready(task_id); itti_inst->notify_task_ready(task_id);
do { do {
...@@ -101,27 +100,24 @@ void amf_app_task(void*) { ...@@ -101,27 +100,24 @@ void amf_app_task(void*) {
case NAS_SIG_ESTAB_REQ: { case NAS_SIG_ESTAB_REQ: {
Logger::amf_app().debug("Received NAS_SIG_ESTAB_REQ"); Logger::amf_app().debug("Received NAS_SIG_ESTAB_REQ");
itti_nas_signalling_establishment_request *m = itti_nas_signalling_establishment_request *m =
dynamic_cast<itti_nas_signalling_establishment_request*>(msg); dynamic_cast<itti_nas_signalling_establishment_request *>(msg);
amf_app_inst->handle_itti_message(ref(*m)); amf_app_inst->handle_itti_message(ref(*m));
} } break;
break;
case N1N2_MESSAGE_TRANSFER_REQ: { case N1N2_MESSAGE_TRANSFER_REQ: {
Logger::amf_app().debug("Received N1N2_MESSAGE_TRANSFER_REQ"); Logger::amf_app().debug("Received N1N2_MESSAGE_TRANSFER_REQ");
itti_n1n2_message_transfer_request *m = itti_n1n2_message_transfer_request *m =
dynamic_cast<itti_n1n2_message_transfer_request*>(msg); dynamic_cast<itti_n1n2_message_transfer_request *>(msg);
amf_app_inst->handle_itti_message(ref(*m)); amf_app_inst->handle_itti_message(ref(*m));
} } break;
break;
case TIME_OUT: case TIME_OUT:
if (itti_msg_timeout *to = dynamic_cast<itti_msg_timeout*>(msg)) { if (itti_msg_timeout *to = dynamic_cast<itti_msg_timeout *>(msg)) {
switch (to->arg1_user) { switch (to->arg1_user) {
case TASK_AMF_APP_PERIODIC_STATISTICS: case TASK_AMF_APP_PERIODIC_STATISTICS:
tid = itti_inst->timer_setup(amf_cfg.statistics_interval, 0, tid = itti_inst->timer_setup(amf_cfg.statistics_interval, 0,
TASK_AMF_APP, TASK_AMF_APP,
TASK_AMF_APP_PERIODIC_STATISTICS, TASK_AMF_APP_PERIODIC_STATISTICS, 0);
0);
stacs.display(); stacs.display();
break; break;
default: default:
...@@ -147,7 +143,7 @@ long amf_app::generate_amf_ue_ngap_id() { ...@@ -147,7 +143,7 @@ long amf_app::generate_amf_ue_ngap_id() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool amf_app::is_amf_ue_id_2_ue_context(const long &amf_ue_ngap_id) const { bool amf_app::is_amf_ue_id_2_ue_context(const long &amf_ue_ngap_id) const {
std::shared_lock lock(m_amf_ue_ngap_id2ue_ctx); std::shared_lock lock(m_amf_ue_ngap_id2ue_ctx);
return bool { amf_ue_ngap_id2ue_ctx.count(amf_ue_ngap_id) > 0 }; return bool{amf_ue_ngap_id2ue_ctx.count(amf_ue_ngap_id) > 0};
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -167,7 +163,7 @@ void amf_app::set_amf_ue_ngap_id_2_ue_context(const long &amf_ue_ngap_id, ...@@ -167,7 +163,7 @@ void amf_app::set_amf_ue_ngap_id_2_ue_context(const long &amf_ue_ngap_id,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool amf_app::is_ran_amf_id_2_ue_context(const string &ue_context_key) const { bool amf_app::is_ran_amf_id_2_ue_context(const string &ue_context_key) const {
std::shared_lock lock(m_ue_ctx_key); std::shared_lock lock(m_ue_ctx_key);
return bool { ue_ctx_key.count(ue_context_key) > 0 }; return bool{ue_ctx_key.count(ue_context_key) > 0};
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -188,11 +184,11 @@ void amf_app::set_ran_amf_id_2_ue_context(const string &ue_context_key, ...@@ -188,11 +184,11 @@ void amf_app::set_ran_amf_id_2_ue_context(const string &ue_context_key,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_app::handle_itti_message( void amf_app::handle_itti_message(
itti_n1n2_message_transfer_request &itti_msg) { itti_n1n2_message_transfer_request &itti_msg) {
//1. encode DL NAS TRANSPORT message(NAS message) // 1. encode DL NAS TRANSPORT message(NAS message)
DLNASTransport *dl = new DLNASTransport(); DLNASTransport *dl = new DLNASTransport();
dl->setHeader(PLAIN_5GS_MSG); dl->setHeader(PLAIN_5GS_MSG);
dl->setPayload_Container_Type(N1_SM_INFORMATION); dl->setPayload_Container_Type(N1_SM_INFORMATION);
dl->setPayload_Container((uint8_t*) bdata(itti_msg.n1sm), dl->setPayload_Container((uint8_t *)bdata(itti_msg.n1sm),
blength(itti_msg.n1sm)); blength(itti_msg.n1sm));
dl->setPDUSessionId(itti_msg.pdu_session_id); dl->setPDUSessionId(itti_msg.pdu_session_id);
uint8_t nas[1024]; uint8_t nas[1024];
...@@ -200,8 +196,8 @@ void amf_app::handle_itti_message( ...@@ -200,8 +196,8 @@ void amf_app::handle_itti_message(
print_buffer("amf_app", "n1n2 transfer", nas, encoded_size); print_buffer("amf_app", "n1n2 transfer", nas, encoded_size);
bstring dl_nas = blk2bstr(nas, encoded_size); bstring dl_nas = blk2bstr(nas, encoded_size);
itti_downlink_nas_transfer *dl_msg = new itti_downlink_nas_transfer( itti_downlink_nas_transfer *dl_msg =
TASK_AMF_APP, TASK_AMF_N1); new itti_downlink_nas_transfer(TASK_AMF_APP, TASK_AMF_N1);
dl_msg->dl_nas = dl_nas; dl_msg->dl_nas = dl_nas;
if (!itti_msg.is_n2sm_set) { if (!itti_msg.is_n2sm_set) {
dl_msg->is_n2sm_set = false; dl_msg->is_n2sm_set = false;
...@@ -213,8 +209,8 @@ void amf_app::handle_itti_message( ...@@ -213,8 +209,8 @@ void amf_app::handle_itti_message(
} }
dl_msg->amf_ue_ngap_id = amf_n1_inst->supi2amfId.at(itti_msg.supi); dl_msg->amf_ue_ngap_id = amf_n1_inst->supi2amfId.at(itti_msg.supi);
dl_msg->ran_ue_ngap_id = amf_n1_inst->supi2ranId.at(itti_msg.supi); dl_msg->ran_ue_ngap_id = amf_n1_inst->supi2ranId.at(itti_msg.supi);
std::shared_ptr < itti_downlink_nas_transfer > i = std::shared_ptr std::shared_ptr<itti_downlink_nas_transfer> i =
< itti_downlink_nas_transfer > (dl_msg); std::shared_ptr<itti_downlink_nas_transfer>(dl_msg);
int ret = itti_inst->send_msg(i); int ret = itti_inst->send_msg(i);
if (0 != ret) { if (0 != ret) {
Logger::amf_app().error( Logger::amf_app().error(
...@@ -226,26 +222,26 @@ void amf_app::handle_itti_message( ...@@ -226,26 +222,26 @@ void amf_app::handle_itti_message(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_app::handle_itti_message( void amf_app::handle_itti_message(
itti_nas_signalling_establishment_request &itti_msg) { itti_nas_signalling_establishment_request &itti_msg) {
//1. generate amf_ue_ngap_id // 1. generate amf_ue_ngap_id
//2. establish ue_context associated with amf_ue_ngap_id // 2. establish ue_context associated with amf_ue_ngap_id
//3. store ue-reated core information // 3. store ue-reated core information
//4. send nas-pdu to task_amf_n1 // 4. send nas-pdu to task_amf_n1
long amf_ue_ngap_id = 0; long amf_ue_ngap_id = 0;
std::shared_ptr < ue_context > uc; std::shared_ptr<ue_context> uc;
//check ue context with 5g-s-tmsi // check ue context with 5g-s-tmsi
if ((amf_ue_ngap_id = itti_msg.amf_ue_ngap_id) == -1) { if ((amf_ue_ngap_id = itti_msg.amf_ue_ngap_id) == -1) {
amf_ue_ngap_id = generate_amf_ue_ngap_id(); amf_ue_ngap_id = generate_amf_ue_ngap_id();
} }
string ue_context_key = "app_ue_ranid_" + to_string(itti_msg.ran_ue_ngap_id) string ue_context_key = "app_ue_ranid_" + to_string(itti_msg.ran_ue_ngap_id) +
+ ":amfid_" + to_string(amf_ue_ngap_id); ":amfid_" + to_string(amf_ue_ngap_id);
//if(!is_amf_ue_id_2_ue_context(amf_ue_ngap_id)){ // if(!is_amf_ue_id_2_ue_context(amf_ue_ngap_id)){
if (!is_ran_amf_id_2_ue_context(ue_context_key)) { if (!is_ran_amf_id_2_ue_context(ue_context_key)) {
Logger::amf_app().debug( Logger::amf_app().debug(
"No existing UE Context, Create a new one with ran_amf_id %s", "No existing UE Context, Create a new one with ran_amf_id %s",
ue_context_key.c_str()); ue_context_key.c_str());
uc = std::shared_ptr < ue_context > (new ue_context()); uc = std::shared_ptr<ue_context>(new ue_context());
//set_amf_ue_ngap_id_2_ue_context(amf_ue_ngap_id, uc); // set_amf_ue_ngap_id_2_ue_context(amf_ue_ngap_id, uc);
set_ran_amf_id_2_ue_context(ue_context_key, uc); set_ran_amf_id_2_ue_context(ue_context_key, uc);
} }
if (uc.get() == nullptr) { if (uc.get() == nullptr) {
...@@ -255,8 +251,8 @@ void amf_app::handle_itti_message( ...@@ -255,8 +251,8 @@ void amf_app::handle_itti_message(
uc.get()->cgi = itti_msg.cgi; uc.get()->cgi = itti_msg.cgi;
uc.get()->tai = itti_msg.tai; uc.get()->tai = itti_msg.tai;
if (itti_msg.rrc_cause != -1) if (itti_msg.rrc_cause != -1)
uc.get()->rrc_estb_cause = (e_Ngap_RRCEstablishmentCause) itti_msg uc.get()->rrc_estb_cause =
.rrc_cause; (e_Ngap_RRCEstablishmentCause)itti_msg.rrc_cause;
if (itti_msg.ueCtxReq == -1) if (itti_msg.ueCtxReq == -1)
uc.get()->isUeContextRequest = false; uc.get()->isUeContextRequest = false;
else else
...@@ -267,14 +263,14 @@ void amf_app::handle_itti_message( ...@@ -267,14 +263,14 @@ void amf_app::handle_itti_message(
std::string guti; std::string guti;
bool is_guti_valid = false; bool is_guti_valid = false;
if (itti_msg.is_5g_s_tmsi_present) { if (itti_msg.is_5g_s_tmsi_present) {
guti = itti_msg.tai.mcc + itti_msg.tai.mnc + amf_cfg.guami.regionID guti = itti_msg.tai.mcc + itti_msg.tai.mnc + amf_cfg.guami.regionID +
+ itti_msg._5g_s_tmsi; itti_msg._5g_s_tmsi;
is_guti_valid = true; is_guti_valid = true;
Logger::amf_app().debug("Receiving GUTI %s", guti.c_str()); Logger::amf_app().debug("Receiving GUTI %s", guti.c_str());
} }
itti_uplink_nas_data_ind *itti_n1_msg = new itti_uplink_nas_data_ind( itti_uplink_nas_data_ind *itti_n1_msg =
TASK_AMF_APP, TASK_AMF_N1); new itti_uplink_nas_data_ind(TASK_AMF_APP, TASK_AMF_N1);
itti_n1_msg->amf_ue_ngap_id = amf_ue_ngap_id; itti_n1_msg->amf_ue_ngap_id = amf_ue_ngap_id;
itti_n1_msg->ran_ue_ngap_id = itti_msg.ran_ue_ngap_id; itti_n1_msg->ran_ue_ngap_id = itti_msg.ran_ue_ngap_id;
itti_n1_msg->is_nas_signalling_estab_req = true; itti_n1_msg->is_nas_signalling_estab_req = true;
...@@ -285,8 +281,8 @@ void amf_app::handle_itti_message( ...@@ -285,8 +281,8 @@ void amf_app::handle_itti_message(
if (is_guti_valid) { if (is_guti_valid) {
itti_n1_msg->guti = guti; itti_n1_msg->guti = guti;
} }
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_n1_msg); std::shared_ptr<itti_uplink_nas_data_ind>(itti_n1_msg);
int ret = itti_inst->send_msg(i); int ret = itti_inst->send_msg(i);
if (0 != ret) { if (0 != ret) {
Logger::amf_app().error( Logger::amf_app().error(
...@@ -296,7 +292,7 @@ void amf_app::handle_itti_message( ...@@ -296,7 +292,7 @@ void amf_app::handle_itti_message(
} }
} }
//SMF Client response handlers // SMF Client response handlers
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_app::handle_post_sm_context_response_error_400() { void amf_app::handle_post_sm_context_response_error_400() {
Logger::amf_app().error("Post SM context response error 400"); Logger::amf_app().error("Post SM context response error 400");
...@@ -304,14 +300,14 @@ void amf_app::handle_post_sm_context_response_error_400() { ...@@ -304,14 +300,14 @@ void amf_app::handle_post_sm_context_response_error_400() {
bool amf_app::generate_5g_guti(uint32_t ranid, long amfid, string &mcc, bool amf_app::generate_5g_guti(uint32_t ranid, long amfid, string &mcc,
string &mnc, uint32_t &tmsi) { string &mnc, uint32_t &tmsi) {
string ue_context_key = "app_ue_ranid_" + to_string(ranid) + ":amfid_" string ue_context_key =
+ to_string(amfid); "app_ue_ranid_" + to_string(ranid) + ":amfid_" + to_string(amfid);
if (!is_ran_amf_id_2_ue_context(ue_context_key)) { if (!is_ran_amf_id_2_ue_context(ue_context_key)) {
Logger::amf_app().error("No UE context for ran_amf_id %s, exit", Logger::amf_app().error("No UE context for ran_amf_id %s, exit",
ue_context_key.c_str()); ue_context_key.c_str());
return false; return false;
} }
std::shared_ptr < ue_context > uc; std::shared_ptr<ue_context> uc;
uc = ran_amf_id_2_ue_context(ue_context_key); uc = ran_amf_id_2_ue_context(ue_context_key);
mcc = uc.get()->tai.mcc; mcc = uc.get()->tai.mcc;
mnc = uc.get()->tai.mnc; mnc = uc.get()->tai.mnc;
......
...@@ -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
* *
...@@ -48,14 +48,14 @@ namespace amf_application { ...@@ -48,14 +48,14 @@ namespace amf_application {
class amf_app { class amf_app {
public: public:
explicit amf_app(const amf_config &amf_cfg); explicit amf_app(const amf_config &amf_cfg);
amf_app(amf_app const&) = delete; amf_app(amf_app const &) = delete;
void operator=(amf_app const&) = delete; void operator=(amf_app const &) = delete;
void allRegistredModulesInit(const amf_modules &modules); void allRegistredModulesInit(const amf_modules &modules);
long generate_amf_ue_ngap_id(); long generate_amf_ue_ngap_id();
//itti handlers // itti handlers
void handle_itti_message(itti_nas_signalling_establishment_request &itti_msg); void handle_itti_message(itti_nas_signalling_establishment_request &itti_msg);
void handle_itti_message(itti_n1n2_message_transfer_request &itti_msg); void handle_itti_message(itti_n1n2_message_transfer_request &itti_msg);
//context management // context management
std::map<long, std::shared_ptr<ue_context>> amf_ue_ngap_id2ue_ctx; std::map<long, std::shared_ptr<ue_context>> amf_ue_ngap_id2ue_ctx;
mutable std::shared_mutex m_amf_ue_ngap_id2ue_ctx; mutable std::shared_mutex m_amf_ue_ngap_id2ue_ctx;
std::map<std::string, std::shared_ptr<ue_context>> ue_ctx_key; std::map<std::string, std::shared_ptr<ue_context>> ue_ctx_key;
...@@ -74,11 +74,11 @@ class amf_app { ...@@ -74,11 +74,11 @@ class amf_app {
std::shared_ptr<ue_context> uc); std::shared_ptr<ue_context> uc);
// SMF Client response handlers // SMF Client response handlers
void handle_post_sm_context_response_error_400(); void handle_post_sm_context_response_error_400();
//others // others
bool generate_5g_guti(uint32_t ranid, long amfid, std::string &mcc, bool generate_5g_guti(uint32_t ranid, long amfid, std::string &mcc,
std::string &mnc, uint32_t &tmsi); std::string &mnc, uint32_t &tmsi);
}; };
} } // namespace amf_application
#endif #endif
...@@ -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
* *
...@@ -37,10 +37,10 @@ ...@@ -37,10 +37,10 @@
#include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/split.hpp>
#include "logger.hpp" #include "3gpp_ts24501.hpp"
#include "amf_app.hpp" #include "amf_app.hpp"
#include "if.hpp" #include "if.hpp"
#include "3gpp_ts24501.hpp" #include "logger.hpp"
extern "C" { extern "C" {
#include <arpa/inet.h> #include <arpa/inet.h>
...@@ -57,12 +57,11 @@ namespace config { ...@@ -57,12 +57,11 @@ namespace config {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
amf_config::amf_config() { amf_config::amf_config() {
//TODO: // TODO:
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
amf_config::~amf_config() { amf_config::~amf_config() {}
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int amf_config::load(const std::string &config_file) { int amf_config::load(const std::string &config_file) {
...@@ -126,7 +125,8 @@ int amf_config::load(const std::string &config_file) { ...@@ -126,7 +125,8 @@ int amf_config::load(const std::string &config_file) {
nfex.getPath()); nfex.getPath());
} }
try { try {
const Setting &guami_list_cfg = amf_cfg[AMF_CONFIG_STRING_SERVED_GUAMI_LIST]; const Setting &guami_list_cfg =
amf_cfg[AMF_CONFIG_STRING_SERVED_GUAMI_LIST];
int count = guami_list_cfg.getLength(); int count = guami_list_cfg.getLength();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
guami_t guami; guami_t guami;
...@@ -176,11 +176,13 @@ int amf_config::load(const std::string &config_file) { ...@@ -176,11 +176,13 @@ int amf_config::load(const std::string &config_file) {
} }
try { try {
const Setting &new_if_cfg = amf_cfg[AMF_CONFIG_STRING_INTERFACES]; const Setting &new_if_cfg = amf_cfg[AMF_CONFIG_STRING_INTERFACES];
const Setting &n2_amf_cfg = new_if_cfg[AMF_CONFIG_STRING_INTERFACE_NGAP_AMF]; const Setting &n2_amf_cfg =
new_if_cfg[AMF_CONFIG_STRING_INTERFACE_NGAP_AMF];
load_interface(n2_amf_cfg, n2); load_interface(n2_amf_cfg, n2);
const Setting &n11_cfg = new_if_cfg[AMF_CONFIG_STRING_INTERFACE_N11]; const Setting &n11_cfg = new_if_cfg[AMF_CONFIG_STRING_INTERFACE_N11];
load_interface(n11_cfg, n11); load_interface(n11_cfg, n11);
const Setting &smf_addr_pool = n11_cfg[AMF_CONFIG_STRING_SMF_INSTANCES_POOL]; const Setting &smf_addr_pool =
n11_cfg[AMF_CONFIG_STRING_SMF_INSTANCES_POOL];
int count = smf_addr_pool.getLength(); int count = smf_addr_pool.getLength();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
const Setting &smf_addr_item = smf_addr_pool[i]; const Setting &smf_addr_item = smf_addr_pool[i];
...@@ -291,11 +293,10 @@ void amf_config::display() { ...@@ -291,11 +293,10 @@ void amf_config::display() {
Logger::config().info( Logger::config().info(
"- SERVED_GUAMI_LIST...................................: "); "- SERVED_GUAMI_LIST...................................: ");
for (int i = 0; i < guami_list.size(); i++) { for (int i = 0; i < guami_list.size(); i++) {
Logger::config().info(" (%s, %s, %s , %s, %s)", guami_list[i].mcc.c_str(), Logger::config().info(
guami_list[i].mnc.c_str(), " (%s, %s, %s , %s, %s)", guami_list[i].mcc.c_str(),
guami_list[i].regionID.c_str(), guami_list[i].mnc.c_str(), guami_list[i].regionID.c_str(),
guami_list[i].AmfSetID.c_str(), guami_list[i].AmfSetID.c_str(), guami_list[i].AmfPointer.c_str());
guami_list[i].AmfPointer.c_str());
} }
Logger::config().info( Logger::config().info(
"- RELATIVE_CAPACITY...................................: %d", "- RELATIVE_CAPACITY...................................: %d",
...@@ -345,7 +346,7 @@ void amf_config::display() { ...@@ -345,7 +346,7 @@ void amf_config::display() {
Logger::config().info(" iface ................: %s", n11.if_name.c_str()); Logger::config().info(" iface ................: %s", n11.if_name.c_str());
Logger::config().info(" ip ...................: %s", inet_ntoa(n11.addr4)); Logger::config().info(" ip ...................: %s", inet_ntoa(n11.addr4));
Logger::config().info(" port .................: %d", n11.port); Logger::config().info(" port .................: %d", n11.port);
// Logger::config().info(" HTTP2 port ............: %d", n11_http2_port); // Logger::config().info(" HTTP2 port ............: %d", n11_http2_port);
Logger::config().info( Logger::config().info(
"- Remote SMF Pool.....................................: "); "- Remote SMF Pool.....................................: ");
...@@ -368,7 +369,7 @@ int amf_config::load_interface(const libconfig::Setting &if_cfg, ...@@ -368,7 +369,7 @@ int amf_config::load_interface(const libconfig::Setting &if_cfg,
if_cfg.lookupValue(AMF_CONFIG_STRING_INTERFACE_NAME, cfg.if_name); if_cfg.lookupValue(AMF_CONFIG_STRING_INTERFACE_NAME, cfg.if_name);
util::trim(cfg.if_name); util::trim(cfg.if_name);
if (not boost::iequals(cfg.if_name, "none")) { if (not boost::iequals(cfg.if_name, "none")) {
std::string address = { }; std::string address = {};
if_cfg.lookupValue(AMF_CONFIG_STRING_IPV4_ADDRESS, address); if_cfg.lookupValue(AMF_CONFIG_STRING_IPV4_ADDRESS, address);
util::trim(address); util::trim(address);
if (boost::iequals(address, "read")) { if (boost::iequals(address, "read")) {
...@@ -376,31 +377,32 @@ int amf_config::load_interface(const libconfig::Setting &if_cfg, ...@@ -376,31 +377,32 @@ int amf_config::load_interface(const libconfig::Setting &if_cfg,
cfg.mtu)) { cfg.mtu)) {
Logger::amf_app().error( Logger::amf_app().error(
"Could not read %s network interface configuration", cfg.if_name); "Could not read %s network interface configuration", cfg.if_name);
return RETURNerror ; return RETURNerror;
} }
} else { } else {
std::vector < std::string > words; std::vector<std::string> words;
boost::split(words, address, boost::is_any_of("/"), boost::split(words, address, boost::is_any_of("/"),
boost::token_compress_on); boost::token_compress_on);
if (words.size() != 2) { if (words.size() != 2) {
Logger::amf_app().error( Logger::amf_app().error("Bad value " AMF_CONFIG_STRING_IPV4_ADDRESS
"Bad value " AMF_CONFIG_STRING_IPV4_ADDRESS " = %s in config file", " = %s in config file",
address.c_str()); address.c_str());
return RETURNerror ; return RETURNerror;
} }
unsigned char buf_in_addr[sizeof(struct in6_addr)]; // you never know... unsigned char buf_in_addr[sizeof(struct in6_addr)]; // you never know...
if (inet_pton(AF_INET, util::trim(words.at(0)).c_str(), buf_in_addr) if (inet_pton(AF_INET, util::trim(words.at(0)).c_str(), buf_in_addr) ==
== 1) { 1) {
memcpy(&cfg.addr4, buf_in_addr, sizeof(struct in_addr)); memcpy(&cfg.addr4, buf_in_addr, sizeof(struct in_addr));
} else { } else {
Logger::amf_app().error( Logger::amf_app().error(
"In conversion: Bad value " AMF_CONFIG_STRING_IPV4_ADDRESS " = %s in config file", "In conversion: Bad value " AMF_CONFIG_STRING_IPV4_ADDRESS
" = %s in config file",
util::trim(words.at(0)).c_str()); util::trim(words.at(0)).c_str());
return RETURNerror ; return RETURNerror;
} }
cfg.network4.s_addr = htons( cfg.network4.s_addr =
ntohs(cfg.addr4.s_addr) htons(ntohs(cfg.addr4.s_addr) &
& 0xFFFFFFFF << (32 - std::stoi(util::trim(words.at(1))))); 0xFFFFFFFF << (32 - std::stoi(util::trim(words.at(1)))));
} }
if_cfg.lookupValue(AMF_CONFIG_STRING_PORT, cfg.port); if_cfg.lookupValue(AMF_CONFIG_STRING_PORT, cfg.port);
...@@ -412,13 +414,12 @@ int amf_config::load_interface(const libconfig::Setting &if_cfg, ...@@ -412,13 +414,12 @@ int amf_config::load_interface(const libconfig::Setting &if_cfg,
nfex.getPath()); nfex.getPath());
} }
} }
return RETURNok ; return RETURNok;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int amf_config::load_thread_sched_params(const Setting &thread_sched_params_cfg, int amf_config::load_thread_sched_params(const Setting &thread_sched_params_cfg,
util::thread_sched_params &cfg) { util::thread_sched_params &cfg) {
try { try {
thread_sched_params_cfg.lookupValue(AMF_CONFIG_STRING_THREAD_RD_CPU_ID, thread_sched_params_cfg.lookupValue(AMF_CONFIG_STRING_THREAD_RD_CPU_ID,
cfg.cpu_id); cfg.cpu_id);
...@@ -429,8 +430,7 @@ int amf_config::load_thread_sched_params(const Setting &thread_sched_params_cfg, ...@@ -429,8 +430,7 @@ int amf_config::load_thread_sched_params(const Setting &thread_sched_params_cfg,
try { try {
std::string thread_rd_sched_policy; std::string thread_rd_sched_policy;
thread_sched_params_cfg.lookupValue( thread_sched_params_cfg.lookupValue(
AMF_CONFIG_STRING_THREAD_RD_SCHED_POLICY, AMF_CONFIG_STRING_THREAD_RD_SCHED_POLICY, thread_rd_sched_policy);
thread_rd_sched_policy);
util::trim(thread_rd_sched_policy); util::trim(thread_rd_sched_policy);
if (boost::iequals(thread_rd_sched_policy, "SCHED_OTHER")) { if (boost::iequals(thread_rd_sched_policy, "SCHED_OTHER")) {
cfg.sched_policy = SCHED_OTHER; cfg.sched_policy = SCHED_OTHER;
...@@ -446,7 +446,7 @@ int amf_config::load_thread_sched_params(const Setting &thread_sched_params_cfg, ...@@ -446,7 +446,7 @@ int amf_config::load_thread_sched_params(const Setting &thread_sched_params_cfg,
Logger::amf_app().error( Logger::amf_app().error(
"thread_rd_sched_policy: %s, unknown in config file", "thread_rd_sched_policy: %s, unknown in config file",
thread_rd_sched_policy.c_str()); thread_rd_sched_policy.c_str());
return RETURNerror ; return RETURNerror;
} }
} catch (const SettingNotFoundException &nfex) { } catch (const SettingNotFoundException &nfex) {
Logger::amf_app().info("%s : %s, using defaults", nfex.what(), Logger::amf_app().info("%s : %s, using defaults", nfex.what(),
...@@ -455,19 +455,19 @@ int amf_config::load_thread_sched_params(const Setting &thread_sched_params_cfg, ...@@ -455,19 +455,19 @@ int amf_config::load_thread_sched_params(const Setting &thread_sched_params_cfg,
try { try {
thread_sched_params_cfg.lookupValue( thread_sched_params_cfg.lookupValue(
AMF_CONFIG_STRING_THREAD_RD_SCHED_PRIORITY, AMF_CONFIG_STRING_THREAD_RD_SCHED_PRIORITY, cfg.sched_priority);
cfg.sched_priority);
if ((cfg.sched_priority > 99) || (cfg.sched_priority < 1)) { if ((cfg.sched_priority > 99) || (cfg.sched_priority < 1)) {
Logger::amf_app().error( Logger::amf_app().error(
"thread_rd_sched_priority: %d, must be in interval [1..99] in config file", "thread_rd_sched_priority: %d, must be in interval [1..99] in config "
"file",
cfg.sched_priority); cfg.sched_priority);
return RETURNerror ; return RETURNerror;
} }
} catch (const SettingNotFoundException &nfex) { } catch (const SettingNotFoundException &nfex) {
Logger::amf_app().info("%s : %s, using defaults", nfex.what(), Logger::amf_app().info("%s : %s, using defaults", nfex.what(),
nfex.getPath()); nfex.getPath());
} }
return RETURNok ; return RETURNok;
} }
} } // namespace config
...@@ -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
* *
...@@ -180,6 +180,6 @@ class amf_config { ...@@ -180,6 +180,6 @@ class amf_config {
std::vector<smf_inst_t> smf_pool; std::vector<smf_inst_t> smf_pool;
}; };
} } // namespace config
#endif #endif
...@@ -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
* *
...@@ -72,7 +72,7 @@ int amf_modules::load(const std::string &config_file) { ...@@ -72,7 +72,7 @@ int amf_modules::load(const std::string &config_file) {
procedure_code); procedure_code);
item.lookupValue(MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_TYPEOFMSG, item.lookupValue(MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_TYPEOFMSG,
typeOfMessage); typeOfMessage);
procedureCode = (Ngap_ProcedureCode_t) procedure_code; procedureCode = (Ngap_ProcedureCode_t)procedure_code;
if (!(typeOfMessage.compare("initialMessage"))) { if (!(typeOfMessage.compare("initialMessage"))) {
typeOfMsg = Ngap_NGAP_PDU_PR_initiatingMessage; typeOfMsg = Ngap_NGAP_PDU_PR_initiatingMessage;
} else if (!(typeOfMessage.compare("successfuloutcome"))) { } else if (!(typeOfMessage.compare("successfuloutcome"))) {
...@@ -93,4 +93,4 @@ void amf_modules::display() { ...@@ -93,4 +93,4 @@ void amf_modules::display() {
msgName.c_str(), procedureCode, typeOfMsg); msgName.c_str(), procedureCode, typeOfMsg);
} }
} } // namespace config
...@@ -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
* *
...@@ -29,18 +29,19 @@ ...@@ -29,18 +29,19 @@
#ifndef _AMF_MODULE_FROM_CONFIG_H_ #ifndef _AMF_MODULE_FROM_CONFIG_H_
#define _AMF_MODULE_FROM_CONFIG_H_ #define _AMF_MODULE_FROM_CONFIG_H_
#include <libconfig.h++>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/split.hpp>
#include <libconfig.h++>
#include "Ngap_ProcedureCode.h"
#include "Ngap_NGAP-PDU.h" #include "Ngap_NGAP-PDU.h"
#include "Ngap_ProcedureCode.h"
#define MODULES_CONFIG_STRING_AMF_MODULES "MODULES" #define MODULES_CONFIG_STRING_AMF_MODULES "MODULES"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE "NGAP_MESSAGE" #define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE "NGAP_MESSAGE"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_NAME "MSG_NAME" #define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_NAME "MSG_NAME"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_PROCEDURECODE "ProcedureCode" #define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_PROCEDURECODE \
"ProcedureCode"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_TYPEOFMSG "TypeOfMessage" #define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_TYPEOFMSG "TypeOfMessage"
using namespace libconfig; using namespace libconfig;
...@@ -52,13 +53,13 @@ class amf_modules { ...@@ -52,13 +53,13 @@ class amf_modules {
int load(const std::string &config_file); int load(const std::string &config_file);
void display(); void display();
void makeModulesAlive(); void makeModulesAlive();
private: private:
std::string msgName; //vector to store more msgs std::string msgName; // vector to store more msgs
Ngap_NGAP_PDU_PR typeOfMsg; Ngap_NGAP_PDU_PR typeOfMsg;
Ngap_ProcedureCode_t procedureCode; Ngap_ProcedureCode_t procedureCode;
// NGSetupRequestMsg *ngSetupRequest; // NGSetupRequestMsg *ngSetupRequest;
}; };
} } // namespace config
#endif #endif
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
* *
...@@ -29,20 +29,20 @@ ...@@ -29,20 +29,20 @@
#ifndef _AMF_N1_H_ #ifndef _AMF_N1_H_
#define _AMF_N1_H_ #define _AMF_N1_H_
#include <map> #include <mysql/mysql.h>
#include <shared_mutex>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <mysql/mysql.h> #include <map>
#include <shared_mutex>
#include "nas_context.hpp"
#include "pdu_session_context.hpp"
#include "itti_msg_n1.hpp"
#include "bstrlib.h"
#include "3gpp_ts24501.hpp" #include "3gpp_ts24501.hpp"
#include "amf_statistics.hpp"
#include "amf.hpp" #include "amf.hpp"
#include "amf_statistics.hpp"
#include "bstrlib.h"
#include "itti_msg_n1.hpp"
#include "mysql_db.hpp" #include "mysql_db.hpp"
#include "nas_context.hpp"
#include "pdu_session_context.hpp"
namespace amf_application { namespace amf_application {
...@@ -61,7 +61,7 @@ class amf_n1 { ...@@ -61,7 +61,7 @@ class amf_n1 {
public: public:
amf_n1(); amf_n1();
~amf_n1(); ~amf_n1();
void handle_itti_message(itti_uplink_nas_data_ind&); void handle_itti_message(itti_uplink_nas_data_ind &);
void handle_itti_message(itti_downlink_nas_transfer &itti_msg); void handle_itti_message(itti_downlink_nas_transfer &itti_msg);
// nas message decode // nas message decode
void nas_signalling_establishment_request_handle( void nas_signalling_establishment_request_handle(
...@@ -74,7 +74,8 @@ class amf_n1 { ...@@ -74,7 +74,8 @@ class amf_n1 {
bstring plain_msg, plmn_t plmn); bstring plain_msg, plmn_t plmn);
bool check_security_header_type(SecurityHeaderType &type, uint8_t *buffer); bool check_security_header_type(SecurityHeaderType &type, uint8_t *buffer);
std::map<long, std::shared_ptr<nas_context>> amfueid2nas_context; // amf ue ngap id std::map<long, std::shared_ptr<nas_context>>
amfueid2nas_context; // amf ue ngap id
std::map<std::string, std::shared_ptr<nas_context>> imsi2nas_context; std::map<std::string, std::shared_ptr<nas_context>> imsi2nas_context;
std::map<std::string, long> supi2amfId; std::map<std::string, long> supi2amfId;
std::map<std::string, uint32_t> supi2ranId; std::map<std::string, uint32_t> supi2ranId;
...@@ -97,18 +98,18 @@ class amf_n1 { ...@@ -97,18 +98,18 @@ class amf_n1 {
std::shared_ptr<nas_context> nc); std::shared_ptr<nas_context> nc);
database_t *db_desc; database_t *db_desc;
//procedures // procedures
void run_registration_procedure(std::shared_ptr<nas_context> &nc); void run_registration_procedure(std::shared_ptr<nas_context> &nc);
void run_initial_registration_procedure(); void run_initial_registration_procedure();
void run_mobility_registration_update_procedure( void run_mobility_registration_update_procedure(
std::shared_ptr<nas_context> nc); std::shared_ptr<nas_context> nc);
//authentication // authentication
bool auth_vectors_generator(std::shared_ptr<nas_context> &nc); bool auth_vectors_generator(std::shared_ptr<nas_context> &nc);
bool authentication_vectors_generator_in_ausf( bool authentication_vectors_generator_in_ausf(
std::shared_ptr<nas_context> &nc); std::shared_ptr<nas_context> &nc);
bool authentication_vectors_generator_in_udm( bool authentication_vectors_generator_in_udm(
std::shared_ptr<nas_context> &nc); std::shared_ptr<nas_context> &nc);
//mysql handlers in mysql_db.cpp // mysql handlers in mysql_db.cpp
bool get_mysql_auth_info(std::string imsi, mysql_auth_info_t &resp); bool get_mysql_auth_info(std::string imsi, mysql_auth_info_t &resp);
void mysql_push_rand_sqn(std::string imsi, uint8_t *rand_p, uint8_t *sqn); void mysql_push_rand_sqn(std::string imsi, uint8_t *rand_p, uint8_t *sqn);
void mysql_increment_sqn(std::string imsi); void mysql_increment_sqn(std::string imsi);
...@@ -152,7 +153,7 @@ class amf_n1 { ...@@ -152,7 +153,7 @@ class amf_n1 {
void set_5gmm_state(std::shared_ptr<nas_context> nc, _5gmm_state_t state); void set_5gmm_state(std::shared_ptr<nas_context> nc, _5gmm_state_t state);
void get_5gmm_state(std::shared_ptr<nas_context> nc, _5gmm_state_t &state); void get_5gmm_state(std::shared_ptr<nas_context> nc, _5gmm_state_t &state);
private: //nas message handlers private: // nas message handlers
void ue_initiate_de_registration_handle(uint32_t ran_ue_ngap_id, void ue_initiate_de_registration_handle(uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id, bstring nas); long amf_ue_ngap_id, bstring nas);
void registration_request_handle(bool isNasSig, void registration_request_handle(bool isNasSig,
...@@ -178,15 +179,15 @@ class amf_n1 { ...@@ -178,15 +179,15 @@ class amf_n1 {
void identity_response_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, void identity_response_handle(uint32_t ran_ue_ngap_id, long amf_ue_ngap_id,
bstring plain_msg); bstring plain_msg);
//authentication vector // authentication vector
bool generate_authentication_vector(); bool generate_authentication_vector();
void itti_send_dl_nas_buffer_to_task_n2(bstring &b, uint32_t ran_ue_ngap_id, void itti_send_dl_nas_buffer_to_task_n2(bstring &b, uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id); long amf_ue_ngap_id);
//response message // response message
void response_registration_reject_msg(uint8_t cause_value, void response_registration_reject_msg(uint8_t cause_value,
uint32_t ran_ue_ngap_id, uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id); long amf_ue_ngap_id);
}; };
} } // namespace amf_application
#endif #endif
...@@ -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
* *
...@@ -31,18 +31,18 @@ ...@@ -31,18 +31,18 @@
#include <curl/curl.h> #include <curl/curl.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "3gpp_ts24501.hpp"
#include "amf.hpp"
#include "amf_config.hpp"
#include "amf_n1.hpp" #include "amf_n1.hpp"
#include "itti.hpp" #include "itti.hpp"
#include "itti_msg_amf_app.hpp" #include "itti_msg_amf_app.hpp"
#include "amf_config.hpp"
#include "nas_context.hpp" #include "nas_context.hpp"
#include "amf.hpp"
#include "3gpp_ts24501.hpp"
// For smf_client // For smf_client
#include "SmContextCreateData.h"
#include "SMContextsCollectionApi.h"
#include "ApiConfiguration.h"
#include "ApiClient.h" #include "ApiClient.h"
#include "ApiConfiguration.h"
#include "SMContextsCollectionApi.h"
#include "SmContextCreateData.h"
#include "mime_parser.hpp" #include "mime_parser.hpp"
extern "C" { extern "C" {
...@@ -68,8 +68,8 @@ extern void print_buffer(const std::string app, const std::string commit, ...@@ -68,8 +68,8 @@ extern void print_buffer(const std::string app, const std::string commit,
uint8_t *buf, int len); uint8_t *buf, int len);
extern bool multipart_parser(std::string input, std::string &jsonData, extern bool multipart_parser(std::string input, std::string &jsonData,
std::string &n1sm, std::string &n2sm); 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(const char *in, std::size_t size, std::size_t num,
...@@ -82,7 +82,7 @@ std::size_t callback(const char *in, std::size_t size, std::size_t num, ...@@ -82,7 +82,7 @@ std::size_t callback(const char *in, std::size_t size, std::size_t num,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
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]);
} }
...@@ -95,9 +95,9 @@ void octet_stream_2_hex_stream(uint8_t *buf, int len, std::string &out) { ...@@ -95,9 +95,9 @@ void octet_stream_2_hex_stream(uint8_t *buf, int len, std::string &out) {
/** used to run NF(s) consumer, like smf_client ****/ /** used to run NF(s) consumer, like smf_client ****/
/***************************************************/ /***************************************************/
void amf_n11_task(void*); void amf_n11_task(void *);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n11_task(void*) { void amf_n11_task(void *) {
const task_id_t task_id = TASK_AMF_N11; const task_id_t task_id = TASK_AMF_N11;
itti_inst->notify_task_ready(task_id); itti_inst->notify_task_ready(task_id);
do { do {
...@@ -107,26 +107,23 @@ void amf_n11_task(void*) { ...@@ -107,26 +107,23 @@ void amf_n11_task(void*) {
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("Receive unknown message type %d",
msg->msg_type); msg->msg_type);
...@@ -146,21 +143,20 @@ amf_n11::amf_n11() { ...@@ -146,21 +143,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)) {
...@@ -183,7 +179,7 @@ void amf_n11::handle_itti_message( ...@@ -183,7 +179,7 @@ void amf_n11::handle_itti_message(
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);
...@@ -198,13 +194,13 @@ void amf_n11::handle_itti_message( ...@@ -198,13 +194,13 @@ 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"] = "n2msg"; pdu_session_update_request["n2SmInfo"]["contentId"] = "n2msg";
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((uint8_t *)bdata(itti_msg.n2sm),
blength(itti_msg.n2sm), n2SmMsg); blength(itti_msg.n2sm), n2SmMsg);
curl_http_client(remote_uri, json_part, "", n2SmMsg, supi, curl_http_client(remote_uri, json_part, "", n2SmMsg, supi,
itti_msg.pdu_session_id); itti_msg.pdu_session_id);
...@@ -213,7 +209,7 @@ void amf_n11::handle_itti_message( ...@@ -213,7 +209,7 @@ void amf_n11::handle_itti_message(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
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;
...@@ -221,7 +217,7 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) { ...@@ -221,7 +217,7 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) {
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);
} }
...@@ -235,12 +231,12 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) { ...@@ -235,12 +231,12 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) {
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);
} }
Logger::amf_n11().debug("Requested DNN: %s", dnn.c_str()); Logger::amf_n11().debug("Requested DNN: %s", dnn.c_str());
...@@ -258,8 +254,8 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) { ...@@ -258,8 +254,8 @@ 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);
...@@ -269,8 +265,8 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) { ...@@ -269,8 +265,8 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) {
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);
...@@ -278,8 +274,8 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) { ...@@ -278,8 +274,8 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) {
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(
...@@ -291,18 +287,16 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) { ...@@ -291,18 +287,16 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer &smf) {
handle_pdu_session_initial_request(supi, psc, smf_addr, smf.sm_msg, handle_pdu_session_initial_request(supi, psc, smf_addr, smf.sm_msg,
dnn); 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
// release request
send_pdu_session_update_sm_context_request(supi, psc, smf_addr, send_pdu_session_update_sm_context_request(supi, psc, smf_addr,
smf.sm_msg, dnn); smf.sm_msg, dnn);
} }
...@@ -314,11 +308,12 @@ void amf_n11::send_pdu_session_update_sm_context_request( ...@@ -314,11 +308,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);
...@@ -333,12 +328,12 @@ void amf_n11::send_pdu_session_update_sm_context_request( ...@@ -333,12 +328,12 @@ 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(remote_uri, json_part, n1SmMsg, "", supi,
psc.get()->pdu_session_id); psc.get()->pdu_session_id);
} }
...@@ -351,8 +346,8 @@ void amf_n11::handle_pdu_session_initial_request( ...@@ -351,8 +346,8 @@ 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";
...@@ -361,24 +356,25 @@ void amf_n11::handle_pdu_session_initial_request( ...@@ -361,24 +356,25 @@ void amf_n11::handle_pdu_session_initial_request(
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"]["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"] =
.mcc; psc.get()->plmn.mcc;
pdu_session_establishment_request["servingNetwork"]["mnc"] = psc.get()->plmn pdu_session_establishment_request["servingNetwork"]["mnc"] =
.mnc; psc.get()->plmn.mnc;
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(remote_uri, json_part, n1SmMsg, "", supi,
psc.get()->pdu_session_id); psc.get()->pdu_session_id);
} }
...@@ -410,11 +406,11 @@ void amf_n11::handle_itti_message( ...@@ -410,11 +406,11 @@ void amf_n11::handle_itti_message(
psc.get()->pdu_session_id); 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(
...@@ -430,12 +426,13 @@ void amf_n11::set_supi_to_pdu_ctx(const string &supi, ...@@ -430,12 +426,13 @@ void amf_n11::set_supi_to_pdu_ctx(const string &supi,
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;
} }
...@@ -445,13 +442,12 @@ bool amf_n11::smf_selection_from_configuration(std::string &smf_addr) { ...@@ -445,13 +442,12 @@ 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(long code,
...@@ -459,15 +455,15 @@ void amf_n11::handle_post_sm_context_response_error(long code, ...@@ -459,15 +455,15 @@ void amf_n11::handle_post_sm_context_response_error(long code,
bstring n1sm, bstring n1sm,
std::string supi, std::string supi,
uint8_t pdu_session_id) { 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(
...@@ -483,7 +479,7 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, ...@@ -483,7 +479,7 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData,
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;
...@@ -492,20 +488,20 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, ...@@ -492,20 +488,20 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData,
} else { } else {
Logger::amf_n11().warn("PDU Session context for SUPI %s doesn't exit!", Logger::amf_n11().warn("PDU Session context for SUPI %s doesn't exit!",
supi.c_str()); 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(body, jsonData, CURL_MIME_BOUNDARY,
n1SmMsg, n2SmMsg); 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);
...@@ -515,19 +511,19 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, ...@@ -515,19 +511,19 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData,
body.c_str()); 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());
...@@ -536,9 +532,9 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, ...@@ -536,9 +532,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);
...@@ -551,20 +547,20 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, ...@@ -551,20 +547,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("Cannot get response when calling %s",
remoteUri.c_str()); 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;
...@@ -574,18 +570,18 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, ...@@ -574,18 +570,18 @@ 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;
} }
...@@ -593,15 +589,18 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, ...@@ -593,15 +589,18 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData,
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("Get response with jsonData: %s",
json_data_response.c_str()); 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(
...@@ -610,8 +609,9 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, ...@@ -610,8 +609,9 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData,
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(httpCode, cause, n1sm_hex, supi,
pdu_session_id); 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");
...@@ -627,14 +627,14 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, ...@@ -627,14 +627,14 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData,
} }
} }
//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 =
...@@ -642,25 +642,27 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, ...@@ -642,25 +642,27 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData,
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("amf_n11",
(uint8_t*) bdata(n1sm_hex), blength(n1sm_hex)); "Get response n1sm:", (uint8_t *)bdata(n1sm_hex),
blength(n1sm_hex));
itti_msg->n1sm = 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("amf_n11",
(uint8_t*) bdata(n2sm_hex), blength(n2sm_hex)); "Get response n2sm:", (uint8_t *)bdata(n2sm_hex),
blength(n2sm_hex));
itti_msg->n2sm = n2sm_hex; itti_msg->n2sm = n2sm_hex;
itti_msg->is_n2sm_set = true; itti_msg->is_n2sm_set = true;
itti_msg->n2sm_info_type = response_data["n2SmInfoType"]; //response_data["n2InfoContainer"]["smInfo"]["n2InfoContent"]["ngapIeType"]; 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(
...@@ -675,5 +677,5 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData, ...@@ -675,5 +677,5 @@ void amf_n11::curl_http_client(std::string remoteUri, std::string jsonData,
} }
curl_global_cleanup(); curl_global_cleanup();
free_wrapper((void**) &body_data); free_wrapper((void **)&body_data);
} }
...@@ -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
* *
...@@ -43,7 +43,7 @@ class amf_n11 { ...@@ -43,7 +43,7 @@ class amf_n11 {
amf_n11(); amf_n11();
~amf_n11(); ~amf_n11();
void handle_itti_message(itti_smf_services_consumer&); void handle_itti_message(itti_smf_services_consumer &);
void handle_pdu_session_initial_request( void handle_pdu_session_initial_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);
...@@ -54,7 +54,8 @@ class amf_n11 { ...@@ -54,7 +54,8 @@ class amf_n11 {
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);
std::map<std::string, std::shared_ptr<pdu_session_context>> supi2pdu; // amf ue ngap id std::map<std::string, std::shared_ptr<pdu_session_context>>
supi2pdu; // amf ue ngap id
mutable std::shared_mutex m_supi2pdu; mutable std::shared_mutex m_supi2pdu;
bool is_supi_to_pdu_ctx(const std::string &supi) const; bool is_supi_to_pdu_ctx(const std::string &supi) const;
std::shared_ptr<pdu_session_context> supi_to_pdu_ctx( std::shared_ptr<pdu_session_context> supi_to_pdu_ctx(
...@@ -75,6 +76,6 @@ class amf_n11 { ...@@ -75,6 +76,6 @@ class amf_n11 {
std::string supi, uint8_t pdu_session_id); std::string supi, uint8_t pdu_session_id);
}; };
} } // namespace amf_application
#endif #endif
...@@ -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
* *
...@@ -28,28 +28,28 @@ ...@@ -28,28 +28,28 @@
#include "amf_n2.hpp" #include "amf_n2.hpp"
#include "amf_n1.hpp"
#include "amf_n11.hpp"
#include "amf_app.hpp"
#include "logger.hpp"
#include "sctp_server.hpp"
#include "itti.hpp"
#include "itti_msg_amf_app.hpp"
#include "amf_config.hpp"
#include "DefaultPagingDRX.hpp" #include "DefaultPagingDRX.hpp"
#include "DownLinkNasTransport.hpp"
#include "InitialContextSetupRequest.hpp"
#include "NGSetupFailure.hpp" #include "NGSetupFailure.hpp"
#include "NGSetupResponse.hpp" #include "NGSetupResponse.hpp"
#include "Ngap_Cause.h"
#include "Ngap_CauseNas.h"
#include "Ngap_CauseRadioNetwork.h"
#include "Ngap_TimeToWait.h"
#include "PDUSessionResourceHandoverCommandTransfer.hpp" #include "PDUSessionResourceHandoverCommandTransfer.hpp"
#include "DownLinkNasTransport.hpp"
#include "InitialContextSetupRequest.hpp"
#include "PduSessionResourceSetupRequest.hpp"
#include "PduSessionResourceReleaseCommand.hpp" #include "PduSessionResourceReleaseCommand.hpp"
#include "PduSessionResourceSetupRequest.hpp"
#include "UEContextReleaseCommand.hpp" #include "UEContextReleaseCommand.hpp"
#include "amf_app.hpp"
#include "amf_config.hpp"
#include "amf_n1.hpp"
#include "amf_n11.hpp"
#include "amf_statistics.hpp" #include "amf_statistics.hpp"
#include "Ngap_Cause.h" #include "itti.hpp"
#include "Ngap_CauseRadioNetwork.h" #include "itti_msg_amf_app.hpp"
#include "Ngap_TimeToWait.h" #include "logger.hpp"
#include "Ngap_CauseNas.h" #include "sctp_server.hpp"
extern "C" { extern "C" {
#include "dynamic_memory_check.h" #include "dynamic_memory_check.h"
...@@ -59,14 +59,15 @@ using namespace amf_application; ...@@ -59,14 +59,15 @@ 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;
...@@ -76,131 +77,115 @@ sctp_assoc_id_t source_assoc_id = 0; ...@@ -76,131 +77,115 @@ sctp_assoc_id_t source_assoc_id = 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,32 +195,32 @@ amf_n2::amf_n2(const std::string &address, const uint16_t port_num) ...@@ -210,32 +195,32 @@ 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("Parameters: assoc_id %d, stream %d",
itti_msg.assoc_id, itti_msg.stream); 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("No existed gNB context with assoc_id(%d)",
itti_msg.assoc_id); 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("Update gNB context with assoc id (%d)",
...@@ -244,7 +229,7 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) { ...@@ -244,7 +229,7 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) {
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;
...@@ -273,43 +258,47 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) { ...@@ -273,43 +258,47 @@ 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_CauseRadioNetwork_unspecified,
Ngap_TimeToWait_v5s); 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);
} }
} }
//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);
...@@ -322,7 +311,7 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) { ...@@ -322,7 +311,7 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) {
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);
...@@ -340,7 +329,7 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) { ...@@ -340,7 +329,7 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) {
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");
...@@ -354,14 +343,14 @@ void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) { ...@@ -354,14 +343,14 @@ 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)) {
...@@ -369,12 +358,13 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) { ...@@ -369,12 +358,13 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) {
init_ue_msg.assoc_id); 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("gNB with assoc_id (%d) is illegal",
...@@ -382,18 +372,18 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) { ...@@ -382,18 +372,18 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) {
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);
...@@ -402,7 +392,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) { ...@@ -402,7 +392,7 @@ 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;
...@@ -421,7 +411,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) { ...@@ -421,7 +411,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();
} }
...@@ -443,7 +433,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) { ...@@ -443,7 +433,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) {
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);
...@@ -452,12 +442,11 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) { ...@@ -452,12 +442,11 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) {
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(
...@@ -467,20 +456,21 @@ void amf_n2::handle_itti_message(itti_initial_ue_message &init_ue_msg) { ...@@ -467,20 +456,21 @@ 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("gNB with assoc_id(%d) is illegal",
ul_nas_transport.assoc_id); 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;
} }
...@@ -492,21 +482,23 @@ void amf_n2::handle_itti_message(itti_ul_nas_transport &ul_nas_transport) { ...@@ -492,21 +482,23 @@ void amf_n2::handle_itti_message(itti_ul_nas_transport &ul_nas_transport) {
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);
...@@ -514,9 +506,9 @@ void amf_n2::handle_itti_message(itti_ul_nas_transport &ul_nas_transport) { ...@@ -514,9 +506,9 @@ void amf_n2::handle_itti_message(itti_ul_nas_transport &ul_nas_transport) {
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;
...@@ -524,8 +516,8 @@ void amf_n2::handle_itti_message(itti_ul_nas_transport &ul_nas_transport) { ...@@ -524,8 +516,8 @@ 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("Could not send ITTI message %s to task TASK_AMF_N1",
...@@ -534,15 +526,15 @@ void amf_n2::handle_itti_message(itti_ul_nas_transport &ul_nas_transport) { ...@@ -534,15 +526,15 @@ void amf_n2::handle_itti_message(itti_ul_nas_transport &ul_nas_transport) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
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("Illegal UE with ran_ue_ngap_id (0x%x)",
dl_nas_transport.ran_ue_ngap_id); 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("Illegal gNB with assoc id (0x%x)",
...@@ -551,11 +543,11 @@ void amf_n2::handle_itti_message(itti_dl_nas_transport &dl_nas_transport) { ...@@ -551,11 +543,11 @@ void amf_n2::handle_itti_message(itti_dl_nas_transport &dl_nas_transport) {
} }
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((uint8_t*)bdata(dl_nas_transport.nas),
blength(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);
...@@ -565,22 +557,22 @@ void amf_n2::handle_itti_message(itti_dl_nas_transport &dl_nas_transport) { ...@@ -565,22 +557,22 @@ void amf_n2::handle_itti_message(itti_dl_nas_transport &dl_nas_transport) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
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("Illegal UE with ran_ue_ngap_id (0x%x)",
itti_msg.ran_ue_ngap_id); 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("Illegal gNB with assoc id (0x%x)",
unc.get()->gnb_assoc_id); 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);
...@@ -591,9 +583,10 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request &itti_msg) { ...@@ -591,9 +583,10 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request &itti_msg) {
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,
msg->setSecurityKey((uint8_t*) bdata(itti_msg.kgnb)); 0xe000); // TODO: remove hardcoded value
msg->setNasPdu((uint8_t*) bdata(itti_msg.nas), blength(itti_msg.nas)); msg->setSecurityKey((uint8_t*)bdata(itti_msg.kgnb));
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;
...@@ -605,15 +598,15 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request &itti_msg) { ...@@ -605,15 +598,15 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request &itti_msg) {
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";
...@@ -622,17 +615,18 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request &itti_msg) { ...@@ -622,17 +615,18 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request &itti_msg) {
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
} }
} }
...@@ -645,22 +639,22 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request &itti_msg) { ...@@ -645,22 +639,22 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request &itti_msg) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
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("Illegal UE with ran_ue_ngap_id (0x%x)",
itti_msg.ran_ue_ngap_id); 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("Illegal gNB with assoc id (0x%x)",
unc.get()->gnb_assoc_id); 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);
...@@ -669,22 +663,22 @@ void amf_n2::handle_itti_message( ...@@ -669,22 +663,22 @@ 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("No existed nas_context with amf_ue_ngap_id(0x%x)",
itti_msg.amf_ue_ngap_id); itti_msg.amf_ue_ngap_id);
//TODO: // 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());
...@@ -695,46 +689,44 @@ void amf_n2::handle_itti_message( ...@@ -695,46 +689,44 @@ void amf_n2::handle_itti_message(
Logger::amf_n2().warn("Cannot get pdu_session_context with SUPI (%s)", Logger::amf_n2().warn("Cannot get pdu_session_context with SUPI (%s)",
supi.c_str()); 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(gc.get()->sctp_assoc_id,
unc.get()->sctp_stream_send, &b); 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("Illegal UE with ran_ue_ngap_id (0x%x)",
itti_msg.ran_ue_ngap_id); 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("Illegal gNB with assoc id (0x%x)",
...@@ -742,14 +734,14 @@ void amf_n2::handle_itti_message( ...@@ -742,14 +734,14 @@ void amf_n2::handle_itti_message(
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));
...@@ -757,41 +749,39 @@ void amf_n2::handle_itti_message( ...@@ -757,41 +749,39 @@ 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(gc.get()->sctp_assoc_id,
unc.get()->sctp_stream_send, &b); 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);
...@@ -801,17 +791,17 @@ void amf_n2::handle_itti_message(itti_ue_context_release_request &itti_msg) { ...@@ -801,17 +791,17 @@ void amf_n2::handle_itti_message(itti_ue_context_release_request &itti_msg) {
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("Illegal ue with ran_ue_ngap_id(0x%x)",
itti_msg.ran_ue_ngap_id); 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("Illegal gnb with assoc id(0x%x)",
...@@ -819,16 +809,16 @@ void amf_n2::handle_itti_message(itti_ue_context_release_command &itti_msg) { ...@@ -819,16 +809,16 @@ void amf_n2::handle_itti_message(itti_ue_context_release_command &itti_msg) {
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.amf_ue_ngap_id,
itti_msg.ran_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());
} }
if (itti_msg.cause.getChoiceOfCause() == Ngap_Cause_PR_radioNetwork) { if (itti_msg.cause.getChoiceOfCause() == Ngap_Cause_PR_radioNetwork) {
ueCtxRelCmd->setCauseRadioNetwork( ueCtxRelCmd->setCauseRadioNetwork(
(e_Ngap_CauseRadioNetwork) itti_msg.cause.getValue()); (e_Ngap_CauseRadioNetwork)itti_msg.cause.getValue());
} }
uint8_t buffer[200]; uint8_t buffer[200];
int encoded_size = ueCtxRelCmd->encode2buffer(buffer, 200); int encoded_size = ueCtxRelCmd->encode2buffer(buffer, 200);
...@@ -840,8 +830,8 @@ void amf_n2::handle_itti_message(itti_ue_context_release_command &itti_msg) { ...@@ -840,8 +830,8 @@ void amf_n2::handle_itti_message(itti_ue_context_release_command &itti_msg) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
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("No existed gNB context with assoc_id (%d)",
itti_msg.assoc_id); itti_msg.assoc_id);
...@@ -852,97 +842,111 @@ void amf_n2::handle_itti_message( ...@@ -852,97 +842,111 @@ 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");
} }
gc.get()->ue_radio_cap_ind = blk2bstr(ue_radio_cap, (int) size); gc.get()->ue_radio_cap_ind = blk2bstr(ue_radio_cap, (int)size);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_handover_required &itti_msg) void amf_n2::handle_itti_message(itti_handover_required& itti_msg) {
{
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("gnb with assoc_id(%d) is illegal",
Logger::amf_n2().error("gnb with assoc_id(%d) is illegal", itti_msg.assoc_id); 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("no ue ngap context with ran_ue_ngap_id(%d)",
Logger::amf_n2().error("no ue ngap context with ran_ue_ngap_id(%d)", ran_ue_ngap_id); 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);
...@@ -950,32 +954,35 @@ void amf_n2::handle_itti_message(itti_handover_required &itti_msg) ...@@ -950,32 +954,35 @@ 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,
2);
/*Authentication_5gaka::derive_kgnb(ulcount, 0x01, kamf, kgnb); /*Authentication_5gaka::derive_kgnb(ulcount, 0x01, kamf, kgnb);
print_buffer("amf_n1", "HO:kgnb", kgnb, 32); print_buffer("amf_n1", "HO:kgnb", kgnb, 32);
...@@ -998,10 +1005,11 @@ void amf_n2::handle_itti_message(itti_handover_required &itti_msg) ...@@ -998,10 +1005,11 @@ void amf_n2::handle_itti_message(itti_handover_required &itti_msg)
print_buffer("amf_n1", "Knh2", knh2, 32); print_buffer("amf_n1", "Knh2", knh2, 32);
bstring knh_bs = blk2bstr(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(2 /*NCC count*/, (uint8_t*)bdata(knh_bs));
//handoverrequest->setSourceToTarget_TransparentContainer(sourceTotarget); // 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;
...@@ -1009,14 +1017,11 @@ void amf_n2::handle_itti_message(itti_handover_required &itti_msg) ...@@ -1009,14 +1017,11 @@ void amf_n2::handle_itti_message(itti_handover_required &itti_msg)
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);
...@@ -1035,43 +1040,47 @@ void amf_n2::handle_itti_message(itti_handover_required &itti_msg) ...@@ -1035,43 +1040,47 @@ void amf_n2::handle_itti_message(itti_handover_required &itti_msg)
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
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("gnb with assoc_id(%d) is illegal",
Logger::amf_n2().error("gnb with assoc_id(%d) is illegal", itti_msg.assoc_id); 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(buf, list[0].handoverRequestAcknowledgeTransfer.buf,
if (!PDUHandoverRequestAckTransfer->decodefromHandoverRequestAckTransfer(buf, list[0].handoverRequestAcknowledgeTransfer.size)) 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;
} }
...@@ -1080,44 +1089,51 @@ void amf_n2::handle_itti_message(itti_handover_request_Ack &itti_msg) ...@@ -1080,44 +1089,51 @@ void amf_n2::handle_itti_message(itti_handover_request_Ack &itti_msg)
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;
...@@ -1130,97 +1146,114 @@ void amf_n2::handle_itti_message(itti_handover_request_Ack &itti_msg) ...@@ -1130,97 +1146,114 @@ void amf_n2::handle_itti_message(itti_handover_request_Ack &itti_msg)
int encoded_size = handovercommand->encode2buffer(buffer, 10240); int encoded_size = handovercommand->encode2buffer(buffer, 10240);
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;
} }
//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 =
//std::shared_ptr<ue_ngap_context> ngc = ran_ue_id_2_ue_ngap_context(ran_id_Global); // ran_ue_id_2_ue_ngap_context(nc.get()->ran_ue_ngap_id);
//sctp_s_38412.sctp_send_msg(ngc.get()->gnb_assoc_id, 0, &b); // 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);
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);
std::shared_ptr<ue_ngap_context> ngc =
ran_ue_id_2_ue_ngap_context(nc.get()->ran_ue_ngap_id);
sctp_s_38412.sctp_send_msg(ngc.get()->gnb_assoc_id, 0, &b); sctp_s_38412.sctp_send_msg(ngc.get()->gnb_assoc_id, 0, &b);
/*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 =
string supi = "imsi-" + nc.get()->imsi; amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id); string supi = "imsi-" +
std::shared_ptr<pdu_session_context> psc = amf_n11_inst->supi_to_pdu_ctx(supi); nc.get()->imsi; std::shared_ptr<pdu_session_context> psc =
itti_nsmf_pdusession_update_sm_context *itti_nsmf_msg = new itti_nsmf_pdusession_update_sm_context(TASK_AMF_N2, TASK_AMF_N11); amf_n11_inst->supi_to_pdu_ctx(supi); itti_nsmf_pdusession_update_sm_context
itti_nsmf_msg->supi = supi; *itti_nsmf_msg = new itti_nsmf_pdusession_update_sm_context(TASK_AMF_N2,
itti_nsmf_msg->pdu_session_id = psc.get()->pdu_session_id; TASK_AMF_N11); itti_nsmf_msg->supi = supi; itti_nsmf_msg->pdu_session_id =
itti_nsmf_msg->n2sm = psc.get()->n2sm; 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); 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("uplinkranstatustransfer amf_ue_ngap_id(%d)",
if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) 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;
...@@ -1231,36 +1264,39 @@ void amf_n2::handle_itti_message(itti_uplinkranstatsutransfer &itti_msg) ...@@ -1231,36 +1264,39 @@ 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);
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;
} }
...@@ -1276,8 +1312,8 @@ bool amf_n2::verifyPlmn(vector<SupportedItem_t> list) { ...@@ -1276,8 +1312,8 @@ bool amf_n2::verifyPlmn(vector<SupportedItem_t> list) {
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;
} }
} }
...@@ -1289,7 +1325,7 @@ bool amf_n2::verifyPlmn(vector<SupportedItem_t> list) { ...@@ -1289,7 +1325,7 @@ 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++) {
...@@ -1299,8 +1335,8 @@ std::vector<SupportedItem_t> amf_n2::get_common_plmn( ...@@ -1299,8 +1335,8 @@ std::vector<SupportedItem_t> amf_n2::get_common_plmn(
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]);
} }
} }
......
...@@ -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
* *
...@@ -29,13 +29,13 @@ ...@@ -29,13 +29,13 @@
#ifndef _AMF_N2_H_ #ifndef _AMF_N2_H_
#define _AMF_N2_H_ #define _AMF_N2_H_
#include "ngap_app.hpp" #include "DownlinkRANStatusTransfer.hpp"
#include "HandoverCommandMsg.hpp"
#include "HandoverRequest.hpp"
#include "PduSessionResourceReleaseCommand.hpp"
#include "itti_msg_n2.hpp" #include "itti_msg_n2.hpp"
#include "ngap_app.hpp"
#include "ue_ngap_context.hpp" #include "ue_ngap_context.hpp"
#include "PduSessionResourceReleaseCommand.hpp"
#include "HandoverRequest.hpp"
#include "HandoverCommandMsg.hpp"
#include "DownlinkRANStatusTransfer.hpp"
#include "amf.hpp" #include "amf.hpp"
...@@ -73,11 +73,11 @@ class amf_n2 : public ngap::ngap_app { ...@@ -73,11 +73,11 @@ class amf_n2 : public ngap::ngap_app {
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);
private: private:
std::map<uint32_t, std::shared_ptr<ue_ngap_context>> ranid2uecontext; // ran ue ngap id std::map<uint32_t, std::shared_ptr<ue_ngap_context>>
ranid2uecontext; // ran ue ngap id
mutable std::shared_mutex m_ranid2uecontext; mutable std::shared_mutex m_ranid2uecontext;
}; };
} } // namespace amf_application
#endif #endif
...@@ -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
* *
...@@ -33,52 +33,63 @@ ...@@ -33,52 +33,63 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void statistics::display() { void statistics::display() {
Logger::amf_app().info(""); Logger::amf_app().info("");
//Logger::amf_app().info("--------------------------------------------------"); // Logger::amf_app().info("--------------------------------------------------");
//Logger::amf_app().info("| connected gNBs | connected UEs | registered UEs |"); // Logger::amf_app().info("| connected gNBs | connected UEs | registered UEs
//Logger::amf_app().info("--------------------------------------------------"); // |");
//Logger::amf_app().info("| %d | %d | %d |",gNB_connected,UE_connected,UE_registred); // Logger::amf_app().info("--------------------------------------------------");
//Logger::amf_app().info("--------------------------------------------------"); // Logger::amf_app().info("| %d | %d | %d
// |",gNB_connected,UE_connected,UE_registred);
// Logger::amf_app().info("--------------------------------------------------");
Logger::amf_app().info( Logger::amf_app().info(
"|----------------------------------------------------------------------------------------------------------------|"); "|-----------------------------------------------------------------------"
"-----------------------------------------|");
Logger::amf_app().info( Logger::amf_app().info(
"|----------------------------------------------------gNBs' information-------------------------------------------|"); "|----------------------------------------------------gNBs' "
"information-------------------------------------------|");
Logger::amf_app().info( Logger::amf_app().info(
"| Index | Status | Global ID | gNB Name | Tracking Area (PLMN, TAC) |"); "| Index | Status | Global ID | gNB "
"Name | Tracking Area (PLMN, TAC) |");
if (gnbs.size() == 0) { if (gnbs.size() == 0) {
Logger::amf_app().info( Logger::amf_app().info(
"| - | - | - | - | - |"); "| - | - | - | "
"- | - |");
} }
//TODO: Show the list of common PLMNs // TODO: Show the list of common PLMNs
for (int i = 0; i < gnbs.size(); i++) { for (int i = 0; i < gnbs.size(); i++) {
Logger::amf_app().info( Logger::amf_app().info(
"| %d | Connected | 0x%x | %s | %s, %d | ", "| %d | Connected | 0x%x | %s "
" | %s, %d | ",
i + 1, gnbs[i].gnb_id, gnbs[i].gnb_name.c_str(), i + 1, gnbs[i].gnb_id, gnbs[i].gnb_name.c_str(),
(gnbs[i].mcc + gnbs[i].mnc).c_str(), gnbs[i].tac); (gnbs[i].mcc + gnbs[i].mnc).c_str(), gnbs[i].tac);
} }
Logger::amf_app().info( Logger::amf_app().info(
"|----------------------------------------------------------------------------------------------------------------|"); "|-----------------------------------------------------------------------"
"-----------------------------------------|");
Logger::amf_app().info(""); Logger::amf_app().info("");
Logger::amf_app().info( Logger::amf_app().info(
"|----------------------------------------------------------------------------------------------------------------|"); "|-----------------------------------------------------------------------"
"-----------------------------------------|");
Logger::amf_app().info( Logger::amf_app().info(
"|----------------------------------------------------UEs' information--------------------------------------------|"); "|----------------------------------------------------UEs' "
"information--------------------------------------------|");
Logger::amf_app().info( Logger::amf_app().info(
"| Index | 5GMM state | IMSI | GUTI | RAN UE NGAP ID | AMF UE ID | PLMN |Cell ID|"); "| Index | 5GMM state | IMSI | GUTI | RAN "
"UE NGAP ID | AMF UE ID | PLMN |Cell ID|");
int i = 0; int i = 0;
for (auto const &ue : ue_infos) { for (auto const &ue : ue_infos) {
Logger::amf_app().info("|%7d|%22s|%18s|%15s|%16d|%11d|%9s|%7d|", i + 1, Logger::amf_app().info(
ue.second.registerStatus.c_str(), "|%7d|%22s|%18s|%15s|%16d|%11d|%9s|%7d|", i + 1,
ue.second.imsi.c_str(), ue.second.guti.c_str(), ue.second.registerStatus.c_str(), ue.second.imsi.c_str(),
ue.second.ranid, ue.second.amfid, ue.second.guti.c_str(), ue.second.ranid, ue.second.amfid,
(ue.second.mcc + ue.second.mnc).c_str(), (ue.second.mcc + ue.second.mnc).c_str(), ue.second.cellId);
ue.second.cellId);
i++; i++;
} }
Logger::amf_app().info( Logger::amf_app().info(
"|----------------------------------------------------------------------------------------------------------------|"); "|-----------------------------------------------------------------------"
"-----------------------------------------|");
Logger::amf_app().info(""); Logger::amf_app().info("");
} }
...@@ -124,5 +135,4 @@ void statistics::update_5gmm_state(const std::string &imsi, ...@@ -124,5 +135,4 @@ void statistics::update_5gmm_state(const std::string &imsi,
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
statistics::~statistics() { statistics::~statistics() {}
}
...@@ -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
* *
...@@ -29,21 +29,21 @@ ...@@ -29,21 +29,21 @@
#ifndef _STATISTICS_H_ #ifndef _STATISTICS_H_
#define _STATISTICS_H_ #define _STATISTICS_H_
#include <vector>
#include <string> #include <string>
#include <vector>
#include "amf.hpp" #include "amf.hpp"
#include "ngap_app.hpp" #include "ngap_app.hpp"
typedef struct { typedef struct {
uint32_t gnb_id; uint32_t gnb_id;
//TODO: list of PLMNs // TODO: list of PLMNs
std::vector<SupportedItem_t> plmn_list; std::vector<SupportedItem_t> plmn_list;
std::string mcc; std::string mcc;
std::string mnc; std::string mnc;
std::string gnb_name; std::string gnb_name;
uint32_t tac; uint32_t tac;
//long nrCellId; // long nrCellId;
} gnb_infos; } gnb_infos;
typedef struct ue_info_s { typedef struct ue_info_s {
...@@ -65,14 +65,14 @@ class statistics { ...@@ -65,14 +65,14 @@ class statistics {
~statistics(); ~statistics();
void update_ue_info(const ue_info_t &ue_info); void update_ue_info(const ue_info_t &ue_info);
void update_5gmm_state(const std::string &imsi, const std::string &state); void update_5gmm_state(const std::string &imsi, const std::string &state);
public: public:
uint32_t gNB_connected; uint32_t gNB_connected;
uint32_t UE_connected; uint32_t UE_connected;
uint32_t UE_registred; uint32_t UE_registred;
//uint32_t system_pdu_sessions; // uint32_t system_pdu_sessions;
std::vector<gnb_infos> gnbs; std::vector<gnb_infos> gnbs;
std::map<std::string, ue_info_t> ue_infos; std::map<std::string, ue_info_t> ue_infos;
}; };
#endif #endif
...@@ -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
* *
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
\email: contact@openairinterface.org \email: contact@openairinterface.org
*/ */
#include "amf_config.hpp"
#include "amf_n1.hpp" #include "amf_n1.hpp"
#include "logger.hpp" #include "logger.hpp"
#include "amf_config.hpp"
using namespace amf_application; using namespace amf_application;
using namespace config; using namespace config;
...@@ -36,7 +36,10 @@ using namespace config; ...@@ -36,7 +36,10 @@ using namespace config;
extern amf_config amf_cfg; extern amf_config amf_cfg;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool amf_n1::get_mysql_auth_info(std::string imsi, mysql_auth_info_t &resp) { //openair-cn/tree/v0.5.0/src/oai_hss/db/db_connector.c bool amf_n1::get_mysql_auth_info(
std::string imsi,
mysql_auth_info_t
&resp) { // openair-cn/tree/v0.5.0/src/oai_hss/db/db_connector.c
MYSQL_RES *res; MYSQL_RES *res;
MYSQL_ROW row; MYSQL_ROW row;
std::string query; std::string query;
...@@ -45,8 +48,9 @@ bool amf_n1::get_mysql_auth_info(std::string imsi, mysql_auth_info_t &resp) { / ...@@ -45,8 +48,9 @@ bool amf_n1::get_mysql_auth_info(std::string imsi, mysql_auth_info_t &resp) { /
Logger::amf_n1().error("Cannot connect to MySQL DB"); Logger::amf_n1().error("Cannot connect to MySQL DB");
return false; return false;
} }
query = "SELECT `key`,`sqn`,`rand`,`OPc` FROM `users` WHERE `users`.`imsi`='" query =
+ imsi + "' "; "SELECT `key`,`sqn`,`rand`,`OPc` FROM `users` WHERE `users`.`imsi`='" +
imsi + "' ";
pthread_mutex_lock(&db_desc->db_cs_mutex); pthread_mutex_lock(&db_desc->db_cs_mutex);
if (mysql_query(db_desc->db_conn, query.c_str())) { if (mysql_query(db_desc->db_conn, query.c_str())) {
pthread_mutex_unlock(&db_desc->db_cs_mutex); pthread_mutex_unlock(&db_desc->db_cs_mutex);
...@@ -84,7 +88,7 @@ bool amf_n1::get_mysql_auth_info(std::string imsi, mysql_auth_info_t &resp) { / ...@@ -84,7 +88,7 @@ bool amf_n1::get_mysql_auth_info(std::string imsi, mysql_auth_info_t &resp) { /
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool amf_n1::connect_to_mysql() { bool amf_n1::connect_to_mysql() {
const int mysql_reconnect_val = 1; const int mysql_reconnect_val = 1;
db_desc = (database_t*) calloc(1, sizeof(database_t)); db_desc = (database_t *)calloc(1, sizeof(database_t));
if (!db_desc) { if (!db_desc) {
Logger::amf_n1().error( Logger::amf_n1().error(
"An error occurs when allocating memory for DB_DESC"); "An error occurs when allocating memory for DB_DESC");
...@@ -125,16 +129,18 @@ void amf_n1::mysql_push_rand_sqn(std::string imsi, uint8_t *rand_p, ...@@ -125,16 +129,18 @@ void amf_n1::mysql_push_rand_sqn(std::string imsi, uint8_t *rand_p,
Logger::amf_n1().error("Need sqn and rand"); Logger::amf_n1().error("Need sqn and rand");
return; return;
} }
sqn_decimal = ((uint64_t) sqn[0] << 40) | ((uint64_t) sqn[1] << 32) sqn_decimal = ((uint64_t)sqn[0] << 40) | ((uint64_t)sqn[1] << 32) |
| ((uint64_t) sqn[2] << 24) | (sqn[3] << 16) | (sqn[4] << 8) | sqn[5]; ((uint64_t)sqn[2] << 24) | (sqn[3] << 16) | (sqn[4] << 8) |
sqn[5];
query_length = sprintf(query, "UPDATE `users` SET `rand`=UNHEX('"); query_length = sprintf(query, "UPDATE `users` SET `rand`=UNHEX('");
for (int i = 0; i < RAND_LENGTH; i++) { for (int i = 0; i < RAND_LENGTH; i++) {
query_length += sprintf(&query[query_length], "%02x", rand_p[i]); query_length += sprintf(&query[query_length], "%02x", rand_p[i]);
} }
query_length += sprintf (&query[query_length], "'),`sqn`=%" PRIu64, sqn_decimal); query_length +=
query_length += sprintf(&query[query_length], " WHERE `users`.`imsi`='%s'", sprintf(&query[query_length], "'),`sqn`=%" PRIu64, sqn_decimal);
imsi.c_str()); query_length +=
sprintf(&query[query_length], " WHERE `users`.`imsi`='%s'", imsi.c_str());
pthread_mutex_lock(&db_desc->db_cs_mutex); pthread_mutex_lock(&db_desc->db_cs_mutex);
if (mysql_query(db_desc->db_conn, query)) { if (mysql_query(db_desc->db_conn, query)) {
pthread_mutex_unlock(&db_desc->db_cs_mutex); pthread_mutex_unlock(&db_desc->db_cs_mutex);
......
...@@ -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
* *
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
#ifndef _MYSQL_DB_HANDLERS_H_ #ifndef _MYSQL_DB_HANDLERS_H_
#define _MYSQL_DB_HANDLERS_H_ #define _MYSQL_DB_HANDLERS_H_
#include <pthread.h>
#include <mysql/mysql.h> #include <mysql/mysql.h>
#include <pthread.h>
#include <string> #include <string>
#define KEY_LENGTH (16) #define KEY_LENGTH (16)
...@@ -44,7 +44,7 @@ typedef struct { ...@@ -44,7 +44,7 @@ typedef struct {
} mysql_auth_info_t; } mysql_auth_info_t;
typedef struct { typedef struct {
//mysql reference connector object // mysql reference connector object
MYSQL *db_conn; MYSQL *db_conn;
std::string server; std::string server;
std::string user; std::string user;
......
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