created a unique byte buffer that automatically deallocates

This commit is contained in:
Francisco Paisana 2019-04-29 20:16:51 +01:00 committed by Andre Puschmann
parent 4edcedd2b3
commit 0976ea6f27
23 changed files with 265 additions and 206 deletions

View File

@ -119,9 +119,7 @@ public:
while (try_pop(item));
}
myobj front() {
return q.front();
}
myobj& front() { return q.front(); }
size_t size() {
return q.size();

View File

@ -222,6 +222,25 @@ private:
buffer_pool<byte_buffer_t> *pool;
};
inline bool byte_buffer_guard::allocate()
{
deallocate();
buf = pool->allocate();
if (buf == nullptr) {
// allocation failed
pool = nullptr;
return false;
}
return true;
}
inline void byte_buffer_guard::deallocate()
{
if (buf != nullptr) {
pool->deallocate(buf);
buf = nullptr;
}
}
} // namespace srsue

View File

@ -266,6 +266,80 @@ private:
#endif
};
class byte_buffer_pool;
class byte_buffer_guard
{
public:
byte_buffer_guard(byte_buffer_pool* pool_) : pool(pool_) {}
byte_buffer_guard(byte_buffer_t* buf_, byte_buffer_pool* pool_) : buf(buf_), pool(pool_) {}
byte_buffer_guard(const byte_buffer_guard& other) = delete;
byte_buffer_guard& operator=(const byte_buffer_guard& other) = delete;
// move ctor
byte_buffer_guard(byte_buffer_guard&& other)
{
printf("In move ctor\n");
buf = other.buf;
pool = other.pool;
other.buf = nullptr;
}
byte_buffer_guard& operator=(byte_buffer_guard&& other) noexcept
{
printf("in copy move ctor\n");
if (this == &other) {
return *this;
}
this->buf = other.buf;
this->pool = other.pool;
other.buf = nullptr;
return *this;
}
~byte_buffer_guard() { deallocate(); }
void set_pool(byte_buffer_pool* pool_)
{
deallocate();
pool = pool_;
}
// acquire already alloc buffer
void acquire(byte_buffer_t* buf_) { buf = buf_; }
// allocate buffer
// bool allocate() {
// deallocate();
// buf = pool->allocate();
// if(buf == nullptr) {
// // allocation failed
// pool = nullptr;
// return false;
// }
// return true;
// }
bool allocate();
void deallocate();
byte_buffer_t* operator->() { return buf; }
const byte_buffer_t* operator->() const { return buf; }
byte_buffer_t* get() { return buf; }
const byte_buffer_t* get() const { return buf; }
const byte_buffer_pool* get_pool() const { return pool; }
private:
byte_buffer_t* buf = nullptr;
byte_buffer_pool* pool;
// void deallocate() {
// if (buf != nullptr) {
// printf("called dealloc!\n");
// pool->deallocate(buf);
// }
// }
};
typedef byte_buffer_guard unique_pool_buffer;
} // namespace srslte
#endif // SRSLTE_COMMON_H

View File

@ -199,7 +199,7 @@ public:
class pdcp_interface_gtpu
{
public:
virtual void write_sdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t *sdu) = 0;
virtual void write_sdu(uint16_t rnti, uint32_t lcid, srslte::unique_pool_buffer sdu) = 0;
};
// PDCP interface for RRC

View File

@ -114,8 +114,8 @@ public:
class gw_interface_pdcp
{
public:
virtual void write_pdu(uint32_t lcid, srslte::byte_buffer_t *pdu) = 0;
virtual void write_pdu_mch(uint32_t lcid, srslte::byte_buffer_t *pdu) = 0;
virtual void write_pdu(uint32_t lcid, srslte::unique_pool_buffer pdu) = 0;
virtual void write_pdu_mch(uint32_t lcid, srslte::unique_pool_buffer pdu) = 0;
};
// NAS interface for RRC
@ -132,7 +132,7 @@ public:
virtual void set_barring(barring_t barring) = 0;
virtual void paging(asn1::rrc::s_tmsi_s* ue_identiy) = 0;
virtual bool is_attached() = 0;
virtual void write_pdu(uint32_t lcid, srslte::byte_buffer_t *pdu) = 0;
virtual void write_pdu(uint32_t lcid, srslte::unique_pool_buffer pdu) = 0;
virtual uint32_t get_k_enb_count() = 0;
virtual bool get_k_asme(uint8_t *k_asme_, uint32_t n) = 0;
virtual uint32_t get_ipv4_addr() = 0;
@ -189,7 +189,7 @@ public:
const static int MAX_FOUND_PLMNS = 16;
virtual void write_sdu(srslte::byte_buffer_t *sdu) = 0;
virtual void write_sdu(srslte::unique_pool_buffer sdu) = 0;
virtual uint16_t get_mcc() = 0;
virtual uint16_t get_mnc() = 0;
virtual void enable_capabilities() = 0;
@ -205,11 +205,11 @@ public:
class rrc_interface_pdcp
{
public:
virtual void write_pdu(uint32_t lcid, srslte::byte_buffer_t *pdu) = 0;
virtual void write_pdu_bcch_bch(srslte::byte_buffer_t *pdu) = 0;
virtual void write_pdu_bcch_dlsch(srslte::byte_buffer_t *pdu) = 0;
virtual void write_pdu_pcch(srslte::byte_buffer_t *pdu) = 0;
virtual void write_pdu_mch(uint32_t lcid, srslte::byte_buffer_t *pdu) = 0;
virtual void write_pdu(uint32_t lcid, srslte::unique_pool_buffer pdu) = 0;
virtual void write_pdu_bcch_bch(srslte::unique_pool_buffer pdu) = 0;
virtual void write_pdu_bcch_dlsch(srslte::unique_pool_buffer pdu) = 0;
virtual void write_pdu_pcch(srslte::unique_pool_buffer pdu) = 0;
virtual void write_pdu_mch(uint32_t lcid, srslte::unique_pool_buffer pdu) = 0;
virtual std::string get_rb_name(uint32_t lcid) = 0;
};
@ -225,7 +225,7 @@ public:
class pdcp_interface_gw
{
public:
virtual void write_sdu(uint32_t lcid, srslte::byte_buffer_t *sdu, bool blocking) = 0;
virtual void write_sdu(uint32_t lcid, srslte::unique_pool_buffer sdu, bool blocking) = 0;
virtual bool is_lcid_enabled(uint32_t lcid) = 0;
};
@ -235,7 +235,7 @@ class pdcp_interface_rrc
public:
virtual void reestablish() = 0;
virtual void reset() = 0;
virtual void write_sdu(uint32_t lcid, srslte::byte_buffer_t *sdu, bool blocking = true) = 0;
virtual void write_sdu(uint32_t lcid, srslte::unique_pool_buffer sdu, bool blocking = true) = 0;
virtual void add_bearer(uint32_t lcid, srslte::srslte_pdcp_config_t cnfg = srslte::srslte_pdcp_config_t()) = 0;
virtual void change_lcid(uint32_t old_lcid, uint32_t new_lcid) = 0;
virtual void config_security(uint32_t lcid,
@ -260,11 +260,11 @@ class pdcp_interface_rlc
{
public:
/* RLC calls PDCP to push a PDCP PDU. */
virtual void write_pdu(uint32_t lcid, srslte::byte_buffer_t *sdu) = 0;
virtual void write_pdu_bcch_bch(srslte::byte_buffer_t *sdu) = 0;
virtual void write_pdu_bcch_dlsch(srslte::byte_buffer_t *sdu) = 0;
virtual void write_pdu_pcch(srslte::byte_buffer_t *sdu) = 0;
virtual void write_pdu_mch(uint32_t lcid, srslte::byte_buffer_t *sdu) = 0;
virtual void write_pdu(uint32_t lcid, srslte::unique_pool_buffer sdu) = 0;
virtual void write_pdu_bcch_bch(srslte::unique_pool_buffer sdu) = 0;
virtual void write_pdu_bcch_dlsch(srslte::unique_pool_buffer sdu) = 0;
virtual void write_pdu_pcch(srslte::unique_pool_buffer sdu) = 0;
virtual void write_pdu_mch(uint32_t lcid, srslte::unique_pool_buffer sdu) = 0;
};
// RLC interface for RRC
@ -289,7 +289,7 @@ class rlc_interface_pdcp
public:
/* PDCP calls RLC to push an RLC SDU. SDU gets placed into the RLC buffer and MAC pulls
* RLC PDUs according to TB size. */
virtual void write_sdu(uint32_t lcid, srslte::byte_buffer_t *sdu, bool blocking = true) = 0;
virtual void write_sdu(uint32_t lcid, srslte::unique_pool_buffer sdu, bool blocking = true) = 0;
virtual bool rb_is_um(uint32_t lcid) = 0;
};

