From 96fd3aae3c749926b55558e3cbfde4e3c5e672cc Mon Sep 17 00:00:00 2001 From: Francisco Date: Thu, 4 Nov 2021 15:01:13 +0000 Subject: [PATCH] nr,gnb: small gnb interface refactors and fix of byte buffer operator= --- lib/include/srsran/asn1/rrc_nr_utils.h | 6 --- lib/include/srsran/common/byte_buffer.h | 2 +- .../srsran/interfaces/gnb_interfaces.h | 4 +- .../srsran/interfaces/gnb_rrc_nr_interfaces.h | 10 ++--- lib/src/asn1/rrc_nr_utils.cc | 29 ------------- srsenb/hdr/stack/rrc/rrc_nr.h | 4 +- srsenb/src/stack/mac/nr/mac_nr.cc | 2 +- srsenb/src/stack/rrc/rrc_nr.cc | 42 ++++--------------- srsenb/test/common/dummy_classes_nr.h | 4 +- 9 files changed, 21 insertions(+), 82 deletions(-) diff --git a/lib/include/srsran/asn1/rrc_nr_utils.h b/lib/include/srsran/asn1/rrc_nr_utils.h index 9b39785e7..18d284646 100644 --- a/lib/include/srsran/asn1/rrc_nr_utils.h +++ b/lib/include/srsran/asn1/rrc_nr_utils.h @@ -13,7 +13,6 @@ #ifndef SRSRAN_RRC_NR_UTILS_H #define SRSRAN_RRC_NR_UTILS_H -#include "srsenb/hdr/stack/mac/sched_interface.h" #include "srsran/common/phy_cfg_nr.h" #include "srsran/interfaces/mac_interface_types.h" #include "srsran/interfaces/pdcp_interface_types.h" @@ -143,9 +142,4 @@ pdcp_config_t make_drb_pdcp_config_t(const uint8_t bearer_id, bool is_ue, const } // namespace srsran -namespace srsenb { - -int set_sched_cell_cfg_sib1(srsenb::sched_interface::cell_cfg_t* sched_cfg, const asn1::rrc_nr::sib1_s& sib1); -} - #endif // SRSRAN_RRC_NR_UTILS_H diff --git a/lib/include/srsran/common/byte_buffer.h b/lib/include/srsran/common/byte_buffer.h index f6d2e6479..5a8027423 100644 --- a/lib/include/srsran/common/byte_buffer.h +++ b/lib/include/srsran/common/byte_buffer.h @@ -119,7 +119,7 @@ public: // avoid self assignment if (&buf == this) return *this; - msg = &buffer[SRSRAN_BUFFER_HEADER_OFFSET]; + msg = &buffer[buf.msg - &(*buf.buffer)]; N_bytes = buf.N_bytes; md = buf.md; memcpy(msg, buf.msg, N_bytes); diff --git a/lib/include/srsran/interfaces/gnb_interfaces.h b/lib/include/srsran/interfaces/gnb_interfaces.h index 68dbf1ee8..b902829e6 100644 --- a/lib/include/srsran/interfaces/gnb_interfaces.h +++ b/lib/include/srsran/interfaces/gnb_interfaces.h @@ -132,8 +132,8 @@ class rrc_interface_mac_nr { public: // Provides MIB packed message - virtual int read_pdu_bcch_bch(const uint32_t tti, srsran::unique_byte_buffer_t& buffer) = 0; - virtual int read_pdu_bcch_dlsch(uint32_t sib_index, srsran::unique_byte_buffer_t& buffer) = 0; + virtual int read_pdu_bcch_bch(const uint32_t tti, srsran::byte_buffer_t& buffer) = 0; + virtual int read_pdu_bcch_dlsch(uint32_t sib_index, srsran::byte_buffer_t& buffer) = 0; /// User management virtual int add_user(uint16_t rnti, const sched_nr_ue_cfg_t& uecfg) = 0; diff --git a/lib/include/srsran/interfaces/gnb_rrc_nr_interfaces.h b/lib/include/srsran/interfaces/gnb_rrc_nr_interfaces.h index 883749d37..03c0041c4 100644 --- a/lib/include/srsran/interfaces/gnb_rrc_nr_interfaces.h +++ b/lib/include/srsran/interfaces/gnb_rrc_nr_interfaces.h @@ -27,10 +27,10 @@ public: virtual int ue_set_security_cfg_capabilities(uint16_t rnti, const asn1::ngap_nr::ue_security_cap_s& caps) = 0; virtual int start_security_mode_procedure(uint16_t rnti) = 0; virtual int - establish_rrc_bearer(uint16_t rnti, uint16_t pdu_session_id, srsran::const_byte_span nas_pdu, uint32_t lcid) = 0; - virtual int allocate_lcid(uint16_t rnti) = 0; - virtual int release_bearers(uint16_t rnti) = 0; - virtual void write_dl_info(uint16_t rnti, srsran::unique_byte_buffer_t sdu) = 0; + establish_rrc_bearer(uint16_t rnti, uint16_t pdu_session_id, srsran::const_byte_span nas_pdu, uint32_t lcid) = 0; + virtual int allocate_lcid(uint16_t rnti) = 0; + virtual int release_bearers(uint16_t rnti) = 0; + virtual void write_dl_info(uint16_t rnti, srsran::unique_byte_buffer_t sdu) = 0; }; // Cell/Sector configuration for NR cells @@ -51,4 +51,4 @@ typedef std::vector rrc_cell_list_nr_t; } // namespace srsenb -#endif // SRSRAN_GNB_RRC_NR_INTERFACES_H \ No newline at end of file +#endif // SRSRAN_GNB_RRC_NR_INTERFACES_H diff --git a/lib/src/asn1/rrc_nr_utils.cc b/lib/src/asn1/rrc_nr_utils.cc index b1c120726..e11633519 100644 --- a/lib/src/asn1/rrc_nr_utils.cc +++ b/lib/src/asn1/rrc_nr_utils.cc @@ -1595,32 +1595,3 @@ bool fill_phy_pdcch_cfg_common(const asn1::rrc_nr::pdcch_cfg_common_s& pdcch_cfg } } // namespace srsran - -namespace srsenb { - -int set_sched_cell_cfg_sib1(srsenb::sched_interface::cell_cfg_t* sched_cfg, const asn1::rrc_nr::sib1_s& sib1) -{ - bzero(sched_cfg, sizeof(srsenb::sched_interface::cell_cfg_t)); - - // set SIB1 and SIB2+ period - sched_cfg->sibs[0].period_rf = 16; // SIB1 is always 16 rf - for (uint32_t i = 0; i < sib1.si_sched_info.sched_info_list.size(); i++) { - sched_cfg->sibs[i + 1].period_rf = sib1.si_sched_info.sched_info_list[i].si_periodicity.to_number(); - } - - // si-WindowLength - sched_cfg->si_window_ms = sib1.si_sched_info.si_win_len.to_number(); - - // setup PRACH - if (not sib1.si_sched_info.si_request_cfg.rach_occasions_si_present) { - asn1::log_warning("rach_occasions_si option not present"); - return SRSRAN_ERROR; - } - sched_cfg->prach_rar_window = sib1.si_sched_info.si_request_cfg.rach_occasions_si.rach_cfg_si.ra_resp_win.to_number(); - sched_cfg->prach_freq_offset = sib1.si_sched_info.si_request_cfg.rach_occasions_si.rach_cfg_si.msg1_freq_start; - sched_cfg->maxharq_msg3tx = sib1.si_sched_info.si_request_cfg.rach_occasions_si.rach_cfg_si.preamb_trans_max; - - return SRSRAN_SUCCESS; -} - -} // namespace srsenb diff --git a/srsenb/hdr/stack/rrc/rrc_nr.h b/srsenb/hdr/stack/rrc/rrc_nr.h index 75fe397fa..2e8305f27 100644 --- a/srsenb/hdr/stack/rrc/rrc_nr.h +++ b/srsenb/hdr/stack/rrc/rrc_nr.h @@ -65,8 +65,8 @@ public: void config_phy(); void config_mac(); int32_t generate_sibs(); - int read_pdu_bcch_bch(const uint32_t tti, srsran::unique_byte_buffer_t& buffer) final; - int read_pdu_bcch_dlsch(uint32_t sib_index, srsran::unique_byte_buffer_t& buffer) final; + int read_pdu_bcch_bch(const uint32_t tti, srsran::byte_buffer_t& buffer) final; + int read_pdu_bcch_dlsch(uint32_t sib_index, srsran::byte_buffer_t& buffer) final; /// User manegement int add_user(uint16_t rnti, const sched_nr_ue_cfg_t& uecfg); diff --git a/srsenb/src/stack/mac/nr/mac_nr.cc b/srsenb/src/stack/mac/nr/mac_nr.cc index 8bf7a4577..496cc7c6a 100644 --- a/srsenb/src/stack/mac/nr/mac_nr.cc +++ b/srsenb/src/stack/mac/nr/mac_nr.cc @@ -117,7 +117,7 @@ int mac_nr::cell_cfg(const std::vector& logger.error("Couldn't allocate PDU in %s().", __FUNCTION__); return SRSRAN_ERROR; } - if (rrc->read_pdu_bcch_dlsch(sib.index, sib.payload) != SRSRAN_SUCCESS) { + if (rrc->read_pdu_bcch_dlsch(sib.index, *sib.payload) != SRSRAN_SUCCESS) { logger.error("Couldn't read SIB %d from RRC", sib.index); } diff --git a/srsenb/src/stack/rrc/rrc_nr.cc b/srsenb/src/stack/rrc/rrc_nr.cc index 7d8bd5f15..50ac298bd 100644 --- a/srsenb/src/stack/rrc/rrc_nr.cc +++ b/srsenb/src/stack/rrc/rrc_nr.cc @@ -307,22 +307,6 @@ void rrc_nr::config_mac() ret2 = srsran::make_duplex_cfg_from_serv_cell(base_sp_cell_cfg.recfg_with_sync.sp_cell_cfg_common, &cell.duplex); srsran_assert(ret2, "Invalid NR cell configuration."); - // FIXME: entire SI configuration, etc needs to be ported to NR - sched_interface::cell_cfg_t cell_cfg; - set_sched_cell_cfg_sib1(&cell_cfg, cfg.sib1); - - // set SIB length - for (uint32_t i = 0; i < nof_si_messages + 1; i++) { - cell_cfg.sibs[i].len = sib_buffer[i]->N_bytes; - } - - // PUCCH width - cell_cfg.nrb_pucch = SRSRAN_MAX(cfg.sr_cfg.nof_prb, /* TODO: where is n_rb2 in NR? */ 0); - logger.info("Allocating %d PRBs for PUCCH", cell_cfg.nrb_pucch); - - // Copy Cell configuration - // cell_cfg.cell = cfg.cell; - // Configure MAC/scheduler mac->cell_cfg(sched_cells_cfg); } @@ -397,33 +381,23 @@ int32_t rrc_nr::generate_sibs() MAC interface *******************************************************************************/ -int rrc_nr::read_pdu_bcch_bch(const uint32_t tti, srsran::unique_byte_buffer_t& buffer) +int rrc_nr::read_pdu_bcch_bch(const uint32_t tti, srsran::byte_buffer_t& buffer) { - if (mib_buffer == nullptr || buffer->get_tailroom() < mib_buffer->N_bytes) { + if (mib_buffer == nullptr || buffer.get_tailroom() < mib_buffer->N_bytes) { return SRSRAN_ERROR; } - memcpy(buffer->msg, mib_buffer->msg, mib_buffer->N_bytes); - buffer->N_bytes = mib_buffer->N_bytes; + buffer = *mib_buffer; return SRSRAN_SUCCESS; } -int rrc_nr::read_pdu_bcch_dlsch(uint32_t sib_index, srsran::unique_byte_buffer_t& buffer) +int rrc_nr::read_pdu_bcch_dlsch(uint32_t sib_index, srsran::byte_buffer_t& buffer) { if (sib_index >= sib_buffer.size()) { logger.error("SIB %d is not a configured SIB.", sib_index); return SRSRAN_ERROR; } - if (buffer->get_tailroom() < sib_buffer[sib_index]->N_bytes) { - logger.error("Not enough space to fit SIB %d into buffer (%d < %d)", - sib_index, - buffer->get_tailroom(), - sib_buffer[sib_index]->N_bytes); - return SRSRAN_ERROR; - } - - memcpy(buffer->msg, sib_buffer[sib_index]->msg, sib_buffer[sib_index]->N_bytes); - buffer->N_bytes = sib_buffer[sib_index]->N_bytes; + buffer = *sib_buffer[sib_index]; return SRSRAN_SUCCESS; } @@ -527,9 +501,9 @@ void rrc_nr::sgnb_addition_request(uint16_t eutra_rnti, const sgnb_addition_req_ uecfg.carriers[0].cc = 0; uecfg.ue_bearers[0].direction = mac_lc_ch_cfg_t::BOTH; srsran::phy_cfg_nr_default_t::reference_cfg_t ref_args{}; - ref_args.duplex = cfg.cell_list[0].duplex_mode == SRSRAN_DUPLEX_MODE_TDD - ? srsran::phy_cfg_nr_default_t::reference_cfg_t::R_DUPLEX_TDD_CUSTOM_6_4 - : srsran::phy_cfg_nr_default_t::reference_cfg_t::R_DUPLEX_FDD; + ref_args.duplex = cfg.cell_list[0].duplex_mode == SRSRAN_DUPLEX_MODE_TDD + ? srsran::phy_cfg_nr_default_t::reference_cfg_t::R_DUPLEX_TDD_CUSTOM_6_4 + : srsran::phy_cfg_nr_default_t::reference_cfg_t::R_DUPLEX_FDD; uecfg.phy_cfg = srsran::phy_cfg_nr_default_t{ref_args}; uecfg.phy_cfg.csi = {}; // disable CSI until RA is complete diff --git a/srsenb/test/common/dummy_classes_nr.h b/srsenb/test/common/dummy_classes_nr.h index 018599afa..362946324 100644 --- a/srsenb/test/common/dummy_classes_nr.h +++ b/srsenb/test/common/dummy_classes_nr.h @@ -21,8 +21,8 @@ namespace srsenb { class rrc_nr_dummy : public rrc_interface_mac_nr { public: - int read_pdu_bcch_bch(const uint32_t tti, srsran::unique_byte_buffer_t& buffer) { return SRSRAN_SUCCESS; } - int read_pdu_bcch_dlsch(uint32_t sib_index, srsran::unique_byte_buffer_t& buffer) { return SRSRAN_SUCCESS; } + int read_pdu_bcch_bch(const uint32_t tti, srsran::byte_buffer_t& buffer) { return SRSRAN_SUCCESS; } + int read_pdu_bcch_dlsch(uint32_t sib_index, srsran::byte_buffer_t& buffer) { return SRSRAN_SUCCESS; } int add_user(uint16_t rnti, const sched_nr_ue_cfg_t& uecfg) { return SRSRAN_SUCCESS; } int update_user(uint16_t new_rnti, uint16_t old_rnti) { return SRSRAN_SUCCESS; } void set_activity_user(uint16_t rnti) {}