srsLTE/srsue/src/stack/ue_stack_nr.cc

192 lines
4.6 KiB
C++
Raw Normal View History

/**
2020-05-28 09:06:48 -07:00
*
* \section COPYRIGHT
2020-05-28 09:06:48 -07:00
*
* Copyright 2013-2020 Software Radio Systems Limited
2020-05-28 09:06:48 -07:00
*
* 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.
2020-05-28 09:06:48 -07:00
*
*/
#include "srsue/hdr/stack/ue_stack_nr.h"
#include "srslte/srslte.h"
using namespace srslte;
namespace srsue {
ue_stack_nr::ue_stack_nr(srslte::logger* logger_) :
2021-02-01 03:43:41 -08:00
logger(logger_), thread("STACK"), task_sched(64, 2, 64), rlc_log("RLC"), pdcp_log("PDCP")
2020-05-28 09:06:48 -07:00
{
2020-07-09 09:54:42 -07:00
mac.reset(new mac_nr(&task_sched));
2020-07-08 14:06:15 -07:00
pdcp.reset(new srslte::pdcp(&task_sched, "PDCP"));
2020-05-28 09:06:48 -07:00
rlc.reset(new srslte::rlc("RLC"));
rrc.reset(new rrc_nr(&task_sched));
2020-05-28 09:06:48 -07:00
// setup logging for pool, RLC and PDCP
2021-02-01 03:43:41 -08:00
byte_buffer_pool::get_instance()->enable_logger(true);
2020-05-28 09:06:48 -07:00
2020-07-08 14:06:15 -07:00
ue_task_queue = task_sched.make_task_queue();
sync_task_queue = task_sched.make_task_queue();
gw_task_queue = task_sched.make_task_queue();
2020-05-28 09:06:48 -07:00
}
ue_stack_nr::~ue_stack_nr()
{
stop();
}
std::string ue_stack_nr::get_type()
{
return "nr";
}
int ue_stack_nr::init(const stack_args_t& args_, phy_interface_stack_nr* phy_, gw_interface_stack* gw_)
{
phy = phy_;
gw = gw_;
return init(args_);
}
int ue_stack_nr::init(const stack_args_t& args_)
{
args = args_;
srslte::logmap::register_log(std::unique_ptr<srslte::log>{new srslte::log_filter{"MAC", logger, true}});
srslte::log_ref mac_log{"MAC"};
mac_log->set_level(args.log.mac_level);
mac_log->set_hex_limit(args.log.mac_hex_limit);
rlc_log->set_level(args.log.rlc_level);
rlc_log->set_hex_limit(args.log.rlc_hex_limit);
pdcp_log->set_level(args.log.pdcp_level);
pdcp_log->set_hex_limit(args.log.pdcp_hex_limit);
mac_nr_args_t mac_args = {};
mac_args.pcap = args.pcap;
2020-07-09 09:54:42 -07:00
mac->init(mac_args, phy, rlc.get());
2020-07-08 14:06:15 -07:00
rlc->init(pdcp.get(), rrc.get(), task_sched.get_timer_handler(), 0 /* RB_ID_SRB0 */);
2020-05-28 09:06:48 -07:00
pdcp->init(rlc.get(), rrc.get(), gw);
// TODO: where to put RRC args?
rrc_nr_args_t rrc_args = {};
rrc_args.log_level = args.log.rrc_level;
rrc_args.log_hex_limit = args.log.rrc_hex_limit;
rrc_args.coreless.drb_lcid = 4;
rrc_args.coreless.ip_addr = "192.168.1.3";
2021-01-22 05:28:12 -08:00
rrc->init(
phy, mac.get(), rlc.get(), pdcp.get(), gw, nullptr, nullptr, task_sched.get_timer_handler(), this, rrc_args);
2020-12-15 04:10:46 -08:00
rrc->init_core_less();
2020-05-28 09:06:48 -07:00
running = true;
start(STACK_MAIN_THREAD_PRIO);
return SRSLTE_SUCCESS;
}
void ue_stack_nr::stop()
{
if (running) {
2020-07-08 14:06:15 -07:00
ue_task_queue.try_push([this]() { stop_impl(); });
2020-05-28 09:06:48 -07:00
wait_thread_finish();
}
}
void ue_stack_nr::stop_impl()
{
running = false;
rrc->stop();
rlc->stop();
pdcp->stop();
mac->stop();
}
bool ue_stack_nr::switch_on()
{
2020-06-19 11:54:38 -07:00
// statically setup TUN (will be done through RRC later)
char* err_str = nullptr;
if (gw->setup_if_addr(5, 4, LIBLTE_MME_PDN_TYPE_IPV4, htonl(inet_addr("192.168.1.3")), nullptr, err_str)) {
2020-06-19 11:54:38 -07:00
printf("Error configuring TUN interface\n");
}
2020-05-28 09:06:48 -07:00
return true;
}
bool ue_stack_nr::switch_off()
{
return true;
}
bool ue_stack_nr::get_metrics(stack_metrics_t* metrics)
{
// mac.get_metrics(metrics->mac);
rlc->get_metrics(metrics->rlc, metrics->mac[0].nof_tti);
2020-05-28 09:06:48 -07:00
// rrc.get_metrics(metrics->rrc);
return true;
}
void ue_stack_nr::run_thread()
{
while (running) {
task_sched.run_next_task();
2020-05-28 09:06:48 -07:00
}
}
/***********************************************************************************************************************
* Stack Interfaces
**********************************************************************************************************************/
/********************
* GW Interface
*******************/
/**
* Push GW SDU to stack
* @param lcid
* @param sdu
* @param blocking
*/
void ue_stack_nr::write_sdu(uint32_t lcid, srslte::unique_byte_buffer_t sdu)
2020-05-28 09:06:48 -07:00
{
if (pdcp != nullptr) {
2020-07-08 14:06:15 -07:00
std::pair<bool, move_task_t> ret = gw_task_queue.try_push(std::bind(
[this, lcid](srslte::unique_byte_buffer_t& sdu) { pdcp->write_sdu(lcid, std::move(sdu)); }, std::move(sdu)));
2020-05-28 09:06:48 -07:00
if (not ret.first) {
Upgrade loggers in srsue (#2163) * Replaced UE logger in the ue class. * Replaced loggers in the main phy class and prach. * Replaced loggers in phy common and ta_control. * Replace loggers in cc and sf workers. * Replaced loggers in intra_measure, scell_recv, search, sfn_sync, sync. * Remove last uses of the old loggers in the main phy class. * Remove stray newline in logs. * Replaced loggers in ue gw. * - Started to replace loggers in the ue stack. - Replaced loggers in usim and pcsc. - Adapted nas and usim tests. * Replace loggers in nas. * Added missing log init calls in two previously modified tests. * Replaced logger in nas idle procs. * Replaced loggers in nas emm state. * Replaced loggers in tft packet filter and adapted tft test. * Replaced loggers in main RRC class. * Replaced loggers in RRC cell. * Replaced loggers in RRC meas. * Replaced loggers in rrc procedures. * Started logger replacement in MAC layer, more precisely in demux and dl_harq classes. Been unable to inject loggers in construction for dl_tb_process due to very weird static assertions in the std::vector code being the type not constructible which is not true, so instead use the main MAC logger directly. * Replaced loggers in mac mux class. * Replaced loggers in mac pro_bsr. * Replaced loggers in mac proc phr. * Replaced loggers in mac proc SR and RA. * Replace loggers in mac UL HARQ. * Replaced loggers in main ue stack class. * Fixed nas test crashing due to a null string. * Ported mac_test to use the new loggers. * Removed TTI reporting for the PHY log as the old logger did. * Replaced loggers in UE phy tests. * Configure loggers in nas_test. * Replaced loggers in rrc_meas_test. * Replaced loggers in rrc_reconfig_test. * Added missing newline in tft_test. * Fix compilation errors in TTCN3 tests. * Fix linker error detected in CI and warning. * Replaced loggers in TTCN3 tests. * Fix a text replace error in some log messages. * Remove trailing newlines from log entries. * Remove old logger from rrc. * Flush backend before printing the test status. * - Fix compilation error from previous rebase. - Remove trailing newlines from some missing log entries.
2021-01-28 08:17:43 -08:00
pdcp_log->warning("GW SDU with lcid=%d was discarded.", lcid);
2020-05-28 09:06:48 -07:00
}
}
}
/********************
* SYNC Interface
*******************/
/**
* Sync thread signal that it is in sync
*/
void ue_stack_nr::in_sync()
{
// pending_tasks.push(sync_task_queue, task_t{[this](task_t*) { rrc.in_sync(); }});
2020-05-28 09:06:48 -07:00
}
void ue_stack_nr::out_of_sync()
{
// pending_tasks.push(sync_task_queue, task_t{[this](task_t*) { rrc.out_of_sync(); }});
2020-05-28 09:06:48 -07:00
}
void ue_stack_nr::run_tti(uint32_t tti)
{
2020-07-08 14:06:15 -07:00
sync_task_queue.push([this, tti]() { run_tti_impl(tti); });
2020-05-28 09:06:48 -07:00
}
void ue_stack_nr::run_tti_impl(uint32_t tti)
{
mac->run_tti(tti);
rrc->run_tti(tti);
2020-07-08 14:06:15 -07:00
task_sched.tic();
2020-05-28 09:06:48 -07:00
}
2020-06-16 04:08:34 -07:00
} // namespace srsue