@ -219,9 +219,9 @@ uint32_t bsr_proc::get_buffer_state_lcg(uint32_t lcg)
return n ;
return n ;
}
}
bool bsr_proc : : generate_bsr ( bsr_t * bsr , uint32_t nof_padding_bytes )
bool bsr_proc : : generate_bsr ( bsr_t * bsr , uint32_t pdu_space )
{
{
bool ret = false ;
bool send_bs r = false ;
uint32_t nof_lcg = 0 ;
uint32_t nof_lcg = 0 ;
bzero ( bsr , sizeof ( bsr_t ) ) ;
bzero ( bsr , sizeof ( bsr_t ) ) ;
@ -230,13 +230,22 @@ bool bsr_proc::generate_bsr(bsr_t* bsr, uint32_t nof_padding_bytes)
bsr - > buff_size [ i ] = get_buffer_state_lcg ( i ) ;
bsr - > buff_size [ i ] = get_buffer_state_lcg ( i ) ;
if ( bsr - > buff_size [ i ] > 0 ) {
if ( bsr - > buff_size [ i ] > 0 ) {
nof_lcg + + ;
nof_lcg + + ;
ret = true ;
}
}
}
}
if ( triggered_bsr_type = = PADDING ) {
if ( nof_padding_bytes < 4 ) {
if ( pdu_space > = CE_SUBHEADER_LEN + ce_size ( srslte : : ul_sch_lcid : : LONG_BSR ) ) {
// If space only for short
// we could fit a long BSR
if ( triggered_bsr_type ! = PADDING & & nof_lcg < = 1 ) {
// for Regular and periodic BSR we still send a short BSR if only one LCG has data to send
bsr - > format = SHORT_BSR ;
} else {
bsr - > format = LONG_BSR ;
}
send_bsr = true ;
} else if ( pdu_space > = CE_SUBHEADER_LEN + ce_size ( srslte : : ul_sch_lcid : : SHORT_BSR ) ) {
// we can only fit a short or truncated BSR
if ( nof_lcg > 1 ) {
if ( nof_lcg > 1 ) {
// only send truncated BSR for a padding BSR
bsr - > format = TRUNC_BSR ;
bsr - > format = TRUNC_BSR ;
uint32_t max_prio_lcg = find_max_priority_lcg_with_data ( ) ;
uint32_t max_prio_lcg = find_max_priority_lcg_with_data ( ) ;
for ( uint32_t i = 0 ; i < NOF_LCG ; i + + ) {
for ( uint32_t i = 0 ; i < NOF_LCG ; i + + ) {
@ -247,16 +256,10 @@ bool bsr_proc::generate_bsr(bsr_t* bsr, uint32_t nof_padding_bytes)
} else {
} else {
bsr - > format = SHORT_BSR ;
bsr - > format = SHORT_BSR ;
}
}
} else {
send_bsr = true ;
// If space for long BSR
bsr - > format = LONG_BSR ;
}
} else {
bsr - > format = SHORT_BSR ;
if ( nof_lcg > 1 ) {
bsr - > format = LONG_BSR ;
}
}
}
if ( send_bsr ) {
Info ( " BSR: Type %s, Format %s, Value=%d,%d,%d,%d \n " ,
Info ( " BSR: Type %s, Format %s, Value=%d,%d,%d,%d \n " ,
bsr_type_tostring ( triggered_bsr_type ) ,
bsr_type_tostring ( triggered_bsr_type ) ,
bsr_format_tostring ( bsr - > format ) ,
bsr_format_tostring ( bsr - > format ) ,
@ -270,8 +273,9 @@ bool bsr_proc::generate_bsr(bsr_t* bsr, uint32_t nof_padding_bytes)
timer_periodic . run ( ) ;
timer_periodic . run ( ) ;
Debug ( " BSR: Started periodicBSR-Timer \n " ) ;
Debug ( " BSR: Started periodicBSR-Timer \n " ) ;
}
}
}
return ret ;
return send_bs r;
}
}
// Checks if Regular BSR must be assembled, as defined in 5.4.5
// Checks if Regular BSR must be assembled, as defined in 5.4.5
@ -332,19 +336,8 @@ bool bsr_proc::need_to_send_bsr_on_ul_grant(uint32_t grant_size, bsr_t* bsr)
bool bsr_included = false ;
bool bsr_included = false ;
uint32_t bsr_sz = 0 ;
if ( triggered_bsr_type = = PERIODIC | | triggered_bsr_type = = REGULAR ) {
if ( triggered_bsr_type = = PERIODIC | | triggered_bsr_type = = REGULAR ) {
bsr_included = generate_bsr ( bsr , grant_size ) ;
generate_bsr ( bsr , 0 ) ;
// Only include BSR if it can fit into the remaining grant
bsr_sz = bsr - > format = = LONG_BSR ? 3 : 1 ;
if ( bsr_sz > grant_size ) {
Debug ( " Grant is not enough to accommodate the BSR MAC CE \n " ) ;
} else {
Debug ( " BSR: Including Regular BSR: grant_size=%d, bsr_sz=%d \n " , grant_size , bsr_sz ) ;
bsr_included = true ;
}
}
}
// All triggered BSRs shall be cancelled in case the UL grant can accommodate all pending data available for
// All triggered BSRs shall be cancelled in case the UL grant can accommodate all pending data available for
@ -383,7 +376,7 @@ bool bsr_proc::generate_padding_bsr(uint32_t nof_padding_bytes, bsr_t* bsr)
bool ret = false ;
bool ret = false ;
// This function is called by MUX only if Regular BSR has not been triggered before
// This function is called by MUX only if Regular BSR has not been triggered before
if ( nof_padding_bytes > = 2 ) {
if ( nof_padding_bytes > = CE_SUBHEADER_LEN + ce_size ( srslte : : ul_sch_lcid : : SHORT_BSR ) ) {
// generate padding BSR
// generate padding BSR
set_trigger ( PADDING ) ;
set_trigger ( PADDING ) ;
generate_bsr ( bsr , nof_padding_bytes ) ;
generate_bsr ( bsr , nof_padding_bytes ) ;