mirror of https://github.com/pvnis/srsRAN_4G.git
introduce new UE layer design
- abstract UE object now consists of a radio, a PHY, and a stack layer - add new stack abstraction layer that combines MAC, RLC, RRC, PDCP, NAS and GW - PHY layer now has a single stack interface and does not talk to MAC and RRC seperatlymaster
parent
3a6dd9b164
commit
65f50cd7ba
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* 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.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* File: ue_phy_base.h
|
||||
* Description: Base class for all UE PHYs.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef SRSUE_UE_PHY_BASE_H
|
||||
#define SRSUE_UE_PHY_BASE_H
|
||||
|
||||
#include "srslte/common/logger.h"
|
||||
#include "srslte/interfaces/ue_interfaces.h"
|
||||
#include "srsue/hdr/phy/phy_metrics.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace srsue {
|
||||
|
||||
class ue_phy_base
|
||||
{
|
||||
public:
|
||||
ue_phy_base(){};
|
||||
virtual ~ue_phy_base(){};
|
||||
|
||||
virtual std::string get_type() = 0;
|
||||
|
||||
virtual int init(const phy_args_t& args_, srslte::logger* logger_) = 0;
|
||||
virtual void stop() = 0;
|
||||
|
||||
virtual void set_earfcn(std::vector<uint32_t> earfcns) = 0;
|
||||
virtual void force_freq(float dl_freq, float ul_freq) = 0;
|
||||
|
||||
virtual void wait_initialize() = 0;
|
||||
virtual void start_plot() = 0;
|
||||
|
||||
virtual void get_metrics(phy_metrics_t* m) = 0;
|
||||
};
|
||||
|
||||
} // namespace srsue
|
||||
|
||||
#endif // SRSUE_UE_PHY_BASE_H
|
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* 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.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* File: ue_radio_multi.h
|
||||
* Description: UE radio module using the srslte_radio_multi() object.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef SRSUE_UE_RADIO_MULTI_H
|
||||
#define SRSUE_UE_RADIO_MULTI_H
|
||||
|
||||
#include "srslte/common/log_filter.h"
|
||||
#include "srslte/radio/radio.h"
|
||||
#include "srsue/hdr/radio/ue_radio_base.h"
|
||||
#include "srsue/hdr/ue_metrics_interface.h"
|
||||
|
||||
namespace srsue {
|
||||
|
||||
/*******************************************************************************
|
||||
Main UE stack class
|
||||
*******************************************************************************/
|
||||
|
||||
class ue_radio : public ue_radio_base, public radio_interface_phy
|
||||
{
|
||||
public:
|
||||
ue_radio();
|
||||
~ue_radio();
|
||||
|
||||
std::string get_type();
|
||||
|
||||
int init(const rf_args_t& args_, srslte::logger* logger_);
|
||||
int init(const rf_args_t& args_, srslte::logger* logger_, phy_interface_radio* phy_);
|
||||
|
||||
void stop();
|
||||
|
||||
static void rf_msg(srslte_rf_error_t error);
|
||||
void handle_rf_msg(srslte_rf_error_t error);
|
||||
|
||||
bool get_metrics(rf_metrics_t* metrics);
|
||||
|
||||
// radio_interface_phy
|
||||
bool is_init() { return radios.at(0)->is_init(); }
|
||||
void reset() { return radios.at(0)->reset(); }
|
||||
bool is_continuous_tx() { return radios.at(0)->is_continuous_tx(); }
|
||||
bool tx(cf_t* buffer[SRSLTE_MAX_PORTS], const uint32_t& nof_samples, const srslte_timestamp_t& tx_time)
|
||||
{
|
||||
for (auto& radio : radios) {
|
||||
radio->tx(buffer, nof_samples, tx_time);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void tx_end() { return radios.at(0)->tx_end(); }
|
||||
|
||||
bool rx_now(cf_t* buffer[SRSLTE_MAX_PORTS], const uint32_t& nof_samples, srslte_timestamp_t* rxd_time)
|
||||
{
|
||||
return radios.at(0)->rx_now(buffer, nof_samples, rxd_time);
|
||||
}
|
||||
void set_rx_gain(const uint32_t& radio_idx, const float& gain) { radios.at(radio_idx)->set_rx_gain(gain); }
|
||||
double set_rx_gain_th(const float& gain) { return radios.at(0)->set_rx_gain_th(gain); }
|
||||
float get_rx_gain(const uint32_t& radio_idx) { return radios.at(radio_idx)->get_rx_gain(); }
|
||||
void set_tx_freq(const uint32_t& radio_idx, const double& freq) { radios.at(radio_idx)->set_tx_freq(0, freq); }
|
||||
void set_rx_freq(const uint32_t& radio_idx, const double& freq) { radios.at(radio_idx)->set_rx_freq(0, freq); }
|
||||
double get_freq_offset() { return radios.at(0)->get_freq_offset(); }
|
||||
double get_tx_freq(const uint32_t& radio_idx) { return radios.at(radio_idx)->get_tx_freq(); }
|
||||
double get_rx_freq(const uint32_t& radio_idx) { return radios.at(radio_idx)->get_rx_freq(); }
|
||||
float get_max_tx_power() { return radios.at(0)->get_max_tx_power(); }
|
||||
void set_master_clock_rate(const double& rate) { radios.at(0)->set_master_clock_rate(rate); }
|
||||
void set_tx_srate(const double& srate) { radios.at(0)->set_tx_srate(srate); }
|
||||
void set_rx_srate(const double& srate) { radios.at(0)->set_rx_srate(srate); }
|
||||
float set_tx_power(const float& power) { return radios.at(0)->set_tx_power(power); }
|
||||
srslte_rf_info_t* get_info(const uint32_t& radio_idx) { return radios.at(radio_idx)->get_info(); }
|
||||
|
||||
private:
|
||||
srsue::rf_args_t args;
|
||||
|
||||
std::vector<std::unique_ptr<srslte::radio> > radios;
|
||||
|
||||
srslte::logger* logger;
|
||||
srslte::log_filter log;
|
||||
bool running;
|
||||
|
||||
rf_metrics_t rf_metrics;
|
||||
phy_interface_radio* phy;
|
||||
};
|
||||
|
||||
} // namespace srsue
|
||||
|
||||
#endif // SRSUE_UE_RADIO_MULTI_H
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* 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.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* File: ue_radio_base.h
|
||||
* Description: Base class for all UE Radios.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef SRSUE_UE_RADIO_BASE_H
|
||||
#define SRSUE_UE_RADIO_BASE_H
|
||||
|
||||
#include "srslte/common/logger.h"
|
||||
#include "srslte/interfaces/ue_interfaces.h"
|
||||
#include "srsue/hdr/ue_metrics_interface.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace srsue {
|
||||
|
||||
class ue_radio_base
|
||||
{
|
||||
public:
|
||||
ue_radio_base(){};
|
||||
virtual ~ue_radio_base(){};
|
||||
|
||||
static std::shared_ptr<ue_radio_base> get_instance(const std::string& type);
|
||||
|
||||
virtual std::string get_type() = 0;
|
||||
|
||||
virtual int init(const srsue::rf_args_t& args_, srslte::logger* logger_) = 0;
|
||||
virtual void stop() = 0;
|
||||
|
||||
virtual bool get_metrics(rf_metrics_t* metrics) = 0;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace srsue
|
||||
|
||||
#endif // SRSUE_UE_RADIO_BASE_H
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* 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.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSUE_UE_STACK_BASE_H
|
||||
#define SRSUE_UE_STACK_BASE_H
|
||||
|
||||
#include "srslte/common/logger.h"
|
||||
#include "srslte/interfaces/ue_interfaces.h"
|
||||
#include "srsue/hdr/ue_metrics_interface.h"
|
||||
#include "srsue/hdr/ue_stack_interface.h"
|
||||
#include <memory>
|
||||
|
||||
namespace srsue {
|
||||
|
||||
class ue_stack_base : public ue_interface
|
||||
{
|
||||
public:
|
||||
ue_stack_base(){};
|
||||
virtual ~ue_stack_base(){};
|
||||
|
||||
virtual std::string get_type() = 0;
|
||||
|
||||
virtual int init(const stack_args_t& args_, srslte::logger* logger_) = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual bool switch_on() = 0;
|
||||
virtual bool switch_off() = 0;
|
||||
virtual bool is_rrc_connected() = 0;
|
||||
|
||||
// UE metrics interface
|
||||
virtual bool get_metrics(stack_metrics_t* metrics) = 0;
|
||||
};
|
||||
|
||||
} // namespace srsue
|
||||
|
||||
#endif // SRSUE_UE_BASE_H
|
@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* 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.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
/******************************************************************************
|
||||
* File: ue_stack.h
|
||||
* Description: L2/L3 LTE stack class.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef SRSUE_UE_STACK_LTE_H
|
||||
#define SRSUE_UE_STACK_LTE_H
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <string>
|
||||
|
||||
#include "mac/mac.h"
|
||||
#include "rrc/rrc.h"
|
||||
#include "srslte/radio/radio.h"
|
||||
#include "srslte/upper/pdcp.h"
|
||||
#include "srslte/upper/rlc.h"
|
||||
#include "upper/gw.h"
|
||||
#include "upper/nas.h"
|
||||
#include "upper/usim.h"
|
||||
|
||||
#include "srslte/common/buffer_pool.h"
|
||||
#include "srslte/interfaces/ue_interfaces.h"
|
||||
#include "srslte/common/log_filter.h"
|
||||
|
||||
#include "srsue/hdr/ue_metrics_interface.h"
|
||||
#include "ue_stack_base.h"
|
||||
|
||||
namespace srsue {
|
||||
|
||||
class ue_stack_lte : public ue_stack_base, public stack_interface_phy_lte
|
||||
{
|
||||
public:
|
||||
ue_stack_lte();
|
||||
~ue_stack_lte();
|
||||
|
||||
std::string get_type();
|
||||
|
||||
int init(const stack_args_t& args_, srslte::logger* logger_);
|
||||
int init(const stack_args_t& args_, srslte::logger* logger_, phy_interface_stack_lte* phy_);
|
||||
bool switch_on();
|
||||
bool switch_off();
|
||||
void stop();
|
||||
|
||||
bool get_metrics(stack_metrics_t* metrics);
|
||||
bool is_rrc_connected();
|
||||
|
||||
// RRC interface for PHY
|
||||
void in_sync() { rrc.in_sync(); };
|
||||
void out_of_sync() { rrc.out_of_sync(); };
|
||||
void new_phy_meas(float rsrp, float rsrq, uint32_t tti, int earfcn = -1, int pci = -1)
|
||||
{
|
||||
rrc.new_phy_meas(rsrp, rsrq, tti, earfcn, pci);
|
||||
};
|
||||
|
||||
// MAC Interface for PHY
|
||||
uint16_t get_dl_sched_rnti(uint32_t tti) { return mac.get_dl_sched_rnti(tti); }
|
||||
uint16_t get_ul_sched_rnti(uint32_t tti) { return mac.get_ul_sched_rnti(tti); }
|
||||
|
||||
void new_grant_ul(uint32_t cc_idx, mac_grant_ul_t grant, tb_action_ul_t* action)
|
||||
{
|
||||
mac.new_grant_ul(cc_idx, grant, action);
|
||||
}
|
||||
|
||||
void new_grant_dl(uint32_t cc_idx, mac_grant_dl_t grant, tb_action_dl_t* action)
|
||||
{
|
||||
mac.new_grant_dl(cc_idx, grant, action);
|
||||
}
|
||||
|
||||
void tb_decoded(uint32_t cc_idx, mac_grant_dl_t grant, bool ack[SRSLTE_MAX_CODEWORDS])
|
||||
{
|
||||
mac.tb_decoded(cc_idx, grant, ack);
|
||||
}
|
||||
|
||||
void bch_decoded_ok(uint8_t* payload, uint32_t len) { mac.bch_decoded_ok(payload, len); }
|
||||
|
||||
void mch_decoded(uint32_t len, bool crc) { mac.mch_decoded(len, crc); }
|
||||
|
||||
void new_mch_dl(srslte_pdsch_grant_t phy_grant, tb_action_dl_t* action) { mac.new_mch_dl(phy_grant, action); }
|
||||
|
||||
void set_mbsfn_config(uint32_t nof_mbsfn_services) { mac.set_mbsfn_config(nof_mbsfn_services); }
|
||||
|
||||
void run_tti(const uint32_t tti) { mac.run_tti(tti); }
|
||||
|
||||
private:
|
||||
bool running;
|
||||
srsue::stack_args_t args;
|
||||
|
||||
srsue::mac mac;
|
||||
srslte::mac_pcap mac_pcap;
|
||||
srslte::nas_pcap nas_pcap;
|
||||
srslte::rlc rlc;
|
||||
srslte::pdcp pdcp;
|
||||
srsue::rrc rrc;
|
||||
srsue::nas nas;
|
||||
srsue::gw gw;
|
||||
srsue::usim_base* usim;
|
||||
|
||||
srslte::logger* logger;
|
||||
|
||||
// Radio and PHY log are in ue.cc
|
||||
srslte::log_filter mac_log;
|
||||
srslte::log_filter rlc_log;
|
||||
srslte::log_filter pdcp_log;
|
||||
srslte::log_filter rrc_log;
|
||||
srslte::log_filter nas_log;
|
||||
srslte::log_filter gw_log;
|
||||
srslte::log_filter usim_log;
|
||||
srslte::log_filter pool_log;
|
||||
|
||||
// RAT-specific interfaces
|
||||
phy_interface_stack_lte* phy;
|
||||
};
|
||||
|
||||
} // namespace srsue
|
||||
|
||||
#endif // SRSUE_UE_STACK_LTE_H
|
@ -1,185 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* 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.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* File: ue_base.h
|
||||
* Description: Base class for UEs.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef SRSUE_UE_BASE_H
|
||||
#define SRSUE_UE_BASE_H
|
||||
|
||||
#include "phy/phy.h"
|
||||
#include "rrc/rrc.h"
|
||||
#include "srslte/interfaces/ue_interfaces.h"
|
||||
#include "srslte/radio/radio_multi.h"
|
||||
#include "upper/nas.h"
|
||||
#include "upper/usim.h"
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <string>
|
||||
|
||||
#include "srslte/common/logger.h"
|
||||
#include "srslte/common/log_filter.h"
|
||||
|
||||
#include "ue_metrics_interface.h"
|
||||
|
||||
namespace srsue {
|
||||
|
||||
/*******************************************************************************
|
||||
UE Parameters
|
||||
*******************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
std::string dl_earfcn;
|
||||
float dl_freq;
|
||||
float ul_freq;
|
||||
float freq_offset;
|
||||
float rx_gain;
|
||||
float tx_gain;
|
||||
uint32_t nof_radios;
|
||||
uint32_t nof_rf_channels; // Number of RF channels per radio
|
||||
uint32_t nof_rx_ant; // Number of RF channels for MIMO
|
||||
std::string device_name;
|
||||
std::string device_args[SRSLTE_MAX_RADIOS];
|
||||
std::string time_adv_nsamples;
|
||||
std::string burst_preamble;
|
||||
std::string continuous_tx;
|
||||
} rf_args_t;
|
||||
|
||||
typedef struct {
|
||||
bool enable;
|
||||
std::string filename;
|
||||
bool nas_enable;
|
||||
std::string nas_filename;
|
||||
} pcap_args_t;
|
||||
|
||||
typedef struct {
|
||||
std::string phy_level;
|
||||
std::string phy_lib_level;
|
||||
std::string mac_level;
|
||||
std::string rlc_level;
|
||||
std::string pdcp_level;
|
||||
std::string rrc_level;
|
||||
std::string gw_level;
|
||||
std::string nas_level;
|
||||
std::string usim_level;
|
||||
std::string all_level;
|
||||
int phy_hex_limit;
|
||||
int mac_hex_limit;
|
||||
int rlc_hex_limit;
|
||||
int pdcp_hex_limit;
|
||||
int rrc_hex_limit;
|
||||
int gw_hex_limit;
|
||||
int nas_hex_limit;
|
||||
int usim_hex_limit;
|
||||
int all_hex_limit;
|
||||
int file_max_size;
|
||||
std::string filename;
|
||||
} log_args_t;
|
||||
|
||||
typedef struct {
|
||||
bool enable;
|
||||
}gui_args_t;
|
||||
|
||||
typedef struct {
|
||||
std::string ip_netmask;
|
||||
std::string ip_devname;
|
||||
phy_args_t phy;
|
||||
float metrics_period_secs;
|
||||
bool pregenerate_signals;
|
||||
bool print_buffer_state;
|
||||
bool metrics_csv_enable;
|
||||
std::string metrics_csv_filename;
|
||||
int mbms_service;
|
||||
} expert_args_t;
|
||||
|
||||
typedef struct {
|
||||
rf_args_t rf;
|
||||
pcap_args_t pcap;
|
||||
log_args_t log;
|
||||
gui_args_t gui;
|
||||
usim_args_t usim;
|
||||
rrc_args_t rrc;
|
||||
nas_args_t nas;
|
||||
expert_args_t expert;
|
||||
} all_args_t;
|
||||
|
||||
typedef enum {
|
||||
LTE = 0,
|
||||
SRSUE_INSTANCE_TYPE_NITEMS
|
||||
} srsue_instance_type_t;
|
||||
static const char srsue_instance_type_text[SRSUE_INSTANCE_TYPE_NITEMS][10] = { "LTE" };
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
Main UE class
|
||||
*******************************************************************************/
|
||||
|
||||
class ue_base
|
||||
:public ue_interface
|
||||
,public ue_metrics_interface
|
||||
{
|
||||
public:
|
||||
ue_base();
|
||||
virtual ~ue_base();
|
||||
|
||||
static ue_base* get_instance(srsue_instance_type_t type);
|
||||
|
||||
void cleanup(void);
|
||||
|
||||
virtual bool init(all_args_t *args_) = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual bool switch_on() = 0;
|
||||
virtual bool switch_off() = 0;
|
||||
virtual bool is_attached() = 0;
|
||||
virtual void start_plot() = 0;
|
||||
|
||||
virtual void print_pool() = 0;
|
||||
|
||||
virtual void radio_overflow() = 0;
|
||||
|
||||
virtual void print_mbms() = 0;
|
||||
virtual bool mbms_service_start(uint32_t serv, uint32_t port) = 0;
|
||||
|
||||
void handle_rf_msg(srslte_rf_error_t error);
|
||||
|
||||
// UE metrics interface
|
||||
virtual bool get_metrics(ue_metrics_t &m) = 0;
|
||||
|
||||
virtual void pregenerate_signals(bool enable) = 0;
|
||||
|
||||
srslte::log_filter rf_log;
|
||||
rf_metrics_t rf_metrics;
|
||||
srslte::LOG_LEVEL_ENUM level(std::string l);
|
||||
|
||||
std::string get_build_mode();
|
||||
std::string get_build_info();
|
||||
std::string get_build_string();
|
||||
|
||||
private:
|
||||
srslte::byte_buffer_pool *pool;
|
||||
};
|
||||
|
||||
} // namespace srsue
|
||||
|
||||
#endif // SRSUE_UE_BASE_H
|
||||
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* 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.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* File: ue_stack_interface.h
|
||||
* Description: Pure virtual interface to the UE stack.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef SRSUE_UE_STACK_INTERFACE_H
|
||||
#define SRSUE_UE_STACK_INTERFACE_H
|
||||
|
||||
#include "srslte/common/logger.h"
|
||||
#include "stack/rrc/rrc.h"
|
||||
#include "stack/upper/gw.h"
|
||||
#include "stack/upper/nas.h"
|
||||
#include "stack/upper/usim.h"
|
||||
#include "ue_metrics_interface.h"
|
||||
|
||||
namespace srsue {
|
||||
|
||||
typedef struct {
|
||||
bool enable;
|
||||
std::string filename;
|
||||
bool nas_enable;
|
||||
std::string nas_filename;
|
||||
} pcap_args_t;
|
||||
|
||||
typedef struct {
|
||||
std::string mac_level;
|
||||
std::string rlc_level;
|
||||
std::string pdcp_level;
|
||||
std::string rrc_level;
|
||||
std::string gw_level;
|
||||
std::string nas_level;
|
||||
std::string usim_level;
|
||||
|
||||
int mac_hex_limit;
|
||||
int rlc_hex_limit;
|
||||
int pdcp_hex_limit;
|
||||
int rrc_hex_limit;
|
||||
int gw_hex_limit;
|
||||
int nas_hex_limit;
|
||||
int usim_hex_limit;
|
||||
} stack_log_args_t;
|
||||
|
||||
typedef struct {
|
||||
std::string type;
|
||||
pcap_args_t pcap;
|
||||
stack_log_args_t log;
|
||||
usim_args_t usim;
|
||||
rrc_args_t rrc;
|
||||
std::string ue_category_str;
|
||||
nas_args_t nas;
|
||||
gw_args_t gw;
|
||||
} stack_args_t;
|
||||
|
||||
class ue_stack_interface
|
||||
{
|
||||
public:
|
||||
virtual bool init(stack_args_t args_, srslte::logger* logger_) = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual bool switch_on() = 0;
|
||||
virtual bool switch_off() = 0;
|
||||
|
||||
virtual bool get_metrics(ue_metrics_t* metrics) = 0;
|
||||
|
||||
virtual bool is_rrc_connected() = 0;
|
||||
};
|
||||
|
||||
} // namespace srsue
|
||||
|
||||
#endif // SRSUE_UE_STACK_INTERFACE_H
|
@ -0,0 +1,27 @@
|
||||
#
|
||||
# Copyright 2013-2019 Software Radio Systems Limited
|
||||
#
|
||||
# This file is part of srsLTE
|
||||
#
|
||||
# srsLTE is free software: you can redistribute it and/or modify
|
||||
# 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.
|
||||
#
|
||||
# srsLTE is distributed in the hope that it will be useful,
|
||||
# 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.
|
||||
#
|
||||
# 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/.
|
||||
#
|
||||
|
||||
set(SOURCES ue_radio.cc)
|
||||
|
||||
add_library(srsue_radio STATIC ${SOURCES})
|
||||
|
||||
target_link_libraries(srsue_radio srslte_radio)
|
||||
|
||||
install(TARGETS srsue_radio DESTINATION ${LIBRARY_DIR})
|
@ -0,0 +1,192 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* 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.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "srsue/hdr/radio/ue_radio.h"
|
||||
#include <mutex>
|
||||
|
||||
using namespace srslte;
|
||||
|
||||
namespace srsue {
|
||||
|
||||
std::mutex instance_mutex;
|
||||
static ue_radio* instance;
|
||||
|
||||
ue_radio::ue_radio() : args(), logger(nullptr), running(false), phy(nullptr), rf_metrics(), radios()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(instance_mutex);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
ue_radio::~ue_radio()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
std::string ue_radio::get_type()
|
||||
{
|
||||
return "radio";
|
||||
}
|
||||
|
||||
int ue_radio::init(const rf_args_t& args_, srslte::logger* logger_, phy_interface_radio* phy_)
|
||||
{
|
||||
if (init(args_, logger_)) {
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
|
||||
phy = phy_;
|
||||
|
||||
return SRSLTE_SUCCESS;
|
||||
}
|
||||
|
||||
int ue_radio::init(const rf_args_t& args_, srslte::logger* logger_)
|
||||
{
|
||||
args = args_;
|
||||
logger = logger_;
|
||||
|
||||
// Init log
|
||||
log.init("RF ", logger);
|
||||
log.set_level(args.log_level);
|
||||
|
||||
if (args.nof_radios > SRSLTE_MAX_RADIOS) {
|
||||
log.error("Maximum supported number of radios exceeded (%d > %d)\n", args.nof_radios, SRSLTE_MAX_RADIOS);
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
|
||||
// Init and start Radio
|
||||
char* dev_name = NULL;
|
||||
if (args.device_name.compare("auto")) {
|
||||
dev_name = (char*)args.device_name.c_str();
|
||||
}
|
||||
|
||||
char* dev_args[SRSLTE_MAX_RADIOS] = {NULL};
|
||||
for (int i = 0; i < SRSLTE_MAX_RADIOS; i++) {
|
||||
if (args.device_args[0].compare("auto")) {
|
||||
dev_args[i] = (char*)args.device_args[i].c_str();
|
||||
}
|
||||
}
|
||||
|
||||
log.console(
|
||||
"Opening %d RF devices with %d RF channels...\n", args.nof_radios, args.nof_rf_channels * args.nof_rx_ant);
|
||||
for (uint32_t r = 0; r < args.nof_radios; r++) {
|
||||
std::unique_ptr<srslte::radio> radio = std::unique_ptr<srslte::radio>(new srslte::radio());
|
||||
if (!radio->init(&log, dev_args[r], dev_name, args.nof_rf_channels * args.nof_rx_ant)) {
|
||||
log.console("Failed to find device %s with args %s\n", args.device_name.c_str(), args.device_args[0].c_str());
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
|
||||
// Set RF options
|
||||
if (args.time_adv_nsamples.compare("auto")) {
|
||||
int t = atoi(args.time_adv_nsamples.c_str());
|
||||
radio->set_tx_adv(abs(t));
|
||||
radio->set_tx_adv_neg(t < 0);
|
||||
}
|
||||
if (args.burst_preamble.compare("auto")) {
|
||||
radio->set_burst_preamble(atof(args.burst_preamble.c_str()));
|
||||
}
|
||||
if (args.continuous_tx.compare("auto")) {
|
||||
log.console("set continuous %s\n", args.continuous_tx.c_str());
|
||||
radio->set_continuous_tx(args.continuous_tx.compare("yes") ? false : true);
|
||||
}
|
||||
|
||||
// Set PHY options
|
||||
if (args.rx_gain < 0) {
|
||||
radio->start_agc(false);
|
||||
} else {
|
||||
radio->set_rx_gain(args.rx_gain);
|
||||
}
|
||||
if (args.tx_gain > 0) {
|
||||
radio->set_tx_gain(args.tx_gain);
|
||||
} else {
|
||||
radio->set_tx_gain(args.rx_gain);
|
||||
log.console("\nWarning: TX gain was not set. Using open-loop power control (not working properly)\n\n");
|
||||
}
|
||||
|
||||
radio->register_error_handler(rf_msg);
|
||||
radio->set_freq_offset(args.freq_offset);
|
||||
|
||||
// append to radios
|
||||
radios.push_back(std::move(radio));
|
||||
}
|
||||
|
||||
running = true;
|
||||
|
||||
return SRSLTE_SUCCESS;
|
||||
}
|
||||
|
||||
void ue_radio::stop()
|
||||
{
|
||||
if (running) {
|
||||
std::lock_guard<std::mutex> lock(instance_mutex);
|
||||
instance = nullptr;
|
||||
|
||||
for (auto& radio : radios) {
|
||||
radio->stop();
|
||||
}
|
||||
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ue_radio::get_metrics(rf_metrics_t* metrics)
|
||||
{
|
||||
*metrics = rf_metrics;
|
||||
rf_metrics = {};
|
||||
return true;
|
||||
}
|
||||
|
||||
void ue_radio::rf_msg(srslte_rf_error_t error)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(instance_mutex);
|
||||
if (instance) {
|
||||
instance->handle_rf_msg(error);
|
||||
}
|
||||
}
|
||||
|
||||
void ue_radio::handle_rf_msg(srslte_rf_error_t error)
|
||||
{
|
||||
if (error.type == srslte_rf_error_t::SRSLTE_RF_ERROR_OVERFLOW) {
|
||||
rf_metrics.rf_o++;
|
||||
rf_metrics.rf_error = true;
|
||||
log.info("Overflow\n");
|
||||
|
||||
// inform PHY about overflow
|
||||
phy->radio_overflow();
|
||||
} else if (error.type == srslte_rf_error_t::SRSLTE_RF_ERROR_UNDERFLOW) {
|
||||
rf_metrics.rf_u++;
|
||||
rf_metrics.rf_error = true;
|
||||
log.info("Underflow\n");
|
||||
} else if (error.type == srslte_rf_error_t::SRSLTE_RF_ERROR_LATE) {
|
||||
rf_metrics.rf_l++;
|
||||
rf_metrics.rf_error = true;
|
||||
log.info("Late (detected in %s)\n", error.opt ? "rx call" : "asynchronous thread");
|
||||
} else if (error.type == srslte_rf_error_t::SRSLTE_RF_ERROR_RX) {
|
||||
log.error("Fatal radio error occured.\n");
|
||||
phy->radio_failure();
|
||||
} else if (error.type == srslte_rf_error_t::SRSLTE_RF_ERROR_OTHER) {
|
||||
std::string str(error.msg);
|
||||
str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());
|
||||
str.erase(std::remove(str.begin(), str.end(), '\r'), str.end());
|
||||
str.push_back('\n');
|
||||
log.info("%s\n", str.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace srsue
|
@ -0,0 +1,31 @@
|
||||
#
|
||||
# Copyright 2013-2019 Software Radio Systems Limited
|
||||
#
|
||||
# This file is part of srsLTE
|
||||
#
|
||||
# srsLTE is free software: you can redistribute it and/or modify
|
||||
# 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.
|
||||
#
|
||||
# srsLTE is distributed in the hope that it will be useful,
|
||||
# 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.
|
||||
#
|
||||
# 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/.
|
||||
#
|
||||
|
||||
add_subdirectory(mac)
|
||||
add_subdirectory(rrc)
|
||||
add_subdirectory(upper)
|
||||
|
||||
set(SOURCES ue_stack_lte.cc)
|
||||
|
||||
add_library(srsue_stack STATIC ${SOURCES})
|
||||
target_link_libraries(srsue_stack)
|
||||
|
||||
install(TARGETS srsue_stack DESTINATION ${LIBRARY_DIR})
|
||||
|
@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* 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.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "srsue/hdr/stack/ue_stack_lte.h"
|
||||
#include "srslte/srslte.h"
|
||||
|
||||
using namespace srslte;
|
||||
|
||||
namespace srsue {
|
||||
|
||||
ue_stack_lte::ue_stack_lte() : running(false), args(), logger(nullptr), usim(nullptr), phy(nullptr) {}
|
||||
|
||||
ue_stack_lte::~ue_stack_lte()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
std::string ue_stack_lte::get_type()
|
||||
{
|
||||
return "lte";
|
||||
}
|
||||
|
||||
int ue_stack_lte::init(const stack_args_t& args_, srslte::logger* logger_, phy_interface_stack_lte* phy_)
|
||||
{
|
||||
phy = phy_;
|
||||
|
||||
if (init(args_, logger_)) {
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
|
||||
return SRSLTE_SUCCESS;
|
||||
}
|
||||
|
||||
int ue_stack_lte::init(const stack_args_t& args_, srslte::logger* logger_)
|
||||
{
|
||||
args = args_;
|
||||
logger = logger_;
|
||||
|
||||
// setup logging for each layer
|
||||
mac_log.init("MAC ", logger, true);
|
||||
rlc_log.init("RLC ", logger);
|
||||
pdcp_log.init("PDCP", logger);
|
||||
rrc_log.init("RRC ", logger);
|
||||
nas_log.init("NAS ", logger);
|
||||
gw_log.init("GW ", logger);
|
||||
usim_log.init("USIM", logger);
|
||||
|
||||
pool_log.init("POOL", logger);
|
||||
pool_log.set_level(srslte::LOG_LEVEL_ERROR);
|
||||
byte_buffer_pool::get_instance()->set_log(&pool_log);
|
||||
|
||||
mac_log.set_level(args.log.mac_level);
|
||||
rlc_log.set_level(args.log.rlc_level);
|
||||
pdcp_log.set_level(args.log.pdcp_level);
|
||||
rrc_log.set_level(args.log.rrc_level);
|
||||
nas_log.set_level(args.log.nas_level);
|
||||
gw_log.set_level(args.log.gw_level);
|
||||
usim_log.set_level(args.log.usim_level);
|
||||
|
||||
mac_log.set_hex_limit(args.log.mac_hex_limit);
|
||||
rlc_log.set_hex_limit(args.log.rlc_hex_limit);
|
||||
pdcp_log.set_hex_limit(args.log.pdcp_hex_limit);
|
||||
rrc_log.set_hex_limit(args.log.rrc_hex_limit);
|
||||
nas_log.set_hex_limit(args.log.nas_hex_limit);
|
||||
gw_log.set_hex_limit(args.log.gw_hex_limit);
|
||||
usim_log.set_hex_limit(args.log.usim_hex_limit);
|
||||
|
||||
// Set up pcap
|
||||
if (args.pcap.enable) {
|
||||
mac_pcap.open(args.pcap.filename.c_str());
|
||||
mac.start_pcap(&mac_pcap);
|
||||
}
|
||||
if (args.pcap.nas_enable) {
|
||||
nas_pcap.open(args.pcap.nas_filename.c_str());
|
||||
nas.start_pcap(&nas_pcap);
|
||||
}
|
||||
|
||||
// Init USIM first to allow early exit in case reader couldn't be found
|
||||
usim = usim_base::get_instance(&args.usim);
|
||||
if (usim->init(&args.usim, &usim_log)) {
|
||||
usim_log.console("Failed to initialize USIM.\n");
|
||||
return SRSLTE_ERROR;
|
||||
}
|
||||
|
||||
mac.init(phy, &rlc, &rrc, &mac_log);
|
||||
rlc.init(&pdcp, &rrc, NULL, &rlc_log, &mac, 0 /* RB_ID_SRB0 */);
|
||||
pdcp.init(&rlc, &rrc, &gw, &pdcp_log, 0 /* RB_ID_SRB0 */, SECURITY_DIRECTION_UPLINK);
|
||||
nas.init(usim, &rrc, &gw, &nas_log, args.nas);
|
||||
gw.init(&pdcp, &nas, &gw_log, args.gw);
|
||||
rrc.init(phy, &mac, &rlc, &pdcp, &nas, usim, &gw, &mac, &rrc_log, args.rrc);
|
||||
|
||||
running = true;
|
||||
|
||||
return SRSLTE_SUCCESS;
|
||||
}
|
||||
|
||||
void ue_stack_lte::stop()
|
||||
{
|
||||
if (running) {
|
||||
usim->stop();
|
||||
nas.stop();
|
||||
rrc.stop();
|
||||
|
||||
// Caution here order of stop is very important to avoid locks
|
||||
|
||||
// Stop RLC and PDCP before GW to avoid locking on queue
|
||||
rlc.stop();
|
||||
pdcp.stop();
|
||||
gw.stop();
|
||||
mac.stop();
|
||||
|
||||
if (args.pcap.enable) {
|
||||
mac_pcap.close();
|
||||
}
|
||||
if (args.pcap.nas_enable) {
|
||||
nas_pcap.close();
|
||||
}
|
||||
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ue_stack_lte::switch_on()
|
||||
{
|
||||
if (running) {
|
||||
return nas.attach_request();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ue_stack_lte::switch_off()
|
||||
{
|
||||
// generate detach request
|
||||
nas.detach_request();
|
||||
|
||||
// wait for max. 5s for it to be sent (according to TS 24.301 Sec 25.5.2.2)
|
||||
const uint32_t RB_ID_SRB1 = 1;
|
||||
int cnt = 0, timeout = 5;
|
||||
while (rlc.has_data(RB_ID_SRB1) && ++cnt <= timeout) {
|
||||
sleep(1);
|
||||
}
|
||||
bool detach_sent = true;
|
||||
if (rlc.has_data(RB_ID_SRB1)) {
|
||||
nas_log.warning("Detach couldn't be sent after %ds.\n", timeout);
|
||||
detach_sent = false;
|
||||
}
|
||||
|
||||
return detach_sent;
|
||||
}
|
||||
|
||||
bool ue_stack_lte::get_metrics(stack_metrics_t* metrics)
|
||||
{
|
||||
if (EMM_STATE_REGISTERED == nas.get_state()) {
|
||||
if (RRC_STATE_CONNECTED == rrc.get_state()) {
|
||||
mac.get_metrics(metrics->mac);
|
||||
rlc.get_metrics(metrics->rlc);
|
||||
gw.get_metrics(metrics->gw);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ue_stack_lte::is_rrc_connected()
|
||||
{
|
||||
return rrc.is_connected();
|
||||
}
|
||||
|
||||
}
|
@ -1,144 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2019 Software Radio Systems Limited
|
||||
*
|
||||
* This file is part of srsLTE.
|
||||
*
|
||||
* srsLTE is free software: you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* srsLTE is distributed in the hope that it will be useful,
|
||||
* 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.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "srsue/hdr/ue_base.h"
|
||||
#include "srsue/hdr/ue.h"
|
||||
#include "srslte/srslte.h"
|
||||
#include "srslte/build_info.h"
|
||||
#include <pthread.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
using namespace srslte;
|
||||
|
||||
namespace srsue {
|
||||
|
||||
static ue_base* instance = NULL;
|
||||
pthread_mutex_t ue_instance_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
ue_base* ue_base::get_instance(srsue_instance_type_t type)
|
||||
{
|
||||
pthread_mutex_lock(&ue_instance_mutex);
|
||||
if(NULL == instance) {
|
||||
switch (type) {
|
||||
case LTE:
|
||||
instance = new ue();
|
||||
break;
|
||||
default:
|
||||
perror("Unknown UE type.\n");
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&ue_instance_mutex);
|
||||
return(instance);
|
||||
}
|
||||
|
||||
ue_base::ue_base() {
|
||||
// print build info
|
||||
std::cout << std::endl << get_build_string() << std::endl;
|
||||
|
||||
// load FFTW wisdom
|
||||
srslte_dft_load();
|
||||
|
||||
pool = byte_buffer_pool::get_instance();
|
||||
}
|
||||
|
||||
ue_base::~ue_base() {
|
||||
byte_buffer_pool::cleanup();
|
||||
}
|
||||
|
||||
void ue_base::cleanup(void)
|
||||
{
|
||||
// save FFTW wisdom
|
||||
srslte_dft_exit();
|
||||
|
||||
pthread_mutex_lock(&ue_instance_mutex);
|
||||
if(NULL != instance) {
|
||||
delete instance;
|
||||
instance = NULL;
|
||||
}
|
||||
pthread_mutex_unlock(&ue_instance_mutex);
|
||||
}
|
||||
|
||||
void ue_base::handle_rf_msg(srslte_rf_error_t error)
|
||||
{
|
||||
if(error.type == srslte_rf_error_t::SRSLTE_RF_ERROR_OVERFLOW) {
|
||||
rf_metrics.rf_o++;
|
||||
rf_metrics.rf_error = true;
|
||||
rf_log.warning("Overflow\n");
|
||||
}else if(error.type == srslte_rf_error_t::SRSLTE_RF_ERROR_UNDERFLOW) {
|
||||
rf_metrics.rf_u++;
|
||||
rf_metrics.rf_error = true;
|
||||
rf_log.warning("Underflow\n");
|
||||
} else if(error.type == srslte_rf_error_t::SRSLTE_RF_ERROR_LATE) {
|
||||
rf_metrics.rf_l++;
|
||||
rf_metrics.rf_error = true;
|
||||
rf_log.warning("Late (detected in %s)\n", error.opt?"rx call":"asynchronous thread");
|
||||
} else if (error.type == srslte_rf_error_t::SRSLTE_RF_ERROR_OTHER) {
|
||||
std::string str(error.msg);
|
||||
str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());
|
||||
str.erase(std::remove(str.begin(), str.end(), '\r'), str.end());
|
||||
str.push_back('\n');
|
||||
rf_log.info("%s\n", str.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
srslte::LOG_LEVEL_ENUM ue_base::level(std::string l)
|
||||
{
|
||||
std::transform(l.begin(), l.end(), l.begin(), ::toupper);
|
||||
if("NONE" == l){
|
||||
return srslte::LOG_LEVEL_NONE;
|
||||
}else if("ERROR" == l){
|
||||
return srslte::LOG_LEVEL_ERROR;
|
||||
}else if("WARNING" == l){
|
||||
return srslte::LOG_LEVEL_WARNING;
|
||||
}else if("INFO" == l){
|
||||
return srslte::LOG_LEVEL_INFO;
|
||||
}else if("DEBUG" == l){
|
||||
return srslte::LOG_LEVEL_DEBUG;
|
||||
}else{
|
||||
return srslte::LOG_LEVEL_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
std::string ue_base::get_build_mode()
|
||||
{
|
||||
return std::string(srslte_get_build_mode());
|
||||
}
|
||||
|
||||
std::string ue_base::get_build_info()
|
||||
{
|
||||
if (std::string(srslte_get_build_info()).find(" ") != std::string::npos) {
|
||||
return std::string(srslte_get_version());
|
||||
}
|
||||
return std::string(srslte_get_build_info());
|
||||
}
|
||||
|
||||
std::string ue_base::get_build_string()
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Built in " << get_build_mode() << " mode using " << get_build_info() << "." << std::endl;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
} // namespace srsue
|
Loading…
Reference in New Issue