srsLTE/srsenb/hdr/stack/mac/ue.h

169 lines
6.3 KiB
C
Raw Normal View History

2019-04-26 12:27:38 -07:00
/*
2020-03-13 04:12:52 -07:00
* Copyright 2013-2020 Software Radio Systems Limited
2017-06-02 03:46:06 -07:00
*
* This file is part of srsLTE.
*
2019-04-26 12:27:38 -07:00
* srsLTE is free software: you can redistribute it and/or modify
2017-06-02 03:46:06 -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.
*
2019-04-26 12:27:38 -07:00
* srsLTE is distributed in the hope that it will be useful,
2017-06-02 03:46:06 -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.
*
* 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/.
*
*/
2017-06-01 03:25:57 -07:00
2018-03-31 10:04:04 -07:00
#ifndef SRSENB_UE_H
#define SRSENB_UE_H
2017-06-01 03:25:57 -07:00
#include "mac_metrics.h"
#include "srslte/common/block_queue.h"
2017-06-01 03:25:57 -07:00
#include "srslte/common/log.h"
#include "srslte/common/mac_pcap.h"
#include "srslte/common/pdu.h"
2017-06-01 03:25:57 -07:00
#include "srslte/common/pdu_queue.h"
#include "srslte/interfaces/enb_interfaces.h"
#include "srslte/interfaces/sched_interface.h"
2020-03-13 05:10:29 -07:00
#include "ta.h"
2017-06-01 03:25:57 -07:00
#include <pthread.h>
#include <vector>
2017-06-01 03:25:57 -07:00
namespace srsenb {
2020-03-13 05:10:29 -07:00
class ue : public srslte::read_pdu_interface, public srslte::pdu_queue::process_callback, public mac_ta_ue_interface
2017-06-01 03:25:57 -07:00
{
public:
2020-03-11 09:31:14 -07:00
ue(uint16_t rnti,
uint32_t nof_prb,
sched_interface* sched,
rrc_interface_mac* rrc_,
rlc_interface_mac* rlc,
phy_interface_stack_lte* phy_,
srslte::log* log_,
uint32_t nof_rx_harq_proc = SRSLTE_FDD_NOF_HARQ,
uint32_t nof_tx_harq_proc = SRSLTE_FDD_NOF_HARQ * SRSLTE_MAX_TB);
2019-04-23 01:53:11 -07:00
virtual ~ue();
void reset();
void start_pcap(srslte::mac_pcap* pcap_);
void set_tti(uint32_t tti);
2020-03-13 05:10:29 -07:00
uint32_t set_ta(int ta) override;
uint32_t set_ta_us(float ta_us) { return ta_fsm.push_value(ta_us); };
uint32_t tick_ta_fsm() { return ta_fsm.tick(); };
void config(uint16_t rnti,
uint32_t nof_prb,
sched_interface* sched,
rrc_interface_mac* rrc_,
rlc_interface_mac* rlc,
srslte::log* log_h);
uint8_t* generate_pdu(uint32_t ue_cc_idx,
uint32_t harq_pid,
uint32_t tb_idx,
sched_interface::dl_sched_pdu_t pdu[sched_interface::MAX_RLC_PDU_LIST],
uint32_t nof_pdu_elems,
uint32_t grant_size);
uint8_t*
generate_mch_pdu(uint32_t harq_pid, sched_interface::dl_pdu_mch_t sched, uint32_t nof_pdu_elems, uint32_t grant_size);
srslte_softbuffer_tx_t*
get_tx_softbuffer(const uint32_t ue_cc_idx, const uint32_t harq_process, const uint32_t tb_idx);
srslte_softbuffer_rx_t* get_rx_softbuffer(const uint32_t ue_cc_idx, const uint32_t tti);
2019-04-26 06:57:50 -07:00
2019-04-23 01:53:11 -07:00
bool process_pdus();
uint8_t* request_buffer(const uint32_t ue_cc_idx, const uint32_t tti, const uint32_t len);
2019-04-23 01:53:11 -07:00
void process_pdu(uint8_t* pdu, uint32_t nof_bytes, srslte::pdu_queue::channel_t channel);
void push_pdu(const uint32_t ue_cc_idx, const uint32_t tti, uint32_t len);
void deallocate_pdu(const uint32_t ue_cc_idx, const uint32_t tti);
2017-06-01 03:25:57 -07:00
uint32_t rl_failure();
void rl_failure_reset();
void set_lcg(uint32_t lcid, uint32_t lcg);
2017-06-01 03:25:57 -07:00
void metrics_read(srsenb::mac_metrics_t* metrics);
void metrics_rx(bool crc, uint32_t tbs);
void metrics_tx(bool crc, uint32_t tbs);
2017-09-05 06:26:36 -07:00
void metrics_phr(float phr);
void metrics_dl_ri(uint32_t dl_cqi);
void metrics_dl_pmi(uint32_t dl_cqi);
2017-09-05 06:26:36 -07:00
void metrics_dl_cqi(uint32_t dl_cqi);
void metrics_cnt();
2017-09-05 06:26:36 -07:00
bool is_phy_added = false;
int read_pdu(uint32_t lcid, uint8_t* payload, uint32_t requested_bytes);
private:
uint32_t allocate_cc_buffers(const uint32_t num_cc = 1); ///< Add and initialize softbuffers for CC
void allocate_sdu(srslte::sch_pdu* pdu, uint32_t lcid, uint32_t sdu_len);
bool process_ce(srslte::sch_subh* subh);
void allocate_ce(srslte::sch_pdu* pdu, uint32_t lcid);
std::vector<uint32_t> lc_groups[4];
2017-09-05 06:26:36 -07:00
uint32_t phr_counter = 0;
uint32_t dl_cqi_counter = 0;
uint32_t dl_ri_counter = 0;
uint32_t dl_pmi_counter = 0;
mac_metrics_t metrics = {};
srslte::mac_pcap* pcap = nullptr;
uint64_t conres_id = 0;
uint16_t rnti = 0;
uint32_t nof_prb = 0;
uint32_t last_tti = 0;
uint32_t nof_failures = 0;
int nof_rx_harq_proc = 0;
int nof_tx_harq_proc = 0;
typedef std::vector<srslte_softbuffer_tx_t>
cc_softbuffer_tx_list_t; ///< List of Tx softbuffers for all HARQ processes of one carrier
std::vector<cc_softbuffer_tx_list_t> softbuffer_tx; ///< List of softbuffer lists for Tx
typedef std::vector<srslte_softbuffer_rx_t>
cc_softbuffer_rx_list_t; ///< List of Rx softbuffers for all HARQ processes of one carrier
std::vector<cc_softbuffer_rx_list_t> softbuffer_rx; ///< List of softbuffer lists for Rx
typedef std::vector<uint8_t*> cc_buffer_ptr_t; ///< List of buffer pointers for RX HARQ processes of one carrier
std::vector<cc_buffer_ptr_t> pending_buffers; ///< List of buffer pointer list for Rx
2017-06-01 03:25:57 -07:00
// For DL there are two buffers, one for each Transport block
srslte::byte_buffer_t tx_payload_buffer[SRSLTE_MAX_CARRIERS][SRSLTE_FDD_NOF_HARQ][SRSLTE_MAX_TB];
srslte::block_queue<uint32_t> pending_ta_commands;
2020-03-13 05:10:29 -07:00
ta ta_fsm;
2017-06-01 03:25:57 -07:00
// For UL there are multiple buffers per PID and are managed by pdu_queue
srslte::pdu_queue pdus;
srslte::sch_pdu mac_msg_dl, mac_msg_ul;
srslte::mch_pdu mch_mac_msg_dl;
2020-03-11 09:31:14 -07:00
rlc_interface_mac* rlc = nullptr;
rrc_interface_mac* rrc = nullptr;
phy_interface_stack_lte* phy = nullptr;
srslte::log* log_h = nullptr;
sched_interface* sched = nullptr;
bool conres_id_available = false;
2017-06-01 03:25:57 -07:00
// Mutexes
std::mutex mutex;
2020-03-04 01:49:51 -08:00
const uint8_t UL_CC_IDX = 0; ///< Passed to write CC index in PCAP (TODO: use actual CC idx)
2017-06-01 03:25:57 -07:00
};
} // namespace srsenb
2017-06-01 03:25:57 -07:00
2018-03-31 10:04:04 -07:00
#endif // SRSENB_UE_H