Commit 474fed58 authored by yangjian's avatar yangjian

fix gnb/ue display problem

parent e9011b79
......@@ -798,6 +798,15 @@ void amf_n1::registration_request_handle(bool isNasSig,
ueItem.mnc = uc.get()->cgi.mnc;
ueItem.cellId = uc.get()->cgi.nrCellID;
std::shared_ptr<ue_ngap_context> unc;
unc = amf_n2_inst->ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id);
if (unc.get() == nullptr) {
Logger::amf_n2().error(
"Illegal UE with ran_ue_ngap_id (0x%x)",ran_ue_ngap_id);
return;
}
ueItem.gnb_assoc_id = unc.get()->gnb_assoc_id;
stacs.update_ue_info(ueItem);
set_5gmm_state(nc, _5GMM_COMMON_PROCEDURE_INITIATED);
nc.get()->is_stacs_available = true;
......
......@@ -398,6 +398,8 @@ void amf_n2::handle_itti_message(itti_ng_setup_request& itti_msg) {
Logger::amf_n2().debug(
"gNB with gNB_id 0x%x, assoc_id %d has been attached to AMF",
gc.get()->globalRanNodeId, itti_msg.assoc_id);
// if()
stacs.gNB_connected += 1;
stacs.gnbs.push_back(gnbItem);
return;
......
......@@ -102,6 +102,7 @@ statistics::statistics() {
//------------------------------------------------------------------------------
void statistics::update_ue_info(const ue_info_t& ue_info) {
std::shared_lock lock(m_ue_infos);
if (!(ue_info.imsi.size() > 0)) {
Logger::amf_app().warn("Update UE Info with invalid IMSI");
}
......@@ -121,6 +122,7 @@ void statistics::update_ue_info(const ue_info_t& ue_info) {
//------------------------------------------------------------------------------
void statistics::update_5gmm_state(
const std::string& imsi, const std::string& state) {
std::shared_lock lock(m_ue_infos);
if (ue_infos.count(imsi) > 0) {
ue_info_t ue_info = ue_infos.at(imsi);
ue_info.registerStatus = state;
......@@ -135,5 +137,15 @@ void statistics::update_5gmm_state(
}
}
//------------------------------------------------------------------------------
void statistics::delete_ue_info_about_gnb(sctp::sctp_assoc_id_t gnb_assoc_id) {
std::shared_lock lock(m_ue_infos);
for(auto it : ue_infos){
// cout << it.first <<" "<< it.second <<endl;
if(it.second.gnb_assoc_id == gnb_assoc_id)
ue_infos.erase(it.second.imsi);
}
}
//------------------------------------------------------------------------------
statistics::~statistics() {}
......@@ -35,6 +35,8 @@
#include "amf.hpp"
#include "ngap_app.hpp"
#include "sctp_server.hpp"
typedef struct {
uint32_t gnb_id;
// TODO: list of PLMNs
......@@ -56,6 +58,7 @@ typedef struct ue_info_s {
std::string mcc;
std::string mnc;
uint32_t cellId;
sctp::sctp_assoc_id_t gnb_assoc_id;
} ue_info_t;
class statistics {
......@@ -65,6 +68,7 @@ class statistics {
~statistics();
void update_ue_info(const ue_info_t& ue_info);
void update_5gmm_state(const std::string& imsi, const std::string& state);
void delete_ue_info_about_gnb(sctp::sctp_assoc_id_t gnb_assoc_id);
public:
uint32_t gNB_connected;
......@@ -73,6 +77,7 @@ class statistics {
// uint32_t system_pdu_sessions;
std::vector<gnb_infos> gnbs;
std::map<std::string, ue_info_t> ue_infos;
mutable std::shared_mutex m_ue_infos;
};
#endif
......@@ -38,12 +38,14 @@ extern "C" {
#include "Ngap_InitiatingMessage.h"
}
#include "amf_statistics.hpp"
using namespace sctp;
using namespace config;
using namespace ngap;
extern amf_config amf_cfg;
extern statistics stacs;
//------------------------------------------------------------------------------
ngap_app::ngap_app(const std::string& address, const uint16_t port_num)
......@@ -121,6 +123,43 @@ void ngap_app::handle_sctp_new_association(
}
}
// handle shutdown sctp association
void ngap_app::handle_sctp_del_association(sctp_assoc_id_t assoc_id/*, sctp_stream_id_t instreams,sctp_stream_id_t outstreams*/)
{
Logger::ngap().debug("Ready to handle del NGAP SCTP association (id: %d)", assoc_id);
if(is_assoc_id_2_gnb_context(assoc_id))
{
Logger::ngap().debug("gnb_context exist");
std::shared_ptr<gnb_context> gc;
gc = assoc_id_2_gnb_context(assoc_id);
Logger::ngap().debug("globalRanNodeId(%d)",gc.get()->globalRanNodeId);
//Example Delete UE information
stacs.delete_ue_info_about_gnb(assoc_id);
//Example Delete GNB information
for (auto iter = stacs.gnbs.begin(); iter != stacs.gnbs.end(); ++iter) {
if (iter->gnb_id == gc.get()->globalRanNodeId) {
stacs.gnbs.erase(iter);
break;
}
}
del_assoc_id_2_gnb_context(assoc_id);
// Logger::ngap().debug("s_ta_list size(%d)",gc.get()->s_ta_list.size());
// Logger::ngap().debug("s_ta_list[0] tac(%d)",gc.get()->s_ta_list[0].tac);
// Logger::ngap().debug("s_ta_list[0] PlmnSliceSupport size(%d)",gc.get()->s_ta_list[0].b_plmn_list.size());
// Logger::ngap().debug("s_ta_list[0] PlmnSliceSupport[0] mcc(%s)",gc.get()->s_ta_list[0].b_plmn_list[0].mcc.c_str());
// Logger::ngap().debug("s_ta_list[0] PlmnSliceSupport[0] mnc(%s)",gc.get()->s_ta_list[0].b_plmn_list[0].mnc.c_str());
// Logger::ngap().debug("sctp_assoc_id (%d)",gc.get()->sctp_assoc_id);
// traversing_gnb_context();
}
}
//------------------------------------------------------------------------------
uint32_t ngap_app::getPpid() {
//return ppid_;
......@@ -149,6 +188,12 @@ void ngap_app::set_assoc_id_2_gnb_context(
assoc2gnbContext[assoc_id] = gc;
}
//------------------------------------------------------------------------------
void ngap_app::del_assoc_id_2_gnb_context(const sctp_assoc_id_t& assoc_id) {
std::shared_lock lock(m_assoc2gnbContext);
assoc2gnbContext.erase(assoc_id);
}
//------------------------------------------------------------------------------
bool ngap_app::is_gnb_id_2_gnb_context(const long& gnb_id) const {
std::shared_lock lock(m_gnbid2gnbContext);
......@@ -168,3 +213,11 @@ void ngap_app::set_gnb_id_2_gnb_context(
std::shared_lock lock(m_gnbid2gnbContext);
gnbid2gnbContext[gnb_id] = gc;
}
//------------------------------------------------------------------------------
void ngap_app::traversing_gnb_context() {
std::shared_lock lock(m_assoc2gnbContext);
for(auto it : assoc2gnbContext){
cout << it.first <<" "<< it.second <<endl;
}
}
......@@ -54,12 +54,16 @@ class ngap_app : public sctp_application {
void handle_sctp_new_association(
sctp_assoc_id_t assoc_id, sctp_stream_id_t instreams,
sctp_stream_id_t outstreams);
void handle_sctp_del_association(sctp_assoc_id_t assoc_id/*, sctp_stream_id_t instreams,sctp_stream_id_t outstreams*/);
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);
void del_assoc_id_2_gnb_context(const sctp_assoc_id_t& assoc_id);
std::shared_ptr<gnb_context> assoc_id_2_gnb_context(
const sctp_assoc_id_t& assoc_id) const;
void traversing_gnb_context();
bool is_gnb_id_2_gnb_context(const long& gnb_id) const;
void set_gnb_id_2_gnb_context(
const long& gnb_id, std::shared_ptr<gnb_context> gc);
......
......@@ -208,7 +208,10 @@ int sctp_server::sctp_read_from_socket(int sd, uint32_t ppid) {
}
//------------------------------------------------------------------------------
int sctp_server::sctp_handle_com_down(sctp_assoc_id_t assoc_id) {}
int sctp_server::sctp_handle_com_down(sctp_assoc_id_t assoc_id) {
Logger::sctp().info("SCTP_SHUTDOWN_COMP assoc_id (%d) ", assoc_id);
app_->handle_sctp_del_association(assoc_id);
}
//------------------------------------------------------------------------------
int sctp_server::sctp_handle_reset(const sctp_assoc_id_t assoc_id) {}
......@@ -235,7 +238,12 @@ int sctp_server::handle_assoc_change(
break;
}
case SCTP_COMM_LOST:
case SCTP_SHUTDOWN_COMP:
case SCTP_SHUTDOWN_COMP:{
Logger::sctp().info("SCTP_SHUTDOWN_COMP ppid (%d) socket (%d) sctp message (%d)", ppid, sd, sctp_assoc_changed->sac_state);
//break;
}
case SCTP_CANT_STR_ASSOC: {
if (sctp_is_assoc_in_list(
(sctp_assoc_id_t) sctp_assoc_changed->sac_assoc_id) != NULL) {
......
......@@ -85,6 +85,7 @@ class sctp_application {
sctp_assoc_id_t assoc_id, sctp_stream_id_t instreams,
sctp_stream_id_t outstreams) = 0;
virtual uint32_t getPpid() = 0;
virtual void handle_sctp_del_association(sctp_assoc_id_t assoc_id/*, sctp_stream_id_t instreams,sctp_stream_id_t outstreams*/) = 0;
};
class sctp_server {
......
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