remove old direct uses of byte_buffer_pool

This commit is contained in:
Francisco 2021-02-05 21:11:49 +00:00 committed by Francisco Paisana
parent 1e2153769e
commit 8a9c326bcb
16 changed files with 128 additions and 114 deletions

View File

@ -167,31 +167,37 @@ private:
class byte_buffer_pool
{
using mem_chunk = typename std::aligned_storage<sizeof(byte_buffer_t), alignof(byte_buffer_t)>::type;
public:
// Singleton static methods
static byte_buffer_pool* get_instance(int capacity = -1);
static byte_buffer_pool* get_instance(int capacity = -1)
{
static std::unique_ptr<byte_buffer_pool> instance(new byte_buffer_pool(capacity));
return instance.get();
}
byte_buffer_pool(int capacity = -1) : pool(capacity) {}
byte_buffer_pool(const byte_buffer_pool& other) = delete;
byte_buffer_pool(byte_buffer_pool&& other) = delete;
byte_buffer_pool& operator=(const byte_buffer_pool& other) = delete;
byte_buffer_t* allocate(const char* debug_name = nullptr, bool blocking = false)
byte_buffer_pool& operator=(byte_buffer_pool&& other) = delete;
void* allocate(const char* debug_name = nullptr, bool blocking = false)
{
return pool.allocate(debug_name, blocking);
}
void enable_logger(bool enabled) { print_to_log = enabled; }
void deallocate(byte_buffer_t* b)
void deallocate(void* b)
{
if (!b) {
return;
}
b->clear();
if (!pool.deallocate(b)) {
if (!pool.deallocate(static_cast<mem_chunk*>(b))) {
#ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED
print_error("Error deallocating PDU: Addr=0x%p, name=%s not found in pool", (void*)b, b->debug_name);
#else
print_error("Error deallocating PDU: Addr=0x%p", (void*)b);
#endif
}
b = nullptr;
}
void print_all_buffers() { pool.print_all_buffers(); }
@ -208,19 +214,37 @@ private:
}
private:
bool print_to_log = false;
buffer_pool<byte_buffer_t> pool;
bool print_to_log = false;
buffer_pool<mem_chunk> pool;
};
inline unique_byte_buffer_t allocate_unique_buffer(byte_buffer_pool& pool, bool blocking = false)
inline unique_byte_buffer_t allocate_unique_buffer(byte_buffer_pool& pool, bool blocking = false) noexcept
{
return unique_byte_buffer_t(pool.allocate(nullptr, blocking), byte_buffer_deleter(&pool));
return std::unique_ptr<byte_buffer_t>(new (std::nothrow) byte_buffer_t());
}
inline unique_byte_buffer_t
allocate_unique_buffer(byte_buffer_pool& pool, const char* debug_name, bool blocking = false)
allocate_unique_buffer(byte_buffer_pool& pool, const char* debug_name, bool blocking = false) noexcept
{
return unique_byte_buffer_t(pool.allocate(debug_name, blocking), byte_buffer_deleter(&pool));
std::unique_ptr<byte_buffer_t> buffer(new (std::nothrow) byte_buffer_t());
if (buffer == nullptr) {
srslog::fetch_basic_logger("POOL").error("Failed to allocate byte buffer in %s", debug_name);
}
return buffer;
}
inline unique_byte_buffer_t make_byte_buffer() noexcept
{
return std::unique_ptr<byte_buffer_t>(new (std::nothrow) byte_buffer_t());
}
inline unique_byte_buffer_t make_byte_buffer(const char* debug_ctxt) noexcept
{
std::unique_ptr<byte_buffer_t> buffer(new (std::nothrow) byte_buffer_t());
if (buffer == nullptr) {
srslog::fetch_basic_logger("POOL").error("Failed to allocate byte buffer in %s", debug_ctxt);
}
return buffer;
}
} // namespace srslte

View File

