From cb5f3954b652c223f1d452fcf67ed448e64435f6 Mon Sep 17 00:00:00 2001 From: Maud Tribaudeau Date: Thu, 10 Aug 2023 10:13:08 +0000 Subject: [PATCH] fix gtp delete. we should not delete all bearer in case of dedicaded bearer release --- openair2/RRC/LTE/rrc_eNB.c | 2 +- openair2/RRC/NR/rrc_gNB_nsa.c | 2 +- openair3/ocp-gtpu/gtp_itf.cpp | 42 ++++++++++++++++++++++++++++++++--- openair3/ocp-gtpu/gtp_itf.h | 1 + 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/openair2/RRC/LTE/rrc_eNB.c b/openair2/RRC/LTE/rrc_eNB.c index 6b78e27f63..d7812df89e 100644 --- a/openair2/RRC/LTE/rrc_eNB.c +++ b/openair2/RRC/LTE/rrc_eNB.c @@ -3842,7 +3842,7 @@ void rrc_eNB_handover_ue_context_release( ue_context_p->ue_context.enb_gtp_ebi[e_rab] = 0; } - gtpv1u_delete_s1u_tunnel(ctxt_pP->module_id, &delete_tunnels); + gtpv1u_delete_all_s1u_tunnel(ctxt_pP->module_id, delete_tunnels.rnti); struct rrc_ue_s1ap_ids_s *rrc_ue_s1ap_ids = NULL; rrc_ue_s1ap_ids = rrc_eNB_S1AP_get_ue_ids(RC.rrc[ctxt_pP->module_id], 0, eNB_ue_s1ap_id); diff --git a/openair2/RRC/NR/rrc_gNB_nsa.c b/openair2/RRC/NR/rrc_gNB_nsa.c index 656c7d0663..2c98e9f27b 100644 --- a/openair2/RRC/NR/rrc_gNB_nsa.c +++ b/openair2/RRC/NR/rrc_gNB_nsa.c @@ -423,7 +423,7 @@ void rrc_remove_nsa_user(gNB_RRC_INST *rrc, int rnti) { memset(&ue_context->ue_context.nsa_gtp_addrs[e_rab], 0, sizeof(ue_context->ue_context.nsa_gtp_addrs[e_rab])); ue_context->ue_context.nsa_gtp_ebi[e_rab] = 0; } - gtpv1u_delete_s1u_tunnel(rrc->module_id, &tmp); + gtpv1u_delete_all_s1u_tunnel(rrc->module_id, rnti); /* remove context */ rrc_gNB_remove_ue_context(rrc, ue_context); } diff --git a/openair3/ocp-gtpu/gtp_itf.cpp b/openair3/ocp-gtpu/gtp_itf.cpp index 5a75b8953a..96c9c79e85 100644 --- a/openair3/ocp-gtpu/gtp_itf.cpp +++ b/openair3/ocp-gtpu/gtp_itf.cpp @@ -825,11 +825,47 @@ int newGtpuDeleteAllTunnels(instance_t instance, ue_id_t ue_id) { return !GTPNOK; } -// Legacy delete tunnel finish by deleting all the ue id -// so the list of bearer provided is only a design bug int gtpv1u_delete_s1u_tunnel( const instance_t instance, const gtpv1u_enb_delete_tunnel_req_t *const req_pP) { - return newGtpuDeleteAllTunnels(instance, req_pP->rnti); + LOG_D(GTPU, "[%ld] Start delete tunnels for RNTI %x\n", instance, req_pP->rnti); + pthread_mutex_lock(&globGtp.gtp_lock); + auto inst = &globGtp.instances[compatInst(instance)]; + auto ptrRNTI = inst->ue2te_mapping.find(req_pP->rnti); + if (ptrRNTI == inst->ue2te_mapping.end()) { + LOG_W(GTPU, "[%ld] Delete Released GTP tunnels for rnti: %x, but no tunnel exits\n", instance, req_pP->rnti); + pthread_mutex_unlock(&globGtp.gtp_lock); + return -1; + } + + int nb = 0; + + for (int i = 0; i < req_pP->num_erab; i++) { + auto ptr2 = ptrRNTI->second.bearers.find(req_pP->eps_bearer_id[i]); + if (ptr2 == ptrRNTI->second.bearers.end()) { + LOG_E(GTPU, + "[%ld] GTP-U instance: delete of not existing tunnel RNTI:RAB: %x/%x\n", + instance, + req_pP->rnti, + req_pP->eps_bearer_id[i]); + } else { + globGtp.te2ue_mapping.erase(ptr2->second.teid_incoming); + nb++; + } + } + + if (ptrRNTI->second.bearers.size() == 0) + // no tunnels on this rnti, erase the ue entry + inst->ue2te_mapping.erase(ptrRNTI); + + pthread_mutex_unlock(&globGtp.gtp_lock); + LOG_I(GTPU, "[%ld] Deleted released tunnels for RNTI %x (%d tunnels deleted)\n", instance, req_pP->rnti, nb); + return !GTPNOK; +} + +// Legacy delete tunnel finish by deleting all the ue id +int gtpv1u_delete_all_s1u_tunnel(const instance_t instance, const rnti_t rnti) +{ + return newGtpuDeleteAllTunnels(instance, rnti); } int newGtpuDeleteTunnels(instance_t instance, ue_id_t ue_id, int nbTunnels, pdusessionid_t *pdusession_id) { diff --git a/openair3/ocp-gtpu/gtp_itf.h b/openair3/ocp-gtpu/gtp_itf.h index 9592070ca9..bf2272529e 100644 --- a/openair3/ocp-gtpu/gtp_itf.h +++ b/openair3/ocp-gtpu/gtp_itf.h @@ -61,6 +61,7 @@ extern "C" { ); int gtpv1u_delete_s1u_tunnel( const instance_t instance, const gtpv1u_enb_delete_tunnel_req_t *const req_pP); + int gtpv1u_delete_all_s1u_tunnel(const instance_t instance, const rnti_t rnti); int gtpv1u_create_x2u_tunnel(const instance_t instanceP, const gtpv1u_enb_create_x2u_tunnel_req_t *const create_tunnel_req_pP,