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

Fix typo

parent f3616257
......@@ -120,7 +120,7 @@ void amf_app_task(void*) {
stacs.display();
break;
default:
Logger::amf_app().info("no handler for timer(%d) with arg1_user(%d) ", to->timer_id, to->arg1_user);
Logger::amf_app().info("No handler for timer(%d) with arg1_user(%d) ", to->timer_id, to->arg1_user);
}
}
break;
......@@ -221,7 +221,7 @@ void amf_app::handle_itti_message(itti_nas_signalling_establishment_request &itt
string ue_context_key = "app_ue_ranid_" + to_string(itti_msg.ran_ue_ngap_id) + ":amfid_" + to_string(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)) {
Logger::amf_app().debug("no existed ue_context, Create one with ran_amf_id(%s)", ue_context_key.c_str());
Logger::amf_app().debug("No existed ue_context, create one with ran_amf_id(%s)", ue_context_key.c_str());
uc = std::shared_ptr < ue_context > (new ue_context());
//set_amf_ue_ngap_id_2_ue_context(amf_ue_ngap_id, uc);
set_ran_amf_id_2_ue_context(ue_context_key, uc);
......@@ -270,13 +270,13 @@ void amf_app::handle_itti_message(itti_nas_signalling_establishment_request &itt
//SMF Client response handlers
//------------------------------------------------------------------------------
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");
}
bool amf_app::generate_5g_guti(uint32_t ranid, long amfid, string &mcc, string &mnc, uint32_t &tmsi) {
string ue_context_key = "app_ue_ranid_" + to_string(ranid) + ":amfid_" + to_string(amfid);
if (!is_ran_amf_id_2_ue_context(ue_context_key)) {
Logger::amf_app().error("no ue context for ran_amf_id(%s), exit", ue_context_key.c_str());
Logger::amf_app().error("No UE context for ran_amf_id(%s), exit", ue_context_key.c_str());
return false;
}
std::shared_ptr<ue_context> uc;
......
......@@ -63,7 +63,7 @@ amf_config::~amf_config() {
//------------------------------------------------------------------------------
int amf_config::load(const std::string &config_file) {
cout << endl;
Logger::amf_app().debug("Load amf system configuration file(%s)", config_file.c_str());
Logger::amf_app().debug("Load AMF system configuration file(%s)", config_file.c_str());
Config cfg;
unsigned char buf_in6_addr[sizeof(struct in6_addr)];
try {
......
This diff is collapsed.
......@@ -57,6 +57,7 @@ extern amf_app *amf_app_inst;
extern statistics stacs;
void amf_n2_task(void*);
//------------------------------------------------------------------------------
void amf_n2_task(void *args_p) {
const task_id_t task_id = TASK_AMF_N2;
......@@ -134,7 +135,7 @@ amf_n2::amf_n2(const string &address, const uint16_t port_num)
throw std::runtime_error("Cannot create task TASK_AMF_N2");
}
Logger::task_amf_n2().startup("Started");
Logger::task_amf_n2().debug("construct amf_n2 successfully");
Logger::task_amf_n2().debug("Construct amf_n2 successfully");
}
//------------------------------------------------------------------------------
......@@ -150,7 +151,7 @@ void amf_n2::handle_itti_message(itti_new_sctp_association &new_assoc) {
// NG_SETUP_REQUEST Handler
//------------------------------------------------------------------------------
void amf_n2::handle_itti_message(itti_ng_setup_request &itti_msg) {
Logger::amf_n2().debug("parameters(assoc_id(%d))(stream(%d))", itti_msg.assoc_id, itti_msg.stream);
Logger::amf_n2().debug("Parameters(assoc_id(%d))(stream(%d))", itti_msg.assoc_id, itti_msg.stream);
std::shared_ptr<gnb_context> gc;
if (!is_assoc_id_2_gnb_context(itti_msg.assoc_id)) {
......@@ -472,7 +473,6 @@ void amf_n2::handle_itti_message(itti_initial_context_setup_request &itti_msg) {
memcpy(uecap, (uint8_t*) bdata(ueCapability), blength(ueCapability));
uecap[blength(ueCapability)] = '\0';
msg->setUERadioCapability(uecap, (size_t)blength(ueCapability));
//msg->setUERadioCapability((uint8_t*)bdata(ueCapability), (size_t)blength(ueCapability));
Logger::amf_n2().debug("Encoding parameters for service request");
std::vector<PDUSessionResourceSetupRequestItem_t> list;
PDUSessionResourceSetupRequestItem_t item;
......@@ -601,7 +601,7 @@ void amf_n2::set_ran_ue_ngap_id_2_ue_ngap_context(const uint32_t &ran_ue_ngap_id
bool amf_n2::verifyPlmn(vector<SupportedItem_t> list) {
for (int i = 0; i < amf_cfg.plmn_list.size(); i++) {
for (int j = 0; j < list.size(); j++) {
Logger::amf_n2().debug("tac configured(%d) -- tac received(%d)", amf_cfg.plmn_list[i].tac, list[j].tac);
Logger::amf_n2().debug("TAC configured(%d) -- TAC received(%d)", amf_cfg.plmn_list[i].tac, list[j].tac);
if (amf_cfg.plmn_list[i].tac != list[j].tac) {
continue;
}
......
......@@ -41,7 +41,7 @@ bool amf_n1::get_mysql_auth_info(std::string imsi, mysql_auth_info_t &resp) { /
std::string query;
if (!db_desc->db_conn) {
Logger::amf_n1().error("Cannot connect to mysql db");
Logger::amf_n1().error("Cannot connect to MySQL DB");
return false;
}
query = "SELECT `key`,`sqn`,`rand`,`OPc` FROM `users` WHERE `users`.`imsi`='" + imsi + "' ";
......@@ -54,7 +54,7 @@ bool amf_n1::get_mysql_auth_info(std::string imsi, mysql_auth_info_t &resp) { /
res = mysql_store_result(db_desc->db_conn);
pthread_mutex_unlock(&db_desc->db_cs_mutex);
if (!res) {
Logger::amf_n1().error("data fetched from mysql is not present");
Logger::amf_n1().error("data fetched from MySQL is not present");
return false;
}
if (row = mysql_fetch_row(res)) {
......@@ -83,7 +83,7 @@ bool amf_n1::connect_to_mysql() {
const int mysql_reconnect_val = 1;
db_desc = (database_t*) calloc(1, sizeof(database_t));
if (!db_desc) {
Logger::amf_n1().error("An error occurs when calloc");
Logger::amf_n1().error("An error occurs when allocate memory for DB_DESC");
return false;
}
pthread_mutex_init(&db_desc->db_cs_mutex, NULL);
......@@ -110,11 +110,11 @@ void amf_n1::mysql_push_rand_sqn(std::string imsi, uint8_t *rand_p, uint8_t *sqn
int query_length = 0;
uint64_t sqn_decimal = 0;
if (!db_desc->db_conn) {
Logger::amf_n1().error("Cannot connect to mysql");
Logger::amf_n1().error("Cannot connect to MySQL DB");
return;
}
if (!sqn || !rand_p) {
Logger::amf_n1().error("need sqn and rand");
Logger::amf_n1().error("Need sqn and rand");
return;
}
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];
......@@ -156,7 +156,7 @@ void amf_n1::mysql_increment_sqn(std::string imsi) {
MYSQL_RES *res;
char query[1000];
if (db_desc->db_conn == NULL) {
Logger::amf_n1().error("Cannot connect to mysql");
Logger::amf_n1().error("Cannot connect to MySQL DB");
return;
}
sprintf(query, "UPDATE `users` SET `sqn` = `sqn` + 32 WHERE `users`.`imsi`='%s'", imsi.c_str());
......
......@@ -37,7 +37,7 @@ class pdu_session_context {
public:
pdu_session_context();
~pdu_session_context();
public:
uint32_t ran_ue_ngap_id;
long amf_ue_ngap_id;
uint8_t req_type;
......
......@@ -43,17 +43,17 @@ using namespace config;
using namespace ngap;
amf_config amf_cfg;
ngap_app * ngap_inst = NULL;
ngap_app *ngap_inst = NULL;
int main(int argc, char **argv){
int main(int argc, char **argv) {
srand (time(NULL));
if(!Options::parse(argc, argv)){
if (!Options::parse(argc, argv)) {
cout<<"Options::parse() failed"<<endl;
return 1;
}
Logger::init( "amf" , Options::getlogStdout() , Options::getlogRotFilelog());
Logger::init( "AMF" , Options::getlogStdout() , Options::getlogRotFilelog());
Logger::amf_app().startup("Options parsed!");
amf_cfg.load(Options::getlibconfigConfig());
......
......@@ -32,52 +32,59 @@
#include "amf_module_from_config.hpp"
#include "ngap_message_callback.hpp"
extern "C"{
#include "Ngap_NGAP-PDU.h"
#include "Ngap_InitiatingMessage.h"
extern "C" {
#include "Ngap_NGAP-PDU.h"
#include "Ngap_InitiatingMessage.h"
}
using namespace sctp;
using namespace config;
using namespace ngap;
ngap_app::ngap_app(const string & address, const uint16_t port_num):ppid_(60),sctp_s_38412(address.c_str(),port_num){
//------------------------------------------------------------------------------
ngap_app::ngap_app(const string &address, const uint16_t port_num)
:
ppid_(60),
sctp_s_38412(address.c_str(), port_num) {
sctp_s_38412.start_receive(this);
Logger::ngap().info("set n2 amf ipv4_address:port (%s:%d)", address.c_str(), port_num);
}
ngap_app::~ngap_app(){}
/**************************************** received sctp paylaod and decode it to NGAP message and send itti message to TASK_AMF_N2 ***************************************/
//------------------------------------------------------------------------------
ngap_app::~ngap_app() {
}
void ngap_app::handle_receive(bstring payload, sctp_assoc_id_t assoc_id, sctp_stream_id_t stream, sctp_stream_id_t instreams, sctp_stream_id_t outstreams){
Logger::ngap().debug("ngap handle sctp payload from sctp_server on assoc_id(%d), stream_id(%d), instreams(%d), outstreams(%d)", assoc_id,stream,instreams,outstreams);
Ngap_NGAP_PDU_t *ngap_msg_pdu = (Ngap_NGAP_PDU_t*)calloc(1,sizeof(Ngap_NGAP_PDU_t));
asn_dec_rval_t rc = asn_decode(NULL,ATS_ALIGNED_CANONICAL_PER,&asn_DEF_Ngap_NGAP_PDU,(void**)&ngap_msg_pdu,bdata(payload),blength(payload));
Logger::ngap().debug("decoded ngap message[%d,%d]",ngap_msg_pdu->choice.initiatingMessage->procedureCode, ngap_msg_pdu->present);
(*messages_callback[ngap_msg_pdu->choice.initiatingMessage->procedureCode][ngap_msg_pdu->present - 1]) (assoc_id, stream, ngap_msg_pdu);
//------------------------------------------------------------------------------
// received sctp paylaod and decode it to NGAP message and send itti message to TASK_AMF_N2
void ngap_app::handle_receive(bstring payload, sctp_assoc_id_t assoc_id, sctp_stream_id_t stream, sctp_stream_id_t instreams, sctp_stream_id_t outstreams) {
Logger::ngap().debug("NGAP handle SCTP payload from sctp_server on assoc_id(%d), stream_id(%d), instreams(%d), outstreams(%d)", assoc_id, stream, instreams, outstreams);
Ngap_NGAP_PDU_t *ngap_msg_pdu = (Ngap_NGAP_PDU_t*) calloc(1, sizeof(Ngap_NGAP_PDU_t));
asn_dec_rval_t rc = asn_decode(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_Ngap_NGAP_PDU, (void**) &ngap_msg_pdu, bdata(payload), blength(payload));
Logger::ngap().debug("Decoded NGAP message[%d,%d]", ngap_msg_pdu->choice.initiatingMessage->procedureCode, ngap_msg_pdu->present);
(*messages_callback[ngap_msg_pdu->choice.initiatingMessage->procedureCode][ngap_msg_pdu->present - 1])(assoc_id, stream, ngap_msg_pdu);
}
/***************************************** handle new sctp association *************************************/
//------------------------------------------------------------------------------
//handle new sctp association
// TNL association(clause 8.7.1.1, 3gpp ts38.413)
void ngap_app::handle_sctp_new_association(sctp_assoc_id_t assoc_id, sctp_stream_id_t instreams, sctp_stream_id_t outstreams){
Logger::ngap().debug("ready to handle new ngap sctp association(id:%d) request",assoc_id);
void ngap_app::handle_sctp_new_association(sctp_assoc_id_t assoc_id, sctp_stream_id_t instreams, sctp_stream_id_t outstreams) {
Logger::ngap().debug("Ready to handle new NGAP SCTP association(id:%d) request", assoc_id);
std::shared_ptr<gnb_context> gc;
if(!is_assoc_id_2_gnb_context(assoc_id)) {
Logger::ngap().debug("Create a new gNB context with assoc_id(%d)",assoc_id);
gc = std::shared_ptr<gnb_context>(new gnb_context());
if (!is_assoc_id_2_gnb_context(assoc_id)) {
Logger::ngap().debug("Create a new gNB context with assoc_id(%d)", assoc_id);
gc = std::shared_ptr < gnb_context > (new gnb_context());
set_assoc_id_2_gnb_context(assoc_id, gc);
}else{
} else {
gc = assoc_id_2_gnb_context(assoc_id);
if(gc.get()->ng_state == NGAP_RESETING || gc.get()->ng_state == NGAP_SHUTDOWN){
if (gc.get()->ng_state == NGAP_RESETING || gc.get()->ng_state == NGAP_SHUTDOWN) {
Logger::ngap().warn("Received new association request on an association that is being %s, ignoring", ng_gnb_state_str[gc.get()->ng_state]);
}else{
} else {
Logger::ngap().debug("Update gNB context with assoc id (%d)", assoc_id);
}
}
if(gc.get() == nullptr){
if (gc.get() == nullptr) {
Logger::ngap().error("Failed to create gNB context for assoc_id(%d)", assoc_id);
}else{
} else {
gc.get()->sctp_assoc_id = assoc_id;
gc.get()->instreams = instreams;
gc.get()->outstreams = outstreams;
......@@ -86,26 +93,26 @@ void ngap_app::handle_sctp_new_association(sctp_assoc_id_t assoc_id, sctp_stream
}
}
uint32_t ngap_app::getPpid(){
//------------------------------------------------------------------------------
uint32_t ngap_app::getPpid() {
return ppid_;
}
/******************************************* gnb context management **********************************************/
bool ngap_app::is_assoc_id_2_gnb_context(const sctp_assoc_id_t & assoc_id) const{
//gnb context management
//------------------------------------------------------------------------------
bool ngap_app::is_assoc_id_2_gnb_context(const sctp_assoc_id_t &assoc_id) const {
std::shared_lock lock(m_assoc2gnbContext);
return bool{assoc2gnbContext.count(assoc_id) > 0};
return bool { assoc2gnbContext.count(assoc_id) > 0 };
}
std::shared_ptr<gnb_context> ngap_app::assoc_id_2_gnb_context(const sctp_assoc_id_t & assoc_id) const{
//------------------------------------------------------------------------------
std::shared_ptr<gnb_context> ngap_app::assoc_id_2_gnb_context(const sctp_assoc_id_t &assoc_id) const {
std::shared_lock lock(m_assoc2gnbContext);
return assoc2gnbContext.at(assoc_id);
}
void ngap_app::set_assoc_id_2_gnb_context(const sctp_assoc_id_t& assoc_id, std::shared_ptr<gnb_context> gc){
//------------------------------------------------------------------------------
void ngap_app::set_assoc_id_2_gnb_context(const sctp_assoc_id_t &assoc_id, std::shared_ptr<gnb_context> gc) {
std::shared_lock lock(m_assoc2gnbContext);
assoc2gnbContext[assoc_id] = gc;
}
......@@ -37,48 +37,32 @@
#include <string>
#include <thread>
using namespace sctp;
namespace ngap{
namespace ngap {
static const char * const ng_gnb_state_str [] = {"NGAP_INIT", "NGAP_RESETTING", "NGAP_READY", "NGAP_SHUTDOWN"};
static const char *const ng_gnb_state_str[] = { "NGAP_INIT", "NGAP_RESETTING", "NGAP_READY", "NGAP_SHUTDOWN" };
class ngap_app : public sctp_application{
public:
class ngap_app : public sctp_application {
public:
ngap_app(const string &address, const uint16_t port_num);
~ngap_app();
uint32_t getPpid();
protected:
protected:
sctp_server sctp_s_38412;
uint32_t ppid_;
std::map<sctp_assoc_id_t, std::shared_ptr<gnb_context>> assoc2gnbContext;
mutable std::shared_mutex m_assoc2gnbContext;
public:
public:
void handle_receive(bstring payload, sctp_assoc_id_t assoc_id, sctp_stream_id_t stream, sctp_stream_id_t instreams, sctp_stream_id_t outstreams);
void handle_sctp_new_association(sctp_assoc_id_t assoc_id, sctp_stream_id_t instreams, sctp_stream_id_t outstreams);
public:
bool is_assoc_id_2_gnb_context(const sctp_assoc_id_t & assoc_id) const;
void set_assoc_id_2_gnb_context(const sctp_assoc_id_t& assoc_id, std::shared_ptr<gnb_context> gc);
std::shared_ptr<gnb_context> assoc_id_2_gnb_context(const sctp_assoc_id_t & assoc_id) const;
};
bool is_assoc_id_2_gnb_context(const sctp_assoc_id_t &assoc_id) const;
void set_assoc_id_2_gnb_context(const sctp_assoc_id_t &assoc_id, std::shared_ptr<gnb_context> gc);
std::shared_ptr<gnb_context> assoc_id_2_gnb_context(const sctp_assoc_id_t &assoc_id) const;
};
}
#endif
This diff is collapsed.
......@@ -52,7 +52,7 @@ if (!Options::parse(argc, argv)) {
return 1;
}
Logger::init( "amf" , Options::getlogStdout() , Options::getlogRotFilelog());
Logger::init( "AMF" , Options::getlogStdout() , Options::getlogRotFilelog());
Logger::amf_app().startup("Options parsed!");
amf_cfg.load(Options::getlibconfigConfig());
......@@ -67,7 +67,7 @@ if (!Options::parse(argc, argv)) {
amf_app_inst = new amf_app(amf_cfg);
amf_app_inst->allRegistredModulesInit(modules);
Logger::amf_app().debug("initiating amf server endpoints");
Logger::amf_app().debug("Initiating AMF server endpoints");
Pistache::Address addr(std::string(inet_ntoa (*((struct in_addr *)&amf_cfg.n2.addr4))) , Pistache::Port(8282));
AMFApiServer amfApiServer(addr, amf_app_inst);
amfApiServer.init(2);
......
......@@ -29,7 +29,7 @@ bool Options::m_log_stdout;
//------------------------------------------------------------------------------
void Options::help() {
std::cout << std::endl << "Usage: smf [OPTIONS]..." << std::endl << " -h, --help Print help and exit" << std::endl << " -c, --libconfigcfg filename Read the application configuration from this file." << std::endl
std::cout << std::endl << "Usage: AMF [OPTIONS]..." << std::endl << " -h, --help Print help and exit" << std::endl << " -c, --libconfigcfg filename Read the application configuration from this file." << std::endl
<< " -o, --stdoutlog Send the application logs to STDOUT fd." << std::endl << " -r, --rotatelog Send the application logs to local file (in current working directory)." << std::endl;
}
......
......@@ -189,7 +189,7 @@ int sctp_server::sctp_read_from_socket(int sd, uint32_t ppid) {
}
association->messages_recv++;
if (ntohl(sinfo.sinfo_ppid) != association->ppid) {
Logger::sctp().error("Received data from peer with unsollicited PPID(%d), expecting(%d)", ntohl(sinfo.sinfo_ppid), association->ppid);
Logger::sctp().error("Received data from peer with unsolicited PPID(%d), expecting(%d)", ntohl(sinfo.sinfo_ppid), association->ppid);
return SCTP_RC_ERROR;
}
Logger::sctp().info("[assoc_id(%d)][socket(%d)] Msg of length(%d) received from port(%d), on stream(%d), PPID(%d)", sinfo.sinfo_assoc_id, sd, n, ntohs(addr.sin6_port), sinfo.sinfo_stream, ntohl(sinfo.sinfo_ppid));
......@@ -213,7 +213,7 @@ int sctp_server::handle_assoc_change(int sd, uint32_t ppid, struct sctp_assoc_ch
switch (sctp_assoc_changed->sac_state) {
case SCTP_COMM_UP: {
if (add_new_association(sd, ppid, sctp_assoc_changed) == NULL) {
Logger::sctp().error("add new association with ppid(%d) socket(%d) error", ppid, sd);
Logger::sctp().error("Add new association with ppid(%d) socket(%d) error", ppid, sd);
rc = SCTP_RC_ERROR;
}
break;
......@@ -248,7 +248,7 @@ sctp_association_t* sctp_server::add_new_association(int sd, uint32_t ppid, stru
new_association->instreams = sctp_assoc_changed->sac_inbound_streams;
new_association->outstreams = sctp_assoc_changed->sac_outbound_streams;
new_association->assoc_id = (sctp_assoc_id_t) sctp_assoc_changed->sac_assoc_id;
Logger::sctp().debug("add new association with id(%d)", (sctp_assoc_id_t) sctp_assoc_changed->sac_assoc_id);
Logger::sctp().debug("Add new association with id(%d)", (sctp_assoc_id_t) sctp_assoc_changed->sac_assoc_id);
sctp_ctx.push_back(new_association);
sctp_get_localaddresses(sd, NULL, NULL);
sctp_get_peeraddresses(sd, &new_association->peer_addresses, &new_association->nb_peer_addresses);
......@@ -383,7 +383,7 @@ int sctp_server::sctp_send_msg(sctp_assoc_id_t sctp_assoc_id, sctp_stream_id_t s
}
Logger::sctp().debug("[%d][%d] Sending buffer %p of %d bytes on stream %d with ppid %d", assoc_desc->sd, sctp_assoc_id, bdata(*payload), blength(*payload), stream, assoc_desc->ppid);
if (sctp_sendmsg(assoc_desc->sd, (const void*) bdata(*payload), (size_t) blength(*payload), NULL, 0, htonl(assoc_desc->ppid), 0, stream, 0, 0) < 0) {
Logger::sctp().error("send, sd:%u,stream:%u,ppid:%u, len:%u, failed: %s,%d", assoc_desc->sd, stream, htonl(assoc_desc->ppid), blength(*payload), strerror(errno), errno);
Logger::sctp().error("Send, sd:%u,stream:%u,ppid:%u, len:%u, failed: %s,%d", assoc_desc->sd, stream, htonl(assoc_desc->ppid), blength(*payload), strerror(errno), errno);
*payload = NULL;
return -1;
}
......
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