diff --git a/lib/include/srsran/phy/phch/ra_nr.h b/lib/include/srsran/phy/phch/ra_nr.h index 99fc624ec..6227a92b7 100644 --- a/lib/include/srsran/phy/phch/ra_nr.h +++ b/lib/include/srsran/phy/phch/ra_nr.h @@ -168,4 +168,32 @@ SRSRAN_API int srsran_ra_nr_cqi_to_mcs(uint8_t cqi, srsran_dci_format_nr_t dci_format, srsran_search_space_type_t search_space_type, srsran_rnti_type_t rnti_type); + +/** + * @brief Returns the Spectral Efficiency corresponding to CQI + * + * Mapping is performed as: return the MCS that has the closest spectral efficiency to that of the CQI + * @param cqi CQI value + * @param cqi_table_idx CQI table index + * @return The Spectral Efficiency + */ +SRSRAN_API double srsran_ra_nr_cqi_to_se(uint8_t cqi, srsran_csi_cqi_table_t cqi_table_idx); + +/** + * @brief Returns the MCS corresponding to Spectral Efficiency + * + * Mapping is performed as: return the greatest MCS with an SE lower than or equal to target SE + * @param se_target Target Spectral efficiency to be mapped into MCS + * @param mcs_table MCS table parameter + * @param dci_format DCI format + * @param search_space_type Seach Space type + * @param rnti_type RNTI type + * @return The MCS index + */ +SRSRAN_API int srsran_ra_nr_se_to_mcs(double se_target, + srsran_mcs_table_t mcs_table, + srsran_dci_format_nr_t dci_format, + srsran_search_space_type_t search_space_type, + srsran_rnti_type_t rnti_type); + #endif // SRSRAN_RA_NR_H diff --git a/lib/src/phy/phch/ra_nr.c b/lib/src/phy/phch/ra_nr.c index f853aa7df..f5e4e9b45 100644 --- a/lib/src/phy/phch/ra_nr.c +++ b/lib/src/phy/phch/ra_nr.c @@ -19,6 +19,7 @@ #include "srsran/phy/phch/ra_ul_nr.h" #include "srsran/phy/phch/uci_nr.h" #include "srsran/phy/utils/debug.h" +#include /* floor */ typedef struct { srsran_mod_t modulation; @@ -145,7 +146,7 @@ typedef enum { ra_nr_table_1 = 0, ra_nr_table_2, ra_nr_table_3 } ra_nr_table_t; * The array ra_nr_cqi_to_mcs_table[CQI_table_idx][MCS_table_idx][CQI] contains the MCS corresponding to CQI, based on * the given CQI_table_idx and MCS_table_idx tables * CQI_table_idx: 1 -> Table 5.2.2.1-2; 2 -> Table 5.2.2.1-3, 3 -> Table 5.2.2.1-4 - * CQI_table_idx: 1 -> Table 5.1.3.1-1; 2 -> Table 5.1.3.1-2; 3 -> Table 5.1.3.1-3 + * MCS_table_idx: 1 -> Table 5.1.3.1-1; 2 -> Table 5.1.3.1-2; 3 -> Table 5.1.3.1-3 */ static int ra_nr_cqi_to_mcs_table[3][3][RA_NR_CQI_TABLE_SIZE] = { @@ -162,6 +163,65 @@ static int ra_nr_cqi_to_mcs_table[3][3][RA_NR_CQI_TABLE_SIZE] = { /* MCS Table 2 */ {-1, 0, 0, 0, 0, 1, 2, 3, 4, 5, 7, 9, 11, 13, 15, 17}, /* MCS Table 3 */ {-1, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28}}}; +/** + * The CQI to Spectral efficiency table. + * The array ra_nr_cqi_to_se_table[CQI_table_idx][CQI] contains the Spectracl Efficiency corresponding to CQI, based on + * the given CQI_table_idx: + * CQI_table_idx: 1 -> Table 5.2.2.1-2; 2 -> Table 5.2.2.1-3, 3 -> Table 5.2.2.1-4 + */ +static const double ra_nr_cqi_to_se_table[3][RA_NR_CQI_TABLE_SIZE] = { + /* ROW 1 - CQI Table 1 */ + {-1, + 0.1523, + 0.2344, + 0.3770, + 0.6016, + 0.8770, + 1.1758, + 1.4766, + 1.9141, + 2.4063, + 2.7305, + 3.3223, + 3.9023, + 4.5234, + 5.1152, + 5.5547}, + /* ROW 2 - CQI Table 2 */ + {-1, + 0.1523, + 0.3770, + 0.8770, + 1.4766, + 1.9141, + 2.4063, + 2.7305, + 3.3223, + 3.9023, + 4.5234, + 5.1152, + 5.5547, + 6.2266, + 6.9141, + 7.4063}, + /* ROW 3 - CQI Table 3 */ + {-1, + 0.0586, + 0.0977, + 0.1523, + 0.2344, + 0.3770, + 0.6016, + 0.8770, + 1.1758, + 1.4766, + 1.9141, + 2.4063, + 2.7305, + 3.3223, + 3.9023, + 4.5234}}; + static ra_nr_table_t ra_nr_select_table_pusch_noprecoding(srsran_mcs_table_t mcs_table, srsran_dci_format_nr_t dci_format, srsran_search_space_type_t search_space_type, @@ -1126,20 +1186,136 @@ int srsran_ra_nr_cqi_to_mcs(uint8_t cqi, return -1; } - typedef enum { table_1 = 0, table_2, table_3, table_N } mcs_table_t; + ra_nr_table_t mcs_table_idx = ra_nr_select_table_pdsch(mcs_table, dci_format, search_space_type, rnti_type); - // The following logic to select the MCS table is the same as in the function ra_nr_select_table_pdsch() in this same - // file - mcs_table_t mcs_table_idx; - if (mcs_table == srsran_mcs_table_256qam && dci_format == srsran_dci_format_nr_1_1 && - rnti_type == srsran_rnti_type_c) { - mcs_table_idx = table_2; - } else if (mcs_table == srsran_mcs_table_qam64LowSE && search_space_type == srsran_search_space_type_ue && - rnti_type == srsran_rnti_type_c) { - mcs_table_idx = table_3; - } else { - mcs_table_idx = table_1; + return ra_nr_cqi_to_mcs_table[cqi_table_idx][mcs_table_idx][cqi]; +} + +double srsran_ra_nr_cqi_to_se(uint8_t cqi, srsran_csi_cqi_table_t cqi_table_idx) +{ + if (cqi >= RA_NR_CQI_TABLE_SIZE) { + ERROR("Invalid CQI (%u)", cqi); + return -1; } - return ra_nr_cqi_to_mcs_table[cqi_table_idx][mcs_table_idx][cqi]; + return ra_nr_cqi_to_se_table[cqi_table_idx][cqi]; +} + +static inline int srsran_ra_nr_mcs_bin_search(double se, size_t mcs_table_size, const mcs_entry_t* mcs_se_table) +{ + if (mcs_se_table == NULL) { + ERROR("Missing MCS table pointer"); + return -1; + } + + if (se < mcs_se_table[0].S) { + return 0; + } else if (se > mcs_se_table[mcs_table_size - 1].S) { + return mcs_table_size - 1; + } + + size_t lb = 0; + size_t ub = mcs_table_size - 1; + while (ub > lb + 1) { + size_t mid_point = (size_t)floor(((double)(lb + ub)) / 2); + // break out of loop is there is an exact match + if (mcs_se_table[mid_point].S == se) { + ub = mid_point; + break; + } + // restrict the search to the left half of the vector + else if (se < mcs_se_table[mid_point].S) { + ub = mid_point; + } + // restrict the search to the right half of the vector + else { /* se > mcs_se_table[mid_point].S ) */ + lb = mid_point; + } + } + + return (int)ub; +} + +int srsran_ra_nr_se_to_mcs(double se_target, + srsran_mcs_table_t mcs_table, + srsran_dci_format_nr_t dci_format, + srsran_search_space_type_t search_space_type, + srsran_rnti_type_t rnti_type) +{ + // Get MCS table index to be used + ra_nr_table_t mcs_table_idx = ra_nr_select_table_pdsch(mcs_table, dci_format, search_space_type, rnti_type); + + // Get MCS table and size based on mcs_table_idx + const mcs_entry_t* mcs_se_table; + size_t mcs_table_size; + switch (mcs_table_idx) { + case ra_nr_table_1: + mcs_se_table = ra_nr_table1; + mcs_table_size = RA_NR_MCS_SIZE_TABLE1; + break; + case ra_nr_table_2: + mcs_se_table = ra_nr_table2; + mcs_table_size = RA_NR_MCS_SIZE_TABLE2; + break; + case ra_nr_table_3: + mcs_se_table = ra_nr_table3; + mcs_table_size = RA_NR_MCS_SIZE_TABLE3; + break; + default: + ERROR("Invalid MCS table index (%u)", mcs_table_idx); + return -1; + } + + // if SE is lower than min possible value, return min MCS + if (se_target <= mcs_se_table[0].S) { + return 0; + } + // if SE is greater than max possible value, return max MCS + else if (se_target >= mcs_se_table[mcs_table_size - 1].S) { + return mcs_table_size - 1; + } + + // handle monotonicity oddity between MCS 16 and 17 for MCS table 1 + if (mcs_table_idx == ra_nr_table_1) { + if (se_target == mcs_se_table[17].S) { + return 17; + } else if (se_target <= mcs_se_table[16].S && se_target > mcs_se_table[17].S) { + return 16; + } + } + + /* In the following, we search for the greatest MCS value such that MCS(SE) <= target SE, where the target SE is the + * value provided as an input argument. The MCS is the vector index, the content of the vector is the SE. + * The search is performed by means of a binary-search like algorithm. At each iteration, we look for the SE in the + * left or right half of the vector, depending on the target SE. + * We stop when the lower-bound (lb) and upper-bound (ub) are two consecutive MCS values and we return the + * lower-bound, which approximates the greatest MCS value such that MCS(SE) <= target SE + * */ + size_t lb = 0; // lower-bound of MCS-to-SE vector where to perform binary search + size_t ub = mcs_table_size - 1; // upper-bound of MCS-to-SE vector where to perform binary search + while (ub > lb + 1) { + size_t mid_point = (size_t)floor(((double)(lb + ub)) / 2); + // break out of loop is there is an exact match + if (mcs_se_table[mid_point].S == se_target) { + return (int)mid_point; + } + // restrict the search to the left half of the vector + else if (se_target < mcs_se_table[mid_point].S) { + ub = mid_point; + // handle monotonicity oddity between MCS 16 and 17 for MCS table 1 + if (mcs_table_idx == ra_nr_table_1 && ub == 17) { + ub = 16; + } + } + // restrict the search to the right half of the vector + else { /* se_target > mcs_se_table[mid_point].S ) */ + lb = mid_point; + // handle monotonicity oddity between MCS 16 and 17 for MCS table 1 + if (mcs_table_idx == ra_nr_table_1 && lb == 16) { + lb = 17; + } + } + } + + return (int)lb; } diff --git a/srsgnb/hdr/stack/mac/sched_nr.h b/srsgnb/hdr/stack/mac/sched_nr.h index cda4de6bb..36ea03c54 100644 --- a/srsgnb/hdr/stack/mac/sched_nr.h +++ b/srsgnb/hdr/stack/mac/sched_nr.h @@ -49,6 +49,7 @@ public: void ul_sr_info(uint16_t rnti) override; void ul_bsr(uint16_t rnti, uint32_t lcg_id, uint32_t bsr) override; void dl_buffer_state(uint16_t rnti, uint32_t lcid, uint32_t newtx, uint32_t retx); + void dl_cqi_info(uint16_t rnti, uint32_t cc, uint32_t cqi_value); /// Called once per slot in a non-concurrent fashion void slot_indication(slot_point slot_tx) override; diff --git a/srsgnb/src/stack/mac/mac_nr.cc b/srsgnb/src/stack/mac/mac_nr.cc index ecf41ec7c..38c768742 100644 --- a/srsgnb/src/stack/mac/mac_nr.cc +++ b/srsgnb/src/stack/mac/mac_nr.cc @@ -584,7 +584,17 @@ bool mac_nr::handle_uci_data(uint16_t rnti, const srsran_uci_cfg_nr_t& cfg_, con } // Process CQI - { + for (uint32_t i = 0; i < cfg_.nof_csi; i++) { + // Skip if invalid or not supported CSI report + if (not value.valid or cfg_.csi[i].cfg.quantity != SRSRAN_CSI_REPORT_QUANTITY_CRI_RI_PMI_CQI or + cfg_.csi[i].cfg.freq_cfg != SRSRAN_CSI_REPORT_FREQ_WIDEBAND or value.csi[i].wideband_cri_ri_pmi_cqi.cqi == 0) { + continue; + } + + // 1. Pass CQI report to scheduler + sched->dl_cqi_info(rnti, 0, value.csi->wideband_cri_ri_pmi_cqi.cqi); + + // 2. Save CQI report for metrics stats srsran::rwlock_read_guard rw_lock(rwmutex); if (ue_db.contains(rnti) && value.valid) { ue_db[rnti]->metrics_dl_cqi(cfg_, value.csi->wideband_cri_ri_pmi_cqi.cqi); diff --git a/srsgnb/src/stack/mac/sched_nr.cc b/srsgnb/src/stack/mac/sched_nr.cc index c2f13d360..d631e2fa5 100644 --- a/srsgnb/src/stack/mac/sched_nr.cc +++ b/srsgnb/src/stack/mac/sched_nr.cc @@ -480,6 +480,15 @@ void sched_nr::dl_buffer_state(uint16_t rnti, uint32_t lcid, uint32_t newtx, uin }); } +void sched_nr::dl_cqi_info(uint16_t rnti, uint32_t cc, uint32_t cqi_value) +{ + auto callback = [cqi_value](ue_carrier& ue_cc, event_manager::logger& ev_logger) { + ue_cc.dl_cqi = cqi_value; + ev_logger.push("0x{:x}: dl_cqi_info(cqi={})", ue_cc.rnti, ue_cc.dl_cqi); + }; + pending_events->enqueue_ue_cc_feedback("dl_cqi_info", rnti, cc, callback); +} + #define VERIFY_INPUT(cond, msg, ...) \ do { \ if (not(cond)) { \ diff --git a/srsgnb/src/stack/mac/test/CMakeLists.txt b/srsgnb/src/stack/mac/test/CMakeLists.txt index 042c8f2b0..c8bdba6d9 100644 --- a/srsgnb/src/stack/mac/test/CMakeLists.txt +++ b/srsgnb/src/stack/mac/test/CMakeLists.txt @@ -40,9 +40,9 @@ add_executable(sched_nr_rar_test sched_nr_rar_test.cc) target_link_libraries(sched_nr_rar_test srsgnb_mac sched_nr_test_suite srsran_common) add_nr_test(sched_nr_rar_test sched_nr_rar_test) -add_executable(sched_nr_utilities_tests sched_nr_utilities_tests.cc) -target_link_libraries(sched_nr_utilities_tests srsgnb_mac srsran_common srsran_phch) -add_nr_test(sched_nr_utilities_tests sched_nr_utilities_tests) +add_executable(sched_nr_dci_utilities_tests sched_nr_dci_utilities_tests.cc) +target_link_libraries(sched_nr_dci_utilities_tests srsgnb_mac srsran_common srsran_phch) +add_nr_test(sched_nr_dci_utilities_tests sched_nr_dci_utilities_tests) add_executable(sched_nr_test sched_nr_test.cc) target_link_libraries(sched_nr_test diff --git a/srsgnb/src/stack/mac/test/sched_nr_dci_utilities_tests.cc b/srsgnb/src/stack/mac/test/sched_nr_dci_utilities_tests.cc new file mode 100644 index 000000000..41487294a --- /dev/null +++ b/srsgnb/src/stack/mac/test/sched_nr_dci_utilities_tests.cc @@ -0,0 +1,469 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2021 Software Radio Systems Limited + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the distribution. + * + */ + +#include "srsran/common/test_common.h" +extern "C" { +#include "srsran/phy/phch/ra_nr.h" +} + +void test_cqi_to_mcs() +{ + // Sample random CQI values and test the returned MCS, for different combinations of CQI and MCS tables + // Set the parameters so that to select a given MCS table (1, 2, or 3) + + // TEST CQI Table 1 - MCS table 1 + int mcs = srsran_ra_nr_cqi_to_mcs(/* cqi */ 3, + /* cqi_table_idx */ SRSRAN_CSI_CQI_TABLE_1, + /* mcs_table */ srsran_mcs_table_64qam, + /* dci_format */ srsran_dci_format_nr_1_0, + /* search_space_type*/ srsran_search_space_type_ue, + /* rnti_type */ srsran_rnti_type_c); + TESTASSERT_EQ(2, mcs); + + mcs = srsran_ra_nr_cqi_to_mcs(5, + SRSRAN_CSI_CQI_TABLE_1, + srsran_mcs_table_64qam, + srsran_dci_format_nr_1_0, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(6, mcs); + + mcs = srsran_ra_nr_cqi_to_mcs(9, + SRSRAN_CSI_CQI_TABLE_1, + srsran_mcs_table_64qam, + srsran_dci_format_nr_1_0, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(15, mcs); + + mcs = srsran_ra_nr_cqi_to_mcs(12, + SRSRAN_CSI_CQI_TABLE_1, + srsran_mcs_table_64qam, + srsran_dci_format_nr_1_0, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(22, mcs); + + // TEST CQI Table 2 - MCS table 2 + mcs = srsran_ra_nr_cqi_to_mcs(1, + SRSRAN_CSI_CQI_TABLE_2, + srsran_mcs_table_256qam, + srsran_dci_format_nr_1_1, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(0, mcs); + + mcs = srsran_ra_nr_cqi_to_mcs(4, + SRSRAN_CSI_CQI_TABLE_2, + srsran_mcs_table_256qam, + srsran_dci_format_nr_1_1, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(5, mcs); + + mcs = srsran_ra_nr_cqi_to_mcs(7, + SRSRAN_CSI_CQI_TABLE_2, + srsran_mcs_table_256qam, + srsran_dci_format_nr_1_1, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(11, mcs); + + mcs = srsran_ra_nr_cqi_to_mcs(11, + SRSRAN_CSI_CQI_TABLE_2, + srsran_mcs_table_256qam, + srsran_dci_format_nr_1_1, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(19, mcs); + + // TEST CQI Table 3 - MCS table 3 + mcs = srsran_ra_nr_cqi_to_mcs(2, + SRSRAN_CSI_CQI_TABLE_3, + srsran_mcs_table_qam64LowSE, + srsran_dci_format_nr_1_0, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(2, mcs); + + mcs = srsran_ra_nr_cqi_to_mcs(8, + SRSRAN_CSI_CQI_TABLE_3, + srsran_mcs_table_qam64LowSE, + srsran_dci_format_nr_1_0, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(14, mcs); + + mcs = srsran_ra_nr_cqi_to_mcs(13, + SRSRAN_CSI_CQI_TABLE_3, + srsran_mcs_table_qam64LowSE, + srsran_dci_format_nr_1_0, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(24, mcs); + + mcs = srsran_ra_nr_cqi_to_mcs(15, + SRSRAN_CSI_CQI_TABLE_3, + srsran_mcs_table_qam64LowSE, + srsran_dci_format_nr_1_0, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(28, mcs); + + // TEST CQI Table 1 - MCS table 2 + mcs = srsran_ra_nr_cqi_to_mcs(6, + SRSRAN_CSI_CQI_TABLE_1, + srsran_mcs_table_256qam, + srsran_dci_format_nr_1_1, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(4, mcs); + + mcs = srsran_ra_nr_cqi_to_mcs(14, + SRSRAN_CSI_CQI_TABLE_1, + srsran_mcs_table_256qam, + srsran_dci_format_nr_1_1, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(19, mcs); + + // TEST CQI Table 1 - MCS table 3 + mcs = srsran_ra_nr_cqi_to_mcs(7, + SRSRAN_CSI_CQI_TABLE_1, + srsran_mcs_table_qam64LowSE, + srsran_dci_format_nr_1_0, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(16, mcs); + + mcs = srsran_ra_nr_cqi_to_mcs(10, + SRSRAN_CSI_CQI_TABLE_1, + srsran_mcs_table_qam64LowSE, + srsran_dci_format_nr_1_0, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(22, mcs); + + // TEST CQI Table 2 - MCS table 1 + mcs = srsran_ra_nr_cqi_to_mcs(3, + SRSRAN_CSI_CQI_TABLE_2, + srsran_mcs_table_64qam, + srsran_dci_format_nr_1_0, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(6, mcs); + + mcs = srsran_ra_nr_cqi_to_mcs(11, + SRSRAN_CSI_CQI_TABLE_2, + srsran_mcs_table_64qam, + srsran_dci_format_nr_1_0, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(26, mcs); + + // TEST CQI Table 2 - MCS table 3 + mcs = srsran_ra_nr_cqi_to_mcs(7, + SRSRAN_CSI_CQI_TABLE_2, + srsran_mcs_table_qam64LowSE, + srsran_dci_format_nr_1_0, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(22, mcs); + + mcs = srsran_ra_nr_cqi_to_mcs(10, + SRSRAN_CSI_CQI_TABLE_2, + srsran_mcs_table_qam64LowSE, + srsran_dci_format_nr_1_0, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(28, mcs); + + // TEST CQI Table 3 - MCS table 1 + mcs = srsran_ra_nr_cqi_to_mcs(2, + SRSRAN_CSI_CQI_TABLE_3, + srsran_mcs_table_64qam, + srsran_dci_format_nr_1_0, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(0, mcs); + + mcs = srsran_ra_nr_cqi_to_mcs(13, + SRSRAN_CSI_CQI_TABLE_3, + srsran_mcs_table_64qam, + srsran_dci_format_nr_1_0, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(20, mcs); + + // TEST CQI Table 3 - MCS table 2 + mcs = srsran_ra_nr_cqi_to_mcs(5, + SRSRAN_CSI_CQI_TABLE_3, + srsran_mcs_table_256qam, + srsran_dci_format_nr_1_1, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(1, mcs); + + mcs = srsran_ra_nr_cqi_to_mcs(14, + SRSRAN_CSI_CQI_TABLE_3, + srsran_mcs_table_256qam, + srsran_dci_format_nr_1_1, + srsran_search_space_type_ue, + srsran_rnti_type_c); + TESTASSERT_EQ(15, mcs); +} + +void test_cqi_to_se() +{ + // TEST CQI Table 1 + double se = srsran_ra_nr_cqi_to_se(2, SRSRAN_CSI_CQI_TABLE_1); + TESTASSERT_EQ(0.2344, se); + + se = srsran_ra_nr_cqi_to_se(5, SRSRAN_CSI_CQI_TABLE_1); + TESTASSERT_EQ(0.8770, se); + + se = srsran_ra_nr_cqi_to_se(8, SRSRAN_CSI_CQI_TABLE_1); + TESTASSERT_EQ(1.9141, se); + + se = srsran_ra_nr_cqi_to_se(11, SRSRAN_CSI_CQI_TABLE_1); + TESTASSERT_EQ(3.3223, se); + + se = srsran_ra_nr_cqi_to_se(13, SRSRAN_CSI_CQI_TABLE_1); + TESTASSERT_EQ(4.5234, se); + + se = srsran_ra_nr_cqi_to_se(15, SRSRAN_CSI_CQI_TABLE_1); + TESTASSERT_EQ(5.5547, se); + + // TEST CQI Table 2 + se = srsran_ra_nr_cqi_to_se(1, SRSRAN_CSI_CQI_TABLE_2); + TESTASSERT_EQ(0.1523, se); + + se = srsran_ra_nr_cqi_to_se(4, SRSRAN_CSI_CQI_TABLE_2); + TESTASSERT_EQ(1.4766, se); + + se = srsran_ra_nr_cqi_to_se(7, SRSRAN_CSI_CQI_TABLE_2); + TESTASSERT_EQ(2.7305, se); + + se = srsran_ra_nr_cqi_to_se(10, SRSRAN_CSI_CQI_TABLE_2); + TESTASSERT_EQ(4.5234, se); + + se = srsran_ra_nr_cqi_to_se(12, SRSRAN_CSI_CQI_TABLE_2); + TESTASSERT_EQ(5.5547, se); + + se = srsran_ra_nr_cqi_to_se(14, SRSRAN_CSI_CQI_TABLE_2); + TESTASSERT_EQ(6.9141, se); + + // TEST CQI Table 3 + se = srsran_ra_nr_cqi_to_se(1, SRSRAN_CSI_CQI_TABLE_3); + TESTASSERT_EQ(0.0586, se); + + se = srsran_ra_nr_cqi_to_se(3, SRSRAN_CSI_CQI_TABLE_3); + TESTASSERT_EQ(0.1523, se); + + se = srsran_ra_nr_cqi_to_se(7, SRSRAN_CSI_CQI_TABLE_3); + TESTASSERT_EQ(0.8770, se); + + se = srsran_ra_nr_cqi_to_se(9, SRSRAN_CSI_CQI_TABLE_3); + TESTASSERT_EQ(1.4766, se); + + se = srsran_ra_nr_cqi_to_se(12, SRSRAN_CSI_CQI_TABLE_3); + TESTASSERT_EQ(2.7305, se); + + se = srsran_ra_nr_cqi_to_se(15, SRSRAN_CSI_CQI_TABLE_3); + TESTASSERT_EQ(4.5234, se); +} + +void test_se_to_mcs() +{ + // MCS table 1 + int mcs = srsran_ra_nr_se_to_mcs(/* se */ .1, + /* mcs_table */ srsran_mcs_table_64qam, + /* dci_format */ srsran_dci_format_nr_1_0, + /* search_space_type*/ srsran_search_space_type_ue, + /* rnti_type */ srsran_rnti_type_c); + TESTASSERT_EQ(0, mcs); + + mcs = srsran_ra_nr_se_to_mcs(/* se */ .2344, + /* mcs_table */ srsran_mcs_table_64qam, + /* dci_format */ srsran_dci_format_nr_1_0, + /* search_space_type*/ srsran_search_space_type_ue, + /* rnti_type */ srsran_rnti_type_c); + TESTASSERT_EQ(0, mcs); + + mcs = srsran_ra_nr_se_to_mcs(/* se */ 1, + /* mcs_table */ srsran_mcs_table_64qam, + /* dci_format */ srsran_dci_format_nr_1_0, + /* search_space_type*/ srsran_search_space_type_ue, + /* rnti_type */ srsran_rnti_type_c); + TESTASSERT_EQ(6, mcs); + + mcs = srsran_ra_nr_se_to_mcs(/* se */ 1.0273, + /* mcs_table */ srsran_mcs_table_64qam, + /* dci_format */ srsran_dci_format_nr_1_0, + /* search_space_type*/ srsran_search_space_type_ue, + /* rnti_type */ srsran_rnti_type_c); + TESTASSERT_EQ(7, mcs); + + mcs = srsran_ra_nr_se_to_mcs(/* se */ 2.5, + /* mcs_table */ srsran_mcs_table_64qam, + /* dci_format */ srsran_dci_format_nr_1_0, + /* search_space_type*/ srsran_search_space_type_ue, + /* rnti_type */ srsran_rnti_type_c); + TESTASSERT_EQ(15, mcs); + + mcs = srsran_ra_nr_se_to_mcs(/* se */ 2.5703, + /* mcs_table */ srsran_mcs_table_64qam, + /* dci_format */ srsran_dci_format_nr_1_0, + /* search_space_type*/ srsran_search_space_type_ue, + /* rnti_type */ srsran_rnti_type_c); + TESTASSERT_EQ(16, mcs); + + mcs = srsran_ra_nr_se_to_mcs(/* se */ 2.57, + /* mcs_table */ srsran_mcs_table_64qam, + /* dci_format */ srsran_dci_format_nr_1_0, + /* search_space_type*/ srsran_search_space_type_ue, + /* rnti_type */ srsran_rnti_type_c); + TESTASSERT_EQ(16, mcs); + + mcs = srsran_ra_nr_se_to_mcs(/* se */ 2.5664, + /* mcs_table */ srsran_mcs_table_64qam, + /* dci_format */ srsran_dci_format_nr_1_0, + /* search_space_type*/ srsran_search_space_type_ue, + /* rnti_type */ srsran_rnti_type_c); + TESTASSERT_EQ(17, mcs); + + mcs = srsran_ra_nr_se_to_mcs(/* se */ 5.5, + /* mcs_table */ srsran_mcs_table_64qam, + /* dci_format */ srsran_dci_format_nr_1_0, + /* search_space_type*/ srsran_search_space_type_ue, + /* rnti_type */ srsran_rnti_type_c); + TESTASSERT_EQ(27, mcs); + + mcs = srsran_ra_nr_se_to_mcs(/* se */ 5.5574, + /* mcs_table */ srsran_mcs_table_64qam, + /* dci_format */ srsran_dci_format_nr_1_0, + /* search_space_type*/ srsran_search_space_type_ue, + /* rnti_type */ srsran_rnti_type_c); + TESTASSERT_EQ(28, mcs); + + mcs = srsran_ra_nr_se_to_mcs(/* se */ 6, + /* mcs_table */ srsran_mcs_table_64qam, + /* dci_format */ srsran_dci_format_nr_1_0, + /* search_space_type*/ srsran_search_space_type_ue, + /* rnti_type */ srsran_rnti_type_c); + TESTASSERT_EQ(28, mcs); + + // MCS table 2 + mcs = srsran_ra_nr_se_to_mcs( + 0.1, srsran_mcs_table_256qam, srsran_dci_format_nr_1_1, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(0, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 0.2344, srsran_mcs_table_256qam, srsran_dci_format_nr_1_1, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(0, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 0.24, srsran_mcs_table_256qam, srsran_dci_format_nr_1_1, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(0, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 1.47, srsran_mcs_table_256qam, srsran_dci_format_nr_1_1, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(4, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 1.4766, srsran_mcs_table_256qam, srsran_dci_format_nr_1_1, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(5, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 3.5, srsran_mcs_table_256qam, srsran_dci_format_nr_1_1, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(13, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 3.6094, srsran_mcs_table_256qam, srsran_dci_format_nr_1_1, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(14, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 5.2, srsran_mcs_table_256qam, srsran_dci_format_nr_1_1, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(19, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 5.3320, srsran_mcs_table_256qam, srsran_dci_format_nr_1_1, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(20, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 5.4, srsran_mcs_table_256qam, srsran_dci_format_nr_1_1, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(20, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 7.4063, srsran_mcs_table_256qam, srsran_dci_format_nr_1_1, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(27, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 7.5, srsran_mcs_table_256qam, srsran_dci_format_nr_1_1, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(27, mcs); + + // MCS table 3 + mcs = srsran_ra_nr_se_to_mcs( + 0.05, srsran_mcs_table_qam64LowSE, srsran_dci_format_nr_1_0, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(0, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 0.0586, srsran_mcs_table_qam64LowSE, srsran_dci_format_nr_1_0, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(0, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 0.056, srsran_mcs_table_qam64LowSE, srsran_dci_format_nr_1_0, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(0, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 0.15, srsran_mcs_table_qam64LowSE, srsran_dci_format_nr_1_0, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(3, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 0.1523, srsran_mcs_table_qam64LowSE, srsran_dci_format_nr_1_0, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(4, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 0.49, srsran_mcs_table_qam64LowSE, srsran_dci_format_nr_1_0, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(8, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 0.4902, srsran_mcs_table_qam64LowSE, srsran_dci_format_nr_1_0, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(9, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 1.69, srsran_mcs_table_qam64LowSE, srsran_dci_format_nr_1_0, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(16, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 1.6953, srsran_mcs_table_qam64LowSE, srsran_dci_format_nr_1_0, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(17, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 4.52, srsran_mcs_table_qam64LowSE, srsran_dci_format_nr_1_0, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(27, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 4.5234, srsran_mcs_table_qam64LowSE, srsran_dci_format_nr_1_0, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(28, mcs); + + mcs = srsran_ra_nr_se_to_mcs( + 4.6, srsran_mcs_table_qam64LowSE, srsran_dci_format_nr_1_0, srsran_search_space_type_ue, srsran_rnti_type_c); + TESTASSERT_EQ(28, mcs); +}; + +int main() +{ + test_cqi_to_mcs(); + test_cqi_to_se(); + test_se_to_mcs(); +} \ No newline at end of file diff --git a/srsgnb/src/stack/mac/test/sched_nr_utilities_tests.cc b/srsgnb/src/stack/mac/test/sched_nr_utilities_tests.cc deleted file mode 100644 index fa6aef467..000000000 --- a/srsgnb/src/stack/mac/test/sched_nr_utilities_tests.cc +++ /dev/null @@ -1,228 +0,0 @@ -/** - * - * \section COPYRIGHT - * - * Copyright 2013-2021 Software Radio Systems Limited - * - * By using this file, you agree to the terms and conditions set - * forth in the LICENSE file which can be found at the top level of - * the distribution. - * - */ - -#include "srsran/common/test_common.h" -extern "C" { -#include "srsran/phy/phch/ra_nr.h" -} - -void test_cqi_to_mcs() -{ - // Sample random CQI values and test the returned MCS, for different combinations of CQI and MCS tables - // Set the parameters so that to select a given MCS table (1, 2, or 3) - - // TEST CQI Table 1 - MCS table 1 - int mcs = srsran_ra_nr_cqi_to_mcs(/* cqi */ 3, - /* cqi_table_idx */ SRSRAN_CSI_CQI_TABLE_1, - /* mcs_table */ srsran_mcs_table_64qam, - /* dci_format */ srsran_dci_format_nr_1_0, - /* search_space_type*/ srsran_search_space_type_ue, - /* rnti_type */ srsran_rnti_type_c); - TESTASSERT_EQ(2, mcs); - - mcs = srsran_ra_nr_cqi_to_mcs(5, - SRSRAN_CSI_CQI_TABLE_1, - srsran_mcs_table_64qam, - srsran_dci_format_nr_1_0, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(6, mcs); - - mcs = srsran_ra_nr_cqi_to_mcs(9, - SRSRAN_CSI_CQI_TABLE_1, - srsran_mcs_table_64qam, - srsran_dci_format_nr_1_0, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(15, mcs); - - mcs = srsran_ra_nr_cqi_to_mcs(12, - SRSRAN_CSI_CQI_TABLE_1, - srsran_mcs_table_64qam, - srsran_dci_format_nr_1_0, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(22, mcs); - - // TEST CQI Table 2 - MCS table 2 - mcs = srsran_ra_nr_cqi_to_mcs(1, - SRSRAN_CSI_CQI_TABLE_2, - srsran_mcs_table_256qam, - srsran_dci_format_nr_1_1, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(0, mcs); - - mcs = srsran_ra_nr_cqi_to_mcs(4, - SRSRAN_CSI_CQI_TABLE_2, - srsran_mcs_table_256qam, - srsran_dci_format_nr_1_1, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(5, mcs); - - mcs = srsran_ra_nr_cqi_to_mcs(7, - SRSRAN_CSI_CQI_TABLE_2, - srsran_mcs_table_256qam, - srsran_dci_format_nr_1_1, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(11, mcs); - - mcs = srsran_ra_nr_cqi_to_mcs(11, - SRSRAN_CSI_CQI_TABLE_2, - srsran_mcs_table_256qam, - srsran_dci_format_nr_1_1, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(19, mcs); - - // TEST CQI Table 3 - MCS table 3 - mcs = srsran_ra_nr_cqi_to_mcs(2, - SRSRAN_CSI_CQI_TABLE_3, - srsran_mcs_table_qam64LowSE, - srsran_dci_format_nr_1_0, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(2, mcs); - - mcs = srsran_ra_nr_cqi_to_mcs(8, - SRSRAN_CSI_CQI_TABLE_3, - srsran_mcs_table_qam64LowSE, - srsran_dci_format_nr_1_0, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(14, mcs); - - mcs = srsran_ra_nr_cqi_to_mcs(13, - SRSRAN_CSI_CQI_TABLE_3, - srsran_mcs_table_qam64LowSE, - srsran_dci_format_nr_1_0, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(24, mcs); - - mcs = srsran_ra_nr_cqi_to_mcs(15, - SRSRAN_CSI_CQI_TABLE_3, - srsran_mcs_table_qam64LowSE, - srsran_dci_format_nr_1_0, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(28, mcs); - - // TEST CQI Table 1 - MCS table 2 - mcs = srsran_ra_nr_cqi_to_mcs(6, - SRSRAN_CSI_CQI_TABLE_1, - srsran_mcs_table_256qam, - srsran_dci_format_nr_1_1, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(4, mcs); - - mcs = srsran_ra_nr_cqi_to_mcs(14, - SRSRAN_CSI_CQI_TABLE_1, - srsran_mcs_table_256qam, - srsran_dci_format_nr_1_1, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(19, mcs); - - // TEST CQI Table 1 - MCS table 3 - mcs = srsran_ra_nr_cqi_to_mcs(7, - SRSRAN_CSI_CQI_TABLE_1, - srsran_mcs_table_qam64LowSE, - srsran_dci_format_nr_1_0, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(16, mcs); - - mcs = srsran_ra_nr_cqi_to_mcs(10, - SRSRAN_CSI_CQI_TABLE_1, - srsran_mcs_table_qam64LowSE, - srsran_dci_format_nr_1_0, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(22, mcs); - - // TEST CQI Table 2 - MCS table 1 - mcs = srsran_ra_nr_cqi_to_mcs(3, - SRSRAN_CSI_CQI_TABLE_2, - srsran_mcs_table_64qam, - srsran_dci_format_nr_1_0, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(6, mcs); - - mcs = srsran_ra_nr_cqi_to_mcs(11, - SRSRAN_CSI_CQI_TABLE_2, - srsran_mcs_table_64qam, - srsran_dci_format_nr_1_0, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(26, mcs); - - // TEST CQI Table 2 - MCS table 3 - mcs = srsran_ra_nr_cqi_to_mcs(7, - SRSRAN_CSI_CQI_TABLE_2, - srsran_mcs_table_qam64LowSE, - srsran_dci_format_nr_1_0, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(22, mcs); - - mcs = srsran_ra_nr_cqi_to_mcs(10, - SRSRAN_CSI_CQI_TABLE_2, - srsran_mcs_table_qam64LowSE, - srsran_dci_format_nr_1_0, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(28, mcs); - - // TEST CQI Table 3 - MCS table 1 - mcs = srsran_ra_nr_cqi_to_mcs(2, - SRSRAN_CSI_CQI_TABLE_3, - srsran_mcs_table_64qam, - srsran_dci_format_nr_1_0, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(0, mcs); - - mcs = srsran_ra_nr_cqi_to_mcs(13, - SRSRAN_CSI_CQI_TABLE_3, - srsran_mcs_table_64qam, - srsran_dci_format_nr_1_0, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(20, mcs); - - // TEST CQI Table 3 - MCS table 2 - mcs = srsran_ra_nr_cqi_to_mcs(5, - SRSRAN_CSI_CQI_TABLE_3, - srsran_mcs_table_256qam, - srsran_dci_format_nr_1_1, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(1, mcs); - - mcs = srsran_ra_nr_cqi_to_mcs(14, - SRSRAN_CSI_CQI_TABLE_3, - srsran_mcs_table_256qam, - srsran_dci_format_nr_1_1, - srsran_search_space_type_ue, - srsran_rnti_type_c); - TESTASSERT_EQ(15, mcs); -} - -int main() -{ - test_cqi_to_mcs(); -} \ No newline at end of file