From 350e90a030bdfa054c6e9ac67761cde7506f0a0c Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 21 Jan 2021 17:13:09 +0000 Subject: [PATCH] Make RLC retransmissions deterministic. It was creating unpredictablity in the RLC AM tests. See issue #2228 --- lib/include/srslte/upper/rlc_am_lte.h | 2 +- lib/src/upper/rlc_am_lte.cc | 13 ++++++------- lib/test/upper/rlc_am_test.cc | 3 +-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/include/srslte/upper/rlc_am_lte.h b/lib/include/srslte/upper/rlc_am_lte.h index f3c39e735..096ca41d4 100644 --- a/lib/include/srslte/upper/rlc_am_lte.h +++ b/lib/include/srslte/upper/rlc_am_lte.h @@ -126,7 +126,7 @@ private: bool retx_queue_has_sn(uint32_t sn); int required_buffer_size(rlc_amd_retx_t retx); - void retransmit_random_pdu(); + void retransmit_pdu(); // Helpers bool poll_required(); diff --git a/lib/src/upper/rlc_am_lte.cc b/lib/src/upper/rlc_am_lte.cc index 6c04c3fca..ab50c750f 100644 --- a/lib/src/upper/rlc_am_lte.cc +++ b/lib/src/upper/rlc_am_lte.cc @@ -409,9 +409,9 @@ int rlc_am_lte::rlc_am_lte_tx::read_pdu(uint8_t* payload, uint32_t nof_bytes) goto unlock_and_exit; } - // Section 5.2.2.3 in TS 36.311, if tx_window is full and retx_queue empty, retransmit random PDU + // Section 5.2.2.3 in TS 36.311, if tx_window is full and retx_queue empty, retransmit PDU if (tx_window.size() >= RLC_AM_WINDOW_SIZE && retx_queue.empty()) { - retransmit_random_pdu(); + retransmit_pdu(); } // RETX if required @@ -435,11 +435,11 @@ void rlc_am_lte::rlc_am_lte_tx::timer_expired(uint32_t timeout_id) pthread_mutex_lock(&mutex); if (poll_retx_timer.is_valid() && poll_retx_timer.id() == timeout_id) { log->debug("%s Poll reTx timer expired after %dms\n", RB_NAME, poll_retx_timer.duration()); - // Section 5.2.2.3 in TS 36.311, schedule random PDU for retransmission if + // Section 5.2.2.3 in TS 36.311, schedule PDU for retransmission if // (a) both tx and retx buffer are empty, or // (b) no new data PDU can be transmitted (tx window is full) if ((retx_queue.empty() && tx_sdu_queue.size() == 0) || tx_window.size() >= RLC_AM_WINDOW_SIZE) { - retransmit_random_pdu(); + retransmit_pdu(); } } pthread_mutex_unlock(&mutex); @@ -449,12 +449,11 @@ void rlc_am_lte::rlc_am_lte_tx::timer_expired(uint32_t timeout_id) } } -void rlc_am_lte::rlc_am_lte_tx::retransmit_random_pdu() +void rlc_am_lte::rlc_am_lte_tx::retransmit_pdu() { if (not tx_window.empty()) { - // randomly select PDU in tx window for retransmission + // select PDU in tx window for retransmission std::map::iterator it = tx_window.begin(); - std::advance(it, rand() % tx_window.size()); log->info("%s Schedule SN=%d for reTx.\n", RB_NAME, it->first); rlc_amd_retx_t retx = {}; retx.is_segment = false; diff --git a/lib/test/upper/rlc_am_test.cc b/lib/test/upper/rlc_am_test.cc index 667df51fa..be2362153 100644 --- a/lib/test/upper/rlc_am_test.cc +++ b/lib/test/upper/rlc_am_test.cc @@ -394,8 +394,7 @@ bool retx_test() assert(metrics.rx_buffered_bytes == 3); // Step timers until reordering timeout expires - int cnt = 5; - while (cnt--) { + for (int cnt = 0; cnt < 5; cnt++) { timers.step_all(); }