From 67e53e72abafff9a122bf6e90aa728d0b6132a90 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Mon, 16 Jan 2017 17:07:47 +0100 Subject: [PATCH 01/19] fix the use of get_eNB_UE_stats The function may return NULL if the UE has been dropped in the PHY layer but is still present in the MAC layer. Deal with the NULL case everywhere it's needed. --- openair2/LAYER2/MAC/eNB_scheduler_ulsch.c | 23 ++++++++++------- openair2/LAYER2/MAC/pre_processor.c | 30 ++++++++++++++++++++--- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c index 831b00a2f9..ec43c2434b 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c @@ -751,6 +751,20 @@ void schedule_ulsch_rnti(module_id_t module_idP, continue; } + /* let's drop the UE if get_eNB_UE_stats returns NULL when calling it with any of the UE's active UL CCs */ + /* TODO: refine? */ + drop_ue = 0; + for (n=0; nnumactiveULCCs[UE_id]; n++) { + CC_id = UE_list->ordered_ULCCids[n][UE_id]; + if (mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti) == NULL) { + LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: no PHY context\n", module_idP,frameP,subframeP,UE_id,rnti,CC_id); + drop_ue = 1; + break; + } + } + if (drop_ue == 1) + continue; + // loop over all active UL CC_ids for this UE for (n=0; nnumactiveULCCs[UE_id]; n++) { // This is the actual CC_id in the list @@ -758,15 +772,6 @@ void schedule_ulsch_rnti(module_id_t module_idP, frame_parms = mac_xface->get_lte_frame_parms(module_idP,CC_id); eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti); - if (eNB_UE_stats==NULL) { - LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: no PHY context\n", module_idP,frameP,subframeP,UE_id,rnti,CC_id); - drop_ue=1; - continue; // mac_xface->macphy_exit("[MAC][eNB] Cannot find eNB_UE_stats\n"); - } - - if (drop_ue==1) - continue; - if (CCE_allocation_infeasible(module_idP,CC_id,0,subframeP,aggregation,rnti)) { LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: not enough nCCE\n", module_idP,frameP,subframeP,UE_id,rnti,CC_id); continue; // break; diff --git a/openair2/LAYER2/MAC/pre_processor.c b/openair2/LAYER2/MAC/pre_processor.c index ed12d322c1..150f2c15de 100644 --- a/openair2/LAYER2/MAC/pre_processor.c +++ b/openair2/LAYER2/MAC/pre_processor.c @@ -153,12 +153,25 @@ void assign_rbs_required (module_id_t Mod_id, UE_list_t *UE_list = &eNB_mac_inst[Mod_id].UE_list; // UE_TEMPLATE *UE_template; LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]; + int skip_ue; // clear rb allocations across all CC_ids for (UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) { pCCid = UE_PCCID(Mod_id,UE_id); rnti = UE_list->UE_template[pCCid][UE_id].rnti; + /* skip UE not present in PHY (for any of its active CCs) */ + skip_ue = 0; + for (n=0; nnumactiveCCs[UE_id]; n++) { + CC_id = UE_list->ordered_CCids[n][UE_id]; + if (mac_xface->get_eNB_UE_stats(Mod_id,CC_id,rnti) == NULL) { + skip_ue = 1; + break; + } + } + if (skip_ue == 1) + continue; + //update CQI information across component carriers for (n=0; nnumactiveCCs[UE_id]; n++) { @@ -262,7 +275,7 @@ int maxround(module_id_t Mod_id,uint16_t rnti,int frame,sub_frame_t subframe,uin } // This function scans all CC_ids for a particular UE to find the maximum DL CQI - +// it returns -1 if the UE is not found in PHY layer (get_eNB_UE_stats gives NULL) int maxcqi(module_id_t Mod_id,int32_t UE_id) { @@ -276,8 +289,9 @@ int maxcqi(module_id_t Mod_id,int32_t UE_id) eNB_UE_stats = mac_xface->get_eNB_UE_stats(Mod_id,CC_id,UE_RNTI(Mod_id,UE_id)); if (eNB_UE_stats==NULL) { - mac_xface->macphy_exit("maxcqi: could not get eNB_UE_stats\n"); - return 0; // not reached + /* the UE may have been removed in the PHY layer, don't exit */ + //mac_xface->macphy_exit("maxcqi: could not get eNB_UE_stats\n"); + return -1; } if (eNB_UE_stats->DL_cqi[0] > CQI) { @@ -329,7 +343,13 @@ void sort_UEs (module_id_t Mod_idP, round2 = maxround(Mod_idP,rnti2,frameP,subframeP,0); //mac_xface->get_ue_active_harq_pid(Mod_id,rnti2,subframe,&harq_pid2,&round2,0); pCC_id2 = UE_PCCID(Mod_idP,UE_id2); - if(round2 > round1) { // Check first if one of the UEs has an active HARQ process which needs service and swap order + /* if 2nd UE is not in PHY, do nothing */ + if (cqi2 == -1) + continue; + /* if 1st UE is not in PHY, swap with 2nd UE */ + if (cqi1 == -1) { + swap_UEs(UE_list,UE_id1,UE_id2,0); + } else if(round2 > round1) { // Check first if one of the UEs has an active HARQ process which needs service and swap order swap_UEs(UE_list,UE_id1,UE_id2,0); } else if (round2 == round1) { // RK->NN : I guess this is for fairness in the scheduling. This doesn't make sense unless all UEs have the same configuration of logical channels. This should be done on the sum of all information that has to be sent. And still it wouldn't ensure fairness. It should be based on throughput seen by each UE or maybe using the head_sdu_creation_time, i.e. swap UEs if one is waiting longer for service. @@ -758,6 +778,8 @@ void dlsch_scheduler_pre_processor_reset (int module_idP, int sf05_upper=-1,sf05_lower=-1; #endif LTE_eNB_UE_stats *eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti); + if (eNB_UE_stats == NULL) return; + // initialize harq_pid and round mac_xface->get_ue_active_harq_pid(module_idP,CC_id,rnti, frameP,subframeP, From adbc609bbf08a9c83bb4f6520351f9bb8a792070 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Wed, 18 Jan 2017 10:33:52 +0100 Subject: [PATCH 02/19] bugfix: reset DCI count before adding one The management of uplink failure generates a DCI to send a RA PDCCH order. It calls add_ue_spec_dci which increases DCI_pdu[CC_id]->Num_ue_spec_dci, but this was reset to 0 *after* the DCI generation. Let's reset *before*. Bug reported by Liang Yong on openair5g-user mailing list. --- openair2/LAYER2/MAC/eNB_scheduler.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c index e8ed8b8f5e..d00167160f 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler.c +++ b/openair2/LAYER2/MAC/eNB_scheduler.c @@ -121,6 +121,17 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, memset(eNB_mac_inst[module_idP].common_channels[CC_id].vrb_map,0,100); } + // clear DCI and BCCH contents before scheduling + for (CC_id=0; CC_idNum_common_dci = 0; + DCI_pdu[CC_id]->Num_ue_spec_dci = 0; +#ifdef Rel10 + eNB_mac_inst[module_idP].common_channels[CC_id].mcch_active =0; +#endif + eNB_mac_inst[module_idP].frame = frameP; + eNB_mac_inst[module_idP].subframe = subframeP; + } + // refresh UE list based on UEs dropped by PHY in previous subframe i = UE_list->head; @@ -318,22 +329,6 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, #endif - // clear DCI and BCCH contents before scheduling - for (CC_id=0; CC_idNum_common_dci = 0; - DCI_pdu[CC_id]->Num_ue_spec_dci = 0; - - -#ifdef Rel10 - eNB_mac_inst[module_idP].common_channels[CC_id].mcch_active =0; -#endif - - eNB_mac_inst[module_idP].frame = frameP; - eNB_mac_inst[module_idP].subframe = subframeP; - - - } - /* #ifndef DISABLE_SF_TRIGGER */ /* //Send subframe trigger to the controller */ /* if (mac_agent_registered[module_idP]) { */ From 05d02c43eced4d5ee8392b1d5692403916a026c8 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Thu, 19 Jan 2017 09:49:39 +0100 Subject: [PATCH 03/19] remove annoying logging (dump_CCE_table) --- openair2/LAYER2/MAC/eNB_scheduler_primitives.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c index ce08bc5408..7f81fa906e 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c @@ -1096,7 +1096,7 @@ try_again: 1<dci_alloc[j].L, nCCE,nCCE_max,DCI_pdu->num_pdcch_symbols); } - dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,dci_alloc->L); + //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,dci_alloc->L); goto failed; } From 38b387794e43ae8af46bc32cf792400328511be9 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Thu, 19 Jan 2017 09:57:43 +0100 Subject: [PATCH 04/19] hack in RLC AM to avoid a race Here is the problem: UE comes. SRB2 is configured via message to RRC. At some point the RLC AM is created but not configured yet. At this moment (I think) MAC calls mac_rlc_status_ind which calls this function. But the init was not finished yet and we have a crash below when testing mem_block != NULL. The "solution" is to test if rlc->input_sdus is NULL. This is a very dirty hack. I would say the solution is to use proper locking mechanism because RLC is used by two threads: PHY/MAC on one hand and RRC on another hand (I think). --- openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.c b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.c index 1d93055487..4051a88ef2 100644 --- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.c +++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.c @@ -557,6 +557,15 @@ rlc_am_mac_status_indication ( status_resp.head_sdu_is_segmented = 0; status_resp.rlc_info.rlc_protocol_state = rlc->protocol_state; + /* TODO: remove this hack. Problem is: there is a race. + * UE comes. SRB2 is configured via message to RRC. + * At some point the RLC AM is created but not configured yet. + * At this moment (I think) MAC calls mac_rlc_status_ind + * which calls this function. But the init was not finished yet + * and we have a crash below when testing mem_block != NULL. + */ + if (rlc->input_sdus == NULL) return status_resp; + if (rlc->last_frame_status_indication != ctxt_pP->frame) { rlc_am_check_timer_poll_retransmit(ctxt_pP, rlc); rlc_am_check_timer_reordering(ctxt_pP, rlc); From 5933f21882d95ccfe5ea1420df05937615d8c2cd Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Thu, 19 Jan 2017 10:00:19 +0100 Subject: [PATCH 05/19] hack to avoid zombie UEs in the MAC layer Here is the problem: Sometimes the UE has no PHY context but is still present in the MAC with 'ul_failure_timer' = 0 and 'ul_out_of_sync' = 0. It seems wrong and the UE stays there forever. Let's start an UL out of sync procedure in this case. The root cause of this problem has to be found and corrected. In the meantime, this hack... This has to be redone at some point. --- openair2/LAYER2/MAC/eNB_scheduler_ulsch.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c index ec43c2434b..6e744a5228 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c @@ -762,8 +762,25 @@ void schedule_ulsch_rnti(module_id_t module_idP, break; } } - if (drop_ue == 1) + if (drop_ue == 1) { + /* TODO: this is a hack. Sometimes the UE has no PHY context but + * is still present in the MAC with 'ul_failure_timer' = 0 and + * 'ul_out_of_sync' = 0. It seems wrong and the UE stays there forever. Let's + * start an UL out of sync procedure in this case. + * The root cause of this problem has to be found and corrected. + * In the meantime, this hack... + */ + if (UE_list->UE_sched_ctrl[UE_id].ul_failure_timer == 0 && + UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 0) { + LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: UE in weird state, let's put it 'out of sync'\n", + module_idP,frameP,subframeP,UE_id,rnti,CC_id); + // inform RRC of failure and clear timer + mac_eNB_rrc_ul_failure(module_idP,CC_id,frameP,subframeP,rnti); + UE_list->UE_sched_ctrl[UE_id].ul_failure_timer=0; + UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync=1; + } continue; + } // loop over all active UL CC_ids for this UE for (n=0; nnumactiveULCCs[UE_id]; n++) { From 390085c377d286db47f0262204d93c1ea4cefb94 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Thu, 19 Jan 2017 12:47:50 +0100 Subject: [PATCH 06/19] remove printing of UE capabilities on stdout Modern UEs have very long UE capabilities. It disrupts realtime behaviour of the modem. Let's put a simple log message indicating we got the UE capabilities. --- openair2/RRC/LITE/rrc_eNB.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openair2/RRC/LITE/rrc_eNB.c b/openair2/RRC/LITE/rrc_eNB.c index 1ed4da9b27..d37741b40f 100644 --- a/openair2/RRC/LITE/rrc_eNB.c +++ b/openair2/RRC/LITE/rrc_eNB.c @@ -96,7 +96,7 @@ #if defined(FLEXRAN_AGENT_SB_IF) #include "flexran_agent_extern.h" #endif -#define XER_PRINT +//#define XER_PRINT #ifdef PHY_EMUL extern EMULATION_VARS *Emul_vars; @@ -4786,6 +4786,7 @@ rrc_eNB_decode_dcch( #ifdef XER_PRINT xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg); #endif + LOG_I(RRC, "got UE capabilities for UE %x\n", ctxt_pP->rnti); dec_rval = uper_decode(NULL, &asn_DEF_UE_EUTRA_Capability, (void **)&UE_EUTRA_Capability, @@ -4796,7 +4797,7 @@ rrc_eNB_decode_dcch( choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list. array[0]->ueCapabilityRAT_Container.size, 0, 0); //#ifdef XER_PRINT - xer_fprint(stdout, &asn_DEF_UE_EUTRA_Capability, (void *)UE_EUTRA_Capability); + //xer_fprint(stdout, &asn_DEF_UE_EUTRA_Capability, (void *)UE_EUTRA_Capability); //#endif #if defined(ENABLE_USE_MME) From 2c578f350aad32e36d39f736bec2424fc419f3e4 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Thu, 19 Jan 2017 17:23:15 +0100 Subject: [PATCH 07/19] remove XER printing in asn1_msg.c, too verbose --- openair2/RRC/LITE/MESSAGES/asn1_msg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openair2/RRC/LITE/MESSAGES/asn1_msg.c b/openair2/RRC/LITE/MESSAGES/asn1_msg.c index 5f9a8e0e2a..b4290e8b9d 100644 --- a/openair2/RRC/LITE/MESSAGES/asn1_msg.c +++ b/openair2/RRC/LITE/MESSAGES/asn1_msg.c @@ -99,7 +99,7 @@ int errno; # endif #endif -#define XER_PRINT +//#define XER_PRINT extern Enb_properties_array_t enb_properties; typedef struct xer_sprint_string_s { From 2a1d1134e91bccd9de37cf89f5461dcba7755aa6 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Fri, 20 Jan 2017 14:54:19 +0100 Subject: [PATCH 08/19] log an error if UE is -1 in rrc_mac_config_req --- openair2/LAYER2/MAC/config.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/openair2/LAYER2/MAC/config.c b/openair2/LAYER2/MAC/config.c index 2e76735fa7..b5d613e4ae 100644 --- a/openair2/LAYER2/MAC/config.c +++ b/openair2/LAYER2/MAC/config.c @@ -195,10 +195,14 @@ rrc_mac_config_req( } } else { - if (logicalChannelConfig) - UE_list->UE_template[CC_idP][UE_id].lcgidmap[logicalChannelIdentity] = *logicalChannelConfig->ul_SpecificParameters->logicalChannelGroup; - else - UE_list->UE_template[CC_idP][UE_id].lcgidmap[logicalChannelIdentity] = 0; + if (UE_id == -1) { + LOG_E(MAC,"%s:%d:%s: ERROR, UE_id == -1\n", __FILE__, __LINE__, __FUNCTION__); + } else { + if (logicalChannelConfig) + UE_list->UE_template[CC_idP][UE_id].lcgidmap[logicalChannelIdentity] = *logicalChannelConfig->ul_SpecificParameters->logicalChannelGroup; + else + UE_list->UE_template[CC_idP][UE_id].lcgidmap[logicalChannelIdentity] = 0; + } } } @@ -296,7 +300,10 @@ rrc_mac_config_req( if (physicalConfigDedicated != NULL) { if (eNB_flagP==1) { - mac_xface->phy_config_dedicated_eNB(Mod_idP, CC_idP, UE_RNTI(Mod_idP, UE_id), physicalConfigDedicated); + if (UE_id == -1) + LOG_E(MAC,"%s:%d:%s: ERROR, UE_id == -1\n", __FILE__, __LINE__, __FUNCTION__); + else + mac_xface->phy_config_dedicated_eNB(Mod_idP, CC_idP, UE_RNTI(Mod_idP, UE_id), physicalConfigDedicated); } else { mac_xface->phy_config_dedicated_ue(Mod_idP,0,eNB_index,physicalConfigDedicated); UE_mac_inst[Mod_idP].physicalConfigDedicated=physicalConfigDedicated; // for SR proc @@ -308,7 +315,10 @@ rrc_mac_config_req( if (sCellToAddMod_r10 != NULL) { if (eNB_flagP==1) { - mac_xface->phy_config_dedicated_scell_eNB(Mod_idP,UE_RNTI(Mod_idP,UE_id),sCellToAddMod_r10,1); + if (UE_id == -1) + LOG_E(MAC,"%s:%d:%s: ERROR, UE_id == -1\n", __FILE__, __LINE__, __FUNCTION__); + else + mac_xface->phy_config_dedicated_scell_eNB(Mod_idP,UE_RNTI(Mod_idP,UE_id),sCellToAddMod_r10,1); } else { //#warning "phy_config_dedicated_scell_ue is empty" From c33afccb1be0f0a5ca96433bb6d77cf356d47095 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Fri, 20 Jan 2017 14:57:28 +0100 Subject: [PATCH 09/19] bugfix: logging was done after modification of values It resulted in wrong log message, leading to complicated debugging. --- openair2/LAYER2/MAC/eNB_scheduler_ulsch.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c index 6e744a5228..d09111290d 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c @@ -904,6 +904,12 @@ void schedule_ulsch_rnti(module_id_t module_idP, T_INT(subframeP), T_INT(harq_pid), T_INT(mcs), T_INT(first_rb[CC_id]), T_INT(rb_table[rb_table_index]), T_INT(TBS), T_INT(ndi)); + if (mac_eNB_get_rrc_status(module_idP,rnti) < RRC_CONNECTED) + LOG_I(MAC,"[eNB %d][PUSCH %d/%x] CC_id %d Frame %d subframeP %d Scheduled UE %d (mcs %d, first rb %d, nb_rb %d, rb_table_index %d, TBS %d, harq_pid %d)\n", + module_idP,harq_pid,rnti,CC_id,frameP,subframeP,UE_id,mcs, + first_rb[CC_id],rb_table[rb_table_index], + rb_table_index,TBS,harq_pid); + // bad indices : 20 (40 PRB), 21 (45 PRB), 22 (48 PRB) // increment for next UE allocation first_rb[CC_id]+=rb_table[rb_table_index]; @@ -913,12 +919,6 @@ void schedule_ulsch_rnti(module_id_t module_idP, if (UE_id == UE_list->head) VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_SCHEDULED,UE_sched_ctrl->ul_scheduled); - if (mac_eNB_get_rrc_status(module_idP,rnti) < RRC_CONNECTED) - LOG_I(MAC,"[eNB %d][PUSCH %d/%x] CC_id %d Frame %d subframeP %d Scheduled UE %d (mcs %d, first rb %d, nb_rb %d, rb_table_index %d, TBS %d, harq_pid %d)\n", - module_idP,harq_pid,rnti,CC_id,frameP,subframeP,UE_id,mcs, - first_rb[CC_id],rb_table[rb_table_index], - rb_table_index,TBS,harq_pid); - // adjust total UL buffer status by TBS, wait for UL sdus to do final update LOG_D(MAC,"[eNB %d] CC_id %d UE %d/%x : adjusting ul_total_buffer, old %d, TBS %d\n", module_idP,CC_id,UE_id,rnti,UE_template->ul_total_buffer,TBS); if (UE_template->ul_total_buffer > TBS) From 89445da9ebb3f136e4b730ec339616e3cc308a1f Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Fri, 20 Jan 2017 14:59:24 +0100 Subject: [PATCH 10/19] attempting at fixing RRC RRC does not work very well when one UE goes away and comes back in some situations. This commit is an attempt at making things work better. It is probably not the end of the story. --- openair2/RRC/LITE/rrc_eNB.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/openair2/RRC/LITE/rrc_eNB.c b/openair2/RRC/LITE/rrc_eNB.c index d37741b40f..8b5b012ff1 100644 --- a/openair2/RRC/LITE/rrc_eNB.c +++ b/openair2/RRC/LITE/rrc_eNB.c @@ -4191,9 +4191,11 @@ rrc_eNB_decode_ccch( * the current one must be removed from MAC/PHY (zombie UE) */ if ((ue_context_p = rrc_eNB_ue_context_random_exist(ctxt_pP, random_value))) { -//#warning "TODO: random_exist: remove UE from MAC/PHY (how?)" - // AssertFatal(0 == 1, "TODO: remove UE from MAC/PHY (how?)"); + LOG_W(RRC, "new UE rnti %x (coming with random value) is already there as UE %x, removing %x from MAC/PHY\n", + ctxt_pP->rnti, ue_context_p->ue_context.rnti, ctxt_pP->rnti); + rrc_mac_remove_ue(ctxt_pP->module_id, ctxt_pP->rnti); ue_context_p = NULL; + return 0; } else { ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP, random_value); } @@ -4204,9 +4206,8 @@ rrc_eNB_decode_ccch( m_tmsi_t m_tmsi = BIT_STRING_to_uint32(&s_TMSI.m_TMSI); random_value = (((uint64_t)mme_code) << 32) | m_tmsi; if ((ue_context_p = rrc_eNB_ue_context_stmsi_exist(ctxt_pP, mme_code, m_tmsi))) { - - //#warning "TODO: stmsi_exist: remove UE from MAC/PHY (how?)" LOG_I(RRC," S-TMSI exists, ue_context_p %p, old rnti %x => %x\n",ue_context_p,ue_context_p->ue_context.rnti,ctxt_pP->rnti); + rrc_mac_remove_ue(ctxt_pP->module_id, ue_context_p->ue_context.rnti); stmsi_received=1; /* replace rnti in the context */ /* for that, remove the context from the RB tree */ @@ -4218,8 +4219,6 @@ rrc_eNB_decode_ccch( /* reset timers */ ue_context_p->ue_context.ul_failure_timer = 0; ue_context_p->ue_context.ue_release_timer = 0; - // AssertFatal(0 == 1, "TODO: remove UE from MAC/PHY (how?)"); - // ue_context_p = NULL; } else { LOG_I(RRC," S-TMSI doesn't exist, setting Initialue_identity_s_TMSI.m_tmsi to %p => %x\n",ue_context_p,m_tmsi); ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP, NOT_A_RANDOM_UE_IDENTITY); @@ -4230,7 +4229,8 @@ rrc_eNB_decode_ccch( ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code = mme_code; ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi = m_tmsi; } else { - break; + /* TODO: do we have to break here? */ + //break; } } From a5d5a21ddb5b467886954c99648a7cf77b1727b0 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Fri, 20 Jan 2017 15:01:51 +0100 Subject: [PATCH 11/19] "fix" handling of UE_id in RA. What if it's -1? Is it possible? We catch the case and abort. We may do a proper fix if the case happen. I don't think it will, but who knows... --- openair2/LAYER2/MAC/eNB_scheduler_RA.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c index e24281b89a..195c78c538 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c @@ -73,7 +73,7 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un unsigned char i,harq_pid,round; int16_t rrc_sdu_length; unsigned char lcid,offset; - module_id_t UE_id= UE_INDEX_INVALID; + int UE_id = -1; unsigned short TBsize = -1; unsigned short msg4_padding,msg4_post_padding,msg4_header; uint8_t *vrb_map; @@ -266,6 +266,7 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un // check for Msg4 Message UE_id = find_UE_id(module_idP,RA_template->rnti); + if (UE_id == -1) { printf("%s:%d:%s: FATAL ERROR\n", __FILE__, __LINE__, __FUNCTION__); abort(); } if (Is_rrc_registered == 1) { From c1fee62473084fe6b75d56172c4954d20622992d Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Fri, 20 Jan 2017 15:05:28 +0100 Subject: [PATCH 12/19] RA: fix allocation of RA process A RA process is not available if and RA_template[i].wait_ack_Msg4 != 0 We can have RA_active==FALSE and wait_ack_Msg4==1, in which case the RA process is in use and cannot be reassigned. --- openair2/LAYER2/MAC/eNB_scheduler_RA.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c index 195c78c538..8ff409978e 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c @@ -747,7 +747,8 @@ void initiate_ra_proc(module_id_t module_idP, int CC_id,frame_t frameP, uint16_t VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_INITIATE_RA_PROC,0); for (i=0; i Date: Fri, 20 Jan 2017 15:09:05 +0100 Subject: [PATCH 13/19] fix: better creation of RNTI The previous version was calling taus(), which may return any value in [0..65535]. The new version restricts it to [1024..59999] (arbitrary values, big enough, and in the valid range). It also checks that the new RNTI is not already present in the MAC. I think we should also check that it's not used by a RA process. The "loop" thing may not be the best solution either. To be refined. --- openair2/LAYER2/MAC/eNB_scheduler_RA.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c index 8ff409978e..63109a4c0f 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c @@ -749,13 +749,24 @@ void initiate_ra_proc(module_id_t module_idP, int CC_id,frame_t frameP, uint16_t for (i=0; i= 1024 && RA_template[i].rnti < 60000)); + if (loop == 100) { printf("%s:%d:%s: FATAL ERROR! contact the authors\n", __FILE__, __LINE__, __FUNCTION__); abort(); } RA_template[i].RA_rnti = 1+subframeP+(10*f_id); RA_template[i].preamble_index = preamble_index; LOG_D(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d Activating RAR generation for process %d, rnti %x, RA_active %d\n", From 0d3fa211878f67198c6760ba37830702f03a3d64 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Fri, 20 Jan 2017 15:11:40 +0100 Subject: [PATCH 14/19] add a LOG in RA --- openair2/LAYER2/MAC/eNB_scheduler_RA.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c index 63109a4c0f..e046c085e1 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c @@ -776,6 +776,8 @@ void initiate_ra_proc(module_id_t module_idP, int CC_id,frame_t frameP, uint16_t return; } } + + LOG_E(MAC,"[eNB %d][RAPROC] FAILURE: CC_id %d Frame %d Initiating RA procedure for preamble index %d\n",module_idP,CC_id,frameP,preamble_index); } void cancel_ra_proc(module_id_t module_idP, int CC_id, frame_t frameP, rnti_t rnti) From c3c2b774d631fe3cba4898bb8ef860b1021d968d Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Fri, 20 Jan 2017 15:15:58 +0100 Subject: [PATCH 15/19] bugfix: do not get pCC_id if UE_id is invalid --- openair2/LAYER2/MAC/eNB_scheduler_primitives.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c index 7f81fa906e..71cbb36ce9 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c @@ -288,7 +288,7 @@ int rrc_mac_remove_ue(module_id_t mod_idP,rnti_t rntiP) UE_list_t *UE_list = &eNB_mac_inst[mod_idP].UE_list; int UE_id = find_UE_id(mod_idP,rntiP); - int pCC_id = UE_PCCID(mod_idP,UE_id); + int pCC_id; if (UE_id == -1) { LOG_W(MAC,"rrc_mac_remove_ue: UE %x not found\n", rntiP); @@ -296,6 +296,8 @@ int rrc_mac_remove_ue(module_id_t mod_idP,rnti_t rntiP) return 0; } + pCC_id = UE_PCCID(mod_idP,UE_id); + LOG_I(MAC,"Removing UE %d from Primary CC_id %d (rnti %x)\n",UE_id,pCC_id, rntiP); dump_ue_list(UE_list,0); From c824eea0745e19b0f0a2604e67aaa4cb47ff3707 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Fri, 20 Jan 2017 15:21:37 +0100 Subject: [PATCH 16/19] better (maybe) freeing of RA process when an UE is removed from MAC The RA process may be in the state: RA_active == FALSE and wait_ack_Msg4 == 1 Testing only the rnti should be enough, if everything else works properly. Also, don't break, just in case. (Not sure it makes a difference.) --- openair2/LAYER2/MAC/eNB_scheduler_primitives.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c index 71cbb36ce9..3cf36eaa8d 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c @@ -365,8 +365,7 @@ int rrc_mac_remove_ue(module_id_t mod_idP,rnti_t rntiP) RA_TEMPLATE *RA_template; for (i=0;iRA_active == TRUE) && - (RA_template->rnti == rntiP)){ + if (RA_template->rnti == rntiP){ RA_template->RA_active=FALSE; RA_template->generate_rar=0; RA_template->generate_Msg4=0; @@ -374,7 +373,7 @@ int rrc_mac_remove_ue(module_id_t mod_idP,rnti_t rntiP) RA_template->timing_offset=0; RA_template->RRC_timer=20; RA_template->rnti = 0; - break; + //break; } } if (ret == 0) { From da75a078709f1952554759110c07d824b7e32fbf Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Fri, 20 Jan 2017 15:36:58 +0100 Subject: [PATCH 17/19] rewrite sort_UE for UL and DL and adapt the rest to the change The previous version did not seem to work properly with several UEs. I too often ended up with a list 'next' where next[i] = i, leading to an infinite loop, crashing the processing. The sorting functions were hard to understand and too slow anyway (O(n*n)). We now use qsort_r and comparison functions, that should define the same order as the previous version. One important point is that the "next" lists and the "head" variable are now considered invalid before calling sort_UE. So all the code (coming before sort_UE) that looped using those variables has been rewritten to loop over all possible UEs and the first instruction of the loop is to exit the loop if the UE is not 'active'. There is room for improvement here. We will reintroduce a list of some kind at some point. Let's first have something that works and then optimize. Today NUMBER_OF_UE_MAX is 16, that's not a big deal. Consequently, the add_new_ue and rrc_mac_remove_ue have also been rewritten, hopefully for the better. This commit is not a basic work and may introduce some problems. --- openair2/LAYER2/MAC/eNB_scheduler.c | 10 +- openair2/LAYER2/MAC/eNB_scheduler_dlsch.c | 2 + .../LAYER2/MAC/eNB_scheduler_primitives.c | 81 +---- openair2/LAYER2/MAC/pre_processor.c | 291 ++++++++++++++++-- 4 files changed, 283 insertions(+), 101 deletions(-) diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c index d00167160f..023d01d656 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler.c +++ b/openair2/LAYER2/MAC/eNB_scheduler.c @@ -99,7 +99,7 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, int result; #endif DCI_PDU *DCI_pdu[MAX_NUM_CCs]; - int CC_id,i,next_i; + int CC_id,i; //,next_i; UE_list_t *UE_list=&eNB_mac_inst[module_idP].UE_list; rnti_t rnti; void *DLSCH_dci=NULL; @@ -133,17 +133,15 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, } // refresh UE list based on UEs dropped by PHY in previous subframe - i = UE_list->head; + for (i = 0; i < NUMBER_OF_UE_MAX; i++) { + if (UE_list->active[i] != TRUE) continue; - while (i>=0) { rnti = UE_RNTI(module_idP, i); CC_id = UE_PCCID(module_idP, i); if ((frameP==0)&&(subframeP==0)) LOG_I(MAC,"UE rnti %x : %s\n", rnti, UE_list->UE_sched_ctrl[i].ul_out_of_sync==0 ? "in synch" : "out of sync"); - next_i= UE_list->next[i]; - PHY_vars_eNB_g[module_idP][CC_id]->pusch_stats_bsr[i][(frameP*10)+subframeP]=-63; if (i==UE_list->head) VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BSR,PHY_vars_eNB_g[module_idP][CC_id]->pusch_stats_bsr[i][(frameP*10)+subframeP]); @@ -271,8 +269,6 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, } } } // ul_failure_timer>0 - - i = next_i; } #if defined(ENABLE_ITTI) diff --git a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c index 93dc993711..770264074f 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c @@ -453,9 +453,11 @@ schedule_ue_spec( UE_sched_ctrl *ue_sched_ctl; int i; +#if 0 if (UE_list->head==-1) { return; } +#endif start_meas(&eNB->schedule_dlsch); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH,VCD_FUNCTION_IN); diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c index 3cf36eaa8d..db204c7762 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c @@ -107,18 +107,17 @@ DCI_PDU *get_dci_sdu(module_id_t module_idP, int CC_id,frame_t frameP, sub_frame int find_UE_id(module_id_t mod_idP, rnti_t rntiP) //------------------------------------------------------------------------------ { - int UE_id; UE_list_t *UE_list = &eNB_mac_inst[mod_idP].UE_list; - for (UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) { + for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) { + if (UE_list->active[UE_id] != TRUE) continue; if (UE_list->UE_template[UE_PCCID(mod_idP,UE_id)][UE_id].rnti==rntiP) { return(UE_id); } } return(-1); - } //------------------------------------------------------------------------------ @@ -235,21 +234,16 @@ void dump_ue_list(UE_list_t *listP, int ul_flag) int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP,int harq_pidP) { int UE_id; - int j; + int i, j; UE_list_t *UE_list = &eNB_mac_inst[mod_idP].UE_list; LOG_D(MAC,"[eNB %d, CC_id %d] Adding UE with rnti %x (next avail %d, num_UEs %d)\n",mod_idP,cc_idP,rntiP,UE_list->avail,UE_list->num_UEs); dump_ue_list(UE_list,0); - if (UE_list->avail>=0) { - UE_id = UE_list->avail; - AssertFatal( UE_id < NUMBER_OF_UE_MAX, "BAD UE_id %u > NUMBER_OF_UE_MAX",UE_id ); - UE_list->avail = UE_list->next[UE_list->avail]; - UE_list->next[UE_id] = UE_list->head; - UE_list->next_ul[UE_id] = UE_list->head_ul; - UE_list->head = UE_id; - UE_list->head_ul = UE_id; + for (i = 0; i < NUMBER_OF_UE_MAX; i++) { + if (UE_list->active[i] == TRUE) continue; + UE_id = i; UE_list->UE_template[cc_idP][UE_id].rnti = rntiP; UE_list->UE_template[cc_idP][UE_id].configured = FALSE; UE_list->numactiveCCs[UE_id] = 1; @@ -282,17 +276,14 @@ int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP,int harq_pidP) int rrc_mac_remove_ue(module_id_t mod_idP,rnti_t rntiP) //------------------------------------------------------------------------------ { - - int prev,i, ret=-1; - - + int i; UE_list_t *UE_list = &eNB_mac_inst[mod_idP].UE_list; int UE_id = find_UE_id(mod_idP,rntiP); int pCC_id; if (UE_id == -1) { LOG_W(MAC,"rrc_mac_remove_ue: UE %x not found\n", rntiP); - mac_phy_remove_ue(mod_idP,rntiP); + mac_phy_remove_ue(mod_idP, rntiP); return 0; } @@ -301,6 +292,9 @@ int rrc_mac_remove_ue(module_id_t mod_idP,rnti_t rntiP) LOG_I(MAC,"Removing UE %d from Primary CC_id %d (rnti %x)\n",UE_id,pCC_id, rntiP); dump_ue_list(UE_list,0); + UE_list->active[UE_id] = FALSE; + UE_list->num_UEs--; + // clear all remaining pending transmissions UE_list->UE_template[pCC_id][UE_id].bsr_info[LCGID0] = 0; UE_list->UE_template[pCC_id][UE_id].bsr_info[LCGID1] = 0; @@ -315,50 +309,6 @@ int rrc_mac_remove_ue(module_id_t mod_idP,rnti_t rntiP) eNB_dlsch_info[mod_idP][pCC_id][UE_id].rnti = NOT_A_RNTI; eNB_dlsch_info[mod_idP][pCC_id][UE_id].status = S_DL_NONE; - prev = UE_list->head; - - for (i=UE_list->head; i>=0; i=UE_list->next[i]) { - if (i == UE_id) { - // link prev to next in Active list - if (i==UE_list->head) { - UE_list->head = UE_list->next[i]; - } else { - UE_list->next[prev] = UE_list->next[i]; - } - - // add UE id (i)to available - UE_list->next[i] = UE_list->avail; - UE_list->avail = i; - UE_list->active[i] = FALSE; - UE_list->num_UEs--; - ret=0; - break; - } - - prev=i; - } - - // do the same for UL - prev = UE_list->head_ul; - - for (i=UE_list->head_ul; i>=0; i=UE_list->next_ul[i]) { - if (i == UE_id) { - // link prev to next in Active list - if (i==UE_list->head_ul) { - UE_list->head_ul = UE_list->next_ul[i]; - } else { - UE_list->next_ul[prev] = UE_list->next_ul[i]; - } - - // add UE id (i)to available - UE_list->next_ul[i] = UE_list->avail; - ret = 0; - break; - } - - prev=i; - } - mac_phy_remove_ue(mod_idP,rntiP); // check if this has an RA process active @@ -376,15 +326,8 @@ int rrc_mac_remove_ue(module_id_t mod_idP,rnti_t rntiP) //break; } } - if (ret == 0) { - return (0); - } - - LOG_E(MAC,"error in mac_remove_ue(), could not find previous to %d in UE_list, should never happen, Dumping UE list\n",UE_id); - dump_ue_list(UE_list,0); - mac_xface->macphy_exit("mac_remove_ue: Problem in UE_list"); - return(-1); + return 0; } diff --git a/openair2/LAYER2/MAC/pre_processor.c b/openair2/LAYER2/MAC/pre_processor.c index 150f2c15de..f2f8c643e8 100644 --- a/openair2/LAYER2/MAC/pre_processor.c +++ b/openair2/LAYER2/MAC/pre_processor.c @@ -29,6 +29,9 @@ */ +#define _GNU_SOURCE +#include + #include "assertions.h" #include "PHY/defs.h" #include "PHY/extern.h" @@ -62,6 +65,17 @@ #endif */ +/* this function checks that get_eNB_UE_stats returns + * a non-NULL pointer for all CCs for a given UE + */ +static int phy_stats_exist(module_id_t Mod_id, int rnti) +{ + int CC_id; + for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) + if (mac_xface->get_eNB_UE_stats(Mod_id, CC_id, rnti) == NULL) + return 0; + return 1; +} // This function stores the downlink buffer for all the logical channels void store_dlsch_buffer (module_id_t Mod_id, @@ -75,7 +89,8 @@ void store_dlsch_buffer (module_id_t Mod_id, UE_list_t *UE_list = &eNB_mac_inst[Mod_id].UE_list; UE_TEMPLATE *UE_template; - for (UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) { + for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) { + if (UE_list->active[UE_id] != TRUE) continue; UE_template = &UE_list->UE_template[UE_PCCID(Mod_id,UE_id)][UE_id]; @@ -153,23 +168,16 @@ void assign_rbs_required (module_id_t Mod_id, UE_list_t *UE_list = &eNB_mac_inst[Mod_id].UE_list; // UE_TEMPLATE *UE_template; LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]; - int skip_ue; // clear rb allocations across all CC_ids - for (UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) { + for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) { + if (UE_list->active[UE_id] != TRUE) continue; + pCCid = UE_PCCID(Mod_id,UE_id); rnti = UE_list->UE_template[pCCid][UE_id].rnti; /* skip UE not present in PHY (for any of its active CCs) */ - skip_ue = 0; - for (n=0; nnumactiveCCs[UE_id]; n++) { - CC_id = UE_list->ordered_CCids[n][UE_id]; - if (mac_xface->get_eNB_UE_stats(Mod_id,CC_id,rnti) == NULL) { - skip_ue = 1; - break; - } - } - if (skip_ue == 1) + if (!phy_stats_exist(Mod_id, rnti)) continue; //update CQI information across component carriers @@ -302,13 +310,124 @@ int maxcqi(module_id_t Mod_id,int32_t UE_id) return(CQI); } +struct sort_ue_dl_params { + int Mod_idP; + int frameP; + int subframeP; +}; +static int ue_dl_compare(const void *_a, const void *_b, void *_params) +{ + struct sort_ue_dl_params *params = _params; + UE_list_t *UE_list = &eNB_mac_inst[params->Mod_idP].UE_list; + + int UE_id1 = *(const int *)_a; + int UE_id2 = *(const int *)_b; + + int rnti1 = UE_RNTI(params->Mod_idP, UE_id1); + int pCC_id1 = UE_PCCID(params->Mod_idP, UE_id1); + int round1 = maxround(params->Mod_idP, rnti1, params->frameP, params->subframeP, 1); + + int rnti2 = UE_RNTI(params->Mod_idP, UE_id2); + int pCC_id2 = UE_PCCID(params->Mod_idP, UE_id2); + int round2 = maxround(params->Mod_idP, rnti2, params->frameP, params->subframeP, 1); + + int cqi1 = maxcqi(params->Mod_idP, UE_id1); + int cqi2 = maxcqi(params->Mod_idP, UE_id2); + + if (round1 > round2) return -1; + if (round1 < round2) return 1; + + if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_info[1] + UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_info[2] > + UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[1] + UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[2]) + return -1; + if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_info[1] + UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_info[2] < + UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[1] + UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[2]) + return 1; + + if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_head_sdu_creation_time_max > + UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_head_sdu_creation_time_max) + return -1; + if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_head_sdu_creation_time_max < + UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_head_sdu_creation_time_max) + return 1; + + if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_total > + UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_total) + return -1; + if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_total < + UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_total) + return 1; + + if (cqi1 > cqi2) return -1; + if (cqi1 < cqi2) return 1; + + return 0; +#if 0 + /* The above order derives from the following. */ + if(round2 > round1) { // Check first if one of the UEs has an active HARQ process which needs service and swap order + swap_UEs(UE_list,UE_id1,UE_id2,0); + } else if (round2 == round1) { + // RK->NN : I guess this is for fairness in the scheduling. This doesn't make sense unless all UEs have the same configuration of logical channels. This should be done on the sum of all information that has to be sent. And still it wouldn't ensure fairness. It should be based on throughput seen by each UE or maybe using the head_sdu_creation_time, i.e. swap UEs if one is waiting longer for service. + // for(j=0;jUE_template[pCC_id1][UE_id1].dl_buffer_info[1] + UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_info[2]) < + (UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[1] + UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[2]) ) { + swap_UEs(UE_list,UE_id1,UE_id2,0); + } else if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_head_sdu_creation_time_max < + UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_head_sdu_creation_time_max ) { + swap_UEs(UE_list,UE_id1,UE_id2,0); + } else if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_total < + UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_total ) { + swap_UEs(UE_list,UE_id1,UE_id2,0); + } else if (cqi1 < cqi2) { + swap_UEs(UE_list,UE_id1,UE_id2,0); + } + } +#endif +} // This fuction sorts the UE in order their dlsch buffer and CQI void sort_UEs (module_id_t Mod_idP, int frameP, sub_frame_t subframeP) { + int i; + int list[NUMBER_OF_UE_MAX]; + int list_size = 0; + int rnti; + struct sort_ue_dl_params params = { Mod_idP, frameP, subframeP }; + + UE_list_t *UE_list = &eNB_mac_inst[Mod_idP].UE_list; + + for (i = 0; i < NUMBER_OF_UE_MAX; i++) { + rnti = UE_RNTI(Mod_idP, i); + if (rnti == NOT_A_RNTI) + continue; + if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) + continue; + if (!phy_stats_exist(Mod_idP, rnti)) + continue; + list[list_size] = i; + list_size++; + } + + qsort_r(list, list_size, sizeof(int), ue_dl_compare, ¶ms); + + if (list_size) { + for (i = 0; i < list_size-1; i++) + UE_list->next[list[i]] = list[i+1]; + UE_list->next[list[list_size-1]] = -1; + UE_list->head = list[0]; + } else { + UE_list->head = -1; + } + +#if 0 int UE_id1,UE_id2; @@ -329,6 +448,8 @@ void sort_UEs (module_id_t Mod_idP, continue; if (UE_list->UE_sched_ctrl[UE_id1].ul_out_of_sync == 1) continue; + if (!phy_stats_exist(Mod_idP, rnti1)) + continue; pCC_id1 = UE_PCCID(Mod_idP,UE_id1); cqi1 = maxcqi(Mod_idP,UE_id1); // round1 = maxround(Mod_idP,rnti1,frameP,subframeP,0); @@ -339,17 +460,13 @@ void sort_UEs (module_id_t Mod_idP, continue; if (UE_list->UE_sched_ctrl[UE_id2].ul_out_of_sync == 1) continue; + if (!phy_stats_exist(Mod_idP, rnti2)) + continue; cqi2 = maxcqi(Mod_idP,UE_id2); round2 = maxround(Mod_idP,rnti2,frameP,subframeP,0); //mac_xface->get_ue_active_harq_pid(Mod_id,rnti2,subframe,&harq_pid2,&round2,0); pCC_id2 = UE_PCCID(Mod_idP,UE_id2); - /* if 2nd UE is not in PHY, do nothing */ - if (cqi2 == -1) - continue; - /* if 1st UE is not in PHY, swap with 2nd UE */ - if (cqi1 == -1) { - swap_UEs(UE_list,UE_id1,UE_id2,0); - } else if(round2 > round1) { // Check first if one of the UEs has an active HARQ process which needs service and swap order + if(round2 > round1) { // Check first if one of the UEs has an active HARQ process which needs service and swap order swap_UEs(UE_list,UE_id1,UE_id2,0); } else if (round2 == round1) { // RK->NN : I guess this is for fairness in the scheduling. This doesn't make sense unless all UEs have the same configuration of logical channels. This should be done on the sum of all information that has to be sent. And still it wouldn't ensure fairness. It should be based on throughput seen by each UE or maybe using the head_sdu_creation_time, i.e. swap UEs if one is waiting longer for service. @@ -374,6 +491,7 @@ void sort_UEs (module_id_t Mod_idP, } } } +#endif } @@ -427,7 +545,9 @@ void dlsch_scheduler_pre_processor (module_id_t Mod_id, min_rb_unit[CC_id]=get_min_rb_unit(Mod_id,CC_id); - for (i=UE_list->head; i>=0; i=UE_list->next[i]) { + for (i = 0; i < NUMBER_OF_UE_MAX; i++) { + if (UE_list->active[i] != TRUE) continue; + UE_id = i; // Initialize scheduling information for all active UEs @@ -473,11 +593,9 @@ void dlsch_scheduler_pre_processor (module_id_t Mod_id, continue; if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) continue; - UE_id = i; - - // if there is no available harq_process, skip the UE - if (UE_list->UE_sched_ctrl[UE_id].harq_pid[CC_id]<0) + if (!phy_stats_exist(Mod_id, rnti)) continue; + UE_id = i; for (ii=0; iiordered_CCids[ii][UE_id]; @@ -485,6 +603,10 @@ void dlsch_scheduler_pre_processor (module_id_t Mod_id, harq_pid = ue_sched_ctl->harq_pid[CC_id]; round = ue_sched_ctl->round[CC_id]; + // if there is no available harq_process, skip the UE + if (UE_list->UE_sched_ctrl[UE_id].harq_pid[CC_id]<0) + continue; + average_rbs_per_user[CC_id]=0; frame_parms[CC_id] = mac_xface->get_lte_frame_parms(Mod_id,CC_id); @@ -526,6 +648,13 @@ void dlsch_scheduler_pre_processor (module_id_t Mod_id, for(i=UE_list->head; i>=0; i=UE_list->next[i]) { rnti = UE_RNTI(Mod_id,i); + if(rnti == NOT_A_RNTI) + continue; + if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) + continue; + if (!phy_stats_exist(Mod_id, rnti)) + continue; + for (ii=0; iiordered_CCids[ii][i]; @@ -584,6 +713,8 @@ void dlsch_scheduler_pre_processor (module_id_t Mod_id, continue; if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue; + if (!phy_stats_exist(Mod_id, rnti)) + continue; transmission_mode = mac_xface->get_transmission_mode(Mod_id,CC_id,rnti); // mac_xface->get_ue_active_harq_pid(Mod_id,CC_id,rnti,frameP,subframeP,&harq_pid,&round,0); @@ -630,6 +761,8 @@ void dlsch_scheduler_pre_processor (module_id_t Mod_id, continue; if (UE_list->UE_sched_ctrl[UE_id2].ul_out_of_sync == 1) continue; + if (!phy_stats_exist(Mod_idP, rnti2)) + continue; eNB_UE_stats2 = mac_xface->get_eNB_UE_stats(Mod_id,CC_id,rnti2); //mac_xface->get_ue_active_harq_pid(Mod_id,CC_id,rnti2,frameP,subframeP,&harq_pid2,&round2,0); @@ -993,6 +1126,9 @@ void ulsch_scheduler_pre_processor(module_id_t module_idP, if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) continue; + if (!phy_stats_exist(module_idP, rnti)) + continue; + UE_id = i; for (n=0; nnumactiveULCCs[UE_id]; n++) { @@ -1043,6 +1179,8 @@ void ulsch_scheduler_pre_processor(module_id_t module_idP, continue; if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) continue; + if (!phy_stats_exist(module_idP, rnti)) + continue; UE_id = i; @@ -1073,6 +1211,8 @@ void ulsch_scheduler_pre_processor(module_id_t module_idP, continue; if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) continue; + if (!phy_stats_exist(module_idP, rnti)) + continue; UE_id = i; @@ -1130,7 +1270,8 @@ void assign_max_mcs_min_rb(module_id_t module_idP,int frameP, sub_frame_t subfra LTE_DL_FRAME_PARMS *frame_parms; - for (i=UE_list->head_ul; i>=0; i=UE_list->next_ul[i]) { + for (i = 0; i < NUMBER_OF_UE_MAX; i++) { + if (UE_list->active[i] != TRUE) continue; rnti = UE_RNTI(module_idP,i); @@ -1138,6 +1279,8 @@ void assign_max_mcs_min_rb(module_id_t module_idP,int frameP, sub_frame_t subfra continue; if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) continue; + if (!phy_stats_exist(module_idP, rnti)) + continue; if (UE_list->UE_sched_ctrl[i].phr_received == 1) mcs = 20; // if we've received the power headroom information the UE, we can go to maximum mcs @@ -1221,10 +1364,103 @@ void assign_max_mcs_min_rb(module_id_t module_idP,int frameP, sub_frame_t subfra } } +struct sort_ue_ul_params { + int module_idP; + int frameP; + int subframeP; +}; + +static int ue_ul_compare(const void *_a, const void *_b, void *_params) +{ + struct sort_ue_ul_params *params = _params; + UE_list_t *UE_list = &eNB_mac_inst[params->module_idP].UE_list; + + int UE_id1 = *(const int *)_a; + int UE_id2 = *(const int *)_b; + + int rnti1 = UE_RNTI(params->module_idP, UE_id1); + int pCCid1 = UE_PCCID(params->module_idP, UE_id1); + int round1 = maxround(params->module_idP, rnti1, params->frameP, params->subframeP, 1); + + int rnti2 = UE_RNTI(params->module_idP, UE_id2); + int pCCid2 = UE_PCCID(params->module_idP, UE_id2); + int round2 = maxround(params->module_idP, rnti2, params->frameP, params->subframeP, 1); + + if (round1 > round2) return -1; + if (round1 < round2) return 1; + + if (UE_list->UE_template[pCCid1][UE_id1].ul_buffer_info[LCGID0] > UE_list->UE_template[pCCid2][UE_id2].ul_buffer_info[LCGID0]) + return -1; + if (UE_list->UE_template[pCCid1][UE_id1].ul_buffer_info[LCGID0] < UE_list->UE_template[pCCid2][UE_id2].ul_buffer_info[LCGID0]) + return 1; + + if (UE_list->UE_template[pCCid1][UE_id1].ul_total_buffer > UE_list->UE_template[pCCid2][UE_id2].ul_total_buffer) + return -1; + if (UE_list->UE_template[pCCid1][UE_id1].ul_total_buffer < UE_list->UE_template[pCCid2][UE_id2].ul_total_buffer) + return 1; + + if (UE_list->UE_template[pCCid1][UE_id1].pre_assigned_mcs_ul > UE_list->UE_template[pCCid2][UE_id2].pre_assigned_mcs_ul) + return -1; + if (UE_list->UE_template[pCCid1][UE_id1].pre_assigned_mcs_ul < UE_list->UE_template[pCCid2][UE_id2].pre_assigned_mcs_ul) + return 1; + + return 0; + +#if 0 + /* The above order derives from the following. + * The last case is not handled: "if (UE_list->UE_template[pCCid2][UE_id2].ul_total_buffer > 0 )" + * I don't think it makes a big difference. + */ + if(round2 > round1) { + swap_UEs(UE_list,UE_id1,UE_id2,1); + } else if (round2 == round1) { + if (UE_list->UE_template[pCCid1][UE_id1].ul_buffer_info[LCGID0] < UE_list->UE_template[pCCid2][UE_id2].ul_buffer_info[LCGID0]) { + swap_UEs(UE_list,UE_id1,UE_id2,1); + } else if (UE_list->UE_template[pCCid1][UE_id1].ul_total_buffer < UE_list->UE_template[pCCid2][UE_id2].ul_total_buffer) { + swap_UEs(UE_list,UE_id1,UE_id2,1); + } else if (UE_list->UE_template[pCCid1][UE_id1].pre_assigned_mcs_ul < UE_list->UE_template[pCCid2][UE_id2].pre_assigned_mcs_ul) { + if (UE_list->UE_template[pCCid2][UE_id2].ul_total_buffer > 0 ) { + swap_UEs(UE_list,UE_id1,UE_id2,1); + } + } + } +#endif +} void sort_ue_ul (module_id_t module_idP,int frameP, sub_frame_t subframeP) { + int i; + int list[NUMBER_OF_UE_MAX]; + int list_size = 0; + int rnti; + struct sort_ue_ul_params params = { module_idP, frameP, subframeP }; + UE_list_t *UE_list = &eNB_mac_inst[module_idP].UE_list; + + for (i = 0; i < NUMBER_OF_UE_MAX; i++) { + rnti = UE_RNTI(module_idP, i); + if (rnti == NOT_A_RNTI) + continue; + if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) + continue; + if (!phy_stats_exist(module_idP, rnti)) + continue; + list[list_size] = i; + list_size++; + } + + qsort_r(list, list_size, sizeof(int), ue_ul_compare, ¶ms); + + if (list_size) { + for (i = 0; i < list_size-1; i++) + UE_list->next_ul[list[i]] = list[i+1]; + UE_list->next_ul[list[list_size-1]] = -1; + UE_list->head_ul = list[0]; + } else { + UE_list->head_ul = -1; + } + +#if 0 int UE_id1,UE_id2; int pCCid1,pCCid2; int round1,round2; @@ -1246,6 +1482,8 @@ void sort_ue_ul (module_id_t module_idP,int frameP, sub_frame_t subframeP) continue; if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) continue; + if (!phy_stats_exist(module_idP, rnti1)) + continue; pCCid1 = UE_PCCID(module_idP,UE_id1); round1 = maxround(module_idP,rnti1,frameP,subframeP,1); @@ -1257,6 +1495,8 @@ void sort_ue_ul (module_id_t module_idP,int frameP, sub_frame_t subframeP) continue; if (UE_list->UE_sched_ctrl[UE_id2].ul_out_of_sync == 1) continue; + if (!phy_stats_exist(module_idP, rnti2)) + continue; pCCid2 = UE_PCCID(module_idP,UE_id2); round2 = maxround(module_idP,rnti2,frameP,subframeP,1); @@ -1276,4 +1516,5 @@ void sort_ue_ul (module_id_t module_idP,int frameP, sub_frame_t subframeP) } } } +#endif } From a6219153d979c5f9e449e968ad478216fec99195 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Fri, 20 Jan 2017 15:47:08 +0100 Subject: [PATCH 18/19] check (to be reworked at some point) We put an abort() at this point in the code, because if the previous commit is correct, the program will never comme here. --- openair2/LAYER2/MAC/eNB_scheduler_ulsch.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c index d09111290d..3fd1ba6508 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c @@ -763,6 +763,8 @@ void schedule_ulsch_rnti(module_id_t module_idP, } } if (drop_ue == 1) { +/* we can't come here, ulsch_scheduler_pre_processor won't put in the list a UE with no PHY context */ +abort(); /* TODO: this is a hack. Sometimes the UE has no PHY context but * is still present in the MAC with 'ul_failure_timer' = 0 and * 'ul_out_of_sync' = 0. It seems wrong and the UE stays there forever. Let's From a0f19a726554794a87697f0114496f66e13319df Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Fri, 20 Jan 2017 15:48:49 +0100 Subject: [PATCH 19/19] add some printf for debug purpose (to be remove at some point) this commit is here to help debug the previous ones. It has to be reverted at some point. --- openair2/LAYER2/MAC/eNB_scheduler_RA.c | 4 ++++ openair2/LAYER2/MAC/eNB_scheduler_primitives.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c index e046c085e1..991f8bfbfa 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c @@ -710,7 +710,10 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un RA_template->RA_dci_size_bits2, RA_template->RA_dci_fmt2, 0); +printf("MAC: msg4 retransmission for rnti %x (round %d) fsf %d/%d\n", RA_template->rnti, round, frameP, subframeP); } +else +printf("MAC: msg4 retransmission for rnti %x (round %d) fsf %d/%d CCE allocation failed!\n", RA_template->rnti, round, frameP, subframeP); LOG_W(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Msg4 not acknowledged, adding ue specific dci (rnti %x) for RA (Msg4 Retransmission)\n", module_idP,CC_id,frameP,subframeP,RA_template->rnti); } else { @@ -719,6 +722,7 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un remove UE instance across all the layers: mac_xface->cancel_RA(); } */ +printf("MAC: msg4 acknowledged for rnti %x fsf %d/%d, let's configure it\n", RA_template->rnti, frameP, subframeP); LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d : Msg4 acknowledged\n",module_idP,CC_id,frameP,subframeP); RA_template->wait_ack_Msg4=0; RA_template->RA_active=FALSE; diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c index db204c7762..9dfd2f095b 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c @@ -243,6 +243,7 @@ int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP,int harq_pidP) for (i = 0; i < NUMBER_OF_UE_MAX; i++) { if (UE_list->active[i] == TRUE) continue; +printf("MAC: new UE id %d rnti %x\n", i, rntiP); UE_id = i; UE_list->UE_template[cc_idP][UE_id].rnti = rntiP; UE_list->UE_template[cc_idP][UE_id].configured = FALSE; @@ -267,6 +268,7 @@ int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP,int harq_pidP) return(UE_id); } +printf("MAC: cannot add new UE for rnti %x\n", rntiP); LOG_E(MAC,"error in add_new_ue(), could not find space in UE_list, Dumping UE list\n"); dump_ue_list(UE_list,0); return(-1); @@ -282,6 +284,7 @@ int rrc_mac_remove_ue(module_id_t mod_idP,rnti_t rntiP) int pCC_id; if (UE_id == -1) { +printf("MAC: cannot remove UE rnti %x\n", rntiP); LOG_W(MAC,"rrc_mac_remove_ue: UE %x not found\n", rntiP); mac_phy_remove_ue(mod_idP, rntiP); return 0; @@ -289,6 +292,7 @@ int rrc_mac_remove_ue(module_id_t mod_idP,rnti_t rntiP) pCC_id = UE_PCCID(mod_idP,UE_id); +printf("MAC: remove UE %d rnti %x\n", UE_id, rntiP); LOG_I(MAC,"Removing UE %d from Primary CC_id %d (rnti %x)\n",UE_id,pCC_id, rntiP); dump_ue_list(UE_list,0);