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.
201 lines
7.1 KiB
C++
201 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
|
*
|
||
|
*/
|
||
|
#include "pdcp_lte_test.h"
|
||
|
#include <numeric>
|
||
|
|
||
|
/*
|
||
|
* Genric function to test reception of in-sequence packets
|
||
|
*/
|
||
|
int test_rx(std::vector<pdcp_test_event_t> events,
|
||
4 years ago
|
const srsran::pdcp_lte_state_t& init_state,
|
||
5 years ago
|
uint8_t pdcp_sn_len,
|
||
4 years ago
|
srsran::pdcp_rb_type_t rb_type,
|
||
5 years ago
|
uint32_t n_sdus_exp,
|
||
4 years ago
|
const srsran::unique_byte_buffer_t& sdu_exp,
|
||
4 years ago
|
srslog::basic_logger& logger)
|
||
5 years ago
|
|
||
|
{
|
||
4 years ago
|
srsran::pdcp_config_t cfg_rx = {1,
|
||
5 years ago
|
rb_type,
|
||
4 years ago
|
srsran::SECURITY_DIRECTION_DOWNLINK,
|
||
|
srsran::SECURITY_DIRECTION_UPLINK,
|
||
5 years ago
|
pdcp_sn_len,
|
||
4 years ago
|
srsran::pdcp_t_reordering_t::ms500,
|
||
|
srsran::pdcp_discard_timer_t::infinity,
|
||
4 years ago
|
false,
|
||
|
srsran::srsran_rat_t::lte};
|
||
5 years ago
|
|
||
4 years ago
|
pdcp_lte_test_helper pdcp_hlp_rx(cfg_rx, sec_cfg, logger);
|
||
4 years ago
|
srsran::pdcp_entity_lte* pdcp_rx = &pdcp_hlp_rx.pdcp;
|
||
5 years ago
|
gw_dummy* gw_rx = &pdcp_hlp_rx.gw;
|
||
|
rrc_dummy* rrc_rx = &pdcp_hlp_rx.rrc;
|
||
|
srsue::stack_test_dummy* stack = &pdcp_hlp_rx.stack;
|
||
5 years ago
|
pdcp_hlp_rx.set_pdcp_initial_state(init_state);
|
||
|
|
||
|
// Generate test message and encript/decript SDU.
|
||
|
for (pdcp_test_event_t& event : events) {
|
||
|
// Decript and integrity check the PDU
|
||
|
pdcp_rx->write_pdu(std::move(event.pkt));
|
||
|
for (uint32_t i = 0; i < event.ticks; ++i) {
|
||
5 years ago
|
stack->run_tti();
|
||
5 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// Test if the number of RX packets
|
||
4 years ago
|
if (rb_type == srsran::PDCP_RB_IS_DRB) {
|
||
5 years ago
|
TESTASSERT(gw_rx->rx_count == n_sdus_exp);
|
||
4 years ago
|
if (n_sdus_exp > 0) {
|
||
4 years ago
|
srsran::unique_byte_buffer_t sdu_act = srsran::make_byte_buffer();
|
||
4 years ago
|
gw_rx->get_last_pdu(sdu_act);
|
||
|
TESTASSERT(compare_two_packets(sdu_exp, sdu_act) == 0);
|
||
|
}
|
||
|
|
||
5 years ago
|
} else {
|
||
|
TESTASSERT(rrc_rx->rx_count == n_sdus_exp);
|
||
4 years ago
|
if (n_sdus_exp > 0) {
|
||
4 years ago
|
srsran::unique_byte_buffer_t sdu_act = srsran::make_byte_buffer();
|
||
4 years ago
|
rrc_rx->get_last_pdu(sdu_act);
|
||
|
TESTASSERT(compare_two_packets(sdu_exp, sdu_act) == 0);
|
||
|
}
|
||
5 years ago
|
}
|
||
5 years ago
|
return 0;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* RX Test: PDCP Entity with SN LEN = 5 and 12.
|
||
|
* PDCP entity configured with EIA2 and EEA2
|
||
|
*/
|
||
4 years ago
|
int test_rx_all(srslog::basic_logger& logger)
|
||
5 years ago
|
{
|
||
|
// Test SDUs
|
||
4 years ago
|
srsran::unique_byte_buffer_t tst_sdu1 = srsran::make_byte_buffer(); // SDU 1
|
||
5 years ago
|
tst_sdu1->append_bytes(sdu1, sizeof(sdu1));
|
||
4 years ago
|
srsran::unique_byte_buffer_t tst_sdu2 = srsran::make_byte_buffer(); // SDU 2
|
||
5 years ago
|
tst_sdu2->append_bytes(sdu2, sizeof(sdu2));
|
||
|
|
||
|
/*
|
||
|
* RX Test 1: PDCP LTE Entity with SN LEN = 5
|
||
|
* Test in-sequence reception of 32 packets.
|
||
|
* This tests correct handling of HFN in the case of SN wraparound (SN LEN 5)
|
||
|
*/
|
||
|
{
|
||
|
std::vector<uint32_t> test1_counts(2); // Test two packets
|
||
|
std::iota(test1_counts.begin(), test1_counts.end(), 31); // Starting at COUNT 31
|
||
4 years ago
|
std::vector<pdcp_test_event_t> test1_pdus = gen_expected_pdus_vector(
|
||
4 years ago
|
tst_sdu1, test1_counts, srsran::PDCP_SN_LEN_5, srsran::PDCP_RB_IS_SRB, sec_cfg, logger);
|
||
|
srsran::pdcp_lte_state_t test1_init_state = {
|
||
5 years ago
|
.next_pdcp_tx_sn = 0, .tx_hfn = 0, .rx_hfn = 0, .next_pdcp_rx_sn = 31, .last_submitted_pdcp_rx_sn = 30};
|
||
4 years ago
|
TESTASSERT(test_rx(std::move(test1_pdus),
|
||
|
test1_init_state,
|
||
4 years ago
|
srsran::PDCP_SN_LEN_5,
|
||
|
srsran::PDCP_RB_IS_SRB,
|
||
4 years ago
|
2,
|
||
|
tst_sdu1,
|
||
|
logger) == 0);
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
/*
|
||
5 years ago
|
* RX Test 2: PDCP LTE Entity with SN LEN = 12
|
||
5 years ago
|
* Test in-sequence reception of 4096 packets.
|
||
|
* This tests correct handling of HFN in the case of SN wraparound (SN LEN 12)
|
||
|
*/
|
||
|
{
|
||
5 years ago
|
std::vector<uint32_t> test_counts(2); // Test two packets
|
||
5 years ago
|
std::iota(test_counts.begin(), test_counts.end(), 4095); // Starting at COUNT 4095
|
||
4 years ago
|
std::vector<pdcp_test_event_t> test_pdus = gen_expected_pdus_vector(
|
||
4 years ago
|
tst_sdu1, test_counts, srsran::PDCP_SN_LEN_12, srsran::PDCP_RB_IS_DRB, sec_cfg, logger);
|
||
|
srsran::pdcp_lte_state_t test_init_state = {
|
||
5 years ago
|
.next_pdcp_tx_sn = 0, .tx_hfn = 0, .rx_hfn = 0, .next_pdcp_rx_sn = 4095, .last_submitted_pdcp_rx_sn = 4094};
|
||
4 years ago
|
TESTASSERT(test_rx(std::move(test_pdus),
|
||
|
test_init_state,
|
||
4 years ago
|
srsran::PDCP_SN_LEN_12,
|
||
|
srsran::PDCP_RB_IS_DRB,
|
||
4 years ago
|
2,
|
||
|
tst_sdu1,
|
||
|
logger) == 0);
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
/*
|
||
|
* RX Test 3: PDCP LTE Entity with SN LEN = 12
|
||
5 years ago
|
* Test reception of a dublicate SN, the duplicate should just be dropped.
|
||
5 years ago
|
*/
|
||
|
{
|
||
|
std::vector<uint32_t> test_counts(2); // Test two packets
|
||
5 years ago
|
std::iota(test_counts.begin(), test_counts.end(), 31); // Starting at COUNT 31
|
||
4 years ago
|
std::vector<pdcp_test_event_t> test_pdus = gen_expected_pdus_vector(
|
||
4 years ago
|
tst_sdu1, test_counts, srsran::PDCP_SN_LEN_12, srsran::PDCP_RB_IS_DRB, sec_cfg, logger);
|
||
|
srsran::pdcp_lte_state_t test_init_state = {
|
||
5 years ago
|
.next_pdcp_tx_sn = 0, .tx_hfn = 0, .rx_hfn = 0, .next_pdcp_rx_sn = 32, .last_submitted_pdcp_rx_sn = 31};
|
||
5 years ago
|
TESTASSERT(test_rx(std::move(test_pdus),
|
||
|
test_init_state,
|
||
4 years ago
|
srsran::PDCP_SN_LEN_12,
|
||
|
srsran::PDCP_RB_IS_DRB,
|
||
5 years ago
|
test_counts.size() - 1,
|
||
5 years ago
|
tst_sdu1,
|
||
4 years ago
|
logger) == 0);
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
return SRSRAN_SUCCESS;
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
// Basic test to verify the correct handling of PDCP status PDUs on DRBs
|
||
|
// As long as we don't implement status reporting, the PDU shall be dropped
|
||
4 years ago
|
int test_rx_control_pdu(srslog::basic_logger& logger)
|
||
4 years ago
|
{
|
||
|
const uint8_t pdcp_status_report_long[] = {0x0a, 0xc9, 0x3c};
|
||
|
|
||
|
std::vector<pdcp_test_event_t> pdu_vec;
|
||
|
|
||
|
pdcp_test_event_t event;
|
||
4 years ago
|
event.pkt = srsran::make_byte_buffer();
|
||
4 years ago
|
memcpy(event.pkt->msg, pdcp_status_report_long, sizeof(pdcp_status_report_long));
|
||
|
event.pkt->N_bytes = sizeof(pdcp_status_report_long);
|
||
|
pdu_vec.push_back(std::move(event));
|
||
|
|
||
4 years ago
|
srsran::unique_byte_buffer_t tst_sdu1 = srsran::make_byte_buffer();
|
||
4 years ago
|
|
||
4 years ago
|
srsran::pdcp_lte_state_t test_init_state = {
|
||
4 years ago
|
.next_pdcp_tx_sn = 0, .tx_hfn = 0, .rx_hfn = 0, .next_pdcp_rx_sn = 32, .last_submitted_pdcp_rx_sn = 31};
|
||
4 years ago
|
TESTASSERT(
|
||
4 years ago
|
test_rx(
|
||
4 years ago
|
std::move(pdu_vec), test_init_state, srsran::PDCP_SN_LEN_12, srsran::PDCP_RB_IS_DRB, 0, tst_sdu1, logger) ==
|
||
4 years ago
|
0);
|
||
4 years ago
|
|
||
4 years ago
|
return SRSRAN_SUCCESS;
|
||
4 years ago
|
}
|
||
|
|
||
5 years ago
|
// Setup all tests
|
||
4 years ago
|
int run_all_tests()
|
||
5 years ago
|
{
|
||
|
// Setup log
|
||
4 years ago
|
auto& logger = srslog::fetch_basic_logger("PDCP LTE Test RX", false);
|
||
|
logger.set_level(srslog::basic_levels::debug);
|
||
|
logger.set_hex_dump_max_size(128);
|
||
5 years ago
|
|
||
4 years ago
|
TESTASSERT(test_rx_all(logger) == 0);
|
||
|
TESTASSERT(test_rx_control_pdu(logger) == 0);
|
||
4 years ago
|
|
||
5 years ago
|
return 0;
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
4 years ago
|
srslog::init();
|
||
|
|
||
4 years ago
|
if (run_all_tests() != SRSRAN_SUCCESS) {
|
||
5 years ago
|
fprintf(stderr, "pdcp_nr_tests_rx() failed\n");
|
||
4 years ago
|
return SRSRAN_ERROR;
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
return SRSRAN_SUCCESS;
|
||
5 years ago
|
}
|