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
|
|
|
*
|
2020-11-26 01:25:22 -08:00
|
|
|
* Copyright 2013-2020 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-04-21 12:53:37 -07:00
|
|
|
#include "srslte/mac/pdu_queue.h"
|
2020-03-30 06:48:58 -07:00
|
|
|
#include "srslte/common/log_helper.h"
|
2017-05-18 03:11:31 -07:00
|
|
|
|
|
|
|
namespace srslte {
|
|
|
|
|
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.
|
|
|
|
*/
|
2020-12-15 07:19:12 -08:00
|
|
|
void pdu_queue::push(const uint8_t* ptr, uint32_t len, channel_t channel)
|
2017-05-18 03:11:31 -07:00
|
|
|
{
|
2018-03-05 05:33:51 -08:00
|
|
|
if (ptr) {
|
2019-12-16 07:04:22 -08:00
|
|
|
pdu_t* pdu = (pdu_t*)ptr;
|
|
|
|
pdu->len = len;
|
2018-04-25 04:44:58 -07:00
|
|
|
pdu->channel = channel;
|
2018-03-05 05:33:51 -08:00
|
|
|
pdu_q.push(pdu);
|
|
|
|
} 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;
|
|
|
|
while (pdu_q.try_pop(&pdu)) {
|
2017-05-18 03:11:31 -07:00
|
|
|
if (callback) {
|
2019-04-23 01:53:11 -07:00
|
|
|
callback->process_pdu(pdu->ptr, pdu->len, pdu->channel);
|
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;
|
|
|
|
while (pdu_q.try_pop(&pdu)) {
|
|
|
|
// nop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
} // namespace srslte
|