From 1c041b2c1dc6fc9f2bba4bd20f8c23afa1fb75b6 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Thu, 5 Mar 2020 12:12:47 +0000 Subject: [PATCH] created harq entity class --- srsenb/hdr/stack/mac/scheduler_harq.h | 34 +++++++++++++++++++ srsenb/src/stack/mac/scheduler_harq.cc | 45 ++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/srsenb/hdr/stack/mac/scheduler_harq.h b/srsenb/hdr/stack/mac/scheduler_harq.h index 7e335c0da..fc93f6bda 100644 --- a/srsenb/hdr/stack/mac/scheduler_harq.h +++ b/srsenb/hdr/stack/mac/scheduler_harq.h @@ -149,6 +149,40 @@ private: typedef srslte::bounded_bitset<100, true> prbmask_t; +class dl_harq_entity : private std::vector +{ + using base_t = std::vector; + +public: + static const bool is_async = ASYNC_DL_SCHED; + + using base_t::const_iterator; + using base_t::iterator; + using base_t::operator[]; + using base_t::begin; + using base_t::data; + using base_t::end; + using base_t::size; + + explicit dl_harq_entity(size_t nof_harqs) : base_t(nof_harqs) {} + + /** + * Get the DL harq proc based on tti_tx_dl + * @param tti_tx_dl assumed to always be equal or ahead in time in comparison to current harqs + * @return pointer to found dl_harq + */ + dl_harq_proc* get_pending_harq(uint32_t tti_tx_dl); + /** + * Get empty DL Harq + * @param tti_tx_dl only used in case of sync dl sched + * @return pointer to found dl_harq + */ + dl_harq_proc* get_empty_harq(uint32_t tti_tx_dl); + +private: + dl_harq_proc* get_oldest_harq(uint32_t tti_tx_dl); +}; + } // namespace srsenb #endif // SRSENB_SCHEDULER_HARQ_H diff --git a/srsenb/src/stack/mac/scheduler_harq.cc b/srsenb/src/stack/mac/scheduler_harq.cc index af4fdb166..841ae2d1d 100644 --- a/srsenb/src/stack/mac/scheduler_harq.cc +++ b/srsenb/src/stack/mac/scheduler_harq.cc @@ -303,4 +303,49 @@ uint32_t ul_harq_proc::get_pending_data() const return (uint32_t)pending_data; } +/******************** + * Harq Entity + *******************/ + +dl_harq_proc* dl_harq_entity::get_empty_harq(uint32_t tti_tx_dl) +{ + if (not is_async) { + dl_harq_proc* h = &(*this)[tti_tx_dl % size()]; + return h->is_empty() ? h : nullptr; + } + + auto it = std::find_if(begin(), end(), [](dl_harq_proc& h) { return h.is_empty(); }); + return it != end() ? &(*it) : nullptr; +} + +dl_harq_proc* dl_harq_entity::get_pending_harq(uint32_t tti_tx_dl) +{ + if (not is_async) { + dl_harq_proc* h = &(*this)[tti_tx_dl % size()]; + return (h->has_pending_retx(0, tti_tx_dl) or h->has_pending_retx(1, tti_tx_dl)) ? h : nullptr; + } + return get_oldest_harq(tti_tx_dl); +} + +/** + * Get the oldest DL Harq Proc that has pending retxs + * @param tti_tx_dl assumed to always be equal or ahead in time in comparison to current harqs + * @return pointer to found dl_harq + */ +dl_harq_proc* dl_harq_entity::get_oldest_harq(uint32_t tti_tx_dl) +{ + int oldest_idx = -1; + uint32_t oldest_tti = 0; + for (const dl_harq_proc& h : *this) { + if (h.has_pending_retx(0, tti_tx_dl) or h.has_pending_retx(1, tti_tx_dl)) { + uint32_t x = srslte_tti_interval(tti_tx_dl, h.get_tti()); + if (x > oldest_tti) { + oldest_idx = h.get_id(); + oldest_tti = x; + } + } + } + return (oldest_idx >= 0) ? &(*this)[oldest_idx] : nullptr; +} + } // namespace srsenb