diff --git a/CMakeLists.txt b/CMakeLists.txt index 03cbc144c7..de7e300a67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -463,7 +463,7 @@ add_library(f1ap ${F1AP_DIR}/f1ap_handlers.c ${F1AP_DIR}/f1ap_itti_messaging.c) target_include_directories(f1ap PUBLIC F1AP_DIR) -target_link_libraries(f1ap PUBLIC asn1_f1ap) +target_link_libraries(f1ap PUBLIC asn1_f1ap L2_NR) target_link_libraries(f1ap PRIVATE ngap nr_rrc HASHTABLE) # LPP @@ -1181,9 +1181,10 @@ target_include_directories(PHY_UE PRIVATE ${blas_INCLUDE_DIRS} ${lapacke_INCLUDE add_library(PHY_NR_COMMON ${PHY_NR_SRC_COMMON}) add_library(PHY_NR ${PHY_NR_SRC}) +target_link_libraries(PHY_NR nr_phy_common nr_common) add_library(PHY_NR_UE ${PHY_NR_UE_SRC}) -target_link_libraries(PHY_NR_UE PRIVATE asn1_nr_rrc_hdrs) +target_link_libraries(PHY_NR_UE PRIVATE asn1_nr_rrc_hdrs nr_phy_common nr_common) add_library(PHY_RU ${PHY_SRC_RU}) target_link_libraries(PHY_RU PRIVATE asn1_lte_rrc_hdrs) @@ -1413,7 +1414,6 @@ set (MAC_NR_SRC_UE ${NR_UE_MAC_DIR}/nr_ue_scheduler.c ${NR_UE_MAC_DIR}/nr_ue_dci_configuration.c ${NR_UE_MAC_DIR}/nr_ra_procedures.c - ${NR_UE_MAC_DIR}/nr_ue_power_procedures.c ) set (ENB_APP_SRC @@ -1462,7 +1462,7 @@ endif() add_library(MAC_UE_NR ${MAC_NR_SRC_UE}) -target_link_libraries(MAC_UE_NR PRIVATE asn1_lte_rrc_hdrs asn1_nr_rrc_hdrs) +target_link_libraries(MAC_UE_NR PRIVATE asn1_lte_rrc_hdrs asn1_nr_rrc_hdrs PUBLIC nr_ue_power_procedures) add_library(L2_LTE ${L2_LTE_SRC}) target_link_libraries(L2_LTE PRIVATE asn1_lte_rrc_hdrs asn1_nr_rrc_hdrs) @@ -1481,7 +1481,7 @@ add_library(e1_if target_link_libraries(e1_if PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs asn1_f1ap SECURITY ${OPENSSL_LIBRARIES} e1ap GTPV1U) -target_link_libraries(L2_NR PRIVATE f1ap x2ap s1ap ngap nr_rrc e1ap nr_rlc) +target_link_libraries(L2_NR PRIVATE f1ap x2ap s1ap ngap nr_rrc e1ap nr_rlc nr_common) if(E2_AGENT) target_link_libraries(L2_NR PUBLIC e2_agent e2_agent_arg e2_ran_func_du_cucp_cuup) target_compile_definitions(L2_NR PRIVATE ${E2AP_VERSION} ${KPM_VERSION} E2_AGENT) @@ -1516,7 +1516,7 @@ target_link_libraries(L2_UE PRIVATE asn1_lte_rrc_hdrs) add_library( NR_L2_UE ${NR_L2_SRC_UE} ${MAC_NR_SRC_UE} ) target_link_libraries(NR_L2_UE PRIVATE f1ap nr_rlc) -target_link_libraries(NR_L2_UE PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) +target_link_libraries(NR_L2_UE PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs nr_common nr_ue_power_procedures) add_library(MAC_NR_COMMON ${OPENAIR2_DIR}/LAYER2/NR_MAC_COMMON/nr_mac_common.c @@ -2083,7 +2083,6 @@ add_executable(nr-softmodem ${OPENAIR2_DIR}/RRC/NAS/rb_config.c ${OPENAIR_DIR}/common/utils/lte/ue_power.c ${OPENAIR_DIR}/common/utils/lte/prach_utils.c - ${OPENAIR_DIR}/common/utils/nr/nr_common.c ${PHY_INTERFACE_DIR}/queue_t.c ${OPENAIR1_DIR}/PHY/TOOLS/phy_scope_interface.c ) @@ -2152,7 +2151,6 @@ add_executable(nr-uesoftmodem ${OPENAIR2_DIR}/LAYER2/NR_MAC_COMMON/nr_mac_common.c ${OPENAIR2_DIR}/RRC/NAS/rb_config.c ${OPENAIR3_DIR}/NAS/UE/nas_ue_task.c - ${OPENAIR_DIR}/common/utils/nr/nr_common.c ${OPENAIR1_DIR}/PHY/TOOLS/phy_scope_interface.c ) @@ -2207,7 +2205,6 @@ target_link_libraries(rftest PRIVATE asn1_lte_rrc_hdrs asn1_nr_rrc_hdrs) add_executable(polartest ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/polartest.c - ${OPENAIR_DIR}/common/utils/nr/nr_common.c ) target_link_libraries(polartest PRIVATE -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR PHY_NR_COMMON PHY_NR_UE CONFIG_LIB -Wl,--end-group @@ -2216,7 +2213,6 @@ target_link_libraries(polartest PRIVATE add_executable(smallblocktest ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/smallblocktest.c - ${OPENAIR_DIR}/common/utils/nr/nr_common.c ) target_link_libraries(smallblocktest PRIVATE @@ -2242,7 +2238,6 @@ target_link_libraries(ldpctest PRIVATE add_executable(nr_dlschsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/dlschsim.c ${OPENAIR1_DIR}/SIMULATION/NR_PHY/nr_dummy_functions.c - ${OPENAIR_DIR}/common/utils/nr/nr_common.c ) target_link_libraries(nr_dlschsim PRIVATE -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB CONFIG_LIB MAC_NR_COMMON -Wl,--end-group @@ -2253,7 +2248,6 @@ target_link_libraries(nr_dlschsim PRIVATE asn1_nr_rrc_hdrs) add_executable(nr_pbchsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/pbchsim.c ${OPENAIR1_DIR}/SIMULATION/NR_PHY/nr_dummy_functions.c - ${OPENAIR_DIR}/common/utils/nr/nr_common.c ) target_link_libraries(nr_pbchsim PRIVATE -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB CONFIG_LIB MAC_NR_COMMON -Wl,--end-group @@ -2264,7 +2258,6 @@ target_link_libraries(nr_pbchsim PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) add_executable(nr_psbchsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/psbchsim.c ${OPENAIR1_DIR}/SIMULATION/NR_PHY/nr_dummy_functions.c - ${OPENAIR_DIR}/common/utils/nr/nr_common.c ${OPENAIR_DIR}/executables/softmodem-common.c ${OPENAIR2_DIR}/RRC/NAS/nas_config.c ${NR_UE_RRC_DIR}/rrc_nsa.c @@ -2282,7 +2275,6 @@ target_link_libraries(nr_psbchsim PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) add_executable(nr_pucchsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/pucchsim.c ${OPENAIR1_DIR}/SIMULATION/NR_PHY/nr_dummy_functions.c - ${OPENAIR_DIR}/common/utils/nr/nr_common.c ) target_link_libraries(nr_pucchsim PRIVATE -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB CONFIG_LIB MAC_NR_COMMON -Wl,--end-group @@ -2293,7 +2285,6 @@ target_link_libraries(nr_pucchsim PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) add_executable(nr_dlsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/dlsim.c ${OPENAIR1_DIR}/SIMULATION/NR_PHY/nr_dummy_functions.c - ${OPENAIR_DIR}/common/utils/nr/nr_common.c ${OPENAIR_DIR}/executables/softmodem-common.c ${OPENAIR2_DIR}/RRC/NAS/nas_config.c ${NR_UE_RRC_DIR}/rrc_nsa.c @@ -2310,7 +2301,6 @@ target_link_libraries(nr_dlsim PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) add_executable(nr_prachsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/prachsim.c ${OPENAIR1_DIR}/SIMULATION/NR_PHY/nr_dummy_functions.c - ${OPENAIR_DIR}/common/utils/nr/nr_common.c ) target_link_libraries(nr_prachsim PRIVATE -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR_COMMON PHY_NR PHY_RU PHY_NR_UE MAC_NR_COMMON SCHED_NR_LIB CONFIG_LIB -lz -Wl,--end-group @@ -2320,7 +2310,6 @@ target_link_libraries(nr_prachsim PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) add_executable(nr_ulschsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/ulschsim.c ${OPENAIR1_DIR}/SIMULATION/NR_PHY/nr_dummy_functions.c - ${OPENAIR_DIR}/common/utils/nr/nr_common.c ${PHY_INTERFACE_DIR}/queue_t.c ) target_link_libraries(nr_ulschsim PRIVATE @@ -2332,7 +2321,6 @@ target_link_libraries(nr_ulschsim PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) add_executable(nr_ulsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/ulsim.c ${OPENAIR1_DIR}/SIMULATION/NR_PHY/nr_dummy_functions.c - ${OPENAIR_DIR}/common/utils/nr/nr_common.c ${OPENAIR_DIR}/executables/softmodem-common.c ${OPENAIR2_DIR}/RRC/NAS/nas_config.c ${NR_UE_RRC_DIR}/rrc_nsa.c @@ -2410,7 +2398,7 @@ if (${T_TRACER}) PHY_COMMON PHY PHY_UE PHY_NR PHY_NR_COMMON PHY_NR_UE PHY_RU PHY_MEX L2 L2_LTE L2_NR L2_LTE_NR L2_UE NR_L2_UE L2_UE_LTE_NR MAC_NR_COMMON MAC_UE_NR ngap CN_UTILS GTPV1U SCTP_CLIENT MME_APP LIB_NAS_UE NB_IoT SIMU SIMU_ETH OPENAIR0_LIB - ldpc_orig ldpc_optim ldpc_optim8seg ldpc_t2 ldpc_cl ldpc_cuda ldpc dfts config_internals) + ldpc_orig ldpc_optim ldpc_optim8seg ldpc_t2 ldpc_cl ldpc_cuda ldpc dfts config_internals nr_common) if (TARGET ${i}) add_dependencies(${i} generate_T) endif() @@ -2507,6 +2495,21 @@ if(ENABLE_TESTS) # meta-target: each test is supposed to add_dependencies(tests ${NEWTEST}) # then, it is possible to build and execute all tests using "ninja tests && ctest" add_custom_target(tests) + find_package(GTest) + if (NOT GTest_FOUND) + message(STATUS "GTest package not found, will download googletest automatically. To prevent that install google test on your system (libgtest-dev)") + include(FetchContent) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG 58d77fa8070e8cec2dc1ed015d66b454c8d78850 # 1.12.1 + ) + set(BUILD_GMOCK OFF) + set(INSTALL_GTEST OFF) + FetchContent_MakeAvailable(googletest) + add_library(GTest::gtest ALIAS gtest) + add_library(GTest::gtest_main ALIAS gtest_main) + endif() endif() add_subdirectory(common) diff --git a/ci-scripts/cls_containerize.py b/ci-scripts/cls_containerize.py index db34e38feb..5d353f2b77 100644 --- a/ci-scripts/cls_containerize.py +++ b/ci-scripts/cls_containerize.py @@ -680,6 +680,8 @@ class Containerize(): dockerfile = "ci-scripts/docker/Dockerfile.unittest.ubuntu20" ret = cmd.run(f'docker build --progress=plain --tag ran-unittests:{baseTag} --file {dockerfile} . &> {lSourcePath}/cmake_targets/log/unittest-build.log') if ret.returncode != 0: + build_log_name = f'build_log_{self.testCase_id}' + CopyLogsToExecutor(cmd, lSourcePath, build_log_name) logging.error(f'Cannot build unit tests') HTML.CreateHtmlTestRow("Unit test build failed", 'KO', [dockerfile]) HTML.CreateHtmlTabFooter(False) diff --git a/ci-scripts/docker/Dockerfile.unittest.ubuntu20 b/ci-scripts/docker/Dockerfile.unittest.ubuntu20 index 7e47988719..57bc7f3bef 100644 --- a/ci-scripts/docker/Dockerfile.unittest.ubuntu20 +++ b/ci-scripts/docker/Dockerfile.unittest.ubuntu20 @@ -27,6 +27,11 @@ FROM ran-base:develop as ran-tests +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get upgrade --yes && \ + DEBIAN_FRONTEND=noninteractive apt-get install --yes \ + libgtest-dev + RUN rm -Rf /oai-ran WORKDIR /oai-ran COPY . . diff --git a/common/utils/CMakeLists.txt b/common/utils/CMakeLists.txt index 094ca6b10d..c945f644bc 100644 --- a/common/utils/CMakeLists.txt +++ b/common/utils/CMakeLists.txt @@ -10,3 +10,4 @@ if(ENABLE_WEBSRV) endif() add_subdirectory(T) +add_subdirectory(nr) diff --git a/common/utils/nr/CMakeLists.txt b/common/utils/nr/CMakeLists.txt new file mode 100644 index 0000000000..6b58544a6d --- /dev/null +++ b/common/utils/nr/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(nr_common nr_common.c) +target_include_directories(nr_common PUBLIC .) +if (ENABLE_TESTS) + add_subdirectory(tests) +endif() diff --git a/common/utils/nr/nr_common.c b/common/utils/nr/nr_common.c index 977b5051f8..dd24660c44 100644 --- a/common/utils/nr/nr_common.c +++ b/common/utils/nr/nr_common.c @@ -1176,38 +1176,6 @@ void init_delay_table(uint16_t ofdm_symbol_size, } } -void freq2time(uint16_t ofdm_symbol_size, - int16_t *freq_signal, - int16_t *time_signal) -{ - const idft_size_idx_t idft_size = get_idft(ofdm_symbol_size); - idft(idft_size, freq_signal, time_signal, 1); -} - -void nr_est_delay(int ofdm_symbol_size, const c16_t *ls_est, c16_t *ch_estimates_time, delay_t *delay) -{ - freq2time(ofdm_symbol_size, (int16_t *)ls_est, (int16_t *)ch_estimates_time); - - int max_pos = delay->delay_max_pos; - int max_val = delay->delay_max_val; - const int sync_pos = 0; - - for (int i = 0; i < ofdm_symbol_size; i++) { - int temp = c16amp2(ch_estimates_time[i]) >> 1; - if (temp > max_val) { - max_pos = i; - max_val = temp; - } - } - - if (max_pos > ofdm_symbol_size / 2) - max_pos = max_pos - ofdm_symbol_size; - - delay->delay_max_pos = max_pos; - delay->delay_max_val = max_val; - delay->est_delay = max_pos - sync_pos; -} - void nr_timer_start(NR_timer_t *timer) { timer->active = true; diff --git a/common/utils/nr/nr_common.h b/common/utils/nr/nr_common.h index d044130412..6ed86cb7bd 100644 --- a/common/utils/nr/nr_common.h +++ b/common/utils/nr/nr_common.h @@ -241,12 +241,6 @@ uint32_t get_ssb_offset_to_pointA(uint32_t absoluteFrequencySSB, int get_ssb_subcarrier_offset(uint32_t absoluteFrequencySSB, uint32_t absoluteFrequencyPointA, int scs); int get_delay_idx(int delay, int max_delay_comp); -void freq2time(uint16_t ofdm_symbol_size, - int16_t *freq_signal, - int16_t *time_signal); - -void nr_est_delay(int ofdm_symbol_size, const c16_t *ls_est, c16_t *ch_estimates_time, delay_t *delay); - int get_scan_ssb_first_sc(const double fc, const int nbRB, const int nrBand, diff --git a/common/utils/nr/tests/CMakeLists.txt b/common/utils/nr/tests/CMakeLists.txt new file mode 100644 index 0000000000..fb995d2ab8 --- /dev/null +++ b/common/utils/nr/tests/CMakeLists.txt @@ -0,0 +1,5 @@ +add_executable(test_nr_common test_nr_common.cpp) +target_link_libraries(test_nr_common PRIVATE nr_common GTest::gtest minimal_lib) +add_dependencies(tests test_nr_common) +add_test(NAME test_nr_common + COMMAND ./test_nr_common) diff --git a/common/utils/nr/tests/test_nr_common.cpp b/common/utils/nr/tests/test_nr_common.cpp new file mode 100644 index 0000000000..fede91b8ee --- /dev/null +++ b/common/utils/nr/tests/test_nr_common.cpp @@ -0,0 +1,47 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#include +extern "C" { +#include "nr_common.h" +#include "common/utils/LOG/log.h" +} + +TEST(nr_common, nr_timer) { + NR_timer_t timer; + nr_timer_setup(&timer, 10, 1); + nr_timer_start(&timer); + EXPECT_TRUE(is_nr_timer_active(timer)); + EXPECT_FALSE(nr_timer_expired(timer)); + for (auto i = 0; i < 10; i++) { + nr_timer_tick(&timer); + } + EXPECT_FALSE(is_nr_timer_active(timer)); + EXPECT_TRUE(nr_timer_expired(timer)); +} + + +int main(int argc, char **argv) +{ + logInit(); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/doc/UnitTests.md b/doc/UnitTests.md index 6ea18e2280..d1bbbed0ae 100644 --- a/doc/UnitTests.md +++ b/doc/UnitTests.md @@ -8,8 +8,9 @@ explaining how to test with cmake and ctest; it is a suggested read, and the following just lists the main points of how to compile the tests and how to add new ones. -At the time of writing, only the NR RLC tests have been integrated. The author -hopes that more tests follow suit. +GoogleTest is a C++ unit testing framework that has been added as an external dependency. While using GoogleTest is not a requirement it can simplify writing unit tests. +See [primer](http://google.github.io/googletest/primer.html) for a quick introduction. To add it to your test executable link against +`GTest::gtest` or `GTest::gtest_main`. # How to compile tests diff --git a/openair1/PHY/CMakeLists.txt b/openair1/PHY/CMakeLists.txt index 0a53c969a7..6f364e4daf 100644 --- a/openair1/PHY/CMakeLists.txt +++ b/openair1/PHY/CMakeLists.txt @@ -4,3 +4,4 @@ add_boolean_option(ENABLE_NRSCOPE OFF "Whether to build the 5G scope" OFF) if(ENABLE_UESCOPE OR ENABLE_ENBSCOPE OR ENABLE_NRSCOPE) add_subdirectory(TOOLS) endif() +add_subdirectory(nr_phy_common) diff --git a/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c b/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c index a7f0ef6682..5f49549d21 100644 --- a/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c +++ b/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c @@ -33,6 +33,7 @@ #include "PHY/NR_REFSIG/ul_ref_seq_nr.h" #include "executables/softmodem-common.h" +#include "nr_phy_common.h" //#define DEBUG_CH diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c index 4245d3a7bf..0c3847baaf 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c @@ -29,12 +29,13 @@ #include "PHY/NR_REFSIG/nr_mod_table.h" #include "PHY/NR_TRANSPORT/nr_sch_dmrs.h" #include "PHY/NR_TRANSPORT/nr_transport_proto.h" -#include "common/utils/nr/nr_common.h" +#include "nr_phy_common.h" #include "filt16a_32.h" #include "T.h" #include #include "nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h" + extern openair0_config_t openair0_cfg[]; // #define DEBUG_PDSCH diff --git a/openair1/PHY/nr_phy_common/CMakeLists.txt b/openair1/PHY/nr_phy_common/CMakeLists.txt new file mode 100644 index 0000000000..79dc8dd7f3 --- /dev/null +++ b/openair1/PHY/nr_phy_common/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(nr_phy_common src/nr_phy_common.c) +target_include_directories(nr_phy_common PUBLIC inc/) diff --git a/openair1/PHY/nr_phy_common/inc/nr_phy_common.h b/openair1/PHY/nr_phy_common/inc/nr_phy_common.h new file mode 100644 index 0000000000..8e8f7399f0 --- /dev/null +++ b/openair1/PHY/nr_phy_common/inc/nr_phy_common.h @@ -0,0 +1,30 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#ifndef __NR_PHY_COMMON__H__ +#define __NR_PHY_COMMON__H__ +#include "PHY/impl_defs_top.h" +#include "PHY/TOOLS/tools_defs.h" + +void freq2time(uint16_t ofdm_symbol_size, int16_t *freq_signal, int16_t *time_signal); +void nr_est_delay(int ofdm_symbol_size, const c16_t *ls_est, c16_t *ch_estimates_time, delay_t *delay); +unsigned int nr_get_tx_amp(int power_dBm, int power_max_dBm, int total_nb_rb, int nb_rb); +#endif diff --git a/openair1/PHY/nr_phy_common/src/nr_phy_common.c b/openair1/PHY/nr_phy_common/src/nr_phy_common.c new file mode 100644 index 0000000000..b67a94d8f6 --- /dev/null +++ b/openair1/PHY/nr_phy_common/src/nr_phy_common.c @@ -0,0 +1,69 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#include "nr_phy_common.h" + +void freq2time(uint16_t ofdm_symbol_size, int16_t *freq_signal, int16_t *time_signal) +{ + const idft_size_idx_t idft_size = get_idft(ofdm_symbol_size); + idft(idft_size, freq_signal, time_signal, 1); +} + +void nr_est_delay(int ofdm_symbol_size, const c16_t *ls_est, c16_t *ch_estimates_time, delay_t *delay) +{ + freq2time(ofdm_symbol_size, (int16_t *)ls_est, (int16_t *)ch_estimates_time); + + int max_pos = delay->delay_max_pos; + int max_val = delay->delay_max_val; + const int sync_pos = 0; + + for (int i = 0; i < ofdm_symbol_size; i++) { + int temp = c16amp2(ch_estimates_time[i]) >> 1; + if (temp > max_val) { + max_pos = i; + max_val = temp; + } + } + + if (max_pos > ofdm_symbol_size / 2) + max_pos = max_pos - ofdm_symbol_size; + + delay->delay_max_pos = max_pos; + delay->delay_max_val = max_val; + delay->est_delay = max_pos - sync_pos; +} + +unsigned int nr_get_tx_amp(int power_dBm, int power_max_dBm, int total_nb_rb, int nb_rb) +{ + // assume power at AMP is 20dBm + // if gain = 20 (power == 40) + int gain_dB = power_dBm - power_max_dBm; + double gain_lin; + + gain_lin = pow(10, .1 * gain_dB); + if ((nb_rb > 0) && (nb_rb <= total_nb_rb)) { + return ((int)(AMP * sqrt(gain_lin * total_nb_rb / (double)nb_rb))); + } else { + LOG_E(PHY, "Illegal nb_rb/N_RB_UL combination (%d/%d)\n", nb_rb, total_nb_rb); + // mac_xface->macphy_exit(""); + } + return (0); +} diff --git a/openair1/SCHED_NR_UE/defs.h b/openair1/SCHED_NR_UE/defs.h index bdb3341387..1488a9433a 100644 --- a/openair1/SCHED_NR_UE/defs.h +++ b/openair1/SCHED_NR_UE/defs.h @@ -111,8 +111,6 @@ int8_t nr_find_ue(uint16_t rnti, PHY_VARS_eNB *phy_vars_eNB); */ void ue_ta_procedures(PHY_VARS_NR_UE *ue, int slot_tx, int frame_tx); -unsigned int nr_get_tx_amp(int power_dBm, int power_max_dBm, int N_RB_UL, int nb_rb); - void set_tx_harq_id(NR_UE_ULSCH_t *ulsch, int harq_pid, int slot_tx); int get_tx_harq_id(NR_UE_ULSCH_t *ulsch, int slot_tx); diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index cbeda2e106..603120abdc 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -407,23 +407,6 @@ static int nr_ue_pbch_procedures(PHY_VARS_NR_UE *ue, return ret; } -unsigned int nr_get_tx_amp(int power_dBm, int power_max_dBm, int N_RB_UL, int nb_rb) -{ - - int gain_dB = power_dBm - power_max_dBm; - double gain_lin; - - gain_lin = pow(10,.1*gain_dB); - if ((nb_rb >0) && (nb_rb <= N_RB_UL)) { - return((int)(AMP*sqrt(gain_lin*N_RB_UL/(double)nb_rb))); - } - else { - LOG_E(PHY,"Illegal nb_rb/N_RB_UL combination (%d/%d)\n",nb_rb,N_RB_UL); - //mac_xface->macphy_exit(""); - } - return(0); -} - int nr_ue_pdcch_procedures(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, int32_t pdcch_est_size, diff --git a/openair2/LAYER2/CMakeLists.txt b/openair2/LAYER2/CMakeLists.txt index b8bc21e78c..9360ed7b2b 100644 --- a/openair2/LAYER2/CMakeLists.txt +++ b/openair2/LAYER2/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(nr_rlc) +add_subdirectory(NR_MAC_UE) diff --git a/openair2/LAYER2/NR_MAC_UE/CMakeLists.txt b/openair2/LAYER2/NR_MAC_UE/CMakeLists.txt new file mode 100644 index 0000000000..6589a2fda5 --- /dev/null +++ b/openair2/LAYER2/NR_MAC_UE/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(nr_ue_power_procedures nr_ue_power_procedures.c) +target_link_libraries(nr_ue_power_procedures PUBLIC asn1_nr_rrc ${T_LIB} MAC_NR_COMMON nr_common) +if (ENABLE_TESTS) + add_subdirectory(tests) +endif() diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index a6a60fbd7f..01f49f8319 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -227,7 +227,16 @@ int nr_ue_configure_pucch(NR_UE_MAC_INST_t *mac, PUCCH_sched_t *pucch, fapi_nr_ul_config_pucch_pdu *pucch_pdu); -int nr_get_Pcmax(NR_UE_MAC_INST_t *mac, int Qm, bool powerBoostPi2BPSK, int scs, int N_RB_UL, bool is_transform_precoding, int n_prbs, int start_prb); +int nr_get_Pcmax(int p_Max, + uint16_t nr_band, + frequency_range_t frequency_range, + int Qm, + bool powerBoostPi2BPSK, + int scs, + int N_RB_UL, + bool is_transform_precoding, + int n_prbs, + int start_prb); int get_sum_delta_pucch(NR_UE_MAC_INST_t *mac, int slot, frame_t frame); diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c index 5831bd2b11..1fc6f4b6e8 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c @@ -79,7 +79,16 @@ void init_RA(NR_UE_MAC_INST_t *mac, int n_prbs = get_N_RA_RB(prach_scs, mac->current_UL_BWP->scs); int start_prb = rach_ConfigGeneric->msg1_FrequencyStart + mac->current_UL_BWP->BWPStart; // PRACH shall be as specified for QPSK modulated DFT-s-OFDM of equivalent RB allocation (38.101-1) - prach_resources->RA_PCMAX = nr_get_Pcmax(mac, 2, false, prach_scs, cfg->carrier_config.dl_grid_size[prach_scs], true, n_prbs, start_prb); + prach_resources->RA_PCMAX = nr_get_Pcmax(mac->p_Max, + mac->nr_band, + mac->frequency_range, + 2, + false, + prach_scs, + cfg->carrier_config.dl_grid_size[prach_scs], + true, + n_prbs, + start_prb); prach_resources->RA_PREAMBLE_TRANSMISSION_COUNTER = 1; prach_resources->RA_PREAMBLE_POWER_RAMPING_COUNTER = 1; prach_resources->POWER_OFFSET_2STEP_RA = 0; diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_power_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_power_procedures.c index 3e9669775d..e826d95e4c 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_power_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_power_procedures.c @@ -85,16 +85,24 @@ static int get_deltatf(uint16_t nb_of_prbs, // -- Powerclass 3 capable UE (which is default power class unless otherwise stated) // -- Maximum power reduction (MPR_c) for power class 3 // -- no additional MPR (A_MPR_c) -int nr_get_Pcmax(NR_UE_MAC_INST_t *mac, int Qm, bool powerBoostPi2BPSK, int scs, int N_RB_UL, bool is_transform_precoding, int n_prbs, int start_prb) +int nr_get_Pcmax(int p_Max, + uint16_t nr_band, + frequency_range_t frequency_range, + int Qm, + bool powerBoostPi2BPSK, + int scs, + int N_RB_UL, + bool is_transform_precoding, + int n_prbs, + int start_prb) { - int nr_band = mac->nr_band; - if(mac->frequency_range == FR1) { - - //TODO configure P-MAX from the upper layers according to 38.331 + if (frequency_range == FR1) { + // TODO configure P-MAX from the upper layers according to 38.331 int p_powerclass = 23; // dBm assuming poweclass 3 UE - int p_emax = mac->p_Max != INT_MIN ? mac->p_Max : p_powerclass; + int p_emax = p_Max != INT_MIN ? p_Max : p_powerclass; int delta_P_powerclass = 0; // for powerclass 2 needs to be changed - if(mac->p_Max && Qm == 1 && powerBoostPi2BPSK && (nr_band == 40 || nr_band == 41 || nr_band == 77 || nr_band == 78 || nr_band == 79)) { + if (p_Max && Qm == 1 && powerBoostPi2BPSK + && (nr_band == 40 || nr_band == 41 || nr_band == 77 || nr_band == 78 || nr_band == 79)) { p_emax += 3; delta_P_powerclass -= 3; } @@ -103,54 +111,52 @@ int nr_get_Pcmax(NR_UE_MAC_INST_t *mac, int Qm, bool powerBoostPi2BPSK, int scs, int delta_T_IB = 0; // TODO in case of band 41 and PRB allocation within 4MHz of the upper or lower limit of the band -> delta_TC = 1.5 - if(nr_band == 41) + if (nr_band == 41) LOG_E(NR_MAC, "Need to implement delta_TC for band 41\n"); int delta_TC = 0; float MPR = 0; frame_type_t frame_type = get_frame_type(nr_band, scs); - if(compare_relative_ul_channel_bw(nr_band, scs, N_RB_UL, frame_type)) { + if (compare_relative_ul_channel_bw(nr_band, scs, N_RB_UL, frame_type)) { int rb_low = (n_prbs / 2) > 1 ? (n_prbs / 2) : 1; int rb_high = N_RB_UL - rb_low - n_prbs; bool is_inner_rb = start_prb >= rb_low && start_prb <= rb_high && n_prbs <= ((N_RB_UL / 2) + (N_RB_UL & 1)); // Table 6.2.2-1 in 38.101 switch (Qm) { - case 1 : + case 1: AssertFatal(false, "MPR for Pi/2 BPSK not implemented yet\n"); break; - case 2 : + case 2: if (is_transform_precoding) { - if(!is_inner_rb) + if (!is_inner_rb) MPR = 1; - } - else { - if(is_inner_rb) + } else { + if (is_inner_rb) MPR = 1.5; else MPR = 3; } break; - case 4 : + case 4: if (is_transform_precoding) { - if(is_inner_rb) + if (is_inner_rb) MPR = 1; else MPR = 2; - } - else { - if(is_inner_rb) + } else { + if (is_inner_rb) MPR = 2; else MPR = 3; } break; - case 6 : + case 6: if (is_transform_precoding) MPR = 2.5; else MPR = 3.5; break; - case 8 : + case 8: if (is_transform_precoding) MPR = 4.5; else @@ -170,12 +176,12 @@ int nr_get_Pcmax(NR_UE_MAC_INST_t *mac, int Qm, bool powerBoostPi2BPSK, int scs, if (P_MPR > total_reduction) total_reduction = P_MPR; int pcmax_high, pcmax_low; - if(mac->p_Max) { + if (p_Max) { pcmax_high = p_emax < (p_powerclass - delta_P_powerclass) ? p_emax : (p_powerclass - delta_P_powerclass); - pcmax_low = (p_emax - delta_TC) < (p_powerclass - delta_P_powerclass - total_reduction) ? - (p_emax - delta_TC) : (p_powerclass - delta_P_powerclass - total_reduction); - } - else { + pcmax_low = (p_emax - delta_TC) < (p_powerclass - delta_P_powerclass - total_reduction) + ? (p_emax - delta_TC) + : (p_powerclass - delta_P_powerclass - total_reduction); + } else { pcmax_high = p_powerclass - delta_P_powerclass; pcmax_low = p_powerclass - delta_P_powerclass - total_reduction; } @@ -183,8 +189,7 @@ int nr_get_Pcmax(NR_UE_MAC_INST_t *mac, int Qm, bool powerBoostPi2BPSK, int scs, int pcmax = (pcmax_low + pcmax_high) / 2; LOG_D(MAC, "Configured maximum output power: %d dBm <= PCMAX %d dBm <= %d dBm \n", pcmax_low, pcmax, pcmax_high); return pcmax; - } - else { + } else { // FR2 TODO it is even more complex because it is radiated power return 23; } @@ -294,7 +299,16 @@ int16_t get_pucch_tx_power_ue(NR_UE_MAC_INST_t *mac, // PUCCH shall be as specified for QPSK modulated DFT-s-OFDM of equivalent RB allocation (38.101-1) // TODO: P_CMAX for format 2 - int P_CMAX = nr_get_Pcmax(mac, 2, false, mac->current_UL_BWP->scs, mac->current_UL_BWP->BWPSize, true, 1, start_prb); + int P_CMAX = nr_get_Pcmax(mac->p_Max, + mac->nr_band, + mac->frequency_range, + 2, + false, + mac->current_UL_BWP->scs, + mac->current_UL_BWP->BWPSize, + true, + 1, + start_prb); int P_CMIN = -40; // TODO: minimum TX power, possibly 38.101-1 6.3.1 int16_t pathloss = compute_nr_SSB_PL(mac, mac->ssb_measurements.ssb_rsrp_dBm); @@ -358,3 +372,27 @@ static int get_deltatf(uint16_t nb_of_prbs, } return DELTA_TF; } + +// Returns the pathloss in dB for the active UL BWP on the selected carrier based on the DL RS associated with the PRACH transmission +// computation according to clause 7.4 (Physical random access channel) of 3GPP TS 38.213 version 16.3.0 Release 16 +// Assumptions: +// - PRACH transmission from a UE is not in response to a detection of a PDCCH order by the UE +// Measurement units: +// - referenceSignalPower: dBm/RE (average EPRE of the resources elements that carry secondary synchronization signals in dBm) +int16_t compute_nr_SSB_PL(NR_UE_MAC_INST_t *mac, short ssb_rsrp_dBm) +{ + fapi_nr_config_request_t *cfg = &mac->phy_config.config_req; + int referenceSignalPower = cfg->ssb_config.ss_pbch_power; + //TODO improve PL measurements. Probably not correct as it is. + + int16_t pathloss = (int16_t)(referenceSignalPower - ssb_rsrp_dBm); + + LOG_D(NR_MAC, "pathloss %d dB, referenceSignalPower %d dBm/RE (%f mW), RSRP %d dBm (%f mW)\n", + pathloss, + referenceSignalPower, + pow(10, referenceSignalPower/10), + ssb_rsrp_dBm, + pow(10, ssb_rsrp_dBm/10)); + + return pathloss; +} diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 80bf75e844..68f969fcdc 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -3945,26 +3945,3 @@ static void nr_ue_process_rar(NR_UE_MAC_INST_t *mac, nr_downlink_indication_t *d return; } -// Returns the pathloss in dB for the active UL BWP on the selected carrier based on the DL RS associated with the PRACH transmission -// computation according to clause 7.4 (Physical random access channel) of 3GPP TS 38.213 version 16.3.0 Release 16 -// Assumptions: -// - PRACH transmission from a UE is not in response to a detection of a PDCCH order by the UE -// Measurement units: -// - referenceSignalPower: dBm/RE (average EPRE of the resources elements that carry secondary synchronization signals in dBm) -int16_t compute_nr_SSB_PL(NR_UE_MAC_INST_t *mac, short ssb_rsrp_dBm) -{ - fapi_nr_config_request_t *cfg = &mac->phy_config.config_req; - int referenceSignalPower = cfg->ssb_config.ss_pbch_power; - //TODO improve PL measurements. Probably not correct as it is. - - int16_t pathloss = (int16_t)(referenceSignalPower - ssb_rsrp_dBm); - - LOG_D(NR_MAC, "pathloss %d dB, referenceSignalPower %d dBm/RE (%f mW), RSRP %d dBm (%f mW)\n", - pathloss, - referenceSignalPower, - pow(10, referenceSignalPower/10), - ssb_rsrp_dBm, - pow(10, ssb_rsrp_dBm/10)); - - return pathloss; -} diff --git a/openair2/LAYER2/NR_MAC_UE/tests/CMakeLists.txt b/openair2/LAYER2/NR_MAC_UE/tests/CMakeLists.txt new file mode 100644 index 0000000000..40c8c5372b --- /dev/null +++ b/openair2/LAYER2/NR_MAC_UE/tests/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(test_nr_ue_power_procedures + test_nr_ue_power_procedures.cpp) +target_link_libraries(test_nr_ue_power_procedures PRIVATE nr_ue_power_procedures GTest::gtest minimal_lib) +add_dependencies(tests test_nr_ue_power_procedures) +add_test(NAME test_nr_ue_power_procedures + COMMAND ./test_nr_ue_power_procedures) diff --git a/openair2/LAYER2/NR_MAC_UE/tests/test_nr_ue_power_procedures.cpp b/openair2/LAYER2/NR_MAC_UE/tests/test_nr_ue_power_procedures.cpp new file mode 100644 index 0000000000..179d94bd1b --- /dev/null +++ b/openair2/LAYER2/NR_MAC_UE/tests/test_nr_ue_power_procedures.cpp @@ -0,0 +1,64 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + + +#include "gtest/gtest.h" +extern "C" { +#include "openair2/LAYER2/NR_MAC_UE/mac_proto.h" +#include "executables/softmodem-common.h" +uint64_t get_softmodem_optmask(void) {return 0;} +static softmodem_params_t softmodem_params; +softmodem_params_t *get_softmodem_params(void) { + return &softmodem_params; + +} +} +#include +#include "common/utils/LOG/log.h" + +TEST(power_procedures_fr1, test_prach_max_tx_power_mpr) +{ + // Inner PRB, MPR = 1.5 + int prb_start = 4; + int N_RB_UL = 51; // 10Mhz + EXPECT_EQ(22, nr_get_Pcmax(23, 20, FR1, 2, false, 1, N_RB_UL, false, 6, prb_start)); + + // Outer PRB, MPR = 3 + prb_start = 0; + EXPECT_EQ(21, nr_get_Pcmax(23, 20, FR1, 2, false, 1, N_RB_UL, false, 6, prb_start)); + + // Channel bandwidth conditon not met, no MPR + N_RB_UL = 106; + EXPECT_EQ(23, nr_get_Pcmax(23, 20, FR1, 2, false, 1, N_RB_UL, false, 6, prb_start)); +} + +TEST(power_procedures_fr1, test_not_implemented) +{ + int N_RB_UL = 51; + EXPECT_DEATH(nr_get_Pcmax(23, 20, FR1, 1, false, 1, N_RB_UL, false, 6, 0), "MPR for Pi/2 BPSK not implemented yet"); +} + +int main(int argc, char** argv) +{ + logInit(); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}