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;