srsLTE/srsenb/src/stack/upper/rlc.cc

265 lines
7.4 KiB
C++
Raw Normal View History

2019-04-26 12:27:38 -07:00
/*
* Copyright 2013-2019 Software Radio Systems Limited
2017-06-02 03:46:06 -07:00
*
* This file is part of srsLTE.
*
2019-04-26 12:27:38 -07:00
* srsLTE is free software: you can redistribute it and/or modify
2017-06-02 03:46:06 -07:00
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
2019-04-26 12:27:38 -07:00
* srsLTE is distributed in the hope that it will be useful,
2017-06-02 03:46:06 -07:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#include "srsenb/hdr/stack/upper/rlc.h"
#include "srsenb/hdr/stack/upper/common_enb.h"
2017-06-01 03:25:57 -07:00
namespace srsenb {
void rlc::init(pdcp_interface_rlc* pdcp_,
rrc_interface_rlc* rrc_,
mac_interface_rlc* mac_,
srslte::timer_handler* timers_,
srslte::log* log_h_)
2017-06-01 03:25:57 -07:00
{
pdcp = pdcp_;
rrc = rrc_;
log_h = log_h_;
mac = mac_;
timers = timers_;
2017-06-01 03:25:57 -07:00
pool = srslte::byte_buffer_pool::get_instance();
2017-06-01 03:25:57 -07:00
pthread_rwlock_init(&rwlock, NULL);
2017-06-01 03:25:57 -07:00
}
void rlc::stop()
{
pthread_rwlock_wrlock(&rwlock);
for (auto& user : users) {
user.second.rlc->stop();
2017-06-01 03:25:57 -07:00
}
users.clear();
pthread_rwlock_unlock(&rwlock);
pthread_rwlock_destroy(&rwlock);
2017-06-01 03:25:57 -07:00
}
void rlc::add_user(uint16_t rnti)
{
pthread_rwlock_rdlock(&rwlock);
if (users.count(rnti) == 0) {
std::unique_ptr<srslte::rlc> obj(new srslte::rlc(log_h));
obj->init(&users[rnti], &users[rnti], timers, RB_ID_SRB0);
users[rnti].rnti = rnti;
users[rnti].pdcp = pdcp;
users[rnti].rrc = rrc;
users[rnti].rlc = std::move(obj);
2017-06-01 03:25:57 -07:00
users[rnti].parent = this;
}
pthread_rwlock_unlock(&rwlock);
2017-06-01 03:25:57 -07:00
}
void rlc::rem_user(uint16_t rnti)
2017-06-01 03:25:57 -07:00
{
pthread_rwlock_wrlock(&rwlock);
2017-06-01 03:25:57 -07:00
if (users.count(rnti)) {
users[rnti].rlc->stop();
users.erase(rnti);
} else {
log_h->error("Removing rnti=0x%x. Already removed\n", rnti);
2017-06-01 03:25:57 -07:00
}
pthread_rwlock_unlock(&rwlock);
2017-06-01 03:25:57 -07:00
}
void rlc::clear_buffer(uint16_t rnti)
{
pthread_rwlock_rdlock(&rwlock);
2017-06-01 03:25:57 -07:00
if (users.count(rnti)) {
2017-08-22 06:06:51 -07:00
users[rnti].rlc->empty_queue();
2017-06-06 11:34:09 -07:00
for (int i=0;i<SRSLTE_N_RADIO_BEARERS;i++) {
2017-06-01 03:25:57 -07:00
mac->rlc_buffer_state(rnti, i, 0, 0);
}
2017-08-22 06:06:51 -07:00
log_h->info("Cleared buffer rnti=0x%x\n", rnti);
2017-06-01 03:25:57 -07:00
}
pthread_rwlock_unlock(&rwlock);
2017-06-01 03:25:57 -07:00
}
void rlc::add_bearer(uint16_t rnti, uint32_t lcid, srslte::rlc_config_t cnfg)
2017-06-01 03:25:57 -07:00
{
pthread_rwlock_rdlock(&rwlock);
2017-06-01 03:25:57 -07:00
if (users.count(rnti)) {
users[rnti].rlc->add_bearer(lcid, cnfg);
}
pthread_rwlock_unlock(&rwlock);
2017-06-01 03:25:57 -07:00
}
void rlc::add_bearer_mrb(uint16_t rnti, uint32_t lcid)
{
pthread_rwlock_rdlock(&rwlock);
if (users.count(rnti)) {
users[rnti].rlc->add_bearer_mrb(lcid);
}
pthread_rwlock_unlock(&rwlock);
}
bool rlc::has_bearer(uint16_t rnti, uint32_t lcid)
{
pthread_rwlock_rdlock(&rwlock);
bool result = false;
if (users.count(rnti)) {
result = users[rnti].rlc->has_bearer(lcid);
}
pthread_rwlock_unlock(&rwlock);
return result;
}
2017-06-01 03:25:57 -07:00
void rlc::read_pdu_pcch(uint8_t* payload, uint32_t buffer_size)
{
rrc->read_pdu_pcch(payload, buffer_size);
}
int rlc::read_pdu(uint16_t rnti, uint32_t lcid, uint8_t* payload, uint32_t nof_bytes)
{
int ret;
uint32_t tx_queue;
pthread_rwlock_rdlock(&rwlock);
if(users.count(rnti)) {
if(rnti != SRSLTE_MRNTI) {
ret = users[rnti].rlc->read_pdu(lcid, payload, nof_bytes);
tx_queue = users[rnti].rlc->get_buffer_state(lcid);
} else {
ret = users[rnti].rlc->read_pdu_mch(lcid, payload, nof_bytes);
tx_queue = users[rnti].rlc->get_total_mch_buffer_state(lcid);
}
// In the eNodeB, there is no polling for buffer state from the scheduler, thus
// communicate buffer state every time a PDU is read
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);
}else{
ret = SRSLTE_ERROR;
}
pthread_rwlock_unlock(&rwlock);
return ret;
2017-06-01 03:25:57 -07:00
}
void rlc::write_pdu(uint16_t rnti, uint32_t lcid, uint8_t* payload, uint32_t nof_bytes)
{
pthread_rwlock_rdlock(&rwlock);
2017-06-01 03:25:57 -07:00
if (users.count(rnti)) {
users[rnti].rlc->write_pdu(lcid, payload, nof_bytes);
// In the eNodeB, there is no polling for buffer state from the scheduler, thus
// communicate buffer state every time a new PDU is written
uint32_t tx_queue = users[rnti].rlc->get_buffer_state(lcid);
2017-06-01 03:25:57 -07:00
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);
}
pthread_rwlock_unlock(&rwlock);
2017-06-01 03:25:57 -07:00
}
void rlc::read_pdu_bcch_dlsch(uint32_t sib_index, uint8_t *payload)
{
// RLC is transparent for BCCH
rrc->read_pdu_bcch_dlsch(sib_index, payload);
}
2019-05-13 07:34:15 -07:00
void rlc::write_sdu(uint16_t rnti, uint32_t lcid, srslte::unique_byte_buffer_t sdu)
2017-06-01 03:25:57 -07:00
{
uint32_t tx_queue;
pthread_rwlock_rdlock(&rwlock);
2017-06-01 03:25:57 -07:00
if (users.count(rnti)) {
if(rnti != SRSLTE_MRNTI){
users[rnti].rlc->write_sdu(lcid, std::move(sdu), false);
tx_queue = users[rnti].rlc->get_buffer_state(lcid);
}else {
users[rnti].rlc->write_sdu_mch(lcid, std::move(sdu));
tx_queue = users[rnti].rlc->get_total_mch_buffer_state(lcid);
}
2017-06-01 03:25:57 -07:00
// In the eNodeB, there is no polling for buffer state from the scheduler, thus
// communicate buffer state every time a new SDU is written
2017-06-01 03:25:57 -07:00
uint32_t retx_queue = 0;
mac->rlc_buffer_state(rnti, lcid, tx_queue, retx_queue);
log_h->info("Buffer state: rnti=0x%x, lcid=%d, tx_queue=%d\n", rnti, lcid, tx_queue);
2017-06-01 03:25:57 -07:00
}
pthread_rwlock_unlock(&rwlock);
2017-06-01 03:25:57 -07:00
}
void rlc::discard_sdu(uint16_t rnti, uint32_t lcid, uint32_t discard_sn)
{
uint32_t tx_queue;
pthread_rwlock_rdlock(&rwlock);
if (users.count(rnti)) {
users[rnti].rlc->discard_sdu(lcid, discard_sn);
tx_queue = users[rnti].rlc->get_buffer_state(lcid);
// In the eNodeB, there is no polling for buffer state from the scheduler, thus
// communicate buffer state every time a new SDU is discarded
uint32_t retx_queue = 0;
mac->rlc_buffer_state(rnti, lcid, tx_queue, retx_queue);
log_h->info("Buffer state: rnti=0x%x, lcid=%d, tx_queue=%d\n", rnti, lcid, tx_queue);
}
pthread_rwlock_unlock(&rwlock);
}
2017-11-23 10:46:34 -08:00
bool rlc::rb_is_um(uint16_t rnti, uint32_t lcid) {
bool ret = false;
pthread_rwlock_rdlock(&rwlock);
2017-11-23 10:46:34 -08:00
if (users.count(rnti)) {
ret = users[rnti].rlc->rb_is_um(lcid);
2017-11-23 10:46:34 -08:00
}
pthread_rwlock_unlock(&rwlock);
return ret;
2017-11-23 10:46:34 -08:00
}
2017-06-01 03:25:57 -07:00
void rlc::user_interface::max_retx_attempted()
{
rrc->max_retx_attempted(rnti);
}
2019-05-13 07:34:15 -07:00
void rlc::user_interface::write_pdu(uint32_t lcid, srslte::unique_byte_buffer_t sdu)
2017-06-01 03:25:57 -07:00
{
if (lcid == RB_ID_SRB0) {
rrc->write_pdu(rnti, lcid, std::move(sdu));
} else {
pdcp->write_pdu(rnti, lcid, std::move(sdu));
}
2017-06-01 03:25:57 -07:00
}
2019-05-13 07:34:15 -07:00
void rlc::user_interface::write_pdu_bcch_bch(srslte::unique_byte_buffer_t sdu)
2017-06-01 03:25:57 -07:00
{
2019-04-23 01:53:11 -07:00
ERROR("Error: Received BCCH from ue=%d\n", rnti);
2017-06-01 03:25:57 -07:00
}
2019-05-13 07:34:15 -07:00
void rlc::user_interface::write_pdu_bcch_dlsch(srslte::unique_byte_buffer_t sdu)
2017-06-01 03:25:57 -07:00
{
2019-04-23 01:53:11 -07:00
ERROR("Error: Received BCCH from ue=%d\n", rnti);
2017-06-01 03:25:57 -07:00
}
2019-05-13 07:34:15 -07:00
void rlc::user_interface::write_pdu_pcch(srslte::unique_byte_buffer_t sdu)
2017-06-01 03:25:57 -07:00
{
2019-04-23 01:53:11 -07:00
ERROR("Error: Received PCCH from ue=%d\n", rnti);
2017-06-01 03:25:57 -07:00
}
std::string rlc::user_interface::get_rb_name(uint32_t lcid)
{
return std::string(rb_id_text[lcid]);
}
2017-06-01 03:25:57 -07:00
}