@ -162,6 +162,13 @@ public:
iterator end() { return msg + N_bytes; }
const_iterator end() const { return msg + N_bytes; }
void* operator new(size_t sz);
void* operator new(size_t sz, const std::nothrow_t& nothrow_value) noexcept;
void* operator new(size_t sz, void* ptr) noexcept { return ptr; }
void* operator new[](size_t sz) = delete;
void operator delete(void* ptr);
void operator delete[](void* ptr) = delete;
private:
buffer_latency_calc tp;
};
@ -198,21 +205,12 @@ struct bit_buffer_t {
N_bits = 0;
}
uint32_t get_headroom() { return msg - buffer; }
private:
};
// Create a Managed Life-Time Byte Buffer
class byte_buffer_pool;
class byte_buffer_deleter
{
public:
explicit byte_buffer_deleter(byte_buffer_pool* pool_ = nullptr) : pool(pool_) {}
void operator()(byte_buffer_t* buf) const;
byte_buffer_pool* pool;
};
using unique_byte_buffer_t = std::unique_ptr<byte_buffer_t, byte_buffer_deleter>;
using unique_byte_buffer_t = std::unique_ptr<byte_buffer_t>;
///
/// Utilities to create a span out of a byte_buffer.

View File

@ -15,12 +15,4 @@
#include <stdio.h>
#include <string>
namespace srslte {
byte_buffer_pool* byte_buffer_pool::get_instance(int capacity)
{
static std::unique_ptr<byte_buffer_pool> instance(new byte_buffer_pool(capacity));
return instance.get();
}
} // namespace srslte
namespace srslte {} // namespace srslte

View File

@ -15,11 +15,25 @@
namespace srslte {
void byte_buffer_deleter::operator()(byte_buffer_t* buf) const
void* byte_buffer_t::operator new(size_t sz, const std::nothrow_t& nothrow_value) noexcept
{
if (buf) {
pool->deallocate(buf);
}
assert(sz == sizeof(byte_buffer_t));
return byte_buffer_pool::get_instance()->allocate(nullptr, false);
}
} // namespace srslte
void* byte_buffer_t::operator new(size_t sz)
{
assert(sz == sizeof(byte_buffer_t));
void* ptr = byte_buffer_pool::get_instance()->allocate(nullptr, false);
if (ptr == nullptr) {
throw std::bad_alloc();
}
return ptr;
}
void byte_buffer_t::operator delete(void* ptr)
{
byte_buffer_pool::get_instance()->deallocate(ptr);
}
} // namespace srslte

View File

