2020-11-26 01:25:22 -08:00
|
|
|
/**
|
2017-05-18 03:11:31 -07:00
|
|
|
*
|
2020-11-26 01:25:22 -08:00
|
|
|
* \section COPYRIGHT
|
2017-05-18 03:11:31 -07:00
|
|
|
*
|
2021-03-19 03:45:56 -07:00
|
|
|
* Copyright 2013-2021 Software Radio Systems Limited
|
2017-05-18 03:11:31 -07:00
|
|
|
*
|
2020-11-26 01:25:22 -08:00
|
|
|
* By using this file, you agree to the terms and conditions set
|
|
|
|
* forth in the LICENSE file which can be found at the top level of
|
|
|
|
* the distribution.
|
2017-05-18 03:11:31 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-03-19 03:45:56 -07:00
|
|
|
#include "srsran/mac/pdu_queue.h"
|
|
|
|
#include "srsran/common/log_helper.h"
|
2021-04-15 01:34:54 -07:00
|
|
|
#include "srsran/phy/utils/debug.h"
|
2017-05-18 03:11:31 -07:00
|
|
|
|
2021-03-19 03:45:56 -07:00
|
|
|
namespace srsran {
|
2017-05-18 03:11:31 -07:00
|
|
|
|
2021-02-02 04:49:54 -08:00
|
|
|
void pdu_queue::init(process_callback* callback_)
|
2017-05-18 03:11:31 -07:00
|
|
|
{
|
2019-12-16 07:04:22 -08:00
|
|
|
callback = callback_;
|
2017-05-18 03:11:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* pdu_queue::request(uint32_t len)
|
2019-12-16 07:04:22 -08:00
|
|
|
{
|
2017-05-18 03:11:31 -07:00
|
|
|
if (len > MAX_PDU_LEN) {
|
2021-02-02 04:49:54 -08:00
|
|
|
ERROR("Error request buffer of invalid size %d. Max bytes %d", len, MAX_PDU_LEN);
|
2019-12-16 07:04:22 -08:00
|
|
|
return NULL;
|
2017-05-18 03:11:31 -07:00
|
|
|
}
|
2021-01-15 01:59:39 -08:00
|
|
|
// This function must be non-blocking. In case we run out of buffers, it shall handle the error properly
|
|
|
|
pdu_t* pdu = pool.allocate("pdu_queue::request", false);
|
|
|
|
if (pdu) {
|
|
|
|
if ((void*)pdu->ptr != (void*)pdu) {
|
2021-02-02 04:49:54 -08:00
|
|
|
ERROR("Fatal error in memory alignment in struct pdu_queue::pdu_t");
|
2021-01-15 01:59:39 -08:00
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
return pdu->ptr;
|
|
|
|
} else {
|
2021-02-02 04:49:54 -08:00
|
|
|
logger.error("Not enough buffers for MAC PDU");
|
|
|
|
ERROR("Not enough buffers for MAC PDU");
|
2021-01-15 01:59:39 -08:00
|
|
|
return nullptr;
|
2017-05-18 03:11:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-15 07:19:12 -08:00
|
|
|
void pdu_queue::deallocate(const uint8_t* pdu)
|
2017-05-18 03:11:31 -07:00
|
|
|
{
|
2019-12-16 07:04:22 -08:00
|
|
|
if (!pool.deallocate((pdu_t*)pdu)) {
|
2021-02-02 04:49:54 -08:00
|
|
|
logger.warning("Error deallocating from buffer pool in deallocate(): buffer not created in this pool.");
|
2017-05-18 03:11:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
/* Demultiplexing of logical channels and dissassemble of MAC CE
|
|
|
|
* This function enqueues the packet and returns quicly because ACK
|
|
|
|
* deadline is important here.
|
|
|
|
*/
|
2021-06-02 08:31:17 -07:00
|
|
|
void pdu_queue::push(const uint8_t* ptr, uint32_t len, channel_t channel, int grant_nof_prbs)
|
2017-05-18 03:11:31 -07:00
|
|
|
{
|
2018-03-05 05:33:51 -08:00
|
|
|
if (ptr) {
|
2021-06-02 08:31:17 -07:00
|
|
|
pdu_t* pdu = (pdu_t*)ptr;
|
|
|
|
pdu->len = len;
|
|
|
|
pdu->channel = channel;
|
|
|
|
pdu->grant_nof_prbs = grant_nof_prbs;
|
2021-03-10 12:25:11 -08:00
|
|
|
if (!pdu_q.try_push(pdu)) {
|
|
|
|
logger.warning("Error pushing pdu: queue is full");
|
|
|
|
}
|
2018-03-05 05:33:51 -08:00
|
|
|
} else {
|
2021-02-02 04:49:54 -08:00
|
|
|
logger.warning("Error pushing pdu: ptr is empty");
|
2018-03-05 05:33:51 -08:00
|
|
|
}
|
2017-05-18 03:11:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool pdu_queue::process_pdus()
|
|
|
|
{
|
2019-12-16 07:04:22 -08:00
|
|
|
bool have_data = false;
|
|
|
|
uint32_t cnt = 0;
|
|
|
|
pdu_t* pdu;
|
2021-03-08 01:50:39 -08:00
|
|
|
while (pdu_q.try_pop(pdu)) {
|
2017-05-18 03:11:31 -07:00
|
|
|
if (callback) {
|
2021-06-02 08:31:17 -07:00
|
|
|
callback->process_pdu(pdu->ptr, pdu->len, pdu->channel, pdu->grant_nof_prbs);
|
2017-05-18 03:11:31 -07:00
|
|
|
}
|
|
|
|
cnt++;
|
|
|
|
have_data = true;
|
|
|
|
}
|
|
|
|
if (cnt > 20) {
|
2021-02-02 04:49:54 -08:00
|
|
|
logger.warning("PDU queue dispatched %d packets", cnt);
|
2017-05-18 03:11:31 -07:00
|
|
|
printf("Warning PDU queue dispatched %d packets\n", cnt);
|
|
|
|
}
|
2019-12-16 07:04:22 -08:00
|
|
|
return have_data;
|
2017-05-18 03:11:31 -07:00
|
|
|
}
|
|
|
|
|
2020-11-11 11:51:49 -08:00
|
|
|
void pdu_queue::reset()
|
|
|
|
{
|
|
|
|
pdu_t* pdu;
|
2021-03-08 01:50:39 -08:00
|
|
|
while (pdu_q.try_pop(pdu)) {
|
2020-11-11 11:51:49 -08:00
|
|
|
// nop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-19 03:45:56 -07:00
|
|
|
} // namespace srsran
|