2020-11-26 01:25:22 -08:00
|
|
|
/**
|
2019-11-14 12:29:17 -08:00
|
|
|
*
|
2020-11-26 01:25:22 -08:00
|
|
|
* \section COPYRIGHT
|
2019-11-14 12:29:17 -08:00
|
|
|
*
|
2021-03-19 03:45:56 -07:00
|
|
|
* Copyright 2013-2021 Software Radio Systems Limited
|
2019-11-14 12:29:17 -08:00
|
|
|
*
|
2020-11-26 01:25:22 -08: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.
|
2019-11-14 12:29:17 -08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-03-19 03:45:56 -07:00
|
|
|
#ifndef SRSRAN_RLC_AM_NR_H
|
|
|
|
#define SRSRAN_RLC_AM_NR_H
|
2019-11-14 12:29:17 -08:00
|
|
|
|
2021-03-19 03:45:56 -07:00
|
|
|
#include "srsran/common/buffer_pool.h"
|
|
|
|
#include "srsran/common/common.h"
|
2021-10-01 03:38:33 -07:00
|
|
|
#include "srsran/common/timers.h"
|
2022-02-18 07:15:40 -08:00
|
|
|
#include "srsran/interfaces/pdcp_interface_types.h"
|
2021-06-25 06:24:56 -07:00
|
|
|
#include "srsran/rlc/rlc_am_base.h"
|
2021-08-04 04:43:41 -07:00
|
|
|
#include "srsran/rlc/rlc_am_data_structs.h"
|
|
|
|
#include "srsran/rlc/rlc_am_nr_packing.h"
|
2021-03-19 03:45:56 -07:00
|
|
|
#include "srsran/upper/byte_buffer_queue.h"
|
2019-11-14 12:29:17 -08:00
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <queue>
|
|
|
|
|
2021-03-19 03:45:56 -07:00
|
|
|
namespace srsran {
|
2019-11-14 12:29:17 -08:00
|
|
|
|
2021-07-23 05:13:10 -07:00
|
|
|
/******************************
|
|
|
|
*
|
|
|
|
* RLC AM NR entity
|
|
|
|
*
|
|
|
|
*****************************/
|
2021-11-10 10:12:47 -08:00
|
|
|
class rlc_am_nr_tx;
|
|
|
|
class rlc_am_nr_rx;
|
|
|
|
|
2021-11-19 08:44:52 -08:00
|
|
|
/****************************************************************************
|
|
|
|
* Tx state variables
|
2021-12-10 04:21:08 -08:00
|
|
|
* Ref: 3GPP TS 38.322 version 16.2.0 Section 7.1
|
2021-11-19 08:44:52 -08:00
|
|
|
***************************************************************************/
|
|
|
|
struct rlc_am_nr_tx_state_t {
|
|
|
|
/*
|
|
|
|
* TX_Next_Ack: This state variable holds the value of the SN of the next RLC SDU for which a positive
|
|
|
|
* acknowledgment is to be received in-sequence, and it serves as the lower edge of the transmitting window. It is
|
|
|
|
* initially set to 0, and is updated whenever the AM RLC entity receives a positive acknowledgment for an RLC SDU
|
|
|
|
* with SN = TX_Next_Ack.
|
|
|
|
*/
|
|
|
|
uint32_t tx_next_ack;
|
|
|
|
/*
|
|
|
|
* TX_Next: This state variable holds the value of the SN to be assigned for the next newly generated AMD PDU. It is
|
|
|
|
* initially set to 0, and is updated whenever the AM RLC entity constructs an AMD PDU with SN = TX_Next and
|
|
|
|
* contains an RLC SDU or the last segment of a RLC SDU.
|
|
|
|
*/
|
|
|
|
uint32_t tx_next;
|
|
|
|
/*
|
|
|
|
* POLL_SN: This state variable holds the value of the highest SN of the AMD PDU among the AMD PDUs submitted to
|
|
|
|
* lower layer when POLL_SN is set according to sub clause 5.3.3.2. It is initially set to 0.
|
|
|
|
*/
|
|
|
|
uint32_t poll_sn;
|
|
|
|
/*
|
|
|
|
* PDU_WITHOUT_POLL: This counter is initially set to 0. It counts the number of AMD PDUs sent since the most recent
|
|
|
|
* poll bit was transmitted.
|
|
|
|
*/
|
|
|
|
uint32_t pdu_without_poll;
|
|
|
|
/*
|
|
|
|
* BYTE_WITHOUT_POLL: This counter is initially set to 0. It counts the number of data bytes sent since the most
|
|
|
|
* recent poll bit was transmitted.
|
|
|
|
*/
|
|
|
|
uint32_t byte_without_poll;
|
|
|
|
};
|
|
|
|
|
2021-12-01 02:40:06 -08:00
|
|
|
struct rlc_amd_tx_pdu_nr {
|
|
|
|
const uint32_t rlc_sn = INVALID_RLC_SN;
|
2022-02-18 07:15:40 -08:00
|
|
|
uint32_t pdcp_sn = INVALID_RLC_SN;
|
2021-12-01 02:40:06 -08:00
|
|
|
rlc_am_nr_pdu_header_t header = {};
|
2022-01-19 04:14:50 -08:00
|
|
|
unique_byte_buffer_t sdu_buf = nullptr;
|
2022-02-24 02:50:42 -08:00
|
|
|
uint32_t retx_count = RETX_COUNT_NOT_STARTED;
|
2021-12-01 02:40:06 -08:00
|
|
|
struct pdu_segment {
|
|
|
|
uint32_t so = 0;
|
|
|
|
uint32_t payload_len = 0;
|
|
|
|
};
|
|
|
|
std::list<pdu_segment> segment_list;
|
|
|
|
explicit rlc_amd_tx_pdu_nr(uint32_t sn) : rlc_sn(sn) {}
|
|
|
|
};
|
|
|
|
|
2021-11-10 09:31:56 -08:00
|
|
|
class rlc_am_nr_tx : public rlc_am::rlc_am_base_tx
|
2021-06-28 10:52:58 -07:00
|
|
|
{
|
|
|
|
public:
|
2021-11-10 09:31:56 -08:00
|
|
|
explicit rlc_am_nr_tx(rlc_am* parent_);
|
|
|
|
~rlc_am_nr_tx() = default;
|
|
|
|
|
2021-11-10 10:12:47 -08:00
|
|
|
void set_rx(rlc_am_nr_rx* rx_) { rx = rx_; }
|
2021-11-10 09:31:56 -08:00
|
|
|
bool configure(const rlc_config_t& cfg_) final;
|
|
|
|
uint32_t read_pdu(uint8_t* payload, uint32_t nof_bytes) final;
|
|
|
|
void handle_control_pdu(uint8_t* payload, uint32_t nof_bytes) final;
|
|
|
|
|
|
|
|
bool sdu_queue_is_full() final;
|
|
|
|
void reestablish() final;
|
|
|
|
|
2021-11-24 02:12:35 -08:00
|
|
|
int write_sdu(unique_byte_buffer_t sdu);
|
|
|
|
void empty_queue() final;
|
|
|
|
|
|
|
|
// Data PDU helpers
|
2022-01-19 09:11:56 -08:00
|
|
|
uint32_t build_new_pdu(uint8_t* payload, uint32_t nof_bytes);
|
|
|
|
uint32_t build_new_sdu_segment(rlc_amd_tx_pdu_nr& tx_pdu, uint8_t* payload, uint32_t nof_bytes);
|
|
|
|
uint32_t build_continuation_sdu_segment(rlc_amd_tx_pdu_nr& tx_pdu, uint8_t* payload, uint32_t nof_bytes);
|
|
|
|
uint32_t build_retx_pdu(uint8_t* payload, uint32_t nof_bytes);
|
2022-03-15 03:53:55 -07:00
|
|
|
uint32_t build_retx_pdu_without_segmentation(rlc_amd_retx_nr_t retx, uint8_t* payload, uint32_t nof_bytes);
|
2022-03-07 06:01:57 -08:00
|
|
|
uint32_t build_retx_pdu_with_segmentation(rlc_amd_retx_nr_t& retx, uint8_t* payload, uint32_t nof_bytes);
|
|
|
|
bool is_retx_segmentation_required(const rlc_amd_retx_nr_t& retx, uint32_t nof_bytes);
|
|
|
|
uint32_t get_retx_expected_hdr_len(const rlc_amd_retx_nr_t& retx);
|
2022-02-07 03:57:35 -08:00
|
|
|
|
2021-11-24 02:12:35 -08:00
|
|
|
// Buffer State
|
2021-11-10 09:31:56 -08:00
|
|
|
bool has_data() final;
|
|
|
|
uint32_t get_buffer_state() final;
|
2021-10-21 05:39:54 -07:00
|
|
|
void get_buffer_state(uint32_t& tx_queue, uint32_t& prio_tx_queue) final;
|
2021-11-10 09:31:56 -08:00
|
|
|
|
2021-11-24 02:12:35 -08:00
|
|
|
// Status PDU
|
2021-09-27 09:43:14 -07:00
|
|
|
bool do_status();
|
|
|
|
uint32_t build_status_pdu(byte_buffer_t* payload, uint32_t nof_bytes);
|
|
|
|
|
2021-11-24 02:12:35 -08:00
|
|
|
// Polling
|
2022-03-11 07:02:14 -08:00
|
|
|
uint8_t get_pdu_poll(bool is_retx, uint32_t sdu_bytes);
|
2021-11-05 10:42:24 -07:00
|
|
|
|
2021-11-10 09:31:56 -08:00
|
|
|
void stop() final;
|
|
|
|
|
2022-02-14 03:13:44 -08:00
|
|
|
bool inside_tx_window(uint32_t sn) const;
|
2021-12-06 03:12:10 -08:00
|
|
|
|
2021-11-10 09:31:56 -08:00
|
|
|
private:
|
2021-11-10 10:12:47 -08:00
|
|
|
rlc_am* parent = nullptr;
|
|
|
|
rlc_am_nr_rx* rx = nullptr;
|
2021-11-10 09:31:56 -08:00
|
|
|
|
2022-03-11 01:34:41 -08:00
|
|
|
uint32_t mod_nr = cardinality(rlc_am_nr_sn_size_t());
|
2021-12-06 03:12:10 -08:00
|
|
|
inline uint32_t tx_mod_base_nr(uint32_t sn) const;
|
2022-02-24 02:50:42 -08:00
|
|
|
void check_sn_reached_max_retx(uint32_t sn);
|
2021-12-02 06:18:07 -08:00
|
|
|
|
2021-11-10 09:31:56 -08:00
|
|
|
/****************************************************************************
|
|
|
|
* Configurable parameters
|
2021-12-10 04:21:08 -08:00
|
|
|
* Ref: 3GPP TS 38.322 version 16.2.0 Section 7.4
|
2021-11-10 09:31:56 -08:00
|
|
|
***************************************************************************/
|
2021-10-12 02:47:00 -07:00
|
|
|
rlc_am_nr_config_t cfg = {};
|
2021-11-10 09:31:56 -08:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Tx state variables
|
2021-12-10 04:21:08 -08:00
|
|
|
* Ref: 3GPP TS 38.322 version 16.2.0 Section 7.1
|
2021-11-10 09:31:56 -08:00
|
|
|
***************************************************************************/
|
2022-03-08 09:55:03 -08:00
|
|
|
struct rlc_am_nr_tx_state_t st = {};
|
2022-03-11 21:21:43 -08:00
|
|
|
std::unique_ptr<rlc_ringbuffer_base<rlc_amd_tx_pdu_nr> > tx_window;
|
2021-11-30 08:26:19 -08:00
|
|
|
|
2022-03-11 22:44:51 -08:00
|
|
|
// Queues, buffers and container
|
2022-03-11 21:21:43 -08:00
|
|
|
std::unique_ptr<pdu_retx_queue_base<rlc_amd_retx_nr_t> > retx_queue;
|
2022-03-08 09:55:03 -08:00
|
|
|
uint32_t sdu_under_segmentation_sn = INVALID_RLC_SN; // SN of the SDU currently being segmented.
|
|
|
|
pdcp_sn_vector_t notify_info_vec;
|
2022-03-11 22:44:51 -08:00
|
|
|
rlc_am_nr_status_pdu_t tx_status;
|
2021-11-19 08:44:52 -08:00
|
|
|
|
2022-01-10 04:51:51 -08:00
|
|
|
// Helper constants
|
|
|
|
uint32_t min_hdr_size = 2;
|
|
|
|
uint32_t so_size = 2;
|
|
|
|
uint32_t max_hdr_size = 4;
|
|
|
|
|
2022-03-10 05:10:07 -08:00
|
|
|
/****************************************************************************
|
|
|
|
* Tx constants
|
|
|
|
* Ref: 3GPP TS 38.322 version 16.2.0 Section 7.2
|
|
|
|
***************************************************************************/
|
|
|
|
inline uint32_t tx_window_size() const;
|
|
|
|
|
2021-11-19 08:44:52 -08:00
|
|
|
public:
|
|
|
|
// Getters/Setters
|
2022-03-17 02:45:54 -07:00
|
|
|
void set_tx_state(const rlc_am_nr_tx_state_t& st_) { st = st_; } // This should only be used for testing.
|
|
|
|
rlc_am_nr_tx_state_t get_tx_state() { return st; } // This should only be used for testing.
|
|
|
|
uint32_t get_tx_window_utilization() { return tx_window->size(); } // This should only be used for testing.
|
2022-01-19 09:11:56 -08:00
|
|
|
|
|
|
|
// Debug Helper
|
2022-02-14 03:13:44 -08:00
|
|
|
void debug_state() const;
|
2021-11-10 09:31:56 -08:00
|
|
|
};
|
|
|
|
|
2021-12-03 08:09:21 -08:00
|
|
|
/****************************************************************************
|
2021-12-10 04:21:08 -08:00
|
|
|
* State Variables
|
|
|
|
* Ref: 3GPP TS 38.322 version 16.2.0 Section 7.1
|
2021-12-03 08:09:21 -08:00
|
|
|
***************************************************************************/
|
|
|
|
struct rlc_am_nr_rx_state_t {
|
|
|
|
/*
|
|
|
|
* RX_Next: This state variable holds the value of the SN following the last in-sequence completely received RLC
|
|
|
|
* SDU, and it serves as the lower edge of the receiving window. It is initially set to 0, and is updated whenever
|
|
|
|
* the AM RLC entity receives an RLC SDU with SN = RX_Next.
|
|
|
|
*/
|
|
|
|
uint32_t rx_next = 0;
|
|
|
|
/*
|
|
|
|
* RX_Next_Status_Trigger: This state variable holds the value of the SN following the SN of the RLC SDU which
|
|
|
|
* triggered t-Reassembly.
|
|
|
|
*/
|
|
|
|
uint32_t rx_next_status_trigger = 0;
|
|
|
|
/*
|
|
|
|
* RX_Next_Highest: This state variable holds the highest possible value of the SN which can be indicated by
|
|
|
|
*"ACK_SN" when a STATUS PDU needs to be constructed. It is initially set to 0.
|
|
|
|
*/
|
|
|
|
uint32_t rx_highest_status = 0;
|
|
|
|
/*
|
|
|
|
* RX_Next_Highest: This state variable holds the value of the SN following the SN of the RLC SDU with the
|
|
|
|
* highest SN among received RLC SDUs. It is initially set to 0.
|
|
|
|
*/
|
|
|
|
uint32_t rx_next_highest = 0;
|
|
|
|
};
|
|
|
|
|
2021-11-10 09:31:56 -08:00
|
|
|
// Receiver sub-class
|
|
|
|
class rlc_am_nr_rx : public rlc_am::rlc_am_base_rx
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit rlc_am_nr_rx(rlc_am* parent_);
|
|
|
|
~rlc_am_nr_rx() = default;
|
|
|
|
|
2021-11-10 10:12:47 -08:00
|
|
|
void set_tx(rlc_am_nr_tx* tx_) { tx = tx_; }
|
2021-11-10 09:31:56 -08:00
|
|
|
bool configure(const rlc_config_t& cfg_) final;
|
|
|
|
|
|
|
|
void handle_data_pdu(uint8_t* payload, uint32_t nof_bytes) final;
|
|
|
|
|
|
|
|
void stop();
|
|
|
|
void reestablish();
|
|
|
|
|
2021-09-27 09:43:14 -07:00
|
|
|
// Status PDU
|
|
|
|
bool get_do_status();
|
|
|
|
uint32_t get_status_pdu(rlc_am_nr_status_pdu_t* status, uint32_t len);
|
|
|
|
uint32_t get_status_pdu_length();
|
|
|
|
|
2021-10-04 09:19:22 -07:00
|
|
|
// Data handling methods
|
2021-12-01 10:48:15 -08:00
|
|
|
int handle_full_data_sdu(const rlc_am_nr_pdu_header_t& header, const uint8_t* payload, uint32_t nof_bytes);
|
|
|
|
int handle_segment_data_sdu(const rlc_am_nr_pdu_header_t& header, const uint8_t* payload, uint32_t nof_bytes);
|
2021-10-04 09:19:22 -07:00
|
|
|
bool inside_rx_window(uint32_t sn);
|
2021-11-19 10:09:46 -08:00
|
|
|
void write_to_upper_layers(uint32_t lcid, unique_byte_buffer_t sdu);
|
2022-02-14 03:13:44 -08:00
|
|
|
void insert_received_segment(rlc_amd_rx_pdu_nr segment, rlc_amd_rx_sdu_nr_t::segment_list_t& segment_list) const;
|
|
|
|
bool have_all_segments_been_received(const rlc_amd_rx_sdu_nr_t::segment_list_t& segment_list) const;
|
2021-10-04 09:19:22 -07:00
|
|
|
|
2021-10-21 05:39:54 -07:00
|
|
|
// Metrics
|
|
|
|
uint32_t get_sdu_rx_latency_ms() final;
|
|
|
|
uint32_t get_rx_buffered_bytes() final;
|
|
|
|
|
2021-10-14 03:45:37 -07:00
|
|
|
// Timers
|
|
|
|
void timer_expired(uint32_t timeout_id);
|
|
|
|
|
2021-10-04 09:19:22 -07:00
|
|
|
// Helpers
|
2022-02-14 03:13:44 -08:00
|
|
|
void debug_state() const;
|
2021-10-04 09:19:22 -07:00
|
|
|
|
2021-06-28 10:52:58 -07:00
|
|
|
private:
|
2021-11-10 09:31:56 -08:00
|
|
|
rlc_am* parent = nullptr;
|
2021-11-10 10:12:47 -08:00
|
|
|
rlc_am_nr_tx* tx = nullptr;
|
2021-11-10 09:31:56 -08:00
|
|
|
byte_buffer_pool* pool = nullptr;
|
|
|
|
|
2022-03-10 05:10:07 -08:00
|
|
|
uint32_t mod_nr = cardinality(rlc_am_nr_sn_size_t());
|
2021-12-03 09:22:17 -08:00
|
|
|
uint32_t rx_mod_base_nr(uint32_t sn) const;
|
2021-12-02 06:18:07 -08:00
|
|
|
|
2021-09-27 09:43:14 -07:00
|
|
|
// RX Window
|
2022-03-11 21:21:43 -08:00
|
|
|
std::unique_ptr<rlc_ringbuffer_base<rlc_amd_rx_sdu_nr_t> > rx_window;
|
2021-09-27 09:43:14 -07:00
|
|
|
|
|
|
|
// Mutexes
|
|
|
|
std::mutex mutex;
|
|
|
|
|
2021-10-21 05:39:54 -07:00
|
|
|
/****************************************************************************
|
|
|
|
* Rx timers
|
2021-12-10 04:21:08 -08:00
|
|
|
* Ref: 3GPP TS 38.322 version 16.2.0 Section 7.3
|
2021-10-21 05:39:54 -07:00
|
|
|
***************************************************************************/
|
|
|
|
srsran::timer_handler::unique_timer status_prohibit_timer;
|
|
|
|
srsran::timer_handler::unique_timer reassembly_timer;
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Configurable parameters
|
2021-12-10 04:21:08 -08:00
|
|
|
* Ref: 3GPP TS 38.322 version 16.2.0 Section 7.4
|
2021-10-21 05:39:54 -07:00
|
|
|
***************************************************************************/
|
|
|
|
rlc_am_nr_config_t cfg = {};
|
2021-12-03 08:09:21 -08:00
|
|
|
|
|
|
|
/****************************************************************************
|
2022-03-10 05:10:07 -08:00
|
|
|
* Rx state variables
|
2021-12-10 04:21:08 -08:00
|
|
|
* Ref: 3GPP TS 38.322 version 16.2.0 Section 7.1
|
2021-12-03 08:09:21 -08:00
|
|
|
***************************************************************************/
|
|
|
|
struct rlc_am_nr_rx_state_t st = {};
|
|
|
|
|
2022-03-10 05:10:07 -08:00
|
|
|
/****************************************************************************
|
|
|
|
* Rx constants
|
|
|
|
* Ref: 3GPP TS 38.322 version 16.2.0 Section 7.2
|
|
|
|
***************************************************************************/
|
|
|
|
inline uint32_t rx_window_size() const;
|
|
|
|
|
2021-12-03 08:09:21 -08:00
|
|
|
public:
|
|
|
|
// Getters/Setters
|
2022-03-08 09:55:03 -08:00
|
|
|
void set_rx_state(const rlc_am_nr_rx_state_t& st_) { st = st_; } // This should only be used for testing.
|
|
|
|
rlc_am_nr_rx_state_t get_rx_state() { return st; } // This should only be used for testing.
|
2022-03-11 01:34:41 -08:00
|
|
|
uint32_t get_rx_window_size() { return rx_window->size(); } // This should only be used for testing.
|
2021-06-28 10:52:58 -07:00
|
|
|
};
|
2019-11-22 13:19:55 -08:00
|
|
|
|
2021-03-19 03:45:56 -07:00
|
|
|
} // namespace srsran
|
|
|
|
#endif // SRSRAN_RLC_AM_NR_H
|