@ -235,7 +235,7 @@ int reassmble_test()
int n_pdus = 0;
byte_buffer_t* pdu_bufs[max_n_pdus];
for (int i = 0; i < max_n_pdus; i++) {
pdu_bufs[i] = byte_buffer_pool::get_instance()->allocate();
pdu_bufs[i] = new byte_buffer_t();
int len = ctxt.rlc1.read_pdu(pdu_bufs[i]->msg, (i == 0) ? sdu_len * 3 / 4 : sdu_len * 1.25);
pdu_bufs[i]->N_bytes = len;
if (len) {
@ -260,7 +260,7 @@ int reassmble_test()
// Read second batch of PDUs (use large grants)
for (int i = n_pdus; i < max_n_pdus; i++) {
pdu_bufs[i] = byte_buffer_pool::get_instance()->allocate();
pdu_bufs[i] = new byte_buffer_t();
int len = ctxt.rlc1.read_pdu(pdu_bufs[i]->msg, sdu_len * 1.25);
pdu_bufs[i]->N_bytes = len;
if (len) {
@ -327,7 +327,7 @@ int reassmble_test2()
int n_pdus = 0;
byte_buffer_t* pdu_bufs[max_n_pdus];
for (int i = 0; i < max_n_pdus; i++) {
pdu_bufs[i] = byte_buffer_pool::get_instance()->allocate();
pdu_bufs[i] = new byte_buffer_t();
int len = ctxt.rlc1.read_pdu(pdu_bufs[i]->msg, (i == 0) ? sdu_len * .75 : sdu_len * .25);
pdu_bufs[i]->N_bytes = len;
if (len) {
@ -352,7 +352,7 @@ int reassmble_test2()
// Read second batch of PDUs
for (int i = n_pdus; i < max_n_pdus; i++) {
pdu_bufs[i] = byte_buffer_pool::get_instance()->allocate();
pdu_bufs[i] = new byte_buffer_t();
int len = ctxt.rlc1.read_pdu(pdu_bufs[i]->msg, sdu_len * 1.25);
pdu_bufs[i]->N_bytes = len;
if (len) {

View File

@ -71,10 +71,9 @@ private:
uint16_t in_cksum(uint16_t* iphdr, int count);
/* Members */
bool m_running;
srslte::byte_buffer_pool* m_pool;
srslte::log_ref m_mbms_gw_log;
srslog::basic_logger& m_logger = srslog::fetch_basic_logger("MBMS");
bool m_running;
srslte::log_ref m_mbms_gw_log;
srslog::basic_logger& m_logger = srslog::fetch_basic_logger("MBMS");
bool m_sgi_mb_up;
int m_sgi_mb_if;

View File

@ -40,8 +40,7 @@ private:
s1ap_nas_transport();
virtual ~s1ap_nas_transport();
srslog::basic_logger& m_logger = srslog::fetch_basic_logger("S1AP");
srslte::byte_buffer_pool* m_pool;
srslog::basic_logger& m_logger = srslog::fetch_basic_logger("S1AP");
s1ap* m_s1ap;

View File

@ -67,9 +67,6 @@ public:
srslog::basic_logger& m_logger = srslog::fetch_basic_logger("GTPU");
//:TODO: remove this once srslte common code loggers have been upgraded.
srslte::log_ref m_gtpu_log;
private:
srslte::byte_buffer_pool* m_pool;
};
inline int spgw::gtpu::get_sgi()

View File

@ -73,9 +73,8 @@ private:
spgw_tunnel_ctx_t* create_gtp_ctx(struct srslte::gtpc_create_session_request* cs_req);
bool delete_gtp_ctx(uint32_t ctrl_teid);
bool m_running;
srslte::byte_buffer_pool* m_pool;
mme_gtpc* m_mme_gtpc;
bool m_running;
mme_gtpc* m_mme_gtpc;
// GTP-C and GTP-U handlers
gtpc* m_gtpc;

View File

@ -63,7 +63,6 @@ void mbms_gw::cleanup(void)
int mbms_gw::init(mbms_gw_args_t* args, srslte::log_ref mbms_gw_log)
{
int err;
m_pool = srslte::byte_buffer_pool::get_instance();
// Init log
m_mbms_gw_log = mbms_gw_log;
@ -232,7 +231,7 @@ void mbms_gw::run_thread()
// Mark the thread as running
m_running = true;
srslte::byte_buffer_t* msg;
msg = m_pool->allocate();
msg = new srslte::byte_buffer_t();
uint8_t seq = 0;
while (m_running) {
@ -249,7 +248,7 @@ void mbms_gw::run_thread()
handle_sgi_md_pdu(msg);
}
}
m_pool->deallocate(msg);
delete msg;
return;
}

View File

@ -89,8 +89,8 @@ void mme::stop()
void mme::run_thread()
{
srslte::byte_buffer_t* pdu = m_pool->allocate("mme::run_thread");
uint32_t sz = SRSLTE_MAX_BUFFER_SIZE_BYTES - SRSLTE_BUFFER_HEADER_OFFSET;
srslte::unique_byte_buffer_t pdu = srslte::make_byte_buffer("mme::run_thread");
uint32_t sz = SRSLTE_MAX_BUFFER_SIZE_BYTES - SRSLTE_BUFFER_HEADER_OFFSET;
struct sockaddr_in enb_addr;
struct sctp_sndrcvinfo sri;
@ -147,14 +147,14 @@ void mme::run_thread()
// Received data
pdu->N_bytes = rd_sz;
m_s1ap_logger.info("Received S1AP msg. Size: %d", pdu->N_bytes);
m_s1ap->handle_s1ap_rx_pdu(pdu, &sri);
m_s1ap->handle_s1ap_rx_pdu(pdu.get(), &sri);
}
}
}
// Handle S11
if (FD_ISSET(s11, &m_set)) {
pdu->N_bytes = recvfrom(s11, pdu->msg, sz, 0, NULL, NULL);
m_mme_gtpc->handle_s11_pdu(pdu);
m_mme_gtpc->handle_s11_pdu(pdu.get());
}
// Handle NAS Timers
for (std::vector<mme_timer_t>::iterator it = timers.begin(); it != timers.end();) {

View File

@ -276,13 +276,13 @@ bool nas::handle_imsi_attach_request_unknown_ue(uint32_t
s1ap->add_ue_to_enb_set(enb_sri->sinfo_assoc_id, nas_ctx->m_ecm_ctx.mme_ue_s1ap_id);
// Pack NAS Authentication Request in Downlink NAS Transport msg
nas_tx = pool->allocate();
nas_tx = new srslte::byte_buffer_t();
nas_ctx->pack_authentication_request(nas_tx);
// Send reply to eNB
s1ap->send_downlink_nas_transport(
nas_ctx->m_ecm_ctx.enb_ue_s1ap_id, nas_ctx->m_ecm_ctx.mme_ue_s1ap_id, nas_tx, nas_ctx->m_ecm_ctx.enb_sri);
pool->deallocate(nas_tx);
delete nas_tx;
nas_logger.info("Downlink NAS: Sending Authentication Request");
srslte::console("Downlink NAS: Sending Authentication Request\n");
@ -387,11 +387,11 @@ bool nas::handle_guti_attach_request_unknown_ue(uint32_t
s1ap->add_ue_to_enb_set(enb_sri->sinfo_assoc_id, nas_ctx->m_ecm_ctx.mme_ue_s1ap_id);
// Send Identity Request
nas_tx = pool->allocate();
nas_tx = new srslte::byte_buffer_t();
nas_ctx->pack_identity_request(nas_tx);
s1ap->send_downlink_nas_transport(
nas_ctx->m_ecm_ctx.enb_ue_s1ap_id, nas_ctx->m_ecm_ctx.mme_ue_s1ap_id, nas_tx, nas_ctx->m_ecm_ctx.enb_sri);
pool->deallocate(nas_tx);
delete nas_tx;
return true;
}
@ -465,7 +465,7 @@ bool nas::handle_guti_attach_request_known_ue(nas*
nas_logger.info(sec_ctx->k_enb, 32, "Key eNodeB (k_enb)");
// Send reply
nas_tx = pool->allocate();
nas_tx = new srslte::byte_buffer_t();
if (ecm_ctx->eit) {
srslte::console("Secure ESM information transfer requested.\n");
nas_logger.info("Secure ESM information transfer requested.");
@ -480,7 +480,7 @@ bool nas::handle_guti_attach_request_known_ue(nas*
gtpc->send_create_session_request(emm_ctx->imsi);
}
sec_ctx->ul_nas_count++;
pool->deallocate(nas_tx);
delete nas_tx;
return true;
} else {
if (emm_ctx->state != EMM_STATE_DEREGISTERED) {
@ -539,12 +539,12 @@ bool nas::handle_guti_attach_request_known_ue(nas*
// Restarting security context. Reseting eKSI to 0.
sec_ctx->eksi = 0;
nas_tx = pool->allocate();
nas_tx = new srslte::byte_buffer_t();
nas_ctx->pack_authentication_request(nas_tx);
// Send reply to eNB
s1ap->send_downlink_nas_transport(ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id, nas_tx, *enb_sri);
pool->deallocate(nas_tx);
delete nas_tx;
nas_logger.info("Downlink NAS: Sent Authentication Request");
srslte::console("Downlink NAS: Sent Authentication Request\n");
return true;
@ -590,10 +590,10 @@ bool nas::handle_service_request(uint32_t m_tmsi,
nas_tmp.m_ecm_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id;
nas_tmp.m_ecm_ctx.mme_ue_s1ap_id = s1ap->get_next_mme_ue_s1ap_id();
srslte::byte_buffer_t* nas_tx = pool->allocate();
srslte::byte_buffer_t* nas_tx = new srslte::byte_buffer_t();
nas_tmp.pack_service_reject(nas_tx, LIBLTE_MME_EMM_CAUSE_IMPLICITLY_DETACHED);
s1ap->send_downlink_nas_transport(enb_ue_s1ap_id, nas_tmp.m_ecm_ctx.mme_ue_s1ap_id, nas_tx, *enb_sri);
pool->deallocate(nas_tx);
delete nas_tx;
return true;
}
@ -605,10 +605,10 @@ bool nas::handle_service_request(uint32_t m_tmsi,
nas_tmp.m_ecm_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id;
nas_tmp.m_ecm_ctx.mme_ue_s1ap_id = s1ap->get_next_mme_ue_s1ap_id();
srslte::byte_buffer_t* nas_tx = pool->allocate();
srslte::byte_buffer_t* nas_tx = new srslte::byte_buffer_t();
nas_tmp.pack_service_reject(nas_tx, LIBLTE_MME_EMM_CAUSE_IMPLICITLY_DETACHED);
s1ap->send_downlink_nas_transport(enb_ue_s1ap_id, nas_tmp.m_ecm_ctx.mme_ue_s1ap_id, nas_tx, *enb_sri);
pool->deallocate(nas_tx);
delete nas_tx;
return true;
}
emm_ctx_t* emm_ctx = &nas_ctx->m_emm_ctx;
@ -690,10 +690,10 @@ bool nas::handle_service_request(uint32_t m_tmsi,
ecm_ctx->mme_ue_s1ap_id = s1ap->get_next_mme_ue_s1ap_id();
s1ap->add_nas_ctx_to_mme_ue_s1ap_id_map(nas_ctx);
s1ap->add_ue_to_enb_set(enb_sri->sinfo_assoc_id, nas_ctx->m_ecm_ctx.mme_ue_s1ap_id);
srslte::byte_buffer_t* nas_tx = pool->allocate();
srslte::byte_buffer_t* nas_tx = new srslte::byte_buffer_t();
nas_ctx->pack_service_reject(nas_tx, LIBLTE_MME_EMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED_BY_THE_NETWORK);
s1ap->send_downlink_nas_transport(ecm_ctx->enb_ue_s1ap_id, ecm_ctx->mme_ue_s1ap_id, nas_tx, *enb_sri);
pool->deallocate(nas_tx);
delete nas_tx;
srslte::console("Service Request -- Short MAC invalid. Sending service reject.\n");
nas_logger.warning("Service Request -- Short MAC invalid. Sending service reject.");
@ -796,10 +796,10 @@ bool nas::handle_tracking_area_update_request(uint32_t m_tmsi,
nas_tmp.m_ecm_ctx.enb_ue_s1ap_id = enb_ue_s1ap_id;
nas_tmp.m_ecm_ctx.mme_ue_s1ap_id = s1ap->get_next_mme_ue_s1ap_id();
srslte::byte_buffer_t* nas_tx = pool->allocate();
srslte::byte_buffer_t* nas_tx = new srslte::byte_buffer_t();
nas_tmp.pack_tracking_area_update_reject(nas_tx, LIBLTE_MME_EMM_CAUSE_IMPLICITLY_DETACHED);
s1ap->send_downlink_nas_transport(enb_ue_s1ap_id, nas_tmp.m_ecm_ctx.mme_ue_s1ap_id, nas_tx, *enb_sri);
pool->deallocate(nas_tx);
delete nas_tx;
return true;
}
@ -900,12 +900,12 @@ bool nas::handle_attach_request(srslte::byte_buffer_t* nas_rx)
m_s1ap->add_nas_ctx_to_imsi_map(this);
// Pack NAS Authentication Request in Downlink NAS Transport msg
srslte::byte_buffer_t* nas_tx = m_pool->allocate();
srslte::byte_buffer_t* nas_tx = new srslte::byte_buffer_t();
pack_authentication_request(nas_tx);
// Send reply to eNB
m_s1ap->send_downlink_nas_transport(m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id, nas_tx, m_ecm_ctx.enb_sri);
m_pool->deallocate(nas_tx);
delete nas_tx;
m_logger.info("Downlink NAS: Sending Authentication Request");
srslte::console("Downlink NAS: Sending Authentication Request\n");
@ -942,7 +942,7 @@ bool nas::handle_authentication_response(srslte::byte_buffer_t* nas_rx)
}
}
nas_tx = m_pool->allocate();
nas_tx = new srslte::byte_buffer_t();
if (!ue_valid) {
// Authentication rejected
srslte::console("UE Authentication Rejected.\n");
@ -964,7 +964,7 @@ bool nas::handle_authentication_response(srslte::byte_buffer_t* nas_rx)
// Send reply
m_s1ap->send_downlink_nas_transport(m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id, nas_tx, m_ecm_ctx.enb_sri);
m_pool->deallocate(nas_tx);
delete nas_tx;
return true;
}
@ -985,7 +985,7 @@ bool nas::handle_security_mode_complete(srslte::byte_buffer_t* nas_rx)
srslte::console("Security Mode Command Complete -- IMSI: %015" PRIu64 "\n", m_emm_ctx.imsi);
// Check wether secure ESM information transfer is required
nas_tx = m_pool->allocate();
nas_tx = new srslte::byte_buffer_t();
if (m_ecm_ctx.eit == true) {
// Secure ESM information transfer is required
srslte::console("Sending ESM information request\n");
@ -1003,7 +1003,7 @@ bool nas::handle_security_mode_complete(srslte::byte_buffer_t* nas_rx)
srslte::console("Getting subscription information -- QCI %d\n", m_esm_ctx[default_bearer].qci);
m_gtpc->send_create_session_request(m_emm_ctx.imsi);
}
m_pool->deallocate(nas_tx);
delete nas_tx;
return true;
}
@ -1042,11 +1042,11 @@ bool nas::handle_attach_complete(srslte::byte_buffer_t* nas_rx)
m_emm_ctx.imsi, act_bearer.eps_bearer_id, &m_esm_ctx[act_bearer.eps_bearer_id].enb_fteid);
// Send reply to EMM Info to UE
nas_tx = m_pool->allocate();
nas_tx = new srslte::byte_buffer_t();
pack_emm_information(nas_tx);
m_s1ap->send_downlink_nas_transport(m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id, nas_tx, m_ecm_ctx.enb_sri);
m_pool->deallocate(nas_tx);
delete nas_tx;
srslte::console("Sending EMM Information\n");
m_logger.info("Sending EMM Information");
@ -1131,12 +1131,12 @@ bool nas::handle_identity_response(srslte::byte_buffer_t* nas_rx)
m_s1ap->add_nas_ctx_to_imsi_map(this);
// Pack NAS Authentication Request in Downlink NAS Transport msg
nas_tx = m_pool->allocate();
nas_tx = new srslte::byte_buffer_t();
pack_authentication_request(nas_tx);
// Send reply to eNB
m_s1ap->send_downlink_nas_transport(m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id, nas_tx, m_ecm_ctx.enb_sri);
m_pool->deallocate(nas_tx);
delete nas_tx;
m_logger.info("Downlink NAS: Sent Authentication Request");
srslte::console("Downlink NAS: Sent Authentication Request\n");
@ -1153,12 +1153,12 @@ bool nas::handle_tracking_area_update_request(srslte::byte_buffer_t* nas_rx)
/* TAU handling unsupported, therefore send TAU reject with cause IMPLICITLY DETACHED.
* this will trigger full re-attach by the UE, instead of going to a TAU request loop */
nas_tx = pool->allocate();
nas_tx = new srslte::byte_buffer_t();
// TODO we could enable integrity protection in some cases, but UE should comply anyway
pack_tracking_area_update_reject(nas_tx, LIBLTE_MME_EMM_CAUSE_IMPLICITLY_DETACHED);
// Send reply
m_s1ap->send_downlink_nas_transport(m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id, nas_tx, m_ecm_ctx.enb_sri);
pool->deallocate(nas_tx);
delete nas_tx;
return true;
}
@ -1210,13 +1210,13 @@ bool nas::handle_authentication_failure(srslte::byte_buffer_t* nas_rx)
m_sec_ctx.eksi = (m_sec_ctx.eksi + 1) % 6;
// Pack NAS Authentication Request in Downlink NAS Transport msg
nas_tx = m_pool->allocate();
nas_tx = new srslte::byte_buffer_t();
pack_authentication_request(nas_tx);
// Send reply to eNB
m_s1ap->send_downlink_nas_transport(
m_ecm_ctx.enb_ue_s1ap_id, m_ecm_ctx.mme_ue_s1ap_id, nas_tx, m_ecm_ctx.enb_sri);
m_pool->deallocate(nas_tx);
delete nas_tx;
m_logger.info("Downlink NAS: Sent Authentication Request");
srslte::console("Downlink NAS: Sent Authentication Request\n");
@ -1228,7 +1228,6 @@ bool nas::handle_authentication_failure(srslte::byte_buffer_t* nas_rx)
bool nas::handle_detach_request(srslte::byte_buffer_t* nas_msg)
{
srslte::console("Detach request -- IMSI %015" PRIu64 "\n", m_emm_ctx.imsi);
m_logger.info("Detach request -- IMSI %015" PRIu64 "", m_emm_ctx.imsi);
LIBLTE_MME_DETACH_REQUEST_MSG_STRUCT detach_req;

View File

@ -57,7 +57,6 @@ void s1ap_nas_transport::cleanup(void)
void s1ap_nas_transport::init()
{
m_s1ap = s1ap::get_instance();
m_pool = srslte::byte_buffer_pool::get_instance();
// Init NAS args
m_nas_init.mcc = m_s1ap->m_s1ap_args.mcc;
@ -83,7 +82,7 @@ bool s1ap_nas_transport::handle_initial_ue_message(const asn1::s1ap::init_ue_msg
{
bool err, mac_valid;
uint8_t pd, msg_type, sec_hdr_type;
srslte::byte_buffer_t* nas_msg = m_pool->allocate();
srslte::byte_buffer_t* nas_msg = new srslte::byte_buffer_t();
memcpy(nas_msg->msg, init_ue.protocol_ies.nas_pdu.value.data(), init_ue.protocol_ies.nas_pdu.value.size());
nas_msg->N_bytes = init_ue.protocol_ies.nas_pdu.value.size();
@ -125,7 +124,7 @@ bool s1ap_nas_transport::handle_initial_ue_message(const asn1::s1ap::init_ue_msg
srslte::console("Unhandled Initial UE Message 0x%x \n", msg_type);
err = false;
}
m_pool->deallocate(nas_msg);
delete nas_msg;
return err;
}
@ -151,7 +150,7 @@ bool s1ap_nas_transport::handle_uplink_nas_transport(const asn1::s1ap::ul_nas_tr
sec_ctx_t* sec_ctx = &nas_ctx->m_sec_ctx;
// Parse NAS message header
srslte::byte_buffer_t* nas_msg = m_pool->allocate();
srslte::byte_buffer_t* nas_msg = new srslte::byte_buffer_t();
memcpy(nas_msg->msg, ul_xport.protocol_ies.nas_pdu.value.data(), ul_xport.protocol_ies.nas_pdu.value.size());
nas_msg->N_bytes = ul_xport.protocol_ies.nas_pdu.value.size();
bool msg_encrypted = false;
@ -166,7 +165,7 @@ bool s1ap_nas_transport::handle_uplink_nas_transport(const asn1::s1ap::ul_nas_tr
sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_WITH_NEW_EPS_SECURITY_CONTEXT ||
sec_hdr_type == LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED_WITH_NEW_EPS_SECURITY_CONTEXT)) {
m_logger.error("Unhandled security header type in Uplink NAS Transport: %d", sec_hdr_type);
m_pool->deallocate(nas_msg);
delete nas_msg;
return false;
}
// Todo: Check on count mismatch of uplink count and do resync nas counter...
@ -206,7 +205,7 @@ bool s1ap_nas_transport::handle_uplink_nas_transport(const asn1::s1ap::ul_nas_tr
m_logger.warning(
"Uplink NAS: could not find security context for integrity protected message. MME-UE S1AP id: %d",
mme_ue_s1ap_id);
m_pool->deallocate(nas_msg);
delete nas_msg;
return false;
}
}
@ -311,7 +310,7 @@ bool s1ap_nas_transport::handle_uplink_nas_transport(const asn1::s1ap::ul_nas_tr
default:
m_logger.warning("Unhandled NAS integrity protected message %s", liblte_nas_msg_type_to_string(msg_type));
srslte::console("Unhandled NAS integrity protected message %s\n", liblte_nas_msg_type_to_string(msg_type));
m_pool->deallocate(nas_msg);
delete nas_msg;
return false;
}
@ -320,7 +319,7 @@ bool s1ap_nas_transport::handle_uplink_nas_transport(const asn1::s1ap::ul_nas_tr
if (increase_ul_nas_cnt == true) {
sec_ctx->ul_nas_count++;
}
m_pool->deallocate(nas_msg);
delete nas_msg;
return true;
}

View File

@ -510,7 +510,7 @@ bool spgw::gtpc::queue_downlink_packet(uint32_t ctrl_teid, srslte::byte_buffer_t
return true;
pkt_discard:
m_pool->deallocate(msg);
delete msg;
return false;
}
@ -523,7 +523,7 @@ bool spgw::gtpc::free_all_queued_packets(spgw_tunnel_ctx_t* tunnel_ctx)
while (!tunnel_ctx->paging_queue.empty()) {
srslte::byte_buffer_t* pkt = tunnel_ctx->paging_queue.front();
m_logger.debug("Dropping packet. Bytes %d", pkt->N_bytes);
m_pool->deallocate(pkt);
delete pkt;
tunnel_ctx->paging_queue.pop();
}
return true;

View File

@ -35,7 +35,6 @@ namespace srsepc {
spgw::gtpu::gtpu() : m_sgi_up(false), m_s1u_up(false)
{
m_pool = srslte::byte_buffer_pool::get_instance();
return;
}
@ -244,7 +243,7 @@ void spgw::gtpu::handle_sgi_pdu(srslte::byte_buffer_t* msg)
return;
pkt_discard_out:
m_pool->deallocate(msg);
delete msg;
return;
}
@ -299,7 +298,7 @@ void spgw::gtpu::send_s1u_pdu(srslte::gtp_fteid_t enb_fteid, srslte::byte_buffer
out:
m_logger.debug("Deallocating packet after sending S1-U message");
m_pool->deallocate(msg);
delete msg;
return;
}

View File

@ -59,7 +59,6 @@ void spgw::cleanup()
int spgw::init(spgw_args_t* args, srslte::log_ref gtpu_log, const std::map<std::string, uint64_t>& ip_to_imsi)
{
int err;
m_pool = srslte::byte_buffer_pool::get_instance();
// Init GTP-U
if (m_gtpu->init(args, this, m_gtpc, gtpu_log) != SRSLTE_SUCCESS) {
@ -95,9 +94,9 @@ void spgw::run_thread()
{
// Mark the thread as running
m_running = true;
srslte::byte_buffer_t *sgi_msg, *s1u_msg, *s11_msg;
s1u_msg = m_pool->allocate("spgw::run_thread::s1u");
s11_msg = m_pool->allocate("spgw::run_thread::s11");
srslte::unique_byte_buffer_t sgi_msg, s1u_msg, s11_msg;
s1u_msg = srslte::make_byte_buffer("spgw::run_thread::s1u");
s11_msg = srslte::make_byte_buffer("spgw::run_thread::s11");
struct sockaddr_in src_addr_in;
struct sockaddr_un src_addr_un;
@ -113,7 +112,6 @@ void spgw::run_thread()
int max_fd = std::max(s1u, sgi);
max_fd = std::max(max_fd, s11);
while (m_running) {
s1u_msg->clear();
s11_msg->clear();
@ -136,28 +134,26 @@ void spgw::run_thread()
* handle_downlink_data_notification_failure)
*/
m_logger.debug("Message received at SPGW: SGi Message");
sgi_msg = m_pool->allocate("spgw::run_thread::sgi_msg");
sgi_msg = srslte::make_byte_buffer("spgw::run_thread::sgi_msg");
sgi_msg->N_bytes = read(sgi, sgi_msg->msg, buf_len);
m_gtpu->handle_sgi_pdu(sgi_msg);
m_gtpu->handle_sgi_pdu(sgi_msg.get());
}
if (FD_ISSET(s1u, &set)) {
m_logger.debug("Message received at SPGW: S1-U Message");
socklen_t addrlen = sizeof(src_addr_in);
s1u_msg->N_bytes = recvfrom(s1u, s1u_msg->msg, buf_len, 0, (struct sockaddr*)&src_addr_in, &addrlen);
m_gtpu->handle_s1u_pdu(s1u_msg);
m_gtpu->handle_s1u_pdu(s1u_msg.get());
}
if (FD_ISSET(s11, &set)) {
m_logger.debug("Message received at SPGW: S11 Message");
socklen_t addrlen = sizeof(src_addr_un);
s11_msg->N_bytes = recvfrom(s11, s11_msg->msg, buf_len, 0, (struct sockaddr*)&src_addr_un, &addrlen);
m_gtpc->handle_s11_pdu(s11_msg);
m_gtpc->handle_s11_pdu(s11_msg.get());
}
} else {
m_logger.debug("No data from select.");
}
}
m_pool->deallocate(s1u_msg);
m_pool->deallocate(s11_msg);
return;
}