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

Move target_amf and upf_node_id from context_ref to pdu_session

parent 391fd2b7
...@@ -1067,6 +1067,19 @@ struct node_id_s { ...@@ -1067,6 +1067,19 @@ struct node_id_s {
return false; return false;
} }
}; };
node_id_s& operator=(const struct node_id_s& i) {
node_id_type = i.node_id_type;
fqdn = i.fqdn;
u1.ipv4_address.s_addr = i.u1.ipv4_address.s_addr;
u1.ipv6_address.s6_addr32[0] = i.u1.ipv6_address.s6_addr32[0];
u1.ipv6_address.s6_addr32[1] = i.u1.ipv6_address.s6_addr32[1];
u1.ipv6_address.s6_addr32[2] = i.u1.ipv6_address.s6_addr32[2];
u1.ipv6_address.s6_addr32[3] = i.u1.ipv6_address.s6_addr32[3];
return *this;
}
std::string toString() const { std::string toString() const {
if (NODE_ID_TYPE_FQDN == this->node_id_type) { if (NODE_ID_TYPE_FQDN == this->node_id_type) {
return fqdn; return fqdn;
......
...@@ -514,14 +514,38 @@ void smf_app::handle_itti_msg(std::shared_ptr<itti_n4_node_failure> snf) { ...@@ -514,14 +514,38 @@ void smf_app::handle_itti_msg(std::shared_ptr<itti_n4_node_failure> snf) {
pfcp::node_id_t node_id = snf->node_id; pfcp::node_id_t node_id = snf->node_id;
for (auto it : scid2smf_context) { for (auto it : scid2smf_context) {
if (it.second->upf_node_id == node_id) { std::shared_ptr<smf_context> sc = {};
supi64_t supi64 = smf_supi_to_u64(it.second->supi); supi64_t supi64 = smf_supi_to_u64(it.second->supi);
Logger::smf_app().debug( if (is_supi_2_smf_context(supi64)) {
"Remove the associated PDU session (SUPI " SUPI_64_FMT sc = supi_2_smf_context(supi64);
", PDU Sessin Id %d)", }
supi64, it.second->pdu_session_id); if (sc.get() == nullptr) {
// TODO: remove the session Logger::smf_app().debug("No SMF Context found");
return;
} }
std::map<pdu_session_id_t, std::shared_ptr<smf_pdu_session>> sessions;
sc.get()->get_pdu_sessions(sessions);
for (auto s : sessions) {
pfcp::node_id_t n = s.second->get_upf_node_id();
if (n == node_id) {
Logger::smf_app().debug(
"Remove the associated PDU session (SUPI " SUPI_64_FMT
", PDU Sessin Id %d)",
supi64, it.first);
// TODO: remove the session
}
}
/*
if (it.second->upf_node_id == node_id) {
supi64_t supi64 = smf_supi_to_u64(it.second->supi);
Logger::smf_app().debug(
"Remove the associated PDU session (SUPI " SUPI_64_FMT
", PDU Sessin Id %d)",
supi64, it.second->pdu_session_id);
// TODO: remove the session
}
*/
} }
} }
...@@ -578,8 +602,8 @@ void smf_app::handle_itti_msg( ...@@ -578,8 +602,8 @@ void smf_app::handle_itti_msg(
// Get UPF node // Get UPF node
std::shared_ptr<smf_context_ref> scf = {}; std::shared_ptr<smf_context_ref> scf = {};
if (smf_app_inst->is_scid_2_smf_context(m.scid)) { if (smf_app_inst->is_scid_2_smf_context(m.scid)) {
scf = scid_2_smf_context(m.scid); scf = scid_2_smf_context(m.scid);
up_node_id = scf.get()->upf_node_id; // up_node_id = scf.get()->upf_node_id;
} else { } else {
Logger::smf_app().warn( Logger::smf_app().warn(
"SM Context associated with this id " SCID_FMT " does not exit!", "SM Context associated with this id " SCID_FMT " does not exit!",
...@@ -587,6 +611,33 @@ void smf_app::handle_itti_msg( ...@@ -587,6 +611,33 @@ void smf_app::handle_itti_msg(
return; return;
} }
std::shared_ptr<smf_context> sc = {};
supi64_t supi64 = smf_supi_to_u64(scf.get()->supi);
if (is_supi_2_smf_context(supi64)) {
Logger::smf_app().debug(
"Update SMF context with SUPI " SUPI_64_FMT "", supi64);
sc = supi_2_smf_context(supi64);
}
if (sc.get() == nullptr) {
Logger::smf_app().warn(
"SM Context associated with this id " SCID_FMT " does not exit!",
m.scid);
return;
}
std::shared_ptr<smf_pdu_session> sp = {};
if (!sc.get()->find_pdu_session(scf.get()->pdu_session_id, sp)) {
Logger::smf_app().warn("PDU session context does not exist!");
}
if (sp.get() != nullptr) {
sp.get()->get_upf_node_id(up_node_id);
} else {
Logger::smf_app().warn("PDU session context does not exist!");
return;
}
std::shared_ptr<itti_n4_session_failure_indication> std::shared_ptr<itti_n4_session_failure_indication>
itti_n4_failure_indication = itti_n4_failure_indication =
std::make_shared<itti_n4_session_failure_indication>( std::make_shared<itti_n4_session_failure_indication>(
...@@ -1143,7 +1194,9 @@ void smf_app::handle_pdu_session_update_sm_context_request( ...@@ -1143,7 +1194,9 @@ void smf_app::handle_pdu_session_update_sm_context_request(
// Step 6. Update targetServingNfId if available (for N2 Handover with AMF // Step 6. Update targetServingNfId if available (for N2 Handover with AMF
// change) // change)
if (smreq.get()->req.target_serving_nf_id_is_set()) { if (smreq.get()->req.target_serving_nf_id_is_set()) {
scf.get()->target_amf = smreq.get()->req.get_target_serving_nf_id(); // scf.get()->target_amf = smreq.get()->req.get_target_serving_nf_id();
std::string target_amf = smreq.get()->req.get_target_serving_nf_id();
sp.get()->set_target_amf(target_amf);
} }
// Step 7. Handle the message in smf_context // Step 7. Handle the message in smf_context
......
...@@ -84,9 +84,9 @@ class smf_context_ref { ...@@ -84,9 +84,9 @@ class smf_context_ref {
// dnn = {}; // dnn = {};
pdu_session_id = 0; pdu_session_id = 0;
// amf_status_uri = {}; // amf_status_uri = {};
amf_addr = {}; // amf_addr = {};
upf_node_id = {}; // upf_node_id = {};
target_amf = ""; // target_amf = "";
} }
supi_t supi; supi_t supi;
...@@ -94,9 +94,9 @@ class smf_context_ref { ...@@ -94,9 +94,9 @@ class smf_context_ref {
pdu_session_id_t pdu_session_id; pdu_session_id_t pdu_session_id;
// snssai_t nssai; // snssai_t nssai;
// std::string amf_status_uri; // std::string amf_status_uri;
std::string amf_addr; // std::string amf_addr;
std::string target_amf; // targetServingNfId // std::string target_amf; // targetServingNfId
pfcp::node_id_t upf_node_id; // pfcp::node_id_t upf_node_id;
}; };
class smf_app { class smf_app {
......
...@@ -626,7 +626,7 @@ std::string smf_pdu_session::get_amf_addr() const { ...@@ -626,7 +626,7 @@ std::string smf_pdu_session::get_amf_addr() const {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void smf_pdu_session::set_amf_status_uri(std::string& status_uri) { void smf_pdu_session::set_amf_status_uri(const std::string& status_uri) {
amf_status_uri = status_uri; amf_status_uri = status_uri;
} }
...@@ -640,6 +640,26 @@ std::string smf_pdu_session::get_amf_status_uri() const { ...@@ -640,6 +640,26 @@ std::string smf_pdu_session::get_amf_status_uri() const {
return amf_status_uri; return amf_status_uri;
} }
void smf_pdu_session::set_target_amf(const std::string& amf) {
target_amf = amf;
}
void smf_pdu_session::get_target_amf(std::string& amf) const {
amf = target_amf;
}
std::string smf_pdu_session::get_target_amf() const {
return target_amf;
}
void smf_pdu_session::set_upf_node_id(const pfcp::node_id_t& node_id) {
upf_node_id = node_id;
}
void smf_pdu_session::get_upf_node_id(pfcp::node_id_t& node_id) const {
node_id = upf_node_id;
}
pfcp::node_id_t smf_pdu_session::get_upf_node_id() const {
return upf_node_id;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
std::string smf_pdu_session::get_dnn() const { std::string smf_pdu_session::get_dnn() const {
return dnn; return dnn;
...@@ -3684,6 +3704,17 @@ size_t smf_context::get_number_pdu_sessions() const { ...@@ -3684,6 +3704,17 @@ size_t smf_context::get_number_pdu_sessions() const {
return pdu_sessions.size(); return pdu_sessions.size();
} }
//------------------------------------------------------------------------------
void smf_context::get_pdu_sessions(
std::map<pdu_session_id_t, std::shared_ptr<smf_pdu_session>>& sessions) {
std::shared_lock lock(m_pdu_sessions_mutex);
for (auto it : pdu_sessions) {
sessions.insert(
std::pair<pdu_session_id_t, std::shared_ptr<smf_pdu_session>>(
it.first, it.second));
}
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void smf_context::handle_sm_context_status_change( void smf_context::handle_sm_context_status_change(
scid_t scid, const std::string& status, uint8_t http_version) { scid_t scid, const std::string& status, uint8_t http_version) {
......
...@@ -454,10 +454,18 @@ class smf_pdu_session : public std::enable_shared_from_this<smf_pdu_session> { ...@@ -454,10 +454,18 @@ class smf_pdu_session : public std::enable_shared_from_this<smf_pdu_session> {
void get_amf_addr(std::string& addr) const; void get_amf_addr(std::string& addr) const;
std::string get_amf_addr() const; std::string get_amf_addr() const;
void set_amf_status_uri(std::string& status_uri); void set_amf_status_uri(const std::string& status_uri);
void get_amf_status_uri(std::string& status_uri) const; void get_amf_status_uri(std::string& status_uri) const;
std::string get_amf_status_uri() const; std::string get_amf_status_uri() const;
void set_target_amf(const std::string& amf);
void get_target_amf(std::string& amf) const;
std::string get_target_amf() const;
void set_upf_node_id(const pfcp::node_id_t& node_id);
void get_upf_node_id(pfcp::node_id_t& node_id) const;
pfcp::node_id_t get_upf_node_id() const;
std::string get_dnn() const; std::string get_dnn() const;
snssai_t get_snssai() const; snssai_t get_snssai() const;
void set_dnn(const std::string& d); void set_dnn(const std::string& d);
...@@ -479,6 +487,8 @@ class smf_pdu_session : public std::enable_shared_from_this<smf_pdu_session> { ...@@ -479,6 +487,8 @@ class smf_pdu_session : public std::enable_shared_from_this<smf_pdu_session> {
std::string amf_id; std::string amf_id;
std::string amf_addr; std::string amf_addr;
std::string amf_status_uri; std::string amf_status_uri;
std::string target_amf; // targetServingNfId
pfcp::node_id_t upf_node_id;
pdu_session_status_e pdu_session_status; pdu_session_status_e pdu_session_status;
upCnx_state_e upCnx_state_e
...@@ -1097,6 +1107,9 @@ class smf_context : public std::enable_shared_from_this<smf_context> { ...@@ -1097,6 +1107,9 @@ class smf_context : public std::enable_shared_from_this<smf_context> {
*/ */
size_t get_number_pdu_sessions() const; size_t get_number_pdu_sessions() const;
void get_pdu_sessions(
std::map<pdu_session_id_t, std::shared_ptr<smf_pdu_session>>& sessions);
/* /*
* Handle SM Context Status Change (Send notification AMF) * Handle SM Context Status Change (Send notification AMF)
* @param [scid_t] scid: SMF Context ID * @param [scid_t] scid: SMF Context ID
......
...@@ -102,9 +102,10 @@ int session_create_sm_context_procedure::run( ...@@ -102,9 +102,10 @@ int session_create_sm_context_procedure::run(
std::shared_ptr<smf::smf_context> sc) { std::shared_ptr<smf::smf_context> sc) {
Logger::smf_app().info("Perform a procedure - Create SM Context Request"); Logger::smf_app().info("Perform a procedure - Create SM Context Request");
// TODO check if compatible with ongoing procedures if any // TODO check if compatible with ongoing procedures if any
pfcp::node_id_t up_node_id = {}; pfcp::node_id_t up_node_id = {};
snssai_t snssai = sm_context_req->req.get_snssai(); snssai_t snssai = sm_context_req->req.get_snssai();
std::string dnn = sm_context_req->req.get_dnn(); std::string dnn = sm_context_req->req.get_dnn();
pdu_session_id_t pdu_session_id = sm_context_req->req.get_pdu_session_id();
if (not pfcp_associations::get_instance().select_up_node( if (not pfcp_associations::get_instance().select_up_node(
up_node_id, snssai, dnn)) { up_node_id, snssai, dnn)) {
...@@ -116,7 +117,16 @@ int session_create_sm_context_procedure::run( ...@@ -116,7 +117,16 @@ int session_create_sm_context_procedure::run(
std::shared_ptr<smf_context_ref> scf = {}; std::shared_ptr<smf_context_ref> scf = {};
if (smf_app_inst->is_scid_2_smf_context(sm_context_req->scid)) { if (smf_app_inst->is_scid_2_smf_context(sm_context_req->scid)) {
scf = smf_app_inst->scid_2_smf_context(sm_context_req->scid); scf = smf_app_inst->scid_2_smf_context(sm_context_req->scid);
scf.get()->upf_node_id = up_node_id; // scf.get()->upf_node_id = up_node_id;
std::shared_ptr<smf_pdu_session> sp = {};
if (!sc.get()->find_pdu_session(scf.get()->pdu_session_id, sp)) {
Logger::smf_app().warn("PDU session context does not exist!");
sm_context_resp->res.set_cause(
PDU_SESSION_APPLICATION_ERROR_CONTEXT_NOT_FOUND);
return RETURNerror;
}
if (sp.get() != nullptr) sp.get()->set_upf_node_id(up_node_id);
} else { } else {
Logger::smf_app().warn( Logger::smf_app().warn(
"SM Context associated with this id " SCID_FMT " does not exit!", "SM Context associated with this id " SCID_FMT " does not exit!",
...@@ -527,12 +537,24 @@ int session_update_sm_context_procedure::run( ...@@ -527,12 +537,24 @@ int session_update_sm_context_procedure::run(
sm_context_req->scid); sm_context_req->scid);
} }
if (smf_app_inst->is_scid_2_smf_context(scid)) { if (smf_app_inst->is_scid_2_smf_context(scid)) {
scf = smf_app_inst->scid_2_smf_context(scid); scf = smf_app_inst->scid_2_smf_context(scid);
up_node_id = scf.get()->upf_node_id; // up_node_id = scf.get()->upf_node_id;
} else { } else {
Logger::smf_app().warn( Logger::smf_app().warn(
"SM Context associated with this id " SCID_FMT " does not exit!", scid); "SM Context associated with this id " SCID_FMT " does not exit!", scid);
// TODO: // TODO:
return RETURNerror;
}
std::shared_ptr<smf_pdu_session> sp = {};
if (!sc.get()->find_pdu_session(scf.get()->pdu_session_id, sp)) {
Logger::smf_app().warn("PDU session context does not exist!");
}
if (sp.get() != nullptr) {
sp.get()->get_upf_node_id(up_node_id);
} else {
Logger::smf_app().warn("PDU session context does not exist!");
return RETURNerror;
} }
// TODO: UPF insertion in case of Handover // TODO: UPF insertion in case of Handover
...@@ -1383,12 +1405,24 @@ int session_release_sm_context_procedure::run( ...@@ -1383,12 +1405,24 @@ int session_release_sm_context_procedure::run(
sm_context_req->scid); sm_context_req->scid);
} }
if (smf_app_inst->is_scid_2_smf_context(scid)) { if (smf_app_inst->is_scid_2_smf_context(scid)) {
scf = smf_app_inst->scid_2_smf_context(scid); scf = smf_app_inst->scid_2_smf_context(scid);
up_node_id = scf.get()->upf_node_id; // up_node_id = scf.get()->upf_node_id;
} else { } else {
Logger::smf_app().warn( Logger::smf_app().warn(
"SM Context associated with this id " SCID_FMT " does not exit!", scid); "SM Context associated with this id " SCID_FMT " does not exit!", scid);
// TODO: // TODO:
return RETURNerror;
}
std::shared_ptr<smf_pdu_session> sp = {};
if (!sc.get()->find_pdu_session(scf.get()->pdu_session_id, sp)) {
Logger::smf_app().warn("PDU session context does not exist!");
}
if (sp.get() != nullptr) {
sp.get()->get_upf_node_id(up_node_id);
} else {
Logger::smf_app().warn("PDU session context does not exist!");
return RETURNerror;
} }
/* if (not pfcp_associations::get_instance().select_up_node( /* if (not pfcp_associations::get_instance().select_up_node(
......
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