srsRAN/lib/src/upper/rlc_tm.cc

178 lines
4.5 KiB
C++
Raw Normal View History

2017-05-18 10:52:29 +00:00
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2015 Software Radio Systems Limited
*
* \section LICENSE
*
* This file is part of the srsUE library.
*
* srsUE is free software: you can redistribute it and/or modify
* 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.
*
* srsUE is distributed in the hope that it will be useful,
* 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 "srslte/upper/rlc_tm.h"
2017-05-18 10:52:29 +00:00
namespace srslte {
2017-05-18 10:52:29 +00:00
rlc_tm::rlc_tm(uint32_t queue_len) : ul_queue(queue_len)
2017-05-18 10:52:29 +00:00
{
2018-01-31 15:48:50 +00:00
log = NULL;
pdcp = NULL;
rrc = NULL;
lcid = 0;
2017-05-18 10:52:29 +00:00
pool = byte_buffer_pool::get_instance();
}
// Warning: must call stop() to properly deallocate all buffers
rlc_tm::~rlc_tm() {
pool = NULL;
}
void rlc_tm::init(srslte::log *log_,
uint32_t lcid_,
srsue::pdcp_interface_rlc *pdcp_,
srsue::rrc_interface_rlc *rrc_,
mac_interface_timers *mac_timers)
2017-05-18 10:52:29 +00:00
{
log = log_;
lcid = lcid_;
pdcp = pdcp_;
rrc = rrc_;
tx_enabled = true;
2017-05-18 10:52:29 +00:00
}
void rlc_tm::configure(srslte_rlc_config_t cnfg)
2017-05-18 10:52:29 +00:00
{
2018-04-27 14:25:37 +00:00
log->error("Attempted to configure TM RLC entity\n");
2017-05-18 10:52:29 +00:00
}
void rlc_tm::empty_queue()
{
// Drop all messages in TX queue
byte_buffer_t *buf;
while(ul_queue.try_read(&buf)) {
pool->deallocate(buf);
2017-05-18 10:52:29 +00:00
}
}
2017-09-19 13:15:25 +00:00
void rlc_tm::stop()
{
tx_enabled = false;
empty_queue();
2017-09-19 13:15:25 +00:00
}
2017-05-18 10:52:29 +00:00
rlc_mode_t rlc_tm::get_mode()
{
return RLC_MODE_TM;
}
uint32_t rlc_tm::get_bearer()
{
return lcid;
}
// PDCP interface
void rlc_tm::write_sdu(byte_buffer_t *sdu)
{
if (!tx_enabled) {
byte_buffer_pool::get_instance()->deallocate(sdu);
return;
}
if (sdu) {
ul_queue.write(sdu);
log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU, queue size=%d, bytes=%d",
rrc->get_rb_name(lcid).c_str(), ul_queue.size(), ul_queue.size_bytes());
} else {
log->warning("NULL SDU pointer in write_sdu()\n");
}
}
void rlc_tm::write_sdu_nb(byte_buffer_t *sdu)
{
if (!tx_enabled) {
byte_buffer_pool::get_instance()->deallocate(sdu);
return;
}
if (sdu) {
if (ul_queue.try_write(sdu)) {
log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU, queue size=%d, bytes=%d",
rrc->get_rb_name(lcid).c_str(), ul_queue.size(), ul_queue.size_bytes());
} else {
log->debug_hex(sdu->msg, sdu->N_bytes, "[Dropped SDU] %s Tx SDU, queue size=%d, bytes=%d",
rrc->get_rb_name(lcid).c_str(), ul_queue.size(), ul_queue.size_bytes());
pool->deallocate(sdu);
}
} else {
log->warning("NULL SDU pointer in write_sdu()\n");
}
2017-05-18 10:52:29 +00:00
}
// MAC interface
uint32_t rlc_tm::get_buffer_state()
{
return ul_queue.size_bytes();
}
uint32_t rlc_tm::get_total_buffer_state()
{
return get_buffer_state();
}
int rlc_tm::read_pdu(uint8_t *payload, uint32_t nof_bytes)
{
uint32_t pdu_size = ul_queue.size_tail_bytes();
if(pdu_size > nof_bytes)
{
2018-01-12 13:55:58 +00:00
log->error("TX %s PDU size larger than MAC opportunity\n", rrc->get_rb_name(lcid).c_str());
return -1;
2017-05-18 10:52:29 +00:00
}
byte_buffer_t *buf;
2018-04-26 11:17:55 +00:00
if (ul_queue.try_read(&buf)) {
pdu_size = buf->N_bytes;
memcpy(payload, buf->msg, buf->N_bytes);
log->debug("%s Complete SDU scheduled for tx. Stack latency: %ld us\n",
rrc->get_rb_name(lcid).c_str(), buf->get_latency_us());
pool->deallocate(buf);
log->info_hex(payload, pdu_size, "TX %s, %s PDU, queue size=%d, bytes=%d",
rrc->get_rb_name(lcid).c_str(), rlc_mode_text[RLC_MODE_TM], ul_queue.size(), ul_queue.size_bytes());
2018-04-26 11:17:55 +00:00
return pdu_size;
} else {
log->warning("Queue empty while trying to read\n");
if (ul_queue.size_bytes() > 0) {
log->warning("Corrupted queue: empty but size_bytes > 0. Resetting queue\n");
ul_queue.reset();
}
2018-04-26 11:17:55 +00:00
return 0;
}
2017-05-18 10:52:29 +00:00
}
2017-07-06 14:42:16 +00:00
void rlc_tm::write_pdu(uint8_t *payload, uint32_t nof_bytes)
2017-05-18 10:52:29 +00:00
{
byte_buffer_t *buf = pool_allocate;
if (buf) {
memcpy(buf->msg, payload, nof_bytes);
buf->N_bytes = nof_bytes;
buf->set_timestamp();
pdcp->write_pdu(lcid, buf);
} else {
log->error("Fatal Error: Couldn't allocate buffer in rlc_tm::write_pdu().\n");
}
2017-05-18 10:52:29 +00:00
}
} // namespace srsue