From 54be15e7a6537a620aa1d0b33c473adaeffa1807 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 29 Jul 2021 17:00:10 +0100 Subject: [PATCH] Moved write pdu to rlc_am_base::rlc_am_base_rx --- lib/include/srsran/rlc/rlc_am_base.h | 32 +++++++++-------- lib/include/srsran/rlc/rlc_am_lte.h | 5 ++- lib/include/srsran/rlc/rlc_am_nr.h | 28 ++++++++------- lib/src/rlc/rlc_am_base.cc | 17 +++++++++ lib/src/rlc/rlc_am_lte.cc | 54 ++++++++++++++-------------- lib/src/rlc/rlc_am_nr.cc | 16 +++++---- 6 files changed, 88 insertions(+), 64 deletions(-) diff --git a/lib/include/srsran/rlc/rlc_am_base.h b/lib/include/srsran/rlc/rlc_am_base.h index 471e07910..720a654af 100644 --- a/lib/include/srsran/rlc/rlc_am_base.h +++ b/lib/include/srsran/rlc/rlc_am_base.h @@ -128,19 +128,20 @@ protected: explicit rlc_am_base_tx(srslog::basic_logger* logger_) : logger(logger_) {} virtual bool configure(const rlc_config_t& cfg_) = 0; + virtual void handle_control_pdu(uint8_t* payload, uint32_t nof_bytes) = 0; + virtual uint32_t get_buffer_state() = 0; + virtual void get_buffer_state(uint32_t& tx_queue, uint32_t& prio_tx_queue) = 0; virtual void reestablish() = 0; - virtual void stop() = 0; virtual void empty_queue() = 0; virtual void discard_sdu(uint32_t pdcp_sn) = 0; virtual bool sdu_queue_is_full() = 0; virtual bool has_data() = 0; - virtual uint32_t get_buffer_state() = 0; - virtual void get_buffer_state(uint32_t& tx_queue, uint32_t& prio_tx_queue) = 0; - virtual uint32_t read_pdu(uint8_t* payload, uint32_t nof_bytes) = 0; + virtual void stop() = 0; void set_bsr_callback(bsr_callback_t callback); - int write_sdu(unique_byte_buffer_t sdu); + int write_sdu(unique_byte_buffer_t sdu); + virtual uint32_t read_pdu(uint8_t* payload, uint32_t nof_bytes) = 0; bool tx_enabled = false; byte_buffer_pool* pool = nullptr; @@ -164,17 +165,20 @@ protected: class rlc_am_base_rx { public: - explicit rlc_am_base_rx(srslog::basic_logger* logger_) : logger(logger_) {} + explicit rlc_am_base_rx(rlc_am_base* parent_, srslog::basic_logger* logger_) : parent(parent_), logger(logger_) {} - virtual bool configure(const rlc_config_t& cfg_) = 0; - virtual void reestablish() = 0; - virtual void stop() = 0; - virtual void write_pdu(uint8_t* payload, uint32_t nof_bytes) = 0; - virtual uint32_t get_sdu_rx_latency_ms() = 0; - virtual uint32_t get_rx_buffered_bytes() = 0; + virtual bool configure(const rlc_config_t& cfg_) = 0; + virtual void handle_data_pdu(uint8_t* payload, uint32_t nof_bytes) = 0; + virtual void reestablish() = 0; + virtual void stop() = 0; + virtual uint32_t get_sdu_rx_latency_ms() = 0; + virtual uint32_t get_rx_buffered_bytes() = 0; - srslog::basic_logger* logger; - byte_buffer_pool* pool = nullptr; + void write_pdu(uint8_t* payload, uint32_t nof_bytes); + + srslog::basic_logger* logger = nullptr; + byte_buffer_pool* pool = nullptr; + rlc_am_base* parent = nullptr; }; rlc_am_base_tx* tx_base = nullptr; diff --git a/lib/include/srsran/rlc/rlc_am_lte.h b/lib/include/srsran/rlc/rlc_am_lte.h index e3d201619..0fb69324d 100644 --- a/lib/include/srsran/rlc/rlc_am_lte.h +++ b/lib/include/srsran/rlc/rlc_am_lte.h @@ -210,8 +210,6 @@ public: void reestablish() final; void stop() final; - void write_pdu(uint8_t* payload, uint32_t nof_bytes) final; - uint32_t get_rx_buffered_bytes() final; // returns sum of PDUs in rx_window uint32_t get_sdu_rx_latency_ms() final; @@ -224,7 +222,8 @@ public: bool get_do_status(); private: - void handle_data_pdu(uint8_t* payload, uint32_t nof_bytes, rlc_amd_pdu_header_t& header); + void handle_data_pdu(uint8_t* payload, uint32_t nof_bytes) final; + void handle_data_pdu_full(uint8_t* payload, uint32_t nof_bytes, rlc_amd_pdu_header_t& header); void handle_data_pdu_segment(uint8_t* payload, uint32_t nof_bytes, rlc_amd_pdu_header_t& header); void reassemble_rx_sdus(); bool inside_rx_window(const int16_t sn); diff --git a/lib/include/srsran/rlc/rlc_am_nr.h b/lib/include/srsran/rlc/rlc_am_nr.h index 1321440b8..92f9d531a 100644 --- a/lib/include/srsran/rlc/rlc_am_nr.h +++ b/lib/include/srsran/rlc/rlc_am_nr.h @@ -46,20 +46,22 @@ public: explicit rlc_am_nr_tx(rlc_am_nr* parent_); ~rlc_am_nr_tx() = default; - bool configure(const rlc_config_t& cfg_); - void stop(); + 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; + + void discard_sdu(uint32_t discard_sn) final; + bool sdu_queue_is_full() final; + void reestablish() final; int write_sdu(unique_byte_buffer_t sdu); - uint32_t read_pdu(uint8_t* payload, uint32_t nof_bytes); - void discard_sdu(uint32_t discard_sn); - bool sdu_queue_is_full(); - void reestablish(); - - void empty_queue(); - bool has_data(); - uint32_t get_buffer_state(); + void empty_queue() final; + bool has_data() final; + uint32_t get_buffer_state() final; void get_buffer_state(uint32_t& tx_queue, uint32_t& prio_tx_queue); + void stop() final; + private: rlc_am_nr* parent = nullptr; @@ -89,11 +91,13 @@ public: explicit rlc_am_nr_rx(rlc_am_nr* parent_); ~rlc_am_nr_rx() = default; - bool configure(const rlc_config_t& cfg_); + bool configure(const rlc_config_t& cfg_) final; + + void handle_data_pdu(uint8_t* payload, uint32_t nof_bytes) final; + void stop(); void reestablish(); - void write_pdu(uint8_t* payload, uint32_t nof_bytes); uint32_t get_sdu_rx_latency_ms(); uint32_t get_rx_buffered_bytes(); diff --git a/lib/src/rlc/rlc_am_base.cc b/lib/src/rlc/rlc_am_base.cc index dc629a4c9..4d6b00bd0 100644 --- a/lib/src/rlc/rlc_am_base.cc +++ b/lib/src/rlc/rlc_am_base.cc @@ -212,4 +212,21 @@ void rlc_am_base::rlc_am_base_tx::set_bsr_callback(bsr_callback_t callback) bsr_callback = callback; } +/******************************************************* + * RLC AM RX entity + * This class is used for common code between the + * LTE and NR TX entitites + *******************************************************/ +void rlc_am_base::rlc_am_base_rx::write_pdu(uint8_t* payload, const uint32_t nof_bytes) +{ + if (nof_bytes < 1) { + return; + } + + if (rlc_am_is_control_pdu(payload)) { + parent->tx_base->handle_control_pdu(payload, nof_bytes); + } else { + handle_data_pdu(payload, nof_bytes); + } +} } // namespace srsran diff --git a/lib/src/rlc/rlc_am_lte.cc b/lib/src/rlc/rlc_am_lte.cc index 9c36a8666..209fb30d0 100644 --- a/lib/src/rlc/rlc_am_lte.cc +++ b/lib/src/rlc/rlc_am_lte.cc @@ -1260,7 +1260,7 @@ rlc_am_lte::rlc_am_lte_rx::rlc_am_lte_rx(rlc_am_lte* parent_) : parent(parent_), pool(byte_buffer_pool::get_instance()), reordering_timer(parent_->timers->get_unique_timer()), - rlc_am_base_rx(&parent_->logger) + rlc_am_base_rx(parent_, &parent_->logger) {} rlc_am_lte::rlc_am_lte_rx::~rlc_am_lte_rx() {} @@ -1315,13 +1315,36 @@ void rlc_am_lte::rlc_am_lte_rx::stop() rx_window.clear(); } +/** Called from stack thread when MAC has received a new RLC PDU + * + * @param payload Pointer to payload + * @param nof_bytes Payload length + */ +void rlc_am_lte::rlc_am_lte_rx::handle_data_pdu(uint8_t* payload, uint32_t nof_bytes) +{ + std::lock_guard lock(mutex); + + rlc_amd_pdu_header_t header = {}; + uint32_t payload_len = nof_bytes; + rlc_am_read_data_pdu_header(&payload, &payload_len, &header); + if (payload_len > nof_bytes) { + logger->info("Dropping corrupted PDU (%d B). Remaining length after header %d B.", nof_bytes, payload_len); + return; + } + if (header.rf != 0) { + handle_data_pdu_segment(payload, payload_len, header); + } else { + handle_data_pdu_full(payload, payload_len, header); + } +} + /** Called from stack thread when MAC has received a new RLC PDU * * @param payload Pointer to payload * @param nof_bytes Payload length * @param header Reference to PDU header (unpacked by caller) */ -void rlc_am_lte::rlc_am_lte_rx::handle_data_pdu(uint8_t* payload, uint32_t nof_bytes, rlc_amd_pdu_header_t& header) +void rlc_am_lte::rlc_am_lte_rx::handle_data_pdu_full(uint8_t* payload, uint32_t nof_bytes, rlc_amd_pdu_header_t& header) { std::map::iterator it; @@ -1690,31 +1713,6 @@ bool rlc_am_lte::rlc_am_lte_rx::get_do_status() return do_status.load(std::memory_order_relaxed); } -void rlc_am_lte::rlc_am_lte_rx::write_pdu(uint8_t* payload, const uint32_t nof_bytes) -{ - if (nof_bytes < 1) { - return; - } - - if (rlc_am_is_control_pdu(payload)) { - parent->tx->handle_control_pdu(payload, nof_bytes); - } else { - std::lock_guard lock(mutex); - rlc_amd_pdu_header_t header = {}; - uint32_t payload_len = nof_bytes; - rlc_am_read_data_pdu_header(&payload, &payload_len, &header); - if (payload_len > nof_bytes) { - logger->info("Dropping corrupted PDU (%d B). Remaining length after header %d B.", nof_bytes, payload_len); - return; - } - if (header.rf) { - handle_data_pdu_segment(payload, payload_len, header); - } else { - handle_data_pdu(payload, payload_len, header); - } - } -} - uint32_t rlc_am_lte::rlc_am_lte_rx::get_rx_buffered_bytes() { std::lock_guard lock(mutex); @@ -2023,7 +2021,7 @@ bool rlc_am_lte::rlc_am_lte_rx::add_segment_and_check(rlc_amd_rx_pdu_segments_t* full_pdu->N_bytes += n; } - handle_data_pdu(full_pdu->msg, full_pdu->N_bytes, header); + handle_data_pdu_full(full_pdu->msg, full_pdu->N_bytes, header); return true; } diff --git a/lib/src/rlc/rlc_am_nr.cc b/lib/src/rlc/rlc_am_nr.cc index 8fb2950c3..39b05ad80 100644 --- a/lib/src/rlc/rlc_am_nr.cc +++ b/lib/src/rlc/rlc_am_nr.cc @@ -66,10 +66,7 @@ uint32_t rlc_am_nr::rlc_am_nr_tx::read_pdu(uint8_t* payload, uint32_t nof_bytes) return 0; } -void rlc_am_nr::rlc_am_nr_tx::reestablish() -{ - stop(); -} +void rlc_am_nr::rlc_am_nr_tx::handle_control_pdu(uint8_t* payload, uint32_t nof_bytes) {} uint32_t rlc_am_nr::rlc_am_nr_tx::get_buffer_state() { @@ -83,6 +80,11 @@ int rlc_am_nr::rlc_am_nr_tx::write_sdu(unique_byte_buffer_t sdu) return 0; } +void rlc_am_nr::rlc_am_nr_tx::reestablish() +{ + stop(); +} + void rlc_am_nr::rlc_am_nr_tx::discard_sdu(uint32_t discard_sn) {} bool rlc_am_nr::rlc_am_nr_tx::sdu_queue_is_full() @@ -98,7 +100,7 @@ void rlc_am_nr::rlc_am_nr_tx::stop() {} * Rx subclass implementation ***************************************************************************/ rlc_am_nr::rlc_am_nr_rx::rlc_am_nr_rx(rlc_am_nr* parent_) : - parent(parent_), pool(byte_buffer_pool::get_instance()), rlc_am_base_rx(&parent_->logger) + parent(parent_), pool(byte_buffer_pool::get_instance()), rlc_am_base_rx(parent_, &parent_->logger) {} bool rlc_am_nr::rlc_am_nr_rx::configure(const rlc_config_t& cfg_) @@ -108,9 +110,9 @@ bool rlc_am_nr::rlc_am_nr_rx::configure(const rlc_config_t& cfg_) return true; } -void rlc_am_nr::rlc_am_nr_rx::stop() {} +void rlc_am_nr::rlc_am_nr_rx::handle_data_pdu(uint8_t* payload, uint32_t nof_bytes) {} -void rlc_am_nr::rlc_am_nr_rx::write_pdu(uint8_t* payload, uint32_t nof_bytes) {} +void rlc_am_nr::rlc_am_nr_rx::stop() {} void rlc_am_nr::rlc_am_nr_rx::reestablish() {