Refactor TUN Interface Management and Move to SDAP Layer

This commit refactors the TUN interface management by moving its creation
and configuration from the PDCP layer to the SDAP layer for UE.

Key changes include:

- Introduced `tun_generate_ue_ifname` and `tun_destroy` functions for better
  TUN interface lifecycle management.
- Added support for creating and destroying UE-specific TUN interfaces in SDAP.
- Refactored `nr_pdcp_module_init` to remove TUN-related logic and moved it
  to SDAP.
- Updated NAS and SDAP layers to handle PDU session-specific TUN interface
  creation and configuration.
- Enhanced SDAP entity management to include TUN socket handling and thread
  lifecycle.
- Updated NAS message handling to initialize default PDU session TUN
  interfaces in NOS1 mode.
- Use a single SDAP thread function for gNB and UE
- Allow noS1 mode also in SA on gNB

These changes improve modularity by isolating TUN interface management within
the SDAP layer, aligning with the 3GPP architecture, and simplifying the PDCP
layer.

Co-Authored-By: Robert Schmidt <robert.schmidt@openairinterface.org>
This commit is contained in:
Bartosz Podrygajlo
2025-04-16 15:03:18 +02:00
co-authored by Robert Schmidt
parent f3eb713084
commit 1ab8a58a2f
17 changed files with 238 additions and 272 deletions
+23 -3
View File
@@ -31,6 +31,8 @@
#include "gtpv1_u_messages_types.h"
#include "intertask_interface.h"
#include "rlc.h"
#include "tun_if.h"
#include "nr_sdap.h"
typedef struct {
nr_sdap_entity_t *sdap_entity_llist;
@@ -103,7 +105,7 @@ static bool nr_sdap_tx_entity(nr_sdap_entity_t *entity,
/* The offset of the SDAP header, it might be 0 if has_sdap_tx is not true in the pdcp entity. */
int offset=0;
bool ret = false;
/*Hardcode DRB ID given from upper layer (ue/enb_tun_read_thread rb_id), it will change if we have SDAP*/
/*Hardcode DRB ID given from upper layer (ue/gnb_tun_read_thread rb_id), it will change if we have SDAP*/
rb_id_t sdap_drb_id = rb_id;
int pdcp_ent_has_sdap = 0;
@@ -321,8 +323,7 @@ static void nr_sdap_rx_entity(nr_sdap_entity_t *entity,
* 5.2.2 Downlink
* deliver the retrieved SDAP SDU to the upper layer.
*/
extern int nas_sock_fd[];
int len = write(nas_sock_fd[0], &buf[offset], size-offset);
int len = write(entity->pdusession_sock, &buf[offset], size - offset);
LOG_D(SDAP, "RX Entity len : %d\n", len);
LOG_D(SDAP, "RX Entity size : %d\n", size);
LOG_D(SDAP, "RX Entity offset : %d\n", offset);
@@ -513,6 +514,8 @@ nr_sdap_entity_t *new_nr_sdap_entity(int is_gnb,
sdap_entity->qfi2drb_map_delete = nr_sdap_qfi2drb_map_del;
sdap_entity->qfi2drb_map = nr_sdap_qfi2drb_map;
sdap_entity->pdusession_sock = -1;
if(is_defaultDRB) {
sdap_entity->default_drb = drb_identity;
LOG_I(SDAP, "Default DRB for the created SDAP entity: %ld \n", sdap_entity->default_drb);
@@ -523,6 +526,12 @@ nr_sdap_entity_t *new_nr_sdap_entity(int is_gnb,
sdap_entity->next_entity = sdap_info.sdap_entity_llist;
sdap_info.sdap_entity_llist = sdap_entity;
if (IS_SOFTMODEM_NOS1 && is_gnb) {
// In NOS1 mode, terminate SDAP for the first UE on the gNB. This allows injecting/receiving
// PDCP SDUs to/from the TUN interface.
start_sdap_tun_gnb_first_ue_default_pdu_session(ue_id);
}
return sdap_entity;
}
@@ -591,6 +600,9 @@ bool nr_sdap_delete_entity(ue_id_t ue_id, int pdusession_id)
if (entityPtr->ue_id == ue_id && entityPtr->pdusession_id == pdusession_id) {
entityPrev->next_entity = entityPtr->next_entity;
if (entityPrev->pdusession_sock != -1) {
remove_ue_ip_if(entityPrev);
}
free(entityPtr);
LOG_D(SDAP, "Successfully deleted Entity.\n");
ret = true;
@@ -674,3 +686,11 @@ void nr_reconfigure_sdap_entity(NR_SDAP_Config_t *sdap_config, ue_id_t ue_id, in
}
}
}
void set_qfi(uint8_t qfi, uint8_t pduid, ue_id_t ue_id)
{
nr_sdap_entity_t *entity = nr_sdap_get_entity(ue_id, pduid);
DevAssert(entity != NULL);
entity->qfi = qfi;
return;
}