srsLTE/test/phy/nr_phy_test.cc

192 lines
8.1 KiB
C++
Raw Normal View History

2021-06-20 22:59:57 -07:00
/**
*
* \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.
*
*/
2021-06-23 03:59:32 -07:00
#include "dummy_gnb_stack.h"
2021-07-06 06:26:00 -07:00
#include "dummy_ue_stack.h"
2021-06-30 08:12:17 -07:00
#include "srsran/common/phy_cfg_nr_default.h"
2021-06-20 22:59:57 -07:00
#include "srsran/common/test_common.h"
#include "test_bench.h"
2021-07-06 09:26:33 -07:00
#include <boost/program_options.hpp>
#include <iostream>
// shorten boost program options namespace
namespace bpo = boost::program_options;
2021-06-20 22:59:57 -07:00
test_bench::args_t::args_t(int argc, char** argv)
{
2021-07-06 09:26:33 -07:00
bpo::options_description options("Test bench options");
bpo::options_description options_gnb_stack("gNb stack and scheduling related options");
bpo::options_description options_gnb_phy("gNb PHY related options");
bpo::options_description options_ue_stack("UE stack options");
bpo::options_description options_ue_phy("UE stack options");
uint16_t rnti = 0x1234;
2021-07-07 01:24:34 -07:00
gnb_stack.pdsch.slots = "0,1,2,3,4,5";
gnb_stack.pusch.slots = "6,7,8,9";
2021-07-06 09:26:33 -07:00
// clang-format off
options.add_options()
("rnti", bpo::value<uint16_t>(&rnti)->default_value(rnti), "UE RNTI")
("duration", bpo::value<uint64_t>(&durations_slots)->default_value(durations_slots), "Test duration in slots")
;
options_gnb_stack.add_options()
("gnb.stack.pdcch.aggregation_level", bpo::value<uint32_t>(&gnb_stack.pdcch_aggregation_level)->default_value(gnb_stack.pdcch_aggregation_level), "PDCCH aggregation level")
("gnb.stack.pdsch.candidate", bpo::value<uint32_t>(&gnb_stack.pdcch_dl_candidate)->default_value(gnb_stack.pdcch_dl_candidate), "PDCCH candidate index for PDSCH")
2021-07-07 01:24:34 -07:00
("gnb.stack.pdsch.start", bpo::value<uint32_t>(&gnb_stack.pdsch.rb_start)->default_value(0), "PDSCH scheduling frequency allocation start")
("gnb.stack.pdsch.length", bpo::value<uint32_t>(&gnb_stack.pdsch.rb_length)->default_value(gnb_stack.pdsch.rb_length), "PDSCH scheduling frequency allocation length")
("gnb.stack.pdsch.slots", bpo::value<std::string>(&gnb_stack.pdsch.slots)->default_value(gnb_stack.pdsch.slots), "Slots enabled for PDSCH")
("gnb.stack.pdsch.mcs", bpo::value<uint32_t>(&gnb_stack.pdsch.mcs)->default_value(gnb_stack.pdsch.mcs), "PDSCH/PUSCH scheduling modulation code scheme")
2021-07-06 09:26:33 -07:00
("gnb.stack.pusch.candidate", bpo::value<uint32_t>(&gnb_stack.pdcch_ul_candidate)->default_value(gnb_stack.pdcch_ul_candidate), "PDCCH candidate index for PUSCH")
2021-07-07 01:24:34 -07:00
("gnb.stack.pusch.start", bpo::value<uint32_t>(&gnb_stack.pusch.rb_start)->default_value(0), "PUSCH scheduling frequency allocation start")
("gnb.stack.pusch.length", bpo::value<uint32_t>(&gnb_stack.pusch.rb_length)->default_value(gnb_stack.pusch.rb_length), "PUSCH scheduling frequency allocation length")
("gnb.stack.pusch.slots", bpo::value<std::string>(&gnb_stack.pusch.slots)->default_value(gnb_stack.pusch.slots), "Slots enabled for PUSCH")
2021-07-06 09:26:33 -07:00
("gnb.stack.log_level", bpo::value<std::string>(&gnb_stack.log_level)->default_value(gnb_stack.log_level), "Stack log level")
;
options_gnb_phy.add_options()
("gnb.phy.nof_threads", bpo::value<uint32_t>(&gnb_phy.nof_phy_threads)->default_value(1), "Number of threads")
("gnb.phy.log.level", bpo::value<std::string>(&gnb_phy.log.phy_level)->default_value("warning"), "gNb PHY log level")
("gnb.phy.log.hex_limit", bpo::value<int>(&gnb_phy.log.phy_hex_limit)->default_value(0), "gNb PHY log hex limit")
("gnb.phy.log.id_preamble", bpo::value<std::string>(&gnb_phy.log.id_preamble)->default_value("GNB/"), "gNb PHY log ID preamble")
("gnb.phy.pusch.max_iter", bpo::value<uint32_t>(&gnb_phy.pusch_max_nof_iter)->default_value(10), "PUSCH LDPC max number of iterations")
;
options_ue_phy.add_options()
("ue.phy.nof_threads", bpo::value<uint32_t>(&ue_phy.nof_phy_threads)->default_value(1), "Number of threads")
("ue.phy.log.level", bpo::value<std::string>(&ue_phy.log.phy_level)->default_value("warning"), "UE PHY log level")
("ue.phy.log.hex_limit", bpo::value<int>(&ue_phy.log.phy_hex_limit)->default_value(0), "UE PHY log hex limit")
("ue.phy.log.id_preamble", bpo::value<std::string>(&ue_phy.log.id_preamble)->default_value(" UE/"), "UE PHY log ID preamble")
;
options.add(options_gnb_stack).add(options_gnb_phy).add(options_ue_stack).add(options_ue_phy).add_options()
("help", "Show this message")
;
// clang-format on
bpo::variables_map vm;
try {
bpo::store(bpo::command_line_parser(argc, argv).options(options).run(), vm);
bpo::notify(vm);
} catch (bpo::error& e) {
std::cerr << e.what() << std::endl;
return;
}
// help option was given or error - print usage and exit
if (vm.count("help")) {
std::cout << "Usage: " << argv[0] << " [OPTIONS] config_file" << std::endl << std::endl;
std::cout << options << std::endl << std::endl;
return;
}
2021-06-20 22:59:57 -07:00
2021-06-30 08:12:17 -07:00
// Load default reference configuration
srsran::phy_cfg_nr_default_t::reference_cfg_t reference_cfg;
phy_cfg = srsran::phy_cfg_nr_default_t(reference_cfg);
2021-06-23 03:59:32 -07:00
cell_list.resize(1);
cell_list[0].carrier = phy_cfg.carrier;
cell_list[0].rf_port = 0;
cell_list[0].cell_id = 0;
cell_list[0].pdcch = phy_cfg.pdcch;
2021-07-06 09:26:33 -07:00
ue_stack.rnti = rnti;
gnb_stack.rnti = rnti;
gnb_stack.phy_cfg = phy_cfg;
2021-07-07 01:24:34 -07:00
if (gnb_stack.pdsch.rb_length == 0) {
gnb_stack.pdsch.rb_length = phy_cfg.carrier.nof_prb;
gnb_stack.pdsch.rb_start = 0;
2021-07-06 09:26:33 -07:00
}
2021-07-07 01:24:34 -07:00
if (gnb_stack.pusch.rb_length == 0) {
gnb_stack.pusch.rb_length = phy_cfg.carrier.nof_prb;
gnb_stack.pdsch.rb_start = 0;
2021-07-06 09:26:33 -07:00
}
// Flag configuration as valid
valid = true;
2021-06-20 22:59:57 -07:00
}
int main(int argc, char** argv)
{
srslog::init();
// Parse test bench arguments
2021-06-20 22:59:57 -07:00
test_bench::args_t args(argc, argv);
// Parse arguments
TESTASSERT(args.valid);
// Create test bench
2021-07-06 09:26:33 -07:00
test_bench tb(args);
2021-06-20 22:59:57 -07:00
// Assert bench is initialised correctly
TESTASSERT(tb.is_initialised());
// Run per TTI basis
2021-07-06 09:26:33 -07:00
while (tb.run_tti()) {
; // Do nothing
2021-06-20 22:59:57 -07:00
}
// Stop test bench
tb.stop();
// Flush log
srslog::flush();
// Retrieve MAC metrics
2021-07-06 09:26:33 -07:00
srsenb::mac_ue_metrics_t mac_metrics = tb.get_gnb_metrics();
// Print metrics
float pdsch_bler = 0.0f;
if (mac_metrics.tx_pkts != 0) {
pdsch_bler = (float)mac_metrics.tx_errors / (float)mac_metrics.tx_pkts;
}
2021-07-06 06:26:00 -07:00
float pusch_bler = 0.0f;
if (mac_metrics.rx_pkts != 0) {
pusch_bler = (float)mac_metrics.rx_errors / (float)mac_metrics.rx_pkts;
}
float pdsch_shed_rate = 0.0f;
if (mac_metrics.tx_pkts != 0) {
2021-07-06 06:26:00 -07:00
pdsch_shed_rate = (float)mac_metrics.tx_brate / (float)mac_metrics.tx_pkts / 1000.0f;
}
float pusch_shed_rate = 0.0f;
if (mac_metrics.rx_pkts != 0) {
pusch_shed_rate = (float)mac_metrics.rx_brate / (float)mac_metrics.rx_pkts / 1000.0f;
}
srsran::console("PDSCH:\n");
2021-07-06 06:26:00 -07:00
srsran::console(" Count: %d\n", mac_metrics.tx_pkts);
srsran::console(" BLER: %f\n", pdsch_bler);
srsran::console(" Sched Rate: %f Mbps\n", pdsch_shed_rate);
srsran::console(" Net Rate: %f Mbps\n", (1.0f - pdsch_bler) * pdsch_shed_rate);
srsran::console(" Retx Rate: %f Mbps\n", pdsch_bler * pdsch_shed_rate);
srsran::console("\n");
srsran::console("PUSCH:\n");
srsran::console(" Count: %d\n", mac_metrics.rx_pkts);
srsran::console(" BLER: %f\n", pusch_bler);
srsran::console(" Sched Rate: %f Mbps\n", pusch_shed_rate);
srsran::console(" Net Rate: %f Mbps\n", (1.0f - pusch_bler) * pusch_shed_rate);
srsran::console(" Retx Rate: %f Mbps\n", pusch_bler * pusch_shed_rate);
// Assert metrics
TESTASSERT(mac_metrics.tx_errors == 0);
2021-07-06 06:26:00 -07:00
TESTASSERT(mac_metrics.rx_errors == 0);
2021-06-20 22:59:57 -07:00
// If reached here, the test is successful
return SRSRAN_SUCCESS;
}