From b2f85f7ac2ed19f13cb27ae7023c6462bfeba8f8 Mon Sep 17 00:00:00 2001 From: Ricky S Date: Thu, 14 Jan 2021 15:53:06 -0800 Subject: [PATCH 01/26] Episys/initial channel model --- openair2/PHY_INTERFACE/phy_stub_UE.c | 208 ++++++++++++++++++++++++--- openair2/PHY_INTERFACE/phy_stub_UE.h | 31 ++++ targets/RT/USER/lte-softmodem.h | 2 + targets/RT/USER/lte-uesoftmodem.c | 65 +++++++++ 4 files changed, 287 insertions(+), 19 deletions(-) diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c index 371c5bc6b7..118714e1b3 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.c +++ b/openair2/PHY_INTERFACE/phy_stub_UE.c @@ -50,6 +50,8 @@ queue_t hi_dci0_req_queue; int current_sfn_sf; sem_t sfn_semaphore; +static sf_rnti_mcs_s sf_rnti_mcs[10]; + static int ue_tx_sock_descriptor = -1; static int ue_rx_sock_descriptor = -1; @@ -293,7 +295,7 @@ void fill_ulsch_cqi_indication_UE_MAC(int Mod_id, pdu->ul_cqi_information.channel = 1; // eNB_scheduler_primitives.c:4839: the upper four bits seem to be the CQI - const int cqi = 15; + const int cqi = 15; // Need to map EMANE SINR to CQI! raw_pdu->pdu[0] = cqi << 4; UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis++; @@ -373,7 +375,7 @@ void fill_uci_harq_indication_UE_MAC(int Mod_id, pdu->ul_cqi_information.tl.tag = NFAPI_UL_CQI_INFORMATION_TAG; - int SNRtimes10 = 640; + int SNRtimes10 = 640; // TODO: Replace with EpiSci SNR * 10 if (SNRtimes10 < -640) pdu->ul_cqi_information.ul_cqi = 0; @@ -402,6 +404,12 @@ void fill_uci_harq_indication_UE_MAC(int Mod_id, // go look to see if dl_config_req (with c-rnti) was received in subframe (n - 4) // 3.) if the answer to #2 is yes then send ACK IF NOT send DTX + if (drop_tb((subframe+6) % 10, rnti)) // TODO: Handle DTX. Also discuss handling PDCCH + { + pdu->harq_indication_fdd_rel13.harq_tb_n[0] = 2; + LOG_I(PHY, "Setting HARQ No ACK - Channel Model\n"); + } + } else if ((harq_information->harq_information_rel9_fdd.ack_nack_mode == 0) && (harq_information->harq_information_rel9_fdd.harq_size == 2)) { @@ -791,10 +799,18 @@ void dl_config_req_UE_MAC_dci(int sfn, sfn, sf, dci->pdu_size, dlsch->dlsch_pdu.dlsch_pdu_rel8.pdu_index, tx_req_pdu_list->num_pdus); - ue_send_sdu(ue_id, 0, sfn, sf, - tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, - tx_req_pdu_list->pdus[pdu_index].segments[0].segment_length, - 0); + + if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) + { + ue_send_sdu(ue_id, 0, sfn, sf, + tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, + tx_req_pdu_list->pdus[pdu_index].segments[0].segment_length, + 0); + } + else + { + LOG_I(MAC, "Transport Block discarded - ue_send_sdu not called. sf: %d", sf); + } return; } } @@ -804,17 +820,33 @@ void dl_config_req_UE_MAC_dci(int sfn, if (UE_mac_inst[ue_id].UE_mode[0] == NOT_SYNCHED) continue; - ue_decode_si(ue_id, 0, sfn, 0, - tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, - tx_req_pdu_list->pdus[pdu_index].segments[0].segment_length); + if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) + { + ue_decode_si(ue_id, 0, sfn, 0, + tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, + tx_req_pdu_list->pdus[pdu_index].segments[0].segment_length); + } + else + { + LOG_I(MAC, "Transport Block discarded - ue_decode_si not called. sf: %d", sf); + } } } else if (rnti == 0xFFFE) { /* PI-RNTI */ for (int ue_id = 0; ue_id < num_ue; ue_id++) { LOG_I(MAC, "%s() Received paging message: sfn/sf:%d.%d\n", __func__, sfn, sf); - ue_decode_p(ue_id, 0, sfn, 0, - tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, - tx_req_pdu_list->pdus[pdu_index].segments[0].segment_length); + + + if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) + { + ue_decode_p(ue_id, 0, sfn, 0, + tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, + tx_req_pdu_list->pdus[pdu_index].segments[0].segment_length); + } + else + { + LOG_I(MAC, "Transport Block discarded - ue_decode_p not called. sf: %d", sf); + } } } else if (rnti == 0x0002) { /* RA-RNTI */ for (int ue_id = 0; ue_id < num_ue; ue_id++) { @@ -834,12 +866,21 @@ void dl_config_req_UE_MAC_dci(int sfn, LOG_E(MAC, "%s(): Received RAR, PreambleIndex: %d\n", __func__, UE_mac_inst[ue_id].RA_prach_resources.ra_PreambleIndex); - ue_process_rar(ue_id, 0, sfn, - ra_rnti, //RA-RNTI - tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, - &UE_mac_inst[ue_id].crnti, //t-crnti - UE_mac_inst[ue_id].RA_prach_resources.ra_PreambleIndex, - tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data); + + + if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) + { + ue_process_rar(ue_id, 0, sfn, + ra_rnti, //RA-RNTI + tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, + &UE_mac_inst[ue_id].crnti, //t-crnti + UE_mac_inst[ue_id].RA_prach_resources.ra_PreambleIndex, + tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data); + } + else + { + LOG_I(MAC, "Transport Block discarded - RAR Not Processed. sf: %d, ra_rnti: %d", sf, ra_rnti); + } // UE_mac_inst[ue_id].UE_mode[0] = RA_RESPONSE; LOG_I(MAC, "setting UE_MODE now: %d\n", UE_mac_inst[ue_id].UE_mode[0]); // Expecting an UL_CONFIG_ULSCH_PDU to enable Msg3 Txon (first @@ -1251,7 +1292,6 @@ void *ue_standalone_pnf_task(void *context) struct sockaddr_in server_address; socklen_t addr_len = sizeof(server_address); char buffer[1024]; - int sd = ue_rx_sock_descriptor; assert(sd > 0); @@ -1280,6 +1320,26 @@ void *ue_standalone_pnf_task(void *context) abort(); } } + else if (len == sizeof(channel_info)) + { + LOG_I(MAC, "Entered Channel Info Loop"); + channel_info * ch_info = malloc(sizeof(channel_info)); + + memcpy(ch_info, buffer, sizeof(channel_info)); + current_sfn_sf = ch_info->sfn_sf; + if (sem_post(&sfn_semaphore) != 0) + { + LOG_E(MAC, "sem_post() error\n"); + abort(); + } + uint16_t sf = ch_info->sfn_sf & 15; + if(sf > 10 && sf < 0) + { + LOG_E(MAC, "sf out of bounds, sfn: %d\n", sf); + abort(); + } + sf_rnti_mcs[sf].sinr = ch_info->sinr; + } else { nfapi_p7_message_header_t header; @@ -1318,6 +1378,7 @@ void *ue_standalone_pnf_task(void *context) tx_req_valid = false; break; } + read_channel_param(&dl_config_req, (dl_config_req.sfn_sf & 15)); enqueue_dl_config_req_tx_req(&dl_config_req, &tx_req); dl_config_req_valid = false; tx_req_valid = false; @@ -1865,3 +1926,112 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) void init_eNB_afterRU(void) { } + + void read_channel_param(nfapi_dl_config_request_t * dl_config, int sf) + { + if (dl_config == NULL) + { + LOG_E(MAC,"DL_CONFIG NULL\n"); + abort(); + } + + // Store all rnti and mcs for all pdus + sf_rnti_mcs[sf].pdu_size = dl_config->dl_config_request_body.number_pdu; + for (int n = 0; n < sf_rnti_mcs[sf].pdu_size; n++) + { + sf_rnti_mcs[sf].rnti[n] = dl_config->dl_config_request_body.dl_config_pdu_list[n].dci_dl_pdu.dci_dl_pdu_rel8.rnti; + sf_rnti_mcs[sf].mcs[n] = dl_config->dl_config_request_body.dl_config_pdu_list[n].dci_dl_pdu.dci_dl_pdu_rel8.mcs_1; + } + } + + int drop_tb(int sf, uint16_t rnti) + { + int sinr_index = 0; + bool lin_interp = false; + bool skip_search = false; + + assert(sf < 10 && sf >= 0); + + uint8_t mcs = 99; + for (int n = 0; n < sf_rnti_mcs[sf].pdu_size; n++) + { + if (sf_rnti_mcs[sf].rnti[n] == rnti) + { + mcs = sf_rnti_mcs[sf].mcs[n]; + break; + } + } + + if (mcs == 99) + { + LOG_E(MAC, "NO MCS Found\n"); + abort(); + } + + // Loop through bler table to find sinr_index - What if EMANE SINR doesn't match any of the table SINR values?? + //float epsilon = 0.0001; + int temp_bler = 0; + int temp_sinr = ((int)(sf_rnti_mcs[sf].sinr * 10)); + int i; + float bler_val = 0.0; + + if (temp_sinr < (int)(bler_data[mcs].bler_table[0][0] * 10)) + { + skip_search = true; + bler_val = 0.0; + } + else if (temp_sinr > (int)(bler_data[mcs].bler_table[bler_data[mcs].length - 1][0] * 10)) + { + skip_search = true; + bler_val = 1.0; + } + + + for (i = 0; i < bler_data[mcs].length; i++) + { + if(skip_search) + break; + + temp_bler = (int)(bler_data[mcs].bler_table[i][0] * 10); + if (temp_bler == temp_sinr) + { + sinr_index = i; + break; + } + // Linear interpolation when SINR is between indices + else if (temp_bler > temp_sinr) + { + sinr_index = i; + lin_interp = true; + break; + } + + } + if (i >= (bler_data[mcs].length - 1)) + { + LOG_E(MAC, "NO SINR INDEX FOUND! - mcs: %d, temp_sinr: %d, temp_bler: %d, sinr_index: %d\n", mcs, temp_sinr, temp_bler, sinr_index); + abort(); + } + + if (lin_interp) + { + bler_val = ((bler_data[mcs].bler_table[sinr_index - 1][3] + bler_data[mcs].bler_table[sinr_index][3]) / 2); + } + else + { + if (skip_search == false) + bler_val = bler_data[mcs].bler_table[sinr_index][3]; // 3 is the rate, or bler rate column + } + + double drop_cutoff = ((double) rand() / (RAND_MAX)); + assert(drop_cutoff < 1); + + if (bler_val <= drop_cutoff) + { + return 1; + } + else + { + return 0; + } + } diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.h b/openair2/PHY_INTERFACE/phy_stub_UE.h index d1324e4e6f..b6f3da8fd5 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.h +++ b/openair2/PHY_INTERFACE/phy_stub_UE.h @@ -21,6 +21,10 @@ //#include "openair1/PHY/LTE_TRANSPORT/defs.h" #include "queue.h" +#define NUM_MCS 28 +#define NUM_SINR 100 +#define NUM_BLER_COL 13 + // this mutex is used to set multiple UE's UL value in L2 FAPI simulator. FILL_UL_INFO_MUTEX_t fill_ul_mutex; //below 2 difinitions move to phy_stub_UE.c to add initialization when difinition. @@ -34,6 +38,30 @@ extern UL_IND_t *UL_INFO; //module_id_t next_Mod_id; eth_params_t stub_eth_params; +typedef struct +{ + uint16_t sfn_sf; + float sinr; + // Incomplete, need all channel parameters +} channel_info; + +typedef struct +{ + uint8_t sf; + uint16_t rnti[256]; + uint8_t mcs[256]; + float sinr; + uint16_t pdu_size; + +} sf_rnti_mcs_s; + +typedef struct +{ + uint16_t length; + float bler_table[NUM_SINR][NUM_BLER_COL]; +} bler_struct; + +extern bler_struct bler_data[NUM_MCS]; @@ -171,6 +199,9 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req); const char *dl_pdu_type_to_string(uint8_t pdu_type); const char *ul_pdu_type_to_string(uint8_t pdu_type); +void read_channel_param(nfapi_dl_config_request_t * dl_config, int sf); +int drop_tb(int sf, uint16_t rnti); + extern queue_t dl_config_req_tx_req_queue; extern queue_t ul_config_req_queue; extern queue_t hi_dci0_req_queue; diff --git a/targets/RT/USER/lte-softmodem.h b/targets/RT/USER/lte-softmodem.h index 0f1ff82b41..521483de5e 100644 --- a/targets/RT/USER/lte-softmodem.h +++ b/targets/RT/USER/lte-softmodem.h @@ -212,4 +212,6 @@ extern void init_UE_standalone_thread(int ue_idx); extern PHY_VARS_UE *init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms, uint8_t UE_id, uint8_t abstraction_flag); +extern void init_bler_table(void); + #endif diff --git a/targets/RT/USER/lte-uesoftmodem.c b/targets/RT/USER/lte-uesoftmodem.c index 55d14287ef..052e0f5247 100644 --- a/targets/RT/USER/lte-uesoftmodem.c +++ b/targets/RT/USER/lte-uesoftmodem.c @@ -194,6 +194,8 @@ int oaisim_flag=0; */ uint8_t abstraction_flag=0; +bler_struct bler_data[NUM_MCS]; + /* forward declarations */ void set_default_frame_parms(LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]); @@ -749,6 +751,8 @@ int main( int argc, char **argv ) { init_queue(&hi_dci0_req_queue); init_queue(&ul_config_req_queue); + init_bler_table(); + config_sync_var=0; if (sem_init(&sfn_semaphore, 0, 0) != 0) { @@ -837,3 +841,64 @@ int main( int argc, char **argv ) { printf("Bye.\n"); return 0; } + + +// Read in each MCS file and build BLER-SINR-TB table +void init_bler_table(void) +{ + size_t bufSize = 128; + char fName[bufSize]; + char * line = NULL; + char * token; + char * temp = NULL; + FILE *pFile; + char * home = getenv("HOME"); + + // Maybe not needed... and may not work. + memset(bler_data, 0, sizeof(bler_data)); + + for (unsigned int i = 0; i < NUM_MCS; i++) + { + // Filename needs to be changed to dynamic name + snprintf(fName, sizeof(fName), "%s/openairinterface5g/openair1/SIMULATION/LTE_PHY/BLER_SIMULATIONS/AWGN/AWGN_results/bler_tx1_chan18_nrx1_mcs%d.csv", home, i); + pFile = fopen(fName, "r"); + if(!pFile) + { + LOG_E(MAC, "Bler File ERROR! - fopen(), file: %s\n", fName); + abort(); + } + int nlines = 0; + while(getline(&line, &bufSize, pFile) > 0) + { + if (!strncmp(line,"SNR",3)) + { + continue; + } + + if (nlines > NUM_SINR) + { + LOG_E(MAC, "BLER FILE ERROR - num lines greater than expected - file: %s\n", fName); + abort(); + } + + token = strtok_r(line, ";", &temp); + int ncols = 0; + while (token != NULL) + { + if (ncols > NUM_BLER_COL) + { + LOG_E(MAC, "BLER FILE ERROR - num of cols greater than expected\n"); + abort(); + } + + bler_data[i].bler_table[nlines][ncols] = strtof(token, NULL); + ncols++; + + token = strtok_r(NULL, ";", &temp); + } + nlines++; + } + bler_data[i].length = nlines; + fclose(pFile); + } +} From c541324c5dc8e52242422c4200731e84921aafa2 Mon Sep 17 00:00:00 2001 From: David Kim Date: Thu, 14 Jan 2021 16:08:54 -0800 Subject: [PATCH 02/26] updating mcs file location to openair_dir --- targets/RT/USER/lte-uesoftmodem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/targets/RT/USER/lte-uesoftmodem.c b/targets/RT/USER/lte-uesoftmodem.c index 052e0f5247..8b81b65c36 100644 --- a/targets/RT/USER/lte-uesoftmodem.c +++ b/targets/RT/USER/lte-uesoftmodem.c @@ -852,7 +852,7 @@ void init_bler_table(void) char * token; char * temp = NULL; FILE *pFile; - char * home = getenv("HOME"); + const char *openair_dir = getenv("OPENAIR_DIR"); // Maybe not needed... and may not work. memset(bler_data, 0, sizeof(bler_data)); @@ -860,7 +860,7 @@ void init_bler_table(void) for (unsigned int i = 0; i < NUM_MCS; i++) { // Filename needs to be changed to dynamic name - snprintf(fName, sizeof(fName), "%s/openairinterface5g/openair1/SIMULATION/LTE_PHY/BLER_SIMULATIONS/AWGN/AWGN_results/bler_tx1_chan18_nrx1_mcs%d.csv", home, i); + snprintf(fName, sizeof(fName), "%s/openair1/SIMULATION/LTE_PHY/BLER_SIMULATIONS/AWGN/AWGN_results/bler_tx1_chan18_nrx1_mcs%d.csv", openair_dir, i); pFile = fopen(fName, "r"); if(!pFile) { From e437a19c505099fbc2a1297dfb713b9d2625dcba Mon Sep 17 00:00:00 2001 From: Michael Cook Date: Thu, 14 Jan 2021 16:34:30 -0800 Subject: [PATCH 03/26] lte-uesoftmodem.c: issues reading bler files --- targets/RT/USER/lte-uesoftmodem.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/targets/RT/USER/lte-uesoftmodem.c b/targets/RT/USER/lte-uesoftmodem.c index 8b81b65c36..a6143c4da7 100644 --- a/targets/RT/USER/lte-uesoftmodem.c +++ b/targets/RT/USER/lte-uesoftmodem.c @@ -846,13 +846,16 @@ int main( int argc, char **argv ) { // Read in each MCS file and build BLER-SINR-TB table void init_bler_table(void) { - size_t bufSize = 128; - char fName[bufSize]; + size_t bufSize = 1024; char * line = NULL; char * token; char * temp = NULL; - FILE *pFile; const char *openair_dir = getenv("OPENAIR_DIR"); + if (!openair_dir) + { + LOG_E(MAC, "No $OPENAIR_DIR\n"); + abort(); + } // Maybe not needed... and may not work. memset(bler_data, 0, sizeof(bler_data)); @@ -860,15 +863,16 @@ void init_bler_table(void) for (unsigned int i = 0; i < NUM_MCS; i++) { // Filename needs to be changed to dynamic name + char fName[1024]; snprintf(fName, sizeof(fName), "%s/openair1/SIMULATION/LTE_PHY/BLER_SIMULATIONS/AWGN/AWGN_results/bler_tx1_chan18_nrx1_mcs%d.csv", openair_dir, i); - pFile = fopen(fName, "r"); - if(!pFile) + FILE *pFile = fopen(fName, "r"); + if (!pFile) { LOG_E(MAC, "Bler File ERROR! - fopen(), file: %s\n", fName); abort(); } int nlines = 0; - while(getline(&line, &bufSize, pFile) > 0) + while (getline(&line, &bufSize, pFile) > 0) { if (!strncmp(line,"SNR",3)) { From 27a232ab63441c578a3bb2dbb214ad4349e7a963 Mon Sep 17 00:00:00 2001 From: Melissa Elkadi Date: Fri, 15 Jan 2021 13:42:31 -0800 Subject: [PATCH 04/26] Sending ACK or NACK for uci_harq_ind fix A fix had to be made in the uci_harq indication function in the UE. The uci_harq indicaiton function was not properly checking for dropped packets four subframes back in the UE. --- openair2/PHY_INTERFACE/phy_stub_UE.c | 77 +++++++++++++++++----------- openair2/PHY_INTERFACE/phy_stub_UE.h | 4 +- targets/RT/USER/lte-softmodem.c | 2 + 3 files changed, 52 insertions(+), 31 deletions(-) diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c index 118714e1b3..db7c87195e 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.c +++ b/openair2/PHY_INTERFACE/phy_stub_UE.c @@ -50,12 +50,12 @@ queue_t hi_dci0_req_queue; int current_sfn_sf; sem_t sfn_semaphore; -static sf_rnti_mcs_s sf_rnti_mcs[10]; +static sf_rnti_mcs_s sf_rnti_mcs[NUM_NFPAI_SUBFRAME]; static int ue_tx_sock_descriptor = -1; static int ue_rx_sock_descriptor = -1; -extern nfapi_tx_request_pdu_t* tx_request_pdu[1023][10][10]; +extern nfapi_tx_request_pdu_t* tx_request_pdu[1023][NUM_NFPAI_SUBFRAME][10]; //TODO Melissa check these values //extern int timer_subframe; //extern int timer_frame; @@ -403,8 +403,7 @@ void fill_uci_harq_indication_UE_MAC(int Mod_id, // 2.) if receiving ul_config_req for uci ack/nack or ulsch ack/nak in subframe n // go look to see if dl_config_req (with c-rnti) was received in subframe (n - 4) // 3.) if the answer to #2 is yes then send ACK IF NOT send DTX - - if (drop_tb((subframe+6) % 10, rnti)) // TODO: Handle DTX. Also discuss handling PDCCH + if (check_drop_tb(((subframe+6) % 10), rnti)) // TODO: Handle DTX. Also discuss handling PDCCH { pdu->harq_indication_fdd_rel13.harq_tb_n[0] = 2; LOG_I(PHY, "Setting HARQ No ACK - Channel Model\n"); @@ -799,8 +798,7 @@ void dl_config_req_UE_MAC_dci(int sfn, sfn, sf, dci->pdu_size, dlsch->dlsch_pdu.dlsch_pdu_rel8.pdu_index, tx_req_pdu_list->num_pdus); - - if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) + if (!check_drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) { ue_send_sdu(ue_id, 0, sfn, sf, tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, @@ -819,8 +817,7 @@ void dl_config_req_UE_MAC_dci(int sfn, for (int ue_id = 0; ue_id < num_ue; ue_id++) { if (UE_mac_inst[ue_id].UE_mode[0] == NOT_SYNCHED) continue; - - if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) + if (!check_drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) { ue_decode_si(ue_id, 0, sfn, 0, tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, @@ -836,8 +833,7 @@ void dl_config_req_UE_MAC_dci(int sfn, LOG_I(MAC, "%s() Received paging message: sfn/sf:%d.%d\n", __func__, sfn, sf); - - if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) + if (!check_drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) { ue_decode_p(ue_id, 0, sfn, 0, tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, @@ -867,8 +863,7 @@ void dl_config_req_UE_MAC_dci(int sfn, "%s(): Received RAR, PreambleIndex: %d\n", __func__, UE_mac_inst[ue_id].RA_prach_resources.ra_PreambleIndex); - - if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) + if (!check_drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) { ue_process_rar(ue_id, 0, sfn, ra_rnti, //RA-RNTI @@ -1368,6 +1363,7 @@ void *ue_standalone_pnf_task(void *context) dl_config_req.sfn_sf & 15); dl_config_req_valid = true; + read_channel_param(&dl_config_req, (dl_config_req.sfn_sf & 15)); if (tx_req_valid) { if (dl_config_req.sfn_sf != tx_req.sfn_sf) @@ -1378,7 +1374,6 @@ void *ue_standalone_pnf_task(void *context) tx_req_valid = false; break; } - read_channel_param(&dl_config_req, (dl_config_req.sfn_sf & 15)); enqueue_dl_config_req_tx_req(&dl_config_req, &tx_req); dl_config_req_valid = false; tx_req_valid = false; @@ -1936,6 +1931,7 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) } // Store all rnti and mcs for all pdus + LOG_I(MAC, "Adding MCS and RNTI for sf_rnti_mcs[%d]\n", sf); sf_rnti_mcs[sf].pdu_size = dl_config->dl_config_request_body.number_pdu; for (int n = 0; n < sf_rnti_mcs[sf].pdu_size; n++) { @@ -1944,32 +1940,56 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) } } - int drop_tb(int sf, uint16_t rnti) + int check_drop_tb(int sf, uint16_t rnti) { - int sinr_index = 0; - bool lin_interp = false; - bool skip_search = false; + if (sf_rnti_mcs[sf].pdu_size <= 0) + { + LOG_E(MAC, "%s: sf_rnti_mcs[%d].pdu_size = 0\n", __FUNCTION__, sf); + abort(); + } - assert(sf < 10 && sf >= 0); - - uint8_t mcs = 99; for (int n = 0; n < sf_rnti_mcs[sf].pdu_size; n++) + { + if (sf_rnti_mcs[sf].rnti[n] == rnti) + { + return sf_rnti_mcs[sf].drop_flag[n]; + } + } + LOG_I(MAC, "No matching rnti in sf_rnti_mcs.\n"); + return 0; + } + + void drop_tb(int sf, uint16_t rnti) + { + assert(sf < 10 && sf >= 0); + + if (sf_rnti_mcs[sf].pdu_size <= 0) + { + LOG_E(MAC, "%s: sf_rnti_mcs[%d].pdu_size = 0\n", __FUNCTION__, sf); + } + + uint8_t mcs = 99; + int n = 0; + for (n = 0; n < sf_rnti_mcs[sf].pdu_size; n++) { if (sf_rnti_mcs[sf].rnti[n] == rnti) { mcs = sf_rnti_mcs[sf].mcs[n]; + sf_rnti_mcs[sf].drop_flag[n] = 0; break; } } if (mcs == 99) { - LOG_E(MAC, "NO MCS Found\n"); + LOG_E(MAC, "NO MCS Found. %d = sf_rnti_mcs[%d].mcs[%d] \n", mcs, sf, n); abort(); } - // Loop through bler table to find sinr_index - What if EMANE SINR doesn't match any of the table SINR values?? - //float epsilon = 0.0001; + // Loop through bler table to find sinr_index + int sinr_index = 0; + bool lin_interp = false; + bool skip_search = false; int temp_bler = 0; int temp_sinr = ((int)(sf_rnti_mcs[sf].sinr * 10)); int i; @@ -2003,9 +2023,9 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) { sinr_index = i; lin_interp = true; - break; + break; } - + } if (i >= (bler_data[mcs].length - 1)) { @@ -2028,10 +2048,7 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) if (bler_val <= drop_cutoff) { - return 1; - } - else - { - return 0; + sf_rnti_mcs[sf].drop_flag[n] = 1; } + return; } diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.h b/openair2/PHY_INTERFACE/phy_stub_UE.h index b6f3da8fd5..f2fc8ef68e 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.h +++ b/openair2/PHY_INTERFACE/phy_stub_UE.h @@ -52,6 +52,7 @@ typedef struct uint8_t mcs[256]; float sinr; uint16_t pdu_size; + int drop_flag[256]; } sf_rnti_mcs_s; @@ -200,7 +201,8 @@ const char *dl_pdu_type_to_string(uint8_t pdu_type); const char *ul_pdu_type_to_string(uint8_t pdu_type); void read_channel_param(nfapi_dl_config_request_t * dl_config, int sf); -int drop_tb(int sf, uint16_t rnti); +void drop_tb(int sf, uint16_t rnti); +int check_drop_tb(int sf, uint16_t rnti); extern queue_t dl_config_req_tx_req_queue; extern queue_t ul_config_req_queue; diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c index 929da68d87..2d2b06c645 100644 --- a/targets/RT/USER/lte-softmodem.c +++ b/targets/RT/USER/lte-softmodem.c @@ -756,6 +756,7 @@ int main ( int argc, char **argv ) LOG_I(ENB_APP,"oai_exit=%d\n",oai_exit); // stop threads + #if 0 //Disable clean up because this tends to crash (and unnecessary) if (RC.nb_inst == 0 || !NODE_IS_CU(node_type)) { if(IS_SOFTMODEM_DOFORMS) end_forms(); @@ -797,6 +798,7 @@ int main ( int argc, char **argv ) } } } + #endif terminate_opt(); logClean(); From 48662ed52060c2bc9c3cf509fa7ae2862ebc9669 Mon Sep 17 00:00:00 2001 From: Melissa Elkadi Date: Fri, 15 Jan 2021 15:39:09 -0800 Subject: [PATCH 05/26] Fixed uci_harq_ind issue by adding drop_tb call Also updated the spelling of global variable NUM_NFAPI_SUBFRAME --- openair2/PHY_INTERFACE/IF_Module.c | 8 ++++---- openair2/PHY_INTERFACE/IF_Module.h | 14 +++++++------- openair2/PHY_INTERFACE/phy_stub_UE.c | 24 ++++++++++++------------ openair2/PHY_INTERFACE/phy_stub_UE.h | 6 +++--- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/openair2/PHY_INTERFACE/IF_Module.c b/openair2/PHY_INTERFACE/IF_Module.c index 1800708c0c..b18f4eca37 100644 --- a/openair2/PHY_INTERFACE/IF_Module.c +++ b/openair2/PHY_INTERFACE/IF_Module.c @@ -98,7 +98,7 @@ void handle_sr(UL_IND_t *UL_info) { oai_nfapi_sr_indication(&UL_info->sr_ind); } } else if(NFAPI_MODE == NFAPI_MODE_VNF) { - for(uint8_t j = 0; j < NUM_NFPAI_SUBFRAME; j++) { + for(uint8_t j = 0; j < NUM_NFAPI_SUBFRAME; j++) { if(UL_RCC_INFO.sr_ind[j].sr_indication_body.number_of_srs > 0) { for (i=0; imodule_id, @@ -139,7 +139,7 @@ void handle_cqi(UL_IND_t *UL_info) { UL_info->cqi_ind.cqi_indication_body.number_of_cqis=0; } } else if (NFAPI_MODE == NFAPI_MODE_VNF) { - for(uint8_t j = 0; j < NUM_NFPAI_SUBFRAME; j++) { + for(uint8_t j = 0; j < NUM_NFAPI_SUBFRAME; j++) { if(UL_RCC_INFO.cqi_ind[j].cqi_indication_body.number_of_cqis > 0) { for (i=0; imodule_id, @@ -184,7 +184,7 @@ void handle_harq(UL_IND_t *UL_info) { UL_info->harq_ind.harq_indication_body.number_of_harqs = 0; } else if(NFAPI_MODE == NFAPI_MODE_VNF) { - for(uint8_t j = 0; j < NUM_NFPAI_SUBFRAME; j++) { + for(uint8_t j = 0; j < NUM_NFAPI_SUBFRAME; j++) { if(UL_RCC_INFO.harq_ind[j].harq_indication_body.number_of_harqs > 0) { for (int i=0; imodule_id, @@ -227,7 +227,7 @@ void handle_ulsch(UL_IND_t *UL_info) { UL_info->rx_ind.rx_indication_body.number_of_pdus = 0; } } else if(NFAPI_MODE == NFAPI_MODE_VNF) { - for(uint8_t k = 0; k < NUM_NFPAI_SUBFRAME; k++) { + for(uint8_t k = 0; k < NUM_NFAPI_SUBFRAME; k++) { if((UL_RCC_INFO.rx_ind[k].rx_indication_body.number_of_pdus>0) && (UL_RCC_INFO.crc_ind[k].crc_indication_body.number_of_crcs>0)) { for (i=0; ipdu_size, dlsch->dlsch_pdu.dlsch_pdu_rel8.pdu_index, tx_req_pdu_list->num_pdus); - if (!check_drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) + if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) { ue_send_sdu(ue_id, 0, sfn, sf, tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, @@ -817,7 +817,7 @@ void dl_config_req_UE_MAC_dci(int sfn, for (int ue_id = 0; ue_id < num_ue; ue_id++) { if (UE_mac_inst[ue_id].UE_mode[0] == NOT_SYNCHED) continue; - if (!check_drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) + if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) { ue_decode_si(ue_id, 0, sfn, 0, tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, @@ -833,7 +833,7 @@ void dl_config_req_UE_MAC_dci(int sfn, LOG_I(MAC, "%s() Received paging message: sfn/sf:%d.%d\n", __func__, sfn, sf); - if (!check_drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) + if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) { ue_decode_p(ue_id, 0, sfn, 0, tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, @@ -863,7 +863,7 @@ void dl_config_req_UE_MAC_dci(int sfn, "%s(): Received RAR, PreambleIndex: %d\n", __func__, UE_mac_inst[ue_id].RA_prach_resources.ra_PreambleIndex); - if (!check_drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) + if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) { ue_process_rar(ue_id, 0, sfn, ra_rnti, //RA-RNTI @@ -1940,7 +1940,7 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) } } - int check_drop_tb(int sf, uint16_t rnti) + bool check_drop_tb(int sf, uint16_t rnti) { if (sf_rnti_mcs[sf].pdu_size <= 0) { @@ -1956,10 +1956,10 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) } } LOG_I(MAC, "No matching rnti in sf_rnti_mcs.\n"); - return 0; + return false; } - void drop_tb(int sf, uint16_t rnti) + bool drop_tb(int sf, uint16_t rnti) { assert(sf < 10 && sf >= 0); @@ -1975,7 +1975,7 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) if (sf_rnti_mcs[sf].rnti[n] == rnti) { mcs = sf_rnti_mcs[sf].mcs[n]; - sf_rnti_mcs[sf].drop_flag[n] = 0; + sf_rnti_mcs[sf].drop_flag[n] = false; break; } } @@ -2048,7 +2048,7 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) if (bler_val <= drop_cutoff) { - sf_rnti_mcs[sf].drop_flag[n] = 1; + sf_rnti_mcs[sf].drop_flag[n] = true; } - return; + return sf_rnti_mcs[sf].drop_flag[n]; } diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.h b/openair2/PHY_INTERFACE/phy_stub_UE.h index f2fc8ef68e..5ee23e0049 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.h +++ b/openair2/PHY_INTERFACE/phy_stub_UE.h @@ -52,7 +52,7 @@ typedef struct uint8_t mcs[256]; float sinr; uint16_t pdu_size; - int drop_flag[256]; + bool drop_flag[256]; } sf_rnti_mcs_s; @@ -201,8 +201,8 @@ const char *dl_pdu_type_to_string(uint8_t pdu_type); const char *ul_pdu_type_to_string(uint8_t pdu_type); void read_channel_param(nfapi_dl_config_request_t * dl_config, int sf); -void drop_tb(int sf, uint16_t rnti); -int check_drop_tb(int sf, uint16_t rnti); +bool drop_tb(int sf, uint16_t rnti); +bool check_drop_tb(int sf, uint16_t rnti); extern queue_t dl_config_req_tx_req_queue; extern queue_t ul_config_req_queue; From 5fef8782931d6c6fa565c8a04446ce39a24a79ba Mon Sep 17 00:00:00 2001 From: Michael Cook Date: Sun, 17 Jan 2021 12:32:27 -0500 Subject: [PATCH 06/26] gdb.txt: Running Vscode remotely --- cmake_targets/gdb.txt | 72 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/cmake_targets/gdb.txt b/cmake_targets/gdb.txt index 54e47c27e9..65b67df13d 100644 --- a/cmake_targets/gdb.txt +++ b/cmake_targets/gdb.txt @@ -81,3 +81,75 @@ See launch.json for details about how vscode launches lte-softmodem for debuggin For example, in lte-softmodem.c, scroll to main() and click the line number to the left of main to add a breakpoint. then do Run => Start debugging (F5) to run lte-softmodem in the debugger + +------------------------------------------------------------------------------- +Running Vscode remotely. + +Currently, running Vscode remotely (via an X-Windows connection) does not work +-- the Vscode window appears but remains blank. Presumably the Vscode +developers will fix this problem eventually. Meanwhile, you can use `sshfs` +to make the remote filesystem appear locally and then run Vscode locally. + +On the local machine: + + $ remote=surfer # or whatever the remote machine's name is + $ mkdir ~/openairinterface5g + $ sshfs $remote:openairinterface5g ~/openairinterface5g + $ ls ~/openairinterface5g + CHANGELOG.md CONTRIBUTING.md nfapi openair3 targets + ... + $ code ~/openairinterface5g + $ + +The remote and local pathnames of your openairinterface5g workspace should be +the same. If they're different, use a symlink on the local machine to make +the remote pathnames work locally. This part is important because executables +built on $remote contain references to the source files and vscode & gdb will +use those pathnames to find the source files. + +You may want to locally mount the remote logs directory, too: + + $ mkdir ~/logs + $ sshfs $remote:logs ~/logs + $ ls -l ~/logs + total 40 + lrwxrwxrwx 1 1002 1002 22 Jan 17 11:54 latest -> logs-2021-01-17-085419 + drwxr-xr-x 1 1002 1002 4096 Jan 17 11:54 logs-2021-01-17-085419 + $ + +That will give you access to core files collected by lte_testscript.py, for +example. + + $ file ~/logs/latest/0001/coredump-6699 + /home/michael/logs/latest/0001/coredump-6699: ELF 64-bit LSB core file, + x86-64, version 1 (SYSV), SVR4-style, from './ran_build/build/lte-softmodem + -O ../ci-scripts/conf_files/rcc.band7.tm1.nfapi', real uid: 0, effective + uid: 0, real gid: 0, effective gid: 0, execfn: + './ran_build/build/lte-softmodem', platform: 'x86_64' + $ + $ file ~/openairinterface5g/cmake_targets/ran_build/build/lte-softmodem + /home/michael/openairinterface5g/cmake_targets/ran_build/build/lte-softmodem: + ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, + interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, + BuildID[sha1]=831400d4aae5d43b94ef3b22ebbd635107de48ae, with debug_info, not + stripped + $ + +Verify gdb can access these remote files: + + $ gdb ~/openairinterface5g/cmake_targets/ran_build/build/lte-softmodem \ + ~/logs/latest/0001/coredump-6699 + ... + Program terminated with signal SIGABRT, Aborted. + #0 0x00007f7fd7d11438 in ?? () + [Current thread is 1 (LWP 39)] + (gdb) + +If this step is too slow, you may want to copy the executable and coredump +files to the local machine first. + + $ scp -C $remote:openairinterface5g/cmake_targets/ran_build/build/lte-softmodem . + $ scp -C $remote:logs/latest/0001/coredump-6699 . + $ gdb lte-softmodem coredump-6699 + +------------------------------------------------------------------------------- From a1ec989d4785fb4b91f301072599a04dc31ce1d3 Mon Sep 17 00:00:00 2001 From: Melissa Elkadi Date: Mon, 18 Jan 2021 11:03:42 -0800 Subject: [PATCH 07/26] Added array index checks and local loop variable --- openair2/PHY_INTERFACE/phy_stub_UE.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c index 678a2bda42..b01f7bbab5 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.c +++ b/openair2/PHY_INTERFACE/phy_stub_UE.c @@ -1948,8 +1948,10 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) abort(); } - for (int n = 0; n < sf_rnti_mcs[sf].pdu_size; n++) + int pdu_size = sf_rnti_mcs[sf].pdu_size; + for (int n = 0; n < pdu_size; n++) { + assert(n < sizeof(sf_rnti_mcs[sf].drop_flag)); if (sf_rnti_mcs[sf].rnti[n] == rnti) { return sf_rnti_mcs[sf].drop_flag[n]; @@ -1970,8 +1972,10 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) uint8_t mcs = 99; int n = 0; - for (n = 0; n < sf_rnti_mcs[sf].pdu_size; n++) + int pdu_size = sf_rnti_mcs[sf].pdu_size; + for (n = 0; n < pdu_size; n++) { + assert(n < sizeof(sf_rnti_mcs[sf].drop_flag) && n < sizeof(sf_rnti_mcs[sf].mcs) && n < sizeof(sf_rnti_mcs[sf].rnti)); if (sf_rnti_mcs[sf].rnti[n] == rnti) { mcs = sf_rnti_mcs[sf].mcs[n]; @@ -2045,10 +2049,12 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) double drop_cutoff = ((double) rand() / (RAND_MAX)); assert(drop_cutoff < 1); + bler_val = 0.6; - if (bler_val <= drop_cutoff) + if (bler_val >= drop_cutoff) { sf_rnti_mcs[sf].drop_flag[n] = true; + LOG_D(MAC, "We are dropping this packet. Bler_val = %f, MCS = %"PRIu8", sf = %d\n", bler_val, sf_rnti_mcs[sf].mcs[n], sf); } return sf_rnti_mcs[sf].drop_flag[n]; } From d0e380da1eae5aedcef002253e917665ba2941a6 Mon Sep 17 00:00:00 2001 From: Melissa Elkadi Date: Mon, 18 Jan 2021 11:39:03 -0800 Subject: [PATCH 08/26] Updated array index check with macro def in log.h --- common/utils/LOG/log.h | 6 ++++++ openair2/PHY_INTERFACE/phy_stub_UE.c | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h index b5c7e1b1ab..27d1fee56d 100644 --- a/common/utils/LOG/log.h +++ b/common/utils/LOG/log.h @@ -54,6 +54,12 @@ #include "T.h" #include /*----------------------------------------------------------------------------*/ +#include +#ifdef NDEBUG +#warning assert is disabled +#endif +#define NUM_ELEMENTS(ARRAY) (sizeof(ARRAY) / sizeof(ARRAY[0])) +#define CHECK_INDEX(ARRAY, INDEX) assert((INDEX) < NUM_ELEMENTS(ARRAY)) #ifdef __cplusplus extern "C" { diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c index b01f7bbab5..39242c36b9 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.c +++ b/openair2/PHY_INTERFACE/phy_stub_UE.c @@ -1949,9 +1949,10 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) } int pdu_size = sf_rnti_mcs[sf].pdu_size; + CHECK_INDEX(sf_rnti_mcs[sf].rnti, pdu_size); + CHECK_INDEX(sf_rnti_mcs[sf].drop_flag, pdu_size); for (int n = 0; n < pdu_size; n++) { - assert(n < sizeof(sf_rnti_mcs[sf].drop_flag)); if (sf_rnti_mcs[sf].rnti[n] == rnti) { return sf_rnti_mcs[sf].drop_flag[n]; @@ -1973,9 +1974,11 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) uint8_t mcs = 99; int n = 0; int pdu_size = sf_rnti_mcs[sf].pdu_size; + CHECK_INDEX(sf_rnti_mcs[sf].rnti, pdu_size); + CHECK_INDEX(sf_rnti_mcs[sf].mcs, pdu_size); + CHECK_INDEX(sf_rnti_mcs[sf].drop_flag, pdu_size); for (n = 0; n < pdu_size; n++) { - assert(n < sizeof(sf_rnti_mcs[sf].drop_flag) && n < sizeof(sf_rnti_mcs[sf].mcs) && n < sizeof(sf_rnti_mcs[sf].rnti)); if (sf_rnti_mcs[sf].rnti[n] == rnti) { mcs = sf_rnti_mcs[sf].mcs[n]; @@ -2049,7 +2052,7 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) double drop_cutoff = ((double) rand() / (RAND_MAX)); assert(drop_cutoff < 1); - bler_val = 0.6; + bler_val = 0.4; if (bler_val >= drop_cutoff) { From 4a763d14cdf031e905e32c19e29ae76c92cbefe9 Mon Sep 17 00:00:00 2001 From: Melissa Elkadi Date: Mon, 18 Jan 2021 11:53:04 -0800 Subject: [PATCH 09/26] Utilizing local pdu_size variable --- openair2/PHY_INTERFACE/phy_stub_UE.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c index 39242c36b9..f12e205085 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.c +++ b/openair2/PHY_INTERFACE/phy_stub_UE.c @@ -1942,7 +1942,8 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) bool check_drop_tb(int sf, uint16_t rnti) { - if (sf_rnti_mcs[sf].pdu_size <= 0) + int pdu_size = sf_rnti_mcs[sf].pdu_size; + if (pdu_size <= 0) { LOG_E(MAC, "%s: sf_rnti_mcs[%d].pdu_size = 0\n", __FUNCTION__, sf); abort(); @@ -1964,16 +1965,16 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) bool drop_tb(int sf, uint16_t rnti) { + int pdu_size = sf_rnti_mcs[sf].pdu_size; assert(sf < 10 && sf >= 0); - if (sf_rnti_mcs[sf].pdu_size <= 0) + if (pdu_size <= 0) { LOG_E(MAC, "%s: sf_rnti_mcs[%d].pdu_size = 0\n", __FUNCTION__, sf); } uint8_t mcs = 99; int n = 0; - int pdu_size = sf_rnti_mcs[sf].pdu_size; CHECK_INDEX(sf_rnti_mcs[sf].rnti, pdu_size); CHECK_INDEX(sf_rnti_mcs[sf].mcs, pdu_size); CHECK_INDEX(sf_rnti_mcs[sf].drop_flag, pdu_size); From 80fc9b390846552d3389f7bd4a15b442ed3aa035 Mon Sep 17 00:00:00 2001 From: Melissa Elkadi Date: Mon, 18 Jan 2021 13:06:57 -0800 Subject: [PATCH 10/26] Removed duplicate def of pdu_size --- openair2/PHY_INTERFACE/phy_stub_UE.c | 1 - 1 file changed, 1 deletion(-) diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c index f12e205085..21cd68daf5 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.c +++ b/openair2/PHY_INTERFACE/phy_stub_UE.c @@ -1949,7 +1949,6 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) abort(); } - int pdu_size = sf_rnti_mcs[sf].pdu_size; CHECK_INDEX(sf_rnti_mcs[sf].rnti, pdu_size); CHECK_INDEX(sf_rnti_mcs[sf].drop_flag, pdu_size); for (int n = 0; n < pdu_size; n++) From 0f210073c503fe44585d2920c02618cc9ff39d67 Mon Sep 17 00:00:00 2001 From: Melissa Date: Fri, 22 Jan 2021 16:37:41 -0800 Subject: [PATCH 11/26] Fixed two bugs There was a variable that was being used that was undefined. Also fixed save_dci_pdu_for_crnti() function. --- openair2/PHY_INTERFACE/phy_stub_UE.c | 372 ++++++++++++++++----------- openair2/PHY_INTERFACE/phy_stub_UE.h | 5 +- 2 files changed, 219 insertions(+), 158 deletions(-) diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c index 21cd68daf5..8d7f078bd9 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.c +++ b/openair2/PHY_INTERFACE/phy_stub_UE.c @@ -33,6 +33,7 @@ #include #include #include +#include extern int oai_nfapi_rach_ind(nfapi_rach_indication_t *rach_ind); void configure_nfapi_pnf(char *vnf_ip_addr, @@ -54,6 +55,13 @@ static sf_rnti_mcs_s sf_rnti_mcs[NUM_NFAPI_SUBFRAME]; static int ue_tx_sock_descriptor = -1; static int ue_rx_sock_descriptor = -1; +static int get_mcs_from_sinr(float sinr); +static int get_cqi_from_mcs(void); +static void read_channel_param(const nfapi_dl_config_request_pdu_t * pdu, int sf, int index); +static bool did_drop_transport_block(int sf, uint16_t rnti); +static float get_bler_val(uint8_t mcs, int sinr); +static bool should_drop_transport_block(int sf, uint16_t rnti); +static void save_dci_pdu_for_crnti(nfapi_dl_config_request_t *dl_config_req); extern nfapi_tx_request_pdu_t* tx_request_pdu[1023][NUM_NFAPI_SUBFRAME][10]; //TODO: NFAPI_TX_MAX_PDU for last dim? Check nfapi_pnf.c ln. 81 //extern int timer_subframe; @@ -295,7 +303,7 @@ void fill_ulsch_cqi_indication_UE_MAC(int Mod_id, pdu->ul_cqi_information.channel = 1; // eNB_scheduler_primitives.c:4839: the upper four bits seem to be the CQI - const int cqi = 15; // Need to map EMANE SINR to CQI! + const int cqi = get_cqi_from_mcs(); raw_pdu->pdu[0] = cqi << 4; UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis++; @@ -403,7 +411,7 @@ void fill_uci_harq_indication_UE_MAC(int Mod_id, // 2.) if receiving ul_config_req for uci ack/nack or ulsch ack/nak in subframe n // go look to see if dl_config_req (with c-rnti) was received in subframe (n - 4) // 3.) if the answer to #2 is yes then send ACK IF NOT send DTX - if (check_drop_tb(((subframe+6) % 10), rnti)) // TODO: Handle DTX. Also discuss handling PDCCH + if (did_drop_transport_block(((subframe+6) % 10), rnti)) // TODO: Handle DTX. Also discuss handling PDCCH { pdu->harq_indication_fdd_rel13.harq_tb_n[0] = 2; LOG_I(PHY, "Setting HARQ No ACK - Channel Model\n"); @@ -798,7 +806,7 @@ void dl_config_req_UE_MAC_dci(int sfn, sfn, sf, dci->pdu_size, dlsch->dlsch_pdu.dlsch_pdu_rel8.pdu_index, tx_req_pdu_list->num_pdus); - if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) + if (!should_drop_transport_block(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) { ue_send_sdu(ue_id, 0, sfn, sf, tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, @@ -817,32 +825,18 @@ void dl_config_req_UE_MAC_dci(int sfn, for (int ue_id = 0; ue_id < num_ue; ue_id++) { if (UE_mac_inst[ue_id].UE_mode[0] == NOT_SYNCHED) continue; - if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) - { - ue_decode_si(ue_id, 0, sfn, 0, - tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, - tx_req_pdu_list->pdus[pdu_index].segments[0].segment_length); - } - else - { - LOG_I(MAC, "Transport Block discarded - ue_decode_si not called. sf: %d", sf); - } + ue_decode_si(ue_id, 0, sfn, 0, + tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, + tx_req_pdu_list->pdus[pdu_index].segments[0].segment_length); } } else if (rnti == 0xFFFE) { /* PI-RNTI */ for (int ue_id = 0; ue_id < num_ue; ue_id++) { LOG_I(MAC, "%s() Received paging message: sfn/sf:%d.%d\n", __func__, sfn, sf); - if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) - { - ue_decode_p(ue_id, 0, sfn, 0, - tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, - tx_req_pdu_list->pdus[pdu_index].segments[0].segment_length); - } - else - { - LOG_I(MAC, "Transport Block discarded - ue_decode_p not called. sf: %d", sf); - } + ue_decode_p(ue_id, 0, sfn, 0, + tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, + tx_req_pdu_list->pdus[pdu_index].segments[0].segment_length); } } else if (rnti == 0x0002) { /* RA-RNTI */ for (int ue_id = 0; ue_id < num_ue; ue_id++) { @@ -863,19 +857,12 @@ void dl_config_req_UE_MAC_dci(int sfn, "%s(): Received RAR, PreambleIndex: %d\n", __func__, UE_mac_inst[ue_id].RA_prach_resources.ra_PreambleIndex); - if (!drop_tb(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti)) - { - ue_process_rar(ue_id, 0, sfn, - ra_rnti, //RA-RNTI - tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, - &UE_mac_inst[ue_id].crnti, //t-crnti - UE_mac_inst[ue_id].RA_prach_resources.ra_PreambleIndex, - tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data); - } - else - { - LOG_I(MAC, "Transport Block discarded - RAR Not Processed. sf: %d, ra_rnti: %d", sf, ra_rnti); - } + ue_process_rar(ue_id, 0, sfn, + ra_rnti, //RA-RNTI + tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data, + &UE_mac_inst[ue_id].crnti, //t-crnti + UE_mac_inst[ue_id].RA_prach_resources.ra_PreambleIndex, + tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data); // UE_mac_inst[ue_id].UE_mode[0] = RA_RESPONSE; LOG_I(MAC, "setting UE_MODE now: %d\n", UE_mac_inst[ue_id].UE_mode[0]); // Expecting an UL_CONFIG_ULSCH_PDU to enable Msg3 Txon (first @@ -1334,6 +1321,7 @@ void *ue_standalone_pnf_task(void *context) abort(); } sf_rnti_mcs[sf].sinr = ch_info->sinr; + LOG_A(MAC, "Received_SINR = %f\n",ch_info->sinr); } else { @@ -1363,7 +1351,9 @@ void *ue_standalone_pnf_task(void *context) dl_config_req.sfn_sf & 15); dl_config_req_valid = true; - read_channel_param(&dl_config_req, (dl_config_req.sfn_sf & 15)); + + save_dci_pdu_for_crnti(&dl_config_req); + if (tx_req_valid) { if (dl_config_req.sfn_sf != tx_req.sfn_sf) @@ -1456,6 +1446,30 @@ void *ue_standalone_pnf_task(void *context) } } +static void save_dci_pdu_for_crnti(nfapi_dl_config_request_t *dl_config_req) +{ + int count_sent = 0; + int number_of_dci = dl_config_req->dl_config_request_body.number_dci; + int number_of_pdu = dl_config_req->dl_config_request_body.number_pdu; + if (number_of_pdu <= 0) + { + LOG_E(MAC, "%s: dl_config_req pdu size <= 0\n", __FUNCTION__); + abort(); + } + if (number_of_dci > 0) + { + for (int n = 0; n < number_of_pdu; n++) + { + const nfapi_dl_config_request_pdu_t *current_pdu_list = &dl_config_req->dl_config_request_body.dl_config_pdu_list[n]; + int rnti_type = current_pdu_list->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type; + if (current_pdu_list->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE && rnti_type == 1 && count_sent < number_of_dci) + { + read_channel_param(current_pdu_list, (dl_config_req->sfn_sf & 15), count_sent); + count_sent++; + } + } + } +} void *memcpy_dl_config_req_standalone(nfapi_dl_config_request_t *dl_config_req) { @@ -1922,142 +1936,192 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req) { } - void read_channel_param(nfapi_dl_config_request_t * dl_config, int sf) +static int get_mcs_from_sinr(float sinr) +{ + if (sinr < (bler_data[0].bler_table[0][0])) { - if (dl_config == NULL) - { - LOG_E(MAC,"DL_CONFIG NULL\n"); - abort(); - } - - // Store all rnti and mcs for all pdus - LOG_I(MAC, "Adding MCS and RNTI for sf_rnti_mcs[%d]\n", sf); - sf_rnti_mcs[sf].pdu_size = dl_config->dl_config_request_body.number_pdu; - for (int n = 0; n < sf_rnti_mcs[sf].pdu_size; n++) - { - sf_rnti_mcs[sf].rnti[n] = dl_config->dl_config_request_body.dl_config_pdu_list[n].dci_dl_pdu.dci_dl_pdu_rel8.rnti; - sf_rnti_mcs[sf].mcs[n] = dl_config->dl_config_request_body.dl_config_pdu_list[n].dci_dl_pdu.dci_dl_pdu_rel8.mcs_1; - } + LOG_I(MAC, "The SINR was found is smaller than first MCS table\n"); + return 0; } - bool check_drop_tb(int sf, uint16_t rnti) + if (sinr > (bler_data[NUM_MCS-1].bler_table[bler_data[NUM_MCS-1].length - 1][0])) { - int pdu_size = sf_rnti_mcs[sf].pdu_size; - if (pdu_size <= 0) - { - LOG_E(MAC, "%s: sf_rnti_mcs[%d].pdu_size = 0\n", __FUNCTION__, sf); - abort(); - } - - CHECK_INDEX(sf_rnti_mcs[sf].rnti, pdu_size); - CHECK_INDEX(sf_rnti_mcs[sf].drop_flag, pdu_size); - for (int n = 0; n < pdu_size; n++) - { - if (sf_rnti_mcs[sf].rnti[n] == rnti) - { - return sf_rnti_mcs[sf].drop_flag[n]; - } - } - LOG_I(MAC, "No matching rnti in sf_rnti_mcs.\n"); - return false; + LOG_I(MAC, "The SINR was found is larger than last MCS table\n"); + return NUM_MCS-1; } - bool drop_tb(int sf, uint16_t rnti) + for (int n = NUM_MCS-1; n >= 0; n--) { - int pdu_size = sf_rnti_mcs[sf].pdu_size; - assert(sf < 10 && sf >= 0); - - if (pdu_size <= 0) + CHECK_INDEX(bler_data, n); + float largest_sinr = (bler_data[n].bler_table[bler_data[n].length - 1][0]); + float smallest_sinr = (bler_data[n].bler_table[0][0]); + if (sinr < largest_sinr && sinr > smallest_sinr) { - LOG_E(MAC, "%s: sf_rnti_mcs[%d].pdu_size = 0\n", __FUNCTION__, sf); + LOG_I(MAC, "The SINR was found in MCS %d table\n", n); + return n; } + } + LOG_E(MAC, "Unable to get an MCS value.\n"); + abort(); +} - uint8_t mcs = 99; - int n = 0; - CHECK_INDEX(sf_rnti_mcs[sf].rnti, pdu_size); - CHECK_INDEX(sf_rnti_mcs[sf].mcs, pdu_size); - CHECK_INDEX(sf_rnti_mcs[sf].drop_flag, pdu_size); - for (n = 0; n < pdu_size; n++) +static int get_cqi_from_mcs(void) +{ + static const int mcs_to_cqi[] = {0, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15}; + assert(NUM_ELEMENTS(mcs_to_cqi) == NUM_MCS); + int sf = 0; + while(sf < NUM_NFAPI_SUBFRAME) + { + if (sf_rnti_mcs[sf].latest) { - if (sf_rnti_mcs[sf].rnti[n] == rnti) + int pdu_size = sf_rnti_mcs[sf].pdu_size; + if (pdu_size <= 0) { - mcs = sf_rnti_mcs[sf].mcs[n]; - sf_rnti_mcs[sf].drop_flag[n] = false; - break; - } - } - - if (mcs == 99) - { - LOG_E(MAC, "NO MCS Found. %d = sf_rnti_mcs[%d].mcs[%d] \n", mcs, sf, n); - abort(); - } - - // Loop through bler table to find sinr_index - int sinr_index = 0; - bool lin_interp = false; - bool skip_search = false; - int temp_bler = 0; - int temp_sinr = ((int)(sf_rnti_mcs[sf].sinr * 10)); - int i; - float bler_val = 0.0; - - if (temp_sinr < (int)(bler_data[mcs].bler_table[0][0] * 10)) - { - skip_search = true; - bler_val = 0.0; - } - else if (temp_sinr > (int)(bler_data[mcs].bler_table[bler_data[mcs].length - 1][0] * 10)) - { - skip_search = true; - bler_val = 1.0; - } - - - for (i = 0; i < bler_data[mcs].length; i++) - { - if(skip_search) - break; - - temp_bler = (int)(bler_data[mcs].bler_table[i][0] * 10); - if (temp_bler == temp_sinr) - { - sinr_index = i; - break; - } - // Linear interpolation when SINR is between indices - else if (temp_bler > temp_sinr) - { - sinr_index = i; - lin_interp = true; - break; + LOG_E(MAC, "%s: sf_rnti_mcs[%d].pdu_size = 0\n", __FUNCTION__, sf); + abort(); } + CHECK_INDEX(sf_rnti_mcs[sf].mcs, pdu_size); + int mcs = get_mcs_from_sinr(sf_rnti_mcs[sf].sinr); + CHECK_INDEX(mcs_to_cqi, mcs); + int cqi = mcs_to_cqi[mcs]; + LOG_A(MAC, "SINR: %f -> MCS: %d -> CQI: %d\n", sf_rnti_mcs[sf].sinr, mcs, cqi); + return cqi; } - if (i >= (bler_data[mcs].length - 1)) - { - LOG_E(MAC, "NO SINR INDEX FOUND! - mcs: %d, temp_sinr: %d, temp_bler: %d, sinr_index: %d\n", mcs, temp_sinr, temp_bler, sinr_index); - abort(); - } + sf++; + } + LOG_E(MAC, "Unable to get CQI value because no MCS found\n"); + abort(); +} - if (lin_interp) +static void read_channel_param(const nfapi_dl_config_request_pdu_t * pdu, int sf, int index) +{ + if (pdu == NULL) + { + LOG_E(MAC,"PDU NULL\n"); + abort(); + } + + /* This function is executed for every dci pdu type in a dl_config_req. We save + the assocaited MCS and RNTI value for each. The 'index' passed in is a count of + how many times we have called this function for a particular dl_config_req. It + allows us to save MCS/RNTI data in correct indicies when multiple dci's are received.*/ + for (int i = 0; i < NUM_NFAPI_SUBFRAME; i++) + { + if (i == sf) { - bler_val = ((bler_data[mcs].bler_table[sinr_index - 1][3] + bler_data[mcs].bler_table[sinr_index][3]) / 2); + CHECK_INDEX(sf_rnti_mcs[sf].rnti, index); + CHECK_INDEX(sf_rnti_mcs[sf].mcs, index); + CHECK_INDEX(sf_rnti_mcs[sf].drop_flag, index); + sf_rnti_mcs[sf].rnti[index] = pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti; + sf_rnti_mcs[sf].mcs[index] = pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1; + sf_rnti_mcs[sf].drop_flag[index] = false; + sf_rnti_mcs[sf].pdu_size = index+1; //index starts at 0 so we incrament to get num of pdus + sf_rnti_mcs[sf].latest = true; + LOG_I(MAC, "Adding MCS %d and RNTI %x for sf_rnti_mcs[%d]\n", sf_rnti_mcs[sf].mcs[index], sf_rnti_mcs[sf].rnti[index], sf); } else { - if (skip_search == false) - bler_val = bler_data[mcs].bler_table[sinr_index][3]; // 3 is the rate, or bler rate column + sf_rnti_mcs[i].latest = false; } - - double drop_cutoff = ((double) rand() / (RAND_MAX)); - assert(drop_cutoff < 1); - bler_val = 0.4; - - if (bler_val >= drop_cutoff) - { - sf_rnti_mcs[sf].drop_flag[n] = true; - LOG_D(MAC, "We are dropping this packet. Bler_val = %f, MCS = %"PRIu8", sf = %d\n", bler_val, sf_rnti_mcs[sf].mcs[n], sf); - } - return sf_rnti_mcs[sf].drop_flag[n]; } + return; +} + +static bool did_drop_transport_block(int sf, uint16_t rnti) +{ + int pdu_size = sf_rnti_mcs[sf].pdu_size; + if(pdu_size <= 0) + { + LOG_E(MAC, "Problem, the PDU size is <= 0. We dropped this packet\n"); + return true; + } + CHECK_INDEX(sf_rnti_mcs[sf].rnti, pdu_size); + CHECK_INDEX(sf_rnti_mcs[sf].drop_flag, pdu_size); + for (int n = 0; n < pdu_size; n++) + { + if (sf_rnti_mcs[sf].rnti[n] == rnti && sf_rnti_mcs[sf].drop_flag[n]) + { + return true; + } + } + return false; +} + +static float get_bler_val(uint8_t mcs, int sinr) +{ + if (sinr < (int)(bler_data[mcs].bler_table[0][0] * 10)) + { + LOG_I(MAC, "MCS %d table. SINR is smaller than lowest SINR, bler_val is set based on lowest SINR in table\n", mcs); + return bler_data[mcs].bler_table[0][3]; + } + if (sinr > (int)(bler_data[mcs].bler_table[bler_data[mcs].length - 1][0] * 10)) + { + LOG_I(MAC, "MCS %d table. SINR is greater than largest SINR. bler_val is set based on largest SINR in table\n", mcs); + return bler_data[mcs].bler_table[(bler_data[mcs].length - 1)][3]; + } + // Loop through bler table to find sinr_index + for (int i = 0; i < bler_data[mcs].length; i++) + { + int temp_sinr = (int)(bler_data[mcs].bler_table[i][0] * 10); + if (temp_sinr == sinr) + { + return bler_data[mcs].bler_table[i][3]; // 3rd column containers bler value + } + // Linear interpolation when SINR is between indices + if (temp_sinr > sinr) + { + return ((bler_data[mcs].bler_table[i - 1][3] + bler_data[mcs].bler_table[i][3]) / 2); + } + } + LOG_E(MAC, "NO SINR INDEX FOUND!\n"); + abort(); + +} + +static bool should_drop_transport_block(int sf, uint16_t rnti) +{ + /* Get block error rate (bler_val) from table based on every saved + MCS and SINR to be used as the cutoff rate for dropping packets. + Generate random uniform vairable to compare against bler_val. */ + int pdu_size = sf_rnti_mcs[sf].pdu_size; + assert(sf < 10 && sf >= 0); + assert(pdu_size > 0); + CHECK_INDEX(sf_rnti_mcs[sf].rnti, pdu_size); + CHECK_INDEX(sf_rnti_mcs[sf].mcs, pdu_size); + CHECK_INDEX(sf_rnti_mcs[sf].drop_flag, pdu_size); + int n = 0; + uint8_t mcs = 99; + for (n = 0; n < pdu_size; n++) + { + if (sf_rnti_mcs[sf].rnti[n] == rnti) + { + mcs = sf_rnti_mcs[sf].mcs[n]; + } + if (mcs != 99) + { + /* Use MCS to get the bler value. Since there can be multiple MCS + values for a particular subframe, we verify that all PDUs are not + flagged for drop before returning. If even one is flagged for drop + we return immediately because we drop the entire packet. */ + float bler_val = get_bler_val(mcs, ((int)(sf_rnti_mcs[sf].sinr * 10))); + double drop_cutoff = ((double) rand() / (RAND_MAX)); + assert(drop_cutoff <= 1); + + if (drop_cutoff <= bler_val) + { + sf_rnti_mcs[sf].drop_flag[n] = true; + LOG_D(MAC, "We are dropping this packet. Bler_val = %f, MCS = %"PRIu8", sf = %d\n", bler_val, sf_rnti_mcs[sf].mcs[n], sf); + return sf_rnti_mcs[sf].drop_flag[n]; + } + } + + } + + if (mcs == 99) + { + LOG_E(MAC, "NO MCS Found for rnti %x. sf_rnti_mcs[%d].mcs[%d] \n", rnti, sf, n); + abort(); + } + return false; +} diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.h b/openair2/PHY_INTERFACE/phy_stub_UE.h index 5ee23e0049..22c35f9423 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.h +++ b/openair2/PHY_INTERFACE/phy_stub_UE.h @@ -53,6 +53,7 @@ typedef struct float sinr; uint16_t pdu_size; bool drop_flag[256]; + bool latest; } sf_rnti_mcs_s; @@ -200,10 +201,6 @@ char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req); const char *dl_pdu_type_to_string(uint8_t pdu_type); const char *ul_pdu_type_to_string(uint8_t pdu_type); -void read_channel_param(nfapi_dl_config_request_t * dl_config, int sf); -bool drop_tb(int sf, uint16_t rnti); -bool check_drop_tb(int sf, uint16_t rnti); - extern queue_t dl_config_req_tx_req_queue; extern queue_t ul_config_req_queue; extern queue_t hi_dci0_req_queue; From 563064ce0b1142c5a0e1b22c4e4873c79812f083 Mon Sep 17 00:00:00 2001 From: Michael Cook Date: Sun, 24 Jan 2021 12:26:30 -0500 Subject: [PATCH 12/26] gdb.txt: Notes on loading coredump files into Vscode --- cmake_targets/gdb.txt | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/cmake_targets/gdb.txt b/cmake_targets/gdb.txt index 65b67df13d..b0997d4eb6 100644 --- a/cmake_targets/gdb.txt +++ b/cmake_targets/gdb.txt @@ -152,4 +152,40 @@ files to the local machine first. $ scp -C $remote:logs/latest/0001/coredump-6699 . $ gdb lte-softmodem coredump-6699 +To load the coredump into Vscode, modify launch.json to add "coreDumpPath". +You may also need to modify the "program" path and delete "miDebuggerPath". + +--- .vscode/launch.json ++++ .vscode/launch.json +@@ -9,7 +9,7 @@ + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", +- "program": "${workspaceFolder}/cmake_targets/ran_build/build/lte-so ++ "program": "/home/michael/tmp/lte-softmodem", + "args": [ + "-O", "../ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf", + "--noS1" +@@ -19,14 +19,14 @@ + "environment": [], + "externalConsole": false, + "MIMode": "gdb", +- "miDebuggerPath": "${workspaceFolder}/cmake_targets/sudo-gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } +- ] ++ ], ++ "coreDumpPath": "/home/michael/tmp/coredump-6699" + } + ] + } + +Then, in Vscode click the debug icon on the left navigation bar, then click +the green "play" triangle near the upper left corner of the window. See the +"CALL STACK" near the lower left of the window. + ------------------------------------------------------------------------------- From 02571e63bb963e8a9b9fb9037bf211750544fa56 Mon Sep 17 00:00:00 2001 From: Michael Cook Date: Sun, 24 Jan 2021 12:38:15 -0500 Subject: [PATCH 13/26] gdb.txt: Linux versions should be the same --- cmake_targets/gdb.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake_targets/gdb.txt b/cmake_targets/gdb.txt index b0997d4eb6..8c59d9a06d 100644 --- a/cmake_targets/gdb.txt +++ b/cmake_targets/gdb.txt @@ -152,6 +152,10 @@ files to the local machine first. $ scp -C $remote:logs/latest/0001/coredump-6699 . $ gdb lte-softmodem coredump-6699 +Note, the local and remote machines should be the same version of Linux (e.g., +both Ubuntu 16.04). Otherwise, gdb will likely have trouble understanding the +coredump. + To load the coredump into Vscode, modify launch.json to add "coreDumpPath". You may also need to modify the "program" path and delete "miDebuggerPath". From 78341d9db1cfa465811ae32527169408426762a8 Mon Sep 17 00:00:00 2001 From: Melissa Elkadi Date: Mon, 25 Jan 2021 14:52:44 -0800 Subject: [PATCH 14/26] Updated bler table lookup mechanism and logs --- openair2/PHY_INTERFACE/phy_stub_UE.c | 20 ++++++++++++++------ targets/RT/USER/lte-ue.c | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c index 8d7f078bd9..db8519acc0 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.c +++ b/openair2/PHY_INTERFACE/phy_stub_UE.c @@ -1321,7 +1321,7 @@ void *ue_standalone_pnf_task(void *context) abort(); } sf_rnti_mcs[sf].sinr = ch_info->sinr; - LOG_A(MAC, "Received_SINR = %f\n",ch_info->sinr); + LOG_D(MAC, "Received_SINR = %f\n",ch_info->sinr); } else { @@ -2050,15 +2050,20 @@ static bool did_drop_transport_block(int sf, uint16_t rnti) static float get_bler_val(uint8_t mcs, int sinr) { + // 4th col = dropped packets, 5th col = total packets + float bler_val = 0.0; + CHECK_INDEX(bler_data, mcs); if (sinr < (int)(bler_data[mcs].bler_table[0][0] * 10)) { LOG_I(MAC, "MCS %d table. SINR is smaller than lowest SINR, bler_val is set based on lowest SINR in table\n", mcs); - return bler_data[mcs].bler_table[0][3]; + bler_val = bler_data[mcs].bler_table[0][4] / bler_data[mcs].bler_table[0][5]; + return bler_val; } if (sinr > (int)(bler_data[mcs].bler_table[bler_data[mcs].length - 1][0] * 10)) { LOG_I(MAC, "MCS %d table. SINR is greater than largest SINR. bler_val is set based on largest SINR in table\n", mcs); - return bler_data[mcs].bler_table[(bler_data[mcs].length - 1)][3]; + bler_val = bler_data[mcs].bler_table[(bler_data[mcs].length - 1)][4] / bler_data[mcs].bler_table[(bler_data[mcs].length - 1)][5]; + return bler_val; } // Loop through bler table to find sinr_index for (int i = 0; i < bler_data[mcs].length; i++) @@ -2066,12 +2071,15 @@ static float get_bler_val(uint8_t mcs, int sinr) int temp_sinr = (int)(bler_data[mcs].bler_table[i][0] * 10); if (temp_sinr == sinr) { - return bler_data[mcs].bler_table[i][3]; // 3rd column containers bler value + bler_val = bler_data[mcs].bler_table[i][4] / bler_data[mcs].bler_table[i][5]; + return bler_val; } // Linear interpolation when SINR is between indices if (temp_sinr > sinr) { - return ((bler_data[mcs].bler_table[i - 1][3] + bler_data[mcs].bler_table[i][3]) / 2); + float bler_val1 = bler_data[mcs].bler_table[i - 1][4] / bler_data[mcs].bler_table[i - 1][5]; + float bler_val2 = bler_data[mcs].bler_table[i][4] / bler_data[mcs].bler_table[i][5]; + return ((bler_val1 + bler_val2) / 2); } } LOG_E(MAC, "NO SINR INDEX FOUND!\n"); @@ -2107,7 +2115,7 @@ static bool should_drop_transport_block(int sf, uint16_t rnti) float bler_val = get_bler_val(mcs, ((int)(sf_rnti_mcs[sf].sinr * 10))); double drop_cutoff = ((double) rand() / (RAND_MAX)); assert(drop_cutoff <= 1); - + LOG_I(MAC, "SINR = %f, Bler_val = %f, MCS = %"PRIu8"\n", sf_rnti_mcs[sf].sinr, bler_val, sf_rnti_mcs[sf].mcs[n]); if (drop_cutoff <= bler_val) { sf_rnti_mcs[sf].drop_flag[n] = true; diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c index 5cd7c44ff5..b15c315c83 100644 --- a/targets/RT/USER/lte-ue.c +++ b/targets/RT/USER/lte-ue.c @@ -1112,7 +1112,7 @@ static void *UE_phy_stub_standalone_pnf_task(void *arg) nfapi_dl_config_request_t *dl_config_req = dl_config_req_tx_req->dl_config_req; uint16_t dl_num_pdus = dl_config_req->dl_config_request_body.number_pdu; - LOG_A(MAC, "(OAI UE) Received dl_config_req from proxy at Frame: %d, Subframe: %d," + LOG_I(MAC, "(OAI UE) Received dl_config_req from proxy at Frame: %d, Subframe: %d," " with number of PDUs: %u\n", NFAPI_SFNSF2SFN(dl_config_req->sfn_sf), NFAPI_SFNSF2SF(dl_config_req->sfn_sf), dl_num_pdus); From b68479aa10b21e0fc8c5d9cb683777c656df29ee Mon Sep 17 00:00:00 2001 From: Melissa Elkadi Date: Mon, 25 Jan 2021 14:55:46 -0800 Subject: [PATCH 15/26] Updating .gitignore file --- cmake_targets/.gitignore | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake_targets/.gitignore b/cmake_targets/.gitignore index d637630bca..32b4dccc26 100644 --- a/cmake_targets/.gitignore +++ b/cmake_targets/.gitignore @@ -1,5 +1,5 @@ -/.ue.nvram0 -/.ue_emm.nvram0 -/.usim.nvram0 +/.ue.nvram* +/.ue_emm.nvram* +/.usim.nvram* /nvram /usim From 9fa09f530f96d23a9e417993ff513af6ec9232db Mon Sep 17 00:00:00 2001 From: Melissa Date: Tue, 9 Feb 2021 14:09:39 -0800 Subject: [PATCH 16/26] Updated non-blocking PDCP socket More accurately, we changed the do/while infinite loop to be an infinite for loop for the read command of the socket. The socket file descriptor choice is more clear now. --- nfapi/open-nFAPI/common/src/debug.c | 4 +- nfapi/open-nFAPI/pnf/inc/pnf_p7.h | 2 +- nfapi/open-nFAPI/pnf/src/pnf_p7.c | 9 +++- nfapi/open-nFAPI/vnf/src/vnf_p7.c | 4 +- openair1/PHY/phy_vars.h | 2 +- openair1/PHY/phy_vars_nr_ue.h | 2 +- openair1/PHY/phy_vars_ue.h | 2 +- openair2/LAYER2/PDCP_v10.1.0/pdcp.h | 5 +- openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c | 62 +++++++++++++++++++----- openair2/PHY_INTERFACE/phy_stub_UE.c | 11 +++-- openair2/PHY_INTERFACE/phy_stub_UE.h | 1 + openair2/RRC/LTE/rrc_UE.c | 9 +++- openair2/UTIL/ASYNC_IF/socket_link.c | 6 ++- openair3/GTPV1-U/gtpv1u_eNB.c | 2 +- openair3/GTPV1-U/gtpv1u_eNB_defs.h | 1 + openair3/UDP/udp_eNB_task.c | 7 ++- openair3/UDP/udp_eNB_task.h | 1 + 17 files changed, 99 insertions(+), 31 deletions(-) diff --git a/nfapi/open-nFAPI/common/src/debug.c b/nfapi/open-nFAPI/common/src/debug.c index a45d41d7d7..d7f3b45e15 100644 --- a/nfapi/open-nFAPI/common/src/debug.c +++ b/nfapi/open-nFAPI/common/src/debug.c @@ -59,7 +59,8 @@ void nfapi_trace_dbg(nfapi_trace_level_t level, const char *format, ...) if (num_chars > TRACE_HEADER_LENGTH) { - printf("trace_dbg: Error, num_chars is too large: %d", num_chars); + printf("trace_dbg: Error, num_chars is too large: %d\n", num_chars); + fflush(stdout); return; } @@ -73,4 +74,5 @@ void nfapi_trace_dbg(nfapi_trace_level_t level, const char *format, ...) printf("%s", trace_buff); } va_end(p_args); + fflush(stdout); } diff --git a/nfapi/open-nFAPI/pnf/inc/pnf_p7.h b/nfapi/open-nFAPI/pnf/inc/pnf_p7.h index 3f08d85e6b..7ef38a25fc 100644 --- a/nfapi/open-nFAPI/pnf/inc/pnf_p7.h +++ b/nfapi/open-nFAPI/pnf/inc/pnf_p7.h @@ -25,7 +25,7 @@ #include "nfapi_pnf_interface.h" -#define NFAPI_MAX_PACKED_MESSAGE_SIZE 8192 +#define NFAPI_MAX_PACKED_MESSAGE_SIZE 4096 typedef struct { uint16_t dl_conf_ontime; diff --git a/nfapi/open-nFAPI/pnf/src/pnf_p7.c b/nfapi/open-nFAPI/pnf/src/pnf_p7.c index 5ba912e059..1aa1b6d891 100644 --- a/nfapi/open-nFAPI/pnf/src/pnf_p7.c +++ b/nfapi/open-nFAPI/pnf/src/pnf_p7.c @@ -1701,12 +1701,19 @@ void pnf_nfapi_p7_read_dispatch_message(pnf_p7_t* pnf_p7, uint32_t now_hr_time) } // read the segment - recvfrom_result = recvfrom(pnf_p7->p7_sock, pnf_p7->rx_message_buffer, header.message_length, MSG_DONTWAIT, (struct sockaddr*)&remote_addr, &remote_addr_size); + recvfrom_result = recvfrom(pnf_p7->p7_sock, pnf_p7->rx_message_buffer, pnf_p7->rx_message_buffer_size, + MSG_DONTWAIT | MSG_TRUNC, (struct sockaddr*)&remote_addr, &remote_addr_size); now_hr_time = pnf_get_current_time_hr(); //DJP - moved to here - get closer timestamp??? if(recvfrom_result > 0) { + if (recvfrom_result != header.message_length) + { + NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s(%d). Received unexpected number of bytes. %d != %d", + __FUNCTION__, __LINE__, recvfrom_result, header.message_length); + break; + } pnf_handle_p7_message(pnf_p7->rx_message_buffer, recvfrom_result, pnf_p7, now_hr_time); } } diff --git a/nfapi/open-nFAPI/vnf/src/vnf_p7.c b/nfapi/open-nFAPI/vnf/src/vnf_p7.c index d06e5bfe4e..79d5436efc 100644 --- a/nfapi/open-nFAPI/vnf/src/vnf_p7.c +++ b/nfapi/open-nFAPI/vnf/src/vnf_p7.c @@ -1537,9 +1537,9 @@ int vnf_p7_read_dispatch_message(vnf_p7_t* vnf_p7) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "recvfrom returned 0\n"); } - else if(recvfrom_result != header.message_length) + else if(recvfrom_result != -1 && recvfrom_result != header.message_length) { - NFAPI_TRACE(NFAPI_TRACE_NOTE, "did not receive the entire message %d %d\n", recvfrom_result, header.message_length); + NFAPI_TRACE(NFAPI_TRACE_ERROR, "Received unexpected number of bytes %d %d\n", recvfrom_result, header.message_length); recvfrom_result += recvfrom(vnf_p7->socket, &vnf_p7->rx_message_buffer[recvfrom_result], header.message_length - recvfrom_result, MSG_WAITALL, (struct sockaddr*)&remote_addr, &remote_addr_size); diff --git a/openair1/PHY/phy_vars.h b/openair1/PHY/phy_vars.h index a74d148479..f5a89fc4b9 100644 --- a/openair1/PHY/phy_vars.h +++ b/openair1/PHY/phy_vars.h @@ -91,7 +91,7 @@ const double sinr_to_cqi[4][16]= { {-2.5051, -2.5051, -1.7451, -0.3655, 1.0812, }; //int cqi_to_mcs[16]={0, 0, 1, 3, 5, 7, 9, 13, 15, 16, 20, 23, 25, 27, 27, 27}; -const int cqi_to_mcs[16]= {0, 0, 1, 2, 4, 6, 8, 11, 13, 16, 18, 20, 23, 25, 27, 28}; +const int cqi_to_mcs[16]= {0, 0, 1, 2, 4, 6, 8, 11, 13, 16, 18, 20, 23, 25, 27, 27}; //for SNR to MI conversion 7 th order Polynomial coeff const double q_qam16[8]= {3.21151853033897e-10,5.55435952230651e-09,-2.30760065362117e-07,-6.25587743817859e-06,4.62251036452795e-06,0.00224150813158937,0.0393723140344367,0.245486379182639}; diff --git a/openair1/PHY/phy_vars_nr_ue.h b/openair1/PHY/phy_vars_nr_ue.h index 1843d8d5bc..321fadbd7b 100644 --- a/openair1/PHY/phy_vars_nr_ue.h +++ b/openair1/PHY/phy_vars_nr_ue.h @@ -91,7 +91,7 @@ const double sinr_to_cqi[4][16]= { {-2.5051, -2.5051, -1.7451, -0.3655, 1.0812, }; //int cqi_to_mcs[16]={0, 0, 1, 3, 5, 7, 9, 13, 15, 16, 20, 23, 25, 27, 27, 27}; -const int cqi_to_mcs[16]= {0, 0, 1, 2, 4, 6, 8, 11, 13, 16, 18, 20, 23, 25, 27, 28}; +const int cqi_to_mcs[16]= {0, 0, 1, 2, 4, 6, 8, 11, 13, 16, 18, 20, 23, 25, 27, 27}; //for SNR to MI conversion 7 th order Polynomial coeff const double q_qam16[8]= {3.21151853033897e-10,5.55435952230651e-09,-2.30760065362117e-07,-6.25587743817859e-06,4.62251036452795e-06,0.00224150813158937,0.0393723140344367,0.245486379182639}; diff --git a/openair1/PHY/phy_vars_ue.h b/openair1/PHY/phy_vars_ue.h index e90c2641aa..8192d9be93 100644 --- a/openair1/PHY/phy_vars_ue.h +++ b/openair1/PHY/phy_vars_ue.h @@ -84,7 +84,7 @@ const double sinr_to_cqi[4][16]= { {-2.5051, -2.5051, -1.7451, -0.3655, 1.0812, }; //int cqi_to_mcs[16]={0, 0, 1, 3, 5, 7, 9, 13, 15, 16, 20, 23, 25, 27, 27, 27}; -const int cqi_to_mcs[16]= {0, 0, 1, 2, 4, 6, 8, 11, 13, 16, 18, 20, 23, 25, 27, 28}; +const int cqi_to_mcs[16]= {0, 0, 1, 2, 4, 6, 8, 11, 13, 16, 18, 20, 23, 25, 27, 27}; //for SNR to MI conversion 7 th order Polynomial coeff const double q_qam16[8]= {3.21151853033897e-10,5.55435952230651e-09,-2.30760065362117e-07,-6.25587743817859e-06,4.62251036452795e-06,0.00224150813158937,0.0393723140344367,0.245486379182639}; diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h index 7dc904c2f0..715b40c4c8 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h @@ -48,7 +48,7 @@ #include "LTE_SRB-ToAddModList.h" #include "LTE_MBMS-SessionInfoList-r9.h" #include "LTE_PMCH-InfoList-r9.h" - +#include "common/utils/ocp_itti/intertask_interface.h" typedef rlc_op_status_t (*send_rlc_data_req_func_t)(const protocol_ctxt_t *const, const srb_flag_t, const MBMS_flag_t, @@ -59,8 +59,9 @@ typedef boolean_t (*pdcp_data_ind_func_t)( const protocol_ctxt_t *, const srb_fl mem_block_t *,const uint32_t *const, const uint32_t *const); /* maximum number of tun interfaces that will be created to emulates UEs */ /* UEs beyond that will be multiplexed on the same tun */ -#define MAX_NUMBER_NETIF 16 +/* If running in nfapi_pnf_standlone mode, we only need one tunnel interface */ +#define MAX_NUMBER_NETIF 1 //16 #define ENB_NAS_USE_TUN_W_MBMS_BIT (1<< 10) #define PDCP_USE_NETLINK_BIT (1<< 11) #define LINK_ENB_PDCP_TO_IP_DRIVER_BIT (1<< 13) diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c index f386d93a8c..03d91456bd 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c @@ -235,21 +235,46 @@ int pdcp_fifo_read_input_sdus_fromtun (const protocol_ctxt_t *const ctxt_pP) { pdcp_t *pdcp_p = NULL; int len; rb_id_t rab_id = DEFAULT_RAB_ID; + int sockd; - do { + if (UE_NAS_USE_TUN) { + if (ue_id_g == 0) { + sockd = nas_sock_fd[ctxt_pP->module_id]; + } + else { + sockd = nas_sock_fd[ue_id_g]; + } + } + else { + sockd = nas_sock_fd[0]; + } + + for (;;) { VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ, 1 ); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 1 ); - if (ue_id_g == 0) - { - len = read(UE_NAS_USE_TUN?nas_sock_fd[ctxt_pP->module_id]:nas_sock_fd[0], &nl_rx_buf, NL_MAX_PAYLOAD); - } - else - { - len = read(UE_NAS_USE_TUN?nas_sock_fd[ue_id_g]:nas_sock_fd[0], &nl_rx_buf, NL_MAX_PAYLOAD); - } - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 0 ); + len = read(sockd, &nl_rx_buf, NL_MAX_PAYLOAD); - if (len<=0) continue; + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 0 ); + if (len == -1) { + if (errno == EAGAIN) { + LOG_D(PDCP, "Error reading NAS socket: %s\n", strerror(errno)); + } + else { + LOG_E(PDCP, "Error reading NAS socket: %s\n", strerror(errno)); + } + break; + } + /* Check for message truncation. Strictly speaking if the packet is exactly sizeof(nl_rx_buf) bytes + that would not be an error. But we cannot distinguish that from a packet > sizeof(nl_rx_buf) */ + if (len == sizeof(nl_rx_buf)) + { + LOG_E(PDCP, "%s(%d). Message truncated %d\n", __FUNCTION__, __LINE__, len); + break; + } + if (len == 0) { + LOG_E(PDCP, "EOF Reading NAS socket\n"); + break; + } if (UE_NAS_USE_TUN) { key = PDCP_COLL_KEY_DEFAULT_DRB_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag); @@ -291,7 +316,7 @@ int pdcp_fifo_read_input_sdus_fromtun (const protocol_ctxt_t *const ctxt_pP) { ctxt.frame, ctxt.instance, rab_id, len, ctxt.module_id, ctxt.rnti, rab_id, key); } - } while (len > 0); + } VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ, 0 ); return len; @@ -664,9 +689,20 @@ void pdcp_fifo_read_input_sdus_frompc5s (const protocol_ctxt_t *const ctxt_pP) //TTN for D2D (PC5S) // receive a message from ProSe App memset(receive_buf, 0, BUFSIZE); - bytes_received = recvfrom(pdcp_pc5_sockfd, receive_buf, BUFSIZE, 0, + bytes_received = recvfrom(pdcp_pc5_sockfd, receive_buf, BUFSIZE, MSG_TRUNC, (struct sockaddr *) &prose_pdcp_addr, (socklen_t *)&prose_addr_len); + if (bytes_received == -1){ + LOG_E(PDCP, "%s(%d). recvfrom failed. %s\n", __FUNCTION__, __LINE__, strerror(errno)); + return; + } + if (bytes_received == 0){ + LOG_E(PDCP, "%s(%d). EOF pdcp_pc5_sockfd.\n", __FUNCTION__, __LINE__); + } + if (bytes_received > BUFSIZE) { + LOG_E(PDCP, "%s(%d). Message truncated. %d\n", __FUNCTION__, __LINE__, bytes_received); + return; + } if (bytes_received > 0) { pc5s_header = calloc(1, sizeof(pc5s_header_t)); memcpy((void *)pc5s_header, (void *)receive_buf, sizeof(pc5s_header_t)); diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c index db8519acc0..af3bd1fdbb 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.c +++ b/openair2/PHY_INTERFACE/phy_stub_UE.c @@ -1273,7 +1273,7 @@ void *ue_standalone_pnf_task(void *context) { struct sockaddr_in server_address; socklen_t addr_len = sizeof(server_address); - char buffer[1024]; + char buffer[NFAPI_MAX_PACKED_MESSAGE_SIZE]; int sd = ue_rx_sock_descriptor; assert(sd > 0); @@ -1283,12 +1283,17 @@ void *ue_standalone_pnf_task(void *context) bool dl_config_req_valid = false; while (true) { - ssize_t len = recvfrom(sd, buffer, sizeof(buffer), 0, (struct sockaddr *)&server_address, &addr_len); + ssize_t len = recvfrom(sd, buffer, sizeof(buffer), MSG_TRUNC, (struct sockaddr *)&server_address, &addr_len); if (len == -1) { LOG_E(MAC, "reading from standalone pnf sctp socket failed \n"); continue; } + if (len > sizeof(buffer)) + { + LOG_E(MAC, "%s(%d). Message truncated. %zd\n", __FUNCTION__, __LINE__, len); + continue; + } if (len == sizeof(uint16_t)) { @@ -1660,7 +1665,7 @@ static void print_rx_ind(nfapi_rx_indication_t *p) void send_standalone_msg(UL_IND_t *UL, nfapi_message_id_e msg_type) { int encoded_size = -1; - char buffer[1024]; + char buffer[NFAPI_MAX_PACKED_MESSAGE_SIZE]; switch (msg_type) { diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.h b/openair2/PHY_INTERFACE/phy_stub_UE.h index 22c35f9423..e148a83688 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.h +++ b/openair2/PHY_INTERFACE/phy_stub_UE.h @@ -19,6 +19,7 @@ //#include "openair1/PHY/LTE_TRANSPORT/defs.h" //#include "openair1/PHY/defs.h" //#include "openair1/PHY/LTE_TRANSPORT/defs.h" +#include "nfapi/open-nFAPI/pnf/inc/pnf_p7.h" #include "queue.h" #define NUM_MCS 28 diff --git a/openair2/RRC/LTE/rrc_UE.c b/openair2/RRC/LTE/rrc_UE.c index 9cc18f66a8..6e8ed5fda5 100644 --- a/openair2/RRC/LTE/rrc_UE.c +++ b/openair2/RRC/LTE/rrc_UE.c @@ -5129,13 +5129,20 @@ void *rrc_control_socket_thread_fct(void *arg) { LOG_I(RRC,"Listening to incoming connection from ProSe App \n"); // receive a message from ProSe App memset(receive_buf, 0, BUFSIZE); - n = recvfrom(ctrl_sock_fd, receive_buf, BUFSIZE, 0, + n = recvfrom(ctrl_sock_fd, receive_buf, BUFSIZE, MSG_TRUNC, (struct sockaddr *) &prose_app_addr, (socklen_t *)&prose_addr_len); if (n < 0) { LOG_E(RRC, "ERROR: Failed to receive from ProSe App\n"); exit(EXIT_FAILURE); } + if (n == 0) { + LOG_E(RRC, "%s(%d). EOF for ctrl_sock_fd\n", __FUNCTION__, __LINE__); + } + if (n > BUFSIZE) { + LOG_E(RRC, "%s(%d). Message truncated. %d\n", __FUNCTION__, __LINE__, n); + exit(EXIT_FAILURE); + } //TODO: should store the address of ProSeApp [UE_rrc_inst] to be able to send UE state notification to the App //sl_ctrl_msg_recv = (struct sidelink_ctrl_element *) receive_buf; diff --git a/openair2/UTIL/ASYNC_IF/socket_link.c b/openair2/UTIL/ASYNC_IF/socket_link.c index 51c5511675..eac0b91069 100644 --- a/openair2/UTIL/ASYNC_IF/socket_link.c +++ b/openair2/UTIL/ASYNC_IF/socket_link.c @@ -409,10 +409,14 @@ static int socket_udp_receive(int socket_fd, void *buf, int size) socklen_t slen = sizeof(client); int l; - l = recvfrom(socket_fd, buf, size, 0, (struct sockaddr *) &client, &slen); + l = recvfrom(socket_fd, buf, size, MSG_TRUNC, (struct sockaddr *) &client, &slen); //getsockname(socket_fd, (struct sockaddr *)&client, &slen); if (l == -1) goto error; if (l == 0) goto socket_closed; + if (l > size) { + LOG_E(MAC, "%s(%d). Message truncated. %d\n", __FUNCTION__, __LINE__, l); + return -1; + } return l; diff --git a/openair3/GTPV1-U/gtpv1u_eNB.c b/openair3/GTPV1-U/gtpv1u_eNB.c index f15f295548..1a074c3902 100644 --- a/openair3/GTPV1-U/gtpv1u_eNB.c +++ b/openair3/GTPV1-U/gtpv1u_eNB.c @@ -221,7 +221,7 @@ NwGtpv1uRcT gtpv1u_eNB_process_stack_req( * - END-MARKER */ case NW_GTPV1U_ULP_API_RECV_TPDU: { - uint8_t buffer[4096]; + uint8_t buffer[NFAPI_MAX_PACKED_MESSAGE_SIZE]; uint32_t buffer_len; struct rrc_eNB_ue_context_s *ue_context_p; uint16_t msgType = NW_GTP_GPDU; diff --git a/openair3/GTPV1-U/gtpv1u_eNB_defs.h b/openair3/GTPV1-U/gtpv1u_eNB_defs.h index 79d9a1dcdd..fb35d65f18 100644 --- a/openair3/GTPV1-U/gtpv1u_eNB_defs.h +++ b/openair3/GTPV1-U/gtpv1u_eNB_defs.h @@ -29,6 +29,7 @@ #include "hashtable.h" #include "LTE_asn_constant.h" +#include "nfapi/open-nFAPI/pnf/inc/pnf_p7.h" #ifndef GTPV1U_ENB_DEFS_H_ #define GTPV1U_ENB_DEFS_H_ diff --git a/openair3/UDP/udp_eNB_task.c b/openair3/UDP/udp_eNB_task.c index 90ee87900d..a1472ff2c0 100644 --- a/openair3/UDP/udp_eNB_task.c +++ b/openair3/UDP/udp_eNB_task.c @@ -235,7 +235,7 @@ udp_eNB_send_to( void udp_eNB_receiver(struct udp_socket_desc_s *udp_sock_pP) { - uint8_t l_buffer[2048]; + uint8_t l_buffer[NFAPI_MAX_PACKED_MESSAGE_SIZE]; int n; socklen_t from_len; struct sockaddr_in addr; @@ -246,10 +246,13 @@ void udp_eNB_receiver(struct udp_socket_desc_s *udp_sock_pP) if (1) { from_len = (socklen_t)sizeof(struct sockaddr_in); - if ((n = recvfrom(udp_sock_pP->sd, l_buffer, sizeof(l_buffer), 0, + if ((n = recvfrom(udp_sock_pP->sd, l_buffer, sizeof(l_buffer), MSG_TRUNC, (struct sockaddr *)&addr, &from_len)) < 0) { LOG_E(UDP_, "Recvfrom failed %s\n", strerror(errno)); return; + } else if (n > sizeof(l_buffer)) { + LOG_E(UDP_, "%s(%d). Message truncated. %d\n", __FUNCTION__, __LINE__, n); + return; } else if (n == 0) { LOG_W(UDP_, "Recvfrom returned 0\n"); return; diff --git a/openair3/UDP/udp_eNB_task.h b/openair3/UDP/udp_eNB_task.h index 8b783f7455..5b1f49a698 100644 --- a/openair3/UDP/udp_eNB_task.h +++ b/openair3/UDP/udp_eNB_task.h @@ -31,6 +31,7 @@ #ifndef UDP_ENB_TASK_H_ #define UDP_ENB_TASK_H_ #include "enb_config.h" +#include "nfapi/open-nFAPI/pnf/inc/pnf_p7.h" /** \brief UDP recv callback prototype. Will be called every time a payload is From 3a5912a00a0cc7220eb037c131363bb37ab1e7c8 Mon Sep 17 00:00:00 2001 From: Melissa Date: Fri, 12 Feb 2021 08:59:00 -0800 Subject: [PATCH 17/26] Updated non-blocking PDCP socket More accurately, we changed the do/while infinite loop to be an infinite for loop for the read command of the socket. The socket file descriptor choice is more clear now. --- nfapi/open-nFAPI/pnf/inc/pnf.h | 3 +- nfapi/open-nFAPI/pnf/src/pnf.c | 1 + nfapi/open-nFAPI/pnf/src/pnf_interface.c | 1 + openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c | 55 +++++++++++------------- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/nfapi/open-nFAPI/pnf/inc/pnf.h b/nfapi/open-nFAPI/pnf/inc/pnf.h index ab38c66e09..9999782dfd 100644 --- a/nfapi/open-nFAPI/pnf/inc/pnf.h +++ b/nfapi/open-nFAPI/pnf/inc/pnf.h @@ -18,9 +18,8 @@ #ifndef _PNF_H_ #define _PNF_H_ -#include "nfapi_pnf_interface.h" +#include "nfapi/open-nFAPI/pnf/inc/pnf_p7.h" -#define NFAPI_MAX_PACKED_MESSAGE_SIZE 8192 typedef struct { diff --git a/nfapi/open-nFAPI/pnf/src/pnf.c b/nfapi/open-nFAPI/pnf/src/pnf.c index eec9ff80c3..349db2e167 100644 --- a/nfapi/open-nFAPI/pnf/src/pnf.c +++ b/nfapi/open-nFAPI/pnf/src/pnf.c @@ -26,6 +26,7 @@ #include #include #include +#include "nfapi/open-nFAPI/pnf/inc/pnf_p7.h" #include "pnf.h" diff --git a/nfapi/open-nFAPI/pnf/src/pnf_interface.c b/nfapi/open-nFAPI/pnf/src/pnf_interface.c index dda0d0fdc6..9c33b87d42 100644 --- a/nfapi/open-nFAPI/pnf/src/pnf_interface.c +++ b/nfapi/open-nFAPI/pnf/src/pnf_interface.c @@ -19,6 +19,7 @@ #include #include #include +#include "nfapi/open-nFAPI/pnf/inc/pnf_p7.h" nfapi_pnf_config_t* nfapi_pnf_config_create() { diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c index 03d91456bd..6399d36794 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c @@ -115,11 +115,13 @@ int pdcp_fifo_flush_sdus(const protocol_ctxt_t *const ctxt_pP) { int pdcp_nb_sdu_sent = 0; int ret=0; - while ((sdu_p = list_get_head (&pdcp_sdu_list)) != NULL && ((pdcp_data_ind_header_t *)(sdu_p->data))->inst == ctxt_pP->module_id) { - ((pdcp_data_ind_header_t *)(sdu_p->data))->inst = 0; - int rb_id = ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id; - int sizeToWrite= sizeof (pdcp_data_ind_header_t) + - ((pdcp_data_ind_header_t *) sdu_p->data)->data_size; + while ((sdu_p = list_get_head (&pdcp_sdu_list)) != NULL) { + pdcp_data_ind_header_t *hdr = (pdcp_data_ind_header_t *) sdu_p->data; + if (hdr->inst != ctxt_pP->module_id) { + break; + } + hdr->inst = 0; + int rb_id = hdr->rb_id; if (rb_id == 10) { //hardcoded for PC5-Signaling if( LOG_DEBUGFLAG(DEBUG_PDCP) ) { @@ -132,42 +134,38 @@ int pdcp_fifo_flush_sdus(const protocol_ctxt_t *const ctxt_pP) { } else if (UE_NAS_USE_TUN) { //ret = write(nas_sock_fd[ctxt_pP->module_id], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite ); - if(rb_id == mbms_rab_id){ - ret = write(nas_sock_mbms_fd, &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite ); - LOG_I(PDCP,"[PDCP_FIFOS] ret %d TRIED TO PUSH MBMS DATA TO rb_id %d handle %d sizeToWrite %d\n",ret,rb_id,nas_sock_fd[ctxt_pP->module_id],sizeToWrite); - } - else - { + if (rb_id == mbms_rab_id) { + ret = write(nas_sock_mbms_fd, &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]), hdr->data_size); + LOG_I(PDCP,"[PDCP_FIFOS] ret %d TRIED TO PUSH MBMS DATA TO rb_id %d handle %d hdr->data_size %d\n", + ret,rb_id,nas_sock_fd[ctxt_pP->module_id], hdr->data_size); + } else { #if defined(ENABLE_PDCP_PAYLOAD_DEBUG) LOG_I(PHY, "PDCP output to be sent to TUN interface: \n"); - for (int i = sizeof(pdcp_data_ind_header_t); i < sizeToWrite; i++) { - printf("%02x ",(unsigned char)sdu_p->data[i]); + for (int i = 0; i < hdr->data_size; i++) { + printf("%02x ",(unsigned char)sdu_p->data[i + sizeof(pdcp_data_ind_header_t)]); } printf("\n"); #endif - if (ue_id_g == 0) - { - ret = write(nas_sock_fd[ctxt_pP->module_id], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite ); + if (ue_id_g == 0) { + ret = write(nas_sock_fd[ctxt_pP->module_id], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]), hdr->data_size); + } else { + ret = write(nas_sock_fd[ue_id_g], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]), hdr->data_size); } - else - { - ret = write(nas_sock_fd[ue_id_g], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite ); - } - //LOG_I(PDCP,"[PDCP_FIFOS] ret %d TRIED TO PUSH DATA TO rb_id %d handle %d sizeToWrite %d\n",ret,rb_id,nas_sock_fd[ctxt_pP->module_id],sizeToWrite); + //LOG_I(PDCP,"[PDCP_FIFOS] ret %d TRIED TO PUSH DATA TO rb_id %d handle %d hdr->data_size %d\n",ret,rb_id,nas_sock_fd[ctxt_pP->module_id],hdr->data_size); } } else if (ENB_NAS_USE_TUN) { #if defined(ENABLE_PDCP_PAYLOAD_DEBUG) LOG_I(PHY, "PDCP output to be sent to TUN interface: \n"); - for (int i = sizeof(pdcp_data_ind_header_t); i < sizeToWrite; i++) { - printf("%02x ",(unsigned char)sdu_p->data[i]); + for (int i = 0; i < hdr->data_size; i++) { + printf("%02x ",(unsigned char)sdu_p->data[i + sizeof(pdcp_data_ind_header_t)]); } printf("\n"); #endif - ret = write(nas_sock_fd[0], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]), sizeToWrite); + ret = write(nas_sock_fd[0], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]), hdr->data_size); } else if (PDCP_USE_NETLINK) { - memcpy(NLMSG_DATA(nas_nlh_tx), (uint8_t *) sdu_p->data, sizeToWrite); - nas_nlh_tx->nlmsg_len = sizeToWrite; + memcpy(NLMSG_DATA(nas_nlh_tx), (uint8_t *) sdu_p->data, sizeof (pdcp_data_ind_header_t) + hdr->data_size); + nas_nlh_tx->nlmsg_len = sizeof (pdcp_data_ind_header_t) + hdr->data_size; ret = sendmsg(nas_sock_fd[0],&nas_msg_tx,0); } // PDCP_USE_NETLINK @@ -691,12 +689,11 @@ void pdcp_fifo_read_input_sdus_frompc5s (const protocol_ctxt_t *const ctxt_pP) memset(receive_buf, 0, BUFSIZE); bytes_received = recvfrom(pdcp_pc5_sockfd, receive_buf, BUFSIZE, MSG_TRUNC, (struct sockaddr *) &prose_pdcp_addr, (socklen_t *)&prose_addr_len); - - if (bytes_received == -1){ + if (bytes_received == -1) { LOG_E(PDCP, "%s(%d). recvfrom failed. %s\n", __FUNCTION__, __LINE__, strerror(errno)); return; } - if (bytes_received == 0){ + if (bytes_received == 0) { LOG_E(PDCP, "%s(%d). EOF pdcp_pc5_sockfd.\n", __FUNCTION__, __LINE__); } if (bytes_received > BUFSIZE) { From df2d3459d8aeeecd2db8ff4af65e01e4f2435cdd Mon Sep 17 00:00:00 2001 From: Melissa Elkadi Date: Fri, 19 Feb 2021 15:00:36 -0800 Subject: [PATCH 18/26] Set first random value to be UE number Also added logs for debugging this rare random value issue. --- openair2/PHY_INTERFACE/phy_stub_UE.c | 3 +-- openair2/RRC/LTE/rrc_UE.c | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c index af3bd1fdbb..de46decfdd 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.c +++ b/openair2/PHY_INTERFACE/phy_stub_UE.c @@ -1113,7 +1113,7 @@ int memcpy_hi_dci0_req (L1_rxtx_proc_t *proc, if (!is_my_hi_dci0_req(req)) { - LOG_W(MAC, "Filtering hi_dci0_req\n"); + LOG_I(MAC, "Filtering hi_dci0_req\n"); return 0; } nfapi_hi_dci0_request_t *p = (nfapi_hi_dci0_request_t *)malloc(sizeof(nfapi_hi_dci0_request_t)); @@ -1309,7 +1309,6 @@ void *ue_standalone_pnf_task(void *context) } else if (len == sizeof(channel_info)) { - LOG_I(MAC, "Entered Channel Info Loop"); channel_info * ch_info = malloc(sizeof(channel_info)); memcpy(ch_info, buffer, sizeof(channel_info)); diff --git a/openair2/RRC/LTE/rrc_UE.c b/openair2/RRC/LTE/rrc_UE.c index 6e8ed5fda5..15835db07a 100644 --- a/openair2/RRC/LTE/rrc_UE.c +++ b/openair2/RRC/LTE/rrc_UE.c @@ -410,7 +410,8 @@ void rrc_ue_generate_RRCConnectionRequest( const protocol_ctxt_t *const ctxt_pP, #endif LOG_T(RRC,"%x.",rv[i]); } - LOG_I(RRC, "%s: random = %02X %02X %02X %02X %02X %02X\n", + rv[0] = ctxt_pP->module_id; // Debugging duplicate random values + LOG_A(RRC, "%s: random = %02X %02X %02X %02X %02X %02X\n", __func__, rv[0], rv[1], From e50de8be023880ccdfc112141099d8cabb27bf81 Mon Sep 17 00:00:00 2001 From: Melissa Elkadi Date: Sat, 6 Mar 2021 12:22:52 -0800 Subject: [PATCH 19/26] Demoting logs and removing duplicate #define Commented out an abort(); used for debugging. An incoming merge request will properly handle the issue of multiple CQIs. --- nfapi/oai_integration/nfapi_pnf.c | 1 - nfapi/oai_integration/nfapi_vnf.c | 4 ++-- nfapi/open-nFAPI/common/src/debug.c | 4 +++- nfapi/open-nFAPI/pnf/inc/pnf_p7.h | 2 +- nfapi/open-nFAPI/vnf/public_inc/nfapi_vnf_interface.h | 4 +--- openair2/PHY_INTERFACE/phy_stub_UE.c | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/nfapi/oai_integration/nfapi_pnf.c b/nfapi/oai_integration/nfapi_pnf.c index d66a396201..a99a181017 100644 --- a/nfapi/oai_integration/nfapi_pnf.c +++ b/nfapi/oai_integration/nfapi_pnf.c @@ -999,7 +999,6 @@ nfapi_pnf_p7_subframe_buffer_t dummy_subframe; int start_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, nfapi_start_request_t *req) { printf("[PNF] Received NFAPI_START_REQ phy_id:%d\n", req->header.phy_id); - nfapi_set_trace_level(NFAPI_TRACE_INFO); pnf_info *pnf = (pnf_info *)(config->user_data); phy_info *phy_info = pnf->phys; nfapi_pnf_p7_config_t *p7_config = nfapi_pnf_p7_config_create(); diff --git a/nfapi/oai_integration/nfapi_vnf.c b/nfapi/oai_integration/nfapi_vnf.c index 6d151799c3..5ed8d35a72 100644 --- a/nfapi/oai_integration/nfapi_vnf.c +++ b/nfapi/oai_integration/nfapi_vnf.c @@ -733,7 +733,7 @@ static void analyze_cqi_pdus_for_duplicates(nfapi_cqi_indication_t *ind) { LOG_E(MAC, "Problem, two cqis received from a single UE for rnti %x\n", rnti_i); - abort(); + //abort(); This will be fixed in merge request which handles multiple CQIs. } } } @@ -1181,7 +1181,7 @@ int oai_nfapi_dl_config_req(nfapi_dl_config_request_t *dl_config_req) { { uint16_t dl_rnti = dl_config_req->dl_config_request_body.dl_config_pdu_list[i].dlsch_pdu.dlsch_pdu_rel8.rnti; uint16_t numPDUs = dl_config_req->dl_config_request_body.number_pdu; - LOG_A(MAC, "(OAI eNB) Sending dl_config_req at VNF during Frame: %d and Subframe: %d," + LOG_I(MAC, "(OAI eNB) Sending dl_config_req at VNF during Frame: %d and Subframe: %d," " with a RNTI value of: %x and with number of PDUs: %u\n", NFAPI_SFNSF2SFN(dl_config_req->sfn_sf),NFAPI_SFNSF2SF(dl_config_req->sfn_sf), dl_rnti, numPDUs); } diff --git a/nfapi/open-nFAPI/common/src/debug.c b/nfapi/open-nFAPI/common/src/debug.c index d7f3b45e15..bfd7f26f69 100644 --- a/nfapi/open-nFAPI/common/src/debug.c +++ b/nfapi/open-nFAPI/common/src/debug.c @@ -37,7 +37,7 @@ void nfapi_trace_dbg(nfapi_trace_level_t level, const char *format, ...); // initialize the trace function to 0 void (*nfapi_trace_g)(nfapi_trace_level_t level, const char* format, ...) = &nfapi_trace_dbg; -nfapi_trace_level_t nfapi_trace_level_g = NFAPI_TRACE_INFO; +nfapi_trace_level_t nfapi_trace_level_g = NFAPI_TRACE_ERROR; //nfapi_trace_level_t nfapi_trace_level_g = NFAPI_TRACE_WARN; void nfapi_set_trace_level(nfapi_trace_level_t new_level) @@ -47,6 +47,8 @@ void nfapi_set_trace_level(nfapi_trace_level_t new_level) void nfapi_trace_dbg(nfapi_trace_level_t level, const char *format, ...) { + if (level < nfapi_trace_level_g) + return; char trace_buff[MAX_MSG_LENGTH + TRACE_HEADER_LENGTH]; uint32_t num_chars; va_list p_args; diff --git a/nfapi/open-nFAPI/pnf/inc/pnf_p7.h b/nfapi/open-nFAPI/pnf/inc/pnf_p7.h index 7ef38a25fc..3f08d85e6b 100644 --- a/nfapi/open-nFAPI/pnf/inc/pnf_p7.h +++ b/nfapi/open-nFAPI/pnf/inc/pnf_p7.h @@ -25,7 +25,7 @@ #include "nfapi_pnf_interface.h" -#define NFAPI_MAX_PACKED_MESSAGE_SIZE 4096 +#define NFAPI_MAX_PACKED_MESSAGE_SIZE 8192 typedef struct { uint16_t dl_conf_ontime; diff --git a/nfapi/open-nFAPI/vnf/public_inc/nfapi_vnf_interface.h b/nfapi/open-nFAPI/vnf/public_inc/nfapi_vnf_interface.h index 5abf6b75c3..e9e22cee97 100644 --- a/nfapi/open-nFAPI/vnf/public_inc/nfapi_vnf_interface.h +++ b/nfapi/open-nFAPI/vnf/public_inc/nfapi_vnf_interface.h @@ -19,16 +19,14 @@ #include "nfapi_interface.h" #include "nfapi_nr_interface_scf.h" - +#include "nfapi/open-nFAPI/pnf/inc/pnf_p7.h" #include "debug.h" - #include "netinet/in.h" #if defined(__cplusplus) extern "C" { #endif -#define NFAPI_MAX_PACKED_MESSAGE_SIZE 8192 /*! The nfapi VNF phy configuration information */ diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c index de46decfdd..1dcf6073cb 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.c +++ b/openair2/PHY_INTERFACE/phy_stub_UE.c @@ -1989,7 +1989,7 @@ static int get_cqi_from_mcs(void) int mcs = get_mcs_from_sinr(sf_rnti_mcs[sf].sinr); CHECK_INDEX(mcs_to_cqi, mcs); int cqi = mcs_to_cqi[mcs]; - LOG_A(MAC, "SINR: %f -> MCS: %d -> CQI: %d\n", sf_rnti_mcs[sf].sinr, mcs, cqi); + LOG_I(MAC, "SINR: %f -> MCS: %d -> CQI: %d\n", sf_rnti_mcs[sf].sinr, mcs, cqi); return cqi; } sf++; From b726053982b54175cb9b44cc648cda7283fc156b Mon Sep 17 00:00:00 2001 From: Michael Cook Date: Sat, 13 Mar 2021 10:24:00 -0800 Subject: [PATCH 20/26] find_ulsch: Skip past null uslch[i] With a small number of runs with 16 UEs, I've seen this AssertFatal fail twice. There are many other places in the code that simply skip over ulsch[i] values that are NULL. --- openair1/PHY/LTE_TRANSPORT/dci_tools.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openair1/PHY/LTE_TRANSPORT/dci_tools.c b/openair1/PHY/LTE_TRANSPORT/dci_tools.c index 4b06f67bbe..0d5d5ad3f1 100644 --- a/openair1/PHY/LTE_TRANSPORT/dci_tools.c +++ b/openair1/PHY/LTE_TRANSPORT/dci_tools.c @@ -84,7 +84,8 @@ int16_t find_ulsch(uint16_t rnti, PHY_VARS_eNB *eNB,find_type_t type) { AssertFatal(eNB!=NULL,"eNB is null\n"); for (i=0; iulsch[i]!=NULL,"eNB->ulsch[%d] is null\n",i); + if (eNB->ulsch[i] == NULL) + continue; if ((eNB->ulsch[i]->harq_mask >0) && (eNB->ulsch[i]->rnti==rnti)) return i; From df81c0de14ca96db4405b84f05cf4ed4423a5703 Mon Sep 17 00:00:00 2001 From: Michael Cook Date: Sat, 13 Mar 2021 10:26:33 -0800 Subject: [PATCH 21/26] Add asserts for size of rx_indication_body.rx_pdu_list --- nfapi/oai_integration/nfapi_vnf.c | 16 +++++++++++----- nfapi/open-nFAPI/nfapi/src/nfapi_p7.c | 9 ++++++++- nfapi/open-nFAPI/vnf/src/vnf_p7.c | 11 +++++++++-- openair1/SCHED/phy_procedures_lte_eNb.c | 1 + openair2/PHY_INTERFACE/IF_Module.c | 2 ++ openair2/PHY_INTERFACE/phy_stub_UE.c | 2 ++ targets/RT/USER/lte-ue.c | 5 +++-- 7 files changed, 36 insertions(+), 10 deletions(-) diff --git a/nfapi/oai_integration/nfapi_vnf.c b/nfapi/oai_integration/nfapi_vnf.c index 776eecf513..640b5f5e0b 100644 --- a/nfapi/oai_integration/nfapi_vnf.c +++ b/nfapi/oai_integration/nfapi_vnf.c @@ -788,10 +788,15 @@ int phy_rx_indication(struct nfapi_vnf_p7_config *config, nfapi_rx_indication_t UL_RCC_INFO.rx_ind[index] = *ind; - if (ind->rx_indication_body.number_of_pdus > 0) - UL_RCC_INFO.rx_ind[index].rx_indication_body.rx_pdu_list = malloc(sizeof(nfapi_rx_indication_pdu_t)*ind->rx_indication_body.number_of_pdus ); + size_t number_of_pdus = ind->rx_indication_body.number_of_pdus; + assert(number_of_pdus <= NFAPI_RX_IND_MAX_PDU); - for (int i=0; irx_indication_body.number_of_pdus; i++) { + if (number_of_pdus > 0) { + UL_RCC_INFO.rx_ind[index].rx_indication_body.rx_pdu_list = + malloc(sizeof(nfapi_rx_indication_pdu_t) * NFAPI_RX_IND_MAX_PDU); + } + + for (int i=0; irx_indication_body.rx_pdu_list[i]; @@ -804,9 +809,9 @@ int phy_rx_indication(struct nfapi_vnf_p7_config *config, nfapi_rx_indication_t dest_pdu->data = NULL; } - LOG_D(PHY, "%s() NFAPI SFN/SF:%d PDUs:%d [PDU:%d] handle:%d rnti:%04x length:%d offset:%d ul_cqi:%d ta:%d data:%p\n", + LOG_D(PHY, "%s() NFAPI SFN/SF:%d PDUs:%zu [PDU:%d] handle:%d rnti:%04x length:%d offset:%d ul_cqi:%d ta:%d data:%p\n", __FUNCTION__, - NFAPI_SFNSF2DEC(ind->sfn_sf), ind->rx_indication_body.number_of_pdus, i, + NFAPI_SFNSF2DEC(ind->sfn_sf), number_of_pdus, i, dest_pdu->rx_ue_information.handle, dest_pdu->rx_ue_information.rnti, dest_pdu->rx_indication_rel8.length, @@ -822,6 +827,7 @@ int phy_rx_indication(struct nfapi_vnf_p7_config *config, nfapi_rx_indication_t *dest_ind = *ind; dest_ind->rx_indication_body.rx_pdu_list = dest_pdu_list; + assert(ind->rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU); for(int i=0; irx_indication_body.number_of_pdus; i++) { nfapi_rx_indication_pdu_t *dest_pdu = &dest_ind->rx_indication_body.rx_pdu_list[i]; nfapi_rx_indication_pdu_t *src_pdu = &ind->rx_indication_body.rx_pdu_list[i]; diff --git a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c index 7fbd509786..aecb52272e 100755 --- a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c +++ b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c @@ -2592,6 +2592,7 @@ static uint8_t pack_rx_ulsch_indication_body_value(void *tlv, uint8_t **ppWriteP uint16_t total_number_of_pdus = value->number_of_pdus; //printf("ULSCH:pdus:%d\n", total_number_of_pdus); + assert(total_number_of_pdus <= NFAPI_RX_IND_MAX_PDU); for(i = 0; i < total_number_of_pdus; ++i) { nfapi_rx_indication_pdu_t* pdu = &(value->rx_pdu_list[i]); @@ -2615,6 +2616,7 @@ static uint8_t pack_rx_ulsch_indication_body_value(void *tlv, uint8_t **ppWriteP } // Now update the structure to include the offset + assert(total_number_of_pdus <= NFAPI_RX_IND_MAX_PDU); for(i =0; i < total_number_of_pdus; ++i) { nfapi_rx_indication_pdu_t* pdu = &(value->rx_pdu_list[i]); @@ -2630,6 +2632,7 @@ static uint8_t pack_rx_ulsch_indication_body_value(void *tlv, uint8_t **ppWriteP } // Write out the pdu + assert(total_number_of_pdus <= NFAPI_RX_IND_MAX_PDU); for(i = 0; i < total_number_of_pdus; ++i) { nfapi_rx_indication_pdu_t* pdu = &(value->rx_pdu_list[i]); @@ -2640,6 +2643,7 @@ static uint8_t pack_rx_ulsch_indication_body_value(void *tlv, uint8_t **ppWriteP } // Write out the pdu data + assert(total_number_of_pdus <= NFAPI_RX_IND_MAX_PDU); for(i = 0; i < total_number_of_pdus; ++i) { uint16_t length = 0; @@ -6496,7 +6500,8 @@ static uint8_t unpack_rx_indication_body_value(void *tlv, uint8_t **ppReadPacked if (value->number_of_pdus > 0) { - value->rx_pdu_list = (nfapi_rx_indication_pdu_t *)nfapi_p7_allocate(sizeof(nfapi_rx_indication_pdu_t) * value->number_of_pdus, config); + assert(value->number_of_pdus <= NFAPI_RX_IND_MAX_PDU); + value->rx_pdu_list = (nfapi_rx_indication_pdu_t *)nfapi_p7_allocate(sizeof(nfapi_rx_indication_pdu_t) * NFAPI_RX_IND_MAX_PDU, config); if (value->rx_pdu_list == NULL) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate rx ind pdu list (count:%d)\n", __FUNCTION__, value->number_of_pdus); @@ -6529,6 +6534,7 @@ static uint8_t unpack_rx_indication_body_value(void *tlv, uint8_t **ppReadPacked return 0; } + assert(i <= NFAPI_RX_IND_MAX_PDU); nfapi_rx_indication_pdu_t *pdu = &value->rx_pdu_list[i]; pdu->rx_ue_information.tl = generic_tl; @@ -6584,6 +6590,7 @@ static uint8_t unpack_rx_indication_body_value(void *tlv, uint8_t **ppReadPacked } } + assert(value->number_of_pdus <= NFAPI_RX_IND_MAX_PDU); for (int i = 0; i < value->number_of_pdus; ++i) { nfapi_rx_indication_pdu_t *pdu = &value->rx_pdu_list[i]; diff --git a/nfapi/open-nFAPI/vnf/src/vnf_p7.c b/nfapi/open-nFAPI/vnf/src/vnf_p7.c index 1420246fe9..4dacb99b5f 100644 --- a/nfapi/open-nFAPI/vnf/src/vnf_p7.c +++ b/nfapi/open-nFAPI/vnf/src/vnf_p7.c @@ -23,9 +23,14 @@ #include #include #include +#include #include "vnf_p7.h" +#ifdef NDEBUG +# warning assert is disabled +#endif + #define SYNC_CYCLE_COUNT 2 void* vnf_p7_malloc(vnf_p7_t* vnf_p7, size_t size) @@ -818,6 +823,7 @@ void vnf_handle_rx_ulsch_indication(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vn } } + assert(ind.rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU); uint16_t i = 0; for(i = 0; i < ind.rx_indication_body.number_of_pdus; ++i) { @@ -2500,8 +2506,9 @@ void vnf_p7_release_msg(vnf_p7_t* vnf_p7, nfapi_p7_message_header_t* header) case NFAPI_RX_ULSCH_INDICATION: { nfapi_rx_indication_t* rx_ind = (nfapi_rx_indication_t*)(header); - uint16_t i = 0; - for(i = 0; i < rx_ind->rx_indication_body.number_of_pdus; ++i) + size_t number_of_pdus = rx_ind->rx_indication_body.number_of_pdus; + assert(number_of_pdus <= NFAPI_RX_IND_MAX_PDU); + for(size_t i = 0; i < number_of_pdus; ++i) { vnf_p7_codec_free(vnf_p7, rx_ind->rx_indication_body.rx_pdu_list[i].data); } diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c index 38307a7b9e..47e8625f8d 100644 --- a/openair1/SCHED/phy_procedures_lte_eNb.c +++ b/openair1/SCHED/phy_procedures_lte_eNb.c @@ -1554,6 +1554,7 @@ void fill_rx_indication(PHY_VARS_eNB *eNB, pthread_mutex_lock(&eNB->UL_INFO_mutex); eNB->UL_INFO.rx_ind.sfn_sf = frame<<4| subframe; eNB->UL_INFO.rx_ind.rx_indication_body.tl.tag = NFAPI_RX_INDICATION_BODY_TAG; + assert(eNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU); pdu = &eNB->UL_INFO.rx_ind.rx_indication_body.rx_pdu_list[eNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus]; // pdu->rx_ue_information.handle = eNB->ulsch[UE_id]->handle; pdu->rx_ue_information.tl.tag = NFAPI_RX_UE_INFORMATION_TAG; diff --git a/openair2/PHY_INTERFACE/IF_Module.c b/openair2/PHY_INTERFACE/IF_Module.c index c1f22e9f8d..cc146ec41f 100644 --- a/openair2/PHY_INTERFACE/IF_Module.c +++ b/openair2/PHY_INTERFACE/IF_Module.c @@ -227,6 +227,7 @@ void handle_ulsch(UL_IND_t *UL_info) { } else if(NFAPI_MODE == NFAPI_MODE_VNF) { for(uint8_t k = 0; k < NUM_NFPAI_SUBFRAME; k++) { if((UL_RCC_INFO.rx_ind[k].rx_indication_body.number_of_pdus>0) && (UL_RCC_INFO.crc_ind[k].crc_indication_body.number_of_crcs>0)) { + assert(UL_RCC_INFO.rx_ind[k].rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU); for (i=0; irx_ind.rx_indication_body.number_of_pdus>0 && UL_info->crc_ind.crc_indication_body.number_of_crcs>0) { + assert(UL_info->rx_ind.rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU); for (i=0; irx_ind.rx_indication_body.number_of_pdus; i++) { for (j=0; jcrc_ind.crc_indication_body.number_of_crcs; j++) { // find crc_indication j corresponding rx_indication i diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c index 5794d74c6d..d7f667c172 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.c +++ b/openair2/PHY_INTERFACE/phy_stub_UE.c @@ -87,6 +87,7 @@ void fill_rx_indication_UE_MAC(module_id_t Mod_id, UL_INFO->rx_ind.rx_indication_body.tl.tag = NFAPI_RX_INDICATION_BODY_TAG; UL_INFO->rx_ind.vendor_extension = ul_config_req->vendor_extension; + assert(UL_INFO->rx_ind.rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU); pdu = &UL_INFO->rx_ind.rx_indication_body .rx_pdu_list[UL_INFO->rx_ind.rx_indication_body.number_of_pdus]; // pdu = &UL_INFO->rx_ind.rx_indication_body.rx_pdu_list[index]; @@ -1538,6 +1539,7 @@ static void print_rx_ind(nfapi_rx_indication_t *p) printf("rx_indication_body.tl.length: %u\n", p->rx_indication_body.tl.length); printf("rx_indication_body.number_of_pdus: %u\n", p->rx_indication_body.number_of_pdus); + assert(p->rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU); nfapi_rx_indication_pdu_t *pdu = p->rx_indication_body.rx_pdu_list; for (int i = 0; i < p->rx_indication_body.number_of_pdus; i++) { diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c index 3eaccb5fa8..f4d04d636c 100644 --- a/targets/RT/USER/lte-ue.c +++ b/targets/RT/USER/lte-ue.c @@ -1040,7 +1040,7 @@ static void *UE_phy_stub_standalone_pnf_task(void *arg) UE = rtd->UE; UL_INFO = (UL_IND_t *)calloc(1, sizeof(UL_IND_t)); - UL_INFO->rx_ind.rx_indication_body.rx_pdu_list = calloc(NUMBER_OF_UE_MAX, sizeof(nfapi_rx_indication_pdu_t)); + UL_INFO->rx_ind.rx_indication_body.rx_pdu_list = calloc(NFAPI_RX_IND_MAX_PDU, sizeof(nfapi_rx_indication_pdu_t)); UL_INFO->rx_ind.rx_indication_body.number_of_pdus = 0; UL_INFO->crc_ind.crc_indication_body.crc_pdu_list = calloc(NUMBER_OF_UE_MAX, sizeof(nfapi_crc_indication_pdu_t)); UL_INFO->crc_ind.crc_indication_body.number_of_crcs = 0; @@ -1281,7 +1281,8 @@ static void *UE_phy_stub_standalone_pnf_task(void *arg) send_standalone_msg(UL_INFO, UL_INFO->rx_ind.header.message_id); sent_any = true; - for (uint8_t num_pdu = 0; num_pdu < UL_INFO->rx_ind.rx_indication_body.number_of_pdus; num_pdu++) { + assert(UL_INFO->rx_ind.rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU); + for (size_t num_pdu = 0; num_pdu < UL_INFO->rx_ind.rx_indication_body.number_of_pdus; num_pdu++) { free(UL_INFO->rx_ind.rx_indication_body.rx_pdu_list[num_pdu].data); } From 6d2590906c718b479f58f21fbefe73dacc399fcb Mon Sep 17 00:00:00 2001 From: Michael Cook Date: Sat, 13 Mar 2021 10:58:33 -0800 Subject: [PATCH 22/26] Assert NFAPI_CRC_IND_MAX_PDU --- nfapi/oai_integration/nfapi_vnf.c | 8 ++++++-- nfapi/open-nFAPI/nfapi/src/nfapi_p7.c | 5 ++++- openair1/SCHED/phy_procedures_lte_eNb.c | 1 + openair2/PHY_INTERFACE/IF_Module.c | 2 ++ targets/RT/USER/lte-ue.c | 2 +- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/nfapi/oai_integration/nfapi_vnf.c b/nfapi/oai_integration/nfapi_vnf.c index 640b5f5e0b..51e379ae56 100644 --- a/nfapi/oai_integration/nfapi_vnf.c +++ b/nfapi/oai_integration/nfapi_vnf.c @@ -735,9 +735,12 @@ int phy_crc_indication(struct nfapi_vnf_p7_config *config, nfapi_crc_indication_ UL_RCC_INFO.crc_ind[index] = *ind; - if (ind->crc_indication_body.number_of_crcs > 0) - UL_RCC_INFO.crc_ind[index].crc_indication_body.crc_pdu_list = malloc(sizeof(nfapi_crc_indication_pdu_t)*ind->crc_indication_body.number_of_crcs ); + assert(ind->crc_indication_body.number_of_crcs <= NFAPI_CRC_IND_MAX_PDU); + if (ind->crc_indication_body.number_of_crcs > 0) { + UL_RCC_INFO.crc_ind[index].crc_indication_body.crc_pdu_list = malloc(sizeof(nfapi_crc_indication_pdu_t) * NFAPI_CRC_IND_MAX_PDU); + } + assert(ind->crc_indication_body.number_of_crcs <= NFAPI_CRC_IND_MAX_PDU); for (int i=0; icrc_indication_body.number_of_crcs; i++) { memcpy(&UL_RCC_INFO.crc_ind[index].crc_indication_body.crc_pdu_list[i], &ind->crc_indication_body.crc_pdu_list[i], sizeof(ind->crc_indication_body.crc_pdu_list[0])); @@ -759,6 +762,7 @@ int phy_crc_indication(struct nfapi_vnf_p7_config *config, nfapi_crc_indication_ LOG_D(MAC, "%s() NFAPI SFN/SF:%d IND:number_of_crcs:%u UL_INFO:crcs:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->crc_indication_body.number_of_crcs, eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs); + assert(ind->crc_indication_body.number_of_crcs <= NFAPI_CRC_IND_MAX_PDU); for (int i=0; icrc_indication_body.number_of_crcs; i++) { memcpy(&dest_ind->crc_indication_body.crc_pdu_list[i], &ind->crc_indication_body.crc_pdu_list[i], sizeof(ind->crc_indication_body.crc_pdu_list[0])); LOG_D(MAC, "%s() NFAPI SFN/SF:%d CRC_IND:number_of_crcs:%u UL_INFO:crcs:%d PDU[%d] rnti:%04x UL_INFO:rnti:%04x\n", diff --git a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c index aecb52272e..fa169b6841 100755 --- a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c +++ b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c @@ -2532,6 +2532,7 @@ static uint8_t pack_crc_indication_body_value(void* tlv, uint8_t **ppWritePacked uint16_t i = 0; uint16_t total_number_of_pdus = value->number_of_crcs; + assert(total_number_of_pdus <= NFAPI_CRC_IND_MAX_PDU); for(; i < total_number_of_pdus; ++i) { nfapi_crc_indication_pdu_t* pdu = &(value->crc_pdu_list[i]); @@ -6408,7 +6409,8 @@ static uint8_t unpack_crc_indication_body_value(void *tlv, uint8_t **ppReadPacke if(value->number_of_crcs > 0) { - value->crc_pdu_list = (nfapi_crc_indication_pdu_t*)nfapi_p7_allocate(sizeof(nfapi_crc_indication_pdu_t) * value->number_of_crcs, config); + assert(value->number_of_crcs <= NFAPI_CRC_IND_MAX_PDU); + value->crc_pdu_list = (nfapi_crc_indication_pdu_t*)nfapi_p7_allocate(sizeof(nfapi_crc_indication_pdu_t) * NFAPI_CRC_IND_MAX_PDU, config); if(value->crc_pdu_list == NULL) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate crc ind pdu list (count:%d)\n", __FUNCTION__, value->number_of_crcs); @@ -6422,6 +6424,7 @@ static uint8_t unpack_crc_indication_body_value(void *tlv, uint8_t **ppReadPacke uint8_t i = 0; + assert(value->number_of_crcs <= NFAPI_CRC_IND_MAX_PDU); for(i = 0; i < value->number_of_crcs; ++i) { nfapi_crc_indication_pdu_t* pdu = &(value->crc_pdu_list[i]); diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c index 47e8625f8d..dc8d726a41 100644 --- a/openair1/SCHED/phy_procedures_lte_eNb.c +++ b/openair1/SCHED/phy_procedures_lte_eNb.c @@ -2088,6 +2088,7 @@ void fill_uci_harq_indication (int UEid, PHY_VARS_eNB *eNB, LTE_eNB_UCI *uci, in void fill_crc_indication (PHY_VARS_eNB *eNB, int UE_id, int frame, int subframe, uint8_t crc_flag) { pthread_mutex_lock(&eNB->UL_INFO_mutex); + assert(eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs <= NFAPI_CRC_IND_MAX_PDU); nfapi_crc_indication_pdu_t *pdu = &eNB->UL_INFO.crc_ind.crc_indication_body.crc_pdu_list[eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs]; eNB->UL_INFO.crc_ind.sfn_sf = frame<<4 | subframe; eNB->UL_INFO.crc_ind.header.message_id = NFAPI_CRC_INDICATION; diff --git a/openair2/PHY_INTERFACE/IF_Module.c b/openair2/PHY_INTERFACE/IF_Module.c index cc146ec41f..40c9653ea6 100644 --- a/openair2/PHY_INTERFACE/IF_Module.c +++ b/openair2/PHY_INTERFACE/IF_Module.c @@ -229,6 +229,7 @@ void handle_ulsch(UL_IND_t *UL_info) { if((UL_RCC_INFO.rx_ind[k].rx_indication_body.number_of_pdus>0) && (UL_RCC_INFO.crc_ind[k].crc_indication_body.number_of_crcs>0)) { assert(UL_RCC_INFO.rx_ind[k].rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU); for (i=0; icrc_ind.crc_indication_body.crc_pdu_list[%d].rx_ue_information.rnti:%04x UL_info->rx_ind.rx_indication_body.rx_pdu_list[%d].rx_ue_information.rnti:%04x\n", @@ -283,6 +284,7 @@ void handle_ulsch(UL_IND_t *UL_info) { if (UL_info->rx_ind.rx_indication_body.number_of_pdus>0 && UL_info->crc_ind.crc_indication_body.number_of_crcs>0) { assert(UL_info->rx_ind.rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU); for (i=0; irx_ind.rx_indication_body.number_of_pdus; i++) { + assert(UL_info->crc_ind.crc_indication_body.number_of_crcs <= NFAPI_CRC_IND_MAX_PDU); for (j=0; jcrc_ind.crc_indication_body.number_of_crcs; j++) { // find crc_indication j corresponding rx_indication i LOG_D(PHY,"UL_info->crc_ind.crc_indication_body.crc_pdu_list[%d].rx_ue_information.rnti:%04x UL_info->rx_ind.rx_indication_body.rx_pdu_list[%d].rx_ue_information.rnti:%04x\n", j, diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c index f4d04d636c..8b6f9cac2f 100644 --- a/targets/RT/USER/lte-ue.c +++ b/targets/RT/USER/lte-ue.c @@ -1042,7 +1042,7 @@ static void *UE_phy_stub_standalone_pnf_task(void *arg) UL_INFO = (UL_IND_t *)calloc(1, sizeof(UL_IND_t)); UL_INFO->rx_ind.rx_indication_body.rx_pdu_list = calloc(NFAPI_RX_IND_MAX_PDU, sizeof(nfapi_rx_indication_pdu_t)); UL_INFO->rx_ind.rx_indication_body.number_of_pdus = 0; - UL_INFO->crc_ind.crc_indication_body.crc_pdu_list = calloc(NUMBER_OF_UE_MAX, sizeof(nfapi_crc_indication_pdu_t)); + UL_INFO->crc_ind.crc_indication_body.crc_pdu_list = calloc(NFAPI_CRC_IND_MAX_PDU, sizeof(nfapi_crc_indication_pdu_t)); UL_INFO->crc_ind.crc_indication_body.number_of_crcs = 0; UL_INFO->harq_ind.harq_indication_body.harq_pdu_list = calloc(NUMBER_OF_UE_MAX, sizeof(nfapi_harq_indication_pdu_t)); UL_INFO->harq_ind.harq_indication_body.number_of_harqs = 0; From c5ff3376ef36fc378edce2457fa2687faac09d90 Mon Sep 17 00:00:00 2001 From: Michael Cook Date: Sat, 13 Mar 2021 11:56:55 -0800 Subject: [PATCH 23/26] Size asserts for harq_pdu_list, sr_pdu_list, cqi_pdu_list --- nfapi/oai_integration/nfapi_vnf.c | 37 +++++++++++++++++-------- nfapi/open-nFAPI/nfapi/src/nfapi_p7.c | 25 +++++++++++++---- openair1/SCHED/phy_procedures_lte_eNb.c | 4 +++ openair2/PHY_INTERFACE/IF_Module.c | 6 ++++ openair2/PHY_INTERFACE/phy_stub_UE.c | 4 +++ targets/RT/USER/lte-ue.c | 8 +++--- 6 files changed, 63 insertions(+), 21 deletions(-) diff --git a/nfapi/oai_integration/nfapi_vnf.c b/nfapi/oai_integration/nfapi_vnf.c index 51e379ae56..890f5c5fe5 100644 --- a/nfapi/oai_integration/nfapi_vnf.c +++ b/nfapi/oai_integration/nfapi_vnf.c @@ -708,18 +708,23 @@ int phy_harq_indication(struct nfapi_vnf_p7_config *config, nfapi_harq_indicatio UL_RCC_INFO.harq_ind[index] = *ind; - if (ind->harq_indication_body.number_of_harqs > 0) - UL_RCC_INFO.harq_ind[index].harq_indication_body.harq_pdu_list = malloc(sizeof(nfapi_harq_indication_pdu_t)*ind->harq_indication_body.number_of_harqs ); + assert(ind->harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU); + if (ind->harq_indication_body.number_of_harqs > 0) { + UL_RCC_INFO.harq_ind[index].harq_indication_body.harq_pdu_list = malloc(sizeof(nfapi_harq_indication_pdu_t) * NFAPI_HARQ_IND_MAX_PDU); + } for (int i=0; iharq_indication_body.number_of_harqs; i++) { memcpy(&UL_RCC_INFO.harq_ind[index].harq_indication_body.harq_pdu_list[i], &ind->harq_indication_body.harq_pdu_list[i], sizeof(nfapi_harq_indication_pdu_t)); } }else{ - eNB->UL_INFO.harq_ind = *ind; - eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list = eNB->harq_pdu_list; + eNB->UL_INFO.harq_ind = *ind; + eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list = eNB->harq_pdu_list; - for (int i=0; iharq_indication_body.number_of_harqs; i++) { - memcpy(&eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list[i], &ind->harq_indication_body.harq_pdu_list[i], sizeof(eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list[i])); - } + assert(ind->harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU); + for (int i=0; iharq_indication_body.number_of_harqs; i++) { + memcpy(&eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list[i], + &ind->harq_indication_body.harq_pdu_list[i], + sizeof(eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list[i])); + } } pthread_mutex_unlock(&eNB->UL_INFO_mutex); // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); @@ -872,9 +877,12 @@ int phy_sr_indication(struct nfapi_vnf_p7_config *config, nfapi_sr_indication_t UL_RCC_INFO.sr_ind[index] = *ind; LOG_D(MAC,"%s() UL_INFO[%d].sr_ind.sr_indication_body.number_of_srs:%d\n", __FUNCTION__, index, eNB->UL_INFO.sr_ind.sr_indication_body.number_of_srs); - if (ind->sr_indication_body.number_of_srs > 0) - UL_RCC_INFO.sr_ind[index].sr_indication_body.sr_pdu_list = malloc(sizeof(nfapi_sr_indication_pdu_t)*ind->sr_indication_body.number_of_srs ); + if (ind->sr_indication_body.number_of_srs > 0) { + assert(ind->sr_indication_body.number_of_srs <= NFAPI_SR_IND_MAX_PDU); + UL_RCC_INFO.sr_ind[index].sr_indication_body.sr_pdu_list = malloc(sizeof(nfapi_sr_indication_pdu_t) * NFAPI_SR_IND_MAX_PDU); + } + assert(ind->sr_indication_body.number_of_srs <= NFAPI_SR_IND_MAX_PDU); for (int i=0; isr_indication_body.number_of_srs; i++) { nfapi_sr_indication_pdu_t *dest_pdu = &UL_RCC_INFO.sr_ind[index].sr_indication_body.sr_pdu_list[i]; nfapi_sr_indication_pdu_t *src_pdu = &ind->sr_indication_body.sr_pdu_list[i]; @@ -890,6 +898,7 @@ int phy_sr_indication(struct nfapi_vnf_p7_config *config, nfapi_sr_indication_t dest_ind->sr_indication_body.sr_pdu_list = dest_pdu_list; LOG_D(MAC,"%s() eNB->UL_INFO.sr_ind.sr_indication_body.number_of_srs:%d\n", __FUNCTION__, eNB->UL_INFO.sr_ind.sr_indication_body.number_of_srs); + assert(eNB->UL_INFO.sr_ind.sr_indication_body.number_of_srs <= NFAPI_SR_IND_MAX_PDU); for (int i=0; iUL_INFO.sr_ind.sr_indication_body.number_of_srs; i++) { nfapi_sr_indication_pdu_t *dest_pdu = &dest_ind->sr_indication_body.sr_pdu_list[i]; nfapi_sr_indication_pdu_t *src_pdu = &ind->sr_indication_body.sr_pdu_list[i]; @@ -911,6 +920,7 @@ static bool is_ue_same(uint16_t ue_id_1, uint16_t ue_id_2) static void analyze_cqi_pdus_for_duplicates(nfapi_cqi_indication_t *ind) { uint16_t num_cqis = ind->cqi_indication_body.number_of_cqis; + assert(num_cqis <= NFAPI_CQI_IND_MAX_PDU); for (int i = 0; i < num_cqis; i++) { nfapi_cqi_indication_pdu_t *src_pdu = &ind->cqi_indication_body.cqi_pdu_list[i]; @@ -942,13 +952,17 @@ int phy_cqi_indication(struct nfapi_vnf_p7_config *config, nfapi_cqi_indication_ int8_t index = NFAPI_SFNSF2SF(ind->sfn_sf); UL_RCC_INFO.cqi_ind[index] = *ind; + assert(ind->cqi_indication_body.number_of_cqis <= NFAPI_CQI_IND_MAX_PDU); if (ind->cqi_indication_body.number_of_cqis > 0){ - UL_RCC_INFO.cqi_ind[index].cqi_indication_body.cqi_pdu_list = malloc(sizeof(nfapi_cqi_indication_pdu_t)*ind->cqi_indication_body.number_of_cqis ); - UL_RCC_INFO.cqi_ind[index].cqi_indication_body.cqi_raw_pdu_list = malloc(sizeof(nfapi_cqi_indication_raw_pdu_t)*ind->cqi_indication_body.number_of_cqis ); + UL_RCC_INFO.cqi_ind[index].cqi_indication_body.cqi_pdu_list = + malloc(sizeof(nfapi_cqi_indication_pdu_t) * NFAPI_CQI_IND_MAX_PDU); + UL_RCC_INFO.cqi_ind[index].cqi_indication_body.cqi_raw_pdu_list = + malloc(sizeof(nfapi_cqi_indication_raw_pdu_t) * NFAPI_CQI_IND_MAX_PDU); } analyze_cqi_pdus_for_duplicates(ind); + assert(ind->cqi_indication_body.number_of_cqis <= NFAPI_CQI_IND_MAX_PDU); for (int i=0; icqi_indication_body.number_of_cqis; i++) { nfapi_cqi_indication_pdu_t *src_pdu = &ind->cqi_indication_body.cqi_pdu_list[i]; LOG_D(MAC, "SR_IND[PDU:%d][rnti:%x cqi:%d channel:%d]\n", i, src_pdu->rx_ue_information.rnti, @@ -964,6 +978,7 @@ int phy_cqi_indication(struct nfapi_vnf_p7_config *config, nfapi_cqi_indication_ *dest_ind = *ind; dest_ind->cqi_indication_body.cqi_pdu_list = ind->cqi_indication_body.cqi_pdu_list; dest_ind->cqi_indication_body.cqi_raw_pdu_list = ind->cqi_indication_body.cqi_raw_pdu_list; + assert(ind->cqi_indication_body.number_of_cqis <= NFAPI_CQI_IND_MAX_PDU); for(int i=0; icqi_indication_body.number_of_cqis; i++) { nfapi_cqi_indication_pdu_t *src_pdu = &ind->cqi_indication_body.cqi_pdu_list[i]; LOG_D(MAC, "CQI_IND[PDU:%d][rnti:%x cqi:%d channel:%d]\n", i, src_pdu->rx_ue_information.rnti, diff --git a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c index fa169b6841..ab9be037cc 100755 --- a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c +++ b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c @@ -2480,6 +2480,7 @@ static uint8_t pack_harq_indication_body_value(void *tlv, uint8_t **ppWritePacke uint16_t i = 0; uint16_t total_number_of_pdus = value->number_of_harqs; + assert(total_number_of_pdus <= NFAPI_HARQ_IND_MAX_PDU); for(; i < total_number_of_pdus; ++i) { nfapi_harq_indication_pdu_t* pdu = &(value->harq_pdu_list[i]); @@ -2838,6 +2839,7 @@ static uint8_t pack_sr_indication_body_value(void *tlv, uint8_t **ppWritePackedM uint16_t i = 0; uint16_t total_number_of_pdus = value->number_of_srs; + assert(total_number_of_pdus <= NFAPI_SR_IND_MAX_PDU); for(; i < total_number_of_pdus; ++i) { nfapi_sr_indication_pdu_t* pdu = &(value->sr_pdu_list[i]); @@ -2905,6 +2907,7 @@ static uint8_t pack_cqi_indication_body_value(void *tlv, uint8_t **ppWritePacked uint16_t i = 0; uint16_t offset = 2; // taking into account the number_of_cqis uint16_t total_number_of_pdus = value->number_of_cqis; + assert(total_number_of_pdus <= NFAPI_CQI_IND_MAX_PDU); for(i = 0; i < total_number_of_pdus; ++i) { nfapi_cqi_indication_pdu_t* pdu = &(value->cqi_pdu_list[i]); @@ -2933,6 +2936,7 @@ static uint8_t pack_cqi_indication_body_value(void *tlv, uint8_t **ppWritePacked } // Now update the structure to include the offset + assert(total_number_of_pdus <= NFAPI_CQI_IND_MAX_PDU); for(i =0; i < total_number_of_pdus; ++i) { nfapi_cqi_indication_pdu_t* pdu = &(value->cqi_pdu_list[i]); @@ -2958,6 +2962,7 @@ static uint8_t pack_cqi_indication_body_value(void *tlv, uint8_t **ppWritePacked } // Write out the cqi information + assert(total_number_of_pdus <= NFAPI_CQI_IND_MAX_PDU); for(i = 0; i < total_number_of_pdus; ++i) { nfapi_cqi_indication_pdu_t* pdu = &(value->cqi_pdu_list[i]); @@ -2980,6 +2985,7 @@ static uint8_t pack_cqi_indication_body_value(void *tlv, uint8_t **ppWritePacked } // Write out the cqi raw data + assert(total_number_of_pdus <= NFAPI_CQI_IND_MAX_PDU); for(i = 0; i < total_number_of_pdus; ++i) { uint16_t length = 0; @@ -6335,15 +6341,16 @@ static uint8_t unpack_harq_indication_body_value(void* tlv, uint8_t **ppReadPack return 0; } - value->harq_pdu_list = (nfapi_harq_indication_pdu_t*)nfapi_p7_allocate(sizeof(nfapi_harq_indication_pdu_t) * value->number_of_harqs, config); + assert(value->number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU); + value->harq_pdu_list = (nfapi_harq_indication_pdu_t*)nfapi_p7_allocate(sizeof(nfapi_harq_indication_pdu_t) * NFAPI_HARQ_IND_MAX_PDU, config); if(value->harq_pdu_list == NULL) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate harq ind pdu list (count:%d)\n", __FUNCTION__, value->number_of_harqs); return 0; } - uint8_t i = 0; - for(i = 0; i < value->number_of_harqs; ++i) + assert(value->number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU); + for (size_t i = 0; i < value->number_of_harqs; ++i) { nfapi_harq_indication_pdu_t* pdu = &(value->harq_pdu_list[i]); if(pull16(ppReadPackedMsg, &pdu->instance_length, end) == 0) @@ -6875,7 +6882,8 @@ static uint8_t unpack_sr_indication_body_value(void *tlv, uint8_t **ppReadPacked if(value->number_of_srs > 0) { - value->sr_pdu_list = (nfapi_sr_indication_pdu_t*)nfapi_p7_allocate(sizeof(nfapi_sr_indication_pdu_t) * value->number_of_srs, config); + assert(value->number_of_srs <= NFAPI_SR_IND_MAX_PDU); + value->sr_pdu_list = (nfapi_sr_indication_pdu_t*)nfapi_p7_allocate(sizeof(nfapi_sr_indication_pdu_t) * NFAPI_SR_IND_MAX_PDU, config); if(value->sr_pdu_list == NULL) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate sr ind pdu list (count:%d)\n", __FUNCTION__, value->number_of_srs); @@ -6888,6 +6896,7 @@ static uint8_t unpack_sr_indication_body_value(void *tlv, uint8_t **ppReadPacked } uint8_t i = 0; + assert(value->number_of_srs <= NFAPI_SR_IND_MAX_PDU); for(i = 0; i < value->number_of_srs; ++i) { nfapi_sr_indication_pdu_t* pdu = &(value->sr_pdu_list[i]); @@ -6984,7 +6993,8 @@ static uint8_t unpack_cqi_indication_body_value(void* tlv, uint8_t **ppReadPack if(value->number_of_cqis > 0) { - value->cqi_pdu_list = (nfapi_cqi_indication_pdu_t*)nfapi_p7_allocate(sizeof(nfapi_cqi_indication_pdu_t) * value->number_of_cqis, config); + assert(value->number_of_cqis <= NFAPI_SR_IND_MAX_PDU); + value->cqi_pdu_list = (nfapi_cqi_indication_pdu_t*)nfapi_p7_allocate(sizeof(nfapi_cqi_indication_pdu_t) * NFAPI_SR_IND_MAX_PDU, config); if(value->cqi_pdu_list == NULL) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate cqi ind pdu list (count:%d)\n", __FUNCTION__, value->number_of_cqis); @@ -6998,7 +7008,8 @@ static uint8_t unpack_cqi_indication_body_value(void* tlv, uint8_t **ppReadPack if(value->number_of_cqis > 0) { - value->cqi_raw_pdu_list = (nfapi_cqi_indication_raw_pdu_t*)nfapi_p7_allocate(sizeof(nfapi_cqi_indication_raw_pdu_t) * value->number_of_cqis, config); + assert(value->number_of_cqis <= NFAPI_SR_IND_MAX_PDU); + value->cqi_raw_pdu_list = (nfapi_cqi_indication_raw_pdu_t*)nfapi_p7_allocate(sizeof(nfapi_cqi_indication_raw_pdu_t) * NFAPI_SR_IND_MAX_PDU, config); if(value->cqi_raw_pdu_list == NULL) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate raw cqi ind pdu list (count:%d)\n", __FUNCTION__, value->number_of_cqis); @@ -7011,6 +7022,7 @@ static uint8_t unpack_cqi_indication_body_value(void* tlv, uint8_t **ppReadPack } uint8_t i = 0; + assert(value->number_of_cqis <= NFAPI_CQI_IND_MAX_PDU); for(i = 0; i < value->number_of_cqis; ++i) { nfapi_cqi_indication_pdu_t* pdu = &(value->cqi_pdu_list[i]); @@ -7063,6 +7075,7 @@ static uint8_t unpack_cqi_indication_body_value(void* tlv, uint8_t **ppReadPack } uint8_t idx = 0; + assert(value->number_of_cqis <= NFAPI_CQI_IND_MAX_PDU); for(idx = 0; idx < value->number_of_cqis; ++idx) { if(value->cqi_pdu_list[idx].cqi_indication_rel8.tl.tag == NFAPI_CQI_INDICATION_REL8_TAG) diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c index dc8d726a41..eff7ccb282 100644 --- a/openair1/SCHED/phy_procedures_lte_eNb.c +++ b/openair1/SCHED/phy_procedures_lte_eNb.c @@ -749,6 +749,7 @@ void fill_sr_indication(int UEid, PHY_VARS_eNB *eNB,uint16_t rnti,int frame,int pthread_mutex_lock(&eNB->UL_INFO_mutex); nfapi_sr_indication_t *sr_ind = &eNB->UL_INFO.sr_ind; nfapi_sr_indication_body_t *sr_ind_body = &sr_ind->sr_indication_body; + assert(sr_ind_body->number_of_srs <= NFAPI_SR_IND_MAX_PDU); nfapi_sr_indication_pdu_t *pdu = &sr_ind_body->sr_pdu_list[sr_ind_body->number_of_srs]; sr_ind->sfn_sf = frame<<4|subframe; sr_ind->header.message_id = NFAPI_RX_SR_INDICATION; @@ -1796,6 +1797,7 @@ int getM(PHY_VARS_eNB *eNB,int frame,int subframe) { void fill_ulsch_cqi_indication (PHY_VARS_eNB *eNB, uint16_t frame, uint8_t subframe, LTE_UL_eNB_HARQ_t *ulsch_harq, uint16_t rnti) { pthread_mutex_lock (&eNB->UL_INFO_mutex); + assert(eNB->UL_INFO.cqi_ind.cqi_indication_body.number_of_cqis <= NFAPI_CQI_IND_MAX_PDU); nfapi_cqi_indication_pdu_t *pdu = &eNB->UL_INFO.cqi_ind.cqi_indication_body.cqi_pdu_list[eNB->UL_INFO.cqi_ind.cqi_indication_body.number_of_cqis]; nfapi_cqi_indication_raw_pdu_t *raw_pdu = &eNB->UL_INFO.cqi_ind.cqi_indication_body.cqi_raw_pdu_list[eNB->UL_INFO.cqi_ind.cqi_indication_body.number_of_cqis]; pdu->instance_length = 0; @@ -1842,6 +1844,7 @@ void fill_ulsch_harq_indication (PHY_VARS_eNB *eNB, LTE_UL_eNB_HARQ_t *ulsch_har //AssertFatal(UE_id>=0,"UE_id doesn't exist\n"); pthread_mutex_lock(&eNB->UL_INFO_mutex); + assert(eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU); nfapi_harq_indication_pdu_t *pdu = &eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list[eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs]; int M; int i; @@ -1912,6 +1915,7 @@ void fill_uci_harq_indication (int UEid, PHY_VARS_eNB *eNB, LTE_eNB_UCI *uci, in pthread_mutex_lock(&eNB->UL_INFO_mutex); nfapi_harq_indication_t *ind = &eNB->UL_INFO.harq_ind; nfapi_harq_indication_body_t *body = &ind->harq_indication_body; + assert(eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU); nfapi_harq_indication_pdu_t *pdu = &body->harq_pdu_list[eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs]; ind->sfn_sf = frame<<4|subframe; ind->header.message_id = NFAPI_HARQ_INDICATION; diff --git a/openair2/PHY_INTERFACE/IF_Module.c b/openair2/PHY_INTERFACE/IF_Module.c index 40c9653ea6..4bc1210cf1 100644 --- a/openair2/PHY_INTERFACE/IF_Module.c +++ b/openair2/PHY_INTERFACE/IF_Module.c @@ -98,6 +98,7 @@ void handle_sr(UL_IND_t *UL_info) { } else if(NFAPI_MODE == NFAPI_MODE_VNF) { for(uint8_t j = 0; j < NUM_NFPAI_SUBFRAME; j++) { if(UL_RCC_INFO.sr_ind[j].sr_indication_body.number_of_srs > 0) { + assert(UL_RCC_INFO.sr_ind[j].sr_indication_body.number_of_srs <= NFAPI_SR_IND_MAX_PDU); for (i=0; imodule_id, UL_info->CC_id, @@ -113,6 +114,7 @@ void handle_sr(UL_IND_t *UL_info) { } } } else { + assert(UL_info->sr_ind.sr_indication_body.number_of_srs <= NFAPI_SR_IND_MAX_PDU); for (i=0; isr_ind.sr_indication_body.number_of_srs; i++) SR_indication(UL_info->module_id, UL_info->CC_id, @@ -139,6 +141,7 @@ void handle_cqi(UL_IND_t *UL_info) { } else if (NFAPI_MODE == NFAPI_MODE_VNF) { for(uint8_t j = 0; j < NUM_NFPAI_SUBFRAME; j++) { if(UL_RCC_INFO.cqi_ind[j].cqi_indication_body.number_of_cqis > 0) { + assert(UL_RCC_INFO.cqi_ind[j].cqi_indication_body.number_of_cqis <= NFAPI_CQI_IND_MAX_PDU); for (i=0; imodule_id, UL_info->CC_id, @@ -157,6 +160,7 @@ void handle_cqi(UL_IND_t *UL_info) { } } } else { + assert(UL_info->cqi_ind.cqi_indication_body.number_of_cqis <= NFAPI_CQI_IND_MAX_PDU); for (i=0; icqi_ind.cqi_indication_body.number_of_cqis; i++) cqi_indication(UL_info->module_id, UL_info->CC_id, @@ -184,6 +188,7 @@ void handle_harq(UL_IND_t *UL_info) { } else if(NFAPI_MODE == NFAPI_MODE_VNF) { for(uint8_t j = 0; j < NUM_NFPAI_SUBFRAME; j++) { if(UL_RCC_INFO.harq_ind[j].harq_indication_body.number_of_harqs > 0) { + assert(UL_RCC_INFO.harq_ind[j].harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU); for (int i=0; imodule_id, UL_info->CC_id, @@ -198,6 +203,7 @@ void handle_harq(UL_IND_t *UL_info) { } } } else { + assert(UL_info->harq_ind.harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU); for (int i=0; i < UL_info->harq_ind.harq_indication_body.number_of_harqs; i++) harq_indication(UL_info->module_id, UL_info->CC_id, diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c index d7f667c172..8a4dd8e4dc 100644 --- a/openair2/PHY_INTERFACE/phy_stub_UE.c +++ b/openair2/PHY_INTERFACE/phy_stub_UE.c @@ -135,6 +135,7 @@ void fill_sr_indication_UE_MAC(int Mod_id, nfapi_sr_indication_t *sr_ind = &UL_INFO->sr_ind; nfapi_sr_indication_body_t *sr_ind_body = &sr_ind->sr_indication_body; + assert(sr_ind_body->number_of_srs <= NFAPI_SR_IND_MAX_PDU); nfapi_sr_indication_pdu_t *pdu = &sr_ind_body->sr_pdu_list[sr_ind_body->number_of_srs]; UL_INFO->sr_ind.vendor_extension = ul_config_req->vendor_extension; @@ -273,6 +274,7 @@ void fill_ulsch_cqi_indication_UE_MAC(int Mod_id, pthread_mutex_lock(&fill_ul_mutex.cqi_mutex); LOG_D(MAC, "num_cqis: %u in fill_ulsch_cqi_indication_UE_MAC\n", UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis); + assert(UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis <= NFAPI_CQI_IND_MAX_PDU); nfapi_cqi_indication_pdu_t *pdu = &UL_INFO->cqi_ind.cqi_indication_body .cqi_pdu_list[UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis]; @@ -320,6 +322,7 @@ void fill_ulsch_harq_indication_UE_MAC( nfapi_ul_config_request_t *ul_config_req) { pthread_mutex_lock(&fill_ul_mutex.harq_mutex); + assert(UL_INFO->harq_ind.harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU); nfapi_harq_indication_pdu_t *pdu = &UL_INFO->harq_ind.harq_indication_body.harq_pdu_list [UL_INFO->harq_ind.harq_indication_body.number_of_harqs]; @@ -366,6 +369,7 @@ void fill_uci_harq_indication_UE_MAC(int Mod_id, nfapi_harq_indication_t *ind = &UL_INFO->harq_ind; nfapi_harq_indication_body_t *body = &ind->harq_indication_body; + assert(UL_INFO->harq_ind.harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU); nfapi_harq_indication_pdu_t *pdu = &body->harq_pdu_list[UL_INFO->harq_ind.harq_indication_body .number_of_harqs]; diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c index 8b6f9cac2f..76111c4950 100644 --- a/targets/RT/USER/lte-ue.c +++ b/targets/RT/USER/lte-ue.c @@ -1044,12 +1044,12 @@ static void *UE_phy_stub_standalone_pnf_task(void *arg) UL_INFO->rx_ind.rx_indication_body.number_of_pdus = 0; UL_INFO->crc_ind.crc_indication_body.crc_pdu_list = calloc(NFAPI_CRC_IND_MAX_PDU, sizeof(nfapi_crc_indication_pdu_t)); UL_INFO->crc_ind.crc_indication_body.number_of_crcs = 0; - UL_INFO->harq_ind.harq_indication_body.harq_pdu_list = calloc(NUMBER_OF_UE_MAX, sizeof(nfapi_harq_indication_pdu_t)); + UL_INFO->harq_ind.harq_indication_body.harq_pdu_list = calloc(NFAPI_HARQ_IND_MAX_PDU, sizeof(nfapi_harq_indication_pdu_t)); UL_INFO->harq_ind.harq_indication_body.number_of_harqs = 0; - UL_INFO->sr_ind.sr_indication_body.sr_pdu_list = calloc(NUMBER_OF_UE_MAX, sizeof(nfapi_sr_indication_pdu_t)); + UL_INFO->sr_ind.sr_indication_body.sr_pdu_list = calloc(NFAPI_SR_IND_MAX_PDU, sizeof(nfapi_sr_indication_pdu_t)); UL_INFO->sr_ind.sr_indication_body.number_of_srs = 0; - UL_INFO->cqi_ind.cqi_indication_body.cqi_pdu_list = calloc(NUMBER_OF_UE_MAX, sizeof(nfapi_cqi_indication_pdu_t)); - UL_INFO->cqi_ind.cqi_indication_body.cqi_raw_pdu_list = calloc(NUMBER_OF_UE_MAX, sizeof(nfapi_cqi_indication_raw_pdu_t)); + UL_INFO->cqi_ind.cqi_indication_body.cqi_pdu_list = calloc(NFAPI_CQI_IND_MAX_PDU, sizeof(nfapi_cqi_indication_pdu_t)); + UL_INFO->cqi_ind.cqi_indication_body.cqi_raw_pdu_list = calloc(NFAPI_CQI_IND_MAX_PDU, sizeof(nfapi_cqi_indication_raw_pdu_t)); UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis = 0; proc->subframe_rx = proc->sub_frame_start; From 39fbe322aa6dbcf10cdf75bcfe0a353b78fd867e Mon Sep 17 00:00:00 2001 From: Michael Cook Date: Sun, 14 Mar 2021 10:59:05 -0400 Subject: [PATCH 24/26] Fix #include --- nfapi/open-nFAPI/vnf/inc/vnf.h | 1 + 1 file changed, 1 insertion(+) diff --git a/nfapi/open-nFAPI/vnf/inc/vnf.h b/nfapi/open-nFAPI/vnf/inc/vnf.h index b16b842606..e5a9c36b85 100644 --- a/nfapi/open-nFAPI/vnf/inc/vnf.h +++ b/nfapi/open-nFAPI/vnf/inc/vnf.h @@ -18,6 +18,7 @@ #ifndef _VNF_H_ #define _VNF_H_ +#include "pnf_p7.h" #include "nfapi_vnf_interface.h" typedef struct From 176a52f5817d62ea231fb76c8a7df0001190a305 Mon Sep 17 00:00:00 2001 From: Michael Cook Date: Sun, 14 Mar 2021 08:44:42 -0700 Subject: [PATCH 25/26] pnf.c: Disable some printfs --- nfapi/open-nFAPI/pnf/src/pnf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nfapi/open-nFAPI/pnf/src/pnf.c b/nfapi/open-nFAPI/pnf/src/pnf.c index d448e4780f..57b482e006 100644 --- a/nfapi/open-nFAPI/pnf/src/pnf.c +++ b/nfapi/open-nFAPI/pnf/src/pnf.c @@ -1973,11 +1973,13 @@ int pnf_send_message(pnf_t* pnf, uint8_t *msg, uint32_t len, uint16_t stream) if (pnf->sctp) { +#if 0 printf("\nPNF SENDS: \n"); for(int i=0; ip5_sock, msg, len, NULL, 0, 42/*config->sctp_stream_number*/, 0, stream/*P5_STREAM_ID*/, 0, 0) < 0) { @@ -2069,12 +2071,14 @@ int pnf_read_dispatch_message(pnf_t* pnf) } else { +#if 0 // print the received message printf("\n MESSAGE RECEIVED: \n"); for(int i=0; i Date: Sun, 14 Mar 2021 09:13:50 -0700 Subject: [PATCH 26/26] Enable assert for RelWithDebInfo builds assert() statements were enabled for C code but disabled for C++ code. With this commit, assert() is enabled for both C and C++ for RelWithDebInfo builds. --- cmake_targets/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index cb4f64006d..a7d2bb61ab 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -353,6 +353,10 @@ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g3 -O0 -DMALLOC_CHECK_=3") set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -g3 -DMALLOC_CHECK_=3 -O2 -fno-delete-null-pointer-checks") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3") +# Enable assert() for RelWithDebInfo builds +string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}") +string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") + set(GIT_BRANCH "UNKNOWN") set(GIT_COMMIT_HASH "UNKNOWN") set(GIT_COMMIT_DATE "UNKNOWN")