This commit is contained in:
laurent
2022-09-22 16:57:20 +02:00
188 changed files with 4242 additions and 3241 deletions
+10 -1
View File
@@ -3498,6 +3498,15 @@ void csi_period_offset(NR_CSI_ReportConfig_t *csirep,
}
}
uint8_t get_BG(uint32_t A, uint16_t R) {
float code_rate = (float) R / 10240.0f;
if ((A <=292) || ((A<=3824) && (code_rate <= 0.6667)) || code_rate <= 0.25)
return 2;
else
return 1;
}
uint32_t get_Y(NR_SearchSpace_t *ss, int slot, rnti_t rnti) {
if(ss->searchSpaceType->present == NR_SearchSpace__searchSpaceType_PR_common)
@@ -3571,7 +3580,7 @@ void get_type0_PDCCH_CSS_config_parameters(NR_Type0_PDCCH_CSS_config_t *type0_PD
// type0-pdcch coreset
switch( ((int)scs_ssb << 3) | (int)scs_pdcch ){
case (NR_SubcarrierSpacing_kHz15 << 5) | NR_SubcarrierSpacing_kHz15:
case (NR_SubcarrierSpacing_kHz15 << 3) | NR_SubcarrierSpacing_kHz15:
AssertFatal(index_4msb < 15, "38.213 Table 13-1 4 MSB out of range\n");
type0_PDCCH_CSS_config->type0_pdcch_ss_mux_pattern = 1;
type0_PDCCH_CSS_config->num_rbs = table_38213_13_1_c2[index_4msb];
@@ -40,6 +40,8 @@
uint32_t get_Y(NR_SearchSpace_t *ss, int slot, rnti_t rnti);
uint8_t get_BG(uint32_t A, uint16_t R);
uint64_t from_nrarfcn(int nr_bandP, uint8_t scs_index, uint32_t dl_nrarfcn);
uint32_t to_nrarfcn(int nr_bandP, uint64_t dl_CarrierFreq, uint8_t scs_index, uint32_t bw);
@@ -133,6 +133,9 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
gNB->tdd_beam_association[i] = -1;
}
gNB->frame = frame;
gNB->slot = slot;
start_meas(&RC.nrmac[module_idP]->eNB_scheduler);
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_IN);
+17 -11
View File
@@ -458,18 +458,18 @@ void nr_schedule_msg2(uint16_t rach_frame, uint16_t rach_slot,
// slot and frame limit to transmit msg2 according to response window
uint8_t slot_limit = (rach_slot + slot_window)%nr_slots_per_frame[mu];
uint16_t frame_limit = (slot_limit>(rach_slot))? rach_frame : (rach_frame +1);
uint16_t frame_limit = rach_frame + (rach_slot + slot_window)/nr_slots_per_frame[mu];
// computing start of next period
int FR = *scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0] >= 257 ? nr_FR2 : nr_FR1;
uint8_t start_next_period = rach_slot-(rach_slot%tdd_period_slot)+tdd_period_slot;
int eff_slot = start_next_period + last_dl_slot_period; // initializing scheduling of slot to next mixed (or last dl) slot
// we can't schedule msg2 before sl_ahead since prach
while ((eff_slot-rach_slot)<=sl_ahead) {
eff_slot += tdd_period_slot;
}
int FR = *scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0] >= 257 ? nr_FR2 : nr_FR1;
if (FR==nr_FR2) {
int num_tdd_period = (eff_slot%nr_slots_per_frame[mu])/tdd_period_slot;
while((tdd_beam_association[num_tdd_period]!=-1)&&(tdd_beam_association[num_tdd_period]!=beam_index)) {
@@ -480,8 +480,9 @@ void nr_schedule_msg2(uint16_t rach_frame, uint16_t rach_slot,
tdd_beam_association[num_tdd_period] = beam_index;
}
*msg2_frame=(rach_frame + eff_slot/nr_slots_per_frame[mu])%1024;
*msg2_slot=eff_slot%nr_slots_per_frame[mu];
*msg2_frame = rach_frame + eff_slot / nr_slots_per_frame[mu];
*msg2_slot = eff_slot % nr_slots_per_frame[mu];
// go to previous slot if the current scheduled slot is beyond the response window
// and if the slot is not among the PDCCH monitored ones (38.213 10.1)
while (*msg2_frame > frame_limit
@@ -490,10 +491,7 @@ void nr_schedule_msg2(uint16_t rach_frame, uint16_t rach_slot,
if((frame_type == FDD) || ((*msg2_slot%tdd_period_slot) > 0)) {
if (*msg2_slot==0) {
if(*msg2_frame != 0)
(*msg2_frame)--;
else
*msg2_frame = 1023;
(*msg2_frame)--;
*msg2_slot = nr_slots_per_frame[mu] - 1;
}
else
@@ -502,6 +500,9 @@ void nr_schedule_msg2(uint16_t rach_frame, uint16_t rach_slot,
else
AssertFatal(1==0,"No available DL slot to schedule msg2 has been found");
}
// calculate frame number considering wrap-around
*msg2_frame = *msg2_frame % 1024;
}
@@ -1057,6 +1058,8 @@ void fill_msg3_pusch_pdu(nfapi_nr_pusch_pdu_t *pusch_pdu,
pusch_pdu->mcs_index = mcsindex;
pusch_pdu->pusch_data.tb_size = TBS;
pusch_pdu->maintenance_parms_v3.ldpcBaseGraph = get_BG(TBS<<3,R);
}
}
@@ -1322,6 +1325,7 @@ void nr_generate_Msg2(module_id_t module_idP, int CC_id, frame_t frameP, sub_fra
pdsch_pdu_rel15->maintenance_parms_v3.tbSizeLbrmBytes = nr_compute_tbslbrm(mcsTableIdx,
bw_tbslbrm,
1);
pdsch_pdu_rel15->maintenance_parms_v3.ldpcBaseGraph = get_BG(TBS<<3,R);
// Fill PDCCH DL DCI PDU
nfapi_nr_dl_dci_pdu_t *dci_pdu = &pdcch_pdu_rel15->dci_pdu[pdcch_pdu_rel15->numDlDci];
@@ -1674,7 +1678,8 @@ void nr_generate_Msg4(module_id_t module_idP, int CC_id, frame_t frameP, sub_fra
pdsch_pdu_rel15->NrOfCodewords = 1;
int R = nr_get_code_rate_dl(mcsIndex,mcsTableIdx);
pdsch_pdu_rel15->targetCodeRate[0] = R;
pdsch_pdu_rel15->qamModOrder[0] = 2;
int Qm = nr_get_Qm_dl(mcsIndex, mcsTableIdx);
pdsch_pdu_rel15->qamModOrder[0] = Qm;
pdsch_pdu_rel15->mcsIndex[0] = mcsIndex;
pdsch_pdu_rel15->mcsTable[0] = mcsTableIdx;
pdsch_pdu_rel15->rvIndex[0] = nr_rv_round_map[harq->round%4];
@@ -1703,6 +1708,7 @@ void nr_generate_Msg4(module_id_t module_idP, int CC_id, frame_t frameP, sub_fra
pdsch_pdu_rel15->maintenance_parms_v3.tbSizeLbrmBytes = nr_compute_tbslbrm(mcsTableIdx,
bw_tbslbrm,
1);
pdsch_pdu_rel15->maintenance_parms_v3.ldpcBaseGraph = get_BG(harq->tb_size<<3,R);
pdsch_pdu_rel15->precodingAndBeamforming.num_prgs=1;
pdsch_pdu_rel15->precodingAndBeamforming.prg_size=275;
@@ -433,10 +433,10 @@ void nr_fill_nfapi_dl_sib1_pdu(int Mod_idP,
pdsch_pdu_rel15->CyclicPrefix = 0;
pdsch_pdu_rel15->NrOfCodewords = 1;
pdsch_pdu_rel15->targetCodeRate[0] = nr_get_code_rate_dl(gNB_mac->sched_ctrlCommon->sched_pdsch.mcs, 0);
pdsch_pdu_rel15->qamModOrder[0] = 2;
pdsch_pdu_rel15->targetCodeRate[0] = nr_get_code_rate_dl(gNB_mac->sched_ctrlCommon->sched_pdsch.mcs, mcsTableIdx);
pdsch_pdu_rel15->qamModOrder[0] = nr_get_Qm_dl(gNB_mac->sched_ctrlCommon->sched_pdsch.mcs, mcsTableIdx);
pdsch_pdu_rel15->mcsIndex[0] = gNB_mac->sched_ctrlCommon->sched_pdsch.mcs;
pdsch_pdu_rel15->mcsTable[0] = 0;
pdsch_pdu_rel15->mcsTable[0] = mcsTableIdx;
pdsch_pdu_rel15->rvIndex[0] = 0;
pdsch_pdu_rel15->dataScramblingId = *scc->physCellId;
pdsch_pdu_rel15->nrOfLayers = 1;
@@ -451,10 +451,7 @@ void nr_fill_nfapi_dl_sib1_pdu(int Mod_idP,
pdsch_pdu_rel15->rbStart = gNB_mac->sched_ctrlCommon->sched_pdsch.rbStart;
pdsch_pdu_rel15->rbSize = gNB_mac->sched_ctrlCommon->sched_pdsch.rbSize;
pdsch_pdu_rel15->VRBtoPRBMapping = 0;
pdsch_pdu_rel15->qamModOrder[0] = nr_get_Qm_dl(gNB_mac->sched_ctrlCommon->sched_pdsch.mcs,
mcsTableIdx);
pdsch_pdu_rel15->TBSize[0] = TBS;
pdsch_pdu_rel15->mcsTable[0] = mcsTableIdx;
pdsch_pdu_rel15->StartSymbolIndex = StartSymbolIndex;
pdsch_pdu_rel15->NrOfSymbols = NrOfSymbols;
pdsch_pdu_rel15->dlDmrsSymbPos = dlDmrsSymbPos;
@@ -465,6 +462,7 @@ void nr_fill_nfapi_dl_sib1_pdu(int Mod_idP,
pdsch_pdu_rel15->maintenance_parms_v3.tbSizeLbrmBytes = nr_compute_tbslbrm(0,
pdsch_pdu_rel15->BWPSize,
1);
pdsch_pdu_rel15->maintenance_parms_v3.ldpcBaseGraph = get_BG(TBS<<3,pdsch_pdu_rel15->targetCodeRate[0]);
/* Fill PDCCH DL DCI PDU */
nfapi_nr_dl_dci_pdu_t *dci_pdu = &pdcch_pdu_rel15->dci_pdu[pdcch_pdu_rel15->numDlDci];
@@ -896,6 +896,7 @@ void nr_schedule_ue_spec(module_id_t module_id,
NR_sched_pdsch_t *sched_pdsch = &sched_ctrl->sched_pdsch;
UE->mac_stats.dl.current_bytes = 0;
UE->mac_stats.dl.current_rbs = 0;
NR_CellGroupConfig_t *cg = UE->CellGroup;
/* update TA and set ta_apply every 10 frames.
@@ -1070,6 +1071,7 @@ void nr_schedule_ue_spec(module_id_t module_id,
pdsch_pdu->maintenance_parms_v3.tbSizeLbrmBytes = nr_compute_tbslbrm(current_BWP->mcsTableIdx,
bw_tbslbrm,
nl_tbslbrm);
pdsch_pdu->maintenance_parms_v3.ldpcBaseGraph = get_BG(TBS<<3,R);
NR_PDSCH_Config_t *pdsch_Config = current_BWP->pdsch_Config;
@@ -1195,6 +1197,7 @@ void nr_schedule_ue_spec(module_id_t module_id,
current_harq_pid);
T(T_GNB_MAC_RETRANSMISSION_DL_PDU_WITH_DATA, T_INT(module_id), T_INT(CC_id), T_INT(rnti),
T_INT(frame), T_INT(slot), T_INT(current_harq_pid), T_INT(harq->round), T_BUFFER(harq->transportBlock, TBS));
UE->mac_stats.dl.total_rbs_retx += sched_pdsch->rbSize;
} else { /* initial transmission */
LOG_D(NR_MAC, "[%s] Initial HARQ transmission in %d.%d\n", __FUNCTION__, frame, slot);
uint8_t *buf = (uint8_t *) harq->transportBlock;
@@ -1210,6 +1213,7 @@ void nr_schedule_ue_spec(module_id_t module_id,
int dlsch_total_bytes = 0;
/* next, get RLC data */
start_meas(&gNB_mac->rlc_data_req);
int sdus = 0;
if (sched_ctrl->num_total_bytes > 0) {
/* loop over all activated logical channels */
@@ -1261,6 +1265,7 @@ void nr_schedule_ue_spec(module_id_t module_id,
buf += len+sizeof(NR_MAC_SUBHEADER_LONG);
dlsch_total_bytes += len;
lcid_bytes += len;
sdus += 1;
}
UE->mac_stats.dl.lc_bytes[lcid] += lcid_bytes;
@@ -1288,6 +1293,7 @@ void nr_schedule_ue_spec(module_id_t module_id,
}
for (; buf < bufEnd; buf++)
*buf = lrand48() & 0xff;
sdus +=1;
}
}
@@ -1305,6 +1311,10 @@ void nr_schedule_ue_spec(module_id_t module_id,
UE->mac_stats.dl.total_bytes += TBS;
UE->mac_stats.dl.current_bytes = TBS;
UE->mac_stats.dl.total_rbs += sched_pdsch->rbSize;
UE->mac_stats.dl.num_mac_sdu += sdus;
UE->mac_stats.dl.current_rbs = sched_pdsch->rbSize;
/* save retransmission information */
harq->sched_pdsch = *sched_pdsch;
/* save which time allocation has been used, to be used on
@@ -214,6 +214,7 @@ uint8_t get_mcs_from_cqi(int mcs_table, int cqi_table, int cqi_idx)
return 9;
}
void set_dl_dmrs_ports(NR_pdsch_semi_static_t *ps) {
//TODO first basic implementation of dmrs port selection
+425 -328
View File
@@ -53,6 +53,32 @@ const int get_ul_tda(const gNB_MAC_INST *nrmac, const NR_ServingCellConfigCommon
return 0; // if FDD or not mixed slot in TDD, for now use default TDA (TODO handle CSI-RS slots)
}
int compute_bw_factor(int mu, int rb) {
// 38.213 7.1.1
return (10 * log10(rb << mu));
}
int compute_delta_tf(int tbs_bits,
int rb,
int n_layers,
int n_symbols,
int n_dmrs,
long *deltaMCS) {
// 38.213 7.1.1
// if the PUSCH transmission is over more than one layer delta_tf = 0
if(deltaMCS == NULL || n_layers>1)
return 0;
else
AssertFatal(1==0,"Compute DeltaTF not yet fully supported\n");
const int n_re = (NR_NB_SC_PER_RB * n_symbols - n_dmrs) * rb;
const int BPRE = tbs_bits/n_re; //TODO change for PUSCH with CSI
const float f = pow(2, (float) BPRE * 1.25);
const float beta = 1.0f; //TODO change for PUSCH with CSI
return(10 * log10((f - 1) * beta));
}
// For both UL-SCH except:
// - UL-SCH: fixed-size MAC CE(known by LCID)
// - UL-SCH: padding
@@ -77,317 +103,324 @@ const int get_ul_tda(const gNB_MAC_INST *nrmac, const NR_ServingCellConfigCommon
// F: length of L is 0:8 or 1:16 bits wide
// R: Reserved bit, set to zero.
int nr_process_mac_pdu( instance_t module_idP,
NR_UE_info_t* UE,
uint8_t CC_id,
frame_t frameP,
sub_frame_t slot,
uint8_t *pduP,
int pdu_len)
int nr_process_mac_pdu(instance_t module_idP,
NR_UE_info_t* UE,
uint8_t CC_id,
frame_t frameP,
sub_frame_t slot,
uint8_t *pduP,
int pdu_len,
const int8_t harq_pid)
{
uint8_t done = 0;
uint8_t done = 0;
int sdus = 0;
NR_UE_UL_BWP_t *ul_bwp = &UE->current_UL_BWP;
NR_UE_sched_ctrl_t *sched_ctrl = &UE->UE_sched_ctrl;
NR_UE_sched_ctrl_t *sched_ctrl = &UE->UE_sched_ctrl;
if (pduP[0] != UL_SCH_LCID_PADDING)
trace_NRpdu(DIRECTION_UPLINK, pduP, pdu_len, WS_C_RNTI, UE->rnti, frameP, 0, 0, 0);
if ( pduP[0] != UL_SCH_LCID_PADDING )
trace_NRpdu(DIRECTION_UPLINK, pduP, pdu_len, WS_C_RNTI, UE->rnti, frameP, 0, 0, 0);
#ifdef ENABLE_MAC_PAYLOAD_DEBUG
LOG_I(NR_MAC, "In %s: dumping MAC PDU in %d.%d:\n", __func__, frameP, slot);
log_dump(NR_MAC, pduP, pdu_len, LOG_DUMP_CHAR, "\n");
#endif
#ifdef ENABLE_MAC_PAYLOAD_DEBUG
LOG_I(NR_MAC, "In %s: dumping MAC PDU in %d.%d:\n", __func__, frameP, slot);
log_dump(NR_MAC, pduP, pdu_len, LOG_DUMP_CHAR, "\n");
#endif
while (!done && pdu_len > 0){
uint16_t mac_len=0;
uint16_t mac_subheader_len=sizeof(NR_MAC_SUBHEADER_FIXED);
uint8_t rx_lcid = ((NR_MAC_SUBHEADER_FIXED *)pduP)->LCID;
while (!done && pdu_len > 0){
uint16_t mac_len=0;
uint16_t mac_subheader_len=sizeof(NR_MAC_SUBHEADER_FIXED);
uint8_t rx_lcid = ((NR_MAC_SUBHEADER_FIXED *)pduP)->LCID;
LOG_D(NR_MAC, "In %s: received UL-SCH sub-PDU with LCID 0x%x in %d.%d (remaining PDU length %d)\n", __func__, rx_lcid, frameP, slot, pdu_len);
LOG_D(NR_MAC, "In %s: received UL-SCH sub-PDU with LCID 0x%x in %d.%d (remaining PDU length %d)\n", __func__, rx_lcid, frameP, slot, pdu_len);
unsigned char *ce_ptr;
int n_Lcg = 0;
unsigned char *ce_ptr;
int n_Lcg = 0;
switch(rx_lcid){
// MAC CE
/*#ifdef DEBUG_HEADER_PARSING
LOG_D(NR_MAC, "[UE] LCID %d, PDU length %d\n", ((NR_MAC_SUBHEADER_FIXED *)pduP)->LCID, pdu_len);
#endif*/
case UL_SCH_LCID_RECOMMENDED_BITRATE_QUERY:
// 38.321 Ch6.1.3.20
mac_len = 2;
break;
case UL_SCH_LCID_CONFIGURED_GRANT_CONFIRMATION:
// 38.321 Ch6.1.3.7
break;
case UL_SCH_LCID_S_BSR:
case UL_SCH_LCID_S_TRUNCATED_BSR:
//38.321 section 6.1.3.1
//fixed length
mac_len =1;
/* Extract short BSR value */
ce_ptr = &pduP[mac_subheader_len];
NR_BSR_SHORT *bsr_s = (NR_BSR_SHORT *) ce_ptr;
sched_ctrl->estimated_ul_buffer = 0;
sched_ctrl->estimated_ul_buffer = NR_SHORT_BSR_TABLE[bsr_s->Buffer_size];
LOG_D(NR_MAC,
"SHORT BSR at %4d.%2d, LCG ID %d, BS Index %d, BS value < %d, est buf %d\n",
frameP,
slot,
bsr_s->LcgID,
bsr_s->Buffer_size,
NR_SHORT_BSR_TABLE[bsr_s->Buffer_size],
sched_ctrl->estimated_ul_buffer);
break;
case UL_SCH_LCID_L_BSR:
case UL_SCH_LCID_L_TRUNCATED_BSR:
//38.321 section 6.1.3.1
//variable length
/* Several checks have been added to this function to
ensure that the casting of the pduP is possible. There seems
to be a partial PDU at the end of this buffer, so here
we gracefully ignore that by returning 0. See:
https://gitlab.eurecom.fr/oai/openairinterface5g/-/issues/534 */
if (!get_mac_len(pduP, pdu_len, &mac_len, &mac_subheader_len))
return 0;
/* Extract long BSR value */
ce_ptr = &pduP[mac_subheader_len];
NR_BSR_LONG *bsr_l = (NR_BSR_LONG *) ce_ptr;
sched_ctrl->estimated_ul_buffer = 0;
n_Lcg = bsr_l->LcgID7 + bsr_l->LcgID6 + bsr_l->LcgID5 + bsr_l->LcgID4 +
bsr_l->LcgID3 + bsr_l->LcgID2 + bsr_l->LcgID1 + bsr_l->LcgID0;
LOG_D(NR_MAC, "LONG BSR, LCG ID(7-0) %d/%d/%d/%d/%d/%d/%d/%d\n",
bsr_l->LcgID7, bsr_l->LcgID6, bsr_l->LcgID5, bsr_l->LcgID4,
bsr_l->LcgID3, bsr_l->LcgID2, bsr_l->LcgID1, bsr_l->LcgID0);
for (int n = 0; n < n_Lcg; n++){
LOG_D(NR_MAC, "LONG BSR, %d/%d (n/n_Lcg), BS Index %d, BS value < %d",
n, n_Lcg, pduP[mac_subheader_len + 1 + n],
NR_LONG_BSR_TABLE[pduP[mac_subheader_len + 1 + n]]);
sched_ctrl->estimated_ul_buffer +=
NR_LONG_BSR_TABLE[pduP[mac_subheader_len + 1 + n]];
LOG_D(NR_MAC,
"LONG BSR at %4d.%2d, %d/%d (n/n_Lcg), BS Index %d, BS value < %d, total %d\n",
frameP,
slot,
n,
n_Lcg,
pduP[mac_subheader_len + 1 + n],
NR_LONG_BSR_TABLE[pduP[mac_subheader_len + 1 + n]],
sched_ctrl->estimated_ul_buffer);
}
break;
case UL_SCH_LCID_C_RNTI:
for (int i = 0; i < NR_NB_RA_PROC_MAX; i++) {
NR_RA_t *ra = &RC.nrmac[module_idP]->common_channels[CC_id].ra[i];
if (ra->state >= WAIT_Msg3 && ra->rnti == UE->rnti) {
ra->crnti = ((pduP[1]&0xFF)<<8)|(pduP[2]&0xFF);
ra->msg3_dcch_dtch = true;
LOG_I(NR_MAC, "Received UL_SCH_LCID_C_RNTI with C-RNTI 0x%04x\n", ra->crnti);
break;
}
}
//38.321 section 6.1.3.2
//fixed length
mac_len = 2;
/* Extract CRNTI value */
break;
case UL_SCH_LCID_SINGLE_ENTRY_PHR:
//38.321 section 6.1.3.8
//fixed length
mac_len = 2;
/* Extract SINGLE ENTRY PHR elements for PHR calculation */
ce_ptr = &pduP[mac_subheader_len];
NR_SINGLE_ENTRY_PHR_MAC_CE *phr = (NR_SINGLE_ENTRY_PHR_MAC_CE *) ce_ptr;
/* Save the phr info */
const int PH = phr->PH;
const int PCMAX = phr->PCMAX;
/* 38.133 Table10.1.17.1-1 */
if (PH < 55)
sched_ctrl->ph = PH - 32;
else
sched_ctrl->ph = PH - 32 + (PH - 54);
/* 38.133 Table10.1.18.1-1 */
sched_ctrl->pcmax = PCMAX - 29;
LOG_D(NR_MAC, "SINGLE ENTRY PHR R1 %d PH %d (%d dB) R2 %d PCMAX %d (%d dBm)\n",
phr->R1, PH, sched_ctrl->ph, phr->R2, PCMAX, sched_ctrl->pcmax);
break;
case UL_SCH_LCID_MULTI_ENTRY_PHR_1_OCT:
//38.321 section 6.1.3.9
// varialbe length
if (!get_mac_len(pduP, pdu_len, &mac_len, &mac_subheader_len))
return 0;
/* Extract MULTI ENTRY PHR elements from single octet bitmap for PHR calculation */
break;
case UL_SCH_LCID_MULTI_ENTRY_PHR_4_OCT:
//38.321 section 6.1.3.9
// varialbe length
if (!get_mac_len(pduP, pdu_len, &mac_len, &mac_subheader_len))
return 0;
/* Extract MULTI ENTRY PHR elements from four octets bitmap for PHR calculation */
break;
case UL_SCH_LCID_PADDING:
done = 1;
// end of MAC PDU, can ignore the rest.
break;
case UL_SCH_LCID_SRB1:
case UL_SCH_LCID_SRB2:
if (!get_mac_len(pduP, pdu_len, &mac_len, &mac_subheader_len))
return 0;
rnti_t crnti = UE->rnti;
NR_UE_info_t* UE_idx = UE;
for (int i = 0; i < NR_NB_RA_PROC_MAX; i++) {
NR_RA_t *ra = &RC.nrmac[module_idP]->common_channels[CC_id].ra[i];
if (ra->state >= WAIT_Msg3 && ra->rnti == UE->rnti) {
uint8_t *next_subpduP = pduP + mac_subheader_len + mac_len;
if ((pduP[mac_subheader_len+mac_len] & 0x3F) == UL_SCH_LCID_C_RNTI) {
crnti = ((next_subpduP[1]&0xFF)<<8)|(next_subpduP[2]&0xFF);
LOG_W(NR_MAC, " UL_SCH_LCID_SRB for rnti %04x\n", crnti);
UE_idx = find_nr_UE(&RC.nrmac[module_idP]->UE_info, crnti);
break;
}
}
}
if (UE_idx->CellGroup) {
LOG_D(NR_MAC, "Frame %d : ULSCH -> UL-DCCH %d (gNB %ld, %d bytes), rnti: 0x%04x \n", frameP, rx_lcid, module_idP, mac_len, crnti);
mac_rlc_data_ind(module_idP,
crnti,
module_idP,
frameP,
ENB_FLAG_YES,
MBMS_FLAG_NO,
rx_lcid,
(char *) (pduP + mac_subheader_len),
mac_len,
1,
NULL);
} else {
AssertFatal(1==0,"[UE %04x] Frame/Slot %d.%d : Received LCID %d which is not configured, dropping packet\n",UE->rnti,frameP,slot,rx_lcid);
}
break;
case UL_SCH_LCID_SRB3:
// todo
break;
case UL_SCH_LCID_CCCH:
case UL_SCH_LCID_CCCH1:
// fixed length
mac_subheader_len = 1;
if ( rx_lcid == UL_SCH_LCID_CCCH1 ) {
// RRCResumeRequest1 message includes the full I-RNTI and has a size of 8 bytes
mac_len = 8;
// Check if it is a valid CCCH1 message, we get all 00's messages very often
int i = 0;
for(i=0; i<(mac_subheader_len+mac_len); i++) {
if(pduP[i] != 0) {
break;
}
}
if (i == (mac_subheader_len+mac_len)) {
LOG_D(NR_MAC, "%s() Invalid CCCH1 message!, pdu_len: %d\n", __func__, pdu_len);
done = 1;
break;
}
} else {
// fixed length of 6 bytes
mac_len = 6;
}
send_initial_ul_rrc_message(module_idP,
CC_id,
UE,
CCCH,
pduP + mac_subheader_len,
mac_len);
break;
case UL_SCH_LCID_DTCH ... (UL_SCH_LCID_DTCH + 28):
// check if LCID is valid at current time.
if (!get_mac_len(pduP, pdu_len, &mac_len, &mac_subheader_len)) {
return 0;
}
LOG_D(NR_MAC, "[UE %04x] %d.%d : ULSCH -> UL-%s %d (gNB %ld, %d bytes)\n",
UE->rnti,
frameP,
slot,
rx_lcid<4?"DCCH":"DTCH",
rx_lcid,
module_idP,
mac_len);
UE->mac_stats.ul.lc_bytes[rx_lcid] += mac_len;
mac_rlc_data_ind(module_idP,
UE->rnti,
module_idP,
frameP,
ENB_FLAG_YES,
MBMS_FLAG_NO,
rx_lcid,
(char *)(pduP + mac_subheader_len),
mac_len,
1,
NULL);
/* Updated estimated buffer when receiving data */
if (sched_ctrl->estimated_ul_buffer >= mac_len) {
sched_ctrl->estimated_ul_buffer -= mac_len;
} else {
sched_ctrl->estimated_ul_buffer = 0;
}
break;
default:
LOG_E(NR_MAC, "Received unknown MAC header (LCID = 0x%02x)\n", rx_lcid);
return -1;
break;
}
#ifdef ENABLE_MAC_PAYLOAD_DEBUG
if (rx_lcid < 45 || rx_lcid == 52 || rx_lcid == 63) {
LOG_I(NR_MAC, "In %s: dumping UL MAC SDU sub-header with length %d (LCID = 0x%02x):\n", __func__, mac_subheader_len, rx_lcid);
log_dump(NR_MAC, pduP, mac_subheader_len, LOG_DUMP_CHAR, "\n");
LOG_I(NR_MAC, "In %s: dumping UL MAC SDU with length %d (LCID = 0x%02x):\n", __func__, mac_len, rx_lcid);
log_dump(NR_MAC, pduP + mac_subheader_len, mac_len, LOG_DUMP_CHAR, "\n");
} else {
LOG_I(NR_MAC, "In %s: dumping UL MAC CE with length %d (LCID = 0x%02x):\n", __func__, mac_len, rx_lcid);
log_dump(NR_MAC, pduP + mac_subheader_len + mac_len, mac_len, LOG_DUMP_CHAR, "\n");
}
#endif
pduP += ( mac_subheader_len + mac_len );
pdu_len -= ( mac_subheader_len + mac_len );
if (pdu_len < 0) {
LOG_E(NR_MAC, "In %s: residual UL MAC PDU in %d.%d with length < 0!, pdu_len %d \n", __func__, frameP, slot, pdu_len);
LOG_E(NR_MAC, "MAC PDU ");
for (int i = 0; i < 20; i++) // Only printf 1st - 20nd bytes
printf("%02x ", pduP[i]);
printf("\n");
switch(rx_lcid){
// MAC CE
/*#ifdef DEBUG_HEADER_PARSING
LOG_D(NR_MAC, "[UE] LCID %d, PDU length %d\n", ((NR_MAC_SUBHEADER_FIXED *)pduP)->LCID, pdu_len);
#endif*/
case UL_SCH_LCID_RECOMMENDED_BITRATE_QUERY:
// 38.321 Ch6.1.3.20
mac_len = 2;
break;
case UL_SCH_LCID_CONFIGURED_GRANT_CONFIRMATION:
// 38.321 Ch6.1.3.7
break;
case UL_SCH_LCID_S_BSR:
case UL_SCH_LCID_S_TRUNCATED_BSR:
//38.321 section 6.1.3.1
//fixed length
mac_len =1;
/* Extract short BSR value */
ce_ptr = &pduP[mac_subheader_len];
NR_BSR_SHORT *bsr_s = (NR_BSR_SHORT *) ce_ptr;
sched_ctrl->estimated_ul_buffer = 0;
sched_ctrl->estimated_ul_buffer = NR_SHORT_BSR_TABLE[bsr_s->Buffer_size];
LOG_D(NR_MAC,
"SHORT BSR at %4d.%2d, LCG ID %d, BS Index %d, BS value < %d, est buf %d\n",
frameP,
slot,
bsr_s->LcgID,
bsr_s->Buffer_size,
NR_SHORT_BSR_TABLE[bsr_s->Buffer_size],
sched_ctrl->estimated_ul_buffer);
break;
case UL_SCH_LCID_L_BSR:
case UL_SCH_LCID_L_TRUNCATED_BSR:
//38.321 section 6.1.3.1
//variable length
/* Several checks have been added to this function to
ensure that the casting of the pduP is possible. There seems
to be a partial PDU at the end of this buffer, so here
we gracefully ignore that by returning 0. See:
https://gitlab.eurecom.fr/oai/openairinterface5g/-/issues/534 */
if (!get_mac_len(pduP, pdu_len, &mac_len, &mac_subheader_len))
return 0;
/* Extract long BSR value */
ce_ptr = &pduP[mac_subheader_len];
NR_BSR_LONG *bsr_l = (NR_BSR_LONG *) ce_ptr;
sched_ctrl->estimated_ul_buffer = 0;
n_Lcg = bsr_l->LcgID7 + bsr_l->LcgID6 + bsr_l->LcgID5 + bsr_l->LcgID4 +
bsr_l->LcgID3 + bsr_l->LcgID2 + bsr_l->LcgID1 + bsr_l->LcgID0;
LOG_D(NR_MAC, "LONG BSR, LCG ID(7-0) %d/%d/%d/%d/%d/%d/%d/%d\n",
bsr_l->LcgID7, bsr_l->LcgID6, bsr_l->LcgID5, bsr_l->LcgID4,
bsr_l->LcgID3, bsr_l->LcgID2, bsr_l->LcgID1, bsr_l->LcgID0);
for (int n = 0; n < n_Lcg; n++){
LOG_D(NR_MAC, "LONG BSR, %d/%d (n/n_Lcg), BS Index %d, BS value < %d",
n, n_Lcg, pduP[mac_subheader_len + 1 + n],
NR_LONG_BSR_TABLE[pduP[mac_subheader_len + 1 + n]]);
sched_ctrl->estimated_ul_buffer += NR_LONG_BSR_TABLE[pduP[mac_subheader_len + 1 + n]];
LOG_D(NR_MAC,
"LONG BSR at %4d.%2d, %d/%d (n/n_Lcg), BS Index %d, BS value < %d, total %d\n",
frameP,
slot,
n,
n_Lcg,
pduP[mac_subheader_len + 1 + n],
NR_LONG_BSR_TABLE[pduP[mac_subheader_len + 1 + n]],
sched_ctrl->estimated_ul_buffer);
}
}
break;
case UL_SCH_LCID_C_RNTI:
for (int i = 0; i < NR_NB_RA_PROC_MAX; i++) {
NR_RA_t *ra = &RC.nrmac[module_idP]->common_channels[CC_id].ra[i];
if (ra->state >= WAIT_Msg3 && ra->rnti == UE->rnti) {
ra->crnti = ((pduP[1]&0xFF)<<8)|(pduP[2]&0xFF);
ra->msg3_dcch_dtch = true;
LOG_I(NR_MAC, "Received UL_SCH_LCID_C_RNTI with C-RNTI 0x%04x\n", ra->crnti);
break;
}
}
//38.321 section 6.1.3.2
//fixed length
mac_len = 2;
/* Extract CRNTI value */
break;
case UL_SCH_LCID_SINGLE_ENTRY_PHR:
AssertFatal(harq_pid>-1,"Invalid HARQ PID %d\n",harq_pid);
NR_sched_pusch_t *sched_pusch = &sched_ctrl->ul_harq_processes[harq_pid].sched_pusch;;
//38.321 section 6.1.3.8
//fixed length
mac_len = 2;
/* Extract SINGLE ENTRY PHR elements for PHR calculation */
ce_ptr = &pduP[mac_subheader_len];
NR_SINGLE_ENTRY_PHR_MAC_CE *phr = (NR_SINGLE_ENTRY_PHR_MAC_CE *) ce_ptr;
/* Save the phr info */
int PH;
const int PCMAX = phr->PCMAX;
/* 38.133 Table10.1.17.1-1 */
if (phr->PH < 55)
PH = phr->PH - 32;
else
PH = phr->PH - 32 + (phr->PH - 54);
// in sched_ctrl we set normalized PH wrt MCS and PRBs
long *deltaMCS = ul_bwp->pusch_Config ? ul_bwp->pusch_Config->pusch_PowerControl->deltaMCS : NULL;
sched_ctrl->ph = PH +
compute_bw_factor(sched_pusch->mu, sched_pusch->rbSize) +
compute_delta_tf(sched_pusch->tb_size<<3,
sched_pusch->rbSize,
0, //n_layers
0, //n_symbols
0, //n_dmrs
deltaMCS);
/* 38.133 Table10.1.18.1-1 */
sched_ctrl->pcmax = PCMAX - 29;
LOG_D(NR_MAC, "SINGLE ENTRY PHR R1 %d PH %d (%d dB) R2 %d PCMAX %d (%d dBm)\n",
phr->R1, PH, sched_ctrl->ph, phr->R2, PCMAX, sched_ctrl->pcmax);
break;
case UL_SCH_LCID_MULTI_ENTRY_PHR_1_OCT:
//38.321 section 6.1.3.9
// varialbe length
if (!get_mac_len(pduP, pdu_len, &mac_len, &mac_subheader_len))
return 0;
/* Extract MULTI ENTRY PHR elements from single octet bitmap for PHR calculation */
break;
case UL_SCH_LCID_MULTI_ENTRY_PHR_4_OCT:
//38.321 section 6.1.3.9
// varialbe length
if (!get_mac_len(pduP, pdu_len, &mac_len, &mac_subheader_len))
return 0;
/* Extract MULTI ENTRY PHR elements from four octets bitmap for PHR calculation */
break;
case UL_SCH_LCID_PADDING:
done = 1;
// end of MAC PDU, can ignore the rest.
break;
case UL_SCH_LCID_SRB1:
case UL_SCH_LCID_SRB2:
if (!get_mac_len(pduP, pdu_len, &mac_len, &mac_subheader_len))
return 0;
rnti_t crnti = UE->rnti;
NR_UE_info_t* UE_idx = UE;
for (int i = 0; i < NR_NB_RA_PROC_MAX; i++) {
NR_RA_t *ra = &RC.nrmac[module_idP]->common_channels[CC_id].ra[i];
if (ra->state >= WAIT_Msg3 && ra->rnti == UE->rnti) {
uint8_t *next_subpduP = pduP + mac_subheader_len + mac_len;
if ((pduP[mac_subheader_len+mac_len] & 0x3F) == UL_SCH_LCID_C_RNTI) {
crnti = ((next_subpduP[1]&0xFF)<<8)|(next_subpduP[2]&0xFF);
LOG_W(NR_MAC, " UL_SCH_LCID_SRB for rnti %04x\n", crnti);
UE_idx = find_nr_UE(&RC.nrmac[module_idP]->UE_info, crnti);
break;
}
}
}
if (UE_idx->CellGroup) {
LOG_D(NR_MAC, "Frame %d : ULSCH -> UL-DCCH %d (gNB %ld, %d bytes), rnti: 0x%04x \n", frameP, rx_lcid, module_idP, mac_len, crnti);
mac_rlc_data_ind(module_idP,
crnti,
module_idP,
frameP,
ENB_FLAG_YES,
MBMS_FLAG_NO,
rx_lcid,
(char *) (pduP + mac_subheader_len),
mac_len,
1,
NULL);
} else {
AssertFatal(1==0,"[UE %04x] Frame/Slot %d.%d : Received LCID %d which is not configured, dropping packet\n",UE->rnti,frameP,slot,rx_lcid);
}
break;
case UL_SCH_LCID_CCCH:
case UL_SCH_LCID_CCCH1:
// fixed length
mac_subheader_len = 1;
if ( rx_lcid == UL_SCH_LCID_CCCH1 ) {
// RRCResumeRequest1 message includes the full I-RNTI and has a size of 8 bytes
mac_len = 8;
// Check if it is a valid CCCH1 message, we get all 00's messages very often
int i = 0;
for(i=0; i<(mac_subheader_len+mac_len); i++) {
if(pduP[i] != 0) {
break;
}
}
if (i == (mac_subheader_len+mac_len)) {
LOG_D(NR_MAC, "%s() Invalid CCCH1 message!, pdu_len: %d\n", __func__, pdu_len);
done = 1;
break;
}
} else {
// fixed length of 6 bytes
mac_len = 6;
}
send_initial_ul_rrc_message(module_idP,
CC_id,
UE,
CCCH,
pduP + mac_subheader_len,
mac_len);
break;
case UL_SCH_LCID_DTCH ... (UL_SCH_LCID_DTCH + 28):
// check if LCID is valid at current time.
if (!get_mac_len(pduP, pdu_len, &mac_len, &mac_subheader_len))
return 0;
LOG_D(NR_MAC, "[UE %04x] %d.%d : ULSCH -> UL-%s %d (gNB %ld, %d bytes)\n",
UE->rnti,
frameP,
slot,
rx_lcid<4?"DCCH":"DTCH",
rx_lcid,
module_idP,
mac_len);
UE->mac_stats.ul.lc_bytes[rx_lcid] += mac_len;
mac_rlc_data_ind(module_idP,
UE->rnti,
module_idP,
frameP,
ENB_FLAG_YES,
MBMS_FLAG_NO,
rx_lcid,
(char *)(pduP + mac_subheader_len),
mac_len,
1,
NULL);
sdus += 1;
/* Updated estimated buffer when receiving data */
if (sched_ctrl->estimated_ul_buffer >= mac_len)
sched_ctrl->estimated_ul_buffer -= mac_len;
else
sched_ctrl->estimated_ul_buffer = 0;
break;
default:
LOG_E(NR_MAC, "Received unknown MAC header (LCID = 0x%02x)\n", rx_lcid);
return -1;
break;
}
#ifdef ENABLE_MAC_PAYLOAD_DEBUG
if (rx_lcid < 45 || rx_lcid == 52 || rx_lcid == 63) {
LOG_I(NR_MAC, "In %s: dumping UL MAC SDU sub-header with length %d (LCID = 0x%02x):\n", __func__, mac_subheader_len, rx_lcid);
log_dump(NR_MAC, pduP, mac_subheader_len, LOG_DUMP_CHAR, "\n");
LOG_I(NR_MAC, "In %s: dumping UL MAC SDU with length %d (LCID = 0x%02x):\n", __func__, mac_len, rx_lcid);
log_dump(NR_MAC, pduP + mac_subheader_len, mac_len, LOG_DUMP_CHAR, "\n");
} else {
LOG_I(NR_MAC, "In %s: dumping UL MAC CE with length %d (LCID = 0x%02x):\n", __func__, mac_len, rx_lcid);
log_dump(NR_MAC, pduP + mac_subheader_len + mac_len, mac_len, LOG_DUMP_CHAR, "\n");
}
#endif
pduP += ( mac_subheader_len + mac_len );
pdu_len -= ( mac_subheader_len + mac_len );
if (pdu_len < 0) {
LOG_E(NR_MAC, "In %s: residual UL MAC PDU in %d.%d with length < 0!, pdu_len %d \n", __func__, frameP, slot, pdu_len);
LOG_E(NR_MAC, "MAC PDU ");
for (int i = 0; i < 20; i++) // Only printf 1st - 20nd bytes
printf("%02x ", pduP[i]);
printf("\n");
return 0;
}
}
UE->mac_stats.ul.num_mac_sdu += sdus;
return 0;
}
@@ -541,9 +574,9 @@ void nr_rx_sdu(const module_id_t gnb_mod_idP,
LOG_I(NR_MAC, "Printing received UL MAC payload at gNB side: %d \n");
for (int i = 0; i < sdu_lenP ; i++) {
//harq_process_ul_ue->a[i] = (unsigned char) rand();
//printf("a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]);
printf("%02x ",(unsigned char)sduP[i]);
//harq_process_ul_ue->a[i] = (unsigned char) rand();
//printf("a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]);
printf("%02x ",(unsigned char)sduP[i]);
}
printf("\n");
@@ -558,7 +591,7 @@ void nr_rx_sdu(const module_id_t gnb_mod_idP,
if (UE_scheduling_control->sched_ul_bytes < 0)
UE_scheduling_control->sched_ul_bytes = 0;
nr_process_mac_pdu(gnb_mod_idP, UE, CC_idP, frameP, slotP, sduP, sdu_lenP);
nr_process_mac_pdu(gnb_mod_idP, UE, CC_idP, frameP, slotP, sduP, sdu_lenP, harq_pid);
}
else {
NR_UE_ul_harq_t *cur_harq = &UE_scheduling_control->ul_harq_processes[harq_pid];
@@ -657,14 +690,14 @@ void nr_rx_sdu(const module_id_t gnb_mod_idP,
current_rnti,
ra->rnti);
NR_UE_sched_ctrl_t *UE_scheduling_control = &UE->UE_sched_ctrl;
NR_UE_sched_ctrl_t *UE_scheduling_control = &UE->UE_sched_ctrl;
UE_scheduling_control->tpc0 = nr_get_tpc(target_snrx10,ul_cqi,30);
if (timing_advance != 0xffff)
UE_scheduling_control->ta_update = timing_advance;
UE_scheduling_control->raw_rssi = rssi;
UE_scheduling_control->pusch_snrx10 = ul_cqi * 5 - 640;
LOG_D(NR_MAC, "[UE %04x] PUSCH TPC %d and TA %d\n",UE->rnti,UE_scheduling_control->tpc0,UE_scheduling_control->ta_update);
UE_scheduling_control->tpc0 = nr_get_tpc(target_snrx10,ul_cqi,30);
if (timing_advance != 0xffff)
UE_scheduling_control->ta_update = timing_advance;
UE_scheduling_control->raw_rssi = rssi;
UE_scheduling_control->pusch_snrx10 = ul_cqi * 5 - 640;
LOG_D(NR_MAC, "[UE %04x] PUSCH TPC %d and TA %d\n",UE->rnti,UE_scheduling_control->tpc0,UE_scheduling_control->ta_update);
if(ra->cfra) {
LOG_A(NR_MAC, "(rnti 0x%04x) CFRA procedure succeeded!\n", ra->rnti);
@@ -685,8 +718,9 @@ void nr_rx_sdu(const module_id_t gnb_mod_idP,
// Store the first 48 bits belonging to the uplink CCCH SDU within Msg3 to fill in Msg4
// First byte corresponds to R/LCID MAC sub-header
memcpy(ra->cont_res_id, &sduP[1], sizeof(uint8_t) * 6);
if (nr_process_mac_pdu(gnb_mod_idP, UE, CC_idP, frameP, slotP, sduP, sdu_lenP) == 0) {
// harq_pid set a non valid value because it is not used in this call
// the function is only called to decode the contention resolution sub-header
if (nr_process_mac_pdu(gnb_mod_idP, UE, CC_idP, frameP, slotP, sduP, sdu_lenP, -1) == 0) {
ra->state = Msg4;
ra->Msg4_frame = (frameP + 2) % 1024;
ra->Msg4_slot = 1;
@@ -858,6 +892,65 @@ static bool nr_UE_is_to_be_scheduled(const NR_ServingCellConfigCommon_t *scc,
return has_data || sched_ctrl->SR || high_inactivity;
}
void update_ul_ue_R_Qm(int mcs, int mcs_table, const NR_PUSCH_Config_t *pusch_Config, uint16_t *R, uint8_t *Qm)
{
*R = nr_get_code_rate_ul(mcs, mcs_table);
*Qm = nr_get_Qm_ul(mcs, mcs_table);
if (pusch_Config && pusch_Config->tp_pi2BPSK && ((mcs_table == 3 && mcs < 2) || (mcs_table == 4 && mcs < 6))) {
*R >>= 1;
*Qm <<= 1;
}
}
void nr_ue_max_mcs_min_rb(int mu, int ph_limit, NR_pusch_semi_static_t *ps, NR_UE_UL_BWP_t *ul_bwp, uint16_t minRb, uint32_t tbs, uint16_t *Rb, uint8_t *mcs)
{
AssertFatal(*Rb >= minRb, "illegal Rb %d < minRb %d\n", *Rb, minRb);
AssertFatal(*mcs >= 0 && *mcs <= 28, "illegal MCS %d\n", *mcs);
const int tbs_bits = tbs << 3;
uint16_t R;
uint8_t Qm;
update_ul_ue_R_Qm(*mcs, ul_bwp->mcs_table, ul_bwp->pusch_Config, &R, &Qm);
long *deltaMCS = ul_bwp->pusch_Config ? ul_bwp->pusch_Config->pusch_PowerControl->deltaMCS : NULL;
int tx_power = compute_bw_factor(mu, *Rb) +
compute_delta_tf(tbs_bits,
*Rb,
ps->nrOfLayers,
ps->nrOfSymbols,
ps->N_PRB_DMRS*ps->num_dmrs_symb,
deltaMCS);
while (ph_limit < tx_power && *Rb >= minRb) {
(*Rb)--;
tx_power = compute_bw_factor(mu, *Rb) +
compute_delta_tf(tbs_bits,
*Rb,
ps->nrOfLayers,
ps->nrOfSymbols,
ps->N_PRB_DMRS*ps->num_dmrs_symb,
deltaMCS);
}
while (ph_limit < tx_power && *mcs > 6) {
(*mcs)--;
update_ul_ue_R_Qm(*mcs, ul_bwp->mcs_table, ul_bwp->pusch_Config, &R, &Qm);
tx_power = compute_bw_factor(mu, *Rb) +
compute_delta_tf(tbs_bits,
*Rb,
ps->nrOfLayers,
ps->nrOfSymbols,
ps->N_PRB_DMRS*ps->num_dmrs_symb,
deltaMCS);
}
if (ph_limit < tx_power)
LOG_W(NR_MAC, "Normalized power %d based on current resources (RBs %d, MCS %d) exceed reported PHR %d (normalized value)\n",
tx_power, *Rb, *mcs, ph_limit);
}
static bool allocate_ul_retransmission(gNB_MAC_INST *nrmac,
frame_t frame,
sub_frame_t slot,
@@ -1000,18 +1093,6 @@ static bool allocate_ul_retransmission(gNB_MAC_INST *nrmac,
return true;
}
void update_ul_ue_R_Qm(NR_sched_pusch_t *sched_pusch, const NR_PUSCH_Config_t *pusch_Config, const int mcs_table) {
const int mcs = sched_pusch->mcs;
sched_pusch->R = nr_get_code_rate_ul(mcs, mcs_table);
sched_pusch->Qm = nr_get_Qm_ul(mcs, mcs_table);
if (pusch_Config && pusch_Config->tp_pi2BPSK && ((mcs_table == 3 && mcs < 2) || (mcs_table == 4 && mcs < 6))) {
sched_pusch->R >>= 1;
sched_pusch->Qm <<= 1;
}
}
uint32_t ul_pf_tbs[3][29]; // pre-computed, approximate TBS values for PF coefficient
typedef struct UEsched_s {
float coef;
@@ -1182,7 +1263,7 @@ void pf_ul(module_id_t module_id,
NR_sched_pusch_t *sched_pusch = &sched_ctrl->sched_pusch;
sched_pusch->mcs = min(nrmac->min_grant_mcs, sched_pusch->mcs);
update_ul_ue_R_Qm(sched_pusch, current_BWP->pusch_Config, current_BWP->mcs_table);
update_ul_ue_R_Qm(sched_pusch->mcs, current_BWP->mcs_table, current_BWP->pusch_Config, &sched_pusch->R, &sched_pusch->Qm);
sched_pusch->rbStart = rbStart;
sched_pusch->rbSize = min_rb;
sched_pusch->tb_size = nr_compute_tbs(sched_pusch->Qm,
@@ -1268,7 +1349,7 @@ void pf_ul(module_id_t module_id,
nrOfLayers,
ps);
}
update_ul_ue_R_Qm(sched_pusch, current_BWP->pusch_Config, current_BWP->mcs_table);
update_ul_ue_R_Qm(sched_pusch->mcs, current_BWP->mcs_table, current_BWP->pusch_Config, &sched_pusch->R, &sched_pusch->Qm);
int rbStart = 0;
const uint16_t slbitmap = SL_to_bitmap(ps->startSymbolIndex, ps->nrOfSymbols);
@@ -1287,8 +1368,17 @@ void pf_ul(module_id_t module_id,
else
LOG_D(NR_MAC,"allocating UL data for RNTI %04x (rbStsart %d, min_rb %d, bwpSize %d)\n", iterator->UE->rnti,rbStart,min_rb,bwpSize);
/* Calculate the current scheduling bytes and the necessary RBs */
/* Calculate the current scheduling bytes */
const int B = cmax(sched_ctrl->estimated_ul_buffer - sched_ctrl->sched_ul_bytes, 0);
/* adjust rbSize and MCS according to PHR and BPRE */
sched_pusch->mu = scc->uplinkConfigCommon->initialUplinkBWP->genericParameters.subcarrierSpacing;
if(sched_ctrl->pcmax!=0 ||
sched_ctrl->ph!=0) // verify if the PHR related parameter have been initialized
nr_ue_max_mcs_min_rb(sched_pusch->mu, sched_ctrl->ph, ps, current_BWP, min_rbSize, B, &max_rbSize, &sched_pusch->mcs);
if (sched_pusch->mcs < sched_ctrl->ul_bler_stats.mcs)
sched_ctrl->ul_bler_stats.mcs = sched_pusch->mcs; /* force estimated MCS down */
uint16_t rbSize = 0;
uint32_t TBS = 0;
@@ -1302,6 +1392,7 @@ void pf_ul(module_id_t module_id,
max_rbSize,
&TBS,
&rbSize);
sched_pusch->rbSize = rbSize;
sched_pusch->tb_size = TBS;
LOG_D(NR_MAC,"rbSize %d (max_rbSize %d), TBS %d, est buf %d, sched_ul %d, B %d, CCE %d, num_dmrs_symb %d, N_PRB_DMRS %d\n",
@@ -1492,6 +1583,7 @@ void nr_schedule_ulsch(module_id_t module_id, frame_t frame, sub_frame_t slot)
NR_UE_UL_BWP_t *current_BWP = &UE->current_UL_BWP;
UE->mac_stats.ul.current_bytes = 0;
UE->mac_stats.ul.current_rbs = 0;
/* dynamic PUSCH values (RB alloc, MCS, hence R, Qm, TBS) that change in
* every TTI are pre-populated by the preprocessor and used below */
@@ -1546,6 +1638,8 @@ void nr_schedule_ulsch(module_id_t module_id, frame_t frame, sub_frame_t slot)
* retransmissions */
cur_harq->sched_pusch.time_domain_allocation = ps->time_domain_allocation;
sched_ctrl->sched_ul_bytes += sched_pusch->tb_size;
UE->mac_stats.ul.total_rbs += sched_pusch->rbSize;
} else {
LOG_D(NR_MAC,
"%d.%2d UL retransmission RNTI %04x sched %d.%2d HARQ PID %d round %d NDI %d\n",
@@ -1557,8 +1651,10 @@ void nr_schedule_ulsch(module_id_t module_id, frame_t frame, sub_frame_t slot)
harq_id,
cur_harq->round,
cur_harq->ndi);
UE->mac_stats.ul.total_rbs_retx += sched_pusch->rbSize;
}
UE->mac_stats.ul.current_bytes = sched_pusch->tb_size;
UE->mac_stats.ul.current_rbs = sched_pusch->rbSize;
sched_ctrl->last_ul_frame = sched_pusch->frame;
sched_ctrl->last_ul_slot = sched_pusch->slot;
@@ -1682,6 +1778,7 @@ void nr_schedule_ulsch(module_id_t module_id, frame_t frame, sub_frame_t slot)
pusch_pdu->pusch_data.tb_size = sched_pusch->tb_size;
pusch_pdu->pusch_data.num_cb = 0; //CBG not supported
pusch_pdu->maintenance_parms_v3.ldpcBaseGraph = get_BG(sched_pusch->tb_size<<3,sched_pusch->R);
if(current_BWP->pusch_servingcellconfig &&
current_BWP->pusch_servingcellconfig->rateMatching) {
// TBS_LBRM according to section 5.4.2.1 of 38.212
-1
View File
@@ -469,7 +469,6 @@ uint16_t set_pm_index(NR_UE_sched_ctrl_t *sched_ctrl,
int codebook_mode);
uint8_t get_mcs_from_cqi(int mcs_table, int cqi_table, int cqi_idx);
uint8_t set_dl_nrOfLayers(NR_UE_sched_ctrl_t *sched_ctrl);
const int get_dl_tda(const gNB_MAC_INST *nrmac, const NR_ServingCellConfigCommon_t *scc, int slot);
+9
View File
@@ -394,6 +394,7 @@ typedef struct NR_pusch_semi_static_t {
typedef struct NR_sched_pusch {
int frame;
int slot;
int mu;
/// RB allocation within active uBWP
uint16_t rbSize;
@@ -668,6 +669,10 @@ typedef struct NR_mac_dir_stats {
uint64_t errors;
uint64_t total_bytes;
uint32_t current_bytes;
uint32_t total_rbs;
uint32_t total_rbs_retx;
uint32_t num_mac_sdu;
uint32_t current_rbs;
} NR_mac_dir_stats_t;
typedef struct NR_mac_stats {
@@ -851,6 +856,10 @@ typedef struct gNB_MAC_INST_s {
uint8_t min_grant_mcs;
nr_mac_rrc_ul_if_t mac_rrc;
int16_t frame;
int16_t slot;
} gNB_MAC_INST;
#endif /*__LAYER2_NR_MAC_GNB_H__ */
+37
View File
@@ -59,6 +59,9 @@ static void nr_pdcp_entity_recv_pdu(nr_pdcp_entity_t *entity,
We need to investigate why this hack is neccessary. */
buffer[0] |= 128;
}
entity->stats.rxpdu_pkts++;
entity->stats.rxpdu_bytes += size;
if (entity->sn_size == 12) {
rcvd_sn = ((buffer[0] & 0xf) << 8) |
@@ -70,6 +73,7 @@ static void nr_pdcp_entity_recv_pdu(nr_pdcp_entity_t *entity,
buffer[2];
header_size = 3;
}
entity->stats.rxpdu_sn = rcvd_sn;
/* SRBs always have MAC-I, even if integrity is not active */
if (entity->has_integrity || entity->type == NR_PDCP_SRB) {
@@ -80,6 +84,11 @@ static void nr_pdcp_entity_recv_pdu(nr_pdcp_entity_t *entity,
if (size < header_size + integrity_size + 1) {
LOG_E(PDCP, "bad PDU received (size = %d)\n", size);
entity->stats.rxpdu_dd_pkts++;
entity->stats.rxpdu_dd_bytes += size;
return;
}
@@ -109,12 +118,20 @@ static void nr_pdcp_entity_recv_pdu(nr_pdcp_entity_t *entity,
if (memcmp(integrity, buffer + size - integrity_size, 4) != 0) {
LOG_E(PDCP, "discard NR PDU, integrity failed\n");
// return;
entity->stats.rxpdu_dd_pkts++;
entity->stats.rxpdu_dd_bytes += size;
}
}
if (rcvd_count < entity->rx_deliv
|| nr_pdcp_sdu_in_list(entity->rx_list, rcvd_count)) {
LOG_W(PDCP, "discard NR PDU rcvd_count=%d, entity->rx_deliv %d,sdu_in_list %d\n", rcvd_count,entity->rx_deliv,nr_pdcp_sdu_in_list(entity->rx_list,rcvd_count));
entity->stats.rxpdu_dd_pkts++;
entity->stats.rxpdu_dd_bytes += size;
return;
}
@@ -139,6 +156,10 @@ static void nr_pdcp_entity_recv_pdu(nr_pdcp_entity_t *entity,
cur->buffer, cur->size);
entity->rx_list = cur->next;
entity->rx_size -= cur->size;
entity->stats.txsdu_pkts++;
entity->stats.txsdu_bytes += cur->size;
nr_pdcp_free_sdu(cur);
count++;
}
@@ -165,6 +186,9 @@ static void nr_pdcp_entity_recv_sdu(nr_pdcp_entity_t *entity,
int integrity_size;
char buf[size + 3 + 4];
int dc_bit;
entity->stats.rxsdu_pkts++;
entity->stats.rxsdu_bytes += size;
count = entity->tx_next;
sn = entity->tx_next & entity->sn_max;
@@ -215,6 +239,11 @@ static void nr_pdcp_entity_recv_sdu(nr_pdcp_entity_t *entity,
entity->deliver_pdu(entity->deliver_pdu_data, entity, buf,
header_size + size + integrity_size, sdu_id);
entity->stats.txpdu_pkts++;
entity->stats.txpdu_bytes += header_size + size + integrity_size;
entity->stats.txpdu_sn = sn;
}
/* may be called several times, take care to clean previous settings */
@@ -346,6 +375,13 @@ void nr_pdcp_entity_delete(nr_pdcp_entity_t *entity)
free(entity);
}
static void nr_pdcp_entity_get_stats(nr_pdcp_entity_t *entity,
nr_pdcp_statistics_t *out)
{
*out = entity->stats;
}
nr_pdcp_entity_t *new_nr_pdcp_entity(
nr_pdcp_entity_type_t type,
int is_gnb, int rb_id, int pdusession_id,int has_sdap,
@@ -381,6 +417,7 @@ nr_pdcp_entity_t *new_nr_pdcp_entity(
ret->delete_entity = nr_pdcp_entity_delete;
ret->get_stats = nr_pdcp_entity_get_stats;
ret->deliver_sdu = deliver_sdu;
ret->deliver_sdu_data = deliver_sdu_data;
+35
View File
@@ -32,6 +32,39 @@ typedef enum {
NR_PDCP_SRB
} nr_pdcp_entity_type_t;
typedef struct {
//nr_pdcp_entity_type_t mode;
/* PDU stats */
/* TX */
uint32_t txpdu_pkts; /* aggregated number of tx packets */
uint32_t txpdu_bytes; /* aggregated bytes of tx packets */
uint32_t txpdu_sn; /* current sequence number of last tx packet (or TX_NEXT) */
/* RX */
uint32_t rxpdu_pkts; /* aggregated number of rx packets */
uint32_t rxpdu_bytes; /* aggregated bytes of rx packets */
uint32_t rxpdu_sn; /* current sequence number of last rx packet (or RX_NEXT) */
/* TODO? */
uint32_t rxpdu_oo_pkts; /* aggregated number of out-of-order rx pkts (or RX_REORD) */
/* TODO? */
uint32_t rxpdu_oo_bytes; /* aggregated amount of out-of-order rx bytes */
uint32_t rxpdu_dd_pkts; /* aggregated number of duplicated discarded packets (or dropped packets because of other reasons such as integrity failure) (or RX_DELIV) */
uint32_t rxpdu_dd_bytes; /* aggregated amount of discarded packets' bytes */
/* TODO? */
uint32_t rxpdu_ro_count; /* this state variable indicates the COUNT value following the COUNT value associated with the PDCP Data PDU which triggered t-Reordering. (RX_REORD) */
/* SDU stats */
/* TX */
uint32_t txsdu_pkts; /* number of SDUs delivered */
uint32_t txsdu_bytes; /* number of bytes of SDUs delivered */
/* RX */
uint32_t rxsdu_pkts; /* number of SDUs received */
uint32_t rxsdu_bytes; /* number of bytes of SDUs received */
uint8_t mode; /* 0: PDCP AM, 1: PDCP UM, 2: PDCP TM */
} nr_pdcp_statistics_t;
typedef struct nr_pdcp_entity_t {
nr_pdcp_entity_type_t type;
@@ -40,6 +73,7 @@ typedef struct nr_pdcp_entity_t {
void (*recv_sdu)(struct nr_pdcp_entity_t *entity, char *buffer, int size,
int sdu_id);
void (*delete_entity)(struct nr_pdcp_entity_t *entity);
void (*get_stats)(struct nr_pdcp_entity_t *entity, nr_pdcp_statistics_t *out);
/* set_security: pass -1 to integrity_algorithm / ciphering_algorithm
* to keep the current algorithm
@@ -114,6 +148,7 @@ typedef struct nr_pdcp_entity_t {
nr_pdcp_sdu_t *rx_list;
int rx_size;
int rx_maxsize;
nr_pdcp_statistics_t stats;
} nr_pdcp_entity_t;
nr_pdcp_entity_t *new_nr_pdcp_entity(
+40 -2
View File
@@ -1441,6 +1441,44 @@ void nr_pdcp_tick(int frame, int subframe)
/*
* For the SDAP API
*/
nr_pdcp_ue_manager_t *nr_pdcp_sdap_get_ue_manager(){
return nr_pdcp_ue_manager;
nr_pdcp_ue_manager_t *nr_pdcp_sdap_get_ue_manager() {
return nr_pdcp_ue_manager;
}
/* returns false in case of error, true if everything ok */
const bool nr_pdcp_get_statistics(
int rnti,
int srb_flag,
int rb_id,
nr_pdcp_statistics_t *out)
{
nr_pdcp_ue_t *ue;
nr_pdcp_entity_t *rb;
bool ret;
nr_pdcp_manager_lock(nr_pdcp_ue_manager);
ue = nr_pdcp_manager_get_ue(nr_pdcp_ue_manager, rnti);
if (srb_flag == 1) {
if (rb_id < 1 || rb_id > 2)
rb = NULL;
else
rb = ue->srb[rb_id - 1];
} else {
if (rb_id < 1 || rb_id > 5)
rb = NULL;
else
rb = ue->drb[rb_id - 1];
}
if (rb != NULL) {
rb->get_stats(rb, out);
ret = true;
} else {
ret = false;
}
nr_pdcp_manager_unlock(nr_pdcp_ue_manager);
return ret;
}
+39
View File
@@ -29,6 +29,21 @@
#include "LOG/log.h"
#include "common/utils/time_stat.h"
static void nr_rlc_entity_get_stats(
nr_rlc_entity_t *entity,
nr_rlc_statistics_t *out)
{
// printf("Stats from the RLC entity asked\n");
*out = entity->stats;
if (entity->avg_time_is_on)
out->txsdu_avg_time_to_tx = time_average_get_average(entity->txsdu_avg_time_to_tx,
time_average_now());
else
out->txsdu_avg_time_to_tx = 0;
}
nr_rlc_entity_t *new_nr_rlc_entity_am(
int rx_maxsize,
int tx_maxsize,
@@ -86,6 +101,7 @@ nr_rlc_entity_t *new_nr_rlc_entity_am(
ret->common.reestablishment = nr_rlc_entity_am_reestablishment;
ret->common.delete = nr_rlc_entity_am_delete;
ret->common.available_tx_space = nr_rlc_entity_am_available_tx_space;
ret->common.get_stats = nr_rlc_entity_get_stats;
ret->common.deliver_sdu = deliver_sdu;
ret->common.deliver_sdu_data = deliver_sdu_data;
@@ -94,6 +110,13 @@ nr_rlc_entity_t *new_nr_rlc_entity_am(
ret->common.max_retx_reached = max_retx_reached;
ret->common.max_retx_reached_data = max_retx_reached_data;
ret->common.stats.mode = NR_RLC_AM;
/* let's take average over the last 100 milliseconds
* initial_size of 1024 is arbitrary
*/
ret->common.txsdu_avg_time_to_tx = time_average_new(100 * 1000, 1024);
return (nr_rlc_entity_t *)ret;
}
@@ -137,10 +160,18 @@ nr_rlc_entity_t *new_nr_rlc_entity_um(
ret->common.reestablishment = nr_rlc_entity_um_reestablishment;
ret->common.delete = nr_rlc_entity_um_delete;
ret->common.available_tx_space = nr_rlc_entity_um_available_tx_space;
ret->common.get_stats = nr_rlc_entity_get_stats;
ret->common.deliver_sdu = deliver_sdu;
ret->common.deliver_sdu_data = deliver_sdu_data;
ret->common.stats.mode = NR_RLC_UM;
/* let's take average over the last 100 milliseconds
* initial_size of 1024 is arbitrary
*/
ret->common.txsdu_avg_time_to_tx = time_average_new(100 * 1000, 1024);
return (nr_rlc_entity_t *)ret;
}
@@ -169,9 +200,17 @@ nr_rlc_entity_t *new_nr_rlc_entity_tm(
ret->common.reestablishment = nr_rlc_entity_tm_reestablishment;
ret->common.delete = nr_rlc_entity_tm_delete;
ret->common.available_tx_space = nr_rlc_entity_tm_available_tx_space;
ret->common.get_stats = nr_rlc_entity_get_stats;
ret->common.deliver_sdu = deliver_sdu;
ret->common.deliver_sdu_data = deliver_sdu_data;
ret->common.stats.mode = NR_RLC_TM;
/* let's take average over the last 100 milliseconds
* initial_size of 1024 is arbitrary
*/
ret->common.txsdu_avg_time_to_tx = time_average_new(100 * 1000, 1024);
return (nr_rlc_entity_t *)ret;
}
+77
View File
@@ -24,8 +24,79 @@
#include <stdint.h>
#include "common/utils/time_stat.h"
#define NR_SDU_MAX 16000 /* max NR PDCP SDU size is 9000, let's take more */
typedef enum {
NR_RLC_AM,
NR_RLC_UM,
NR_RLC_TM,
} nr_rlc_mode_t;
typedef struct {
nr_rlc_mode_t mode; /* AM, UM, or TM */
/* PDU stats */
/* TX */
uint32_t txpdu_pkts; /* aggregated number of transmitted RLC PDUs */
uint32_t txpdu_bytes; /* aggregated amount of transmitted bytes in RLC PDUs */
/* TODO? */
uint32_t txpdu_wt_ms; /* aggregated head-of-line tx packet waiting time to be transmitted (i.e. send to the MAC layer) */
uint32_t txpdu_dd_pkts; /* aggregated number of dropped or discarded tx packets by RLC */
uint32_t txpdu_dd_bytes; /* aggregated amount of bytes dropped or discarded tx packets by RLC */
uint32_t txpdu_retx_pkts; /* aggregated number of tx pdus/pkts to be re-transmitted (only applicable to RLC AM) */
uint32_t txpdu_retx_bytes; /* aggregated amount of bytes to be re-transmitted (only applicable to RLC AM) */
uint32_t txpdu_segmented; /* aggregated number of segmentations */
uint32_t txpdu_status_pkts; /* aggregated number of tx status pdus/pkts (only applicable to RLC AM) */
uint32_t txpdu_status_bytes; /* aggregated amount of tx status bytes (only applicable to RLC AM) */
/* TODO? */
uint32_t txbuf_occ_bytes; /* current tx buffer occupancy in terms of amount of bytes (average: NOT IMPLEMENTED) */
/* TODO? */
uint32_t txbuf_occ_pkts; /* current tx buffer occupancy in terms of number of packets (average: NOT IMPLEMENTED) */
/* txbuf_wd_ms: the time window for which the txbuf occupancy value is obtained - NOT IMPLEMENTED */
/* RX */
uint32_t rxpdu_pkts; /* aggregated number of received RLC PDUs */
uint32_t rxpdu_bytes; /* amount of bytes received by the RLC */
uint32_t rxpdu_dup_pkts; /* aggregated number of duplicate packets */
uint32_t rxpdu_dup_bytes; /* aggregated amount of duplicated bytes */
uint32_t rxpdu_dd_pkts; /* aggregated number of rx packets dropped or discarded by RLC */
uint32_t rxpdu_dd_bytes; /* aggregated amount of rx bytes dropped or discarded by RLC */
uint32_t rxpdu_ow_pkts; /* aggregated number of out of window received RLC pdu */
uint32_t rxpdu_ow_bytes; /* aggregated number of out of window bytes received RLC pdu */
uint32_t rxpdu_status_pkts; /* aggregated number of rx status pdus/pkts (only applicable to RLC AM) */
uint32_t rxpdu_status_bytes; /* aggregated amount of rx status bytes (only applicable to RLC AM) */
/* rxpdu_rotout_ms: flag indicating rx reordering timeout in ms - NOT IMPLEMENTED */
/* rxpdu_potout_ms: flag indicating the poll retransmit time out in ms - NOT IMPLEMENTED */
/* rxpdu_sptout_ms: flag indicating status prohibit timeout in ms - NOT IMPLEMENTED */
/* TODO? */
uint32_t rxbuf_occ_bytes; /* current rx buffer occupancy in terms of amount of bytes (average: NOT IMPLEMENTED) */
/* TODO? */
uint32_t rxbuf_occ_pkts; /* current rx buffer occupancy in terms of number of packets (average: NOT IMPLEMENTED) */
/* SDU stats */
/* TX */
uint32_t txsdu_pkts; /* number of SDUs delivered */
uint32_t txsdu_bytes; /* number of bytes of SDUs delivered */
/* RX */
uint32_t rxsdu_pkts; /* number of SDUs received */
uint32_t rxsdu_bytes; /* number of bytes of SDUs received */
uint32_t rxsdu_dd_pkts; /* number of dropped or discarded SDUs */
uint32_t rxsdu_dd_bytes; /* number of bytes of SDUs dropped or discarded */
/* Average time for an SDU to be passed to MAC.
* Actually measures the time it takes for any part of an SDU to be
* passed to MAC for the first time, that is: the first TX of (part of) the
* SDU.
* Since the MAC schedules in advance, it does not measure the time of
* transmission over the air, just the time to reach the MAC layer.
*/
double txsdu_avg_time_to_tx;
} nr_rlc_statistics_t;
typedef struct {
int status_size;
int tx_size;
@@ -52,6 +123,8 @@ typedef struct nr_rlc_entity_t {
int (*available_tx_space)(struct nr_rlc_entity_t *entity);
void (*get_stats)(struct nr_rlc_entity_t *entity, nr_rlc_statistics_t *out);
/* callbacks provided to the RLC module */
void (*deliver_sdu)(void *deliver_sdu_data, struct nr_rlc_entity_t *entity,
char *buf, int size);
@@ -67,6 +140,10 @@ typedef struct nr_rlc_entity_t {
void *max_retx_reached_data;
/* buffer status computation */
nr_rlc_entity_buffer_status_t bstatus;
nr_rlc_statistics_t stats;
time_average_t *txsdu_avg_time_to_tx;
int avg_time_is_on;
} nr_rlc_entity_t;
nr_rlc_entity_t *new_nr_rlc_entity_am(
+65 -13
View File
@@ -27,6 +27,7 @@
#include "nr_rlc_pdu.h"
#include "LOG/log.h"
#include "common/utils/time_stat.h"
/* for a given SDU/SDU segment, computes the corresponding PDU header size */
static int compute_pdu_header_size(nr_rlc_entity_am_t *entity,
@@ -221,6 +222,9 @@ static void reassemble_and_deliver(nr_rlc_entity_am_t *entity, int sn)
entity->common.deliver_sdu(entity->common.deliver_sdu_data,
(nr_rlc_entity_t *)entity,
sdu, so);
entity->common.stats.txsdu_pkts++;
entity->common.stats.txsdu_bytes += so;
}
static void reception_actions(nr_rlc_entity_am_t *entity, nr_rlc_pdu_t *pdu)
@@ -473,19 +477,18 @@ process_wait_list_head:
* if fully acked
*/
if (sn_compare_tx(entity, cur_wait_list->sdu->sn, ack_sn) < 0) {
nr_rlc_sdu_segment_t *cur = cur_wait_list;
int upper_layer_id = cur->sdu->upper_layer_id;
int sdu_size = cur->sdu->size;
cur_wait_list = cur_wait_list->next;
prev_wait_list->next = cur_wait_list;
int upper_layer_id = cur_wait_list->sdu->upper_layer_id;
int sdu_size = cur_wait_list->sdu->size;
prev_wait_list->next = cur_wait_list->next;
if (cur_wait_list == entity->wait_end)
end_wait_list = prev_wait_list;
if (nr_rlc_free_sdu_segment(cur)) {
if (nr_rlc_free_sdu_segment(cur_wait_list)) {
entity->tx_size -= sdu_size;
entity->common.sdu_successful_delivery(
entity->common.sdu_successful_delivery_data,
(nr_rlc_entity_t *)entity, upper_layer_id);
}
cur_wait_list = prev_wait_list->next;
goto process_next_pdu;
}
@@ -594,19 +597,18 @@ nacks_done:
/* current segment is acked, free it, indicate successful delivery
* if fully acked
*/
nr_rlc_sdu_segment_t *cur = cur_wait_list;
int upper_layer_id = cur->sdu->upper_layer_id;
int sdu_size = cur->sdu->size;
int upper_layer_id = cur_wait_list->sdu->upper_layer_id;
int sdu_size = cur_wait_list->sdu->size;
prev_wait_list->next = cur_wait_list->next;
if (cur_wait_list == entity->wait_end)
end_wait_list = prev_wait_list;
cur_wait_list = cur_wait_list->next;
if (nr_rlc_free_sdu_segment(cur)) {
if (nr_rlc_free_sdu_segment(cur_wait_list)) {
entity->tx_size -= sdu_size;
entity->common.sdu_successful_delivery(
entity->common.sdu_successful_delivery_data,
(nr_rlc_entity_t *)entity, upper_layer_id);
}
cur_wait_list = prev_wait_list->next;
}
/* deal with retransmit list */
while (cur_retransmit_list != NULL
@@ -684,6 +686,9 @@ void nr_rlc_entity_am_recv_pdu(nr_rlc_entity_t *_entity,
int is_first;
int is_last;
entity->common.stats.rxpdu_pkts++;
entity->common.stats.rxpdu_bytes += size;
nr_rlc_pdu_decoder_init(&decoder, buffer, size);
dc = nr_rlc_pdu_decoder_get_bits(&decoder, 1); R(decoder);
@@ -733,6 +738,10 @@ void nr_rlc_entity_am_recv_pdu(nr_rlc_entity_t *_entity,
LOG_D(RLC, "%s:%d:%s: warning: discard PDU, sn out of window (sn %d rx_next %d)\n",
__FILE__, __LINE__, __FUNCTION__,
sn, entity->rx_next);
entity->common.stats.rxpdu_ow_pkts++;
entity->common.stats.rxpdu_ow_bytes += size;
goto discard;
}
@@ -740,6 +749,10 @@ void nr_rlc_entity_am_recv_pdu(nr_rlc_entity_t *_entity,
if (segment_already_received(entity, sn, so, data_size)) {
LOG_D(RLC, "%s:%d:%s: warning: discard PDU, already received\n",
__FILE__, __LINE__, __FUNCTION__);
entity->common.stats.rxpdu_dup_pkts++;
entity->common.stats.rxpdu_dup_bytes += size;
goto discard;
}
@@ -779,6 +792,9 @@ discard:
if (p)
entity->status_triggered = 1;
entity->common.stats.rxpdu_dd_pkts++;
entity->common.stats.rxpdu_dd_bytes += size;
#undef R
}
@@ -1309,6 +1325,11 @@ static int generate_status(nr_rlc_entity_am_t *entity, char *buffer, int size)
/* start t_status_prohibit */
entity->t_status_prohibit_start = entity->t_current;
entity->common.stats.txpdu_pkts++;
entity->common.stats.txpdu_bytes += encoder.byte;
entity->common.stats.txpdu_status_pkts++;
entity->common.stats.txpdu_status_bytes += encoder.byte;
return encoder.byte;
}
@@ -1473,6 +1494,8 @@ static int generate_retx_pdu(nr_rlc_entity_am_t *entity, char *buffer,
/* update buffer status */
entity->common.bstatus.retx_size += compute_pdu_header_size(entity, next_sdu)
+ next_sdu->size;
entity->common.stats.txpdu_segmented++;
}
/* put SDU/SDU segment in the wait list */
@@ -1496,7 +1519,14 @@ static int generate_retx_pdu(nr_rlc_entity_am_t *entity, char *buffer,
entity->force_poll = 0;
}
return serialize_sdu(entity, sdu, buffer, size, p);
int ret_size = serialize_sdu(entity, sdu, buffer, size, p);
entity->common.stats.txpdu_pkts++;
entity->common.stats.txpdu_bytes += ret_size;
entity->common.stats.txpdu_retx_pkts++;
entity->common.stats.txpdu_retx_bytes += ret_size;
return ret_size;
// return serialize_sdu(entity, sdu, buffer, size, p);
}
static int generate_tx_pdu(nr_rlc_entity_am_t *entity, char *buffer, int size)
@@ -1544,6 +1574,8 @@ static int generate_tx_pdu(nr_rlc_entity_am_t *entity, char *buffer, int size)
entity->tx_list = next_sdu;
if (entity->tx_end == NULL)
entity->tx_end = entity->tx_list;
entity->common.stats.txpdu_segmented++;
/* update buffer status */
entity->common.bstatus.tx_size += compute_pdu_header_size(entity, next_sdu)
+ next_sdu->size;
@@ -1582,8 +1614,21 @@ static int generate_tx_pdu(nr_rlc_entity_am_t *entity, char *buffer, int size)
p = 1;
entity->force_poll = 0;
}
int ret_size = serialize_sdu(entity, sdu, buffer, size, p);
return serialize_sdu(entity, sdu, buffer, size, p);
entity->common.stats.txpdu_pkts++;
entity->common.stats.txpdu_bytes += ret_size;
if (sdu->sdu->time_of_arrival) {
uint64_t time_now = time_average_now();
uint64_t waited_time = time_now - sdu->sdu->time_of_arrival;
/* set time_of_arrival to 0 so as to update stats only once */
sdu->sdu->time_of_arrival = 0;
time_average_add(entity->common.txsdu_avg_time_to_tx, time_now, waited_time);
}
return ret_size;
// return serialize_sdu(entity, sdu, buffer, size, p);
}
nr_rlc_entity_buffer_status_t nr_rlc_entity_am_buffer_status(
@@ -1635,6 +1680,9 @@ void nr_rlc_entity_am_recv_sdu(nr_rlc_entity_t *_entity,
nr_rlc_entity_am_t *entity = (nr_rlc_entity_am_t *)_entity;
nr_rlc_sdu_segment_t *sdu;
entity->common.stats.rxsdu_pkts++;
entity->common.stats.rxsdu_bytes += size;
if (size > NR_SDU_MAX) {
LOG_E(RLC, "%s:%d:%s: fatal: SDU size too big (%d bytes)\n",
__FILE__, __LINE__, __FUNCTION__, size);
@@ -1667,6 +1715,9 @@ void nr_rlc_entity_am_recv_sdu(nr_rlc_entity_t *_entity,
/* update buffer status */
entity->common.bstatus.tx_size += compute_pdu_header_size(entity, sdu)
+ sdu->size;
if (entity->common.avg_time_is_on)
sdu->sdu->time_of_arrival = time_average_now();
}
/*************************************************************************/
@@ -1908,6 +1959,7 @@ void nr_rlc_entity_am_delete(nr_rlc_entity_t *_entity)
{
nr_rlc_entity_am_t *entity = (nr_rlc_entity_am_t *)_entity;
clear_entity(entity);
time_average_free(entity->common.txsdu_avg_time_to_tx);
free(entity);
}
+29
View File
@@ -25,6 +25,7 @@
#include <string.h>
#include "nr_rlc_pdu.h"
#include "common/utils/time_stat.h"
#include "LOG/log.h"
@@ -36,9 +37,16 @@ void nr_rlc_entity_tm_recv_pdu(nr_rlc_entity_t *_entity,
char *buffer, int size)
{
nr_rlc_entity_tm_t *entity = (nr_rlc_entity_tm_t *)_entity;
entity->common.stats.rxpdu_pkts++;
entity->common.stats.rxpdu_bytes += size;
entity->common.deliver_sdu(entity->common.deliver_sdu_data,
(nr_rlc_entity_t *)entity,
buffer, size);
entity->common.stats.txsdu_pkts++;
entity->common.stats.txsdu_bytes += size;
}
/*************************************************************************/
@@ -68,6 +76,16 @@ static int generate_tx_pdu(nr_rlc_entity_tm_t *entity, char *buffer, int size)
memcpy(buffer, sdu->sdu->data, sdu->size);
entity->tx_size -= sdu->size;
entity->common.stats.txpdu_pkts++;
entity->common.stats.txpdu_bytes += size;
if (sdu->sdu->time_of_arrival) {
uint64_t time_now = time_average_now();
uint64_t waited_time = time_now - sdu->sdu->time_of_arrival;
/* set time_of_arrival to 0 so as to update stats only once */
sdu->sdu->time_of_arrival = 0;
time_average_add(entity->common.txsdu_avg_time_to_tx, time_now, waited_time);
}
/* update buffer status */
entity->common.bstatus.tx_size -= sdu->size;
@@ -109,6 +127,9 @@ void nr_rlc_entity_tm_recv_sdu(nr_rlc_entity_t *_entity,
nr_rlc_entity_tm_t *entity = (nr_rlc_entity_tm_t *)_entity;
nr_rlc_sdu_segment_t *sdu;
entity->common.stats.rxsdu_pkts++;
entity->common.stats.rxsdu_bytes += size;
if (size > NR_SDU_MAX) {
LOG_E(RLC, "%s:%d:%s: fatal: SDU size too big (%d bytes)\n",
__FILE__, __LINE__, __FUNCTION__, size);
@@ -118,6 +139,10 @@ void nr_rlc_entity_tm_recv_sdu(nr_rlc_entity_t *_entity,
if (entity->tx_size + size > entity->tx_maxsize) {
LOG_D(RLC, "%s:%d:%s: warning: SDU rejected, SDU buffer full\n",
__FILE__, __LINE__, __FUNCTION__);
entity->common.stats.rxsdu_dd_pkts++;
entity->common.stats.rxsdu_dd_bytes += size;
return;
}
@@ -129,6 +154,9 @@ void nr_rlc_entity_tm_recv_sdu(nr_rlc_entity_t *_entity,
/* update buffer status */
entity->common.bstatus.tx_size += sdu->size;
if (entity->common.avg_time_is_on)
sdu->sdu->time_of_arrival = time_average_now();
}
/*************************************************************************/
@@ -172,6 +200,7 @@ void nr_rlc_entity_tm_delete(nr_rlc_entity_t *_entity)
{
nr_rlc_entity_tm_t *entity = (nr_rlc_entity_tm_t *)_entity;
clear_entity(entity);
time_average_free(entity->common.txsdu_avg_time_to_tx);
free(entity);
}
+55
View File
@@ -27,6 +27,7 @@
#include "nr_rlc_pdu.h"
#include "LOG/log.h"
#include "common/utils/time_stat.h"
/* for a given SDU/SDU segment, computes the corresponding PDU header size */
static int compute_pdu_header_size(nr_rlc_entity_um_t *entity,
@@ -179,6 +180,9 @@ static void reassemble_and_deliver(nr_rlc_entity_um_t *entity, int sn)
entity->common.deliver_sdu(entity->common.deliver_sdu_data,
(nr_rlc_entity_t *)entity,
sdu, so);
entity->common.stats.txsdu_pkts++;
entity->common.stats.txsdu_bytes += so;
}
static void reception_actions(nr_rlc_entity_um_t *entity, nr_rlc_pdu_t *pdu)
@@ -208,6 +212,15 @@ static void reception_actions(nr_rlc_entity_um_t *entity, nr_rlc_pdu_t *pdu)
nr_rlc_pdu_t *p = entity->rx_list;
entity->rx_size -= p->size;
entity->rx_list = p->next;
entity->common.stats.rxpdu_dd_pkts++;
/* we don't count PDU header bytes here, so be it */
entity->common.stats.rxpdu_dd_bytes += p->size;
entity->common.stats.rxpdu_ow_pkts++;
/* we don't count PDU header bytes here, so be it */
entity->common.stats.rxpdu_ow_bytes += p->size;
nr_rlc_free_pdu(p);
}
@@ -272,6 +285,9 @@ void nr_rlc_entity_um_recv_pdu(nr_rlc_entity_t *_entity,
int is_first;
int is_last;
entity->common.stats.rxpdu_pkts++;
entity->common.stats.rxpdu_bytes += size;
nr_rlc_pdu_decoder_init(&decoder, buffer, size);
si = nr_rlc_pdu_decoder_get_bits(&decoder, 2); R(decoder);
@@ -290,6 +306,10 @@ void nr_rlc_entity_um_recv_pdu(nr_rlc_entity_t *_entity,
entity->common.deliver_sdu(entity->common.deliver_sdu_data,
(nr_rlc_entity_t *)entity,
buffer + 1, size - 1);
entity->common.stats.txsdu_pkts++;
entity->common.stats.txsdu_bytes += size - 1;
return;
}
@@ -350,6 +370,9 @@ err:
goto discard;
discard:
entity->common.stats.rxpdu_dd_pkts++;
entity->common.stats.rxpdu_dd_bytes += size;
return;
#undef R
@@ -434,6 +457,8 @@ static nr_rlc_sdu_segment_t *resegment(nr_rlc_sdu_segment_t *sdu,
next->so = sdu->so + sdu->size;
next->is_first = 0;
entity->common.stats.txpdu_segmented++;
return next;
}
@@ -478,6 +503,8 @@ static int generate_tx_pdu(nr_rlc_entity_um_t *entity, char *buffer, int size)
entity->tx_list = next_sdu;
if (entity->tx_end == NULL)
entity->tx_end = entity->tx_list;
entity->common.stats.txpdu_segmented++;
/* update buffer status */
entity->common.bstatus.tx_size += compute_pdu_header_size(entity, next_sdu)
+ next_sdu->size;
@@ -490,6 +517,18 @@ static int generate_tx_pdu(nr_rlc_entity_um_t *entity, char *buffer, int size)
ret = serialize_sdu(entity, sdu, buffer, size);
entity->tx_size -= sdu->size;
entity->common.stats.txpdu_pkts++;
entity->common.stats.txpdu_bytes += size;
if (sdu->sdu->time_of_arrival) {
uint64_t time_now = time_average_now();
uint64_t waited_time = time_now - sdu->sdu->time_of_arrival;
/* set time_of_arrival to 0 so as to update stats only once */
sdu->sdu->time_of_arrival = 0;
time_average_add(entity->common.txsdu_avg_time_to_tx, time_now, waited_time);
}
nr_rlc_free_sdu_segment(sdu);
return ret;
@@ -527,6 +566,9 @@ void nr_rlc_entity_um_recv_sdu(nr_rlc_entity_t *_entity,
nr_rlc_entity_um_t *entity = (nr_rlc_entity_um_t *)_entity;
nr_rlc_sdu_segment_t *sdu;
entity->common.stats.rxsdu_pkts++;
entity->common.stats.rxsdu_bytes += size;
if (size > NR_SDU_MAX) {
LOG_E(RLC, "%s:%d:%s: fatal: SDU size too big (%d bytes)\n",
__FILE__, __LINE__, __FUNCTION__, size);
@@ -536,6 +578,10 @@ void nr_rlc_entity_um_recv_sdu(nr_rlc_entity_t *_entity,
if (entity->tx_size + size > entity->tx_maxsize) {
LOG_W(RLC, "%s:%d:%s: warning: SDU rejected, SDU buffer full\n",
__FILE__, __LINE__, __FUNCTION__);
entity->common.stats.rxsdu_dd_pkts++;
entity->common.stats.rxsdu_dd_bytes += size;
return;
}
@@ -548,6 +594,9 @@ void nr_rlc_entity_um_recv_sdu(nr_rlc_entity_t *_entity,
/* update buffer status */
entity->common.bstatus.tx_size += compute_pdu_header_size(entity, sdu)
+ sdu->size;
if (entity->common.avg_time_is_on)
sdu->sdu->time_of_arrival = time_average_now();
}
/*************************************************************************/
@@ -584,6 +633,11 @@ static void check_t_reassembly(nr_rlc_entity_um_t *entity)
nr_rlc_pdu_t *p = cur;
cur = cur->next;
entity->rx_list = cur;
entity->common.stats.rxpdu_dd_pkts++;
/* we don't count PDU header bytes here, so be it */
entity->common.stats.rxpdu_dd_bytes += p->size;
nr_rlc_free_pdu(p);
}
@@ -693,6 +747,7 @@ void nr_rlc_entity_um_delete(nr_rlc_entity_t *_entity)
{
nr_rlc_entity_um_t *entity = (nr_rlc_entity_um_t *)_entity;
clear_entity(entity);
time_average_free(entity->common.txsdu_avg_time_to_tx);
free(entity);
}
+63
View File
@@ -1110,3 +1110,66 @@ void rlc_tick(int a, int b)
__FILE__, __LINE__, __FUNCTION__);
exit(1);
}
void nr_rlc_activate_avg_time_to_tx(
const rnti_t rnti,
const logical_chan_id_t channel_id,
const bool is_on)
{
nr_rlc_ue_t *ue;
nr_rlc_entity_t *rb;
nr_rlc_manager_lock(nr_rlc_ue_manager);
ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rnti);
switch (channel_id) {
case 1 ... 3: rb = ue->srb[channel_id - 1]; break;
case 4 ... 8: rb = ue->drb[channel_id - 4]; break;
default: rb = NULL; break;
}
if (rb != NULL) {
rb->avg_time_is_on = is_on;
time_average_reset(rb->txsdu_avg_time_to_tx);
} else {
LOG_E(RLC, "[%s] Radio Bearer (channel ID %d) is NULL for UE with rnti %x\n", __FUNCTION__, channel_id, rnti);
}
nr_rlc_manager_unlock(nr_rlc_ue_manager);
}
/* returns false in case of error, true if everything ok */
const bool nr_rlc_get_statistics(
int rnti,
int srb_flag,
int rb_id,
nr_rlc_statistics_t *out)
{
nr_rlc_ue_t *ue;
nr_rlc_entity_t *rb;
bool ret;
nr_rlc_manager_lock(nr_rlc_ue_manager);
ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rnti);
rb = NULL;
if (srb_flag) {
if (rb_id >= 1 && rb_id <= 2)
rb = ue->srb[rb_id - 1];
} else {
if (rb_id >= 1 && rb_id <= 5)
rb = ue->drb[rb_id - 1];
}
if (rb != NULL) {
rb->get_stats(rb, out);
ret = true;
} else {
ret = false;
}
nr_rlc_manager_unlock(nr_rlc_ue_manager);
return ret;
}
+5
View File
@@ -51,3 +51,8 @@ void nr_rlc_bearer_init_ul_spec(struct NR_LogicalChannelConfig *mac_LogicalChann
int nr_rlc_get_available_tx_space(
const rnti_t rntiP,
const logical_chan_id_t channel_idP);
void nr_rlc_activate_avg_time_to_tx(
const rnti_t rnti,
const logical_chan_id_t channel_id,
const bool is_on);
+8
View File
@@ -22,6 +22,8 @@
#ifndef _NR_RLC_SDU_H_
#define _NR_RLC_SDU_H_
#include <stdint.h>
typedef struct nr_rlc_sdu_t {
int sn;
int upper_layer_id;
@@ -34,6 +36,12 @@ typedef struct nr_rlc_sdu_t {
* when it equals ref_count we can free the SDU
* completely
*/
/* for statistics, will be set to 0 after SDU (or first part of it) has
* been serialized for MAC for the first time so that only the first
* transmission is used for statistics
*/
uint64_t time_of_arrival; /* unit microsecond */
} nr_rlc_sdu_t;
typedef struct nr_rlc_sdu_segment_t {
+2 -2
View File
@@ -1,8 +1,8 @@
CC=gcc
CFLAGS=-Wall -g --coverage -I.
CFLAGS=-Wall -g --coverage -I. -I../../../..
LIB=nr_rlc_entity.o nr_rlc_entity_am.o nr_rlc_entity_um.o nr_rlc_entity_tm.o \
nr_rlc_pdu.o nr_rlc_sdu.o
nr_rlc_pdu.o nr_rlc_sdu.o time_stat.o
tests:
@./run_tests.sh
+25
View File
@@ -0,0 +1,25 @@
#include "../../../../common/utils/time_stat.h"
time_average_t *time_average_new(int duration, int initial_size)
{
return (void *)0;
}
void time_average_free(time_average_t *t)
{
}
void time_average_add(time_average_t *t, uint64_t time, uint64_t value)
{
}
double time_average_get_average(time_average_t *t, uint64_t time)
{
return 0;
}
uint64_t time_average_now(void)
{
return 0;
}