mirror of https://github.com/PentHertz/srsLTE.git
- Added a clarification comment on why to use make_span.
- Moved byte_buffer utilities to common.h thus breaking the dependency of ADT to COMMON. - Fixed compilation failures in tests.
This commit is contained in:
parent
af8dfcf19c
commit
eb4b2d4e43
|
@ -22,16 +22,20 @@
|
|||
#ifndef SRSLTE_SPAN_H
|
||||
#define SRSLTE_SPAN_H
|
||||
|
||||
#include "srslte/common/common.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
namespace srslte {
|
||||
|
||||
/// The class template span describes an object that can refer to a contiguous sequence of objects with the first
|
||||
/// element of the sequence at position zero.
|
||||
/// It is encouraged to use the make_span() helper functions for creating new spans instead of using the constructors
|
||||
/// directly. This way is more explicit in code and makes the developer think first to make sure the lifetime of the
|
||||
/// sequence outlasts the new created span.
|
||||
template <typename T>
|
||||
class span
|
||||
{
|
||||
|
@ -176,7 +180,7 @@ inline bool operator!=(span<T> lhs, span<T> rhs)
|
|||
}
|
||||
|
||||
///
|
||||
/// Helpers to construct span objects from different types of arrays.
|
||||
/// Helpers to construct span objects from different types of contiguous containers.
|
||||
///
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
|
@ -209,28 +213,6 @@ inline span<const T> make_span(const std::vector<T>& v)
|
|||
return span<const T>{v.data(), v.size()};
|
||||
}
|
||||
|
||||
using byte_span = span<uint8_t>;
|
||||
|
||||
inline byte_span make_span(byte_buffer_t& b)
|
||||
{
|
||||
return byte_span{b.msg, b.N_bytes};
|
||||
}
|
||||
|
||||
inline span<const uint8_t> make_span(const byte_buffer_t& b)
|
||||
{
|
||||
return span<const uint8_t>{b.msg, b.N_bytes};
|
||||
}
|
||||
|
||||
inline byte_span make_span(unique_byte_buffer_t& b)
|
||||
{
|
||||
return byte_span{b->msg, b->N_bytes};
|
||||
}
|
||||
|
||||
inline span<const uint8_t> make_span(const unique_byte_buffer_t& b)
|
||||
{
|
||||
return span<const uint8_t>{b->msg, b->N_bytes};
|
||||
}
|
||||
|
||||
} // namespace srslte
|
||||
|
||||
#endif // SRSLTE_SPAN_H
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
INCLUDES
|
||||
*******************************************************************************/
|
||||
|
||||
#include "srslte/adt/span.h"
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
@ -266,6 +267,33 @@ public:
|
|||
|
||||
typedef std::unique_ptr<byte_buffer_t, byte_buffer_deleter> unique_byte_buffer_t;
|
||||
|
||||
///
|
||||
/// Utilities to create a span out of a byte_buffer.
|
||||
///
|
||||
|
||||
using byte_span = span<uint8_t>;
|
||||
using const_byte_span = span<const uint8_t>;
|
||||
|
||||
inline byte_span make_span(byte_buffer_t& b)
|
||||
{
|
||||
return byte_span{b.msg, b.N_bytes};
|
||||
}
|
||||
|
||||
inline const_byte_span make_span(const byte_buffer_t& b)
|
||||
{
|
||||
return const_byte_span{b.msg, b.N_bytes};
|
||||
}
|
||||
|
||||
inline byte_span make_span(unique_byte_buffer_t& b)
|
||||
{
|
||||
return byte_span{b->msg, b->N_bytes};
|
||||
}
|
||||
|
||||
inline const_byte_span make_span(const unique_byte_buffer_t& b)
|
||||
{
|
||||
return const_byte_span{b->msg, b->N_bytes};
|
||||
}
|
||||
|
||||
} // namespace srslte
|
||||
|
||||
#endif // SRSLTE_COMMON_H
|
||||
|
|
|
@ -430,13 +430,13 @@ int test_s1ap_mobility(mobility_test_params test_params)
|
|||
0x01, 0x48, 0x04, 0xbc, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x02, 0xa0, 0x07, 0xa0,
|
||||
0x10, 0x00, 0x01, 0x00, 0x05, 0x00, 0xa7, 0xd0, 0xc1, 0xf6, 0xaf, 0x3e, 0x12, 0xcc,
|
||||
0x86, 0x0d, 0x30, 0x00, 0x0b, 0x5a, 0x02, 0x17, 0x86, 0x00, 0x05, 0xa0, 0x20};
|
||||
test_helpers::copy_msg_to_buffer(pdu, ho_cmd_rrc_container);
|
||||
test_helpers::copy_msg_to_buffer(pdu, srslte::make_span(ho_cmd_rrc_container));
|
||||
TESTASSERT(s1ap.last_enb_status.rnti != tester.rnti);
|
||||
tester.rrc.ho_preparation_complete(tester.rnti, true, std::move(pdu));
|
||||
TESTASSERT(s1ap.last_enb_status.status_present);
|
||||
TESTASSERT(tester.rrc_log->error_counter == 0);
|
||||
asn1::rrc::dl_dcch_msg_s ho_cmd;
|
||||
TESTASSERT(test_helpers::unpack_asn1(ho_cmd, tester.pdcp.last_sdu.sdu));
|
||||
TESTASSERT(test_helpers::unpack_asn1(ho_cmd, srslte::make_span(tester.pdcp.last_sdu.sdu)));
|
||||
auto& recfg_r8 = ho_cmd.msg.c1().rrc_conn_recfg().crit_exts.c1().rrc_conn_recfg_r8();
|
||||
TESTASSERT(recfg_r8.mob_ctrl_info_present);
|
||||
|
||||
|
@ -493,7 +493,7 @@ int test_intraenb_mobility(mobility_test_params test_params)
|
|||
TESTASSERT(tester.pdcp.last_sdu.rnti == tester.rnti);
|
||||
TESTASSERT(tester.pdcp.last_sdu.lcid == 1); // SRB1
|
||||
asn1::rrc::dl_dcch_msg_s ho_cmd;
|
||||
TESTASSERT(test_helpers::unpack_asn1(ho_cmd, tester.pdcp.last_sdu.sdu));
|
||||
TESTASSERT(test_helpers::unpack_asn1(ho_cmd, srslte::make_span(tester.pdcp.last_sdu.sdu)));
|
||||
auto& recfg_r8 = ho_cmd.msg.c1().rrc_conn_recfg().crit_exts.c1().rrc_conn_recfg_r8();
|
||||
TESTASSERT(recfg_r8.mob_ctrl_info_present);
|
||||
TESTASSERT(recfg_r8.mob_ctrl_info.new_ue_id.to_number() == tester.rnti);
|
||||
|
@ -543,7 +543,7 @@ int test_intraenb_mobility(mobility_test_params test_params)
|
|||
TESTASSERT(tester.pdcp.last_sdu.sdu != nullptr);
|
||||
TESTASSERT(tester.s1ap.last_ho_required.rrc_container == nullptr);
|
||||
TESTASSERT(not tester.s1ap.last_enb_status.status_present);
|
||||
TESTASSERT(test_helpers::unpack_asn1(ho_cmd, tester.pdcp.last_sdu.sdu));
|
||||
TESTASSERT(test_helpers::unpack_asn1(ho_cmd, srslte::make_span(tester.pdcp.last_sdu.sdu)));
|
||||
recfg_r8 = ho_cmd.msg.c1().rrc_conn_recfg().crit_exts.c1().rrc_conn_recfg_r8();
|
||||
TESTASSERT(recfg_r8.mob_ctrl_info_present);
|
||||
TESTASSERT(recfg_r8.mob_ctrl_info.new_ue_id.to_number() == tester.rnti);
|
||||
|
|
|
@ -204,7 +204,7 @@ int parse_default_cfg(rrc_cfg_t* rrc_cfg, srsenb::all_args_t& args)
|
|||
}
|
||||
|
||||
template <typename ASN1Type>
|
||||
bool unpack_asn1(ASN1Type& asn1obj, const srslte::byte_span pdu)
|
||||
bool unpack_asn1(ASN1Type& asn1obj, srslte::const_byte_span pdu)
|
||||
{
|
||||
asn1::cbit_ref bref{pdu.data(), (uint32_t)pdu.size()};
|
||||
if (asn1obj.unpack(bref) != asn1::SRSASN_SUCCESS) {
|
||||
|
@ -214,7 +214,7 @@ bool unpack_asn1(ASN1Type& asn1obj, const srslte::byte_span pdu)
|
|||
return true;
|
||||
}
|
||||
|
||||
void copy_msg_to_buffer(srslte::unique_byte_buffer_t& pdu, srslte::byte_span msg)
|
||||
void copy_msg_to_buffer(srslte::unique_byte_buffer_t& pdu, srslte::const_byte_span msg)
|
||||
{
|
||||
srslte::byte_buffer_pool* pool = srslte::byte_buffer_pool::get_instance();
|
||||
pdu = srslte::allocate_unique_buffer(*pool, true);
|
||||
|
@ -228,7 +228,7 @@ int bring_rrc_to_reconf_state(srsenb::rrc& rrc, srslte::timer_handler& timers, u
|
|||
|
||||
// Send RRCConnectionRequest
|
||||
uint8_t rrc_conn_request[] = {0x40, 0x12, 0xf6, 0xfb, 0xe2, 0xc6};
|
||||
copy_msg_to_buffer(pdu, rrc_conn_request);
|
||||
copy_msg_to_buffer(pdu, srslte::make_span(rrc_conn_request));
|
||||
rrc.write_pdu(rnti, 0, std::move(pdu));
|
||||
timers.step_all();
|
||||
rrc.tti_clock();
|
||||
|
@ -237,7 +237,7 @@ int bring_rrc_to_reconf_state(srsenb::rrc& rrc, srslte::timer_handler& timers, u
|
|||
uint8_t rrc_conn_setup_complete[] = {0x20, 0x00, 0x40, 0x2e, 0x90, 0x50, 0x49, 0xe8, 0x06, 0x0e, 0x82, 0xa2,
|
||||
0x17, 0xec, 0x13, 0xe2, 0x0f, 0x00, 0x02, 0x02, 0x5e, 0xdf, 0x7c, 0x58,
|
||||
0x05, 0xc0, 0xc0, 0x00, 0x08, 0x04, 0x03, 0xa0, 0x23, 0x23, 0xc0};
|
||||
copy_msg_to_buffer(pdu, rrc_conn_setup_complete);
|
||||
copy_msg_to_buffer(pdu, srslte::make_span(rrc_conn_setup_complete));
|
||||
rrc.write_pdu(rnti, 1, std::move(pdu));
|
||||
timers.step_all();
|
||||
rrc.tti_clock();
|
||||
|
@ -267,7 +267,7 @@ int bring_rrc_to_reconf_state(srsenb::rrc& rrc, srslte::timer_handler& timers, u
|
|||
|
||||
// Send SecurityModeComplete
|
||||
uint8_t sec_mode_complete[] = {0x28, 0x00};
|
||||
copy_msg_to_buffer(pdu, sec_mode_complete);
|
||||
copy_msg_to_buffer(pdu, srslte::make_span(sec_mode_complete));
|
||||
rrc.write_pdu(rnti, 1, std::move(pdu));
|
||||
timers.step_all();
|
||||
rrc.tti_clock();
|
||||
|
@ -275,14 +275,14 @@ int bring_rrc_to_reconf_state(srsenb::rrc& rrc, srslte::timer_handler& timers, u
|
|||
// send UE cap info
|
||||
uint8_t ue_cap_info[] = {0x38, 0x01, 0x01, 0x0c, 0x98, 0x00, 0x00, 0x18, 0x00, 0x0f,
|
||||
0x30, 0x20, 0x80, 0x00, 0x01, 0x00, 0x0e, 0x01, 0x00, 0x00};
|
||||
copy_msg_to_buffer(pdu, ue_cap_info);
|
||||
copy_msg_to_buffer(pdu, srslte::make_span(ue_cap_info));
|
||||
rrc.write_pdu(rnti, 1, std::move(pdu));
|
||||
timers.step_all();
|
||||
rrc.tti_clock();
|
||||
|
||||
// RRCConnectionReconfiguration was sent. Send RRCConnectionReconfigurationComplete
|
||||
uint8_t rrc_conn_reconf_complete[] = {0x10, 0x00};
|
||||
copy_msg_to_buffer(pdu, rrc_conn_reconf_complete);
|
||||
copy_msg_to_buffer(pdu, srslte::make_span(rrc_conn_reconf_complete));
|
||||
rrc.write_pdu(rnti, 1, std::move(pdu));
|
||||
timers.step_all();
|
||||
rrc.tti_clock();
|
||||
|
|
Loading…
Reference in New Issue