View File

@ -51,8 +51,8 @@ public:
// RRC interface
void reestablish();
void reset();
void write_sdu(uint32_t lcid, byte_buffer_t *sdu, bool blocking = true);
void write_sdu_mch(uint32_t lcid, byte_buffer_t *sdu);
void write_sdu(uint32_t lcid, unique_pool_buffer sdu, bool blocking = true);
void write_sdu_mch(uint32_t lcid, unique_pool_buffer sdu);
void add_bearer(uint32_t lcid, srslte_pdcp_config_t cnfg = srslte_pdcp_config_t());
void add_bearer_mrb(uint32_t lcid, srslte_pdcp_config_t cnfg = srslte_pdcp_config_t());
void del_bearer(uint32_t lcid);
@ -74,11 +74,11 @@ public:
uint32_t get_ul_count(uint32_t lcid);
// RLC interface
void write_pdu(uint32_t lcid, byte_buffer_t *sdu);
void write_pdu_mch(uint32_t lcid, byte_buffer_t *sdu);
void write_pdu_bcch_bch(byte_buffer_t *sdu);
void write_pdu_bcch_dlsch(byte_buffer_t *sdu);
void write_pdu_pcch(byte_buffer_t *sdu);
void write_pdu(uint32_t lcid, unique_pool_buffer sdu);
void write_pdu_mch(uint32_t lcid, unique_pool_buffer sdu);
void write_pdu_bcch_bch(unique_pool_buffer sdu);
void write_pdu_bcch_dlsch(unique_pool_buffer sdu);
void write_pdu_pcch(unique_pool_buffer sdu);
private:
srsue::rlc_interface_pdcp *rlc;

View File

@ -72,7 +72,7 @@ public:
bool is_active();
// RRC interface
void write_sdu(byte_buffer_t *sdu, bool blocking);
void write_sdu(unique_pool_buffer sdu, bool blocking);
void config_security(uint8_t *k_rrc_enc_,
uint8_t *k_rrc_int_,
uint8_t *k_up_enc_,
@ -84,7 +84,7 @@ public:
uint32_t get_ul_count();
// RLC interface
void write_pdu(byte_buffer_t *pdu);
void write_pdu(unique_pool_buffer pdu);
private:
byte_buffer_pool *pool;

View File

@ -50,7 +50,7 @@ public:
virtual bool is_active() = 0;
// RRC interface
virtual void write_sdu(byte_buffer_t *sdu, bool blocking) = 0;
virtual void write_sdu(unique_pool_buffer sdu, bool blocking) = 0;
virtual void config_security(uint8_t *k_rrc_enc_,
uint8_t *k_rrc_int_,
uint8_t *k_up_enc_,
@ -62,7 +62,7 @@ public:
virtual uint32_t get_ul_count() = 0;
// RLC interface
virtual void write_pdu(byte_buffer_t *pdu) = 0;
virtual void write_pdu(unique_pool_buffer pdu) = 0;
};
} // namespace srslte

View File

@ -56,8 +56,8 @@ public:
void get_metrics(rlc_metrics_t &m);
// PDCP interface
void write_sdu(uint32_t lcid, byte_buffer_t *sdu, bool blocking = true);
void write_sdu_mch(uint32_t lcid, byte_buffer_t *sdu);
void write_sdu(uint32_t lcid, unique_pool_buffer sdu, bool blocking = true);
void write_sdu_mch(uint32_t lcid, unique_pool_buffer sdu);
bool rb_is_um(uint32_t lcid);
// MAC interface

View File

@ -81,7 +81,7 @@ public:
uint32_t get_bearer();
// PDCP interface
void write_sdu(byte_buffer_t *sdu, bool blocking = true);
void write_sdu(unique_pool_buffer sdu, bool blocking = true);
// MAC interface
bool has_data();
@ -109,7 +109,7 @@ private:
void reestablish();
void stop();
void write_sdu(byte_buffer_t *sdu, bool blocking);
void write_sdu(unique_pool_buffer sdu, bool blocking);
int read_pdu(uint8_t *payload, uint32_t nof_bytes);
bool has_data();

View File

@ -161,7 +161,7 @@ public:
virtual void reset_metrics() = 0;
// PDCP interface
virtual void write_sdu(byte_buffer_t *sdu, bool blocking) = 0;
virtual void write_sdu(unique_pool_buffer sdu, bool blocking) = 0;
// MAC interface
virtual bool has_data() = 0;

View File

