From 52dbc6fe75e14d2d8c91188f5bd5086bd2884f9a Mon Sep 17 00:00:00 2001 From: Robert Schmidt <robert.schmidt@openairinterface.org> Date: Tue, 3 May 2022 11:45:54 +0200 Subject: [PATCH] Refactor linear allocator from LTE/NR; separate LTE/NR headers --- common/utils/collection/linear_alloc.h | 71 +++++++++++++++++++++++ openair2/RRC/LTE/rrc_defs.h | 19 +------ openair2/RRC/LTE/rrc_eNB_UE_context.c | 62 +------------------- openair2/RRC/LTE/rrc_eNB_UE_context.h | 21 ------- openair2/RRC/NR/nr_rrc_defs.h | 34 ++++------- openair2/RRC/NR/rrc_gNB.c | 2 +- openair2/RRC/NR/rrc_gNB_UE_context.c | 79 ++++---------------------- openair2/RRC/NR/rrc_gNB_UE_context.h | 21 ------- openair2/RRC/NR_UE/L2_interface_ue.c | 1 + 9 files changed, 100 insertions(+), 210 deletions(-) create mode 100644 common/utils/collection/linear_alloc.h diff --git a/common/utils/collection/linear_alloc.h b/common/utils/collection/linear_alloc.h new file mode 100644 index 00000000000..ac8a305ff64 --- /dev/null +++ b/common/utils/collection/linear_alloc.h @@ -0,0 +1,71 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#ifndef LINEAR_ALLOC_H +#define LINEAR_ALLOC_H + +#include <limits.h> + +typedef unsigned int uid_t; +#define UID_LINEAR_ALLOCATOR_SIZE 1024 +#define UID_LINEAR_ALLOCATOR_BITMAP_SIZE (((UID_LINEAR_ALLOCATOR_SIZE/8)/sizeof(unsigned int)) + 1) +typedef struct uid_linear_allocator_s { + unsigned int bitmap[UID_LINEAR_ALLOCATOR_BITMAP_SIZE]; +} uid_allocator_t; + +static inline void uid_linear_allocator_init(uid_allocator_t *uia) { + memset(uia, 0, sizeof(uid_allocator_t)); +} + +static inline uid_t uid_linear_allocator_new(uid_allocator_t *uia) { + unsigned int bit_index = 1; + uid_t uid = 0; + + for (unsigned int i = 0; i < UID_LINEAR_ALLOCATOR_BITMAP_SIZE; i++) { + if (uia->bitmap[i] != UINT_MAX) { + bit_index = 1; + uid = 0; + + while ((uia->bitmap[i] & bit_index) == bit_index) { + bit_index = bit_index << 1; + uid += 1; + } + + uia->bitmap[i] |= bit_index; + return uid + (i*sizeof(unsigned int)*8); + } + } + + return UINT_MAX; +} + + +static inline void uid_linear_allocator_free(uid_allocator_t *uia, uid_t uid) { + const unsigned int i = uid/sizeof(unsigned int)/8; + const unsigned int bit = uid % (sizeof(unsigned int) * 8); + const unsigned int value = ~(1 << bit); + + if (i < UID_LINEAR_ALLOCATOR_BITMAP_SIZE) { + uia->bitmap[i] &= value; + } +} + +#endif /* LINEAR_ALLOC_H */ diff --git a/openair2/RRC/LTE/rrc_defs.h b/openair2/RRC/LTE/rrc_defs.h index 22c8a14863e..f5841b09f88 100644 --- a/openair2/RRC/LTE/rrc_defs.h +++ b/openair2/RRC/LTE/rrc_defs.h @@ -36,11 +36,11 @@ #include <string.h> #include "collection/tree.h" +#include "collection/linear_alloc.h" #include "common/ngran_types.h" #include "rrc_types.h" //#include "PHY/phy_defs.h" #include "LAYER2/RLC/rlc.h" -#include "RRC/NR/nr_rrc_types.h" #include "NR_UE-MRDC-Capability.h" #include "NR_UE-NR-Capability.h" @@ -219,17 +219,6 @@ void *send_UE_status_notification(void *); #include "commonDef.h" -//-------- -typedef unsigned int uid_t; -#define UID_LINEAR_ALLOCATOR_BITMAP_SIZE (((MAX_MOBILES_PER_ENB/8)/sizeof(unsigned int)) + 1) -typedef struct uid_linear_allocator_s { - unsigned int bitmap[UID_LINEAR_ALLOCATOR_BITMAP_SIZE]; -} uid_allocator_t; - -//-------- - - - #define PROTOCOL_RRC_CTXT_UE_FMT PROTOCOL_CTXT_FMT #define PROTOCOL_RRC_CTXT_UE_ARGS(CTXT_Pp) PROTOCOL_CTXT_ARGS(CTXT_Pp) @@ -668,8 +657,6 @@ typedef struct eNB_RRC_UE_s { int nr_capabilities_requested; } eNB_RRC_UE_t; -typedef uid_t ue_uid_t; - typedef struct rrc_eNB_ue_context_s { /* Tree related data */ RB_ENTRY(rrc_eNB_ue_context_s) entries; @@ -680,7 +667,7 @@ typedef struct rrc_eNB_ue_context_s { rnti_t ue_id_rnti; // another key for protocol layers but should not be used as a key for RB tree - ue_uid_t local_uid; + uid_t local_uid; /* UE id for initial connection to S1AP */ struct eNB_RRC_UE_s ue_context; @@ -762,7 +749,7 @@ typedef struct eNB_RRC_INST_s { char *node_name; uint32_t node_id; rrc_eNB_carrier_data_t carrier[MAX_NUM_CCs]; - uid_allocator_t uid_allocator; // for rrc_ue_head + uid_allocator_t uid_allocator; RB_HEAD(rrc_ue_tree_s, rrc_eNB_ue_context_s) rrc_ue_head; // ue_context tree key search by rnti uint8_t HO_flag; uint8_t Nb_ue; diff --git a/openair2/RRC/LTE/rrc_eNB_UE_context.c b/openair2/RRC/LTE/rrc_eNB_UE_context.c index 0d262064b53..c9077bfb241 100644 --- a/openair2/RRC/LTE/rrc_eNB_UE_context.c +++ b/openair2/RRC/LTE/rrc_eNB_UE_context.c @@ -37,64 +37,6 @@ #include "rrc_eNB_UE_context.h" -//------------------------------------------------------------------------------ -void -uid_linear_allocator_init( - uid_allocator_t *const uid_pP -) -//------------------------------------------------------------------------------ -{ - memset(uid_pP, 0, sizeof(uid_allocator_t)); -} - -//------------------------------------------------------------------------------ -uid_t -uid_linear_allocator_new( - eNB_RRC_INST *const rrc_instance_pP -) -//------------------------------------------------------------------------------ -{ - unsigned int i; - unsigned int bit_index = 1; - uid_t uid = 0; - uid_allocator_t *uia_p = &rrc_instance_pP->uid_allocator; - - for (i=0; i < UID_LINEAR_ALLOCATOR_BITMAP_SIZE; i++) { - if (uia_p->bitmap[i] != UINT_MAX) { - bit_index = 1; - uid = 0; - - while ((uia_p->bitmap[i] & bit_index) == bit_index) { - bit_index = bit_index << 1; - uid += 1; - } - - uia_p->bitmap[i] |= bit_index; - return uid + (i*sizeof(unsigned int)*8); - } - } - - return UINT_MAX; -} - - -//------------------------------------------------------------------------------ -void -uid_linear_allocator_free( - eNB_RRC_INST *rrc_instance_pP, - uid_t uidP -) -//------------------------------------------------------------------------------ -{ - unsigned int i = uidP/sizeof(unsigned int)/8; - unsigned int bit = uidP % (sizeof(unsigned int) * 8); - unsigned int value = ~(0x00000001 << bit); - - if (i < UID_LINEAR_ALLOCATOR_BITMAP_SIZE) { - rrc_instance_pP->uid_allocator.bitmap[i] &= value; - } -} - //------------------------------------------------------------------------------ int rrc_eNB_compare_ue_rnti_id( @@ -134,7 +76,7 @@ rrc_eNB_allocate_new_UE_context( } memset(new_p, 0, sizeof(struct rrc_eNB_ue_context_s)); - new_p->local_uid = uid_linear_allocator_new(rrc_instance_pP); + new_p->local_uid = uid_linear_allocator_new(&rrc_instance_pP->uid_allocator); for(int i = 0; i < NB_RB_MAX; i++) { new_p->ue_context.e_rab[i].xid = -1; @@ -210,7 +152,7 @@ void rrc_eNB_remove_ue_context( RB_REMOVE(rrc_ue_tree_s, &rrc_instance_pP->rrc_ue_head, ue_context_pP); rrc_eNB_free_mem_UE_context(ctxt_pP, ue_context_pP); - uid_linear_allocator_free(rrc_instance_pP, ue_context_pP->local_uid); + uid_linear_allocator_free(&rrc_instance_pP->uid_allocator, ue_context_pP->local_uid); free(ue_context_pP); rrc_instance_pP->Nb_ue --; LOG_I(RRC, diff --git a/openair2/RRC/LTE/rrc_eNB_UE_context.h b/openair2/RRC/LTE/rrc_eNB_UE_context.h index c6420ca9367..89469529dff 100644 --- a/openair2/RRC/LTE/rrc_eNB_UE_context.h +++ b/openair2/RRC/LTE/rrc_eNB_UE_context.h @@ -34,27 +34,6 @@ #include "COMMON/platform_types.h" #include "rrc_defs.h" - -void -uid_linear_allocator_init( - uid_allocator_t* const uid_pP -); - -uid_t -uid_linear_allocator_new( - eNB_RRC_INST* rrc_instance_pP -); - - -void -uid_linear_allocator_free( - eNB_RRC_INST* rrc_instance_pP, - uid_t uidP -); - - - - int rrc_eNB_compare_ue_rnti_id( struct rrc_eNB_ue_context_s* c1_pP, struct rrc_eNB_ue_context_s* c2_pP diff --git a/openair2/RRC/NR/nr_rrc_defs.h b/openair2/RRC/NR/nr_rrc_defs.h index c709a158dae..e9d9766f41b 100644 --- a/openair2/RRC/NR/nr_rrc_defs.h +++ b/openair2/RRC/NR/nr_rrc_defs.h @@ -36,12 +36,12 @@ #include <string.h> #include "collection/tree.h" +#include "collection/linear_alloc.h" #include "nr_rrc_types.h" +#include "common/ngran_types.h" #include "COMMON/platform_constants.h" #include "COMMON/platform_types.h" -#include "RRC/LTE/rrc_defs.h" -//#include "LAYER2/RLC/rlc.h" #include "mac_rrc_dl.h" //#include "COMMON/mac_rrc_primitives.h" @@ -80,17 +80,6 @@ #include "commonDef.h" - -/*I will change the name of the structure for compile purposes--> hope not to undo this process*/ - -typedef unsigned int uid_nr_t; -#define NR_UID_LINEAR_ALLOCATOR_BITMAP_SIZE (((MAX_MOBILES_PER_GNB/8)/sizeof(unsigned int)) + 1) - -typedef struct nr_uid_linear_allocator_s { - unsigned int bitmap[NR_UID_LINEAR_ALLOCATOR_BITMAP_SIZE]; -} nr_uid_allocator_t; - - #define PROTOCOL_NR_RRC_CTXT_UE_FMT PROTOCOL_CTXT_FMT #define PROTOCOL_NR_RRC_CTXT_UE_ARGS(CTXT_Pp) PROTOCOL_NR_CTXT_ARGS(CTXT_Pp) @@ -283,12 +272,11 @@ typedef struct pdu_session_param_s { typedef struct gNB_RRC_UE_s { uint8_t primaryCC_id; - LTE_SCellToAddMod_r10_t sCell_config[2]; NR_SRB_ToAddModList_t *SRB_configList; - NR_SRB_ToAddModList_t *SRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER]; + NR_SRB_ToAddModList_t *SRB_configList2[NR_RRC_TRANSACTION_IDENTIFIER_NUMBER]; NR_DRB_ToAddModList_t *DRB_configList; - NR_DRB_ToAddModList_t *DRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER]; - NR_DRB_ToReleaseList_t *DRB_Release_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER]; + NR_DRB_ToAddModList_t *DRB_configList2[NR_RRC_TRANSACTION_IDENTIFIER_NUMBER]; + NR_DRB_ToReleaseList_t *DRB_Release_configList2[NR_RRC_TRANSACTION_IDENTIFIER_NUMBER]; uint8_t DRB_active[8]; NR_SRB_INFO SI; @@ -296,7 +284,7 @@ typedef struct gNB_RRC_UE_s { NR_SRB_INFO_TABLE_ENTRY Srb1; NR_SRB_INFO_TABLE_ENTRY Srb2; NR_MeasConfig_t *measConfig; - HANDOVER_INFO *handover_info; + NR_HANDOVER_INFO *handover_info; NR_MeasResults_t *measResults; @@ -353,7 +341,7 @@ typedef struct gNB_RRC_UE_s { /* Number of e_rab to be modified in the list */ uint8_t nb_of_modify_e_rabs; uint8_t nb_of_failed_e_rabs; - e_rab_param_t modify_e_rab[NB_RB_MAX];//[S1AP_MAX_E_RAB]; + nr_e_rab_param_t modify_e_rab[NB_RB_MAX];//[S1AP_MAX_E_RAB]; /* Total number of pdu session already setup in the list */ uint8_t setup_pdu_sessions; /* Number of pdu session to be setup in the list */ @@ -364,7 +352,7 @@ typedef struct gNB_RRC_UE_s { pdu_session_param_t modify_pdusession[NR_NB_RB_MAX]; /* list of e_rab to be setup by RRC layers */ /* list of pdu session to be setup by RRC layers */ - e_rab_param_t e_rab[NB_RB_MAX];//[S1AP_MAX_E_RAB]; + nr_e_rab_param_t e_rab[NB_RB_MAX];//[S1AP_MAX_E_RAB]; pdu_session_param_t pduSession[NR_NB_RB_MAX];//[NGAP_MAX_PDU_SESSION]; //release e_rabs uint8_t nb_release_of_e_rabs; @@ -411,8 +399,6 @@ typedef struct gNB_RRC_UE_s { } gNB_RRC_UE_t; -typedef uid_t ue_uid_t; - typedef struct rrc_gNB_ue_context_s { /* Tree related data */ RB_ENTRY(rrc_gNB_ue_context_s) entries; @@ -423,7 +409,7 @@ typedef struct rrc_gNB_ue_context_s { rnti_t ue_id_rnti; // another key for protocol layers but should not be used as a key for RB tree - ue_uid_t local_uid; + uid_t local_uid; /* UE id for initial connection to S1AP */ struct gNB_RRC_UE_s ue_context; @@ -495,7 +481,7 @@ typedef struct gNB_RRC_INST_s { int module_id; eth_params_t eth_params_s; rrc_gNB_carrier_data_t carrier; - nr_uid_allocator_t uid_allocator; // for rrc_ue_head + uid_allocator_t uid_allocator; RB_HEAD(rrc_nr_ue_tree_s, rrc_gNB_ue_context_s) rrc_ue_head; // ue_context tree key search by rnti int Nb_ue; hash_table_t *initial_id2_s1ap_ids; // key is content is rrc_ue_s1ap_ids_t diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index 4340bfa6bd6..bf122514ce1 100755 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -230,7 +230,7 @@ char openair_rrc_gNB_configuration(const module_id_t gnb_mod_idP, gNB_RrcConfigu rrc->Nb_ue = 0; rrc->carrier.Srb0.Active = 0; rrc_gNB_mac_rrc_init(rrc); - nr_uid_linear_allocator_init(&rrc->uid_allocator); + uid_linear_allocator_init(&rrc->uid_allocator); RB_INIT(&rrc->rrc_ue_head); rrc->initial_id2_s1ap_ids = hashtable_create (NUMBER_OF_UE_MAX * 2, NULL, NULL); rrc->s1ap_id2_s1ap_ids = hashtable_create (NUMBER_OF_UE_MAX * 2, NULL, NULL); diff --git a/openair2/RRC/NR/rrc_gNB_UE_context.c b/openair2/RRC/NR/rrc_gNB_UE_context.c index b8ff19b749e..540ac5d075a 100644 --- a/openair2/RRC/NR/rrc_gNB_UE_context.c +++ b/openair2/RRC/NR/rrc_gNB_UE_context.c @@ -37,61 +37,6 @@ #include "rrc_gNB_UE_context.h" -//------------------------------------------------------------------------------ -void nr_uid_linear_allocator_init( - nr_uid_allocator_t *const uid_pP -) -//------------------------------------------------------------------------------ -{ - memset(uid_pP, 0, sizeof(nr_uid_allocator_t)); -} - -//------------------------------------------------------------------------------ -uid_nr_t nr_uid_linear_allocator_new(gNB_RRC_INST *const rrc_instance_pP) -//------------------------------------------------------------------------------ -{ - unsigned int i; - unsigned int bit_index = 1; - uid_nr_t uid = 0; - nr_uid_allocator_t *uia_p = &rrc_instance_pP->uid_allocator; - - for (i=0; i < UID_LINEAR_ALLOCATOR_BITMAP_SIZE; i++) { - if (uia_p->bitmap[i] != UINT_MAX) { - bit_index = 1; - uid = 0; - - while ((uia_p->bitmap[i] & bit_index) == bit_index) { - bit_index = bit_index << 1; - uid += 1; - } - - uia_p->bitmap[i] |= bit_index; - return uid + (i*sizeof(unsigned int)*8); - } - } - - return UINT_MAX; -} - - -//------------------------------------------------------------------------------ -void -nr_uid_linear_allocator_free( - gNB_RRC_INST *rrc_instance_pP, - uid_nr_t uidP -) -//------------------------------------------------------------------------------ -{ - unsigned int i = uidP/sizeof(unsigned int)/8; - unsigned int bit = uidP % (sizeof(unsigned int) * 8); - unsigned int value = ~(0x00000001 << bit); - - if (i < UID_LINEAR_ALLOCATOR_BITMAP_SIZE) { - rrc_instance_pP->uid_allocator.bitmap[i] &= value; - } -} - - //------------------------------------------------------------------------------ int rrc_gNB_compare_ue_rnti_id( struct rrc_gNB_ue_context_s *c1_pP, struct rrc_gNB_ue_context_s *c2_pP) @@ -130,7 +75,7 @@ rrc_gNB_allocate_new_UE_context( } memset(new_p, 0, sizeof(struct rrc_gNB_ue_context_s)); - new_p->local_uid = nr_uid_linear_allocator_new(rrc_instance_pP); + new_p->local_uid = uid_linear_allocator_new(&rrc_instance_pP->uid_allocator); for(int i = 0; i < NB_RB_MAX; i++) { new_p->ue_context.e_rab[i].xid = -1; @@ -177,12 +122,12 @@ void rrc_gNB_free_mem_UE_context( { LOG_T(RRC, - PROTOCOL_RRC_CTXT_UE_FMT" Clearing UE context 0x%p (free internal structs)\n", - PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP), + PROTOCOL_NR_RRC_CTXT_UE_FMT" Clearing UE context 0x%p (free internal structs)\n", + PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP), ue_context_pP); - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_LTE_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[0]); - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_LTE_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[1]); + //ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_LTE_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[0]); + //ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_LTE_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[1]); // empty the internal fields of the UE context here } @@ -195,25 +140,25 @@ void rrc_gNB_remove_ue_context( //------------------------------------------------------------------------------ { if (rrc_instance_pP == NULL) { - LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Bad RRC instance\n", - PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP)); + LOG_E(RRC, PROTOCOL_NR_RRC_CTXT_UE_FMT" Bad RRC instance\n", + PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP)); return; } if (ue_context_pP == NULL) { - LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Trying to free a NULL UE context\n", - PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP)); + LOG_E(RRC, PROTOCOL_NR_RRC_CTXT_UE_FMT" Trying to free a NULL UE context\n", + PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP)); return; } RB_REMOVE(rrc_nr_ue_tree_s, &rrc_instance_pP->rrc_ue_head, ue_context_pP); rrc_gNB_free_mem_UE_context(ctxt_pP, ue_context_pP); - nr_uid_linear_allocator_free(rrc_instance_pP, ue_context_pP->local_uid); + uid_linear_allocator_free(&rrc_instance_pP->uid_allocator, ue_context_pP->local_uid); free(ue_context_pP); rrc_instance_pP->Nb_ue --; LOG_I(RRC, - PROTOCOL_RRC_CTXT_UE_FMT" Removed UE context\n", - PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP)); + PROTOCOL_NR_RRC_CTXT_UE_FMT" Removed UE context\n", + PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP)); } //----------------------------------------------------------------------------- diff --git a/openair2/RRC/NR/rrc_gNB_UE_context.h b/openair2/RRC/NR/rrc_gNB_UE_context.h index 73bd93e737c..4009f2617f0 100644 --- a/openair2/RRC/NR/rrc_gNB_UE_context.h +++ b/openair2/RRC/NR/rrc_gNB_UE_context.h @@ -34,27 +34,6 @@ #include "COMMON/platform_types.h" #include "nr_rrc_defs.h" - -void -nr_uid_linear_allocator_init( - nr_uid_allocator_t* const uid_pP -); - -uid_t -nr_uid_linear_allocator_new( - gNB_RRC_INST* rrc_instance_pP -); - - -void -nr_uid_linear_allocator_free( - gNB_RRC_INST* rrc_instance_pP, - uid_t uidP -); - - - - int rrc_gNB_compare_ue_rnti_id( struct rrc_gNB_ue_context_s* c1_pP, struct rrc_gNB_ue_context_s* c2_pP diff --git a/openair2/RRC/NR_UE/L2_interface_ue.c b/openair2/RRC/NR_UE/L2_interface_ue.c index b4508e2627d..8907ff315ad 100644 --- a/openair2/RRC/NR_UE/L2_interface_ue.c +++ b/openair2/RRC/NR_UE/L2_interface_ue.c @@ -34,6 +34,7 @@ #include "rrc_proto.h" #include "assertions.h" #include "rrc_vars.h" +#include "MAC/mac.h" typedef uint32_t channel_t; -- GitLab