diff --git a/lib/include/srslte/interfaces/ue_interfaces.h b/lib/include/srslte/interfaces/ue_interfaces.h index df96fdbee..859a46e83 100644 --- a/lib/include/srslte/interfaces/ue_interfaces.h +++ b/lib/include/srslte/interfaces/ue_interfaces.h @@ -35,6 +35,7 @@ #include "srslte/asn1/liblte_mme.h" #include "srslte/common/common.h" #include "srslte/common/interfaces_common.h" +#include "srslte/common/multiqueue.h" #include "srslte/common/security.h" #include "srslte/common/stack_procedure.h" #include "srslte/common/tti_point.h" @@ -296,9 +297,9 @@ public: /* MAC calls RLC to push an RLC PDU. This function is called from an independent MAC thread. * PDU gets placed into the buffer and higher layer thread gets notified. */ virtual void write_pdu(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) = 0; - virtual void write_pdu_bcch_bch(uint8_t* payload, uint32_t nof_bytes) = 0; + virtual void write_pdu_bcch_bch(srslte::unique_byte_buffer_t payload) = 0; virtual void write_pdu_bcch_dlsch(uint8_t* payload, uint32_t nof_bytes) = 0; - virtual void write_pdu_pcch(uint8_t* payload, uint32_t nof_bytes) = 0; + virtual void write_pdu_pcch(srslte::unique_byte_buffer_t payload) = 0; virtual void write_pdu_mch(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) = 0; }; diff --git a/lib/include/srslte/upper/rlc.h b/lib/include/srslte/upper/rlc.h index ad16c464b..522039e13 100644 --- a/lib/include/srslte/upper/rlc.h +++ b/lib/include/srslte/upper/rlc.h @@ -65,9 +65,9 @@ public: int read_pdu_mch(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes); int get_increment_sequence_num(); void write_pdu(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes); - void write_pdu_bcch_bch(uint8_t* payload, uint32_t nof_bytes); + void write_pdu_bcch_bch(srslte::unique_byte_buffer_t pdu); void write_pdu_bcch_dlsch(uint8_t* payload, uint32_t nof_bytes); - void write_pdu_pcch(uint8_t* payload, uint32_t nof_bytes); + void write_pdu_pcch(srslte::unique_byte_buffer_t pdu); void write_pdu_mch(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes); // RRC interface diff --git a/lib/src/upper/rlc.cc b/lib/src/upper/rlc.cc index 5af860bca..52f19edb7 100644 --- a/lib/src/upper/rlc.cc +++ b/lib/src/upper/rlc.cc @@ -346,18 +346,10 @@ void rlc::write_pdu(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) } // Pass directly to PDCP, no DL througput counting done -void rlc::write_pdu_bcch_bch(uint8_t* payload, uint32_t nof_bytes) +void rlc::write_pdu_bcch_bch(srslte::unique_byte_buffer_t pdu) { - rlc_log->info_hex(payload, nof_bytes, "BCCH BCH message received."); - unique_byte_buffer_t buf = allocate_unique_buffer(*pool); - if (buf != NULL) { - memcpy(buf->msg, payload, nof_bytes); - buf->N_bytes = nof_bytes; - buf->set_timestamp(); - pdcp->write_pdu_bcch_bch(std::move(buf)); - } else { - rlc_log->error("Fatal error: Out of buffers from the pool in write_pdu_bcch_bch()\n"); - } + rlc_log->info_hex(pdu->msg, pdu->N_bytes, "BCCH BCH message received."); + pdcp->write_pdu_bcch_bch(std::move(pdu)); } // Pass directly to PDCP, no DL througput counting done @@ -376,18 +368,10 @@ void rlc::write_pdu_bcch_dlsch(uint8_t* payload, uint32_t nof_bytes) } // Pass directly to PDCP, no DL througput counting done -void rlc::write_pdu_pcch(uint8_t* payload, uint32_t nof_bytes) +void rlc::write_pdu_pcch(srslte::unique_byte_buffer_t pdu) { - rlc_log->info_hex(payload, nof_bytes, "PCCH message received."); - unique_byte_buffer_t buf = allocate_unique_buffer(*pool); - if (buf != NULL) { - memcpy(buf->msg, payload, nof_bytes); - buf->N_bytes = nof_bytes; - buf->set_timestamp(); - pdcp->write_pdu_pcch(std::move(buf)); - } else { - rlc_log->error("Fatal error: Out of buffers from the pool in write_pdu_pcch()\n"); - } + rlc_log->info_hex(pdu->msg, pdu->N_bytes, "PCCH message received."); + pdcp->write_pdu_pcch(std::move(pdu)); } void rlc::write_pdu_mch(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) diff --git a/srsue/hdr/stack/mac/mac.h b/srsue/hdr/stack/mac/mac.h index 09d48c200..9ee87378d 100644 --- a/srsue/hdr/stack/mac/mac.h +++ b/srsue/hdr/stack/mac/mac.h @@ -171,6 +171,9 @@ private: void timer_alignment_expire(); srslte::timer_handler* timers = nullptr; + /* Queue to dispatch stack tasks */ + srslte::byte_buffer_pool* pool = nullptr; + // pointer to MAC PCAP object srslte::mac_pcap* pcap = nullptr; bool is_first_ul_grant = false; diff --git a/srsue/src/stack/mac/mac.cc b/srsue/src/stack/mac/mac.cc index 7d70fbe4c..6ed28236f 100644 --- a/srsue/src/stack/mac/mac.cc +++ b/srsue/src/stack/mac/mac.cc @@ -57,6 +57,8 @@ mac::mac(const char* logname) : srslte_softbuffer_rx_init(&pch_softbuffer, 100); srslte_softbuffer_rx_init(&mch_softbuffer, 100); + pool = srslte::byte_buffer_pool::get_instance(); + // Keep initialising members bzero(&metrics, sizeof(mac_metrics_t)); clear_rntis(); @@ -370,7 +372,15 @@ uint16_t mac::get_dl_sched_rnti(uint32_t tti) void mac::bch_decoded_ok(uint32_t cc_idx, uint8_t* payload, uint32_t len) { // Send MIB to RLC - rlc_h->write_pdu_bcch_bch(payload, len); + unique_byte_buffer_t buf = allocate_unique_buffer(*pool); + if (buf != nullptr) { + memcpy(buf->msg, payload, len); + buf->N_bytes = len; + buf->set_timestamp(); + rlc_h->write_pdu_bcch_bch(std::move(buf)); + } else { + log_h->error("Fatal error: Out of buffers from the pool in write_pdu_bcch_bch()\n"); + } if (pcap) { pcap->write_dl_bch(payload, len, true, phy_h->get_current_tti(), cc_idx); @@ -416,7 +426,15 @@ void mac::tb_decoded(uint32_t cc_idx, mac_grant_dl_t grant, bool ack[SRSLTE_MAX_ } } else if (grant.rnti == SRSLTE_PRNTI) { // Send PCH payload to RLC - rlc_h->write_pdu_pcch(pch_payload_buffer, grant.tb[0].tbs); + unique_byte_buffer_t pdu = srslte::allocate_unique_buffer(*pool); + if (pdu != nullptr) { + memcpy(pdu->msg, pch_payload_buffer, grant.tb[0].tbs); + pdu->N_bytes = grant.tb[0].tbs; + pdu->set_timestamp(); + rlc_h->write_pdu_pcch(std::move(pdu)); + } else { + log_h->error("Fatal error: Out of buffers from the pool in write_pdu_pcch()\n"); + } if (pcap) { pcap->write_dl_pch(pch_payload_buffer, grant.tb[0].tbs, true, grant.tti, cc_idx); diff --git a/srsue/test/common/dummy_classes.h b/srsue/test/common/dummy_classes.h index e1d695cb0..b709de6af 100644 --- a/srsue/test/common/dummy_classes.h +++ b/srsue/test/common/dummy_classes.h @@ -26,7 +26,7 @@ namespace srsue { -class stack_dummy : public stack_interface_rrc +class stack_dummy_interface : public stack_interface_rrc { public: srslte::timer_handler::unique_timer get_unique_timer() override { return timers.get_unique_timer(); } @@ -34,7 +34,21 @@ public: void start_cell_select(const phy_interface_rrc_lte::phy_cell_t* cell) override {} srslte::tti_point get_current_tti() override { return srslte::tti_point{timers.get_cur_time() % 10240}; } - srslte::timer_handler timers{100}; + srslte::timer_handler timers{100}; + srslte::task_multiqueue pending_tasks; +}; + +class rlc_dummy_interface : public rlc_interface_mac +{ +public: + bool has_data(const uint32_t lcid) override { return false; } + uint32_t get_buffer_state(const uint32_t lcid) override { return 0; } + int read_pdu(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) override { return 0; } + void write_pdu(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) override {} + void write_pdu_bcch_bch(srslte::unique_byte_buffer_t payload) override {} + void write_pdu_bcch_dlsch(uint8_t* payload, uint32_t nof_bytes) override {} + void write_pdu_pcch(srslte::unique_byte_buffer_t payload) override {} + void write_pdu_mch(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) override {} }; } // namespace srsue diff --git a/srsue/test/mac_test.cc b/srsue/test/mac_test.cc index b8fb2fc9e..6af250498 100644 --- a/srsue/test/mac_test.cc +++ b/srsue/test/mac_test.cc @@ -26,6 +26,7 @@ #include "srslte/interfaces/ue_interfaces.h" #include "srsue/hdr/stack/mac/mac.h" #include "srsue/hdr/stack/mac/mux.h" +#include "srsue/test/common/dummy_classes.h" #include #include #include @@ -50,13 +51,13 @@ srslte::log_ref mac_log{"MAC"}; namespace srslte { // fake classes -class rlc_dummy : public srsue::rlc_interface_mac +class rlc_dummy : public srsue::rlc_dummy_interface { public: rlc_dummy(srslte::log_filter* log_) : received_bytes(0), log(log_) {} - bool has_data(const uint32_t lcid) { return ul_queues[lcid] > 0; } - uint32_t get_buffer_state(const uint32_t lcid) { return ul_queues[lcid]; } - int read_pdu(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) + bool has_data(const uint32_t lcid) final { return ul_queues[lcid] > 0; } + uint32_t get_buffer_state(const uint32_t lcid) final { return ul_queues[lcid]; } + int read_pdu(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) final { if (!read_enable) { return 0; @@ -71,17 +72,13 @@ public: return len; }; - void write_pdu(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) + void write_pdu(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) final { log->debug_hex(payload, nof_bytes, "Received %d B on LCID %d\n", nof_bytes, lcid); received_bytes += nof_bytes; - }; + } void write_sdu(uint32_t lcid, uint32_t nof_bytes) { ul_queues[lcid] += nof_bytes; } - void write_pdu_bcch_bch(uint8_t* payload, uint32_t nof_bytes){}; - void write_pdu_bcch_dlsch(uint8_t* payload, uint32_t nof_bytes){}; - void write_pdu_pcch(uint8_t* payload, uint32_t nof_bytes){}; - void write_pdu_mch(uint32_t lcid, uint8_t* payload, uint32_t nof_bytes){}; uint32_t get_received_bytes() { return received_bytes; } void disable_read() { read_enable = false; } @@ -99,7 +96,7 @@ class phy_dummy : public phy_interface_mac_lte public: phy_dummy() : scell_cmd(0){}; - void set_log(srslte::log* log_h) { this->log_h = log_h; } + void set_log(srslte::log* log_h_) { log_h = log_h_; } void reset() { last_preamble_idx = 0; @@ -266,9 +263,9 @@ public: ul_mac_grant.tb.ndi_present = true; } - ul_mac_grant.is_rar = is_rar; - ul_mac_grant.rnti = rnti; - ul_mac_grant.tb.tbs = len; + ul_mac_grant.is_rar = is_rar; + ul_mac_grant.rnti = rnti; + ul_mac_grant.tb.tbs = len; // Send grant to MAC and get action for this TB, then call tb_decoded to unlock MAC mac_h->new_grant_ul(0, ul_mac_grant, &ul_action); diff --git a/srsue/test/upper/nas_test.cc b/srsue/test/upper/nas_test.cc index b428a9727..a10ac76fa 100644 --- a/srsue/test/upper/nas_test.cc +++ b/srsue/test/upper/nas_test.cc @@ -141,7 +141,7 @@ private: bool is_connected_flag = false; }; -class test_stack_dummy : public srsue::stack_dummy, public stack_interface_gw, public thread +class test_stack_dummy : public srsue::stack_dummy_interface, public stack_interface_gw, public thread { public: test_stack_dummy(pdcp_interface_gw* pdcp_) : pdcp(pdcp_), thread("DUMMY STACK") {} @@ -210,7 +210,7 @@ int security_command_test() rrc_log.set_level(srslte::LOG_LEVEL_DEBUG); rrc_log.set_hex_limit(100000); - stack_dummy stack; + stack_dummy_interface stack; rrc_dummy rrc_dummy; gw_dummy gw; @@ -352,7 +352,7 @@ int esm_info_request_test() rrc_log.set_level(srslte::LOG_LEVEL_DEBUG); rrc_log.set_hex_limit(100000); - srsue::stack_dummy stack{}; + srsue::stack_dummy_interface stack{}; rrc_dummy rrc_dummy; gw_dummy gw; @@ -406,7 +406,7 @@ int dedicated_eps_bearer_test() rrc_log.set_level(srslte::LOG_LEVEL_DEBUG); rrc_log.set_hex_limit(100000); - srsue::stack_dummy stack; + srsue::stack_dummy_interface stack; rrc_dummy rrc_dummy; gw_dummy gw; diff --git a/srsue/test/upper/rrc_meas_test.cc b/srsue/test/upper/rrc_meas_test.cc index cb132ce87..f90b3f505 100644 --- a/srsue/test/upper/rrc_meas_test.cc +++ b/srsue/test/upper/rrc_meas_test.cc @@ -167,10 +167,10 @@ private: class rrc_test : public rrc { - srsue::stack_dummy* stack = nullptr; + srsue::stack_dummy_interface* stack = nullptr; public: - rrc_test(srslte::log* log_, stack_dummy* stack_) : rrc(stack_), stack(stack_) + rrc_test(srslte::log* log_, stack_dummy_interface* stack_) : rrc(stack_), stack(stack_) { pool = srslte::byte_buffer_pool::get_instance(); nastest = std::unique_ptr(new nas_test(stack)); @@ -274,8 +274,8 @@ int cell_select_test() printf("====== Cell Select Testing ===============\n"); printf("==========================================================\n"); - stack_dummy stack; - rrc_test rrctest(&log1, &stack); + stack_dummy_interface stack; + rrc_test rrctest(&log1, &stack); rrctest.init(); rrctest.connect(); @@ -304,8 +304,8 @@ int meas_obj_test() printf("====== Object Configuration Testing ===============\n"); printf("==========================================================\n"); - stack_dummy stack; - rrc_test rrctest(&log1, &stack); + stack_dummy_interface stack; + rrc_test rrctest(&log1, &stack); rrctest.init(); rrctest.connect(); @@ -720,8 +720,8 @@ int a1event_report_test(uint32_t a1_rsrp_th, printf("============ Report Testing A1 ===============\n"); printf("==========================================================\n"); - stack_dummy stack; - rrc_test rrctest(&log1, &stack); + stack_dummy_interface stack; + rrc_test rrctest(&log1, &stack); rrctest.init(); rrctest.connect(); @@ -854,8 +854,8 @@ int a3event_report_test(uint32_t a3_offset, uint32_t hyst, bool report_on_leave) printf("============ Report Testing A3 ===============\n"); printf("==========================================================\n"); - stack_dummy stack; - rrc_test rrctest(&log1, &stack); + stack_dummy_interface stack; + rrc_test rrctest(&log1, &stack); rrctest.init(); rrctest.connect();