2020-11-26 01:25:22 -08:00
|
|
|
/**
|
2021-03-28 14:12:42 -07:00
|
|
|
* Copyright 2013-2021 Software Radio Systems Limited
|
2020-05-28 09:06:48 -07:00
|
|
|
*
|
2021-04-22 01:59:40 -07:00
|
|
|
* This file is part of srsRAN.
|
2020-05-28 09:06:48 -07:00
|
|
|
*
|
2021-04-22 01:59:40 -07:00
|
|
|
* srsRAN is free software: you can redistribute it and/or modify
|
2021-03-28 14:12:42 -07:00
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
2021-04-22 01:59:40 -07:00
|
|
|
* srsRAN is distributed in the hope that it will be useful,
|
2021-03-28 14:12:42 -07:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2020-05-28 09:06:48 -07:00
|
|
|
*
|
2021-03-28 14:12:42 -07:00
|
|
|
* A copy of the GNU Affero General Public License can be found in
|
|
|
|
* the LICENSE file in the top-level directory of this distribution
|
|
|
|
* and at http://www.gnu.org/licenses/.
|
2020-05-28 09:06:48 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "srsue/hdr/stack/ue_stack_nr.h"
|
2021-03-19 03:45:56 -07:00
|
|
|
#include "srsran/srsran.h"
|
2021-11-26 03:29:40 -08:00
|
|
|
#include "srsue/hdr/stack/rrc_nr/rrc_nr.h"
|
2020-05-28 09:06:48 -07:00
|
|
|
|
2021-03-19 03:45:56 -07:00
|
|
|
using namespace srsran;
|
2020-05-28 09:06:48 -07:00
|
|
|
|
|
|
|
namespace srsue {
|
|
|
|
|
2021-03-10 11:41:05 -08:00
|
|
|
ue_stack_nr::ue_stack_nr() :
|
|
|
|
thread("STACK"),
|
|
|
|
task_sched(64, 64),
|
2021-04-13 03:55:09 -07:00
|
|
|
mac_logger(srslog::fetch_basic_logger("MAC-NR")),
|
|
|
|
rlc_logger(srslog::fetch_basic_logger("RLC-NR", false)),
|
|
|
|
pdcp_logger(srslog::fetch_basic_logger("PDCP-NR", false))
|
2020-05-28 09:06:48 -07:00
|
|
|
{
|
2021-02-25 04:11:14 -08:00
|
|
|
get_background_workers().set_nof_workers(2);
|
2020-07-09 09:54:42 -07:00
|
|
|
mac.reset(new mac_nr(&task_sched));
|
2021-04-13 03:55:09 -07:00
|
|
|
pdcp.reset(new srsran::pdcp(&task_sched, "PDCP-NR"));
|
|
|
|
rlc.reset(new srsran::rlc("RLC-NR"));
|
2020-12-15 02:04:42 -08:00
|
|
|
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_;
|
|
|
|
|
2021-03-10 11:41:05 -08:00
|
|
|
mac_logger.set_level(srslog::str_to_basic_level(args.log.mac_level));
|
|
|
|
mac_logger.set_hex_dump_max_size(args.log.mac_hex_limit);
|
|
|
|
rlc_logger.set_level(srslog::str_to_basic_level(args.log.rlc_level));
|
|
|
|
rlc_logger.set_hex_dump_max_size(args.log.rlc_hex_limit);
|
|
|
|
pdcp_logger.set_level(srslog::str_to_basic_level(args.log.pdcp_level));
|
|
|
|
pdcp_logger.set_hex_dump_max_size(args.log.pdcp_hex_limit);
|
2020-05-28 09:06:48 -07:00
|
|
|
|
|
|
|
mac_nr_args_t mac_args = {};
|
2021-03-27 06:11:01 -07:00
|
|
|
mac->init(mac_args, phy, rlc.get(), rrc.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;
|
2022-01-18 08:53:35 -08:00
|
|
|
rrc->init(phy,
|
|
|
|
mac.get(),
|
|
|
|
rlc.get(),
|
|
|
|
pdcp.get(),
|
2022-03-23 05:07:24 -07:00
|
|
|
sdap.get(),
|
2022-01-18 08:53:35 -08:00
|
|
|
gw,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
task_sched.get_timer_handler(),
|
|
|
|
this,
|
|
|
|
rrc_args);
|
2020-05-28 09:06:48 -07:00
|
|
|
running = true;
|
|
|
|
start(STACK_MAIN_THREAD_PRIO);
|
|
|
|
|
2021-03-19 03:45:56 -07:00
|
|
|
return SRSRAN_SUCCESS;
|
2020-05-28 09:06:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2021-02-25 04:11:14 -08:00
|
|
|
|
|
|
|
get_background_workers().stop();
|
2020-05-28 09:06:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ue_stack_nr::switch_on()
|
|
|
|
{
|
2020-06-19 11:54:38 -07:00
|
|
|
// statically setup TUN (will be done through RRC later)
|
2021-10-07 09:39:43 -07:00
|
|
|
char* err_str = nullptr;
|
2021-09-10 08:28:11 -07:00
|
|
|
struct in_addr in_addr;
|
|
|
|
if (inet_pton(AF_INET, "192.168.1.3", &in_addr.s_addr) != 1) {
|
|
|
|
perror("inet_pton");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (gw->setup_if_addr(5, LIBLTE_MME_PDN_TYPE_IPV4, htonl(in_addr.s_addr), 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);
|
2020-11-30 07:32:06 -08:00
|
|
|
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) {
|
2020-07-09 08:03:22 -07:00
|
|
|
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
|
|
|
|
*/
|
2021-03-19 03:45:56 -07:00
|
|
|
void ue_stack_nr::write_sdu(uint32_t lcid, srsran::unique_byte_buffer_t sdu)
|
2020-05-28 09:06:48 -07:00
|
|
|
{
|
|
|
|
if (pdcp != nullptr) {
|
2021-04-23 08:42:42 -07:00
|
|
|
auto ret = gw_task_queue.try_push(std::bind(
|
2021-03-19 03:45:56 -07:00
|
|
|
[this, lcid](srsran::unique_byte_buffer_t& sdu) { pdcp->write_sdu(lcid, std::move(sdu)); }, std::move(sdu)));
|
2021-04-23 08:42:42 -07:00
|
|
|
if (ret.is_error()) {
|
2021-03-10 11:41:05 -08:00
|
|
|
pdcp_logger.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()
|
|
|
|
{
|
2020-07-08 10:39:23 -07:00
|
|
|
// 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()
|
|
|
|
{
|
2020-07-08 10:39:23 -07:00
|
|
|
// pending_tasks.push(sync_task_queue, task_t{[this](task_t*) { rrc.out_of_sync(); }});
|
2020-05-28 09:06:48 -07:00
|
|
|
}
|
|
|
|
|
2021-11-30 05:45:19 -08:00
|
|
|
void ue_stack_nr::run_tti(uint32_t tti, uint32_t tti_jump)
|
2020-05-28 09:06:48 -07:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2021-10-25 01:51:02 -07:00
|
|
|
void ue_stack_nr::set_phy_config_complete(bool status)
|
|
|
|
{
|
|
|
|
sync_task_queue.push([this, status]() { rrc->set_phy_config_complete(status); });
|
|
|
|
}
|
|
|
|
|
2022-01-12 02:47:59 -08:00
|
|
|
void ue_stack_nr::cell_search_found_cell(const cell_search_result_t& result)
|
|
|
|
{
|
|
|
|
sync_task_queue.push([this, result]() { rrc->cell_search_found_cell(result); });
|
|
|
|
}
|
|
|
|
|
2022-01-07 02:43:08 -08:00
|
|
|
void ue_stack_nr::cell_select_completed(const rrc_interface_phy_nr::cell_select_result_t& result)
|
|
|
|
{
|
|
|
|
sync_task_queue.push([this, result]() { rrc->cell_select_completed(result); });
|
|
|
|
}
|
|
|
|
|
2020-06-16 04:08:34 -07:00
|
|
|
} // namespace srsue
|