From 2ff12533213995dbe4d82321f1abe21bb8201d2f Mon Sep 17 00:00:00 2001 From: Bartosz Podrygajlo Date: Sun, 7 Jul 2024 13:34:04 +0200 Subject: [PATCH] Move init_nr_bler_table out of nr-uesoftmodem.c --- executables/nr-uesoftmodem.c | 60 +------------------ openair1/SIMULATION/NR_PHY/dlsim.c | 2 - openair1/SIMULATION/NR_PHY/prachsim.c | 2 - openair1/SIMULATION/NR_PHY/psbchsim.c | 1 - openair1/SIMULATION/NR_PHY/ulsim.c | 2 - openair2/NR_UE_PHY_INTERFACE/NR_Packet_Drop.c | 56 +++++++++++++++++ openair2/NR_UE_PHY_INTERFACE/NR_Packet_Drop.h | 1 + 7 files changed, 59 insertions(+), 65 deletions(-) diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c index a36667f2b7..d78fe26206 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -165,10 +165,6 @@ unsigned int NTN_UE_Koffset = 0; */ uint8_t abstraction_flag=0; -nr_bler_struct nr_bler_data[NR_NUM_MCS]; - -static void init_bler_table(char*); - /*---------------------BMC: timespec helpers -----------------------------*/ struct timespec min_diff_time = { .tv_sec = 0, .tv_nsec = 0 }; @@ -421,9 +417,9 @@ static void get_channel_model_mode(configmodule_interface_t *cfg) int num_xp_antennas = *GNBParams[GNB_PDSCH_ANTENNAPORTS_XP_IDX].iptr; if (num_xp_antennas == 2) - init_bler_table("NR_MIMO2x2_AWGN_RESULTS_DIR"); + init_nr_bler_table("NR_MIMO2x2_AWGN_RESULTS_DIR"); else - init_bler_table("NR_AWGN_RESULTS_DIR"); + init_nr_bler_table("NR_AWGN_RESULTS_DIR"); } void start_oai_nrue_threads() @@ -639,55 +635,3 @@ int main(int argc, char **argv) return 0; } -// Read in each MCS file and build BLER-SINR-TB table -static void init_bler_table(char *env_string) { - memset(nr_bler_data, 0, sizeof(nr_bler_data)); - - const char *awgn_results_dir = getenv(env_string); - if (!awgn_results_dir) { - LOG_W(NR_MAC, "No %s\n", env_string); - return; - } - - for (unsigned int i = 0; i < NR_NUM_MCS; i++) { - char fName[1024]; - snprintf(fName, sizeof(fName), "%s/mcs%u_awgn_5G.csv", awgn_results_dir, i); - FILE *pFile = fopen(fName, "r"); - if (!pFile) { - LOG_E(NR_MAC, "%s: open %s: %s\n", __func__, fName, strerror(errno)); - continue; - } - size_t bufSize = 1024; - char * line = NULL; - char * token; - char * temp = NULL; - int nlines = 0; - while (getline(&line, &bufSize, pFile) > 0) { - if (!strncmp(line, "SNR", 3)) { - continue; - } - - if (nlines > NR_NUM_SINR) { - LOG_E(NR_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(NR_MAC, "BLER FILE ERROR - num of cols greater than expected\n"); - abort(); - } - - nr_bler_data[i].bler_table[nlines][ncols] = strtof(token, NULL); - ncols++; - - token = strtok_r(NULL, ";", &temp); - } - nlines++; - } - nr_bler_data[i].length = nlines; - fclose(pFile); - } -} diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index d6be222a9b..7747ffed26 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -119,8 +119,6 @@ void nr_derive_key(int alg_type, uint8_t alg_id, const uint8_t key[32], uint8_t void processSlotTX(void *arg) {} -nr_bler_struct nr_bler_data[NR_NUM_MCS]; - // needed for some functions openair0_config_t openair0_cfg[MAX_CARDS]; void update_ptrs_config(NR_CellGroupConfig_t *secondaryCellGroup, uint16_t *rbSize, uint8_t *mcsIndex,int8_t *ptrs_arg); diff --git a/openair1/SIMULATION/NR_PHY/prachsim.c b/openair1/SIMULATION/NR_PHY/prachsim.c index 785e8bb96f..f0dfa8c5bc 100644 --- a/openair1/SIMULATION/NR_PHY/prachsim.c +++ b/openair1/SIMULATION/NR_PHY/prachsim.c @@ -114,8 +114,6 @@ nrUE_params_t *get_nrUE_params(void) { return &nrUE_params; } -nr_bler_struct nr_bler_data[NR_NUM_MCS]; - void processSlotTX(void *arg) {} int NB_UE_INST = 1; configmodule_interface_t *uniqCfg = NULL; diff --git a/openair1/SIMULATION/NR_PHY/psbchsim.c b/openair1/SIMULATION/NR_PHY/psbchsim.c index f56735809d..684ed6d783 100644 --- a/openair1/SIMULATION/NR_PHY/psbchsim.c +++ b/openair1/SIMULATION/NR_PHY/psbchsim.c @@ -80,7 +80,6 @@ int8_t nr_mac_rrc_data_req_ue(const module_id_t Mod_idP, return 0; } -nr_bler_struct nr_bler_data[NR_NUM_MCS]; void get_nrUE_params(void) { return; diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c index b191301513..d5374774d8 100644 --- a/openair1/SIMULATION/NR_PHY/ulsim.c +++ b/openair1/SIMULATION/NR_PHY/ulsim.c @@ -121,8 +121,6 @@ int DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(module_id_t module_idP, return 0; } -nr_bler_struct nr_bler_data[NR_NUM_MCS]; - void nr_derive_key(int alg_type, uint8_t alg_id, const uint8_t key[32], uint8_t out[16]) { (void)alg_type; diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_Packet_Drop.c b/openair2/NR_UE_PHY_INTERFACE/NR_Packet_Drop.c index 52aedfbccc..8a6bd3118c 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_Packet_Drop.c +++ b/openair2/NR_UE_PHY_INTERFACE/NR_Packet_Drop.c @@ -23,6 +23,8 @@ #include "executables/softmodem-common.h" #include "NR_MAC_UE/mac_proto.h" + +nr_bler_struct nr_bler_data[NR_NUM_MCS]; slot_rnti_mcs_s slot_rnti_mcs[NUM_NFAPI_SLOT]; void read_channel_param(const nfapi_nr_dl_tti_pdsch_pdu_rel15_t * pdu, int slot, int index) { @@ -204,3 +206,57 @@ int get_mcs_from_sinr(nr_bler_struct *nr_bler_data, float sinr) LOG_E(NR_MAC, "Unable to get an MCS value.\n"); abort(); } + +// Read in each MCS file and build BLER-SINR-TB table +void init_nr_bler_table(const char *env_string) +{ + memset(nr_bler_data, 0, sizeof(nr_bler_data)); + + const char *awgn_results_dir = getenv(env_string); + if (!awgn_results_dir) { + LOG_W(NR_MAC, "No %s\n", env_string); + return; + } + + for (unsigned int i = 0; i < NR_NUM_MCS; i++) { + char fName[1024]; + snprintf(fName, sizeof(fName), "%s/mcs%u_awgn_5G.csv", awgn_results_dir, i); + FILE *pFile = fopen(fName, "r"); + if (!pFile) { + LOG_E(NR_MAC, "%s: open %s: %s\n", __func__, fName, strerror(errno)); + continue; + } + size_t bufSize = 1024; + char *line = NULL; + char *token; + char *temp = NULL; + int nlines = 0; + while (getline(&line, &bufSize, pFile) > 0) { + if (!strncmp(line, "SNR", 3)) { + continue; + } + + if (nlines > NR_NUM_SINR) { + LOG_E(NR_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(NR_MAC, "BLER FILE ERROR - num of cols greater than expected\n"); + abort(); + } + + nr_bler_data[i].bler_table[nlines][ncols] = strtof(token, NULL); + ncols++; + + token = strtok_r(NULL, ";", &temp); + } + nlines++; + } + nr_bler_data[i].length = nlines; + fclose(pFile); + } +} diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_Packet_Drop.h b/openair2/NR_UE_PHY_INTERFACE/NR_Packet_Drop.h index 6658eec595..02907f9940 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_Packet_Drop.h +++ b/openair2/NR_UE_PHY_INTERFACE/NR_Packet_Drop.h @@ -77,5 +77,6 @@ float get_bler_val(uint8_t mcs, int sinr); bool should_drop_transport_block(int slot, uint16_t rnti); bool is_channel_modeling(void); int get_mcs_from_sinr(nr_bler_struct *nr_bler_data, float sinr); +void init_nr_bler_table(const char *env_string); #endif