From d6c732107714369fca08bfad1cb00decfe668fd4 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Mon, 16 Feb 2026 18:40:10 +0100 Subject: [PATCH] Implement removal of endpoint For unit testing, allow to remove endpoints such that we could reuse a port/IP combination. The function does not take care of endpoints that are still "dangling", it is the user's responsibility to remove all existing TEIDs. --- openair3/ocp-gtpu/gtp_itf.cpp | 14 ++++++++++++++ openair3/ocp-gtpu/gtp_itf.h | 1 + openair3/ocp-gtpu/tests/test_gtp.cpp | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/openair3/ocp-gtpu/gtp_itf.cpp b/openair3/ocp-gtpu/gtp_itf.cpp index 9509c5a8a4..2327d24c2f 100644 --- a/openair3/ocp-gtpu/gtp_itf.cpp +++ b/openair3/ocp-gtpu/gtp_itf.cpp @@ -613,6 +613,20 @@ instance_t gtpv1Init(openAddr_t context) return id; } +/* \brief remove the GTP instance from the list of instances. Does not make an + * attempt to free corresponding TEIDs, as we have many and will simply not + * reuse it later. */ +int gtpv1Term(instance_t instance) +{ + pthread_mutex_lock(&globGtp.gtp_lock); + getInstRetInt(compatInst(instance)); + gtpv1uReceiverCancel(inst->thrData.t); + close(instance); + globGtp.instances.erase(instance); + pthread_mutex_unlock(&globGtp.gtp_lock); + return 0; +} + void GtpuUpdateTunnelOutgoingAddressAndTeid(instance_t instance, ue_id_t ue_id, ebi_t bearer_id, diff --git a/openair3/ocp-gtpu/gtp_itf.h b/openair3/ocp-gtpu/gtp_itf.h index 8139eb3667..0ecddd6f19 100644 --- a/openair3/ocp-gtpu/gtp_itf.h +++ b/openair3/ocp-gtpu/gtp_itf.h @@ -130,6 +130,7 @@ typedef struct gtpv1u_gnb_delete_tunnel_req_s gtpv1u_gnb_delete_tunnel_req_t; size_t len); instance_t gtpv1Init(openAddr_t context); + int gtpv1Term(instance_t inst); void *gtpv1uTask(void *args); #ifdef __cplusplus diff --git a/openair3/ocp-gtpu/tests/test_gtp.cpp b/openair3/ocp-gtpu/tests/test_gtp.cpp index 6df27a07f2..ba2d3d622c 100644 --- a/openair3/ocp-gtpu/tests/test_gtp.cpp +++ b/openair3/ocp-gtpu/tests/test_gtp.cpp @@ -136,6 +136,11 @@ static void run_basic_test(uint32_t ue_id, EXPECT_EQ(ret, 0); ret = newGtpuDeleteAllTunnels(ep2, ue_id); EXPECT_EQ(ret, 0); + + ret = gtpv1Term(ep1); + EXPECT_EQ(ret, 0); + ret = gtpv1Term(ep2); + EXPECT_EQ(ret, 0); } static int recv_count_qfi = 0;