From 41da4a3b3af385f155d4b3b5e08261668c5686e4 Mon Sep 17 00:00:00 2001 From: francescomani Date: Tue, 13 May 2025 15:22:41 +0200 Subject: [PATCH] send reject if we reach the max number of UEs allowed --- openair2/LAYER2/NR_MAC_gNB/config.c | 2 +- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c | 5 ---- .../NR_MAC_gNB/gNB_scheduler_primitives.c | 26 +++++++++++-------- .../LAYER2/NR_MAC_gNB/mac_rrc_dl_handler.c | 2 +- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/openair2/LAYER2/NR_MAC_gNB/config.c b/openair2/LAYER2/NR_MAC_gNB/config.c index f87b4024b9..abe6e5218a 100644 --- a/openair2/LAYER2/NR_MAC_gNB/config.c +++ b/openair2/LAYER2/NR_MAC_gNB/config.c @@ -971,7 +971,7 @@ bool nr_mac_add_test_ue(gNB_MAC_INST *nrmac, uint32_t rnti, NR_CellGroupConfig_t NR_SCHED_LOCK(&nrmac->sched_lock); NR_UE_info_t *UE = get_new_nr_ue_inst(&nrmac->UE_info.uid_allocator, rnti, CellGroup); - DevAssert(UE != NULL); // test-mode: we assume we can always create a UE + DevAssert(UE->uid < MAX_MOBILES_PER_GNB); // test-mode: we assume we can always create a UE free_and_zero(UE->ra); // test-mode (sims, phy-test): UE will not do RA bool res = add_connected_nr_ue(nrmac, UE); if (!res) { diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c index cbf414fb31..7459a99579 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c @@ -727,11 +727,6 @@ void nr_initiate_ra_proc(module_id_t module_idP, } UE = get_new_nr_ue_inst(&nr_mac->UE_info.uid_allocator, rnti, NULL); - if (!UE) { - LOG_E(NR_MAC, "FAILURE: %4d.%2d cannot create UE context, ignoring RA because RRC Reject not implemented yet\n", frame, slot); - NR_SCHED_UNLOCK(&nr_mac->sched_lock); - return; - } if (!add_new_UE_RA(nr_mac, UE)) { LOG_E(NR_MAC, "FAILURE: %4d.%2d initiating RA procedure for preamble index %d: no free RA process\n", frame, slot, preamble_index); delete_nr_ue_data(UE, NULL, &nr_mac->UE_info.uid_allocator); diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c index 82fa6d828b..f3c604740a 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c @@ -2577,19 +2577,10 @@ static void init_bler_stats(const NR_bler_options_t *bler_options, NR_bler_stats * error handling). Remove with delete_nr_ue_data(). */ NR_UE_info_t *get_new_nr_ue_inst(uid_allocator_t *uia, rnti_t rnti, NR_CellGroupConfig_t *CellGroup) { - uid_t uid = uid_linear_allocator_new(uia); - /* if the UE list is full, we should reject the UE with an RRC reject - * message, but we do not have this functionality. To keep it simple, do not - * create a UE context here, so we can print an error message. */ - if (uid >= MAX_MOBILES_PER_GNB) { - uid_linear_allocator_free(uia, uid); - return NULL; - } - NR_UE_info_t *UE = calloc_or_fail(1, sizeof(NR_UE_info_t)); + UE->uid = uid_linear_allocator_new(uia); UE->rnti = rnti; UE->CellGroup = CellGroup; - UE->uid = uid; UE->ra = calloc(1, sizeof(*UE->ra)); NR_UE_sched_ctrl_t *sched_ctrl = &UE->UE_sched_ctrl; sched_ctrl->ta_update = 31; @@ -3324,6 +3315,19 @@ bool prepare_initial_ul_rrc_message(gNB_MAC_INST *mac, NR_UE_info_t *UE) if (!nr_rlc_activate_srb0(UE->rnti, UE, send_initial_ul_rrc_message)) return false; + if (UE->uid >= MAX_MOBILES_PER_GNB) { + // verifying if any UE left in the meantime and it is possible to get a valid UID + uid_linear_allocator_free(&mac->UE_info.uid_allocator, UE->uid); + UE->uid = uid_linear_allocator_new(&mac->UE_info.uid_allocator); + if (UE->uid >= MAX_MOBILES_PER_GNB) { + // if the UE list is full, we should reject the UE with an RRC reject message + // to signal the upper layers to send a reject we send an empty CellGroup information element + UE->CellGroup = NULL; + LOG_W(NR_MAC, "Maximum number of UE alllowed at DU reached. Cannot serve UE %04x", UE->rnti); + return true; + } + } + /* create this UE's initial CellGroup */ int CC_id = 0; int srb_id = 1; @@ -3335,7 +3339,7 @@ bool prepare_initial_ul_rrc_message(gNB_MAC_INST *mac, NR_UE_info_t *UE) if (!cellGroupConfig) return true; - + /* the cellGroup sent to CU specifies there is SRB1, so create it */ DevAssert(cellGroupConfig->rlc_BearerToAddModList->list.count == 1); const NR_RLC_BearerConfig_t *bearer = cellGroupConfig->rlc_BearerToAddModList->list.array[0]; diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_rrc_dl_handler.c b/openair2/LAYER2/NR_MAC_gNB/mac_rrc_dl_handler.c index 5d7642c815..5236f817cc 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_rrc_dl_handler.c +++ b/openair2/LAYER2/NR_MAC_gNB/mac_rrc_dl_handler.c @@ -553,7 +553,7 @@ static NR_UE_info_t *create_new_UE(gNB_MAC_INST *mac, uint32_t cu_id, const NR_C DevAssert(success); NR_UE_info_t *UE = get_new_nr_ue_inst(&mac->UE_info.uid_allocator, rnti, NULL); - AssertFatal(UE != NULL, "cannot create UE context, UE context setup failure not implemented\n"); + AssertFatal(UE->uid < MAX_MOBILES_PER_GNB, "cannot create UE context, UE context setup failure not implemented\n"); NR_CellGroupConfig_t *cellGroupConfig = NULL; NR_COMMON_channels_t *cc = &mac->common_channels[CC_id];