Commit 20e0d301 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Fix issue for directly using member variable

parent f15eb00c
......@@ -1391,7 +1391,7 @@ void amf_n1::set_amf_ue_ngap_id_2_nas_context(
void amf_n1::remove_amf_ue_ngap_id_2_nas_context(const long& amf_ue_ngap_id) {
std::unique_lock lock(m_amfueid2nas_context);
if (amfueid2nas_context.count(amf_ue_ngap_id) > 0) {
amfueid2nas_context[amf_ue_ngap_id] = nullptr;
amfueid2nas_context.erase(amf_ue_ngap_id);
}
}
......
......@@ -489,23 +489,15 @@ void amf_n2::handle_itti_message(itti_ng_reset& itti_msg) {
if (reset_type.getResetType() == Ngap_ResetType_PR_nG_Interface) {
// Reset all
// release all the resources related to this interface
for (auto ue_context : ranid2uecontext) {
if (ue_context.second->gnb_assoc_id == itti_msg.assoc_id) {
uint32_t ran_ue_ngap_id = ue_context.second->ran_ue_ngap_id;
long amf_ue_ngap_id = ue_context.second->amf_ue_ngap_id;
// get NAS context
std::shared_ptr<nas_context> nc;
if (amf_n1_inst->is_amf_ue_id_2_nas_context(amf_ue_ngap_id))
nc = amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id);
else {
Logger::amf_n2().warn(
"No existed nas_context with amf_ue_ngap_id(" AMF_UE_NGAP_ID_FMT
")",
amf_ue_ngap_id);
}
stacs.update_5gmm_state(nc.get()->imsi, "5GMM-DEREGISTERED");
}
std::vector<std::shared_ptr<ue_ngap_context>> ue_contexts;
get_ue_ngap_contexts(itti_msg.assoc_id, ue_contexts);
for (auto ue_context : ue_contexts) {
remove_ue_context_with_amf_ue_ngap_id(ue_context->amf_ue_ngap_id);
remove_ue_context_with_ran_ue_ngap_id(ue_context->ran_ue_ngap_id);
}
stacs.display();
} else if (
reset_type.getResetType() == Ngap_ResetType_PR_partOfNG_Interface) {
......@@ -514,18 +506,11 @@ void amf_n2::handle_itti_message(itti_ng_reset& itti_msg) {
ueAssociationLogicalNGConnectionList);
for (auto ue : ueAssociationLogicalNGConnectionList) {
unsigned long amf_ue_ngap_id = {0};
ue.getAmfUeNgapId(amf_ue_ngap_id);
uint32_t ran_ue_ngap_id = {0};
ue.getRanUeNgapId(ran_ue_ngap_id);
// get NAS context
std::shared_ptr<nas_context> nc;
if (amf_n1_inst->is_amf_ue_id_2_nas_context(amf_ue_ngap_id)) {
nc = amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id);
} else {
Logger::amf_n2().warn(
"No existed nas_context with amf_ue_ngap_id(" AMF_UE_NGAP_ID_FMT
")",
amf_ue_ngap_id);
uint32_t ran_ue_ngap_id = {0};
if (ue.getAmfUeNgapId(amf_ue_ngap_id)) {
remove_ue_context_with_amf_ue_ngap_id(amf_ue_ngap_id);
} else if (ue.getRanUeNgapId(ran_ue_ngap_id)) {
remove_ue_context_with_ran_ue_ngap_id(ran_ue_ngap_id);
}
}
}
......@@ -568,27 +553,12 @@ void amf_n2::handle_itti_message(itti_ng_shutdown& itti_msg) {
gc.get()->ng_state = NGAP_SHUTDOWN;
// Release all the resources related to this interface
uint32_t ran_ue_ngap_id = 0;
for (auto ue_context : ranid2uecontext) {
if (ue_context.second->gnb_assoc_id == itti_msg.assoc_id) {
ran_ue_ngap_id = ue_context.second->ran_ue_ngap_id;
long amf_ue_ngap_id = ue_context.second->amf_ue_ngap_id;
// get NAS context
std::shared_ptr<nas_context> nc = {};
if (amf_n1_inst->is_amf_ue_id_2_nas_context(amf_ue_ngap_id)) {
nc = amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id);
stacs.update_5gmm_state(nc.get()->imsi, "5GMM-DEREGISTERED");
} else {
Logger::amf_n2().warn(
"No existed nas_context with amf_ue_ngap_id(" AMF_UE_NGAP_ID_FMT
")",
amf_ue_ngap_id);
}
}
}
// remove UE context
if (ranid2uecontext.count(ran_ue_ngap_id) > 0) {
ranid2uecontext.erase(ran_ue_ngap_id);
std::vector<std::shared_ptr<ue_ngap_context>> ue_contexts;
get_ue_ngap_contexts(itti_msg.assoc_id, ue_contexts);
for (auto ue_context : ue_contexts) {
remove_ue_context_with_amf_ue_ngap_id(ue_context->amf_ue_ngap_id);
remove_ue_context_with_ran_ue_ngap_id(ue_context->ran_ue_ngap_id);
}
// Delete gNB context
......@@ -2180,8 +2150,6 @@ bool amf_n2::is_ran_ue_id_2_ue_ngap_context(
}
}
return false;
// return bool{ranid2uecontext.count(ran_ue_ngap_id) > 0};
}
//------------------------------------------------------------------------------
......@@ -2198,36 +2166,57 @@ void amf_n2::set_ran_ue_ngap_id_2_ue_ngap_context(
ranid2uecontext[ran_ue_ngap_id] = unc;
}
/*
//------------------------------------------------------------------------------
bool amf_n2::get_ue_ngap_context_from_ran_ue_id(const uint32_t ran_ue_ngap_id,
std::shared_ptr<ue_ngap_context>& ue_context){ std::shared_lock
lock(m_ranid2uecontext); if (ranid2uecontext.count(ran_ue_ngap_id) > 0) { if
(ranid2uecontext.at(ran_ue_ngap_id).get() != nullptr) { ue_context =
ranid2uecontext.at(ran_ue_ngap_id); return true;
}
}
return false;
void amf_n2::remove_ran_ue_ngap_id_2_ngap_context(
const uint32_t& ran_ue_ngap_id) {
std::unique_lock lock(m_ranid2uecontext);
if (ranid2uecontext.count(ran_ue_ngap_id) > 0) {
ranid2uecontext.erase(ran_ue_ngap_id);
}
}
*/
//------------------------------------------------------------------------------
void amf_n2::get_ue_ngap_contexts(
std::vector<uint32_t> ran_ue_ngap_ids,
std::vector<std::shared_ptr<ue_ngap_context>>& ue_contexts) {
std::shared_lock lock(m_ranid2uecontext);
for (auto ran_ue_ngap_id : ran_ue_ngap_ids) {
ue_contexts.push_back(ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id));
void amf_n2::remove_ue_context_with_ran_ue_ngap_id(
const uint32_t& ran_ue_ngap_id) {
// Remove NAS context if still available
std::shared_ptr<ue_ngap_context> unc = {};
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 (" GNB_UE_NGAP_ID_FMT ")",
ran_ue_ngap_id);
return;
}
unc = ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id);
// Remove all NAS context if still exist
std::shared_ptr<nas_context> nc = nullptr;
if (amf_n1_inst->is_amf_ue_id_2_nas_context(unc.get()->amf_ue_ngap_id)) {
nc = amf_n1_inst->amf_ue_id_2_nas_context(unc.get()->amf_ue_ngap_id);
// Remove all NAS context
string supi = "imsi-" + nc.get()->imsi;
amf_n1_inst->remove_imsi_2_nas_context(supi);
// TODO: remove_guti_2_nas_context(guti);
amf_n1_inst->remove_amf_ue_ngap_id_2_nas_context(unc.get()->amf_ue_ngap_id);
} else {
Logger::amf_n2().warn(
"No existed nas_context with amf_ue_ngap_id(" AMF_UE_NGAP_ID_FMT ")",
unc.get()->amf_ue_ngap_id);
}
// Remove NGAP context
remove_amf_ue_ngap_id_2_ue_ngap_context(unc.get()->amf_ue_ngap_id);
remove_ran_ue_ngap_id_2_ngap_context(ran_ue_ngap_id);
}
//------------------------------------------------------------------------------
void amf_n2::get_all_ue_ngap_contexts(
void amf_n2::get_ue_ngap_contexts(
const sctp_assoc_id_t& gnb_assoc_id,
std::vector<std::shared_ptr<ue_ngap_context>>& ue_contexts) {
std::shared_lock lock(m_ranid2uecontext);
for (auto ue : ranid2uecontext) {
ue_contexts.push_back(ue.second);
if (ue.second->gnb_assoc_id == gnb_assoc_id)
ue_contexts.push_back(ue.second);
}
}
......@@ -2242,7 +2231,6 @@ std::shared_ptr<ue_ngap_context> amf_n2::amf_ue_id_2_ue_ngap_context(
bool amf_n2::is_amf_ue_id_2_ue_ngap_context(
const unsigned long& amf_ue_ngap_id) const {
std::shared_lock lock(m_amfueid2uecontext);
// return bool{amfueid2uecontext.count(amf_ue_ngap_id) > 0};
if (amfueid2uecontext.count(amf_ue_ngap_id) > 0) {
if (amfueid2uecontext.at(amf_ue_ngap_id).get() != nullptr) {
return true;
......@@ -2258,6 +2246,38 @@ void amf_n2::set_amf_ue_ngap_id_2_ue_ngap_context(
amfueid2uecontext[amf_ue_ngap_id] = unc;
}
//------------------------------------------------------------------------------
void amf_n2::remove_amf_ue_ngap_id_2_ue_ngap_context(
const unsigned long& amf_ue_ngap_id) {
std::unique_lock lock(m_amfueid2uecontext);
if (amfueid2uecontext.count(amf_ue_ngap_id) > 0) {
amfueid2uecontext.erase(amf_ue_ngap_id);
}
}
//------------------------------------------------------------------------------
void amf_n2::remove_ue_context_with_amf_ue_ngap_id(
const unsigned long& amf_ue_ngap_id) {
// Remove all NAS context if still exist
std::shared_ptr<nas_context> nc = nullptr;
if (amf_n1_inst->is_amf_ue_id_2_nas_context(amf_ue_ngap_id)) {
nc = amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id);
// Remove all NAS context
string supi = "imsi-" + nc.get()->imsi;
amf_n1_inst->remove_imsi_2_nas_context(supi);
// TODO: remove_guti_2_nas_context(guti);
amf_n1_inst->remove_amf_ue_ngap_id_2_nas_context(amf_ue_ngap_id);
// Remove NGAP context related to RAN UE NGAP ID
remove_ran_ue_ngap_id_2_ngap_context(nc.get()->ran_ue_ngap_id);
} else {
Logger::amf_n2().warn(
"No existed nas_context with amf_ue_ngap_id(" AMF_UE_NGAP_ID_FMT ")",
amf_ue_ngap_id);
}
// Remove NGAP context
remove_amf_ue_ngap_id_2_ue_ngap_context(amf_ue_ngap_id);
}
//------------------------------------------------------------------------------
bool amf_n2::verifyPlmn(vector<SupportedItem_t> list) {
for (int i = 0; i < amf_cfg.plmn_list.size(); i++) {
......
......@@ -209,6 +209,12 @@ class amf_n2 : public ngap::ngap_app {
// TODO
void set_ran_ue_ngap_id_2_ue_ngap_context(
const uint32_t& ran_ue_ngap_id, std::shared_ptr<ue_ngap_context> unc);
void remove_ran_ue_ngap_id_2_ngap_context(const uint32_t& ran_ue_ngap_id);
// TODO:
void remove_ue_context_with_ran_ue_ngap_id(const uint32_t& ran_ue_ngap_id);
// TODO
std::shared_ptr<ue_ngap_context> amf_ue_id_2_ue_ngap_context(
const unsigned long& amf_ue_ngap_id) const;
......@@ -219,11 +225,12 @@ class amf_n2 : public ngap::ngap_app {
void set_amf_ue_ngap_id_2_ue_ngap_context(
const unsigned long& amf_ue_ngap_id,
std::shared_ptr<ue_ngap_context> unc);
void remove_amf_ue_ngap_id_2_ue_ngap_context(
const unsigned long& amf_ue_ngap_id);
void remove_ue_context_with_amf_ue_ngap_id(
const unsigned long& amf_ue_ngap_id);
void get_ue_ngap_contexts(
std::vector<uint32_t> ran_ue_ngap_ids,
std::vector<std::shared_ptr<ue_ngap_context>>& ue_contexts);
void get_all_ue_ngap_contexts(
const sctp_assoc_id_t& gnb_assoc_id,
std::vector<std::shared_ptr<ue_ngap_context>>& ue_contexts);
private:
......
......@@ -42,6 +42,10 @@ UEAssociationLogicalNGConnectionList::UEAssociationLogicalNGConnectionList() {
number_of_items = 0;
}
UEAssociationLogicalNGConnectionList::~UEAssociationLogicalNGConnectionList() {
if (ueAssociationLogicalNGConnectionItem)
delete[] ueAssociationLogicalNGConnectionItem;
}
//------------------------------------------------------------------------------
void UEAssociationLogicalNGConnectionList::
setUEAssociationLogicalNGConnectionItem(
......
......@@ -44,7 +44,7 @@ namespace ngap {
class UEAssociationLogicalNGConnectionList {
public:
UEAssociationLogicalNGConnectionList();
virtual ~UEAssociationLogicalNGConnectionList(){};
virtual ~UEAssociationLogicalNGConnectionList();
void setUEAssociationLogicalNGConnectionItem(
UEAssociationLogicalNGConnectionItem*
......
......@@ -54,7 +54,13 @@ NGResetAckMsg::NGResetAckMsg() {
CriticalityDiagnostics = nullptr;
}
//------------------------------------------------------------------------------
NGResetAckMsg::~NGResetAckMsg() {}
NGResetAckMsg::~NGResetAckMsg() {
if (ngResetAckPdu) free_wrapper((void**) &ngResetAckPdu);
if (ngResetAckIEs) free_wrapper((void**) &ngResetAckIEs);
if (ueAssociationLogicalNGConnectionList)
free_wrapper((void**) &ueAssociationLogicalNGConnectionList);
if (CriticalityDiagnostics) free_wrapper((void**) &CriticalityDiagnostics);
}
//------------------------------------------------------------------------------
void NGResetAckMsg::setMessageType() {
......
......@@ -65,7 +65,7 @@ class NGResetAckMsg {
Ngap_NGAP_PDU_t* ngResetAckPdu;
Ngap_NGResetAcknowledge_t* ngResetAckIEs;
UEAssociationLogicalNGConnectionList* ueAssociationLogicalNGConnectionList;
std::unique_ptr<Ngap_CriticalityDiagnostics_t> CriticalityDiagnostics;
Ngap_CriticalityDiagnostics_t* CriticalityDiagnostics;
};
} // namespace ngap
......
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