From b8438e9cc3953d8c10e2dad2c73f37269390c840 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 24 Jul 2018 15:49:09 +0200 Subject: [PATCH] extend PDCP interface to allow non-blocking write of SDUs --- lib/include/srslte/interfaces/ue_interfaces.h | 6 ++--- lib/include/srslte/upper/pdcp.h | 2 +- lib/include/srslte/upper/pdcp_entity.h | 2 +- lib/include/srslte/upper/pdcp_interface.h | 2 +- lib/include/srslte/upper/rlc.h | 3 +-- lib/src/upper/pdcp.cc | 12 +++++---- lib/src/upper/pdcp_entity.cc | 6 ++--- lib/src/upper/rlc.cc | 27 +++++++------------ lib/src/upper/rlc_am.cc | 2 ++ 9 files changed, 29 insertions(+), 33 deletions(-) diff --git a/lib/include/srslte/interfaces/ue_interfaces.h b/lib/include/srslte/interfaces/ue_interfaces.h index a4fb2b2cb..1cfcc56e0 100644 --- a/lib/include/srslte/interfaces/ue_interfaces.h +++ b/lib/include/srslte/interfaces/ue_interfaces.h @@ -228,7 +228,7 @@ public: class pdcp_interface_gw { public: - virtual void write_sdu(uint32_t lcid, srslte::byte_buffer_t *sdu) = 0; + virtual void write_sdu(uint32_t lcid, srslte::byte_buffer_t *sdu, bool blocking) = 0; virtual bool is_drb_enabled(uint32_t lcid) = 0; }; @@ -238,7 +238,7 @@ class pdcp_interface_rrc public: virtual void reestablish() = 0; virtual void reset() = 0; - virtual void write_sdu(uint32_t lcid, srslte::byte_buffer_t *sdu) = 0; + virtual void write_sdu(uint32_t lcid, srslte::byte_buffer_t *sdu, bool blocking = true) = 0; virtual void add_bearer(uint32_t lcid, srslte::srslte_pdcp_config_t cnfg = srslte::srslte_pdcp_config_t()) = 0; virtual void config_security(uint32_t lcid, uint8_t *k_enc_, @@ -282,7 +282,7 @@ class rlc_interface_pdcp public: /* PDCP calls RLC to push an RLC SDU. SDU gets placed into the RLC buffer and MAC pulls * RLC PDUs according to TB size. */ - virtual void write_sdu(uint32_t lcid, srslte::byte_buffer_t *sdu) = 0; + virtual void write_sdu(uint32_t lcid, srslte::byte_buffer_t *sdu, bool blocking = true) = 0; virtual bool rb_is_um(uint32_t lcid) = 0; }; diff --git a/lib/include/srslte/upper/pdcp.h b/lib/include/srslte/upper/pdcp.h index cd284619f..53149154a 100644 --- a/lib/include/srslte/upper/pdcp.h +++ b/lib/include/srslte/upper/pdcp.h @@ -56,7 +56,7 @@ public: // RRC interface void reestablish(); void reset(); - void write_sdu(uint32_t lcid, byte_buffer_t *sdu); + void write_sdu(uint32_t lcid, byte_buffer_t *sdu, bool blocking = true); void write_sdu_mch(uint32_t lcid, byte_buffer_t *sdu); void add_bearer(uint32_t lcid, srslte_pdcp_config_t cnfg = srslte_pdcp_config_t()); void add_bearer_mrb(uint32_t lcid, srslte_pdcp_config_t cnfg = srslte_pdcp_config_t()); diff --git a/lib/include/srslte/upper/pdcp_entity.h b/lib/include/srslte/upper/pdcp_entity.h index 6586becc0..fd69c92e9 100644 --- a/lib/include/srslte/upper/pdcp_entity.h +++ b/lib/include/srslte/upper/pdcp_entity.h @@ -76,7 +76,7 @@ public: bool is_active(); // RRC interface - void write_sdu(byte_buffer_t *sdu); + void write_sdu(byte_buffer_t *sdu, bool blocking); void config_security(uint8_t *k_enc_, uint8_t *k_int_, CIPHERING_ALGORITHM_ID_ENUM cipher_algo_, diff --git a/lib/include/srslte/upper/pdcp_interface.h b/lib/include/srslte/upper/pdcp_interface.h index 915fbe420..0c2cb2428 100644 --- a/lib/include/srslte/upper/pdcp_interface.h +++ b/lib/include/srslte/upper/pdcp_interface.h @@ -55,7 +55,7 @@ public: virtual bool is_active() = 0; // RRC interface - virtual void write_sdu(byte_buffer_t *sdu) = 0; + virtual void write_sdu(byte_buffer_t *sdu, bool blocking) = 0; virtual void config_security(uint8_t *k_enc_, uint8_t *k_int_, CIPHERING_ALGORITHM_ID_ENUM cipher_algo_, diff --git a/lib/include/srslte/upper/rlc.h b/lib/include/srslte/upper/rlc.h index 0d8dcad91..4a414f3fe 100644 --- a/lib/include/srslte/upper/rlc.h +++ b/lib/include/srslte/upper/rlc.h @@ -63,8 +63,7 @@ public: void get_metrics(rlc_metrics_t &m); // PDCP interface - void write_sdu(uint32_t lcid, byte_buffer_t *sdu); - void write_sdu_nb(uint32_t lcid, byte_buffer_t *sdu); + void write_sdu(uint32_t lcid, byte_buffer_t *sdu, bool blocking = true); void write_sdu_mch(uint32_t lcid, byte_buffer_t *sdu); bool rb_is_um(uint32_t lcid); diff --git a/lib/src/upper/pdcp.cc b/lib/src/upper/pdcp.cc index e0a000c93..24dbd27d3 100644 --- a/lib/src/upper/pdcp.cc +++ b/lib/src/upper/pdcp.cc @@ -115,11 +115,11 @@ bool pdcp::is_drb_enabled(uint32_t lcid) return ret; } -void pdcp::write_sdu(uint32_t lcid, byte_buffer_t *sdu) +void pdcp::write_sdu(uint32_t lcid, byte_buffer_t *sdu, bool blocking) { pthread_rwlock_rdlock(&rwlock); if (valid_lcid(lcid)) { - pdcp_array.at(lcid)->write_sdu(sdu); + pdcp_array.at(lcid)->write_sdu(sdu, blocking); } else { pdcp_log->warning("Writing sdu: lcid=%d. Deallocating sdu\n", lcid); byte_buffer_pool::get_instance()->deallocate(sdu); @@ -131,7 +131,7 @@ void pdcp::write_sdu_mch(uint32_t lcid, byte_buffer_t *sdu) { pthread_rwlock_rdlock(&rwlock); if (valid_mch_lcid(lcid)){ - pdcp_array_mrb.at(lcid)->write_sdu(sdu); + pdcp_array_mrb.at(lcid)->write_sdu(sdu, true); } pthread_rwlock_unlock(&rwlock); } @@ -141,13 +141,14 @@ void pdcp::add_bearer(uint32_t lcid, srslte_pdcp_config_t cfg) if (not valid_lcid(lcid)) { if (not pdcp_array.insert(pdcp_map_pair_t(lcid, new pdcp_entity())).second) { pdcp_log->error("Error inserting PDCP entity in to array\n."); - return; + goto unlock_and_exit; } pdcp_array.at(lcid)->init(rlc, rrc, gw, pdcp_log, lcid, cfg); pdcp_log->info("Added bearer %s\n", rrc->get_rb_name(lcid).c_str()); } else { pdcp_log->warning("Bearer %s already configured. Reconfiguration not supported\n", rrc->get_rb_name(lcid).c_str()); } +unlock_and_exit: pthread_rwlock_unlock(&rwlock); } @@ -158,13 +159,14 @@ void pdcp::add_bearer_mrb(uint32_t lcid, srslte_pdcp_config_t cfg) if (not valid_mch_lcid(lcid)) { if (not pdcp_array_mrb.insert(pdcp_map_pair_t(lcid, new pdcp_entity())).second) { pdcp_log->error("Error inserting PDCP entity in to array\n."); - return; + goto unlock_and_exit; } pdcp_array_mrb.at(lcid)->init(rlc, rrc, gw, pdcp_log, lcid, cfg); pdcp_log->info("Added bearer %s\n", rrc->get_rb_name(lcid).c_str()); } else { pdcp_log->warning("Bearer %s already configured. Reconfiguration not supported\n", rrc->get_rb_name(lcid).c_str()); } +unlock_and_exit: pthread_rwlock_unlock(&rwlock); } diff --git a/lib/src/upper/pdcp_entity.cc b/lib/src/upper/pdcp_entity.cc index c2c829549..b77a760b9 100644 --- a/lib/src/upper/pdcp_entity.cc +++ b/lib/src/upper/pdcp_entity.cc @@ -108,8 +108,8 @@ bool pdcp_entity::is_active() return active; } -// RRC interface -void pdcp_entity::write_sdu(byte_buffer_t *sdu) +// GW/RRC interface +void pdcp_entity::write_sdu(byte_buffer_t *sdu, bool blocking) { log->info_hex(sdu->msg, sdu->N_bytes, "TX %s SDU, SN: %d, do_integrity = %s, do_encryption = %s", @@ -141,7 +141,7 @@ void pdcp_entity::write_sdu(byte_buffer_t *sdu) } tx_count++; - rlc->write_sdu(lcid, sdu); + rlc->write_sdu(lcid, sdu, blocking); } void pdcp_entity::config_security(uint8_t *k_enc_, diff --git a/lib/src/upper/rlc.cc b/lib/src/upper/rlc.cc index 1a602d7c0..2f0e20313 100644 --- a/lib/src/upper/rlc.cc +++ b/lib/src/upper/rlc.cc @@ -165,12 +165,15 @@ void rlc::reestablish() void rlc::reset() { pthread_rwlock_wrlock(&rwlock); + for (rlc_map_t::iterator it = rlc_array.begin(); it != rlc_array.end(); ++it) { + it->second->stop(); delete(it->second); } rlc_array.clear(); for (rlc_map_t::iterator it = rlc_array_mrb.begin(); it != rlc_array_mrb.end(); ++it) { + it->second->stop(); delete(it->second); } rlc_array_mrb.clear(); @@ -195,24 +198,15 @@ void rlc::empty_queue() PDCP interface *******************************************************************************/ -void rlc::write_sdu(uint32_t lcid, byte_buffer_t *sdu) +void rlc::write_sdu(uint32_t lcid, byte_buffer_t *sdu, bool blocking) { pthread_rwlock_rdlock(&rwlock); if (valid_lcid(lcid)) { - rlc_array.at(lcid)->write_sdu(sdu); - } else { - rlc_log->warning("Writing SDU: lcid=%d. Deallocating sdu\n", lcid); - byte_buffer_pool::get_instance()->deallocate(sdu); - } - pthread_rwlock_unlock(&rwlock); -} - - -void rlc::write_sdu_nb(uint32_t lcid, byte_buffer_t *sdu) -{ - pthread_rwlock_rdlock(&rwlock); - if (valid_lcid(lcid)) { - rlc_array.at(lcid)->write_sdu_nb(sdu); + if (blocking) { + rlc_array.at(lcid)->write_sdu(sdu); + } else { + rlc_array.at(lcid)->write_sdu_nb(sdu); + } } else { rlc_log->warning("Writing SDU: lcid=%d. Deallocating sdu\n", lcid); byte_buffer_pool::get_instance()->deallocate(sdu); @@ -220,7 +214,6 @@ void rlc::write_sdu_nb(uint32_t lcid, byte_buffer_t *sdu) pthread_rwlock_unlock(&rwlock); } - void rlc::write_sdu_mch(uint32_t lcid, byte_buffer_t *sdu) { pthread_rwlock_rdlock(&rwlock); @@ -429,7 +422,7 @@ void rlc::add_bearer(uint32_t lcid, srslte_rlc_config_t cnfg) break; default: rlc_log->error("Cannot add RLC entity - invalid mode\n"); - return; + goto unlock_and_exit; } if (rlc_entity) { diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index 25fc6d770..c2ce16dcc 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -105,11 +105,13 @@ bool rlc_am::configure(srslte_rlc_config_t cfg_) void rlc_am::empty_queue() { // Drop all messages in TX SDU queue + pthread_mutex_lock(&mutex); byte_buffer_t *buf; while(tx_sdu_queue.try_read(&buf)) { pool->deallocate(buf); } tx_sdu_queue.reset(); + pthread_mutex_unlock(&mutex); } void rlc_am::reestablish() {