mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
234 lines
6.3 KiB
C++
234 lines
6.3 KiB
C++
4 years ago
|
/**
|
||
4 years ago
|
*
|
||
4 years ago
|
* \section COPYRIGHT
|
||
4 years ago
|
*
|
||
4 years ago
|
* Copyright 2013-2021 Software Radio Systems Limited
|
||
4 years ago
|
*
|
||
4 years ago
|
* 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.
|
||
4 years ago
|
*
|
||
|
*/
|
||
|
|
||
3 years ago
|
#include "srsgnb/hdr/stack/gnb_stack_nr.h"
|
||
3 years ago
|
#include "srsenb/hdr/stack/upper/gtpu.h"
|
||
3 years ago
|
#include "srsgnb/hdr/stack/ngap/ngap.h"
|
||
3 years ago
|
#include "srsran/common/network_utils.h"
|
||
3 years ago
|
#include "srsran/common/standard_streams.h"
|
||
4 years ago
|
#include "srsran/srsran.h"
|
||
|
#include <srsran/interfaces/enb_metrics_interface.h>
|
||
4 years ago
|
|
||
|
namespace srsenb {
|
||
|
|
||
3 years ago
|
gnb_stack_nr::gnb_stack_nr(srslog::sink& log_sink) :
|
||
|
task_sched{512, 128},
|
||
|
thread("gNB"),
|
||
|
mac_logger(srslog::fetch_basic_logger("MAC-NR", log_sink)),
|
||
|
rlc_logger(srslog::fetch_basic_logger("RLC-NR", log_sink, false)),
|
||
|
pdcp_logger(srslog::fetch_basic_logger("PDCP-NR", log_sink, false)),
|
||
|
rrc_logger(srslog::fetch_basic_logger("RRC-NR", log_sink, false)),
|
||
|
stack_logger(srslog::fetch_basic_logger("STCK-NR", log_sink, false)),
|
||
3 years ago
|
gtpu_logger(srslog::fetch_basic_logger("GTPU", log_sink, false)),
|
||
|
ngap_logger(srslog::fetch_basic_logger("NGAP", log_sink, false)),
|
||
3 years ago
|
mac(&task_sched),
|
||
|
rrc(&task_sched),
|
||
|
pdcp(&task_sched, pdcp_logger),
|
||
|
rlc(rlc_logger)
|
||
4 years ago
|
{
|
||
3 years ago
|
sync_task_queue = task_sched.make_task_queue();
|
||
|
gtpu_task_queue = task_sched.make_task_queue();
|
||
|
metrics_task_queue = task_sched.make_task_queue();
|
||
3 years ago
|
gnb_task_queue = task_sched.make_task_queue();
|
||
3 years ago
|
x2_task_queue = task_sched.make_task_queue();
|
||
4 years ago
|
}
|
||
|
|
||
|
gnb_stack_nr::~gnb_stack_nr()
|
||
|
{
|
||
|
stop();
|
||
|
}
|
||
|
|
||
|
std::string gnb_stack_nr::get_type()
|
||
|
{
|
||
|
return "nr";
|
||
|
}
|
||
|
|
||
3 years ago
|
int gnb_stack_nr::init(const gnb_stack_args_t& args_,
|
||
|
const rrc_nr_cfg_t& rrc_cfg_,
|
||
|
phy_interface_stack_nr* phy_,
|
||
|
x2_interface* x2_)
|
||
4 years ago
|
{
|
||
3 years ago
|
args = args_;
|
||
3 years ago
|
phy = phy_;
|
||
4 years ago
|
|
||
3 years ago
|
// setup logging
|
||
|
mac_logger.set_level(srslog::str_to_basic_level(args.log.mac_level));
|
||
|
rlc_logger.set_level(srslog::str_to_basic_level(args.log.rlc_level));
|
||
|
pdcp_logger.set_level(srslog::str_to_basic_level(args.log.pdcp_level));
|
||
|
rrc_logger.set_level(srslog::str_to_basic_level(args.log.rrc_level));
|
||
|
stack_logger.set_level(srslog::str_to_basic_level(args.log.stack_level));
|
||
3 years ago
|
ngap_logger.set_level(srslog::str_to_basic_level(args.log.s1ap_level));
|
||
|
gtpu_logger.set_level(srslog::str_to_basic_level(args.log.gtpu_level));
|
||
4 years ago
|
|
||
3 years ago
|
mac_logger.set_hex_dump_max_size(args.log.mac_hex_limit);
|
||
|
rlc_logger.set_hex_dump_max_size(args.log.rlc_hex_limit);
|
||
|
pdcp_logger.set_hex_dump_max_size(args.log.pdcp_hex_limit);
|
||
|
rrc_logger.set_hex_dump_max_size(args.log.rrc_hex_limit);
|
||
|
stack_logger.set_hex_dump_max_size(args.log.stack_hex_limit);
|
||
3 years ago
|
ngap_logger.set_hex_dump_max_size(args.log.s1ap_hex_limit);
|
||
|
gtpu_logger.set_hex_dump_max_size(args.log.gtpu_hex_limit);
|
||
|
|
||
3 years ago
|
if (x2_ == nullptr) {
|
||
|
// SA mode
|
||
3 years ago
|
ngap.reset(new srsenb::ngap(&task_sched, ngap_logger, &srsran::get_rx_io_manager()));
|
||
|
gtpu.reset(new srsenb::gtpu(&task_sched, gtpu_logger, &srsran::get_rx_io_manager()));
|
||
|
}
|
||
4 years ago
|
|
||
|
// Init all layers
|
||
3 years ago
|
if (mac.init(args.mac, phy, nullptr, &rlc, &rrc) != SRSRAN_SUCCESS) {
|
||
3 years ago
|
stack_logger.error("Couldn't initialize MAC-NR");
|
||
|
return SRSRAN_ERROR;
|
||
|
}
|
||
4 years ago
|
|
||
3 years ago
|
rlc.init(&pdcp, &rrc, &mac, task_sched.get_timer_handler());
|
||
3 years ago
|
pdcp.init(&rlc, &rrc, x2_);
|
||
4 years ago
|
|
||
3 years ago
|
if (rrc.init(rrc_cfg_, phy, &mac, &rlc, &pdcp, ngap.get(), nullptr, x2_) != SRSRAN_SUCCESS) {
|
||
3 years ago
|
stack_logger.error("Couldn't initialize RRC");
|
||
|
return SRSRAN_ERROR;
|
||
|
}
|
||
4 years ago
|
|
||
3 years ago
|
if (ngap != nullptr) {
|
||
|
ngap->init(args.ngap, &rrc, nullptr);
|
||
|
gtpu_args_t gtpu_args;
|
||
|
gtpu_args.embms_enable = false;
|
||
|
gtpu_args.mme_addr = args.ngap.amf_addr;
|
||
|
gtpu_args.gtp_bind_addr = args.ngap.gtp_bind_addr;
|
||
|
gtpu->init(gtpu_args, &pdcp);
|
||
|
}
|
||
|
|
||
|
// TODO: add SDAP
|
||
4 years ago
|
|
||
|
running = true;
|
||
|
|
||
|
start(STACK_MAIN_THREAD_PRIO);
|
||
|
|
||
4 years ago
|
return SRSRAN_SUCCESS;
|
||
4 years ago
|
}
|
||
|
|
||
|
void gnb_stack_nr::stop()
|
||
|
{
|
||
|
if (running) {
|
||
3 years ago
|
gnb_task_queue.push([this]() { stop_impl(); });
|
||
|
wait_thread_finish();
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
void gnb_stack_nr::stop_impl()
|
||
|
{
|
||
3 years ago
|
srsran::get_rx_io_manager().stop();
|
||
|
|
||
3 years ago
|
rrc.stop();
|
||
|
pdcp.stop();
|
||
|
mac.stop();
|
||
|
|
||
|
task_sched.stop();
|
||
|
srsran::get_background_workers().stop();
|
||
|
|
||
|
running = false;
|
||
|
}
|
||
|
|
||
4 years ago
|
bool gnb_stack_nr::switch_on()
|
||
|
{
|
||
|
// Nothing to be done here
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void gnb_stack_nr::run_thread()
|
||
|
{
|
||
|
while (running) {
|
||
4 years ago
|
task_sched.run_next_task();
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
void gnb_stack_nr::tti_clock()
|
||
4 years ago
|
{
|
||
3 years ago
|
sync_task_queue.push([this]() { tti_clock_impl(); });
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
void gnb_stack_nr::tti_clock_impl()
|
||
4 years ago
|
{
|
||
|
// m_ngap->run_tti();
|
||
4 years ago
|
task_sched.tic();
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
void gnb_stack_nr::process_pdus() {}
|
||
4 years ago
|
|
||
4 years ago
|
/********************************************************
|
||
|
*
|
||
|
* Interface for upper layer timers
|
||
|
*
|
||
|
*******************************************************/
|
||
|
|
||
|
bool gnb_stack_nr::get_metrics(srsenb::stack_metrics_t* metrics)
|
||
|
{
|
||
3 years ago
|
bool metrics_ready = false;
|
||
|
|
||
|
// use stack thread to query RRC metrics
|
||
|
auto ret = metrics_task_queue.try_push([this, metrics, &metrics_ready]() {
|
||
|
rrc.get_metrics(metrics->rrc);
|
||
|
{
|
||
|
std::lock_guard<std::mutex> lock(metrics_mutex);
|
||
|
metrics_ready = true;
|
||
3 years ago
|
}
|
||
3 years ago
|
metrics_cvar.notify_one();
|
||
3 years ago
|
});
|
||
3 years ago
|
if (not ret.has_value()) {
|
||
|
return false;
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
|
// obtain MAC metrics (do not use stack thread)
|
||
|
mac.get_metrics(metrics->mac);
|
||
|
|
||
|
// wait for RRC result
|
||
|
std::unique_lock<std::mutex> lock(metrics_mutex);
|
||
|
metrics_cvar.wait(lock, [&metrics_ready]() { return metrics_ready; });
|
||
|
return true;
|
||
4 years ago
|
}
|
||
|
|
||
|
// Temporary GW interface
|
||
4 years ago
|
void gnb_stack_nr::write_sdu(uint32_t lcid, srsran::unique_byte_buffer_t sdu)
|
||
4 years ago
|
{
|
||
3 years ago
|
// not implemented
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
bool gnb_stack_nr::has_active_radio_bearer(uint32_t eps_bearer_id)
|
||
4 years ago
|
{
|
||
3 years ago
|
return false;
|
||
4 years ago
|
}
|
||
3 years ago
|
int gnb_stack_nr::slot_indication(const srsran_slot_cfg_t& slot_cfg)
|
||
3 years ago
|
{
|
||
3 years ago
|
return mac.slot_indication(slot_cfg);
|
||
3 years ago
|
}
|
||
3 years ago
|
gnb_stack_nr::dl_sched_t* gnb_stack_nr::get_dl_sched(const srsran_slot_cfg_t& slot_cfg)
|
||
3 years ago
|
{
|
||
3 years ago
|
return mac.get_dl_sched(slot_cfg);
|
||
3 years ago
|
}
|
||
3 years ago
|
gnb_stack_nr::ul_sched_t* gnb_stack_nr::get_ul_sched(const srsran_slot_cfg_t& slot_cfg)
|
||
3 years ago
|
{
|
||
3 years ago
|
return mac.get_ul_sched(slot_cfg);
|
||
3 years ago
|
}
|
||
3 years ago
|
int gnb_stack_nr::pucch_info(const srsran_slot_cfg_t& slot_cfg, const mac_interface_phy_nr::pucch_info_t& pucch_info)
|
||
|
{
|
||
3 years ago
|
return mac.pucch_info(slot_cfg, pucch_info);
|
||
3 years ago
|
}
|
||
3 years ago
|
int gnb_stack_nr::pusch_info(const srsran_slot_cfg_t& slot_cfg, mac_interface_phy_nr::pusch_info_t& pusch_info)
|
||
3 years ago
|
{
|
||
3 years ago
|
return mac.pusch_info(slot_cfg, pusch_info);
|
||
3 years ago
|
}
|
||
4 years ago
|
|
||
3 years ago
|
void gnb_stack_nr::rach_detected(const rach_info_t& rach_info)
|
||
|
{
|
||
|
mac.rach_detected(rach_info);
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
} // namespace srsenb
|