From 5359c42b46a485e847847d66df2ba85fa0ec0bfd Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Tue, 19 Sep 2017 15:15:25 +0200 Subject: [PATCH] RLC UM release timer at stop() --- lib/include/srslte/common/interfaces_common.h | 3 +- lib/include/srslte/common/timers.h | 2 +- lib/include/srslte/upper/rlc_am.h | 1 + lib/include/srslte/upper/rlc_common.h | 1 + lib/include/srslte/upper/rlc_entity.h | 1 + lib/include/srslte/upper/rlc_tm.h | 1 + lib/include/srslte/upper/rlc_um.h | 1 + lib/src/upper/rlc.cc | 5 +- lib/src/upper/rlc_am.cc | 6 ++ lib/src/upper/rlc_entity.cc | 5 ++ lib/src/upper/rlc_tm.cc | 5 ++ lib/src/upper/rlc_um.cc | 6 ++ lib/test/upper/rlc_am_test.cc | 1 + lib/test/upper/rlc_um_test.cc | 2 +- srsenb/hdr/mac/mac.h | 25 ++---- srsenb/src/mac/mac.cc | 18 +++- srsue/hdr/mac/mac.h | 14 +-- srsue/src/mac/mac.cc | 85 +++++++++++-------- 18 files changed, 117 insertions(+), 65 deletions(-) diff --git a/lib/include/srslte/common/interfaces_common.h b/lib/include/srslte/common/interfaces_common.h index d919d9fe5..dcb9ee736 100644 --- a/lib/include/srslte/common/interfaces_common.h +++ b/lib/include/srslte/common/interfaces_common.h @@ -71,7 +71,8 @@ public: /* Timer services with ms resolution. * timer_id must be lower than MAC_NOF_UPPER_TIMERS */ - virtual timers::timer* get(uint32_t timer_id) = 0; + virtual timers::timer* get(uint32_t timer_id) = 0; + virtual void free(uint32_t timer_id) = 0; virtual uint32_t get_unique_id() = 0; }; diff --git a/lib/include/srslte/common/timers.h b/lib/include/srslte/common/timers.h index 377df7b1d..533a07a76 100644 --- a/lib/include/srslte/common/timers.h +++ b/lib/include/srslte/common/timers.h @@ -145,7 +145,7 @@ public: } uint32_t get_unique_id() { if (nof_used_timers >= nof_timers) { - fprintf(stderr, "Error getting uinque timer id: no more timers available\n"); + fprintf(stderr, "Error getting unique timer id: no more timers available\n"); return 0; } else { while(used_timers[next_timer]) { diff --git a/lib/include/srslte/upper/rlc_am.h b/lib/include/srslte/upper/rlc_am.h index a92c9a0ad..afbd18544 100644 --- a/lib/include/srslte/upper/rlc_am.h +++ b/lib/include/srslte/upper/rlc_am.h @@ -78,6 +78,7 @@ public: mac_interface_timers *mac_timers); void configure(srslte_rlc_config_t cnfg); void reset(); + void stop(); void empty_queue(); rlc_mode_t get_mode(); diff --git a/lib/include/srslte/upper/rlc_common.h b/lib/include/srslte/upper/rlc_common.h index c68e3e6f3..494cc6174 100644 --- a/lib/include/srslte/upper/rlc_common.h +++ b/lib/include/srslte/upper/rlc_common.h @@ -158,6 +158,7 @@ public: srslte::mac_interface_timers *mac_timers_) = 0; virtual void configure(srslte_rlc_config_t cnfg) = 0; virtual void reset() = 0; + virtual void stop() = 0; virtual void empty_queue() = 0; virtual rlc_mode_t get_mode() = 0; diff --git a/lib/include/srslte/upper/rlc_entity.h b/lib/include/srslte/upper/rlc_entity.h index 651af72fb..e9c41fa30 100644 --- a/lib/include/srslte/upper/rlc_entity.h +++ b/lib/include/srslte/upper/rlc_entity.h @@ -56,6 +56,7 @@ public: void configure(srslte_rlc_config_t cnfg); void reset(); + void stop(); void empty_queue(); bool active(); diff --git a/lib/include/srslte/upper/rlc_tm.h b/lib/include/srslte/upper/rlc_tm.h index def968a92..4a55e33dd 100644 --- a/lib/include/srslte/upper/rlc_tm.h +++ b/lib/include/srslte/upper/rlc_tm.h @@ -48,6 +48,7 @@ public: mac_interface_timers *mac_timers); void configure(srslte_rlc_config_t cnfg); void reset(); + void stop(); void empty_queue(); rlc_mode_t get_mode(); diff --git a/lib/include/srslte/upper/rlc_um.h b/lib/include/srslte/upper/rlc_um.h index 4325bd029..672a7c646 100644 --- a/lib/include/srslte/upper/rlc_um.h +++ b/lib/include/srslte/upper/rlc_um.h @@ -58,6 +58,7 @@ public: mac_interface_timers *mac_timers_); void configure(srslte_rlc_config_t cnfg); void reset(); + void stop(); void empty_queue(); rlc_mode_t get_mode(); diff --git a/lib/src/upper/rlc.cc b/lib/src/upper/rlc.cc index 0cc551a1f..f506ebc63 100644 --- a/lib/src/upper/rlc.cc +++ b/lib/src/upper/rlc.cc @@ -65,7 +65,10 @@ void rlc::reset_metrics() void rlc::stop() { - reset(); + for(uint32_t i=0; istop(); + rlc = NULL; +} void rlc_entity::empty_queue() { diff --git a/lib/src/upper/rlc_tm.cc b/lib/src/upper/rlc_tm.cc index e3bef0a99..627752494 100644 --- a/lib/src/upper/rlc_tm.cc +++ b/lib/src/upper/rlc_tm.cc @@ -66,6 +66,11 @@ void rlc_tm::reset() empty_queue(); } +void rlc_tm::stop() +{ + reset(); +} + rlc_mode_t rlc_tm::get_mode() { return RLC_MODE_TM; diff --git a/lib/src/upper/rlc_um.cc b/lib/src/upper/rlc_um.cc index 3d6bb9553..725bc8925 100644 --- a/lib/src/upper/rlc_um.cc +++ b/lib/src/upper/rlc_um.cc @@ -102,6 +102,12 @@ void rlc_um::empty_queue() { } } +void rlc_um::stop() +{ + reset(); + mac_timers->free(reordering_timeout_id); +} + void rlc_um::reset() { diff --git a/lib/test/upper/rlc_am_test.cc b/lib/test/upper/rlc_am_test.cc index c7ab2aa74..35503707e 100644 --- a/lib/test/upper/rlc_am_test.cc +++ b/lib/test/upper/rlc_am_test.cc @@ -43,6 +43,7 @@ public: return &t; } uint32_t get_unique_id(){return 0;} + void free(uint32_t id){} private: srslte::timers::timer t; diff --git a/lib/test/upper/rlc_um_test.cc b/lib/test/upper/rlc_um_test.cc index 739c9ebf8..926c65561 100644 --- a/lib/test/upper/rlc_um_test.cc +++ b/lib/test/upper/rlc_um_test.cc @@ -47,7 +47,7 @@ public: { t.step(); } - + void free(uint32_t timer_id) {} private: srslte::timers::timer t; }; diff --git a/srsenb/hdr/mac/mac.h b/srsenb/hdr/mac/mac.h index 97be1825b..948065cf3 100644 --- a/srsenb/hdr/mac/mac.h +++ b/srsenb/hdr/mac/mac.h @@ -106,24 +106,14 @@ public: void timer_expired(uint32_t timer_id); srslte::timers::timer* get(uint32_t timer_id); + void free(uint32_t timer_id); u_int32_t get_unique_id(); - + + const static int NOF_MAC_TIMERS = 20; + uint32_t get_current_tti(); void get_metrics(mac_metrics_t metrics[ENB_METRICS_MAX_USERS]); - - enum { - HARQ_RTT, - TIME_ALIGNMENT, - CONTENTION_TIMER, - BSR_TIMER_PERIODIC, - BSR_TIMER_RETX, - PHR_TIMER_PERIODIC, - PHR_TIMER_PROHIBIT, - NOF_MAC_TIMERS - } mac_timers_t; - - static const int MAC_NOF_UPPER_TIMERS = 20; - + private: void log_step_ul(uint32_t tti); @@ -194,12 +184,13 @@ private: /* Class to run upper-layer timers with normal priority */ class upper_timers : public thread { public: - upper_timers() : timers_db(MAC_NOF_UPPER_TIMERS),ttisync(10240) {start();} + upper_timers() : timers_db(NOF_MAC_TIMERS),ttisync(10240) {start();} void tti_clock(); void stop(); void reset(); srslte::timers::timer* get(uint32_t timer_id); - uint32_t get_unique_id(); + void free(uint32_t timer_id); + uint32_t get_unique_id(); private: void run_thread(); srslte::timers timers_db; diff --git a/srsenb/src/mac/mac.cc b/srsenb/src/mac/mac.cc index 284cef3e7..62719009f 100644 --- a/srsenb/src/mac/mac.cc +++ b/srsenb/src/mac/mac.cc @@ -124,6 +124,11 @@ uint32_t mac::get_unique_id() return upper_timers_thread.get_unique_id(); } +void mac::free(uint32_t timer_id) +{ + upper_timers_thread.free(timer_id); +} + /* Front-end to upper-layer timers */ srslte::timers::timer* mac::get(uint32_t timer_id) { @@ -658,9 +663,20 @@ void mac::upper_timers::run_thread() timers_db.step_all(); } } + +void mac::upper_timers::free(uint32_t timer_id) +{ + timers_db.release_id(timer_id); +} + srslte::timers::timer* mac::upper_timers::get(uint32_t timer_id) { - return timers_db.get(timer_id%MAC_NOF_UPPER_TIMERS); + if (timer_id < NOF_MAC_TIMERS) { + return timers_db.get(timer_id); + } else { + fprintf(stderr, "Error requested invalid timer id=%d\n", timer_id); + return NULL; + } } uint32_t mac::upper_timers::get_unique_id() diff --git a/srsue/hdr/mac/mac.h b/srsue/hdr/mac/mac.h index 51bb467f2..6eacdbc78 100644 --- a/srsue/hdr/mac/mac.h +++ b/srsue/hdr/mac/mac.h @@ -93,14 +93,15 @@ public: void timer_expired(uint32_t timer_id); void start_pcap(srslte::mac_pcap* pcap); - + srslte::timers::timer* get(uint32_t timer_id); + void free(uint32_t timer_id); u_int32_t get_unique_id(); - + uint32_t get_current_tti(); - static const int MAC_NOF_UPPER_TIMERS = 20; - + static const int MAC_NOF_UPPER_TIMERS = 20; + private: void run_thread(); @@ -161,16 +162,17 @@ private: /* Class to run upper-layer timers with normal priority */ class upper_timers : public periodic_thread { - public: + public: upper_timers(); void reset(); + void free(uint32_t timer_id); srslte::timers::timer* get(uint32_t timer_id); uint32_t get_unique_id(); private: void run_period(); srslte::timers timers_db; }; - upper_timers upper_timers_thread; + upper_timers upper_timers_thread; diff --git a/srsue/src/mac/mac.cc b/srsue/src/mac/mac.cc index 5c0a00b4a..a74908db2 100644 --- a/srsue/src/mac/mac.cc +++ b/srsue/src/mac/mac.cc @@ -97,7 +97,7 @@ void mac::stop() void mac::start_pcap(srslte::mac_pcap* pcap_) { - pcap = pcap_; + pcap = pcap_; dl_harq.start_pcap(pcap); ul_harq.start_pcap(pcap); ra_procedure.start_pcap(pcap); @@ -113,28 +113,28 @@ void mac::reconfiguration() void mac::reset() { bzero(&metrics, sizeof(mac_metrics_t)); - + Info("Resetting MAC\n"); - + timers_db.stop_all(); upper_timers_thread.reset(); - + ul_harq.reset_ndi(); - + mux_unit.msg3_flush(); mux_unit.reset(); - - ra_procedure.reset(); + + ra_procedure.reset(); sr_procedure.reset(); bsr_procedure.reset(); phr_procedure.reset(); - + dl_harq.reset(); phy_h->pdcch_dl_search_reset(); phy_h->pdcch_ul_search_reset(); - + is_first_ul_grant = true; - + bzero(&uernti, sizeof(ue_rnti_t)); } @@ -158,13 +158,13 @@ void mac::run_thread() { log_h->step(tti); timers_db.step_all(); - - // Step all procedures + + // Step all procedures bsr_procedure.step(tti); phr_procedure.step(tti); - - // Check if BSR procedure need to start SR - + + // Check if BSR procedure need to start SR + if (bsr_procedure.need_to_send_sr(tti)) { Debug("Starting SR procedure by BSR request, PHY TTI=%d\n", tti); sr_procedure.start(); @@ -175,13 +175,13 @@ void mac::run_thread() { } sr_procedure.step(tti); - // Check SR if we need to start RA + // Check SR if we need to start RA if (sr_procedure.need_random_access()) { ra_procedure.start_mac_order(); } ra_procedure.step(tti); } - } + } } void mac::bcch_start_rx() @@ -197,7 +197,7 @@ void mac::bcch_start_rx(int si_window_start, int si_window_length) } else { phy_h->pdcch_dl_search(SRSLTE_RNTI_SI, SRSLTE_SIRNTI, si_window_start); } - Info("SCHED: Searching for DL grant for SI-RNTI window_st=%d, window_len=%d\n", si_window_start, si_window_length); + Info("SCHED: Searching for DL grant for SI-RNTI window_st=%d, window_len=%d\n", si_window_start, si_window_length); } void mac::bcch_stop_rx() @@ -208,7 +208,7 @@ void mac::bcch_stop_rx() void mac::pcch_start_rx() { phy_h->pdcch_dl_search(SRSLTE_RNTI_PCH, SRSLTE_PRNTI); - Info("SCHED: Searching for DL grant for P-RNTI\n"); + Info("SCHED: Searching for DL grant for P-RNTI\n"); } void mac::pcch_stop_rx() @@ -224,9 +224,9 @@ void mac::tti_clock(uint32_t tti) void mac::bch_decoded_ok(uint8_t* payload, uint32_t len) { - // Send MIB to RLC + // Send MIB to RLC rlc_h->write_pdu_bcch_bch(payload, len); - + if (pcap) { pcap->write_dl_bch(payload, len, true, phy_h->get_current_tti()); } @@ -234,9 +234,9 @@ void mac::bch_decoded_ok(uint8_t* payload, uint32_t len) void mac::pch_decoded_ok(uint32_t len) { - // Send PCH payload to RLC + // Send PCH payload to RLC rlc_h->write_pdu_pcch(pch_payload_buffer, len); - + if (pcap) { pcap->write_dl_pch(pch_payload_buffer, len, true, phy_h->get_current_tti()); } @@ -267,7 +267,7 @@ void mac::new_grant_dl(mac_interface_phy::mac_grant_t grant, mac_interface_phy:: } else if (grant.rnti_type == SRSLTE_RNTI_PCH) { memcpy(&action->phy_grant, &grant.phy_grant, sizeof(srslte_phy_grant_t)); - action->generate_ack = false; + action->generate_ack = false; action->decode_enabled[0] = true; srslte_softbuffer_rx_reset_cb(&pch_softbuffer, 1); action->payload_ptr[0] = pch_payload_buffer; @@ -281,7 +281,7 @@ void mac::new_grant_dl(mac_interface_phy::mac_grant_t grant, mac_interface_phy:: } else { // If PDCCH for C-RNTI and RA procedure in Contention Resolution, notify it if (grant.rnti_type == SRSLTE_RNTI_USER && ra_procedure.is_contention_resolution()) { - ra_procedure.pdcch_to_crnti(false); + ra_procedure.pdcch_to_crnti(false); } dl_harq.new_grant_dl(grant, action); } @@ -296,11 +296,11 @@ void mac::new_grant_ul(mac_interface_phy::mac_grant_t grant, mac_interface_phy:: { /* Start PHR Periodic timer on first UL grant */ if (is_first_ul_grant) { - is_first_ul_grant = false; + is_first_ul_grant = false; timers_db.get(PHR_TIMER_PERIODIC)->run(); } if (grant.rnti_type == SRSLTE_RNTI_USER && ra_procedure.is_contention_resolution()) { - ra_procedure.pdcch_to_crnti(true); + ra_procedure.pdcch_to_crnti(true); } ul_harq.new_grant_ul(grant, action); metrics.tx_pkts++; @@ -353,13 +353,13 @@ void mac::timer_expired(uint32_t timer_id) case TIME_ALIGNMENT: timeAlignmentTimerExpire(); break; - default: + default: break; } } /* Function called on expiry of TimeAlignmentTimer */ -void mac::timeAlignmentTimerExpire() +void mac::timeAlignmentTimerExpire() { printf("timeAlignmentTimer has expired value=%d ms\n", timers_db.get(TIME_ALIGNMENT)->get_timeout()); rrc_h->release_pucch_srs(); @@ -374,7 +374,7 @@ void mac::get_rntis(ue_rnti_t* rntis) void mac::set_contention_id(uint64_t uecri) { - uernti.contention_id = uecri; + uernti.contention_id = uecri; } void mac::get_config(mac_cfg_t* mac_cfg) @@ -407,7 +407,7 @@ void mac::set_config_sr(LIBLTE_RRC_SCHEDULING_REQUEST_CONFIG_STRUCT* sr_cfg) void mac::setup_lcid(uint32_t lcid, uint32_t lcg, uint32_t priority, int PBR_x_tti, uint32_t BSD) { - Info("Logical Channel Setup: LCID=%d, LCG=%d, priority=%d, PBR=%d, BSd=%d\n", + Info("Logical Channel Setup: LCID=%d, LCG=%d, priority=%d, PBR=%d, BSd=%d\n", lcid, lcg, priority, PBR_x_tti, BSD); mux_unit.set_priority(lcid, priority, PBR_x_tti, BSD); bsr_procedure.setup_lcg(lcid, lcg); @@ -425,8 +425,13 @@ srslte::timers::timer* mac::get(uint32_t timer_id) return upper_timers_thread.get(timer_id); } +void mac::free(uint32_t timer_id) +{ + upper_timers_thread.free(timer_id); +} -void mac::get_metrics(mac_metrics_t &m) + + void mac::get_metrics(mac_metrics_t &m) { Info("DL retx: %.2f \%%, perpkt: %.2f, UL retx: %.2f \%% perpkt: %.2f\n", metrics.rx_pkts?((float) 100*metrics.rx_errors/metrics.rx_pkts):0.0, @@ -442,20 +447,20 @@ void mac::get_metrics(mac_metrics_t &m) /******************************************************** * - * Class to run upper-layer timers with normal priority + * Class to run upper-layer timers with normal priority * *******************************************************/ -mac::upper_timers::upper_timers() : timers_db(MAC_NOF_UPPER_TIMERS) +mac::upper_timers::upper_timers() : timers_db(MAC_NOF_UPPER_TIMERS) { - start_periodic(1000, MAC_MAIN_THREAD_PRIO+1); + start_periodic(1000, MAC_MAIN_THREAD_PRIO+1); } void mac::upper_timers::run_period() { timers_db.step_all(); } - + srslte::timers::timer* mac::upper_timers::get(uint32_t timer_id) { return timers_db.get(timer_id%MAC_NOF_UPPER_TIMERS); @@ -472,9 +477,15 @@ void mac::upper_timers::reset() } +void mac::upper_timers::free(uint32_t timer_id) +{ + timers_db.release_id(timer_id); +} + + -/******************************************************** + /******************************************************** * * Class that runs a thread to process DL MAC PDUs from * DEMUX unit