@ -36,7 +36,7 @@
namespace srslte {
class rlc_tx_queue : public block_queue<byte_buffer_t*>::call_mutexed_itf
class rlc_tx_queue : public block_queue<unique_pool_buffer>::call_mutexed_itf
{
public:
rlc_tx_queue(int capacity = 128) : queue(capacity) {
@ -54,26 +54,17 @@ public:
unread_bytes = 0;
}
}
void write(byte_buffer_t *msg)
void write(unique_pool_buffer msg) { queue.push(std::move(msg)); }
bool try_write(unique_pool_buffer msg) { return queue.try_push(std::move(msg)); }
void read(unique_pool_buffer* msg)
{
queue.push(msg);
unique_pool_buffer m = queue.wait_pop();
*msg = std::move(m);
}
bool try_write(byte_buffer_t *msg)
{
return queue.try_push(msg);
}
void read(byte_buffer_t **msg)
{
byte_buffer_t *m = queue.wait_pop();
*msg = m;
}
bool try_read(byte_buffer_t **msg)
{
return queue.try_pop(msg);
}
bool try_read(unique_pool_buffer* msg) { return queue.try_pop(msg); }
void resize(uint32_t capacity)
{
@ -92,8 +83,8 @@ public:
uint32_t size_tail_bytes()
{
if (!queue.empty()) {
byte_buffer_t *m = queue.front();
if (m) {
unique_pool_buffer& m = queue.front();
if (m.get()) {
return m->N_bytes;
}
}
@ -110,8 +101,7 @@ public:
}
private:
block_queue<byte_buffer_t*> queue;
block_queue<unique_pool_buffer> queue;
uint32_t unread_bytes;
};

View File

@ -117,23 +117,22 @@ bool pdcp::is_lcid_enabled(uint32_t lcid)
return ret;
}
void pdcp::write_sdu(uint32_t lcid, byte_buffer_t *sdu, bool blocking)
void pdcp::write_sdu(uint32_t lcid, unique_pool_buffer sdu, bool blocking)
{
pthread_rwlock_rdlock(&rwlock);
if (valid_lcid(lcid)) {
pdcp_array.at(lcid)->write_sdu(sdu, blocking);
pdcp_array.at(lcid)->write_sdu(std::move(sdu), blocking);
} else {
pdcp_log->warning("Writing sdu: lcid=%d. Deallocating sdu\n", lcid);
byte_buffer_pool::get_instance()->deallocate(sdu);
}
pthread_rwlock_unlock(&rwlock);
}
void pdcp::write_sdu_mch(uint32_t lcid, byte_buffer_t *sdu)
void pdcp::write_sdu_mch(uint32_t lcid, unique_pool_buffer sdu)
{
pthread_rwlock_rdlock(&rwlock);
if (valid_mch_lcid(lcid)){
pdcp_array_mrb.at(lcid)->write_sdu(sdu, true);
pdcp_array_mrb.at(lcid)->write_sdu(std::move(sdu), true);
}
pthread_rwlock_unlock(&rwlock);
}
@ -277,39 +276,38 @@ uint32_t pdcp::get_ul_count(uint32_t lcid)
/*******************************************************************************
RLC interface
*******************************************************************************/
void pdcp::write_pdu(uint32_t lcid, byte_buffer_t *pdu)
void pdcp::write_pdu(uint32_t lcid, unique_pool_buffer pdu)
{
pthread_rwlock_rdlock(&rwlock);
if (valid_lcid(lcid)) {
pdcp_array.at(lcid)->write_pdu(pdu);
pdcp_array.at(lcid)->write_pdu(std::move(pdu));
} else {
pdcp_log->warning("Writing pdu: lcid=%d. Deallocating pdu\n", lcid);
byte_buffer_pool::get_instance()->deallocate(pdu);
}
pthread_rwlock_unlock(&rwlock);
}
void pdcp::write_pdu_bcch_bch(byte_buffer_t *sdu)
void pdcp::write_pdu_bcch_bch(unique_pool_buffer sdu)
{
rrc->write_pdu_bcch_bch(sdu);
rrc->write_pdu_bcch_bch(std::move(sdu));
}
void pdcp::write_pdu_bcch_dlsch(byte_buffer_t *sdu)
void pdcp::write_pdu_bcch_dlsch(unique_pool_buffer sdu)
{
rrc->write_pdu_bcch_dlsch(sdu);
rrc->write_pdu_bcch_dlsch(std::move(sdu));
}
void pdcp::write_pdu_pcch(byte_buffer_t *sdu)
void pdcp::write_pdu_pcch(unique_pool_buffer sdu)
{
rrc->write_pdu_pcch(sdu);
rrc->write_pdu_pcch(std::move(sdu));
}
void pdcp::write_pdu_mch(uint32_t lcid, byte_buffer_t *sdu)
void pdcp::write_pdu_mch(uint32_t lcid, unique_pool_buffer sdu)
{
if (0 == lcid) {
rrc->write_pdu_mch(lcid, sdu);
rrc->write_pdu_mch(lcid, std::move(sdu));
} else {
gw->write_pdu_mch(lcid, sdu);
gw->write_pdu_mch(lcid, std::move(sdu));
}
}

View File

@ -112,7 +112,7 @@ bool pdcp_entity::is_active()
}
// GW/RRC interface
void pdcp_entity::write_sdu(byte_buffer_t *sdu, bool blocking)
void pdcp_entity::write_sdu(unique_pool_buffer sdu, bool blocking)
{
log->info_hex(sdu->msg, sdu->N_bytes,
"TX %s SDU, SN: %d, do_integrity = %s, do_encryption = %s",
@ -122,7 +122,7 @@ void pdcp_entity::write_sdu(byte_buffer_t *sdu, bool blocking)
pthread_mutex_lock(&mutex);
if (cfg.is_control) {
pdcp_pack_control_pdu(tx_count, sdu);
pdcp_pack_control_pdu(tx_count, sdu.get());
if(do_integrity) {
integrity_generate(sdu->msg,
sdu->N_bytes-4,
@ -132,9 +132,9 @@ void pdcp_entity::write_sdu(byte_buffer_t *sdu, bool blocking)
if (cfg.is_data) {
if(12 == cfg.sn_len) {
pdcp_pack_data_pdu_long_sn(tx_count, sdu);
pdcp_pack_data_pdu_long_sn(tx_count, sdu.get());
} else {
pdcp_pack_data_pdu_short_sn(tx_count, sdu);
pdcp_pack_data_pdu_short_sn(tx_count, sdu.get());
}
}
@ -148,7 +148,7 @@ void pdcp_entity::write_sdu(byte_buffer_t *sdu, bool blocking)
pthread_mutex_unlock(&mutex);
rlc->write_sdu(lcid, sdu, blocking);
rlc->write_sdu(lcid, std::move(sdu), blocking);
}
void pdcp_entity::config_security(uint8_t *k_rrc_enc_,
@ -178,14 +178,13 @@ void pdcp_entity::enable_encryption()
}
// RLC interface
void pdcp_entity::write_pdu(byte_buffer_t *pdu)
void pdcp_entity::write_pdu(unique_pool_buffer pdu)
{
log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU, do_integrity = %s, do_encryption = %s",
rrc->get_rb_name(lcid).c_str(), (do_integrity) ? "true" : "false", (do_encryption) ? "true" : "false");
// Sanity check
if(pdu->N_bytes <= sn_len_bytes) {
pool->deallocate(pdu);
return;
}
@ -203,12 +202,12 @@ void pdcp_entity::write_pdu(byte_buffer_t *pdu)
}
if(12 == cfg.sn_len)
{
pdcp_unpack_data_pdu_long_sn(pdu, &sn);
pdcp_unpack_data_pdu_long_sn(pdu.get(), &sn);
} else {
pdcp_unpack_data_pdu_short_sn(pdu, &sn);
pdcp_unpack_data_pdu_short_sn(pdu.get(), &sn);
}
log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU SN: %d", rrc->get_rb_name(lcid).c_str(), sn);
gw->write_pdu(lcid, pdu);
gw->write_pdu(lcid, std::move(pdu));
} else {
// Handle SRB messages
if (cfg.is_control) {
@ -231,11 +230,11 @@ void pdcp_entity::write_pdu(byte_buffer_t *pdu)
}
}
pdcp_unpack_control_pdu(pdu, &sn);
pdcp_unpack_control_pdu(pdu.get(), &sn);
log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU SN: %d", rrc->get_rb_name(lcid).c_str(), sn);
}
// pass to RRC
rrc->write_pdu(lcid, pdu);
rrc->write_pdu(lcid, std::move(pdu));
}
exit:
rx_count++;

