mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
243 lines
7.1 KiB
C
243 lines
7.1 KiB
C
4 years ago
|
/**
|
||
5 years ago
|
*
|
||
4 years ago
|
* \section COPYRIGHT
|
||
5 years ago
|
*
|
||
4 years ago
|
* Copyright 2013-2021 Software Radio Systems Limited
|
||
5 years ago
|
*
|
||
4 years ago
|
* By using this file, you agree to the terms and conditions set
|
||
|
* forth in the LICENSE file which can be found at the top level of
|
||
|
* the distribution.
|
||
5 years ago
|
*
|
||
|
*/
|
||
|
|
||
|
#ifndef SRSENB_TEST_HELPERS_H
|
||
|
#define SRSENB_TEST_HELPERS_H
|
||
|
|
||
4 years ago
|
#include "srsenb/src/enb_cfg_parser.h"
|
||
5 years ago
|
#include "srsenb/test/common/dummy_classes.h"
|
||
4 years ago
|
#include "srsran/adt/span.h"
|
||
5 years ago
|
|
||
|
using namespace srsenb;
|
||
|
using namespace asn1::rrc;
|
||
|
|
||
|
namespace argparse {
|
||
|
|
||
4 years ago
|
extern std::string repository_dir;
|
||
|
extern srslog::basic_levels log_level;
|
||
5 years ago
|
|
||
4 years ago
|
inline void usage(char* prog)
|
||
5 years ago
|
{
|
||
|
printf("Usage: %s [v] -i repository_dir\n", prog);
|
||
4 years ago
|
printf("\t-v [set srsran_verbose to debug, default none]\n");
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
inline void parse_args(int argc, char** argv)
|
||
5 years ago
|
{
|
||
|
int opt;
|
||
|
|
||
|
while ((opt = getopt(argc, argv, "i")) != -1) {
|
||
|
switch (opt) {
|
||
|
case 'i':
|
||
|
repository_dir = argv[optind];
|
||
|
break;
|
||
|
case 'v':
|
||
4 years ago
|
log_level = srslog::basic_levels::debug;
|
||
5 years ago
|
break;
|
||
|
default:
|
||
|
usage(argv[0]);
|
||
|
exit(-1);
|
||
|
}
|
||
|
}
|
||
|
if (repository_dir.empty()) {
|
||
|
usage(argv[0]);
|
||
|
exit(-1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
} // namespace argparse
|
||
|
|
||
|
namespace test_dummies {
|
||
|
|
||
|
class s1ap_mobility_dummy : public s1ap_dummy
|
||
|
{
|
||
|
public:
|
||
|
struct ho_req_data {
|
||
|
uint16_t rnti;
|
||
|
uint32_t target_eci;
|
||
4 years ago
|
srsran::plmn_id_t target_plmn;
|
||
|
srsran::unique_byte_buffer_t rrc_container;
|
||
5 years ago
|
} last_ho_required = {};
|
||
|
struct enb_status_transfer_info {
|
||
5 years ago
|
bool status_present;
|
||
5 years ago
|
uint16_t rnti;
|
||
|
std::vector<bearer_status_info> bearer_list;
|
||
|
} last_enb_status = {};
|
||
4 years ago
|
struct ho_req_ack {
|
||
4 years ago
|
uint16_t rnti;
|
||
4 years ago
|
srsran::unique_byte_buffer_t ho_cmd_pdu;
|
||
4 years ago
|
std::vector<asn1::s1ap::erab_admitted_item_s> admitted_bearers;
|
||
4 years ago
|
std::vector<asn1::s1ap::erab_item_s> not_admitted_bearers;
|
||
4 years ago
|
} last_ho_req_ack;
|
||
5 years ago
|
|
||
|
bool send_ho_required(uint16_t rnti,
|
||
|
uint32_t target_eci,
|
||
4 years ago
|
srsran::plmn_id_t target_plmn,
|
||
|
srsran::span<uint32_t> fwd_erabs,
|
||
4 years ago
|
srsran::unique_byte_buffer_t rrc_container,
|
||
|
bool has_direct_fwd_path) final
|
||
5 years ago
|
{
|
||
|
last_ho_required = ho_req_data{rnti, target_eci, target_plmn, std::move(rrc_container)};
|
||
|
return true;
|
||
|
}
|
||
5 years ago
|
bool send_enb_status_transfer_proc(uint16_t rnti, std::vector<bearer_status_info>& bearer_status_list) override
|
||
|
{
|
||
|
last_enb_status = {true, rnti, bearer_status_list};
|
||
|
return true;
|
||
|
}
|
||
4 years ago
|
bool send_ho_req_ack(const asn1::s1ap::ho_request_s& msg,
|
||
|
uint16_t rnti,
|
||
4 years ago
|
uint32_t enb_cc_idx,
|
||
4 years ago
|
srsran::unique_byte_buffer_t ho_cmd,
|
||
4 years ago
|
srsran::span<asn1::s1ap::erab_admitted_item_s> admitted_bearers,
|
||
|
srsran::const_span<asn1::s1ap::erab_item_s> not_admitted_bearers) override
|
||
4 years ago
|
{
|
||
|
last_ho_req_ack.rnti = rnti;
|
||
|
last_ho_req_ack.ho_cmd_pdu = std::move(ho_cmd);
|
||
|
last_ho_req_ack.admitted_bearers.assign(admitted_bearers.begin(), admitted_bearers.end());
|
||
4 years ago
|
last_ho_req_ack.not_admitted_bearers.assign(not_admitted_bearers.begin(), not_admitted_bearers.end());
|
||
4 years ago
|
return true;
|
||
|
}
|
||
4 years ago
|
void user_mod(uint16_t old_rnti, uint16_t new_rnti) override {}
|
||
5 years ago
|
};
|
||
|
|
||
|
class pdcp_mobility_dummy : public pdcp_dummy
|
||
|
{
|
||
|
public:
|
||
|
struct last_sdu_t {
|
||
|
uint16_t rnti;
|
||
|
uint32_t lcid;
|
||
4 years ago
|
srsran::unique_byte_buffer_t sdu;
|
||
5 years ago
|
} last_sdu;
|
||
4 years ago
|
struct lcid_cfg_t {
|
||
|
bool enable_integrity = false;
|
||
|
bool enable_encryption = false;
|
||
4 years ago
|
srsran::pdcp_lte_state_t state{};
|
||
|
srsran::as_security_config_t sec_cfg{};
|
||
4 years ago
|
};
|
||
|
std::map<uint16_t, std::map<uint32_t, lcid_cfg_t> > bearers;
|
||
5 years ago
|
|
||
4 years ago
|
void write_sdu(uint16_t rnti, uint32_t lcid, srsran::unique_byte_buffer_t sdu, int pdcp_sn) override
|
||
5 years ago
|
{
|
||
|
last_sdu.rnti = rnti;
|
||
|
last_sdu.lcid = lcid;
|
||
|
last_sdu.sdu = std::move(sdu);
|
||
|
}
|
||
4 years ago
|
bool set_bearer_state(uint16_t rnti, uint32_t lcid, const srsran::pdcp_lte_state_t& state) override
|
||
4 years ago
|
{
|
||
4 years ago
|
bearers[rnti][lcid].state = state;
|
||
4 years ago
|
return true;
|
||
|
}
|
||
4 years ago
|
void enable_integrity(uint16_t rnti, uint32_t lcid) override { bearers[rnti][lcid].enable_integrity = true; }
|
||
|
void enable_encryption(uint16_t rnti, uint32_t lcid) override { bearers[rnti][lcid].enable_encryption = true; }
|
||
4 years ago
|
void config_security(uint16_t rnti, uint32_t lcid, srsran::as_security_config_t sec_cfg_) override
|
||
4 years ago
|
{
|
||
|
bearers[rnti][lcid].sec_cfg = sec_cfg_;
|
||
|
}
|
||
5 years ago
|
};
|
||
|
|
||
5 years ago
|
class rlc_mobility_dummy : public rlc_dummy
|
||
|
{
|
||
|
public:
|
||
|
struct ue_ctxt {
|
||
|
int nof_pdcp_sdus = 0, reest_sdu_counter = 0;
|
||
|
uint32_t last_lcid = 0;
|
||
4 years ago
|
srsran::unique_byte_buffer_t last_sdu;
|
||
5 years ago
|
};
|
||
|
std::map<uint16_t, ue_ctxt> ue_db;
|
||
|
|
||
|
void test_reset_all()
|
||
|
{
|
||
|
for (auto& u : ue_db) {
|
||
|
u.second = {};
|
||
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
void write_sdu(uint16_t rnti, uint32_t lcid, srsran::unique_byte_buffer_t sdu) override
|
||
5 years ago
|
{
|
||
|
ue_db[rnti].nof_pdcp_sdus++;
|
||
|
ue_db[rnti].reest_sdu_counter++;
|
||
|
ue_db[rnti].last_lcid = lcid;
|
||
|
ue_db[rnti].last_sdu = std::move(sdu);
|
||
|
}
|
||
|
void reestablish(uint16_t rnti) final { ue_db[rnti].reest_sdu_counter = 0; }
|
||
|
};
|
||
|
|
||
|
class mac_mobility_dummy : public mac_dummy
|
||
|
{
|
||
|
public:
|
||
|
int ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t* cfg) override
|
||
|
{
|
||
|
ue_db[rnti] = *cfg;
|
||
|
return 0;
|
||
|
}
|
||
4 years ago
|
int ue_set_crnti(uint16_t temp_crnti, uint16_t crnti, sched_interface::ue_cfg_t* cfg) override
|
||
|
{
|
||
|
ue_db[crnti] = *cfg;
|
||
|
return 0;
|
||
|
}
|
||
5 years ago
|
std::map<uint16_t, sched_interface::ue_cfg_t> ue_db;
|
||
|
};
|
||
|
|
||
4 years ago
|
class phy_mobility_dummy : public phy_dummy
|
||
|
{
|
||
|
public:
|
||
4 years ago
|
void set_config(uint16_t rnti, const phy_rrc_cfg_list_t& dedicated_list) override
|
||
|
{
|
||
|
phy_cfg_set = true;
|
||
|
last_cfg = dedicated_list;
|
||
|
}
|
||
|
bool phy_cfg_set = false;
|
||
4 years ago
|
phy_rrc_cfg_list_t last_cfg;
|
||
|
};
|
||
|
|
||
5 years ago
|
} // namespace test_dummies
|
||
|
|
||
|
namespace test_helpers {
|
||
|
|
||
4 years ago
|
int parse_default_cfg(rrc_cfg_t* rrc_cfg, srsenb::all_args_t& args);
|
||
4 years ago
|
int parse_default_cfg_phy(rrc_cfg_t* rrc_cfg, phy_cfg_t* phy_cfg, srsenb::all_args_t& args);
|
||
5 years ago
|
|
||
5 years ago
|
template <typename ASN1Type>
|
||
4 years ago
|
bool unpack_asn1(ASN1Type& asn1obj, srsran::const_byte_span pdu)
|
||
5 years ago
|
{
|
||
4 years ago
|
asn1::cbit_ref bref{pdu.data(), (uint32_t)pdu.size()};
|
||
5 years ago
|
if (asn1obj.unpack(bref) != asn1::SRSASN_SUCCESS) {
|
||
4 years ago
|
srslog::fetch_basic_logger("TEST").error("Failed to unpack ASN1 type");
|
||
5 years ago
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
4 years ago
|
inline void copy_msg_to_buffer(srsran::unique_byte_buffer_t& pdu, srsran::const_byte_span msg)
|
||
5 years ago
|
{
|
||
4 years ago
|
pdu = srsran::make_byte_buffer();
|
||
4 years ago
|
memcpy(pdu->msg, msg.data(), msg.size());
|
||
|
pdu->N_bytes = msg.size();
|
||
5 years ago
|
}
|
||
5 years ago
|
|
||
4 years ago
|
int bring_rrc_to_reconf_state(srsenb::rrc& rrc, srsran::timer_handler& timers, uint16_t rnti);
|
||
5 years ago
|
|
||
|
} // namespace test_helpers
|
||
|
|
||
4 years ago
|
namespace srsenb {
|
||
|
|
||
|
meas_cell_cfg_t generate_cell1();
|
||
|
|
||
|
report_cfg_eutra_s generate_rep1();
|
||
|
|
||
|
bool is_cell_cfg_equal(const meas_cell_cfg_t& cfg, const cells_to_add_mod_s& cell);
|
||
|
|
||
|
} // namespace srsenb
|
||
|
|
||
5 years ago
|
#endif // SRSENB_TEST_HELPERS_H
|