From 8ce73e5a7e16de89bfe78976434cbc7b3012edfa Mon Sep 17 00:00:00 2001 From: calvin wang Date: Tue, 27 Sep 2016 17:08:17 +0800 Subject: [PATCH 1/7] L2 stabilization BSR fertilization --- openair2/LAYER2/MAC/config.c | 23 +++ openair2/LAYER2/MAC/defs.h | 8 + openair2/LAYER2/MAC/extern.h | 2 + openair2/LAYER2/MAC/proto.h | 6 +- openair2/LAYER2/MAC/ue_procedures.c | 219 +++++++++++++++++++--------- openair2/LAYER2/MAC/vars.h | 9 ++ 6 files changed, 198 insertions(+), 69 deletions(-) diff --git a/openair2/LAYER2/MAC/config.c b/openair2/LAYER2/MAC/config.c index 2c5a0799d2..030ac7a9f3 100644 --- a/openair2/LAYER2/MAC/config.c +++ b/openair2/LAYER2/MAC/config.c @@ -76,6 +76,7 @@ void ue_mac_reset(module_id_t module_idP,uint8_t eNB_index) // cancel all pending SRs UE_mac_inst[module_idP].scheduling_info.SR_pending=0; UE_mac_inst[module_idP].scheduling_info.SR_COUNTER=0; + UE_mac_inst[module_idP].BSR_reporting_active=0; // stop ongoing RACH procedure @@ -235,10 +236,31 @@ rrc_mac_config_req( UE_mac_inst[Mod_idP].scheduling_info.sr_ProhibitTimer = (uint16_t) 0; } + if (mac_MainConfig->ext2 && mac_MainConfig->ext2->mac_MainConfig_v1020) { + if (mac_MainConfig->ext2->mac_MainConfig_v1020->extendedBSR_Sizes_r10) { + UE_mac_inst[Mod_idP].scheduling_info.extendedBSR_Sizes_r10 = (uint16_t) *mac_MainConfig->ext2->mac_MainConfig_v1020->extendedBSR_Sizes_r10; + } else { + UE_mac_inst[Mod_idP].scheduling_info.extendedBSR_Sizes_r10 = (uint16_t)0; + } + if (mac_MainConfig->ext2->mac_MainConfig_v1020->extendedPHR_r10) { + UE_mac_inst[Mod_idP].scheduling_info.extendedPHR_r10 = (uint16_t) *mac_MainConfig->ext2->mac_MainConfig_v1020->extendedPHR_r10; + } else { + UE_mac_inst[Mod_idP].scheduling_info.extendedPHR_r10 = (uint16_t)0; + } + } else { + UE_mac_inst[Mod_idP].scheduling_info.extendedBSR_Sizes_r10 = (uint16_t)0; + UE_mac_inst[Mod_idP].scheduling_info.extendedPHR_r10 = (uint16_t)0; + } #endif UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_SF = get_sf_periodicBSRTimer(UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_Timer); UE_mac_inst[Mod_idP].scheduling_info.retxBSR_SF = get_sf_retxBSRTimer(UE_mac_inst[Mod_idP].scheduling_info.retxBSR_Timer); + UE_mac_inst[Mod_idP].BSR_reporting_active = 0; + LOG_D(MAC,"[UE %d]: periodic BSR %d (SF), retx BSR %d (SF)\n", + Mod_idP, + UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_SF, + UE_mac_inst[Mod_idP].scheduling_info.retxBSR_SF); + UE_mac_inst[Mod_idP].scheduling_info.drx_config = mac_MainConfig->drx_Config; UE_mac_inst[Mod_idP].scheduling_info.phr_config = mac_MainConfig->phr_Config; @@ -259,6 +281,7 @@ rrc_mac_config_req( UE_mac_inst[Mod_idP].scheduling_info.periodicPHR_SF = get_sf_perioidicPHR_Timer(UE_mac_inst[Mod_idP].scheduling_info.periodicPHR_Timer); UE_mac_inst[Mod_idP].scheduling_info.prohibitPHR_SF = get_sf_prohibitPHR_Timer(UE_mac_inst[Mod_idP].scheduling_info.prohibitPHR_Timer); UE_mac_inst[Mod_idP].scheduling_info.PathlossChange_db = get_db_dl_PathlossChange(UE_mac_inst[Mod_idP].scheduling_info.PathlossChange); + UE_mac_inst[Mod_idP].PHR_reporting_active = 0; LOG_D(MAC,"[UE %d] config PHR (%d): periodic %d (SF) prohibit %d (SF) pathlosschange %d (db) \n", Mod_idP, (mac_MainConfig->phr_Config)?mac_MainConfig->phr_Config->present:-1, diff --git a/openair2/LAYER2/MAC/defs.h b/openair2/LAYER2/MAC/defs.h index 713c9d967c..4edfef1677 100644 --- a/openair2/LAYER2/MAC/defs.h +++ b/openair2/LAYER2/MAC/defs.h @@ -983,6 +983,12 @@ typedef struct { int16_t prohibitPHR_SF; ///DL Pathloss Change in db uint16_t PathlossChange_db; + + /// default value is false + uint16_t extendedBSR_Sizes_r10; + /// default value is false + uint16_t extendedPHR_r10; + //Bj bucket usage per lcid int16_t Bj[MAX_NUM_LCID]; // Bucket size per lcid @@ -1070,6 +1076,8 @@ typedef struct { uint8_t PHR_reporting_active; /// power backoff due to power management (as allowed by P-MPRc) for this cell uint8_t power_backoff_db[NUMBER_OF_eNB_MAX]; + /// BSR report falg management + uint8_t BSR_reporting_active; /// MBSFN_Subframe Configuration struct MBSFN_SubframeConfig *mbsfn_SubframeConfig[8]; // FIXME replace 8 by MAX_MBSFN_AREA? /// number of subframe allocation pattern available for MBSFN sync area diff --git a/openair2/LAYER2/MAC/extern.h b/openair2/LAYER2/MAC/extern.h index ca847acf4c..bb37a3766f 100644 --- a/openair2/LAYER2/MAC/extern.h +++ b/openair2/LAYER2/MAC/extern.h @@ -53,6 +53,8 @@ extern const uint32_t BSR_TABLE[BSR_TABLE_SIZE]; //extern uint32_t EBSR_Level[63]; +extern const uint32_t Extended_BSR_TABLE[BSR_TABLE_SIZE]; +//extern uint32_t Extended_BSR_TABLE[63]; ----currently not used extern UE_MAC_INST *UE_mac_inst; extern eNB_MAC_INST *eNB_mac_inst; diff --git a/openair2/LAYER2/MAC/proto.h b/openair2/LAYER2/MAC/proto.h index 9a0f60167d..4133d6a2eb 100644 --- a/openair2/LAYER2/MAC/proto.h +++ b/openair2/LAYER2/MAC/proto.h @@ -548,7 +548,7 @@ int cba_access(module_id_t module_idP,frame_t frameP,sub_frame_t subframe, uint8 \param[in] Mod_id instance of the UE \param[out] lcgid */ -int get_bsr_lcgid (module_id_t module_idP); +int get_bsr_lcgid (module_id_t module_idP, int *num_lcgid); /*! \fn uint8_t get_bsr_len (module_id_t module_idP,uint16_t bufflen); \brief determine whether the bsr is short or long assuming that the MAC pdu is built @@ -582,14 +582,14 @@ BSR_LONG * get_bsr_long(module_id_t module_idP, uint8_t bsr_len); */ boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_index, uint8_t lcid, uint8_t lcgid); -/*! \fn locate (int *table, int size, int value) +/*! \fn locate_BsrIndexByBufferSize (int *table, int size, int value) \brief locate the BSR level in the table as defined in 36.321. This function requires that he values in table to be monotonic, either increasing or decreasing. The returned value is not less than 0, nor greater than n-1, where n is the size of table. \param[in] *table Pointer to BSR table \param[in] size Size of the table \param[in] value Value of the buffer \return the index in the BSR_LEVEL table */ -uint8_t locate (const uint32_t *table, int size, int value); +uint8_t locate_BsrIndexByBufferSize (const uint32_t *table, int size, int value); /*! \fn int get_sf_periodicBSRTimer(uint8_t periodicBSR_Timer) diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c index 90d227eb35..6fc95f55d5 100644 --- a/openair2/LAYER2/MAC/ue_procedures.c +++ b/openair2/LAYER2/MAC/ue_procedures.c @@ -110,13 +110,17 @@ void ue_init_mac(module_id_t module_idP) UE_mac_inst[module_idP].scheduling_info.sr_ProhibitTimer_Running=0; UE_mac_inst[module_idP].scheduling_info.maxHARQ_Tx=MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5; UE_mac_inst[module_idP].scheduling_info.ttiBundling=0; + UE_mac_inst[module_idP].scheduling_info.extendedBSR_Sizes_r10=0; + UE_mac_inst[module_idP].scheduling_info.extendedPHR_r10=0; UE_mac_inst[module_idP].scheduling_info.drx_config=NULL; UE_mac_inst[module_idP].scheduling_info.phr_config=NULL; UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF = get_sf_periodicBSRTimer(UE_mac_inst[module_idP].scheduling_info.periodicBSR_Timer); UE_mac_inst[module_idP].scheduling_info.retxBSR_SF = get_sf_retxBSRTimer(UE_mac_inst[module_idP].scheduling_info.retxBSR_Timer); + UE_mac_inst[module_idP].BSR_reporting_active = 0; UE_mac_inst[module_idP].scheduling_info.periodicPHR_SF = get_sf_perioidicPHR_Timer(UE_mac_inst[module_idP].scheduling_info.periodicPHR_Timer); UE_mac_inst[module_idP].scheduling_info.prohibitPHR_SF = get_sf_prohibitPHR_Timer(UE_mac_inst[module_idP].scheduling_info.prohibitPHR_Timer); UE_mac_inst[module_idP].scheduling_info.PathlossChange_db = get_db_dl_PathlossChange(UE_mac_inst[module_idP].scheduling_info.PathlossChange); + UE_mac_inst[module_idP].PHR_reporting_active = 0; for (i=0; i < MAX_NUM_LCID; i++) { LOG_D(MAC,"[UE%d] Applying default logical channel config for LCGID %d\n",module_idP,i); @@ -296,18 +300,28 @@ uint32_t ue_get_SR(module_id_t module_idP,int CC_id,frame_t frameP,uint8_t eNB_i // initiate RA UE_mac_inst[module_idP].scheduling_info.SR_pending=0; UE_mac_inst[module_idP].scheduling_info.SR_COUNTER=0; + // release all pucch resource + UE_mac_inst[module_idP].physicalConfigDedicated = NULL; + UE_mac_inst[module_idP].ul_active=0; + UE_mac_inst[module_idP].BSR_reporting_active=0; + + LOG_T(MAC,"[UE %d] Release all SRs \n", module_idP); return(0); } } //------------------------------------------------------------------------------ void -ue_send_sdu(module_id_t module_idP, - uint8_t CC_id, - frame_t frameP, - uint8_t* sdu, - uint16_t sdu_len, - uint8_t eNB_index) { +ue_send_sdu( + module_id_t module_idP, + uint8_t CC_id, + frame_t frameP, + uint8_t* sdu, + uint16_t sdu_len, + uint8_t eNB_index +) +//------------------------------------------------------------------------------ +{ unsigned char rx_ces[MAX_NUM_CE],num_ce,num_sdu,i,*payload_ptr; unsigned char rx_lcids[NB_RB_MAX]; @@ -1188,17 +1202,20 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf uint8_t payload_offset=0,num_sdus=0; uint8_t ulsch_buff[MAX_ULSCH_PAYLOAD_BYTES]; uint16_t sdu_length_total=0; - BSR_SHORT bsr_short; + BSR_SHORT bsr_short,bsr_truncated; BSR_LONG bsr_long; BSR_SHORT *bsr_s=&bsr_short; + BSR_SHORT *bsr_t=&bsr_truncated; BSR_LONG *bsr_l=&bsr_long; POWER_HEADROOM_CMD phr; POWER_HEADROOM_CMD *phr_p=&phr; - unsigned short short_padding=0, post_padding=0; + unsigned short short_padding=0, post_padding=0, padding_len=0; int lcgid; int j; // used for padding // Compute header length - + int all_pdu_len; + int num_lcgid=0; + if (CC_id>0) { LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n"); mac_xface->macphy_exit("MAC FATAL CC_id>0"); @@ -1243,8 +1260,8 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf } bsr_ce_len = get_bsr_len (module_idP, buflen-phr_len); - - if (bsr_ce_len > 0 ) { + // retxBSR-Timer expires or periodicBSR-Timer expires and UE has data available for transmission + if ((bsr_ce_len > 0 ) && (UE_mac_inst[module_idP].BSR_reporting_active > 0)) { bsr_len = bsr_ce_len + bsr_header_len; LOG_D(MAC,"[UE %d] header size info: dcch %d, dcch1 %d, dtch %d, bsr (ce%d,hdr%d) buff_len %d\n", module_idP, dcch_header_len,dcch1_header_len,dtch_header_len, bsr_ce_len, bsr_header_len, buflen); @@ -1338,8 +1355,9 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf dtch_header_len+=3; dtch_header_len_last=3; + all_pdu_len = bsr_len+phr_len+dcch_header_len+dcch1_header_len+dtch_header_len+sdu_length_total; if ((UE_mac_inst[module_idP].scheduling_info.LCID_status[lcid] == LCID_NOT_EMPTY) && - ((bsr_len+phr_len+dcch_header_len+dcch1_header_len+dtch_header_len+sdu_length_total) <= buflen)) { + (all_pdu_len <= buflen)) { // optimize the dtch header lenght //if ((UE_mac_inst[module_idP].scheduling_info.BSR_bytes[DTCH] > 128) && @@ -1357,7 +1375,7 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf ENB_FLAG_NO, MBMS_FLAG_NO, // eNB_index lcid, - buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-dtch_header_len-sdu_length_total); + buflen-all_pdu_len); LOG_D(MAC,"[UE %d] Frame %d : UL-DTCH -> ULSCH%d, %d bytes to send (Transport Block size %d, mac header len %d, BSR byte[%d] %d)\n", module_idP,frameP, lcid, rlc_status.bytes_in_buffer,buflen,dtch_header_len, @@ -1390,31 +1408,54 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf dtch_header_len -= 3; } } - - lcgid= get_bsr_lcgid(module_idP); - if (lcgid < 0 ) { + lcgid= get_bsr_lcgid(module_idP, &num_lcgid); + + if (num_lcgid == 0 ) { bsr_s = NULL; - bsr_l = NULL ; - } else if ((lcgid ==MAX_NUM_LCGID) && (bsr_ce_len == sizeof(BSR_LONG))) { - bsr_s = NULL; - bsr_l->Buffer_size0 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0]; - bsr_l->Buffer_size1 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1]; - bsr_l->Buffer_size2 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2]; - bsr_l->Buffer_size3 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3]; - LOG_D(MAC, "[UE %d] Frame %d report long BSR (level LCGID0 %d,level LCGID1 %d,level LCGID2 %d,level LCGID3 %d)\n", module_idP,frameP, - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0], - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1], - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2], - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3]); - } else if (bsr_ce_len == sizeof(BSR_SHORT)) { + bsr_t = NULL; bsr_l = NULL; - bsr_s->LCGID = lcgid; - bsr_s->Buffer_size = UE_mac_inst[module_idP].scheduling_info.BSR[lcgid]; - LOG_D(MAC,"[UE %d] Frame %d report SHORT BSR with level %d for LCGID %d\n", + } else if (num_lcgid == 1){ + if (bsr_ce_len == sizeof(BSR_SHORT)){ + bsr_l = NULL; + bsr_t = NULL; + bsr_s->LCGID = lcgid; + bsr_s->Buffer_size = UE_mac_inst[module_idP].scheduling_info.BSR[lcgid]; + LOG_D(MAC,"[UE %d] Frame %d report SHORT BSR with level %d for LCGID %d\n", + module_idP, frameP, UE_mac_inst[module_idP].scheduling_info.BSR[lcgid],lcgid); + } else { + bsr_s = NULL; + bsr_t = NULL; + bsr_l = NULL; + } + } else if (num_lcgid > 1) { + if (bsr_ce_len == sizeof(BSR_LONG)){ + bsr_t = NULL; + bsr_s = NULL; + bsr_l->Buffer_size0 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0]; + bsr_l->Buffer_size1 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1]; + bsr_l->Buffer_size2 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2]; + bsr_l->Buffer_size3 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3]; + LOG_D(MAC, "[UE %d] Frame %d report long BSR (level LCGID0 %d,level LCGID1 %d,level LCGID2 %d,level LCGID3 %d)\n", module_idP,frameP, + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0], + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1], + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2], + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3]); + } else if (bsr_ce_len == sizeof(BSR_SHORT)){ + bsr_l = NULL; + bsr_s = NULL; + bsr_t->LCGID = lcgid; + bsr_s->Buffer_size = UE_mac_inst[module_idP].scheduling_info.BSR[lcgid]; + LOG_D(MAC,"[UE %d] Frame %d report SHORT BSR with level %d for LCGID %d\n", module_idP, frameP, UE_mac_inst[module_idP].scheduling_info.BSR[lcgid],lcgid); + } else { + bsr_s = NULL; + bsr_t = NULL; + bsr_l = NULL; + } } else { bsr_s = NULL; + bsr_t = NULL; bsr_l = NULL; } @@ -1444,12 +1485,14 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf dtch_header_len_last-=1; dtch_header_len= (dtch_header_len >0)? dtch_header_len - dtch_header_len_last : dtch_header_len; } - - if ((buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-dtch_header_len-sdu_length_total) <= 2) { - short_padding = buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-dtch_header_len-sdu_length_total; + // 1-bit padding or 2-bit padding special padding subheader + padding_len = buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-dtch_header_len-sdu_length_total; + if (padding_len <= 2) { + short_padding = padding_len; + // only add padding header post_padding = 0; } else { - if ((buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-dtch_header_len-sdu_length_total) == buflen) { + if (padding_len == buflen) {// nona mac pdu *access_mode=CANCELED_ACCESS; } @@ -1474,7 +1517,7 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf sdu_lcids, // sdu lcid phr_p, // power headroom NULL, // crnti - NULL, // truncated bsr + bsr_t, // truncated bsr bsr_s, // short bsr bsr_l, post_padding); // long_bsr @@ -1494,6 +1537,9 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf module_idP,payload_offset, sdu_length_total); UE_mac_inst[module_idP].scheduling_info.SR_pending=0; UE_mac_inst[module_idP].scheduling_info.SR_COUNTER=0; + UE_mac_inst[module_idP].BSR_reporting_active=0; + UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF = get_sf_periodicBSRTimer(UE_mac_inst[module_idP].scheduling_info.periodicBSR_Timer); + UE_mac_inst[module_idP].scheduling_info.retxBSR_SF = get_sf_retxBSRTimer(UE_mac_inst[module_idP].scheduling_info.retxBSR_Timer); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_GET_SDU, VCD_FUNCTION_OUT); stop_meas(&UE_mac_inst[module_idP].tx_ulsch_sdu); @@ -1655,7 +1701,22 @@ ue_scheduler( // call SR procedure to generate pending SR and BSR for next PUCCH/PUSCH TxOp. This should implement the procedures // outlined in Sections 5.4.4 an 5.4.5 of 36.321 - // Put this in another function + // Call BSR procedure as described in Section 5.4.5 in 36.321 + if (UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF == get_sf_periodicBSRTimer(MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_infinity)) { + UE_mac_inst[module_idP].BSR_reporting_active = 1; + } else if (UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF <= 0 ){ + // trigger BSR and reset the timer later when the BSR report is sent + UE_mac_inst[module_idP].BSR_reporting_active = 1; + } else if (UE_mac_inst[module_idP].BSR_reporting_active == 0 ) { + UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF--; + } + + if (UE_mac_inst[module_idP].scheduling_info.retxBSR_SF <= 0){ + // trigger BSR and reset the timer later when the BSR report is sent + UE_mac_inst[module_idP].BSR_reporting_active = 1; + } else if (UE_mac_inst[module_idP].BSR_reporting_active == 0 ) { + UE_mac_inst[module_idP].scheduling_info.retxBSR_SF--; + } // Get RLC status info and update Bj for all lcids that are active for (lcid=DCCH; lcid <= DTCH; lcid++ ) { @@ -1899,54 +1960,75 @@ int cba_access(module_id_t module_idP,frame_t frameP,sub_frame_t subframe, uint8 } #endif -int get_bsr_lcgid (module_id_t module_idP) +int get_bsr_lcgid (module_id_t module_idP, int *num_lcgid) { int lcgid, lcgid_tmp=-1; int num_active_lcgid = 0; for (lcgid = 0 ; lcgid < MAX_NUM_LCGID; lcgid++) { if (UE_mac_inst[module_idP].scheduling_info.BSR[lcgid] > 0 ) { - lcgid_tmp = lcgid; + if (lcgid_tmp == -1){ + // first priority lcgid + lcgid_tmp = lcgid; + } num_active_lcgid+=1; } } - + *num_lcgid = num_active_lcgid; + if (num_active_lcgid == 0) { - return -1; - } else if (num_active_lcgid == 1) { - return lcgid_tmp; + return -1; // no data } else { - return MAX_NUM_LCGID; + return lcgid_tmp;//only one lcgid, report short bsr } } uint8_t get_bsr_len (module_id_t module_idP, uint16_t buflen) { - int lcgid=0; uint8_t bsr_len=0, num_lcgid=0; int pdu = 0; + int long_bsr_plus_subheader_length = sizeof(BSR_LONG)+sizeof(SCH_SUBHEADER_FIXED); + int short_bsr_plus_subheader_length = sizeof(BSR_SHORT)+sizeof(SCH_SUBHEADER_FIXED); - + // check how many lcg have data to report for (lcgid=0; lcgid < MAX_NUM_LCGID; lcgid++ ) { if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] > 0 ) { - pdu += (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] + bsr_len + 2); //2 = sizeof(SCH_SUBHEADER_SHORT) + num_lcgid ++; + pdu += (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] + sizeof(SCH_SUBHEADER_SHORT)); } - if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] > 128 ) { // long header size: adjust the header size pdu += 1; } - - // current phy buff can not transport all sdu for this lcgid -> transmit a bsr for this lcgid - - if ( (pdu > buflen) && (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] > 0 ) ) { - num_lcgid +=1; - bsr_len = (num_lcgid >= 2 ) ? sizeof(BSR_LONG) : sizeof(BSR_SHORT) ; + LOG_D(MAC,"BSR Bytes %d for lcgid %d num lcgid %d\n", UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid], lcgid, num_lcgid); + } + // current phy buff can not transport all sdu for this lcgid -> transmit a bsr for this lcgid + if (buflen < pdu) { + if (num_lcgid > 0) { + bsr_len = sizeof(BSR_SHORT); + } else { + bsr_len = 0; } - - LOG_D(MAC,"BSR Bytes %d for lcgid %d bsr len %d num lcgid %d\n", UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid], lcgid, bsr_len, num_lcgid); + } + // padding larger then long bsr + if (buflen > (pdu + long_bsr_plus_subheader_length)) { + if (num_lcgid > 1) { + bsr_len = sizeof(BSR_LONG); + } else if (num_lcgid > 0) { + bsr_len = sizeof(BSR_SHORT); + } else { + bsr_len = 0; + } + } + // padding larger then short bsr and shorter then long bsr + if ((buflen < (pdu + long_bsr_plus_subheader_length)) && + (buflen > (pdu + short_bsr_plus_subheader_length))) { + if (num_lcgid > 0) { + bsr_len = sizeof(BSR_SHORT); + } else { + bsr_len = 0; + } } - if ( bsr_len > 0 ) LOG_D(MAC,"[UE %d] Prepare a %s (Transport Block Size %d, MAC pdu Size %d) \n", module_idP, map_int_to_str(BSR_names, bsr_len), buflen, pdu); @@ -1959,11 +2041,11 @@ boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_in { mac_rlc_status_resp_t rlc_status; - boolean_t sr_pending = FALSE; + boolean_t Bsr_pending = FALSE; if ((lcg_id < 0) || (lcg_id >= MAX_NUM_LCGID) ) { - return sr_pending; + return Bsr_pending; } // fixme: need a better way to reset @@ -1979,10 +2061,15 @@ boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_in 0); if (rlc_status.bytes_in_buffer > 0 ) { - sr_pending = TRUE; + //BSR trigger SR + Bsr_pending = TRUE; UE_mac_inst[module_idP].scheduling_info.LCID_status[lcid] = LCID_NOT_EMPTY; - UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id] += locate (BSR_TABLE,BSR_TABLE_SIZE, rlc_status.bytes_in_buffer); - UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id] += rlc_status.bytes_in_buffer; + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id] = rlc_status.bytes_in_buffer; + if (UE_mac_inst[module_idP].scheduling_info.extendedBSR_Sizes_r10 == TRUE){ + UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id] = locate_BsrIndexByBufferSize(Extended_BSR_TABLE, BSR_TABLE_SIZE, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id]); + } else { + UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id] = locate_BsrIndexByBufferSize(BSR_TABLE, BSR_TABLE_SIZE, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id]); + } // UE_mac_inst[module_idP].scheduling_info.BSR_short_lcid = lcid; // only applicable to short bsr LOG_D(MAC,"[UE %d] BSR level %d (LCGID %d, rlc buffer %d byte)\n", module_idP, UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id],lcg_id, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id]); @@ -1992,10 +2079,10 @@ boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_in } //} - return sr_pending; + return Bsr_pending; } -uint8_t locate (const uint32_t *table, int size, int value) +uint8_t locate_BsrIndexByBufferSize (const uint32_t *table, int size, int value) { uint8_t ju, jm, jl; @@ -2026,7 +2113,7 @@ uint8_t locate (const uint32_t *table, int size, int value) if (value == table[jl]) { return jl; - } else { + } else { return jl+1; //equally ju } diff --git a/openair2/LAYER2/MAC/vars.h b/openair2/LAYER2/MAC/vars.h index 508c7f8c21..3020706815 100644 --- a/openair2/LAYER2/MAC/vars.h +++ b/openair2/LAYER2/MAC/vars.h @@ -52,6 +52,15 @@ const uint32_t BSR_TABLE[BSR_TABLE_SIZE]= {0,10,12,14,17,19,22,26,31,36,42,49,57 1326,1552,1817,2127,2490,2915,3413,3995,4677,5467,6411,7505,8787,10287,12043,14099, 16507,19325,22624,26487,31009,36304,42502,49759,58255,68201,79846,93479,109439, 128125,150000, 300000 }; +// extended bsr table--currently not used +const uint32_t Extended_BSR_TABLE[BSR_TABLE_SIZE] = {0,10,13,16,19,23,29,35,43,53,65,80,98,120,147, + 181,223,274,337,414,509,625,769,945,1162,1429, + 1757,2161,2657,3267,4017,4940,6074,7469,9185, + 11294,13888,17077,20999,25822,31752,39045,48012, + 59039,72598,89272,109774,134986,165989,204111, + 250990,308634,379519,466683,573866,705666,867737, + 1067031,1312097,1613447,1984009,2439678,3000000, + 6000000}; //uint32_t EBSR_Level[63]={0,10,13,16,19,23,29,35,43,53,65,80,98,120,147,181}; From 948f2df9f1b00805f30ff0858c3d2ee9bd485a31 Mon Sep 17 00:00:00 2001 From: calvin wang Date: Fri, 21 Oct 2016 18:26:50 +0800 Subject: [PATCH 2/7] modify BSR code according comments --- openair2/LAYER2/MAC/config.c | 2 +- openair2/LAYER2/MAC/defs.h | 2 +- openair2/LAYER2/MAC/proto.h | 4 +- openair2/LAYER2/MAC/ra_procedures.c | 2 +- openair2/LAYER2/MAC/ue_procedures.c | 206 ++++++++++++---------------- 5 files changed, 90 insertions(+), 126 deletions(-) diff --git a/openair2/LAYER2/MAC/config.c b/openair2/LAYER2/MAC/config.c index 030ac7a9f3..90889d6381 100644 --- a/openair2/LAYER2/MAC/config.c +++ b/openair2/LAYER2/MAC/config.c @@ -233,7 +233,7 @@ rrc_mac_config_req( if (mac_MainConfig->ext1 && mac_MainConfig->ext1->sr_ProhibitTimer_r9) { UE_mac_inst[Mod_idP].scheduling_info.sr_ProhibitTimer = (uint16_t) *mac_MainConfig->ext1->sr_ProhibitTimer_r9; } else { - UE_mac_inst[Mod_idP].scheduling_info.sr_ProhibitTimer = (uint16_t) 0; + UE_mac_inst[Mod_idP].scheduling_info.sr_ProhibitTimer = 0; } if (mac_MainConfig->ext2 && mac_MainConfig->ext2->mac_MainConfig_v1020) { diff --git a/openair2/LAYER2/MAC/defs.h b/openair2/LAYER2/MAC/defs.h index 4edfef1677..8f0d4f5951 100644 --- a/openair2/LAYER2/MAC/defs.h +++ b/openair2/LAYER2/MAC/defs.h @@ -941,7 +941,7 @@ typedef enum { typedef struct { /// buffer status for each lcgid uint8_t BSR[MAX_NUM_LCGID]; // should be more for mesh topology - /// keep the number of bytes in rlc buffer for each lcid + /// keep the number of bytes in rlc buffer for each lcgid uint16_t BSR_bytes[MAX_NUM_LCGID]; /// buffer status for each lcid uint8_t LCID_status[MAX_NUM_LCID]; diff --git a/openair2/LAYER2/MAC/proto.h b/openair2/LAYER2/MAC/proto.h index 4133d6a2eb..0bc3eb00ec 100644 --- a/openair2/LAYER2/MAC/proto.h +++ b/openair2/LAYER2/MAC/proto.h @@ -548,7 +548,7 @@ int cba_access(module_id_t module_idP,frame_t frameP,sub_frame_t subframe, uint8 \param[in] Mod_id instance of the UE \param[out] lcgid */ -int get_bsr_lcgid (module_id_t module_idP, int *num_lcgid); +int get_bsr_lcgid (module_id_t module_idP); /*! \fn uint8_t get_bsr_len (module_id_t module_idP,uint16_t bufflen); \brief determine whether the bsr is short or long assuming that the MAC pdu is built @@ -556,7 +556,7 @@ int get_bsr_lcgid (module_id_t module_idP, int *num_lcgid); \param[in] bufflen size of phy transport block \param[out] bsr_len size of bsr control element */ -uint8_t get_bsr_len (module_id_t module_idP, uint16_t buflen); +uint8_t get_bsr_len (module_id_t module_idP, uint8_t eNB_index,frame_t frameP,uint16_t buflen); /*! \fn BSR_SHORT * get_bsr_short(module_id_t module_idP, uint8_t bsr_len) \brief get short bsr level diff --git a/openair2/LAYER2/MAC/ra_procedures.c b/openair2/LAYER2/MAC/ra_procedures.c index 669077bf4f..e60dfc6292 100644 --- a/openair2/LAYER2/MAC/ra_procedures.c +++ b/openair2/LAYER2/MAC/ra_procedures.c @@ -399,7 +399,7 @@ PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP,int CC_id,frame_t frameP, 1); //post_padding return(&UE_mac_inst[module_idP].RA_prach_resources); - } else if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[DCCH] > 0) { + } else if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH]] > 0) { // This is for triggering a transmission on DCCH using PRACH (during handover, or sending SR for example) dcch_header_len = 2 + 2; /// SHORT Subheader + C-RNTI control element rlc_status = mac_rlc_status_ind(module_idP,UE_mac_inst[module_idP].crnti, eNB_indexP,frameP,ENB_FLAG_NO,MBMS_FLAG_NO, diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c index 6fc95f55d5..97b7e433c4 100644 --- a/openair2/LAYER2/MAC/ue_procedures.c +++ b/openair2/LAYER2/MAC/ue_procedures.c @@ -133,7 +133,7 @@ void ue_init_mac(module_id_t module_idP) UE_mac_inst[module_idP].scheduling_info.LCGID[i]=1; } - UE_mac_inst[module_idP].scheduling_info.LCID_status[i]=0; + UE_mac_inst[module_idP].scheduling_info.LCID_status[i]=LCID_EMPTY; } #ifdef CBA @@ -1202,10 +1202,9 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf uint8_t payload_offset=0,num_sdus=0; uint8_t ulsch_buff[MAX_ULSCH_PAYLOAD_BYTES]; uint16_t sdu_length_total=0; - BSR_SHORT bsr_short,bsr_truncated; + BSR_SHORT bsr_short; BSR_LONG bsr_long; BSR_SHORT *bsr_s=&bsr_short; - BSR_SHORT *bsr_t=&bsr_truncated; BSR_LONG *bsr_l=&bsr_long; POWER_HEADROOM_CMD phr; POWER_HEADROOM_CMD *phr_p=&phr; @@ -1214,7 +1213,6 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf int j; // used for padding // Compute header length int all_pdu_len; - int num_lcgid=0; if (CC_id>0) { LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n"); @@ -1249,18 +1247,9 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf dtch_header_len=(buflen > 128 ) ? 3 : 2 ; //sizeof(SCH_SUBHEADER_LONG)-1 : sizeof(SCH_SUBHEADER_SHORT); bsr_header_len = 1;//sizeof(SCH_SUBHEADER_FIXED); phr_header_len = 1;//sizeof(SCH_SUBHEADER_FIXED); - phr_ce_len = (UE_mac_inst[module_idP].PHR_reporting_active == 1) ? 1 /* sizeof(POWER_HEADROOM_CMD)*/: 0; - if (phr_ce_len > 0) { - phr_len = phr_ce_len + phr_header_len; - LOG_D(MAC,"[UE %d] header size info: PHR len %d (ce%d,hdr%d) buff_len %d\n", - module_idP, phr_len, phr_ce_len, phr_header_len, buflen); - } else { - phr_len=0; - } - - bsr_ce_len = get_bsr_len (module_idP, buflen-phr_len); - // retxBSR-Timer expires or periodicBSR-Timer expires and UE has data available for transmission + bsr_ce_len = get_bsr_len (module_idP, eNB_index, frameP, buflen); + // retxBSR-Timer expires or periodicBSR-Timer expires and Regular BSR trigger if ((bsr_ce_len > 0 ) && (UE_mac_inst[module_idP].BSR_reporting_active > 0)) { bsr_len = bsr_ce_len + bsr_header_len; LOG_D(MAC,"[UE %d] header size info: dcch %d, dcch1 %d, dtch %d, bsr (ce%d,hdr%d) buff_len %d\n", @@ -1272,6 +1261,15 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf //bsr_len = bsr_ce_len + bsr_header_len; } + phr_ce_len = (UE_mac_inst[module_idP].PHR_reporting_active == 1) ? 1 /* sizeof(POWER_HEADROOM_CMD)*/: 0; + if (phr_ce_len > 0) { + phr_len = phr_ce_len + phr_header_len; + LOG_D(MAC,"[UE %d] header size info: PHR len %d (ce%d,hdr%d) buff_len %d\n", + module_idP, phr_len, phr_ce_len, phr_header_len, buflen); + } else { + phr_len=0; + } + // check for UL bandwidth requests and add SR control element // check for UL bandwidth requests and add SR control element @@ -1305,8 +1303,9 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf sdu_lcids[0] = DCCH; LOG_D(MAC,"[UE %d] TX Got %d bytes for DCCH\n",module_idP,sdu_lengths[0]); num_sdus = 1; - update_bsr(module_idP, frameP, eNB_index, DCCH, UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH]); + //update_bsr(module_idP, frameP, eNB_index, DCCH, UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH]); //header_len +=2; + UE_mac_inst[module_idP].scheduling_info.LCID_status[DCCH] = LCID_EMPTY; } else { dcch_header_len=0; num_sdus = 0; @@ -1345,6 +1344,7 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf num_sdus++; //update_bsr(module_idP, frameP, DCCH1); //dcch_header_len +=2; // include dcch1 + UE_mac_inst[module_idP].scheduling_info.LCID_status[DCCH1] = LCID_EMPTY; } else { dcch1_header_len =0; } @@ -1379,7 +1379,7 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf LOG_D(MAC,"[UE %d] Frame %d : UL-DTCH -> ULSCH%d, %d bytes to send (Transport Block size %d, mac header len %d, BSR byte[%d] %d)\n", module_idP,frameP, lcid, rlc_status.bytes_in_buffer,buflen,dtch_header_len, - lcid, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcid]); + lcid, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]]); if (rlc_status.bytes_in_buffer > 0) { sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP, @@ -1400,62 +1400,54 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf dtch_header_len_last --; } num_sdus++; - UE_mac_inst[module_idP].ul_active = update_bsr(module_idP, frameP, eNB_index,lcid, UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]); + //UE_mac_inst[module_idP].ul_active = update_bsr(module_idP, frameP, eNB_index,lcid, UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]); } else { dtch_header_len -= 3; } + UE_mac_inst[module_idP].scheduling_info.LCID_status[lcid] = LCID_EMPTY; } else { // no rlc pdu : generate the dummy header dtch_header_len -= 3; } } - lcgid= get_bsr_lcgid(module_idP, &num_lcgid); + lcgid= get_bsr_lcgid(module_idP); - if (num_lcgid == 0 ) { + if (lcgid < 0 ) { bsr_s = NULL; - bsr_t = NULL; + bsr_l = NULL ; + } else if ((lcgid ==MAX_NUM_LCGID) && (bsr_ce_len == sizeof(BSR_LONG))) { + bsr_s = NULL; + bsr_l->Buffer_size0 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0]; + bsr_l->Buffer_size1 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1]; + bsr_l->Buffer_size2 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2]; + bsr_l->Buffer_size3 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3]; + + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[LCGID0] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[LCGID1] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[LCGID2] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[LCGID3] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3] = 0; + + LOG_D(MAC, "[UE %d] Frame %d report long BSR (level LCGID0 %d,level LCGID1 %d,level LCGID2 %d,level LCGID3 %d)\n", module_idP,frameP, + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0], + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1], + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2], + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3]); + } else if (bsr_ce_len == sizeof(BSR_SHORT)) { bsr_l = NULL; - } else if (num_lcgid == 1){ - if (bsr_ce_len == sizeof(BSR_SHORT)){ - bsr_l = NULL; - bsr_t = NULL; - bsr_s->LCGID = lcgid; - bsr_s->Buffer_size = UE_mac_inst[module_idP].scheduling_info.BSR[lcgid]; - LOG_D(MAC,"[UE %d] Frame %d report SHORT BSR with level %d for LCGID %d\n", - module_idP, frameP, UE_mac_inst[module_idP].scheduling_info.BSR[lcgid],lcgid); - } else { - bsr_s = NULL; - bsr_t = NULL; - bsr_l = NULL; - } - } else if (num_lcgid > 1) { - if (bsr_ce_len == sizeof(BSR_LONG)){ - bsr_t = NULL; - bsr_s = NULL; - bsr_l->Buffer_size0 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0]; - bsr_l->Buffer_size1 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1]; - bsr_l->Buffer_size2 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2]; - bsr_l->Buffer_size3 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3]; - LOG_D(MAC, "[UE %d] Frame %d report long BSR (level LCGID0 %d,level LCGID1 %d,level LCGID2 %d,level LCGID3 %d)\n", module_idP,frameP, - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0], - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1], - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2], - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3]); - } else if (bsr_ce_len == sizeof(BSR_SHORT)){ - bsr_l = NULL; - bsr_s = NULL; - bsr_t->LCGID = lcgid; - bsr_s->Buffer_size = UE_mac_inst[module_idP].scheduling_info.BSR[lcgid]; - LOG_D(MAC,"[UE %d] Frame %d report SHORT BSR with level %d for LCGID %d\n", + bsr_s->LCGID = lcgid; + bsr_s->Buffer_size = UE_mac_inst[module_idP].scheduling_info.BSR[lcgid]; + + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR[lcgid] = 0; + + LOG_D(MAC,"[UE %d] Frame %d report SHORT BSR with level %d for LCGID %d\n", module_idP, frameP, UE_mac_inst[module_idP].scheduling_info.BSR[lcgid],lcgid); - } else { - bsr_s = NULL; - bsr_t = NULL; - bsr_l = NULL; - } } else { bsr_s = NULL; - bsr_t = NULL; bsr_l = NULL; } @@ -1517,7 +1509,7 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf sdu_lcids, // sdu lcid phr_p, // power headroom NULL, // crnti - bsr_t, // truncated bsr + NULL, // truncated bsr bsr_s, // short bsr bsr_l, post_padding); // long_bsr @@ -1719,7 +1711,7 @@ ue_scheduler( } // Get RLC status info and update Bj for all lcids that are active - for (lcid=DCCH; lcid <= DTCH; lcid++ ) { + for (lcid=DCCH; lcid < MAX_NUM_LCID; lcid++ ) { if ((lcid == 0) ||(UE_mac_inst[module_idP].logicalChannelConfig[lcid])) { // meausre the Bj if ((directionP == SF_UL)&& (UE_mac_inst[module_idP].scheduling_info.Bj[lcid] >= 0)) { @@ -1740,6 +1732,8 @@ ue_scheduler( if (update_bsr(module_idP,frameP, eNB_indexP, lcid, UE_mac_inst[module_idP].scheduling_info.LCGID[lcid])) { UE_mac_inst[module_idP].scheduling_info.SR_pending= 1; + // Regular BSR trigger + UE_mac_inst[module_idP].BSR_reporting_active = 1; LOG_D(MAC,"[UE %d][SR] Frame %d subframe %d SR for PUSCH is pending for LCGID %d with BSR level %d (%d bytes in RLC)\n", module_idP, frameP,subframeP,UE_mac_inst[module_idP].scheduling_info.LCGID[lcid], UE_mac_inst[module_idP].scheduling_info.BSR[UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]], @@ -1960,75 +1954,49 @@ int cba_access(module_id_t module_idP,frame_t frameP,sub_frame_t subframe, uint8 } #endif -int get_bsr_lcgid (module_id_t module_idP, int *num_lcgid) +int get_bsr_lcgid (module_id_t module_idP) { int lcgid, lcgid_tmp=-1; int num_active_lcgid = 0; for (lcgid = 0 ; lcgid < MAX_NUM_LCGID; lcgid++) { if (UE_mac_inst[module_idP].scheduling_info.BSR[lcgid] > 0 ) { - if (lcgid_tmp == -1){ - // first priority lcgid - lcgid_tmp = lcgid; - } + lcgid_tmp = lcgid; num_active_lcgid+=1; } } - *num_lcgid = num_active_lcgid; - + if (num_active_lcgid == 0) { - return -1; // no data + return -1; + } else if (num_active_lcgid == 1) { + return lcgid_tmp; } else { - return lcgid_tmp;//only one lcgid, report short bsr + return MAX_NUM_LCGID; } } -uint8_t get_bsr_len (module_id_t module_idP, uint16_t buflen) +uint8_t get_bsr_len (module_id_t module_idP, uint8_t eNB_index,frame_t frameP,uint16_t buflen) { - int lcgid=0; - uint8_t bsr_len=0, num_lcgid=0; + int lcid; + uint8_t bsr_len=0, num_lcid=0; int pdu = 0; - int long_bsr_plus_subheader_length = sizeof(BSR_LONG)+sizeof(SCH_SUBHEADER_FIXED); - int short_bsr_plus_subheader_length = sizeof(BSR_SHORT)+sizeof(SCH_SUBHEADER_FIXED); + mac_rlc_status_resp_t rlc_status; - // check how many lcg have data to report - for (lcgid=0; lcgid < MAX_NUM_LCGID; lcgid++ ) { - if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] > 0 ) { - num_lcgid ++; - pdu += (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] + sizeof(SCH_SUBHEADER_SHORT)); + for (lcid=DCCH; lcid 0 ) { + pdu += rlc_status.bytes_in_buffer + sizeof(SCH_SUBHEADER_SHORT) + bsr_len; + if (rlc_status.bytes_in_buffer > 128 ) { + pdu += 1; //sizeof(SCH_SUBHEADER_LONG) + } } - if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] > 128 ) { // long header size: adjust the header size - pdu += 1; - } - LOG_D(MAC,"BSR Bytes %d for lcgid %d num lcgid %d\n", UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid], lcgid, num_lcgid); - } - // current phy buff can not transport all sdu for this lcgid -> transmit a bsr for this lcgid - if (buflen < pdu) { - if (num_lcgid > 0) { - bsr_len = sizeof(BSR_SHORT); - } else { - bsr_len = 0; - } - } - // padding larger then long bsr - if (buflen > (pdu + long_bsr_plus_subheader_length)) { - if (num_lcgid > 1) { - bsr_len = sizeof(BSR_LONG); - } else if (num_lcgid > 0) { - bsr_len = sizeof(BSR_SHORT); - } else { - bsr_len = 0; - } - } - // padding larger then short bsr and shorter then long bsr - if ((buflen < (pdu + long_bsr_plus_subheader_length)) && - (buflen > (pdu + short_bsr_plus_subheader_length))) { - if (num_lcgid > 0) { - bsr_len = sizeof(BSR_SHORT); - } else { - bsr_len = 0; + if ( (pdu > buflen) && (rlc_status.bytes_in_buffer > 0 ) ) { + num_lcid +=1; + bsr_len = (num_lcid >= 2 ) ? sizeof(BSR_LONG) : sizeof(BSR_SHORT) ; } + LOG_D(MAC,"LC buffer Bytes %d for lcid %d bsr len %d num lcid %d\n", rlc_status.bytes_in_buffer, lcid, bsr_len, num_lcid); } + if ( bsr_len > 0 ) LOG_D(MAC,"[UE %d] Prepare a %s (Transport Block Size %d, MAC pdu Size %d) \n", module_idP, map_int_to_str(BSR_names, bsr_len), buflen, pdu); @@ -2036,16 +2004,15 @@ uint8_t get_bsr_len (module_id_t module_idP, uint16_t buflen) return bsr_len; } - boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_index, uint8_t lcid, uint8_t lcg_id) { mac_rlc_status_resp_t rlc_status; - boolean_t Bsr_pending = FALSE; + boolean_t sr_pending = FALSE; if ((lcg_id < 0) || (lcg_id >= MAX_NUM_LCGID) ) { - return Bsr_pending; + return sr_pending; } // fixme: need a better way to reset @@ -2062,14 +2029,11 @@ boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_in if (rlc_status.bytes_in_buffer > 0 ) { //BSR trigger SR - Bsr_pending = TRUE; + sr_pending = TRUE; UE_mac_inst[module_idP].scheduling_info.LCID_status[lcid] = LCID_NOT_EMPTY; - UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id] = rlc_status.bytes_in_buffer; - if (UE_mac_inst[module_idP].scheduling_info.extendedBSR_Sizes_r10 == TRUE){ - UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id] = locate_BsrIndexByBufferSize(Extended_BSR_TABLE, BSR_TABLE_SIZE, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id]); - } else { - UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id] = locate_BsrIndexByBufferSize(BSR_TABLE, BSR_TABLE_SIZE, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id]); - } + // sum lcid buffer which has same lcgid + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id] += rlc_status.bytes_in_buffer; + UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id] = locate_BsrIndexByBufferSize(BSR_TABLE, BSR_TABLE_SIZE, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id]); // UE_mac_inst[module_idP].scheduling_info.BSR_short_lcid = lcid; // only applicable to short bsr LOG_D(MAC,"[UE %d] BSR level %d (LCGID %d, rlc buffer %d byte)\n", module_idP, UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id],lcg_id, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id]); @@ -2079,7 +2043,7 @@ boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_in } //} - return Bsr_pending; + return sr_pending; } uint8_t locate_BsrIndexByBufferSize (const uint32_t *table, int size, int value) From 7e6a74d5be20128ab47cc9bfc8a1fd647b7e83d4 Mon Sep 17 00:00:00 2001 From: calvin wang Date: Wed, 26 Oct 2016 13:21:26 +0800 Subject: [PATCH 3/7] change debug info --- openair2/LAYER2/MAC/ue_procedures.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c index 97b7e433c4..8773186382 100644 --- a/openair2/LAYER2/MAC/ue_procedures.c +++ b/openair2/LAYER2/MAC/ue_procedures.c @@ -1422,6 +1422,12 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf bsr_l->Buffer_size2 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2]; bsr_l->Buffer_size3 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3]; + LOG_D(MAC, "[UE %d] Frame %d report long BSR (level LCGID0 %d,level LCGID1 %d,level LCGID2 %d,level LCGID3 %d)\n", module_idP,frameP, + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0], + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1], + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2], + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3]); + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[LCGID0] = 0; UE_mac_inst[module_idP].scheduling_info.BSR_bytes[LCGID1] = 0; UE_mac_inst[module_idP].scheduling_info.BSR_bytes[LCGID2] = 0; @@ -1430,12 +1436,6 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1] = 0; UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2] = 0; UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3] = 0; - - LOG_D(MAC, "[UE %d] Frame %d report long BSR (level LCGID0 %d,level LCGID1 %d,level LCGID2 %d,level LCGID3 %d)\n", module_idP,frameP, - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0], - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1], - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2], - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3]); } else if (bsr_ce_len == sizeof(BSR_SHORT)) { bsr_l = NULL; bsr_s->LCGID = lcgid; From 6644204765a129610a4b8ec035c5ff90250d077c Mon Sep 17 00:00:00 2001 From: calvin wang Date: Thu, 27 Oct 2016 11:47:17 +0800 Subject: [PATCH 4/7] add BSR trigger code for interoperability test --- openair2/LAYER2/MAC/defs.h | 4 ++++ openair2/LAYER2/MAC/ue_procedures.c | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/openair2/LAYER2/MAC/defs.h b/openair2/LAYER2/MAC/defs.h index e3be4bad6d..d38ca05362 100644 --- a/openair2/LAYER2/MAC/defs.h +++ b/openair2/LAYER2/MAC/defs.h @@ -947,6 +947,10 @@ typedef struct { uint8_t BSR[MAX_NUM_LCGID]; // should be more for mesh topology /// keep the number of bytes in rlc buffer for each lcgid uint16_t BSR_bytes[MAX_NUM_LCGID]; +#if 0 //calvin for BSR test,current buffer greater then previous one, or buffer from 0 to !0 + /// after multiplexing buffer remain for each lcid + uint16_t LCID_buffer_remain[MAX_NUM_LCID]; +#endif /// buffer status for each lcid uint8_t LCID_status[MAX_NUM_LCID]; /// SR pending as defined in 36.321 diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c index 082b61445f..c24702b3b5 100644 --- a/openair2/LAYER2/MAC/ue_procedures.c +++ b/openair2/LAYER2/MAC/ue_procedures.c @@ -1356,6 +1356,9 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf //update_bsr(module_idP, frameP, eNB_index, DCCH, UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH]); //header_len +=2; UE_mac_inst[module_idP].scheduling_info.LCID_status[DCCH] = LCID_EMPTY; +#if 0 //calvin for BSR test,current buffer greater then previous one, or buffer from 0 to !0 + UE_mac_inst[module_idP].scheduling_info.LCID_buffer_remain[DCCH] = rlc_status.bytes_in_buffer-sdu_lengths[0]; +#endif } else { dcch_header_len=0; num_sdus = 0; @@ -1391,10 +1394,13 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf sdu_length_total += sdu_lengths[num_sdus]; sdu_lcids[num_sdus] = DCCH1; LOG_D(MAC,"[UE %d] TX Got %d bytes for DCCH1\n",module_idP,sdu_lengths[num_sdus]); - num_sdus++; //update_bsr(module_idP, frameP, DCCH1); //dcch_header_len +=2; // include dcch1 UE_mac_inst[module_idP].scheduling_info.LCID_status[DCCH1] = LCID_EMPTY; +#if 0 //calvin for BSR test,current buffer greater then previous one, or buffer from 0 to !0 + UE_mac_inst[module_idP].scheduling_info.LCID_buffer_remain[DCCH1] = rlc_status.bytes_in_buffer-sdu_lengths[num_sdus]; +#endif + num_sdus++; } else { dcch1_header_len =0; } @@ -1449,6 +1455,9 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf dtch_header_len --; dtch_header_len_last --; } +#if 0 //calvin for BSR test,current buffer greater then previous one, or buffer from 0 to !0 + UE_mac_inst[module_idP].scheduling_info.LCID_buffer_remain[lcid] = rlc_status.bytes_in_buffer-sdu_lengths[num_sdus]; +#endif num_sdus++; //UE_mac_inst[module_idP].ul_active = update_bsr(module_idP, frameP, eNB_index,lcid, UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]); } else { @@ -2077,7 +2086,11 @@ boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_in lcid, 0); - if (rlc_status.bytes_in_buffer > 0 ) { + if ((rlc_status.bytes_in_buffer > 0 ) +#if 0 //calvin for BSR test,current buffer greater then previous one, or buffer from 0 to !0 + && (rlc_status.bytes_in_buffer > UE_mac_inst[module_idP].scheduling_info.LCID_buffer_remain[lcid]) +#endif + ){ //BSR trigger SR sr_pending = TRUE; UE_mac_inst[module_idP].scheduling_info.LCID_status[lcid] = LCID_NOT_EMPTY; From 048b5384dd30aec8246020f0e1c30d5b8dd1970a Mon Sep 17 00:00:00 2001 From: fnabet Date: Mon, 7 Nov 2016 11:22:11 +0100 Subject: [PATCH 5/7] [OAI-UE] revert commit 8236206c and 9672b410 "BSR-stabilization + rebase from oai1B" --- openair2/LAYER2/MAC/config.c | 25 +--- openair2/LAYER2/MAC/defs.h | 14 +-- openair2/LAYER2/MAC/extern.h | 2 - openair2/LAYER2/MAC/proto.h | 6 +- openair2/LAYER2/MAC/ra_procedures.c | 2 +- openair2/LAYER2/MAC/ue_procedures.c | 184 +++++++++------------------- openair2/LAYER2/MAC/vars.h | 9 -- 7 files changed, 66 insertions(+), 176 deletions(-) diff --git a/openair2/LAYER2/MAC/config.c b/openair2/LAYER2/MAC/config.c index d46b761bd0..3fbcadafbb 100644 --- a/openair2/LAYER2/MAC/config.c +++ b/openair2/LAYER2/MAC/config.c @@ -69,7 +69,6 @@ void ue_mac_reset(module_id_t module_idP,uint8_t eNB_index) // cancel all pending SRs UE_mac_inst[module_idP].scheduling_info.SR_pending=0; UE_mac_inst[module_idP].scheduling_info.SR_COUNTER=0; - UE_mac_inst[module_idP].BSR_reporting_active=0; // stop ongoing RACH procedure @@ -226,34 +225,13 @@ rrc_mac_config_req( if (mac_MainConfig->ext1 && mac_MainConfig->ext1->sr_ProhibitTimer_r9) { UE_mac_inst[Mod_idP].scheduling_info.sr_ProhibitTimer = (uint16_t) *mac_MainConfig->ext1->sr_ProhibitTimer_r9; } else { - UE_mac_inst[Mod_idP].scheduling_info.sr_ProhibitTimer = 0; + UE_mac_inst[Mod_idP].scheduling_info.sr_ProhibitTimer = (uint16_t) 0; } - if (mac_MainConfig->ext2 && mac_MainConfig->ext2->mac_MainConfig_v1020) { - if (mac_MainConfig->ext2->mac_MainConfig_v1020->extendedBSR_Sizes_r10) { - UE_mac_inst[Mod_idP].scheduling_info.extendedBSR_Sizes_r10 = (uint16_t) *mac_MainConfig->ext2->mac_MainConfig_v1020->extendedBSR_Sizes_r10; - } else { - UE_mac_inst[Mod_idP].scheduling_info.extendedBSR_Sizes_r10 = (uint16_t)0; - } - if (mac_MainConfig->ext2->mac_MainConfig_v1020->extendedPHR_r10) { - UE_mac_inst[Mod_idP].scheduling_info.extendedPHR_r10 = (uint16_t) *mac_MainConfig->ext2->mac_MainConfig_v1020->extendedPHR_r10; - } else { - UE_mac_inst[Mod_idP].scheduling_info.extendedPHR_r10 = (uint16_t)0; - } - } else { - UE_mac_inst[Mod_idP].scheduling_info.extendedBSR_Sizes_r10 = (uint16_t)0; - UE_mac_inst[Mod_idP].scheduling_info.extendedPHR_r10 = (uint16_t)0; - } #endif UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_SF = get_sf_periodicBSRTimer(UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_Timer); UE_mac_inst[Mod_idP].scheduling_info.retxBSR_SF = get_sf_retxBSRTimer(UE_mac_inst[Mod_idP].scheduling_info.retxBSR_Timer); - UE_mac_inst[Mod_idP].BSR_reporting_active = 0; - LOG_D(MAC,"[UE %d]: periodic BSR %d (SF), retx BSR %d (SF)\n", - Mod_idP, - UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_SF, - UE_mac_inst[Mod_idP].scheduling_info.retxBSR_SF); - UE_mac_inst[Mod_idP].scheduling_info.drx_config = mac_MainConfig->drx_Config; UE_mac_inst[Mod_idP].scheduling_info.phr_config = mac_MainConfig->phr_Config; @@ -274,7 +252,6 @@ rrc_mac_config_req( UE_mac_inst[Mod_idP].scheduling_info.periodicPHR_SF = get_sf_perioidicPHR_Timer(UE_mac_inst[Mod_idP].scheduling_info.periodicPHR_Timer); UE_mac_inst[Mod_idP].scheduling_info.prohibitPHR_SF = get_sf_prohibitPHR_Timer(UE_mac_inst[Mod_idP].scheduling_info.prohibitPHR_Timer); UE_mac_inst[Mod_idP].scheduling_info.PathlossChange_db = get_db_dl_PathlossChange(UE_mac_inst[Mod_idP].scheduling_info.PathlossChange); - UE_mac_inst[Mod_idP].PHR_reporting_active = 0; LOG_D(MAC,"[UE %d] config PHR (%d): periodic %d (SF) prohibit %d (SF) pathlosschange %d (db) \n", Mod_idP, (mac_MainConfig->phr_Config)?mac_MainConfig->phr_Config->present:-1, diff --git a/openair2/LAYER2/MAC/defs.h b/openair2/LAYER2/MAC/defs.h index d38ca05362..2235c3e1c4 100644 --- a/openair2/LAYER2/MAC/defs.h +++ b/openair2/LAYER2/MAC/defs.h @@ -945,12 +945,8 @@ typedef enum { typedef struct { /// buffer status for each lcgid uint8_t BSR[MAX_NUM_LCGID]; // should be more for mesh topology - /// keep the number of bytes in rlc buffer for each lcgid + /// keep the number of bytes in rlc buffer for each lcid uint16_t BSR_bytes[MAX_NUM_LCGID]; -#if 0 //calvin for BSR test,current buffer greater then previous one, or buffer from 0 to !0 - /// after multiplexing buffer remain for each lcid - uint16_t LCID_buffer_remain[MAX_NUM_LCID]; -#endif /// buffer status for each lcid uint8_t LCID_status[MAX_NUM_LCID]; /// SR pending as defined in 36.321 @@ -991,12 +987,6 @@ typedef struct { int16_t prohibitPHR_SF; ///DL Pathloss Change in db uint16_t PathlossChange_db; - - /// default value is false - uint16_t extendedBSR_Sizes_r10; - /// default value is false - uint16_t extendedPHR_r10; - //Bj bucket usage per lcid int16_t Bj[MAX_NUM_LCID]; // Bucket size per lcid @@ -1084,8 +1074,6 @@ typedef struct { uint8_t PHR_reporting_active; /// power backoff due to power management (as allowed by P-MPRc) for this cell uint8_t power_backoff_db[NUMBER_OF_eNB_MAX]; - /// BSR report falg management - uint8_t BSR_reporting_active; /// MBSFN_Subframe Configuration struct MBSFN_SubframeConfig *mbsfn_SubframeConfig[8]; // FIXME replace 8 by MAX_MBSFN_AREA? /// number of subframe allocation pattern available for MBSFN sync area diff --git a/openair2/LAYER2/MAC/extern.h b/openair2/LAYER2/MAC/extern.h index 4276c342cf..8726cb1349 100644 --- a/openair2/LAYER2/MAC/extern.h +++ b/openair2/LAYER2/MAC/extern.h @@ -46,8 +46,6 @@ extern const uint32_t BSR_TABLE[BSR_TABLE_SIZE]; //extern uint32_t EBSR_Level[63]; -extern const uint32_t Extended_BSR_TABLE[BSR_TABLE_SIZE]; -//extern uint32_t Extended_BSR_TABLE[63]; ----currently not used extern UE_MAC_INST *UE_mac_inst; extern eNB_MAC_INST *eNB_mac_inst; diff --git a/openair2/LAYER2/MAC/proto.h b/openair2/LAYER2/MAC/proto.h index 248f918dc1..59d6c352fe 100644 --- a/openair2/LAYER2/MAC/proto.h +++ b/openair2/LAYER2/MAC/proto.h @@ -551,7 +551,7 @@ int get_bsr_lcgid (module_id_t module_idP); \param[in] bufflen size of phy transport block \param[out] bsr_len size of bsr control element */ -uint8_t get_bsr_len (module_id_t module_idP, uint8_t eNB_index,frame_t frameP,uint16_t buflen); +uint8_t get_bsr_len (module_id_t module_idP, uint16_t buflen); /*! \fn BSR_SHORT * get_bsr_short(module_id_t module_idP, uint8_t bsr_len) \brief get short bsr level @@ -577,14 +577,14 @@ BSR_LONG * get_bsr_long(module_id_t module_idP, uint8_t bsr_len); */ boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_index, uint8_t lcid, uint8_t lcgid); -/*! \fn locate_BsrIndexByBufferSize (int *table, int size, int value) +/*! \fn locate (int *table, int size, int value) \brief locate the BSR level in the table as defined in 36.321. This function requires that he values in table to be monotonic, either increasing or decreasing. The returned value is not less than 0, nor greater than n-1, where n is the size of table. \param[in] *table Pointer to BSR table \param[in] size Size of the table \param[in] value Value of the buffer \return the index in the BSR_LEVEL table */ -uint8_t locate_BsrIndexByBufferSize (const uint32_t *table, int size, int value); +uint8_t locate (const uint32_t *table, int size, int value); /*! \fn int get_sf_periodicBSRTimer(uint8_t periodicBSR_Timer) diff --git a/openair2/LAYER2/MAC/ra_procedures.c b/openair2/LAYER2/MAC/ra_procedures.c index 3b5734756d..30137fab33 100644 --- a/openair2/LAYER2/MAC/ra_procedures.c +++ b/openair2/LAYER2/MAC/ra_procedures.c @@ -391,7 +391,7 @@ PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP,int CC_id,frame_t frameP, 1); //post_padding return(&UE_mac_inst[module_idP].RA_prach_resources); - } else if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH]] > 0) { + } else if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[DCCH] > 0) { // This is for triggering a transmission on DCCH using PRACH (during handover, or sending SR for example) dcch_header_len = 2 + 2; /// SHORT Subheader + C-RNTI control element rlc_status = mac_rlc_status_ind(module_idP,UE_mac_inst[module_idP].crnti, eNB_indexP,frameP,ENB_FLAG_NO,MBMS_FLAG_NO, diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c index c24702b3b5..d5958f6e5e 100644 --- a/openair2/LAYER2/MAC/ue_procedures.c +++ b/openair2/LAYER2/MAC/ue_procedures.c @@ -102,17 +102,13 @@ void ue_init_mac(module_id_t module_idP) UE_mac_inst[module_idP].scheduling_info.sr_ProhibitTimer_Running=0; UE_mac_inst[module_idP].scheduling_info.maxHARQ_Tx=MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5; UE_mac_inst[module_idP].scheduling_info.ttiBundling=0; - UE_mac_inst[module_idP].scheduling_info.extendedBSR_Sizes_r10=0; - UE_mac_inst[module_idP].scheduling_info.extendedPHR_r10=0; UE_mac_inst[module_idP].scheduling_info.drx_config=NULL; UE_mac_inst[module_idP].scheduling_info.phr_config=NULL; UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF = get_sf_periodicBSRTimer(UE_mac_inst[module_idP].scheduling_info.periodicBSR_Timer); UE_mac_inst[module_idP].scheduling_info.retxBSR_SF = get_sf_retxBSRTimer(UE_mac_inst[module_idP].scheduling_info.retxBSR_Timer); - UE_mac_inst[module_idP].BSR_reporting_active = 0; UE_mac_inst[module_idP].scheduling_info.periodicPHR_SF = get_sf_perioidicPHR_Timer(UE_mac_inst[module_idP].scheduling_info.periodicPHR_Timer); UE_mac_inst[module_idP].scheduling_info.prohibitPHR_SF = get_sf_prohibitPHR_Timer(UE_mac_inst[module_idP].scheduling_info.prohibitPHR_Timer); UE_mac_inst[module_idP].scheduling_info.PathlossChange_db = get_db_dl_PathlossChange(UE_mac_inst[module_idP].scheduling_info.PathlossChange); - UE_mac_inst[module_idP].PHR_reporting_active = 0; for (i=0; i < MAX_NUM_LCID; i++) { LOG_D(MAC,"[UE%d] Applying default logical channel config for LCGID %d\n",module_idP,i); @@ -125,7 +121,7 @@ void ue_init_mac(module_id_t module_idP) UE_mac_inst[module_idP].scheduling_info.LCGID[i]=1; } - UE_mac_inst[module_idP].scheduling_info.LCID_status[i]=LCID_EMPTY; + UE_mac_inst[module_idP].scheduling_info.LCID_status[i]=0; } #ifdef CBA @@ -310,28 +306,18 @@ uint32_t ue_get_SR(module_id_t module_idP,int CC_id,frame_t frameP,uint8_t eNB_i // initiate RA UE_mac_inst[module_idP].scheduling_info.SR_pending=0; UE_mac_inst[module_idP].scheduling_info.SR_COUNTER=0; - // release all pucch resource - UE_mac_inst[module_idP].physicalConfigDedicated = NULL; - UE_mac_inst[module_idP].ul_active=0; - UE_mac_inst[module_idP].BSR_reporting_active=0; - - LOG_T(MAC,"[UE %d] Release all SRs \n", module_idP); return(0); } } //------------------------------------------------------------------------------ void -ue_send_sdu( - module_id_t module_idP, - uint8_t CC_id, - frame_t frameP, - uint8_t* sdu, - uint16_t sdu_len, - uint8_t eNB_index -) -//------------------------------------------------------------------------------ -{ +ue_send_sdu(module_id_t module_idP, + uint8_t CC_id, + frame_t frameP, + uint8_t* sdu, + uint16_t sdu_len, + uint8_t eNB_index) { unsigned char rx_ces[MAX_NUM_CE],num_ce,num_sdu,i,*payload_ptr; unsigned char rx_lcids[NB_RB_MAX]; @@ -1258,12 +1244,11 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf BSR_LONG *bsr_l=&bsr_long; POWER_HEADROOM_CMD phr; POWER_HEADROOM_CMD *phr_p=&phr; - unsigned short short_padding=0, post_padding=0, padding_len=0; + unsigned short short_padding=0, post_padding=0; int lcgid; int j; // used for padding // Compute header length - int all_pdu_len; - + if (CC_id>0) { LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n"); mac_xface->macphy_exit("MAC FATAL CC_id>0"); @@ -1297,10 +1282,19 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf dtch_header_len=(buflen > 128 ) ? 3 : 2 ; //sizeof(SCH_SUBHEADER_LONG)-1 : sizeof(SCH_SUBHEADER_SHORT); bsr_header_len = 1;//sizeof(SCH_SUBHEADER_FIXED); phr_header_len = 1;//sizeof(SCH_SUBHEADER_FIXED); + phr_ce_len = (UE_mac_inst[module_idP].PHR_reporting_active == 1) ? 1 /* sizeof(POWER_HEADROOM_CMD)*/: 0; - bsr_ce_len = get_bsr_len (module_idP, eNB_index, frameP, buflen); - // retxBSR-Timer expires or periodicBSR-Timer expires and Regular BSR trigger - if ((bsr_ce_len > 0 ) && (UE_mac_inst[module_idP].BSR_reporting_active > 0)) { + if (phr_ce_len > 0) { + phr_len = phr_ce_len + phr_header_len; + LOG_D(MAC,"[UE %d] header size info: PHR len %d (ce%d,hdr%d) buff_len %d\n", + module_idP, phr_len, phr_ce_len, phr_header_len, buflen); + } else { + phr_len=0; + } + + bsr_ce_len = get_bsr_len (module_idP, buflen-phr_len); + + if (bsr_ce_len > 0 ) { bsr_len = bsr_ce_len + bsr_header_len; LOG_D(MAC,"[UE %d] header size info: dcch %d, dcch1 %d, dtch %d, bsr (ce%d,hdr%d) buff_len %d\n", module_idP, dcch_header_len,dcch1_header_len,dtch_header_len, bsr_ce_len, bsr_header_len, buflen); @@ -1311,15 +1305,6 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf //bsr_len = bsr_ce_len + bsr_header_len; } - phr_ce_len = (UE_mac_inst[module_idP].PHR_reporting_active == 1) ? 1 /* sizeof(POWER_HEADROOM_CMD)*/: 0; - if (phr_ce_len > 0) { - phr_len = phr_ce_len + phr_header_len; - LOG_D(MAC,"[UE %d] header size info: PHR len %d (ce%d,hdr%d) buff_len %d\n", - module_idP, phr_len, phr_ce_len, phr_header_len, buflen); - } else { - phr_len=0; - } - // check for UL bandwidth requests and add SR control element // check for UL bandwidth requests and add SR control element @@ -1353,12 +1338,8 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf sdu_lcids[0] = DCCH; LOG_D(MAC,"[UE %d] TX Got %d bytes for DCCH\n",module_idP,sdu_lengths[0]); num_sdus = 1; - //update_bsr(module_idP, frameP, eNB_index, DCCH, UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH]); + update_bsr(module_idP, frameP, eNB_index, DCCH, UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH]); //header_len +=2; - UE_mac_inst[module_idP].scheduling_info.LCID_status[DCCH] = LCID_EMPTY; -#if 0 //calvin for BSR test,current buffer greater then previous one, or buffer from 0 to !0 - UE_mac_inst[module_idP].scheduling_info.LCID_buffer_remain[DCCH] = rlc_status.bytes_in_buffer-sdu_lengths[0]; -#endif } else { dcch_header_len=0; num_sdus = 0; @@ -1394,13 +1375,9 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf sdu_length_total += sdu_lengths[num_sdus]; sdu_lcids[num_sdus] = DCCH1; LOG_D(MAC,"[UE %d] TX Got %d bytes for DCCH1\n",module_idP,sdu_lengths[num_sdus]); + num_sdus++; //update_bsr(module_idP, frameP, DCCH1); //dcch_header_len +=2; // include dcch1 - UE_mac_inst[module_idP].scheduling_info.LCID_status[DCCH1] = LCID_EMPTY; -#if 0 //calvin for BSR test,current buffer greater then previous one, or buffer from 0 to !0 - UE_mac_inst[module_idP].scheduling_info.LCID_buffer_remain[DCCH1] = rlc_status.bytes_in_buffer-sdu_lengths[num_sdus]; -#endif - num_sdus++; } else { dcch1_header_len =0; } @@ -1411,9 +1388,8 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf dtch_header_len+=3; dtch_header_len_last=3; - all_pdu_len = bsr_len+phr_len+dcch_header_len+dcch1_header_len+dtch_header_len+sdu_length_total; if ((UE_mac_inst[module_idP].scheduling_info.LCID_status[lcid] == LCID_NOT_EMPTY) && - (all_pdu_len <= buflen)) { + ((bsr_len+phr_len+dcch_header_len+dcch1_header_len+dtch_header_len+sdu_length_total) <= buflen)) { // optimize the dtch header lenght //if ((UE_mac_inst[module_idP].scheduling_info.BSR_bytes[DTCH] > 128) && @@ -1431,11 +1407,11 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf ENB_FLAG_NO, MBMS_FLAG_NO, // eNB_index lcid, - buflen-all_pdu_len); + buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-dtch_header_len-sdu_length_total); LOG_D(MAC,"[UE %d] Frame %d : UL-DTCH -> ULSCH%d, %d bytes to send (Transport Block size %d, mac header len %d, BSR byte[%d] %d)\n", module_idP,frameP, lcid, rlc_status.bytes_in_buffer,buflen,dtch_header_len, - lcid, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]]); + lcid, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcid]); if (rlc_status.bytes_in_buffer > 0) { sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP, @@ -1455,20 +1431,16 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf dtch_header_len --; dtch_header_len_last --; } -#if 0 //calvin for BSR test,current buffer greater then previous one, or buffer from 0 to !0 - UE_mac_inst[module_idP].scheduling_info.LCID_buffer_remain[lcid] = rlc_status.bytes_in_buffer-sdu_lengths[num_sdus]; -#endif num_sdus++; - //UE_mac_inst[module_idP].ul_active = update_bsr(module_idP, frameP, eNB_index,lcid, UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]); + UE_mac_inst[module_idP].ul_active = update_bsr(module_idP, frameP, eNB_index,lcid, UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]); } else { dtch_header_len -= 3; } - UE_mac_inst[module_idP].scheduling_info.LCID_status[lcid] = LCID_EMPTY; } else { // no rlc pdu : generate the dummy header dtch_header_len -= 3; } } - + lcgid= get_bsr_lcgid(module_idP); if (lcgid < 0 ) { @@ -1480,29 +1452,15 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf bsr_l->Buffer_size1 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1]; bsr_l->Buffer_size2 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2]; bsr_l->Buffer_size3 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3]; - LOG_D(MAC, "[UE %d] Frame %d report long BSR (level LCGID0 %d,level LCGID1 %d,level LCGID2 %d,level LCGID3 %d)\n", module_idP,frameP, UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0], UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1], UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2], UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3]); - - UE_mac_inst[module_idP].scheduling_info.BSR_bytes[LCGID0] = 0; - UE_mac_inst[module_idP].scheduling_info.BSR_bytes[LCGID1] = 0; - UE_mac_inst[module_idP].scheduling_info.BSR_bytes[LCGID2] = 0; - UE_mac_inst[module_idP].scheduling_info.BSR_bytes[LCGID3] = 0; - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0] = 0; - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1] = 0; - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2] = 0; - UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3] = 0; } else if (bsr_ce_len == sizeof(BSR_SHORT)) { bsr_l = NULL; bsr_s->LCGID = lcgid; bsr_s->Buffer_size = UE_mac_inst[module_idP].scheduling_info.BSR[lcgid]; - - UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] = 0; - UE_mac_inst[module_idP].scheduling_info.BSR[lcgid] = 0; - LOG_D(MAC,"[UE %d] Frame %d report SHORT BSR with level %d for LCGID %d\n", module_idP, frameP, UE_mac_inst[module_idP].scheduling_info.BSR[lcgid],lcgid); } else { @@ -1536,14 +1494,12 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf dtch_header_len_last-=1; dtch_header_len= (dtch_header_len >0)? dtch_header_len - dtch_header_len_last : dtch_header_len; } - // 1-bit padding or 2-bit padding special padding subheader - padding_len = buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-dtch_header_len-sdu_length_total; - if (padding_len <= 2) { - short_padding = padding_len; - // only add padding header + + if ((buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-dtch_header_len-sdu_length_total) <= 2) { + short_padding = buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-dtch_header_len-sdu_length_total; post_padding = 0; } else { - if (padding_len == buflen) {// nona mac pdu + if ((buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-dtch_header_len-sdu_length_total) == buflen) { *access_mode=CANCELED_ACCESS; } @@ -1588,9 +1544,6 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf module_idP,payload_offset, sdu_length_total); UE_mac_inst[module_idP].scheduling_info.SR_pending=0; UE_mac_inst[module_idP].scheduling_info.SR_COUNTER=0; - UE_mac_inst[module_idP].BSR_reporting_active=0; - UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF = get_sf_periodicBSRTimer(UE_mac_inst[module_idP].scheduling_info.periodicBSR_Timer); - UE_mac_inst[module_idP].scheduling_info.retxBSR_SF = get_sf_retxBSRTimer(UE_mac_inst[module_idP].scheduling_info.retxBSR_Timer); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_GET_SDU, VCD_FUNCTION_OUT); stop_meas(&UE_mac_inst[module_idP].tx_ulsch_sdu); @@ -1752,25 +1705,10 @@ ue_scheduler( // call SR procedure to generate pending SR and BSR for next PUCCH/PUSCH TxOp. This should implement the procedures // outlined in Sections 5.4.4 an 5.4.5 of 36.321 - // Call BSR procedure as described in Section 5.4.5 in 36.321 - if (UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF == get_sf_periodicBSRTimer(MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_infinity)) { - UE_mac_inst[module_idP].BSR_reporting_active = 1; - } else if (UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF <= 0 ){ - // trigger BSR and reset the timer later when the BSR report is sent - UE_mac_inst[module_idP].BSR_reporting_active = 1; - } else if (UE_mac_inst[module_idP].BSR_reporting_active == 0 ) { - UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF--; - } - - if (UE_mac_inst[module_idP].scheduling_info.retxBSR_SF <= 0){ - // trigger BSR and reset the timer later when the BSR report is sent - UE_mac_inst[module_idP].BSR_reporting_active = 1; - } else if (UE_mac_inst[module_idP].BSR_reporting_active == 0 ) { - UE_mac_inst[module_idP].scheduling_info.retxBSR_SF--; - } + // Put this in another function // Get RLC status info and update Bj for all lcids that are active - for (lcid=DCCH; lcid < MAX_NUM_LCID; lcid++ ) { + for (lcid=DCCH; lcid <= DTCH; lcid++ ) { if ((lcid == 0) ||(UE_mac_inst[module_idP].logicalChannelConfig[lcid])) { // meausre the Bj if ((directionP == SF_UL)&& (UE_mac_inst[module_idP].scheduling_info.Bj[lcid] >= 0)) { @@ -1791,8 +1729,6 @@ ue_scheduler( if (update_bsr(module_idP,frameP, eNB_indexP, lcid, UE_mac_inst[module_idP].scheduling_info.LCGID[lcid])) { UE_mac_inst[module_idP].scheduling_info.SR_pending= 1; - // Regular BSR trigger - UE_mac_inst[module_idP].BSR_reporting_active = 1; LOG_D(MAC,"[UE %d][SR] Frame %d subframe %d SR for PUSCH is pending for LCGID %d with BSR level %d (%d bytes in RLC)\n", module_idP, frameP,subframeP,UE_mac_inst[module_idP].scheduling_info.LCGID[lcid], UE_mac_inst[module_idP].scheduling_info.BSR[UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]], @@ -2034,26 +1970,31 @@ int get_bsr_lcgid (module_id_t module_idP) } } -uint8_t get_bsr_len (module_id_t module_idP, uint8_t eNB_index,frame_t frameP,uint16_t buflen) +uint8_t get_bsr_len (module_id_t module_idP, uint16_t buflen) { - int lcid; - uint8_t bsr_len=0, num_lcid=0; - int pdu = 0; - mac_rlc_status_resp_t rlc_status; - for (lcid=DCCH; lcid 0 ) { - pdu += rlc_status.bytes_in_buffer + sizeof(SCH_SUBHEADER_SHORT) + bsr_len; - if (rlc_status.bytes_in_buffer > 128 ) { - pdu += 1; //sizeof(SCH_SUBHEADER_LONG) - } + int lcgid=0; + uint8_t bsr_len=0, num_lcgid=0; + int pdu = 0; + + + for (lcgid=0; lcgid < MAX_NUM_LCGID; lcgid++ ) { + if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] > 0 ) { + pdu += (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] + bsr_len + 2); //2 = sizeof(SCH_SUBHEADER_SHORT) } - if ( (pdu > buflen) && (rlc_status.bytes_in_buffer > 0 ) ) { - num_lcid +=1; - bsr_len = (num_lcid >= 2 ) ? sizeof(BSR_LONG) : sizeof(BSR_SHORT) ; + + if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] > 128 ) { // long header size: adjust the header size + pdu += 1; } - LOG_D(MAC,"LC buffer Bytes %d for lcid %d bsr len %d num lcid %d\n", rlc_status.bytes_in_buffer, lcid, bsr_len, num_lcid); + + // current phy buff can not transport all sdu for this lcgid -> transmit a bsr for this lcgid + + if ( (pdu > buflen) && (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] > 0 ) ) { + num_lcgid +=1; + bsr_len = (num_lcgid >= 2 ) ? sizeof(BSR_LONG) : sizeof(BSR_SHORT) ; + } + + LOG_D(MAC,"BSR Bytes %d for lcgid %d bsr len %d num lcgid %d\n", UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid], lcgid, bsr_len, num_lcgid); } if ( bsr_len > 0 ) @@ -2063,6 +2004,7 @@ uint8_t get_bsr_len (module_id_t module_idP, uint8_t eNB_index,frame_t frameP,ui return bsr_len; } + boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_index, uint8_t lcid, uint8_t lcg_id) { @@ -2086,17 +2028,11 @@ boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_in lcid, 0); - if ((rlc_status.bytes_in_buffer > 0 ) -#if 0 //calvin for BSR test,current buffer greater then previous one, or buffer from 0 to !0 - && (rlc_status.bytes_in_buffer > UE_mac_inst[module_idP].scheduling_info.LCID_buffer_remain[lcid]) -#endif - ){ - //BSR trigger SR + if (rlc_status.bytes_in_buffer > 0 ) { sr_pending = TRUE; UE_mac_inst[module_idP].scheduling_info.LCID_status[lcid] = LCID_NOT_EMPTY; - // sum lcid buffer which has same lcgid + UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id] += locate (BSR_TABLE,BSR_TABLE_SIZE, rlc_status.bytes_in_buffer); UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id] += rlc_status.bytes_in_buffer; - UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id] = locate_BsrIndexByBufferSize(BSR_TABLE, BSR_TABLE_SIZE, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id]); // UE_mac_inst[module_idP].scheduling_info.BSR_short_lcid = lcid; // only applicable to short bsr LOG_D(MAC,"[UE %d] BSR level %d (LCGID %d, rlc buffer %d byte)\n", module_idP, UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id],lcg_id, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id]); @@ -2109,7 +2045,7 @@ boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_in return sr_pending; } -uint8_t locate_BsrIndexByBufferSize (const uint32_t *table, int size, int value) +uint8_t locate (const uint32_t *table, int size, int value) { uint8_t ju, jm, jl; @@ -2140,7 +2076,7 @@ uint8_t locate_BsrIndexByBufferSize (const uint32_t *table, int size, int value) if (value == table[jl]) { return jl; - } else { + } else { return jl+1; //equally ju } diff --git a/openair2/LAYER2/MAC/vars.h b/openair2/LAYER2/MAC/vars.h index 236439c6e5..83d159f910 100644 --- a/openair2/LAYER2/MAC/vars.h +++ b/openair2/LAYER2/MAC/vars.h @@ -45,15 +45,6 @@ const uint32_t BSR_TABLE[BSR_TABLE_SIZE]= {0,10,12,14,17,19,22,26,31,36,42,49,57 1326,1552,1817,2127,2490,2915,3413,3995,4677,5467,6411,7505,8787,10287,12043,14099, 16507,19325,22624,26487,31009,36304,42502,49759,58255,68201,79846,93479,109439, 128125,150000, 300000 }; -// extended bsr table--currently not used -const uint32_t Extended_BSR_TABLE[BSR_TABLE_SIZE] = {0,10,13,16,19,23,29,35,43,53,65,80,98,120,147, - 181,223,274,337,414,509,625,769,945,1162,1429, - 1757,2161,2657,3267,4017,4940,6074,7469,9185, - 11294,13888,17077,20999,25822,31752,39045,48012, - 59039,72598,89272,109774,134986,165989,204111, - 250990,308634,379519,466683,573866,705666,867737, - 1067031,1312097,1613447,1984009,2439678,3000000, - 6000000}; //uint32_t EBSR_Level[63]={0,10,13,16,19,23,29,35,43,53,65,80,98,120,147,181}; From d56c651081874c69a42bba2956356514e3f847b2 Mon Sep 17 00:00:00 2001 From: fnabet Date: Mon, 7 Nov 2016 11:57:02 +0100 Subject: [PATCH 6/7] Reapply BSR changes --- openair2/LAYER2/MAC/config.c | 25 +++- openair2/LAYER2/MAC/defs.h | 14 ++- openair2/LAYER2/MAC/extern.h | 2 + openair2/LAYER2/MAC/proto.h | 6 +- openair2/LAYER2/MAC/ra_procedures.c | 2 +- openair2/LAYER2/MAC/ue_procedures.c | 182 +++++++++++++++++++--------- openair2/LAYER2/MAC/vars.h | 9 ++ 7 files changed, 175 insertions(+), 65 deletions(-) diff --git a/openair2/LAYER2/MAC/config.c b/openair2/LAYER2/MAC/config.c index 3fbcadafbb..d46b761bd0 100644 --- a/openair2/LAYER2/MAC/config.c +++ b/openair2/LAYER2/MAC/config.c @@ -69,6 +69,7 @@ void ue_mac_reset(module_id_t module_idP,uint8_t eNB_index) // cancel all pending SRs UE_mac_inst[module_idP].scheduling_info.SR_pending=0; UE_mac_inst[module_idP].scheduling_info.SR_COUNTER=0; + UE_mac_inst[module_idP].BSR_reporting_active=0; // stop ongoing RACH procedure @@ -225,13 +226,34 @@ rrc_mac_config_req( if (mac_MainConfig->ext1 && mac_MainConfig->ext1->sr_ProhibitTimer_r9) { UE_mac_inst[Mod_idP].scheduling_info.sr_ProhibitTimer = (uint16_t) *mac_MainConfig->ext1->sr_ProhibitTimer_r9; } else { - UE_mac_inst[Mod_idP].scheduling_info.sr_ProhibitTimer = (uint16_t) 0; + UE_mac_inst[Mod_idP].scheduling_info.sr_ProhibitTimer = 0; } + if (mac_MainConfig->ext2 && mac_MainConfig->ext2->mac_MainConfig_v1020) { + if (mac_MainConfig->ext2->mac_MainConfig_v1020->extendedBSR_Sizes_r10) { + UE_mac_inst[Mod_idP].scheduling_info.extendedBSR_Sizes_r10 = (uint16_t) *mac_MainConfig->ext2->mac_MainConfig_v1020->extendedBSR_Sizes_r10; + } else { + UE_mac_inst[Mod_idP].scheduling_info.extendedBSR_Sizes_r10 = (uint16_t)0; + } + if (mac_MainConfig->ext2->mac_MainConfig_v1020->extendedPHR_r10) { + UE_mac_inst[Mod_idP].scheduling_info.extendedPHR_r10 = (uint16_t) *mac_MainConfig->ext2->mac_MainConfig_v1020->extendedPHR_r10; + } else { + UE_mac_inst[Mod_idP].scheduling_info.extendedPHR_r10 = (uint16_t)0; + } + } else { + UE_mac_inst[Mod_idP].scheduling_info.extendedBSR_Sizes_r10 = (uint16_t)0; + UE_mac_inst[Mod_idP].scheduling_info.extendedPHR_r10 = (uint16_t)0; + } #endif UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_SF = get_sf_periodicBSRTimer(UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_Timer); UE_mac_inst[Mod_idP].scheduling_info.retxBSR_SF = get_sf_retxBSRTimer(UE_mac_inst[Mod_idP].scheduling_info.retxBSR_Timer); + UE_mac_inst[Mod_idP].BSR_reporting_active = 0; + LOG_D(MAC,"[UE %d]: periodic BSR %d (SF), retx BSR %d (SF)\n", + Mod_idP, + UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_SF, + UE_mac_inst[Mod_idP].scheduling_info.retxBSR_SF); + UE_mac_inst[Mod_idP].scheduling_info.drx_config = mac_MainConfig->drx_Config; UE_mac_inst[Mod_idP].scheduling_info.phr_config = mac_MainConfig->phr_Config; @@ -252,6 +274,7 @@ rrc_mac_config_req( UE_mac_inst[Mod_idP].scheduling_info.periodicPHR_SF = get_sf_perioidicPHR_Timer(UE_mac_inst[Mod_idP].scheduling_info.periodicPHR_Timer); UE_mac_inst[Mod_idP].scheduling_info.prohibitPHR_SF = get_sf_prohibitPHR_Timer(UE_mac_inst[Mod_idP].scheduling_info.prohibitPHR_Timer); UE_mac_inst[Mod_idP].scheduling_info.PathlossChange_db = get_db_dl_PathlossChange(UE_mac_inst[Mod_idP].scheduling_info.PathlossChange); + UE_mac_inst[Mod_idP].PHR_reporting_active = 0; LOG_D(MAC,"[UE %d] config PHR (%d): periodic %d (SF) prohibit %d (SF) pathlosschange %d (db) \n", Mod_idP, (mac_MainConfig->phr_Config)?mac_MainConfig->phr_Config->present:-1, diff --git a/openair2/LAYER2/MAC/defs.h b/openair2/LAYER2/MAC/defs.h index 2235c3e1c4..d38ca05362 100644 --- a/openair2/LAYER2/MAC/defs.h +++ b/openair2/LAYER2/MAC/defs.h @@ -945,8 +945,12 @@ typedef enum { typedef struct { /// buffer status for each lcgid uint8_t BSR[MAX_NUM_LCGID]; // should be more for mesh topology - /// keep the number of bytes in rlc buffer for each lcid + /// keep the number of bytes in rlc buffer for each lcgid uint16_t BSR_bytes[MAX_NUM_LCGID]; +#if 0 //calvin for BSR test,current buffer greater then previous one, or buffer from 0 to !0 + /// after multiplexing buffer remain for each lcid + uint16_t LCID_buffer_remain[MAX_NUM_LCID]; +#endif /// buffer status for each lcid uint8_t LCID_status[MAX_NUM_LCID]; /// SR pending as defined in 36.321 @@ -987,6 +991,12 @@ typedef struct { int16_t prohibitPHR_SF; ///DL Pathloss Change in db uint16_t PathlossChange_db; + + /// default value is false + uint16_t extendedBSR_Sizes_r10; + /// default value is false + uint16_t extendedPHR_r10; + //Bj bucket usage per lcid int16_t Bj[MAX_NUM_LCID]; // Bucket size per lcid @@ -1074,6 +1084,8 @@ typedef struct { uint8_t PHR_reporting_active; /// power backoff due to power management (as allowed by P-MPRc) for this cell uint8_t power_backoff_db[NUMBER_OF_eNB_MAX]; + /// BSR report falg management + uint8_t BSR_reporting_active; /// MBSFN_Subframe Configuration struct MBSFN_SubframeConfig *mbsfn_SubframeConfig[8]; // FIXME replace 8 by MAX_MBSFN_AREA? /// number of subframe allocation pattern available for MBSFN sync area diff --git a/openair2/LAYER2/MAC/extern.h b/openair2/LAYER2/MAC/extern.h index 8726cb1349..4276c342cf 100644 --- a/openair2/LAYER2/MAC/extern.h +++ b/openair2/LAYER2/MAC/extern.h @@ -46,6 +46,8 @@ extern const uint32_t BSR_TABLE[BSR_TABLE_SIZE]; //extern uint32_t EBSR_Level[63]; +extern const uint32_t Extended_BSR_TABLE[BSR_TABLE_SIZE]; +//extern uint32_t Extended_BSR_TABLE[63]; ----currently not used extern UE_MAC_INST *UE_mac_inst; extern eNB_MAC_INST *eNB_mac_inst; diff --git a/openair2/LAYER2/MAC/proto.h b/openair2/LAYER2/MAC/proto.h index 59d6c352fe..248f918dc1 100644 --- a/openair2/LAYER2/MAC/proto.h +++ b/openair2/LAYER2/MAC/proto.h @@ -551,7 +551,7 @@ int get_bsr_lcgid (module_id_t module_idP); \param[in] bufflen size of phy transport block \param[out] bsr_len size of bsr control element */ -uint8_t get_bsr_len (module_id_t module_idP, uint16_t buflen); +uint8_t get_bsr_len (module_id_t module_idP, uint8_t eNB_index,frame_t frameP,uint16_t buflen); /*! \fn BSR_SHORT * get_bsr_short(module_id_t module_idP, uint8_t bsr_len) \brief get short bsr level @@ -577,14 +577,14 @@ BSR_LONG * get_bsr_long(module_id_t module_idP, uint8_t bsr_len); */ boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_index, uint8_t lcid, uint8_t lcgid); -/*! \fn locate (int *table, int size, int value) +/*! \fn locate_BsrIndexByBufferSize (int *table, int size, int value) \brief locate the BSR level in the table as defined in 36.321. This function requires that he values in table to be monotonic, either increasing or decreasing. The returned value is not less than 0, nor greater than n-1, where n is the size of table. \param[in] *table Pointer to BSR table \param[in] size Size of the table \param[in] value Value of the buffer \return the index in the BSR_LEVEL table */ -uint8_t locate (const uint32_t *table, int size, int value); +uint8_t locate_BsrIndexByBufferSize (const uint32_t *table, int size, int value); /*! \fn int get_sf_periodicBSRTimer(uint8_t periodicBSR_Timer) diff --git a/openair2/LAYER2/MAC/ra_procedures.c b/openair2/LAYER2/MAC/ra_procedures.c index 30137fab33..3b5734756d 100644 --- a/openair2/LAYER2/MAC/ra_procedures.c +++ b/openair2/LAYER2/MAC/ra_procedures.c @@ -391,7 +391,7 @@ PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP,int CC_id,frame_t frameP, 1); //post_padding return(&UE_mac_inst[module_idP].RA_prach_resources); - } else if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[DCCH] > 0) { + } else if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH]] > 0) { // This is for triggering a transmission on DCCH using PRACH (during handover, or sending SR for example) dcch_header_len = 2 + 2; /// SHORT Subheader + C-RNTI control element rlc_status = mac_rlc_status_ind(module_idP,UE_mac_inst[module_idP].crnti, eNB_indexP,frameP,ENB_FLAG_NO,MBMS_FLAG_NO, diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c index d5958f6e5e..c24702b3b5 100644 --- a/openair2/LAYER2/MAC/ue_procedures.c +++ b/openair2/LAYER2/MAC/ue_procedures.c @@ -102,13 +102,17 @@ void ue_init_mac(module_id_t module_idP) UE_mac_inst[module_idP].scheduling_info.sr_ProhibitTimer_Running=0; UE_mac_inst[module_idP].scheduling_info.maxHARQ_Tx=MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5; UE_mac_inst[module_idP].scheduling_info.ttiBundling=0; + UE_mac_inst[module_idP].scheduling_info.extendedBSR_Sizes_r10=0; + UE_mac_inst[module_idP].scheduling_info.extendedPHR_r10=0; UE_mac_inst[module_idP].scheduling_info.drx_config=NULL; UE_mac_inst[module_idP].scheduling_info.phr_config=NULL; UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF = get_sf_periodicBSRTimer(UE_mac_inst[module_idP].scheduling_info.periodicBSR_Timer); UE_mac_inst[module_idP].scheduling_info.retxBSR_SF = get_sf_retxBSRTimer(UE_mac_inst[module_idP].scheduling_info.retxBSR_Timer); + UE_mac_inst[module_idP].BSR_reporting_active = 0; UE_mac_inst[module_idP].scheduling_info.periodicPHR_SF = get_sf_perioidicPHR_Timer(UE_mac_inst[module_idP].scheduling_info.periodicPHR_Timer); UE_mac_inst[module_idP].scheduling_info.prohibitPHR_SF = get_sf_prohibitPHR_Timer(UE_mac_inst[module_idP].scheduling_info.prohibitPHR_Timer); UE_mac_inst[module_idP].scheduling_info.PathlossChange_db = get_db_dl_PathlossChange(UE_mac_inst[module_idP].scheduling_info.PathlossChange); + UE_mac_inst[module_idP].PHR_reporting_active = 0; for (i=0; i < MAX_NUM_LCID; i++) { LOG_D(MAC,"[UE%d] Applying default logical channel config for LCGID %d\n",module_idP,i); @@ -121,7 +125,7 @@ void ue_init_mac(module_id_t module_idP) UE_mac_inst[module_idP].scheduling_info.LCGID[i]=1; } - UE_mac_inst[module_idP].scheduling_info.LCID_status[i]=0; + UE_mac_inst[module_idP].scheduling_info.LCID_status[i]=LCID_EMPTY; } #ifdef CBA @@ -306,18 +310,28 @@ uint32_t ue_get_SR(module_id_t module_idP,int CC_id,frame_t frameP,uint8_t eNB_i // initiate RA UE_mac_inst[module_idP].scheduling_info.SR_pending=0; UE_mac_inst[module_idP].scheduling_info.SR_COUNTER=0; + // release all pucch resource + UE_mac_inst[module_idP].physicalConfigDedicated = NULL; + UE_mac_inst[module_idP].ul_active=0; + UE_mac_inst[module_idP].BSR_reporting_active=0; + + LOG_T(MAC,"[UE %d] Release all SRs \n", module_idP); return(0); } } //------------------------------------------------------------------------------ void -ue_send_sdu(module_id_t module_idP, - uint8_t CC_id, - frame_t frameP, - uint8_t* sdu, - uint16_t sdu_len, - uint8_t eNB_index) { +ue_send_sdu( + module_id_t module_idP, + uint8_t CC_id, + frame_t frameP, + uint8_t* sdu, + uint16_t sdu_len, + uint8_t eNB_index +) +//------------------------------------------------------------------------------ +{ unsigned char rx_ces[MAX_NUM_CE],num_ce,num_sdu,i,*payload_ptr; unsigned char rx_lcids[NB_RB_MAX]; @@ -1244,11 +1258,12 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf BSR_LONG *bsr_l=&bsr_long; POWER_HEADROOM_CMD phr; POWER_HEADROOM_CMD *phr_p=&phr; - unsigned short short_padding=0, post_padding=0; + unsigned short short_padding=0, post_padding=0, padding_len=0; int lcgid; int j; // used for padding // Compute header length - + int all_pdu_len; + if (CC_id>0) { LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n"); mac_xface->macphy_exit("MAC FATAL CC_id>0"); @@ -1282,19 +1297,10 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf dtch_header_len=(buflen > 128 ) ? 3 : 2 ; //sizeof(SCH_SUBHEADER_LONG)-1 : sizeof(SCH_SUBHEADER_SHORT); bsr_header_len = 1;//sizeof(SCH_SUBHEADER_FIXED); phr_header_len = 1;//sizeof(SCH_SUBHEADER_FIXED); - phr_ce_len = (UE_mac_inst[module_idP].PHR_reporting_active == 1) ? 1 /* sizeof(POWER_HEADROOM_CMD)*/: 0; - if (phr_ce_len > 0) { - phr_len = phr_ce_len + phr_header_len; - LOG_D(MAC,"[UE %d] header size info: PHR len %d (ce%d,hdr%d) buff_len %d\n", - module_idP, phr_len, phr_ce_len, phr_header_len, buflen); - } else { - phr_len=0; - } - - bsr_ce_len = get_bsr_len (module_idP, buflen-phr_len); - - if (bsr_ce_len > 0 ) { + bsr_ce_len = get_bsr_len (module_idP, eNB_index, frameP, buflen); + // retxBSR-Timer expires or periodicBSR-Timer expires and Regular BSR trigger + if ((bsr_ce_len > 0 ) && (UE_mac_inst[module_idP].BSR_reporting_active > 0)) { bsr_len = bsr_ce_len + bsr_header_len; LOG_D(MAC,"[UE %d] header size info: dcch %d, dcch1 %d, dtch %d, bsr (ce%d,hdr%d) buff_len %d\n", module_idP, dcch_header_len,dcch1_header_len,dtch_header_len, bsr_ce_len, bsr_header_len, buflen); @@ -1305,6 +1311,15 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf //bsr_len = bsr_ce_len + bsr_header_len; } + phr_ce_len = (UE_mac_inst[module_idP].PHR_reporting_active == 1) ? 1 /* sizeof(POWER_HEADROOM_CMD)*/: 0; + if (phr_ce_len > 0) { + phr_len = phr_ce_len + phr_header_len; + LOG_D(MAC,"[UE %d] header size info: PHR len %d (ce%d,hdr%d) buff_len %d\n", + module_idP, phr_len, phr_ce_len, phr_header_len, buflen); + } else { + phr_len=0; + } + // check for UL bandwidth requests and add SR control element // check for UL bandwidth requests and add SR control element @@ -1338,8 +1353,12 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf sdu_lcids[0] = DCCH; LOG_D(MAC,"[UE %d] TX Got %d bytes for DCCH\n",module_idP,sdu_lengths[0]); num_sdus = 1; - update_bsr(module_idP, frameP, eNB_index, DCCH, UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH]); + //update_bsr(module_idP, frameP, eNB_index, DCCH, UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH]); //header_len +=2; + UE_mac_inst[module_idP].scheduling_info.LCID_status[DCCH] = LCID_EMPTY; +#if 0 //calvin for BSR test,current buffer greater then previous one, or buffer from 0 to !0 + UE_mac_inst[module_idP].scheduling_info.LCID_buffer_remain[DCCH] = rlc_status.bytes_in_buffer-sdu_lengths[0]; +#endif } else { dcch_header_len=0; num_sdus = 0; @@ -1375,9 +1394,13 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf sdu_length_total += sdu_lengths[num_sdus]; sdu_lcids[num_sdus] = DCCH1; LOG_D(MAC,"[UE %d] TX Got %d bytes for DCCH1\n",module_idP,sdu_lengths[num_sdus]); - num_sdus++; //update_bsr(module_idP, frameP, DCCH1); //dcch_header_len +=2; // include dcch1 + UE_mac_inst[module_idP].scheduling_info.LCID_status[DCCH1] = LCID_EMPTY; +#if 0 //calvin for BSR test,current buffer greater then previous one, or buffer from 0 to !0 + UE_mac_inst[module_idP].scheduling_info.LCID_buffer_remain[DCCH1] = rlc_status.bytes_in_buffer-sdu_lengths[num_sdus]; +#endif + num_sdus++; } else { dcch1_header_len =0; } @@ -1388,8 +1411,9 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf dtch_header_len+=3; dtch_header_len_last=3; + all_pdu_len = bsr_len+phr_len+dcch_header_len+dcch1_header_len+dtch_header_len+sdu_length_total; if ((UE_mac_inst[module_idP].scheduling_info.LCID_status[lcid] == LCID_NOT_EMPTY) && - ((bsr_len+phr_len+dcch_header_len+dcch1_header_len+dtch_header_len+sdu_length_total) <= buflen)) { + (all_pdu_len <= buflen)) { // optimize the dtch header lenght //if ((UE_mac_inst[module_idP].scheduling_info.BSR_bytes[DTCH] > 128) && @@ -1407,11 +1431,11 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf ENB_FLAG_NO, MBMS_FLAG_NO, // eNB_index lcid, - buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-dtch_header_len-sdu_length_total); + buflen-all_pdu_len); LOG_D(MAC,"[UE %d] Frame %d : UL-DTCH -> ULSCH%d, %d bytes to send (Transport Block size %d, mac header len %d, BSR byte[%d] %d)\n", module_idP,frameP, lcid, rlc_status.bytes_in_buffer,buflen,dtch_header_len, - lcid, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcid]); + lcid, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]]); if (rlc_status.bytes_in_buffer > 0) { sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP, @@ -1431,16 +1455,20 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf dtch_header_len --; dtch_header_len_last --; } +#if 0 //calvin for BSR test,current buffer greater then previous one, or buffer from 0 to !0 + UE_mac_inst[module_idP].scheduling_info.LCID_buffer_remain[lcid] = rlc_status.bytes_in_buffer-sdu_lengths[num_sdus]; +#endif num_sdus++; - UE_mac_inst[module_idP].ul_active = update_bsr(module_idP, frameP, eNB_index,lcid, UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]); + //UE_mac_inst[module_idP].ul_active = update_bsr(module_idP, frameP, eNB_index,lcid, UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]); } else { dtch_header_len -= 3; } + UE_mac_inst[module_idP].scheduling_info.LCID_status[lcid] = LCID_EMPTY; } else { // no rlc pdu : generate the dummy header dtch_header_len -= 3; } } - + lcgid= get_bsr_lcgid(module_idP); if (lcgid < 0 ) { @@ -1452,15 +1480,29 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf bsr_l->Buffer_size1 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1]; bsr_l->Buffer_size2 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2]; bsr_l->Buffer_size3 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3]; + LOG_D(MAC, "[UE %d] Frame %d report long BSR (level LCGID0 %d,level LCGID1 %d,level LCGID2 %d,level LCGID3 %d)\n", module_idP,frameP, UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0], UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1], UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2], UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3]); + + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[LCGID0] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[LCGID1] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[LCGID2] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[LCGID3] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID2] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3] = 0; } else if (bsr_ce_len == sizeof(BSR_SHORT)) { bsr_l = NULL; bsr_s->LCGID = lcgid; bsr_s->Buffer_size = UE_mac_inst[module_idP].scheduling_info.BSR[lcgid]; + + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR[lcgid] = 0; + LOG_D(MAC,"[UE %d] Frame %d report SHORT BSR with level %d for LCGID %d\n", module_idP, frameP, UE_mac_inst[module_idP].scheduling_info.BSR[lcgid],lcgid); } else { @@ -1494,12 +1536,14 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf dtch_header_len_last-=1; dtch_header_len= (dtch_header_len >0)? dtch_header_len - dtch_header_len_last : dtch_header_len; } - - if ((buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-dtch_header_len-sdu_length_total) <= 2) { - short_padding = buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-dtch_header_len-sdu_length_total; + // 1-bit padding or 2-bit padding special padding subheader + padding_len = buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-dtch_header_len-sdu_length_total; + if (padding_len <= 2) { + short_padding = padding_len; + // only add padding header post_padding = 0; } else { - if ((buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-dtch_header_len-sdu_length_total) == buflen) { + if (padding_len == buflen) {// nona mac pdu *access_mode=CANCELED_ACCESS; } @@ -1544,6 +1588,9 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf module_idP,payload_offset, sdu_length_total); UE_mac_inst[module_idP].scheduling_info.SR_pending=0; UE_mac_inst[module_idP].scheduling_info.SR_COUNTER=0; + UE_mac_inst[module_idP].BSR_reporting_active=0; + UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF = get_sf_periodicBSRTimer(UE_mac_inst[module_idP].scheduling_info.periodicBSR_Timer); + UE_mac_inst[module_idP].scheduling_info.retxBSR_SF = get_sf_retxBSRTimer(UE_mac_inst[module_idP].scheduling_info.retxBSR_Timer); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_GET_SDU, VCD_FUNCTION_OUT); stop_meas(&UE_mac_inst[module_idP].tx_ulsch_sdu); @@ -1705,10 +1752,25 @@ ue_scheduler( // call SR procedure to generate pending SR and BSR for next PUCCH/PUSCH TxOp. This should implement the procedures // outlined in Sections 5.4.4 an 5.4.5 of 36.321 - // Put this in another function + // Call BSR procedure as described in Section 5.4.5 in 36.321 + if (UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF == get_sf_periodicBSRTimer(MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_infinity)) { + UE_mac_inst[module_idP].BSR_reporting_active = 1; + } else if (UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF <= 0 ){ + // trigger BSR and reset the timer later when the BSR report is sent + UE_mac_inst[module_idP].BSR_reporting_active = 1; + } else if (UE_mac_inst[module_idP].BSR_reporting_active == 0 ) { + UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF--; + } + + if (UE_mac_inst[module_idP].scheduling_info.retxBSR_SF <= 0){ + // trigger BSR and reset the timer later when the BSR report is sent + UE_mac_inst[module_idP].BSR_reporting_active = 1; + } else if (UE_mac_inst[module_idP].BSR_reporting_active == 0 ) { + UE_mac_inst[module_idP].scheduling_info.retxBSR_SF--; + } // Get RLC status info and update Bj for all lcids that are active - for (lcid=DCCH; lcid <= DTCH; lcid++ ) { + for (lcid=DCCH; lcid < MAX_NUM_LCID; lcid++ ) { if ((lcid == 0) ||(UE_mac_inst[module_idP].logicalChannelConfig[lcid])) { // meausre the Bj if ((directionP == SF_UL)&& (UE_mac_inst[module_idP].scheduling_info.Bj[lcid] >= 0)) { @@ -1729,6 +1791,8 @@ ue_scheduler( if (update_bsr(module_idP,frameP, eNB_indexP, lcid, UE_mac_inst[module_idP].scheduling_info.LCGID[lcid])) { UE_mac_inst[module_idP].scheduling_info.SR_pending= 1; + // Regular BSR trigger + UE_mac_inst[module_idP].BSR_reporting_active = 1; LOG_D(MAC,"[UE %d][SR] Frame %d subframe %d SR for PUSCH is pending for LCGID %d with BSR level %d (%d bytes in RLC)\n", module_idP, frameP,subframeP,UE_mac_inst[module_idP].scheduling_info.LCGID[lcid], UE_mac_inst[module_idP].scheduling_info.BSR[UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]], @@ -1970,31 +2034,26 @@ int get_bsr_lcgid (module_id_t module_idP) } } -uint8_t get_bsr_len (module_id_t module_idP, uint16_t buflen) +uint8_t get_bsr_len (module_id_t module_idP, uint8_t eNB_index,frame_t frameP,uint16_t buflen) { - - int lcgid=0; - uint8_t bsr_len=0, num_lcgid=0; + int lcid; + uint8_t bsr_len=0, num_lcid=0; int pdu = 0; + mac_rlc_status_resp_t rlc_status; - - for (lcgid=0; lcgid < MAX_NUM_LCGID; lcgid++ ) { - if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] > 0 ) { - pdu += (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] + bsr_len + 2); //2 = sizeof(SCH_SUBHEADER_SHORT) + for (lcid=DCCH; lcid 0 ) { + pdu += rlc_status.bytes_in_buffer + sizeof(SCH_SUBHEADER_SHORT) + bsr_len; + if (rlc_status.bytes_in_buffer > 128 ) { + pdu += 1; //sizeof(SCH_SUBHEADER_LONG) + } } - - if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] > 128 ) { // long header size: adjust the header size - pdu += 1; + if ( (pdu > buflen) && (rlc_status.bytes_in_buffer > 0 ) ) { + num_lcid +=1; + bsr_len = (num_lcid >= 2 ) ? sizeof(BSR_LONG) : sizeof(BSR_SHORT) ; } - - // current phy buff can not transport all sdu for this lcgid -> transmit a bsr for this lcgid - - if ( (pdu > buflen) && (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] > 0 ) ) { - num_lcgid +=1; - bsr_len = (num_lcgid >= 2 ) ? sizeof(BSR_LONG) : sizeof(BSR_SHORT) ; - } - - LOG_D(MAC,"BSR Bytes %d for lcgid %d bsr len %d num lcgid %d\n", UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid], lcgid, bsr_len, num_lcgid); + LOG_D(MAC,"LC buffer Bytes %d for lcid %d bsr len %d num lcid %d\n", rlc_status.bytes_in_buffer, lcid, bsr_len, num_lcid); } if ( bsr_len > 0 ) @@ -2004,7 +2063,6 @@ uint8_t get_bsr_len (module_id_t module_idP, uint16_t buflen) return bsr_len; } - boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_index, uint8_t lcid, uint8_t lcg_id) { @@ -2028,11 +2086,17 @@ boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_in lcid, 0); - if (rlc_status.bytes_in_buffer > 0 ) { + if ((rlc_status.bytes_in_buffer > 0 ) +#if 0 //calvin for BSR test,current buffer greater then previous one, or buffer from 0 to !0 + && (rlc_status.bytes_in_buffer > UE_mac_inst[module_idP].scheduling_info.LCID_buffer_remain[lcid]) +#endif + ){ + //BSR trigger SR sr_pending = TRUE; UE_mac_inst[module_idP].scheduling_info.LCID_status[lcid] = LCID_NOT_EMPTY; - UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id] += locate (BSR_TABLE,BSR_TABLE_SIZE, rlc_status.bytes_in_buffer); + // sum lcid buffer which has same lcgid UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id] += rlc_status.bytes_in_buffer; + UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id] = locate_BsrIndexByBufferSize(BSR_TABLE, BSR_TABLE_SIZE, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id]); // UE_mac_inst[module_idP].scheduling_info.BSR_short_lcid = lcid; // only applicable to short bsr LOG_D(MAC,"[UE %d] BSR level %d (LCGID %d, rlc buffer %d byte)\n", module_idP, UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id],lcg_id, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id]); @@ -2045,7 +2109,7 @@ boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_in return sr_pending; } -uint8_t locate (const uint32_t *table, int size, int value) +uint8_t locate_BsrIndexByBufferSize (const uint32_t *table, int size, int value) { uint8_t ju, jm, jl; @@ -2076,7 +2140,7 @@ uint8_t locate (const uint32_t *table, int size, int value) if (value == table[jl]) { return jl; - } else { + } else { return jl+1; //equally ju } diff --git a/openair2/LAYER2/MAC/vars.h b/openair2/LAYER2/MAC/vars.h index 83d159f910..236439c6e5 100644 --- a/openair2/LAYER2/MAC/vars.h +++ b/openair2/LAYER2/MAC/vars.h @@ -45,6 +45,15 @@ const uint32_t BSR_TABLE[BSR_TABLE_SIZE]= {0,10,12,14,17,19,22,26,31,36,42,49,57 1326,1552,1817,2127,2490,2915,3413,3995,4677,5467,6411,7505,8787,10287,12043,14099, 16507,19325,22624,26487,31009,36304,42502,49759,58255,68201,79846,93479,109439, 128125,150000, 300000 }; +// extended bsr table--currently not used +const uint32_t Extended_BSR_TABLE[BSR_TABLE_SIZE] = {0,10,13,16,19,23,29,35,43,53,65,80,98,120,147, + 181,223,274,337,414,509,625,769,945,1162,1429, + 1757,2161,2657,3267,4017,4940,6074,7469,9185, + 11294,13888,17077,20999,25822,31752,39045,48012, + 59039,72598,89272,109774,134986,165989,204111, + 250990,308634,379519,466683,573866,705666,867737, + 1067031,1312097,1613447,1984009,2439678,3000000, + 6000000}; //uint32_t EBSR_Level[63]={0,10,13,16,19,23,29,35,43,53,65,80,98,120,147,181}; From f0f34c029b4718069ea3ed2379df0f309ac7b4a2 Mon Sep 17 00:00:00 2001 From: hbilel Date: Tue, 15 Nov 2016 16:13:24 +0100 Subject: [PATCH 7/7] BSR fixes with CMW500 --- openair2/LAYER2/MAC/config.c | 4 +- openair2/LAYER2/MAC/defs.h | 5 +- openair2/LAYER2/MAC/ue_procedures.c | 219 +++++++++++++++++++++++----- 3 files changed, 191 insertions(+), 37 deletions(-) diff --git a/openair2/LAYER2/MAC/config.c b/openair2/LAYER2/MAC/config.c index d46b761bd0..bca0149791 100644 --- a/openair2/LAYER2/MAC/config.c +++ b/openair2/LAYER2/MAC/config.c @@ -245,8 +245,8 @@ rrc_mac_config_req( UE_mac_inst[Mod_idP].scheduling_info.extendedPHR_r10 = (uint16_t)0; } #endif - UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_SF = get_sf_periodicBSRTimer(UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_Timer); - UE_mac_inst[Mod_idP].scheduling_info.retxBSR_SF = get_sf_retxBSRTimer(UE_mac_inst[Mod_idP].scheduling_info.retxBSR_Timer); + UE_mac_inst[Mod_idP].scheduling_info.periodicBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING; + UE_mac_inst[Mod_idP].scheduling_info.retxBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING; UE_mac_inst[Mod_idP].BSR_reporting_active = 0; LOG_D(MAC,"[UE %d]: periodic BSR %d (SF), retx BSR %d (SF)\n", diff --git a/openair2/LAYER2/MAC/defs.h b/openair2/LAYER2/MAC/defs.h index d38ca05362..336f3f1039 100644 --- a/openair2/LAYER2/MAC/defs.h +++ b/openair2/LAYER2/MAC/defs.h @@ -133,6 +133,7 @@ /*!\brief maximum value for channel quality indicator */ #define MAX_CQI_VALUE 15 +#define MAC_UE_BSR_TIMER_NOT_RUNNING (0xFFFF) #define LCID_EMPTY 0 #define LCID_NOT_EMPTY 1 @@ -962,11 +963,11 @@ typedef struct { /// retxBSR-Timer, default value is sf2560 uint16_t retxBSR_Timer; /// retxBSR_SF, number of subframe before triggering a regular BSR - int16_t retxBSR_SF; + uint16_t retxBSR_SF; /// periodicBSR-Timer, default to infinity uint16_t periodicBSR_Timer; /// periodicBSR_SF, number of subframe before triggering a periodic BSR - int16_t periodicBSR_SF; + uint16_t periodicBSR_SF; /// default value is 0: not configured uint16_t sr_ProhibitTimer; /// sr ProhibitTime running diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c index c24702b3b5..c2701c5f39 100644 --- a/openair2/LAYER2/MAC/ue_procedures.c +++ b/openair2/LAYER2/MAC/ue_procedures.c @@ -91,7 +91,7 @@ void ue_init_mac(module_id_t module_idP) // default values as deined in 36.331 sec 9.2.2 LOG_I(MAC,"[UE%d] Applying default macMainConfig\n",module_idP); //UE_mac_inst[module_idP].scheduling_info.macConfig=NULL; - UE_mac_inst[module_idP].scheduling_info.retxBSR_Timer= MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf2560; + UE_mac_inst[module_idP].scheduling_info.retxBSR_Timer= MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf10240; UE_mac_inst[module_idP].scheduling_info.periodicBSR_Timer=MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_infinity; UE_mac_inst[module_idP].scheduling_info.periodicPHR_Timer = MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20; UE_mac_inst[module_idP].scheduling_info.prohibitPHR_Timer = MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; @@ -106,8 +106,8 @@ void ue_init_mac(module_id_t module_idP) UE_mac_inst[module_idP].scheduling_info.extendedPHR_r10=0; UE_mac_inst[module_idP].scheduling_info.drx_config=NULL; UE_mac_inst[module_idP].scheduling_info.phr_config=NULL; - UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF = get_sf_periodicBSRTimer(UE_mac_inst[module_idP].scheduling_info.periodicBSR_Timer); - UE_mac_inst[module_idP].scheduling_info.retxBSR_SF = get_sf_retxBSRTimer(UE_mac_inst[module_idP].scheduling_info.retxBSR_Timer); + UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING; + UE_mac_inst[module_idP].scheduling_info.retxBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING; UE_mac_inst[module_idP].BSR_reporting_active = 0; UE_mac_inst[module_idP].scheduling_info.periodicPHR_SF = get_sf_perioidicPHR_Timer(UE_mac_inst[module_idP].scheduling_info.periodicPHR_Timer); UE_mac_inst[module_idP].scheduling_info.prohibitPHR_SF = get_sf_prohibitPHR_Timer(UE_mac_inst[module_idP].scheduling_info.prohibitPHR_Timer); @@ -308,14 +308,16 @@ uint32_t ue_get_SR(module_id_t module_idP,int CC_id,frame_t frameP,uint8_t eNB_i // notify RRC to relase PUCCH/SRS // clear any configured dl/ul // initiate RA + if (UE_mac_inst[module_idP].scheduling_info.SR_pending){ + // release all pucch resource + UE_mac_inst[module_idP].physicalConfigDedicated = NULL; + UE_mac_inst[module_idP].ul_active=0; + UE_mac_inst[module_idP].BSR_reporting_active=0; + + LOG_I(MAC,"[UE %d] Release all SRs \n", module_idP); + } UE_mac_inst[module_idP].scheduling_info.SR_pending=0; UE_mac_inst[module_idP].scheduling_info.SR_COUNTER=0; - // release all pucch resource - UE_mac_inst[module_idP].physicalConfigDedicated = NULL; - UE_mac_inst[module_idP].ul_active=0; - UE_mac_inst[module_idP].BSR_reporting_active=0; - - LOG_T(MAC,"[UE %d] Release all SRs \n", module_idP); return(0); } } @@ -1259,10 +1261,16 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf POWER_HEADROOM_CMD phr; POWER_HEADROOM_CMD *phr_p=&phr; unsigned short short_padding=0, post_padding=0, padding_len=0; - int lcgid; int j; // used for padding // Compute header length int all_pdu_len; + int lcg_id = 0; + int lcg_id_bsr_short = 0; + int num_lcg_id_with_data = 0; + + LOG_D(MAC,"[UE %d] MAC PROCESS UL TRANSPORT BLOCK at frame%d subframe %d TBS=%d\n", + module_idP, frameP, subframe, buflen); + if (CC_id>0) { LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n"); @@ -1295,10 +1303,83 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf dcch1_header_len=2;//sizeof(SCH_SUBHEADER_SHORT); // hypo length,in case of long header skip the padding byte dtch_header_len=(buflen > 128 ) ? 3 : 2 ; //sizeof(SCH_SUBHEADER_LONG)-1 : sizeof(SCH_SUBHEADER_SHORT); - bsr_header_len = 1;//sizeof(SCH_SUBHEADER_FIXED); + bsr_header_len = 0; phr_header_len = 1;//sizeof(SCH_SUBHEADER_FIXED); + while (lcg_id < MAX_NUM_LCGID) { + if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id]){ + num_lcg_id_with_data ++; + lcg_id_bsr_short = lcg_id; + } + lcg_id ++; + } + + if (num_lcg_id_with_data){ + LOG_I(MAC,"[UE %d] MAC Tx data pending at frame%d subframe %d nb LCG =%d LCG0 bytes=%d BSR Trigger status =%d TBS=%d\n", + module_idP, frameP, subframe, num_lcg_id_with_data, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[0],UE_mac_inst[module_idP].BSR_reporting_active, buflen); + + } + // ReTxBSR-Timer expires, trigger BSR + if ((num_lcg_id_with_data) && (UE_mac_inst[module_idP].scheduling_info.retxBSR_SF == 0)){ + + // If the UE has data to transmit, trigger a BSR + UE_mac_inst[module_idP].BSR_reporting_active = 1; + + LOG_I(MAC,"[UE %d] MAC BSR Triggered ReTxBSR Timer expiry at frame%d subframe %d TBS=%d\n", + module_idP, frameP, subframe, buflen); + + } + // periodicBSR-Timer expires, trigger BSR + if ((UE_mac_inst[module_idP].scheduling_info.periodicBSR_Timer != MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_infinity) + && (UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF == 0)){ + // Trigger BSR + UE_mac_inst[module_idP].BSR_reporting_active = 1; + + LOG_I(MAC,"[UE %d] MAC BSR Triggered PeriodicBSR Timer expiry at frame%d subframe %d TBS=%d\n", + module_idP, frameP, subframe, buflen); + + } + + //Compute BSR Length + if (UE_mac_inst[module_idP].BSR_reporting_active){ + if (buflen >= 4){ + if (num_lcg_id_with_data <= 1){ + bsr_ce_len = sizeof(BSR_SHORT); //1 byte + } + else{ + bsr_ce_len = sizeof(BSR_LONG); //3 bytes + } + + bsr_header_len = 1;//sizeof(SCH_SUBHEADER_FIXED); + // Reset Periodic and ReTx BSR Timer + UE_mac_inst[module_idP].scheduling_info.retxBSR_SF = get_sf_retxBSRTimer(UE_mac_inst[module_idP].scheduling_info.retxBSR_Timer); + + LOG_I(MAC,"[UE %d] MAC ReTx BSR Timer Reset =%d\n", + UE_mac_inst[module_idP].scheduling_info.retxBSR_SF); + + if (UE_mac_inst[module_idP].scheduling_info.periodicBSR_Timer != MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_infinity){ + UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF = get_sf_periodicBSRTimer(UE_mac_inst[module_idP].scheduling_info.periodicBSR_Timer); + + LOG_I(MAC,"[UE %d] MAC Periodic BSR Timer Reset =%d\n", + UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF); + + } + + LOG_I(MAC,"[UE %d] MAC BSR Triggered !! bsr (ce%d,hdr%d) buff_len %d\n", + module_idP, bsr_ce_len, bsr_header_len, buflen); + + } + else { + // Cancel Regular and Periodic BSR if Grant is smaller than 4 bytes + UE_mac_inst[module_idP].BSR_reporting_active = 0; + bsr_header_len = 0; + } + } + bsr_len = bsr_ce_len + bsr_header_len; +#if 0 bsr_ce_len = get_bsr_len (module_idP, eNB_index, frameP, buflen); + + // retxBSR-Timer expires or periodicBSR-Timer expires and Regular BSR trigger if ((bsr_ce_len > 0 ) && (UE_mac_inst[module_idP].BSR_reporting_active > 0)) { bsr_len = bsr_ce_len + bsr_header_len; @@ -1310,6 +1391,7 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf // bsr_ce_len = sizeof(BSR_LONG); //bsr_len = bsr_ce_len + bsr_header_len; } +#endif phr_ce_len = (UE_mac_inst[module_idP].PHR_reporting_active == 1) ? 1 /* sizeof(POWER_HEADROOM_CMD)*/: 0; if (phr_ce_len > 0) { @@ -1336,9 +1418,22 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf MBMS_FLAG_NO, // eNB_index DCCH, (buflen-dcch_header_len-bsr_len-phr_len)); - LOG_D(MAC, "[UE %d] Frame %d : UL-DCCH -> ULSCH, RRC message has %d bytes to " - "send (Transport Block size %d, mac header len %d)\n", - module_idP,frameP, rlc_status.bytes_in_buffer,buflen,dcch_header_len); + LOG_D(MAC, "[UE %d] Frame %d : UL-DCCH -> ULSCH, RLC SRB1 has %d bytes to " + "send (Transport Block size %d BSR size=%d PHR=%d SDU Length Total %d , mac header len %d)\n", + module_idP,frameP, rlc_status.bytes_in_buffer,buflen,bsr_len,phr_len,sdu_length_total,dcch_header_len); + + /* Update BSR : substract transmitted data */ + if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH]] >= rlc_status.bytes_in_buffer){ + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH]] -= rlc_status.bytes_in_buffer; + } + else if (rlc_status.bytes_in_buffer){ + LOG_I(MAC, "[UE %d] Frame %d Subframe%d: WARNING Buffer occupancy =%d for LCGID%d is lower than data to transmit=%d for LCID%d\n", + module_idP,frameP,subframe, + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH]], + UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH], + rlc_status.bytes_in_buffer,DCCH); + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH]] = 0; + } sdu_lengths[0] += mac_rlc_data_req(module_idP, UE_mac_inst[module_idP].crnti, @@ -1351,7 +1446,7 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf sdu_length_total += sdu_lengths[0]; sdu_lcids[0] = DCCH; - LOG_D(MAC,"[UE %d] TX Got %d bytes for DCCH\n",module_idP,sdu_lengths[0]); + LOG_D(MAC,"[UE %d] TX Multiplex RLC PDU TX Got %d bytes for SRB1\n",module_idP,sdu_lengths[0]); num_sdus = 1; //update_bsr(module_idP, frameP, eNB_index, DCCH, UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH]); //header_len +=2; @@ -1379,9 +1474,22 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf DCCH1, (buflen-bsr_len-phr_len-dcch_header_len-dcch1_header_len-sdu_length_total)); - LOG_D(MAC,"[UE %d] Frame %d : UL-DCCH1 -> ULSCH, RRC message has %d bytes to" - " send (Transport Block size %d, mac header len %d)\n", - module_idP,frameP, rlc_status.bytes_in_buffer,buflen,dcch1_header_len); + LOG_D(MAC,"[UE %d] Frame %d subframe %d: UL-DCCH1 -> ULSCH, RLC SRB2 has %d bytes to" + " send (Transport Block size %d BSR size=%d PHR=%d SRB1 Hdr %d SDU Length Total %d , mac header len %d)\n", + module_idP,frameP, subframe, rlc_status.bytes_in_buffer,buflen,bsr_len,phr_len,dcch_header_len,sdu_length_total,dcch1_header_len); + + /* Update BSR : substract transmitted data */ + if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH1]] >= rlc_status.bytes_in_buffer){ + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH1]] -= rlc_status.bytes_in_buffer; + } + else if (rlc_status.bytes_in_buffer){ + LOG_I(MAC, "[UE %d] Frame %d Subframe%d: WARNING Buffer occupancy =%d for LCGID%d is lower than data to transmit=%d for LCID%d\n", + module_idP,frameP,subframe, + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH1]], + UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH1], + rlc_status.bytes_in_buffer,DCCH1); + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[DCCH1]] = 0; + } sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP, UE_mac_inst[module_idP].crnti, @@ -1393,7 +1501,7 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf (char *)&ulsch_buff[sdu_lengths[num_sdus]]); sdu_length_total += sdu_lengths[num_sdus]; sdu_lcids[num_sdus] = DCCH1; - LOG_D(MAC,"[UE %d] TX Got %d bytes for DCCH1\n",module_idP,sdu_lengths[num_sdus]); + LOG_D(MAC,"[UE %d] TX Multiplex RLC PDU Got %d bytes for SRB2\n",module_idP,sdu_lengths[num_sdus]); //update_bsr(module_idP, frameP, DCCH1); //dcch_header_len +=2; // include dcch1 UE_mac_inst[module_idP].scheduling_info.LCID_status[DCCH1] = LCID_EMPTY; @@ -1438,6 +1546,19 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf lcid, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]]); if (rlc_status.bytes_in_buffer > 0) { + /* Update BSR : substract transmitted data */ + if (UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]] >= rlc_status.bytes_in_buffer){ + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]] -= rlc_status.bytes_in_buffer; + } + else { + LOG_I(MAC, "[UE %d] Frame %d Subframe%d: WARNING Buffer occupancy =%d for LCGID%d is lower than data to transmit=%d for LCID%d\n", + module_idP,frameP,subframe, + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]], + UE_mac_inst[module_idP].scheduling_info.LCGID[lcid], + rlc_status.bytes_in_buffer,lcid); + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[UE_mac_inst[module_idP].scheduling_info.LCGID[lcid]] = 0; + } + sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP, UE_mac_inst[module_idP].crnti, eNB_index, @@ -1469,12 +1590,18 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf } } - lcgid= get_bsr_lcgid(module_idP); + //lcgid= get_bsr_lcgid(module_idP); - if (lcgid < 0 ) { + // Compute BSR Values + for (lcg_id=0;lcg_idBuffer_size0 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID0]; bsr_l->Buffer_size1 = UE_mac_inst[module_idP].scheduling_info.BSR[LCGID1]; @@ -1497,14 +1624,14 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf UE_mac_inst[module_idP].scheduling_info.BSR[LCGID3] = 0; } else if (bsr_ce_len == sizeof(BSR_SHORT)) { bsr_l = NULL; - bsr_s->LCGID = lcgid; - bsr_s->Buffer_size = UE_mac_inst[module_idP].scheduling_info.BSR[lcgid]; + bsr_s->LCGID = lcg_id_bsr_short; + bsr_s->Buffer_size = UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id_bsr_short]; - UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcgid] = 0; - UE_mac_inst[module_idP].scheduling_info.BSR[lcgid] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id_bsr_short] = 0; + UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id_bsr_short] = 0; LOG_D(MAC,"[UE %d] Frame %d report SHORT BSR with level %d for LCGID %d\n", - module_idP, frameP, UE_mac_inst[module_idP].scheduling_info.BSR[lcgid],lcgid); + module_idP, frameP, UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id_bsr_short],lcg_id_bsr_short); } else { bsr_s = NULL; bsr_l = NULL; @@ -1589,8 +1716,6 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf UE_mac_inst[module_idP].scheduling_info.SR_pending=0; UE_mac_inst[module_idP].scheduling_info.SR_COUNTER=0; UE_mac_inst[module_idP].BSR_reporting_active=0; - UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF = get_sf_periodicBSRTimer(UE_mac_inst[module_idP].scheduling_info.periodicBSR_Timer); - UE_mac_inst[module_idP].scheduling_info.retxBSR_SF = get_sf_retxBSRTimer(UE_mac_inst[module_idP].scheduling_info.retxBSR_Timer); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_GET_SDU, VCD_FUNCTION_OUT); stop_meas(&UE_mac_inst[module_idP].tx_ulsch_sdu); @@ -1753,6 +1878,23 @@ ue_scheduler( // call SR procedure to generate pending SR and BSR for next PUCCH/PUSCH TxOp. This should implement the procedures // outlined in Sections 5.4.4 an 5.4.5 of 36.321 // Call BSR procedure as described in Section 5.4.5 in 36.321 + + // TODO : Fix Periodic and ReTx BSR Timers + // First check ReTxBSR Timer because it is always configured +#if 1 + // Decrement ReTxBSR Timer if it is running and not null + if ((UE_mac_inst[module_idP].scheduling_info.retxBSR_SF != MAC_UE_BSR_TIMER_NOT_RUNNING) + && (UE_mac_inst[module_idP].scheduling_info.retxBSR_SF != 0)){ + UE_mac_inst[module_idP].scheduling_info.retxBSR_SF --; + } + + // Decrement Periodic Timer if it is running and not null + if ((UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF != MAC_UE_BSR_TIMER_NOT_RUNNING) + && (UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF != 0)){ + UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF --; + } + +#else if (UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF == get_sf_periodicBSRTimer(MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_infinity)) { UE_mac_inst[module_idP].BSR_reporting_active = 1; } else if (UE_mac_inst[module_idP].scheduling_info.periodicBSR_SF <= 0 ){ @@ -1768,6 +1910,7 @@ ue_scheduler( } else if (UE_mac_inst[module_idP].BSR_reporting_active == 0 ) { UE_mac_inst[module_idP].scheduling_info.retxBSR_SF--; } +#endif // Get RLC status info and update Bj for all lcids that are active for (lcid=DCCH; lcid < MAX_NUM_LCID; lcid++ ) { @@ -2053,12 +2196,22 @@ uint8_t get_bsr_len (module_id_t module_idP, uint8_t eNB_index,frame_t frameP,ui num_lcid +=1; bsr_len = (num_lcid >= 2 ) ? sizeof(BSR_LONG) : sizeof(BSR_SHORT) ; } + else if (rlc_status.bytes_in_buffer) { + LOG_I(MAC,"pdu smaller than TBS! pdu=%d TBS=%d lcid=%d rlc buffer=%d bsr len=%d num lcid=%d\n",pdu,buflen,lcid,rlc_status.bytes_in_buffer,bsr_len, num_lcid); + } LOG_D(MAC,"LC buffer Bytes %d for lcid %d bsr len %d num lcid %d\n", rlc_status.bytes_in_buffer, lcid, bsr_len, num_lcid); } if ( bsr_len > 0 ) - LOG_D(MAC,"[UE %d] Prepare a %s (Transport Block Size %d, MAC pdu Size %d) \n", - module_idP, map_int_to_str(BSR_names, bsr_len), buflen, pdu); + { + LOG_D(MAC,"[UE %d] Prepare a %s (Transport Block Size %d, MAC pdu Size %d) \n", + module_idP, map_int_to_str(BSR_names, bsr_len), buflen, pdu); + } + else if (rlc_status.bytes_in_buffer){ + LOG_I(MAC,"[UE %d] UL Transport Block size is 0 while RLC has pending data=%d pdu=%d\n", + module_idP, rlc_status.bytes_in_buffer,pdu); + + } return bsr_len; } @@ -2098,8 +2251,8 @@ boolean_t update_bsr(module_id_t module_idP, frame_t frameP, eNB_index_t eNB_in UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id] += rlc_status.bytes_in_buffer; UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id] = locate_BsrIndexByBufferSize(BSR_TABLE, BSR_TABLE_SIZE, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id]); // UE_mac_inst[module_idP].scheduling_info.BSR_short_lcid = lcid; // only applicable to short bsr - LOG_D(MAC,"[UE %d] BSR level %d (LCGID %d, rlc buffer %d byte)\n", - module_idP, UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id],lcg_id, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id]); + LOG_D(MAC,"[UE %d] SR Triggered BSR level %d (LCID %d LCGID %d, rlc buffer=%d byte Total BO=%d)\n", + module_idP, UE_mac_inst[module_idP].scheduling_info.BSR[lcg_id],lcid,lcg_id, rlc_status.bytes_in_buffer, UE_mac_inst[module_idP].scheduling_info.BSR_bytes[lcg_id]); } else { UE_mac_inst[module_idP].scheduling_info.LCID_status[lcid]=LCID_EMPTY; }