View File

@ -199,12 +199,11 @@ void rlc::empty_queue()
PDCP interface
*******************************************************************************/
void rlc::write_sdu(uint32_t lcid, byte_buffer_t *sdu, bool blocking)
void rlc::write_sdu(uint32_t lcid, unique_pool_buffer sdu, bool blocking)
{
// FIXME: rework build PDU logic to allow large SDUs (without concatenation)
if (sdu->N_bytes > RLC_MAX_SDU_SIZE) {
rlc_log->warning("Dropping too long SDU of size %d B (Max. size %d B).\n", sdu->N_bytes, RLC_MAX_SDU_SIZE);
pool->deallocate(sdu);
return;
}
@ -213,19 +212,17 @@ void rlc::write_sdu(uint32_t lcid, byte_buffer_t *sdu, bool blocking)
rlc_array.at(lcid)->write_sdu(sdu, blocking);
} else {
rlc_log->warning("RLC LCID %d doesn't exist. Deallocating SDU\n", lcid);
byte_buffer_pool::get_instance()->deallocate(sdu);
}
pthread_rwlock_unlock(&rwlock);
}
void rlc::write_sdu_mch(uint32_t lcid, byte_buffer_t *sdu)
void rlc::write_sdu_mch(uint32_t lcid, unique_pool_buffer sdu)
{
pthread_rwlock_rdlock(&rwlock);
if (valid_lcid_mrb(lcid)) {
rlc_array_mrb.at(lcid)->write_sdu(sdu, false); // write in non-blocking mode by default
} else {
rlc_log->warning("RLC LCID %d doesn't exist. Deallocating SDU\n", lcid);
byte_buffer_pool::get_instance()->deallocate(sdu);
}
pthread_rwlock_unlock(&rwlock);
}

View File

