From cb003e4f1012d534db6394aa80320857842943ff Mon Sep 17 00:00:00 2001 From: francescomani Date: Wed, 16 Aug 2023 14:56:33 +0200 Subject: [PATCH] mapping LCID to RBID to find RLC entity --- openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c | 319 +++++++++------------ openair2/LAYER2/nr_rlc/nr_rlc_ue_manager.h | 14 + 2 files changed, 147 insertions(+), 186 deletions(-) diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c index 7d17829e4f..7a2d3ae0a5 100644 --- a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c +++ b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c @@ -54,23 +54,33 @@ static uint64_t nr_rlc_current_time; static int nr_rlc_current_time_last_frame; static int nr_rlc_current_time_last_subframe; - -void mac_rlc_data_ind ( - const module_id_t module_idP, - const rnti_t rntiP, - const eNB_index_t eNB_index, - const frame_t frameP, - const eNB_flag_t enb_flagP, - const MBMS_flag_t MBMS_flagP, - const logical_chan_id_t channel_idP, - char *buffer_pP, - const tb_size_t tb_sizeP, - num_tb_t num_tbP, - crc_t *crcs_pP) +nr_rlc_entity_t *get_rlc_entity_from_lcid(nr_rlc_ue_t *ue, + logical_chan_id_t channel_id) { - nr_rlc_ue_t *ue; - nr_rlc_entity_t *rb; + if (channel_id == 0) + return ue->srb0; + nr_rlc_rb_t *rb = &ue->lcid2rb[channel_id - 1]; + if (rb->type == NR_RLC_SRB) + return ue->srb[rb->choice.srb_id - 1]; + else { + AssertFatal(rb->type == NR_RLC_DRB, + "Invalid RB type\n"); + return ue->drb[rb->choice.drb_id - 1]; + } +} +void mac_rlc_data_ind(const module_id_t module_idP, + const rnti_t rntiP, + const eNB_index_t eNB_index, + const frame_t rameP, + const eNB_flag_t enb_flagP, + const MBMS_flag_t MBMS_flagP, + const logical_chan_id_t channel_idP, + char *buffer_pP, + const tb_size_t tb_sizeP, + num_tb_t num_tbP, + crc_t *crcs_pP) +{ if (module_idP != 0 || eNB_index != 0 || /*enb_flagP != 1 ||*/ MBMS_flagP != 0) { LOG_E(RLC, "%s:%d:%s: fatal\n", __FILE__, __LINE__, __FUNCTION__); exit(1); @@ -81,20 +91,15 @@ void mac_rlc_data_ind ( T_INT(channel_idP), T_INT(tb_sizeP)); nr_rlc_manager_lock(nr_rlc_ue_manager); - ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP); + nr_rlc_ue_t *ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP); if(ue == NULL) - LOG_I(RLC, "RLC instance for the given UE was not found \n"); + LOG_I(RLC, "RLC instance for the given UE was not found \n"); - switch (channel_idP) { - case 0: rb = ue->srb0; break; - case 1 ... 3: rb = ue->srb[channel_idP - 1]; break; - case 4 ... 32: rb = ue->drb[channel_idP - 4]; break; - default: rb = NULL; break; - } + nr_rlc_entity_t *rb = get_rlc_entity_from_lcid(ue, channel_idP); if (rb != NULL) { - LOG_D(RLC, "RB found! (channel ID %d) \n", channel_idP); + LOG_D(RLC, "RB found! (channel ID %d) \n", channel_idP); rb->set_time(rb, nr_rlc_current_time); rb->recv_pdu(rb, buffer_pP, tb_sizeP); } else { @@ -106,37 +111,24 @@ void mac_rlc_data_ind ( nr_rlc_manager_unlock(nr_rlc_ue_manager); } -tbs_size_t mac_rlc_data_req( - const module_id_t module_idP, - const rnti_t rntiP, - const eNB_index_t eNB_index, - const frame_t frameP, - const eNB_flag_t enb_flagP, - const MBMS_flag_t MBMS_flagP, - const logical_chan_id_t channel_idP, - const tb_size_t tb_sizeP, - char *buffer_pP, - const uint32_t sourceL2Id, - const uint32_t destinationL2Id - ) +tbs_size_t mac_rlc_data_req(const module_id_t module_idP, + const rnti_t rntiP, + const eNB_index_t eNB_index, + const frame_t frameP, + const eNB_flag_t enb_flagP, + const MBMS_flag_t MBMS_flagP, + const logical_chan_id_t channel_idP, + const tb_size_t tb_sizeP, + char *buffer_pP, + const uint32_t sourceL2Id, + const uint32_t destinationL2Id) { int ret; - nr_rlc_ue_t *ue; - nr_rlc_entity_t *rb; int maxsize; nr_rlc_manager_lock(nr_rlc_ue_manager); - ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP); - - switch (channel_idP) { - case 0: rb = ue->srb0; break; - case 1 ... 3: rb = ue->srb[channel_idP - 1]; break; - case 4 ... 32: rb = ue->drb[channel_idP - 4]; break; - default: - rb = NULL; - LOG_E(RLC, "In %s:%d:%s: data request for unknown RB with LCID 0x%02x !\n", __FILE__, __LINE__, __FUNCTION__, channel_idP); - break; - } + nr_rlc_ue_t *ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP); + nr_rlc_entity_t *rb = get_rlc_entity_from_lcid(ue, channel_idP); if (rb != NULL) { LOG_D(RLC, "MAC PDU to get created for channel_idP:%d \n", channel_idP); @@ -157,32 +149,22 @@ tbs_size_t mac_rlc_data_req( return ret; } -mac_rlc_status_resp_t mac_rlc_status_ind( - const module_id_t module_idP, - const rnti_t rntiP, - const eNB_index_t eNB_index, - const frame_t frameP, - const sub_frame_t subframeP, - const eNB_flag_t enb_flagP, - const MBMS_flag_t MBMS_flagP, - const logical_chan_id_t channel_idP, - const uint32_t sourceL2Id, - const uint32_t destinationL2Id - ) +mac_rlc_status_resp_t mac_rlc_status_ind(const module_id_t module_idP, + const rnti_t rntiP, + const eNB_index_t eNB_index, + const frame_t frameP, + const sub_frame_t subframeP, + const eNB_flag_t enb_flagP, + const MBMS_flag_t MBMS_flagP, + const logical_chan_id_t channel_idP, + const uint32_t sourceL2Id, + const uint32_t destinationL2Id) { - nr_rlc_ue_t *ue; mac_rlc_status_resp_t ret; - nr_rlc_entity_t *rb; nr_rlc_manager_lock(nr_rlc_ue_manager); - ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP); - - switch (channel_idP) { - case 0: rb = ue->srb0; break; - case 1 ... 3: rb = ue->srb[channel_idP - 1]; break; - case 4 ... MAX_DRBS_PER_UE: rb = ue->drb[channel_idP - 4]; break; - default: rb = NULL; break; - } + nr_rlc_ue_t *ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP); + nr_rlc_entity_t *rb = get_rlc_entity_from_lcid(ue, channel_idP); if (rb != NULL) { nr_rlc_entity_buffer_status_t buf_stat; @@ -212,18 +194,15 @@ mac_rlc_status_resp_t mac_rlc_status_ind( return ret; } -rlc_buffer_occupancy_t mac_rlc_get_buffer_occupancy_ind( - const module_id_t module_idP, - const rnti_t rntiP, - const eNB_index_t eNB_index, - const frame_t frameP, - const sub_frame_t subframeP, - const eNB_flag_t enb_flagP, - const logical_chan_id_t channel_idP) +rlc_buffer_occupancy_t mac_rlc_get_buffer_occupancy_ind(const module_id_t module_idP, + const rnti_t rntiP, + const eNB_index_t eNB_index, + const frame_t frameP, + const sub_frame_t subframeP, + const eNB_flag_t enb_flagP, + const logical_chan_id_t channel_idP) { - nr_rlc_ue_t *ue; rlc_buffer_occupancy_t ret; - nr_rlc_entity_t *rb; if (enb_flagP) { LOG_E(RLC, "Tx mac_rlc_get_buffer_occupancy_ind function is not implemented for eNB LcId=%u\n", channel_idP); @@ -239,13 +218,8 @@ rlc_buffer_occupancy_t mac_rlc_get_buffer_occupancy_ind( } nr_rlc_manager_lock(nr_rlc_ue_manager); - ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP); - - switch (channel_idP) { - case 1 ... 3: rb = ue->srb[channel_idP - 1]; break; - case 4 ... MAX_DRBS_PER_UE: rb = ue->drb[channel_idP - 4]; break; - default: rb = NULL; break; - } + nr_rlc_ue_t *ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP); + nr_rlc_entity_t *rb = get_rlc_entity_from_lcid(ue, channel_idP); if (rb != NULL) { nr_rlc_entity_buffer_status_t buf_stat; @@ -272,17 +246,16 @@ rlc_buffer_occupancy_t mac_rlc_get_buffer_occupancy_ind( } -rlc_op_status_t rlc_data_req (const protocol_ctxt_t *const ctxt_pP, - const srb_flag_t srb_flagP, - const MBMS_flag_t MBMS_flagP, - const rb_id_t rb_idP, - const mui_t muiP, - confirm_t confirmP, - sdu_size_t sdu_sizeP, - mem_block_t *sdu_pP, - const uint32_t *const sourceL2Id, - const uint32_t *const destinationL2Id - ) +rlc_op_status_t rlc_data_req(const protocol_ctxt_t *const ctxt_pP, + const srb_flag_t srb_flagP, + const MBMS_flag_t MBMS_flagP, + const rb_id_t rb_idP, + const mui_t muiP, + confirm_t confirmP, + sdu_size_t sdu_sizeP, + mem_block_t *sdu_pP, + const uint32_t *const sourceL2Id, + const uint32_t *const destinationL2Id) { int rnti = ctxt_pP->rntiMaybeUEid; nr_rlc_ue_t *ue; @@ -322,22 +295,14 @@ rlc_op_status_t rlc_data_req (const protocol_ctxt_t *const ctxt_pP, return RLC_OP_STATUS_OK; } -int nr_rlc_get_available_tx_space( - const rnti_t rntiP, - const logical_chan_id_t channel_idP) +int nr_rlc_get_available_tx_space(const rnti_t rntiP, + const logical_chan_id_t channel_idP) { - nr_rlc_ue_t *ue; - nr_rlc_entity_t *rb; int ret; nr_rlc_manager_lock(nr_rlc_ue_manager); - ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP); - - switch (channel_idP) { - case 1 ... 3: rb = ue->srb[channel_idP - 1]; break; - case 4 ... MAX_DRBS_PER_UE: rb = ue->drb[channel_idP - 4]; break; - default: rb = NULL; break; - } + nr_rlc_ue_t *ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP); + nr_rlc_entity_t *rb = get_rlc_entity_from_lcid(ue, channel_idP); if (rb != NULL) { ret = rb->available_tx_space(rb); @@ -617,12 +582,8 @@ rb_found: void nr_rlc_add_srb(int rnti, int srb_id, const NR_RLC_BearerConfig_t *rlc_BearerConfig) { - nr_rlc_entity_t *nr_rlc_am; - nr_rlc_ue_t *ue; - struct NR_RLC_Config *r = rlc_BearerConfig->rlc_Config; struct NR_LogicalChannelConfig *l = rlc_BearerConfig->mac_LogicalChannelConfig; - int channel_id = rlc_BearerConfig->logicalChannelIdentity; int logical_channel_group; int t_status_prohibit; @@ -634,17 +595,8 @@ void nr_rlc_add_srb(int rnti, int srb_id, const NR_RLC_BearerConfig_t *rlc_Beare int sn_field_length; LOG_D(RLC,"Trying to add SRB %d\n",srb_id); - if (srb_id != 1 && srb_id != 2) { - LOG_E(RLC, "%s:%d:%s: fatal, bad srb id %d\n", - __FILE__, __LINE__, __FUNCTION__, srb_id); - exit(1); - } - - if (channel_id != srb_id) { - LOG_E(RLC, "%s:%d:%s: todo, remove this limitation\n", - __FILE__, __LINE__, __FUNCTION__); - exit(1); - } + AssertFatal(srb_id > 0 && srb_id < 4, + "Invalid srb id %d\n", srb_id); logical_channel_group = *l->ul_SpecificParameters->logicalChannelGroup; @@ -677,9 +629,16 @@ void nr_rlc_add_srb(int rnti, int srb_id, const NR_RLC_BearerConfig_t *rlc_Beare } nr_rlc_manager_lock(nr_rlc_ue_manager); - ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rnti); + nr_rlc_ue_t *ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rnti); + AssertFatal(rlc_BearerConfig->servedRadioBearer && + (rlc_BearerConfig->servedRadioBearer->present == + NR_RLC_BearerConfig__servedRadioBearer_PR_srb_Identity), + "servedRadioBearer for SRB mandatory present when setting up an SRB RLC entity\n"); + int local_id = rlc_BearerConfig->logicalChannelIdentity - 1; // LCID 0 for SRB 0 not mapped + ue->lcid2rb[local_id].type = NR_RLC_SRB; + ue->lcid2rb[local_id].choice.srb_id = rlc_BearerConfig->servedRadioBearer->choice.srb_Identity; if (ue->srb[srb_id-1] != NULL) { - LOG_W(RLC, "%s:%d:%s: SRB %d already exists for UE with RNTI %04x, do nothing\n", __FILE__, __LINE__, __FUNCTION__, srb_id, rnti); + LOG_E(RLC, "%s:%d:%s: SRB %d already exists for UE with RNTI %04x, do nothing\n", __FILE__, __LINE__, __FUNCTION__, srb_id, rnti); } else { /* hack: hardcode values for NR */ t_poll_retransmit = 45; @@ -689,15 +648,15 @@ void nr_rlc_add_srb(int rnti, int srb_id, const NR_RLC_BearerConfig_t *rlc_Beare poll_byte = -1; max_retx_threshold = 8; sn_field_length = 12; - nr_rlc_am = new_nr_rlc_entity_am(RLC_RX_MAXSIZE, - RLC_TX_MAXSIZE, - deliver_sdu, ue, - successful_delivery, ue, - max_retx_reached, ue, - t_poll_retransmit, - t_reassembly, t_status_prohibit, - poll_pdu, poll_byte, max_retx_threshold, - sn_field_length); + nr_rlc_entity_t *nr_rlc_am = new_nr_rlc_entity_am(RLC_RX_MAXSIZE, + RLC_TX_MAXSIZE, + deliver_sdu, ue, + successful_delivery, ue, + max_retx_reached, ue, + t_poll_retransmit, + t_reassembly, t_status_prohibit, + poll_pdu, poll_byte, max_retx_threshold, + sn_field_length); nr_rlc_ue_add_srb_rlc_entity(ue, srb_id, nr_rlc_am); LOG_I(RLC, "%s:%d:%s: added srb %d to UE with RNTI 0x%x\n", __FILE__, __LINE__, __FUNCTION__, srb_id, rnti); @@ -707,12 +666,8 @@ void nr_rlc_add_srb(int rnti, int srb_id, const NR_RLC_BearerConfig_t *rlc_Beare static void add_drb_am(int rnti, int drb_id, const NR_RLC_BearerConfig_t *rlc_BearerConfig) { - nr_rlc_entity_t *nr_rlc_am; - nr_rlc_ue_t *ue; - struct NR_RLC_Config *r = rlc_BearerConfig->rlc_Config; struct NR_LogicalChannelConfig *l = rlc_BearerConfig->mac_LogicalChannelConfig; - int channel_id = rlc_BearerConfig->logicalChannelIdentity; int logical_channel_group; int t_status_prohibit; @@ -723,17 +678,8 @@ static void add_drb_am(int rnti, int drb_id, const NR_RLC_BearerConfig_t *rlc_Be int t_reassembly; int sn_field_length; - if (!(drb_id >= 1 && drb_id <= MAX_DRBS_PER_UE)) { - LOG_E(RLC, "%s:%d:%s: fatal, bad srb id %d\n", - __FILE__, __LINE__, __FUNCTION__, drb_id); - exit(1); - } - - if (channel_id != drb_id + 3) { - LOG_E(RLC, "%s:%d:%s: todo, remove this limitation\n", - __FILE__, __LINE__, __FUNCTION__); - exit(1); - } + AssertFatal(drb_id > 0 && drb_id <= MAX_DRBS_PER_UE, + "Invalid DRB ID %d\n", drb_id); logical_channel_group = *l->ul_SpecificParameters->logicalChannelGroup; @@ -766,19 +712,26 @@ static void add_drb_am(int rnti, int drb_id, const NR_RLC_BearerConfig_t *rlc_Be } nr_rlc_manager_lock(nr_rlc_ue_manager); - ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rnti); + nr_rlc_ue_t *ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rnti); + AssertFatal(rlc_BearerConfig->servedRadioBearer && + (rlc_BearerConfig->servedRadioBearer->present == + NR_RLC_BearerConfig__servedRadioBearer_PR_drb_Identity), + "servedRadioBearer for DRB mandatory present when setting up an SRB RLC entity\n"); + int local_id = rlc_BearerConfig->logicalChannelIdentity - 1; // LCID 0 for SRB 0 not mapped + ue->lcid2rb[local_id].type = NR_RLC_DRB; + ue->lcid2rb[local_id].choice.drb_id = rlc_BearerConfig->servedRadioBearer->choice.drb_Identity; if (ue->drb[drb_id-1] != NULL) { - LOG_W(RLC, "%s:%d:%s: DRB %d already exists for UE with RNTI %04x, do nothing\n", __FILE__, __LINE__, __FUNCTION__, drb_id, rnti); + LOG_E(RLC, "%s:%d:%s: DRB %d already exists for UE with RNTI %04x, do nothing\n", __FILE__, __LINE__, __FUNCTION__, drb_id, rnti); } else { - nr_rlc_am = new_nr_rlc_entity_am(RLC_RX_MAXSIZE, - RLC_TX_MAXSIZE, - deliver_sdu, ue, - successful_delivery, ue, - max_retx_reached, ue, - t_poll_retransmit, - t_reassembly, t_status_prohibit, - poll_pdu, poll_byte, max_retx_threshold, - sn_field_length); + nr_rlc_entity_t *nr_rlc_am = new_nr_rlc_entity_am(RLC_RX_MAXSIZE, + RLC_TX_MAXSIZE, + deliver_sdu, ue, + successful_delivery, ue, + max_retx_reached, ue, + t_poll_retransmit, + t_reassembly, t_status_prohibit, + poll_pdu, poll_byte, max_retx_threshold, + sn_field_length); nr_rlc_ue_add_drb_rlc_entity(ue, drb_id, nr_rlc_am); LOG_I(RLC, "%s:%d:%s: added drb %d to UE with RNTI 0x%x\n", __FILE__, __LINE__, __FUNCTION__, drb_id, rnti); @@ -788,28 +741,15 @@ static void add_drb_am(int rnti, int drb_id, const NR_RLC_BearerConfig_t *rlc_Be static void add_drb_um(int rnti, int drb_id, const NR_RLC_BearerConfig_t *rlc_BearerConfig) { - nr_rlc_entity_t *nr_rlc_um; - nr_rlc_ue_t *ue; - struct NR_RLC_Config *r = rlc_BearerConfig->rlc_Config; struct NR_LogicalChannelConfig *l = rlc_BearerConfig->mac_LogicalChannelConfig; - int channel_id = rlc_BearerConfig->logicalChannelIdentity; int logical_channel_group; int sn_field_length; int t_reassembly; - if (!(drb_id >= 1 && drb_id <= MAX_DRBS_PER_UE)) { - LOG_E(RLC, "%s:%d:%s: fatal, bad srb id %d\n", - __FILE__, __LINE__, __FUNCTION__, drb_id); - exit(1); - } - - if (channel_id != drb_id + 3) { - LOG_E(RLC, "%s:%d:%s: todo, remove this limitation\n", - __FILE__, __LINE__, __FUNCTION__); - exit(1); - } + AssertFatal(drb_id > 0 && drb_id <= MAX_DRBS_PER_UE, + "Invalid DRB ID %d\n", drb_id); logical_channel_group = *l->ul_SpecificParameters->logicalChannelGroup; @@ -837,15 +777,22 @@ static void add_drb_um(int rnti, int drb_id, const NR_RLC_BearerConfig_t *rlc_Be } nr_rlc_manager_lock(nr_rlc_ue_manager); - ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rnti); + nr_rlc_ue_t *ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rnti); + AssertFatal(rlc_BearerConfig->servedRadioBearer && + (rlc_BearerConfig->servedRadioBearer->present == + NR_RLC_BearerConfig__servedRadioBearer_PR_drb_Identity), + "servedRadioBearer for DRB mandatory present when setting up an SRB RLC entity\n"); + int local_id = rlc_BearerConfig->logicalChannelIdentity - 1; // LCID 0 for SRB 0 not mapped + ue->lcid2rb[local_id].type = NR_RLC_DRB; + ue->lcid2rb[local_id].choice.drb_id = rlc_BearerConfig->servedRadioBearer->choice.drb_Identity; if (ue->drb[drb_id-1] != NULL) { - LOG_W(RLC, "DEBUG add_drb_um %s:%d:%s: warning DRB %d already exist for ue %d, do nothing\n", __FILE__, __LINE__, __FUNCTION__, drb_id, rnti); + LOG_E(RLC, "DEBUG add_drb_um %s:%d:%s: warning DRB %d already exist for ue %d, do nothing\n", __FILE__, __LINE__, __FUNCTION__, drb_id, rnti); } else { - nr_rlc_um = new_nr_rlc_entity_um(RLC_RX_MAXSIZE, - RLC_TX_MAXSIZE, - deliver_sdu, ue, - t_reassembly, - sn_field_length); + nr_rlc_entity_t *nr_rlc_um = new_nr_rlc_entity_um(RLC_RX_MAXSIZE, + RLC_TX_MAXSIZE, + deliver_sdu, ue, + t_reassembly, + sn_field_length); nr_rlc_ue_add_drb_rlc_entity(ue, drb_id, nr_rlc_um); LOG_D(RLC, "%s:%d:%s: added drb %d to UE with RNTI 0x%x\n", __FILE__, __LINE__, __FUNCTION__, drb_id, rnti); diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_ue_manager.h b/openair2/LAYER2/nr_rlc/nr_rlc_ue_manager.h index 958f216592..5c7c58e3ee 100644 --- a/openair2/LAYER2/nr_rlc/nr_rlc_ue_manager.h +++ b/openair2/LAYER2/nr_rlc/nr_rlc_ue_manager.h @@ -27,12 +27,26 @@ typedef void nr_rlc_ue_manager_t; +typedef enum nr_rlc_rb_type { + NR_RLC_SRB = 0, + NR_RLC_DRB = 1 +} nr_rlc_rb_type; + +typedef struct nr_rlc_rb_t { + nr_rlc_rb_type type; + union { + int srb_id; + int drb_id; + } choice; +} nr_rlc_rb_t; + typedef struct nr_rlc_ue_t { int rnti; ue_id_t ue_id; nr_rlc_entity_t *srb0; nr_rlc_entity_t *srb[3]; nr_rlc_entity_t *drb[MAX_DRBS_PER_UE]; + nr_rlc_rb_t lcid2rb[32]; } nr_rlc_ue_t; /***********************************************************************/