From cde432fbb64ef1bad9af1f0289aece6b179864cd Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Mon, 11 Jun 2018 20:15:46 +0200 Subject: [PATCH] Added mutex to RLC and PDCP eNodeB --- srsenb/hdr/upper/pdcp.h | 6 +++++- srsenb/hdr/upper/rlc.h | 11 +++++++---- srsenb/src/upper/pdcp.cc | 21 ++++++++++++++++++++ srsenb/src/upper/rlc.cc | 42 +++++++++++++++++++++++++++++++--------- 4 files changed, 66 insertions(+), 14 deletions(-) diff --git a/srsenb/hdr/upper/pdcp.h b/srsenb/hdr/upper/pdcp.h index c249b856e..37f473117 100644 --- a/srsenb/hdr/upper/pdcp.h +++ b/srsenb/hdr/upper/pdcp.h @@ -41,6 +41,7 @@ class pdcp : public pdcp_interface_rlc, public: void init(rlc_interface_pdcp *rlc_, rrc_interface_pdcp *rrc_, gtpu_interface_pdcp *gtpu_, srslte::log *pdcp_log_); + ~pdcp(); void stop(); // pdcp_interface_rlc @@ -103,7 +104,10 @@ private: user_interface_gtpu gtpu_itf; user_interface_rrc rrc_itf; srslte::pdcp *pdcp; - }; + }; + + // Mutex to protect access to users std::map + pthread_mutex_t mutex; std::map users; diff --git a/srsenb/hdr/upper/rlc.h b/srsenb/hdr/upper/rlc.h index 2b0752cf1..92911df70 100644 --- a/srsenb/hdr/upper/rlc.h +++ b/srsenb/hdr/upper/rlc.h @@ -49,6 +49,7 @@ public: void init(pdcp_interface_rlc *pdcp_, rrc_interface_rlc *rrc_, mac_interface_rlc *mac_, srslte::mac_interface_timers *mac_timers_, srslte::log *log_h); + ~rlc(); void stop(); // rlc_interface_rrc @@ -91,11 +92,13 @@ private: srsenb::rrc_interface_rlc *rrc; srslte::rlc *rlc; srsenb::rlc *parent; - }; - + }; + + // Mutex to protect access to users std::map + pthread_mutex_t mutex; + std::map users; - std::vector mch_services; - + mac_interface_rlc *mac; pdcp_interface_rlc *pdcp; rrc_interface_rlc *rrc; diff --git a/srsenb/src/upper/pdcp.cc b/srsenb/src/upper/pdcp.cc index e6f4f40f5..a8774e408 100644 --- a/srsenb/src/upper/pdcp.cc +++ b/srsenb/src/upper/pdcp.cc @@ -37,6 +37,11 @@ void pdcp::init(rlc_interface_pdcp* rlc_, rrc_interface_pdcp* rrc_, gtpu_interfa log_h = pdcp_log_; pool = srslte::byte_buffer_pool::get_instance(); + pthread_mutex_init(&mutex, NULL); +} + +pdcp::~pdcp() { + pthread_mutex_destroy(&mutex); } void pdcp::stop() @@ -44,11 +49,14 @@ void pdcp::stop() for(std::map::iterator iter=users.begin(); iter!=users.end(); ++iter) { rem_user((uint32_t) iter->first); } + pthread_mutex_lock(&mutex); users.clear(); + pthread_mutex_unlock(&mutex); } void pdcp::add_user(uint16_t rnti) { + pthread_mutex_lock(&mutex); if (users.count(rnti) == 0) { srslte::pdcp *obj = new srslte::pdcp; obj->init(&users[rnti].rlc_itf, &users[rnti].rrc_itf, &users[rnti].gtpu_itf, log_h, RB_ID_SRB0, SECURITY_DIRECTION_DOWNLINK); @@ -61,20 +69,24 @@ void pdcp::add_user(uint16_t rnti) users[rnti].gtpu_itf.gtpu = gtpu; users[rnti].pdcp = obj; } + pthread_mutex_unlock(&mutex); } void pdcp::rem_user(uint16_t rnti) { + pthread_mutex_lock(&mutex); if (users.count(rnti)) { users[rnti].pdcp->stop(); delete users[rnti].pdcp; users[rnti].pdcp = NULL; users.erase(rnti); } + pthread_mutex_unlock(&mutex); } void pdcp::add_bearer(uint16_t rnti, uint32_t lcid, srslte::srslte_pdcp_config_t cfg) { + pthread_mutex_lock(&mutex); if (users.count(rnti)) { if(rnti != SRSLTE_MRNTI){ users[rnti].pdcp->add_bearer(lcid, cfg); @@ -82,37 +94,45 @@ void pdcp::add_bearer(uint16_t rnti, uint32_t lcid, srslte::srslte_pdcp_config_t users[rnti].pdcp->add_bearer_mrb(lcid, cfg); } } + pthread_mutex_unlock(&mutex); } void pdcp::reset(uint16_t rnti) { + pthread_mutex_lock(&mutex); if (users.count(rnti)) { users[rnti].pdcp->reset(); } + pthread_mutex_unlock(&mutex); } void pdcp::config_security(uint16_t rnti, uint32_t lcid, uint8_t* k_rrc_enc_, uint8_t* k_rrc_int_, srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo_, srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo_) { + pthread_mutex_lock(&mutex); if (users.count(rnti)) { users[rnti].pdcp->config_security(lcid, k_rrc_enc_, k_rrc_int_, cipher_algo_, integ_algo_); users[rnti].pdcp->enable_integrity(lcid); users[rnti].pdcp->enable_encryption(lcid); } + pthread_mutex_unlock(&mutex); } void pdcp::write_pdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* sdu) { + pthread_mutex_lock(&mutex); if (users.count(rnti)) { users[rnti].pdcp->write_pdu(lcid, sdu); } else { pool->deallocate(sdu); } + pthread_mutex_unlock(&mutex); } void pdcp::write_sdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* sdu) { + pthread_mutex_lock(&mutex); if (users.count(rnti)) { if(rnti != SRSLTE_MRNTI){ users[rnti].pdcp->write_sdu(lcid, sdu); @@ -122,6 +142,7 @@ void pdcp::write_sdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* sdu) } else { pool->deallocate(sdu); } + pthread_mutex_unlock(&mutex); } void pdcp::user_interface_gtpu::write_pdu(uint32_t lcid, srslte::byte_buffer_t *pdu) diff --git a/srsenb/src/upper/rlc.cc b/srsenb/src/upper/rlc.cc index 0624dbca4..d9860b475 100644 --- a/srsenb/src/upper/rlc.cc +++ b/srsenb/src/upper/rlc.cc @@ -40,6 +40,11 @@ void rlc::init(pdcp_interface_rlc* pdcp_, rrc_interface_rlc* rrc_, mac_interface pool = srslte::byte_buffer_pool::get_instance(); + pthread_mutex_init(&mutex, NULL); +} + +rlc::~rlc() { + pthread_mutex_destroy(&mutex); } void rlc::stop() @@ -47,12 +52,15 @@ void rlc::stop() for(std::map::iterator iter=users.begin(); iter!=users.end(); ++iter) { rem_user((uint32_t) iter->first); } + pthread_mutex_lock(&mutex); users.clear(); + pthread_mutex_unlock(&mutex); } void rlc::add_user(uint16_t rnti) { - if (users.count(rnti) == 0) { + pthread_mutex_lock(&mutex); + if (users.count(rnti) == 0) { srslte::rlc *obj = new srslte::rlc; obj->init(&users[rnti], &users[rnti], &users[rnti], log_h, mac_timers, RB_ID_SRB0); users[rnti].rnti = rnti; @@ -61,27 +69,33 @@ void rlc::add_user(uint16_t rnti) users[rnti].rlc = obj; users[rnti].parent = this; } + pthread_mutex_unlock(&mutex); } void rlc::rem_user(uint16_t rnti) { + pthread_mutex_lock(&mutex); if (users.count(rnti)) { users[rnti].rlc->stop(); delete users[rnti].rlc; users[rnti].rlc = NULL; users.erase(rnti); } + pthread_mutex_unlock(&mutex); } void rlc::reset(uint16_t rnti) { + pthread_mutex_lock(&mutex); if (users.count(rnti)) { users[rnti].rlc->reset(); } + pthread_mutex_unlock(&mutex); } void rlc::clear_buffer(uint16_t rnti) { + pthread_mutex_lock(&mutex); if (users.count(rnti)) { users[rnti].rlc->empty_queue(); for (int i=0;iinfo("Cleared buffer rnti=0x%x\n", rnti); } + pthread_mutex_unlock(&mutex); } void rlc::add_bearer(uint16_t rnti, uint32_t lcid) { + pthread_mutex_lock(&mutex); if (users.count(rnti)) { users[rnti].rlc->add_bearer(lcid); } + pthread_mutex_unlock(&mutex); } void rlc::add_bearer(uint16_t rnti, uint32_t lcid, srslte::srslte_rlc_config_t cnfg) { + pthread_mutex_lock(&mutex); if (users.count(rnti)) { users[rnti].rlc->add_bearer(lcid, cnfg); } + pthread_mutex_unlock(&mutex); } void rlc::add_bearer_mrb(uint16_t rnti, uint32_t lcid) { + pthread_mutex_lock(&mutex); if (users.count(rnti)) { users[rnti].rlc->add_bearer_mrb_enb(lcid); } + pthread_mutex_unlock(&mutex); } void rlc::read_pdu_pcch(uint8_t* payload, uint32_t buffer_size) @@ -119,13 +140,14 @@ void rlc::read_pdu_pcch(uint8_t* payload, uint32_t buffer_size) int rlc::read_pdu(uint16_t rnti, uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) { + pthread_mutex_lock(&mutex); int ret; uint32_t tx_queue; - if(users.count(rnti)){ - if(rnti != SRSLTE_MRNTI){ + if (users.count(rnti)) { + if (rnti != SRSLTE_MRNTI) { ret = users[rnti].rlc->read_pdu(lcid, payload, nof_bytes); tx_queue = users[rnti].rlc->get_total_buffer_state(lcid); - }else{ + } else { ret = users[rnti].rlc->read_pdu_mch(lcid, payload, nof_bytes); tx_queue = users[rnti].rlc->get_total_mch_buffer_state(lcid); } @@ -135,15 +157,14 @@ int rlc::read_pdu(uint16_t rnti, uint32_t lcid, uint8_t* payload, uint32_t nof_b uint32_t retx_queue = 0; log_h->debug("Buffer state PDCP: rnti=0x%x, lcid=%d, tx_queue=%d\n", rnti, lcid, tx_queue); mac->rlc_buffer_state(rnti, lcid, tx_queue, retx_queue); - return ret; - - }else{ - return SRSLTE_ERROR; } + pthread_mutex_unlock(&mutex); + return ret; } void rlc::write_pdu(uint16_t rnti, uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) { + pthread_mutex_lock(&mutex); if (users.count(rnti)) { users[rnti].rlc->write_pdu(lcid, payload, nof_bytes); @@ -154,6 +175,7 @@ void rlc::write_pdu(uint16_t rnti, uint32_t lcid, uint8_t* payload, uint32_t nof log_h->debug("Buffer state PDCP: rnti=0x%x, lcid=%d, tx_queue=%d\n", rnti, lcid, tx_queue); mac->rlc_buffer_state(rnti, lcid, tx_queue, retx_queue); } + pthread_mutex_unlock(&mutex); } void rlc::read_pdu_bcch_dlsch(uint32_t sib_index, uint8_t *payload) @@ -164,7 +186,8 @@ void rlc::read_pdu_bcch_dlsch(uint32_t sib_index, uint8_t *payload) void rlc::write_sdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* sdu) { - + + pthread_mutex_lock(&mutex); uint32_t tx_queue; if (users.count(rnti)) { if(rnti != SRSLTE_MRNTI){ @@ -183,6 +206,7 @@ void rlc::write_sdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* sdu) } else { pool->deallocate(sdu); } + pthread_mutex_unlock(&mutex); } bool rlc::rb_is_um(uint16_t rnti, uint32_t lcid) {