@ -128,7 +128,7 @@ void rlc_am::reset_metrics()
* PDCP interface
***************************************************************************/
void rlc_am::write_sdu(byte_buffer_t *sdu, bool blocking)
void rlc_am::write_sdu(unique_pool_buffer sdu, bool blocking)
{
tx.write_sdu(sdu, blocking);
}
@ -362,26 +362,24 @@ uint32_t rlc_am::rlc_am_tx::get_buffer_state()
return n_bytes;
}
void rlc_am::rlc_am_tx::write_sdu(byte_buffer_t *sdu, bool blocking)
void rlc_am::rlc_am_tx::write_sdu(unique_pool_buffer sdu, bool blocking)
{
if (!tx_enabled) {
byte_buffer_pool::get_instance()->deallocate(sdu);
return;
}
if (sdu != NULL) {
if (sdu.get() != NULL) {
if (blocking) {
// block on write to queue
tx_sdu_queue.write(sdu);
tx_sdu_queue.write(std::move(sdu));
log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU (%d B, tx_sdu_queue_len=%d)", RB_NAME, sdu->N_bytes, tx_sdu_queue.size());
} else {
// non-blocking write
if (tx_sdu_queue.try_write(sdu)) {
if (tx_sdu_queue.try_write(std::move(sdu))) {
log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU (%d B, tx_sdu_queue_len=%d)", RB_NAME, sdu->N_bytes, tx_sdu_queue.size());
} else {
log->info_hex(sdu->msg, sdu->N_bytes, "[Dropped SDU] %s Tx SDU (%d B, tx_sdu_queue_len=%d)", RB_NAME,
sdu->N_bytes, tx_sdu_queue.size());
pool->deallocate(sdu);
}
}
} else {

View File

@ -53,7 +53,7 @@ public:
void rem_user(uint16_t rnti);
// gtpu_interface_pdcp
void write_pdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t *pdu);
void write_pdu(uint16_t rnti, uint32_t lcid, srslte::unique_pool_buffer pdu);
private:
static const int THREAD_PRIO = 65;

View File

@ -45,8 +45,8 @@ public:
// pdcp_interface_rrc
void reset(uint16_t rnti);
void add_user(uint16_t rnti);
void rem_user(uint16_t rnti);
void write_sdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t *sdu);
void rem_user(uint16_t rnti);
void write_sdu(uint16_t rnti, uint32_t lcid, srslte::unique_pool_buffer sdu);
void add_bearer(uint16_t rnti, uint32_t lcid, srslte::srslte_pdcp_config_t cnfg);
void config_security(uint16_t rnti,
uint32_t lcid,

View File

@ -111,7 +111,7 @@ void gtpu::stop()
}
// gtpu_interface_pdcp
void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* pdu)
void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::unique_pool_buffer pdu)
{
gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "TX PDU, RNTI: 0x%x, LCID: %d, n_bytes=%d", rnti, lcid, pdu->N_bytes);
gtpu_header_t header;
@ -125,7 +125,7 @@ void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* pdu)
servaddr.sin_addr.s_addr = htonl(rnti_bearers[rnti].spgw_addrs[lcid]);
servaddr.sin_port = htons(GTPU_PORT);
if(!gtpu_write_header(&header, pdu, gtpu_log)){
if (!gtpu_write_header(&header, pdu.get(), gtpu_log)) {
gtpu_log->error("Error writing GTP-U Header. Flags 0x%x, Message Type 0x%x\n", header.flags, header.message_type);
return;
}
@ -133,7 +133,6 @@ void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* pdu)
perror("sendto");
}
pool->deallocate(pdu);
}
/* Warning: This function is called before calling gtpu::init() during MCCH initialization.
@ -192,9 +191,10 @@ void gtpu::rem_user(uint16_t rnti)
void gtpu::run_thread()
{
byte_buffer_t *pdu = pool_allocate;
unique_pool_buffer pdu(pool);
pdu.allocate();
if (!pdu) {
if (!pdu.get()) {
gtpu_log->error("Fatal Error: Couldn't allocate buffer in gtpu::run_thread().\n");
return;
}
@ -222,7 +222,7 @@ void gtpu::run_thread()
pdu->N_bytes = (uint32_t) n;
gtpu_header_t header;
if(!gtpu_read_header(pdu, &header,gtpu_log)){
if (!gtpu_read_header(pdu.get(), &header, gtpu_log)) {
continue;
}
@ -255,15 +255,15 @@ void gtpu::run_thread()
gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "RX GTPU PDU rnti=0x%x, lcid=%d, n_bytes=%d", rnti, lcid, pdu->N_bytes);
pdcp->write_sdu(rnti, lcid, pdu);
pdcp->write_sdu(rnti, lcid, std::move(pdu));
do {
pdu = pool_allocate;
if (!pdu) {
pdu.allocate();
if (!pdu.get()) {
gtpu_log->console("GTPU Buffer pool empty. Trying again...\n");
usleep(10000);
}
} while(!pdu);
} while (!pdu.get());
break;
}
}
@ -275,7 +275,8 @@ void gtpu::echo_response(in_addr_t addr, in_port_t port, uint16_t seq)
gtpu_log->info("TX GTPU Echo Response, Seq: %d\n", seq);
gtpu_header_t header;
srslte::byte_buffer_t *pdu = pool_allocate;
unique_pool_buffer pdu(pool);
pdu.allocate();
//header
header.flags = GTPU_FLAGS_VERSION_V1 | GTPU_FLAGS_GTP_PROTOCOL | GTPU_FLAGS_SEQUENCE;
@ -286,7 +287,7 @@ void gtpu::echo_response(in_addr_t addr, in_port_t port, uint16_t seq)
header.n_pdu = 0;
header.next_ext_hdr_type = 0;
gtpu_write_header(&header,pdu,gtpu_log);
gtpu_write_header(&header, pdu.get(), gtpu_log);
struct sockaddr_in servaddr;
servaddr.sin_family = AF_INET;
@ -294,7 +295,6 @@ void gtpu::echo_response(in_addr_t addr, in_port_t port, uint16_t seq)
servaddr.sin_port = port;
sendto(fd, pdu->msg, 12, MSG_EOR, (struct sockaddr*)&servaddr, sizeof(struct sockaddr_in));
pool->deallocate(pdu);
}
/****************************************************************************
@ -371,7 +371,7 @@ void gtpu::mch_thread::run_thread()
return;
}
byte_buffer_t *pdu;
unique_pool_buffer pdu(pool);
int n;
socklen_t addrlen;
sockaddr_in src_addr;
@ -385,7 +385,7 @@ void gtpu::mch_thread::run_thread()
run_enable = true;
running=true;
pdu = pool->allocate();
pdu.allocate();
// Warning: Use mutex here if creating multiple services each with a different thread
uint16_t lcid = lcid_counter;
@ -402,15 +402,15 @@ void gtpu::mch_thread::run_thread()
pdu->N_bytes = (uint32_t) n;
gtpu_header_t header;
gtpu_read_header(pdu, &header, gtpu_log);
pdcp->write_sdu(SRSLTE_MRNTI, lcid, pdu);
gtpu_read_header(pdu.get(), &header, gtpu_log);
pdcp->write_sdu(SRSLTE_MRNTI, lcid, std::move(pdu));
do {
pdu = pool_allocate;
if (!pdu) {
pdu.allocate();
if (!pdu.get()) {
gtpu_log->console("GTPU Buffer pool empty. Trying again...\n");
usleep(10000);
}
} while(!pdu);
} while (!pdu.get());
}
running = false;
}

View File

@ -141,7 +141,7 @@ void pdcp::write_pdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* sdu)
pthread_rwlock_unlock(&rwlock);
}
void pdcp::write_sdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* sdu)
void pdcp::write_sdu(uint16_t rnti, uint32_t lcid, srslte::unique_pool_buffer sdu)
{
pthread_rwlock_rdlock(&rwlock);
if (users.count(rnti)) {
@ -150,8 +150,6 @@ void pdcp::write_sdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* sdu)
}else {
users[rnti].pdcp->write_sdu_mch(lcid, sdu);
}
} else {
pool->deallocate(sdu);
}
pthread_rwlock_unlock(&rwlock);
}

View File

@ -82,7 +82,7 @@ public:
// RRC interface
void paging(asn1::rrc::s_tmsi_s* ue_identiy);
void set_barring(barring_t barring);
void write_pdu(uint32_t lcid, byte_buffer_t *pdu);
void write_pdu(uint32_t lcid, unique_pool_buffer pdu);
uint32_t get_k_enb_count();
bool is_attached();
bool get_k_asme(uint8_t *k_asme_, uint32_t n);

View File

@ -307,19 +307,20 @@ public:
typedef enum { Rx = 0, Tx } direction_t;
template <class T>
void log_rrc_message(const std::string source, const direction_t dir, const byte_buffer_t* pdu, const T& msg);
void
log_rrc_message(const std::string source, const direction_t dir, const srslte::unique_pool_buffer& pdu, const T& msg);
void print_mbms();
bool mbms_service_start(uint32_t serv, uint32_t port);
// NAS interface
void write_sdu(byte_buffer_t *sdu);
void write_sdu(srslte::unique_pool_buffer sdu);
void enable_capabilities();
uint16_t get_mcc();
uint16_t get_mnc();
int plmn_search(found_plmn_t found_plmns[MAX_FOUND_PLMNS]);
void plmn_select(asn1::rrc::plmn_id_s plmn_id);
bool connection_request(asn1::rrc::establishment_cause_e cause, srslte::byte_buffer_t* dedicated_info_nas);
bool connection_request(asn1::rrc::establishment_cause_e cause, srslte::unique_pool_buffer dedicated_info_nas);
void set_ue_idenity(asn1::rrc::s_tmsi_s s_tmsi);
// PHY interface
@ -338,11 +339,11 @@ public:
bool have_drb();
// PDCP interface
void write_pdu(uint32_t lcid, byte_buffer_t *pdu);
void write_pdu_bcch_bch(byte_buffer_t *pdu);
void write_pdu_bcch_dlsch(byte_buffer_t *pdu);
void write_pdu_pcch(byte_buffer_t *pdu);
void write_pdu_mch(uint32_t lcid, srslte::byte_buffer_t *pdu);
void write_pdu(uint32_t lcid, srslte::unique_pool_buffer pdu);
void write_pdu_bcch_bch(srslte::unique_pool_buffer pdu);
void write_pdu_bcch_dlsch(srslte::unique_pool_buffer pdu);
void write_pdu_pcch(srslte::unique_pool_buffer pdu);
void write_pdu_mch(uint32_t lcid, srslte::unique_pool_buffer pdu);
private:
@ -352,7 +353,7 @@ private:
PCCH,
STOP
} command;
byte_buffer_t *pdu;
srslte::unique_pool_buffer pdu;
uint16_t lcid;
} cmd_msg_t;
@ -360,7 +361,7 @@ private:
srslte::block_queue<cmd_msg_t> cmd_q;
void run_thread();
void process_pcch(byte_buffer_t *pdu);
void process_pcch(srslte::unique_pool_buffer pdu);
srslte::byte_buffer_pool *pool;
srslte::log *rrc_log;
@ -372,7 +373,7 @@ private:
usim_interface_rrc *usim;
gw_interface_rrc *gw;
byte_buffer_t* dedicated_info_nas;
srslte::unique_pool_buffer dedicated_info_nas;
void send_ul_ccch_msg(const asn1::rrc::ul_ccch_msg_s& msg);
void send_ul_dcch_msg(uint32_t lcid, const asn1::rrc::ul_dcch_msg_s& msg);
@ -625,17 +626,17 @@ private:
void send_con_request(asn1::rrc::establishment_cause_e cause);
void send_con_restablish_request(asn1::rrc::reest_cause_e cause);
void send_con_restablish_complete();
void send_con_setup_complete(byte_buffer_t* nas_msg);
void send_ul_info_transfer(byte_buffer_t* nas_msg);
void send_con_setup_complete(srslte::unique_pool_buffer nas_msg);
void send_ul_info_transfer(srslte::unique_pool_buffer nas_msg);
void send_security_mode_complete();
void send_rrc_con_reconfig_complete();
void send_rrc_ue_cap_info();
// Parsers
void process_pdu(uint32_t lcid, byte_buffer_t* pdu);
void parse_dl_ccch(byte_buffer_t* pdu);
void parse_dl_dcch(uint32_t lcid, byte_buffer_t* pdu);
void parse_dl_info_transfer(uint32_t lcid, byte_buffer_t* pdu);
void process_pdu(uint32_t lcid, srslte::unique_pool_buffer pdu);
void parse_dl_ccch(srslte::unique_pool_buffer pdu);
void parse_dl_dcch(uint32_t lcid, srslte::unique_pool_buffer pdu);
void parse_dl_info_transfer(uint32_t lcid, srslte::unique_pool_buffer pdu);
// Helpers
bool con_reconfig(asn1::rrc::rrc_conn_recfg_s* reconfig);

View File

@ -51,7 +51,8 @@ rrc::rrc() :
last_state(RRC_STATE_CONNECTED),
drb_up(false),
rlc_flush_timeout(2000),
rlc_flush_counter(0)
rlc_flush_counter(0),
dedicated_info_nas(NULL)
{
n310_cnt = 0;
n311_cnt = 0;
@ -96,7 +97,7 @@ void rrc::srslte_rrc_log(const char* str)
}
template <class T>
void rrc::log_rrc_message(const std::string source, const direction_t dir, const byte_buffer_t* pdu, const T& msg)
void rrc::log_rrc_message(const std::string source, const direction_t dir, const unique_pool_buffer& pdu, const T& msg)
{
if (rrc_log->get_level() == srslte::LOG_LEVEL_INFO) {
rrc_log->info("%s - %s %s (%d B)\n", source.c_str(), (dir == Rx) ? "Rx" : "Tx",
@ -157,7 +158,7 @@ void rrc::init(phy_interface_rrc* phy_,
t311 = mac_timers->timer_get_unique_id();
t304 = mac_timers->timer_get_unique_id();
dedicated_info_nas = NULL;
dedicated_info_nas.set_pool(pool);
ue_identity_configured = false;
transaction_id = 0;
@ -218,10 +219,10 @@ void rrc::run_thread() {
cmd_msg_t msg = cmd_q.wait_pop();
switch(msg.command) {
case cmd_msg_t::PDU:
process_pdu(msg.lcid, msg.pdu);
process_pdu(msg.lcid, std::move(msg.pdu));
break;
case cmd_msg_t::PCCH:
process_pcch(msg.pdu);
process_pcch(std::move(msg.pdu));
break;
case cmd_msg_t::STOP:
return;
@ -424,7 +425,7 @@ void rrc::plmn_select(asn1::rrc::plmn_id_s plmn_id)
* it. Sends connectionRequest message and returns if message transmitted successfully.
* It does not wait until completition of Connection Establishment procedure
*/
bool rrc::connection_request(asn1::rrc::establishment_cause_e cause, srslte::byte_buffer_t* dedicated_info_nas)
bool rrc::connection_request(asn1::rrc::establishment_cause_e cause, srslte::unique_pool_buffer dedicated_info_nas)
{
if (!plmn_is_selected) {
@ -472,11 +473,10 @@ bool rrc::connection_request(asn1::rrc::establishment_cause_e cause, srslte::byt
send_con_request(cause);
// Save dedicatedInfoNAS SDU
if (this->dedicated_info_nas) {
if (this->dedicated_info_nas.get()) {
rrc_log->warning("Received a new dedicatedInfoNAS SDU but there was one still in queue. Removing it\n");
pool->deallocate(this->dedicated_info_nas);
}
this->dedicated_info_nas = dedicated_info_nas;
this->dedicated_info_nas = std::move(dedicated_info_nas);
// Wait until t300 stops due to RRCConnectionSetup/Reject or expiry
while (mac_timers->timer_get(t300)->is_running()) {
@ -519,8 +519,7 @@ bool rrc::connection_request(asn1::rrc::establishment_cause_e cause, srslte::byt
if (!ret) {
rrc_log->warning("Could not establish connection. Deallocating dedicatedInfoNAS PDU\n");
pool->deallocate(this->dedicated_info_nas);
this->dedicated_info_nas = NULL;
this->dedicated_info_nas.deallocate();
}
pthread_mutex_unlock(&mutex);
@ -1433,7 +1432,8 @@ void rrc::send_con_restablish_complete() {
send_ul_dcch_msg(RB_ID_SRB1, ul_dcch_msg);
}
void rrc::send_con_setup_complete(byte_buffer_t *nas_msg) {
void rrc::send_con_setup_complete(srslte::unique_pool_buffer nas_msg)
{
rrc_log->debug("Preparing RRC Connection Setup Complete\n");
// Prepare ConnectionSetupComplete packet
@ -1447,11 +1447,10 @@ void rrc::send_con_setup_complete(byte_buffer_t *nas_msg) {
rrc_conn_setup_complete->ded_info_nas.resize(nas_msg->N_bytes);
memcpy(rrc_conn_setup_complete->ded_info_nas.data(), nas_msg->msg, nas_msg->N_bytes); // TODO Check!
pool->deallocate(nas_msg);
send_ul_dcch_msg(RB_ID_SRB1, ul_dcch_msg);
}
void rrc::send_ul_info_transfer(byte_buffer_t* nas_msg)
void rrc::send_ul_info_transfer(unique_pool_buffer nas_msg)
{
uint32_t lcid = rlc->has_bearer(RB_ID_SRB2) ? RB_ID_SRB2 : RB_ID_SRB1;
@ -1464,8 +1463,6 @@ void rrc::send_ul_info_transfer(byte_buffer_t* nas_msg)
rrc_ul_info_transfer->ded_info_type.ded_info_nas().resize(nas_msg->N_bytes);
memcpy(rrc_ul_info_transfer->ded_info_type.ded_info_nas().data(), nas_msg->msg, nas_msg->N_bytes); // TODO Check!
pool->deallocate(nas_msg);
send_ul_dcch_msg(lcid, ul_dcch_msg);
}
@ -1662,13 +1659,13 @@ bool rrc::con_reconfig(asn1::rrc::rrc_conn_recfg_s* reconfig)
send_rrc_con_reconfig_complete();
byte_buffer_t *nas_sdu;
unique_pool_buffer nas_sdu(pool);
for (uint32_t i = 0; i < reconfig_r8->ded_info_nas_list.size(); i++) {
nas_sdu = pool_allocate;
if (nas_sdu) {
nas_sdu.allocate();
if (nas_sdu.get()) {
memcpy(nas_sdu->msg, reconfig_r8->ded_info_nas_list[i].data(), reconfig_r8->ded_info_nas_list[i].size());
nas_sdu->N_bytes = reconfig_r8->ded_info_nas_list[i].size();
nas->write_pdu(RB_ID_SRB1, nas_sdu);
nas->write_pdu(RB_ID_SRB1, std::move(nas_sdu));
} else {
rrc_log->error("Fatal Error: Couldn't allocate PDU in handle_rrc_con_reconfig().\n");
return false;
@ -1770,14 +1767,14 @@ void rrc::stop_timers()
*
*
*******************************************************************************/
void rrc::write_pdu_bcch_bch(byte_buffer_t* pdu)
void rrc::write_pdu_bcch_bch(unique_pool_buffer pdu)
{
// Do we need to do something with BCH?
rrc_log->info_hex(pdu->msg, pdu->N_bytes, "BCCH BCH message received.");
pool->deallocate(pdu);
}
void rrc::write_pdu_bcch_dlsch(byte_buffer_t *pdu) {
void rrc::write_pdu_bcch_dlsch(unique_pool_buffer pdu)
{
// Stop BCCH search after successful reception of 1 BCCH block
mac->bcch_stop_rx();
@ -1790,7 +1787,6 @@ void rrc::write_pdu_bcch_dlsch(byte_buffer_t *pdu) {
}
log_rrc_message("BCCH", Rx, pdu, dlsch_msg);
pool->deallocate(pdu);
if (dlsch_msg.msg.c1().type() == bcch_dl_sch_msg_type_c::c1_c_::types::sib_type1) {
rrc_log->info("Processing SIB1 (1/1)\n");
@ -1930,22 +1926,22 @@ void rrc::handle_sib13()
*
*
*******************************************************************************/
void rrc::write_pdu_pcch(byte_buffer_t* pdu)
void rrc::write_pdu_pcch(unique_pool_buffer pdu)
{
cmd_msg_t msg;
msg.pdu = pdu;
msg.pdu = std::move(pdu);
msg.command = cmd_msg_t::PCCH;
cmd_q.push(msg);
}
void rrc::process_pcch(byte_buffer_t* pdu)
void rrc::process_pcch(unique_pool_buffer pdu)
{
if (pdu->N_bytes > 0 && pdu->N_bytes < SRSLTE_MAX_BUFFER_SIZE_BITS) {
pcch_msg_s pcch_msg;
asn1::bit_ref bref(pdu->msg, pdu->N_bytes);
if (pcch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or pcch_msg.msg.type().value != pcch_msg_type_c::types_opts::c1) {
rrc_log->error("Failed to unpack PCCH message\n");
goto exit;
return;
}
log_rrc_message("PCCH", Rx, pdu, pcch_msg);
@ -1957,7 +1953,7 @@ void rrc::process_pcch(byte_buffer_t* pdu)
if (not ue_identity_configured) {
rrc_log->warning("Received paging message but no ue-Identity is configured\n");
goto exit;
return;
}
s_tmsi_s* s_tmsi_paged;
@ -1992,11 +1988,9 @@ void rrc::process_pcch(byte_buffer_t* pdu)
} else {
rrc_log->error_hex(pdu->buffer, pdu->N_bytes, "Dropping PCCH message with %d B\n", pdu->N_bytes);
}
exit:
pool->deallocate(pdu);
}
void rrc::write_pdu_mch(uint32_t lcid, srslte::byte_buffer_t *pdu)
void rrc::write_pdu_mch(uint32_t lcid, srslte::unique_pool_buffer pdu)
{
if (pdu->N_bytes > 0 && pdu->N_bytes < SRSLTE_MAX_BUFFER_SIZE_BITS) {
//TODO: handle MCCH notifications and update MCCH
@ -2005,15 +1999,13 @@ void rrc::write_pdu_mch(uint32_t lcid, srslte::byte_buffer_t *pdu)
if (serving_cell->mcch.unpack(bref) != asn1::SRSASN_SUCCESS or
serving_cell->mcch.msg.type().value != mcch_msg_type_c::types_opts::c1) {
rrc_log->error("Failed to unpack MCCH message\n");
goto exit;
return;
}
serving_cell->has_mcch = true;
phy->set_config_mbsfn_mcch(&serving_cell->mcch);
log_rrc_message("MCH", Rx, pdu, serving_cell->mcch);
}
}
exit:
pool->deallocate(pdu);
}
@ -2032,8 +2024,8 @@ exit:
void rrc::send_ul_ccch_msg(const asn1::rrc::ul_ccch_msg_s& msg)
{
// Reset and reuse sdu buffer if provided
byte_buffer_t *pdcp_buf = pool_allocate_blocking;
if (not pdcp_buf) {
unique_pool_buffer pdcp_buf(pool_allocate_blocking, pool);
if (not pdcp_buf.get()) {
rrc_log->error("Fatal Error: Couldn't allocate PDU in byte_align_and_pack().\n");
return;
}
@ -2058,14 +2050,14 @@ void rrc::send_ul_ccch_msg(const asn1::rrc::ul_ccch_msg_s& msg)
uint32_t lcid = RB_ID_SRB0;
log_rrc_message(get_rb_name(lcid).c_str(), Tx, pdcp_buf, msg);
pdcp->write_sdu(lcid, pdcp_buf);
pdcp->write_sdu(lcid, std::move(pdcp_buf));
}
void rrc::send_ul_dcch_msg(uint32_t lcid, const asn1::rrc::ul_dcch_msg_s& msg)
{
// Reset and reuse sdu buffer if provided
byte_buffer_t* pdcp_buf = pool_allocate_blocking;
if (not pdcp_buf) {
unique_pool_buffer pdcp_buf(pool_allocate_blocking, pool);
if (not pdcp_buf.get()) {
rrc_log->error("Fatal Error: Couldn't allocate PDU in byte_align_and_pack().\n");
return;
}
@ -2078,19 +2070,20 @@ void rrc::send_ul_dcch_msg(uint32_t lcid, const asn1::rrc::ul_dcch_msg_s& msg)
log_rrc_message(get_rb_name(lcid).c_str(), Tx, pdcp_buf, msg);
pdcp->write_sdu(lcid, pdcp_buf);
pdcp->write_sdu(lcid, std::move(pdcp_buf));
}
void rrc::write_sdu(byte_buffer_t *sdu) {
void rrc::write_sdu(srslte::unique_pool_buffer sdu)
{
if (state == RRC_STATE_IDLE) {
rrc_log->warning("Received ULInformationTransfer SDU when in IDLE\n");
return;
}
send_ul_info_transfer(sdu);
send_ul_info_transfer(std::move(sdu));
}
void rrc::write_pdu(uint32_t lcid, byte_buffer_t* pdu)
void rrc::write_pdu(uint32_t lcid, unique_pool_buffer pdu)
{
// If the message contains a ConnectionSetup, acknowledge the transmission to avoid blocking of paging procedure
if (lcid == 0) {
@ -2100,7 +2093,6 @@ void rrc::write_pdu(uint32_t lcid, byte_buffer_t* pdu)
if (dl_ccch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or
dl_ccch_msg.msg.type().value != dl_ccch_msg_type_c::types_opts::c1) {
rrc_log->error("Failed to unpack DL-CCCH message\n");
pool->deallocate(pdu);
return;
}
if (dl_ccch_msg.msg.c1().type() == dl_ccch_msg_type_c::c1_c_::types::rrc_conn_setup) {
@ -2115,21 +2107,21 @@ void rrc::write_pdu(uint32_t lcid, byte_buffer_t* pdu)
// add PDU to command queue
cmd_msg_t msg;
msg.pdu = pdu;
msg.pdu = std::move(pdu);
msg.command = cmd_msg_t::PDU;
msg.lcid = (uint16_t)lcid;
cmd_q.push(msg);
}
void rrc::process_pdu(uint32_t lcid, byte_buffer_t *pdu)
void rrc::process_pdu(uint32_t lcid, srslte::unique_pool_buffer pdu)
{
switch (lcid) {
case RB_ID_SRB0:
parse_dl_ccch(pdu);
parse_dl_ccch(std::move(pdu));
break;
case RB_ID_SRB1:
case RB_ID_SRB2:
parse_dl_dcch(lcid, pdu);
parse_dl_dcch(lcid, std::move(pdu));
break;
default:
rrc_log->error("RX PDU with invalid bearer id: %d", lcid);
@ -2137,18 +2129,16 @@ void rrc::process_pdu(uint32_t lcid, byte_buffer_t *pdu)
}
}
void rrc::parse_dl_ccch(byte_buffer_t* pdu)
void rrc::parse_dl_ccch(unique_pool_buffer pdu)
{
asn1::bit_ref bref(pdu->msg, pdu->N_bytes);
asn1::rrc::dl_ccch_msg_s dl_ccch_msg;
if (dl_ccch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or
dl_ccch_msg.msg.type().value != dl_ccch_msg_type_c::types_opts::c1) {
rrc_log->error("Failed to unpack DL-CCCH message\n");
pool->deallocate(pdu);
return;
}
log_rrc_message(get_rb_name(RB_ID_SRB0).c_str(), Rx, pdu, dl_ccch_msg);
pool->deallocate(pdu);
dl_ccch_msg_type_c::c1_c_* c1 = &dl_ccch_msg.msg.c1();
switch (dl_ccch_msg.msg.c1().type().value) {
@ -2190,31 +2180,29 @@ void rrc::parse_dl_ccch(byte_buffer_t* pdu)
}
}
void rrc::parse_dl_dcch(uint32_t lcid, byte_buffer_t* pdu)
void rrc::parse_dl_dcch(uint32_t lcid, unique_pool_buffer pdu)
{
asn1::bit_ref bref(pdu->msg, pdu->N_bytes);
asn1::rrc::dl_dcch_msg_s dl_dcch_msg;
if (dl_dcch_msg.unpack(bref) != asn1::SRSASN_SUCCESS or
dl_dcch_msg.msg.type().value != dl_dcch_msg_type_c::types_opts::c1) {
rrc_log->error("Failed to unpack DL-DCCH message\n");
pool->deallocate(pdu);
return;
}
log_rrc_message(get_rb_name(lcid).c_str(), Rx, pdu, dl_dcch_msg);
pool->deallocate(pdu);
dl_dcch_msg_type_c::c1_c_* c1 = &dl_dcch_msg.msg.c1();
switch (dl_dcch_msg.msg.c1().type().value) {
case dl_dcch_msg_type_c::c1_c_::types::dl_info_transfer:
pdu = pool_allocate_blocking;
if (!pdu) {
pdu = unique_pool_buffer(pool_allocate_blocking, pool);
if (!pdu.get()) {
rrc_log->error("Fatal error: out of buffers in pool\n");
return;
}
pdu->N_bytes = c1->dl_info_transfer().crit_exts.c1().dl_info_transfer_r8().ded_info_type.ded_info_nas().size();
memcpy(pdu->msg, c1->dl_info_transfer().crit_exts.c1().dl_info_transfer_r8().ded_info_type.ded_info_nas().data(),
pdu->N_bytes);
nas->write_pdu(lcid, pdu);
nas->write_pdu(lcid, std::move(pdu));
break;
case dl_dcch_msg_type_c::c1_c_::types::security_mode_cmd:
transaction_id = c1->security_mode_cmd().rrc_transaction_id;
@ -2825,9 +2813,8 @@ void rrc::handle_con_setup(rrc_conn_setup_s* setup)
nas->set_barring(nas_interface_rrc::BARRING_NONE);
if (dedicated_info_nas) {
send_con_setup_complete(dedicated_info_nas);
dedicated_info_nas = NULL; // deallocated Inside!
if (dedicated_info_nas.get()) {
send_con_setup_complete(std::move(dedicated_info_nas));
} else {
rrc_log->error("Pending to transmit a ConnectionSetupComplete but no dedicatedInfoNAS was in queue\n");
}