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.
252 lines
9.8 KiB
C++
252 lines
9.8 KiB
C++
4 years ago
|
/**
|
||
4 years ago
|
* Copyright 2013-2021 Software Radio Systems Limited
|
||
5 years ago
|
*
|
||
4 years ago
|
* This file is part of srsRAN.
|
||
5 years ago
|
*
|
||
4 years ago
|
* srsRAN is free software: you can redistribute it and/or modify
|
||
4 years ago
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
4 years ago
|
* srsRAN is distributed in the hope that it will be useful,
|
||
4 years ago
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
5 years ago
|
*
|
||
4 years ago
|
* A copy of the GNU Affero General Public License can be found in
|
||
|
* the LICENSE file in the top-level directory of this distribution
|
||
|
* and at http://www.gnu.org/licenses/.
|
||
5 years ago
|
*
|
||
|
*/
|
||
|
#include "pdcp_nr_test.h"
|
||
|
#include <numeric>
|
||
|
|
||
|
/*
|
||
|
* Genric function to test reception of in-sequence packets
|
||
|
*/
|
||
|
int test_rx(std::vector<pdcp_test_event_t> events,
|
||
|
const pdcp_initial_state& init_state,
|
||
|
uint8_t pdcp_sn_len,
|
||
|
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,
|
||
|
srsran::PDCP_RB_IS_DRB,
|
||
|
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::nr};
|
||
5 years ago
|
|
||
4 years ago
|
pdcp_nr_test_helper pdcp_hlp_rx(cfg_rx, sec_cfg, logger);
|
||
4 years ago
|
srsran::pdcp_entity_nr* pdcp_rx = &pdcp_hlp_rx.pdcp;
|
||
4 years ago
|
gw_dummy* gw_rx = &pdcp_hlp_rx.gw;
|
||
|
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) {
|
||
4 years ago
|
stack->run_tti();
|
||
5 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// Test if the number of RX packets
|
||
|
TESTASSERT(gw_rx->rx_count == n_sdus_exp);
|
||
4 years ago
|
srsran::unique_byte_buffer_t sdu_act = srsran::make_byte_buffer();
|
||
5 years ago
|
gw_rx->get_last_pdu(sdu_act);
|
||
|
TESTASSERT(compare_two_packets(sdu_exp, sdu_act) == 0);
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* RX Test: PDCP Entity with SN LEN = 12 and 18.
|
||
|
* 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 Entity with SN LEN = 12
|
||
|
* Test in-sequence reception of 4097 packets.
|
||
|
* This tests correct handling of HFN in the case of SN wraparound (SN LEN 12)
|
||
|
*/
|
||
|
{
|
||
|
std::vector<uint32_t> test1_counts(2); // Test two packets
|
||
|
std::iota(test1_counts.begin(), test1_counts.end(), 4095); // Starting at COUNT 4095
|
||
|
std::vector<pdcp_test_event_t> test1_pdus =
|
||
4 years ago
|
gen_expected_pdus_vector(tst_sdu1, test1_counts, srsran::PDCP_SN_LEN_12, sec_cfg, logger);
|
||
5 years ago
|
pdcp_initial_state test1_init_state = {.tx_next = 4095, .rx_next = 4095, .rx_deliv = 4095, .rx_reord = 0};
|
||
4 years ago
|
TESTASSERT(test_rx(std::move(test1_pdus), test1_init_state, srsran::PDCP_SN_LEN_12, 2, tst_sdu1, logger) == 0);
|
||
5 years ago
|
}
|
||
|
/*
|
||
|
* RX Test 2: PDCP Entity with SN LEN = 12
|
||
|
* Test in-sequence reception of 4294967297 packets.
|
||
|
* This tests correct handling of COUNT in the case of [HFN|SN] wraparound
|
||
|
* Packet that wraparound should be dropped, so only one packet should be received at the GW.
|
||
|
*/
|
||
|
{
|
||
|
std::vector<uint32_t> test2_counts(2); // Test two packets
|
||
|
std::iota(test2_counts.begin(), test2_counts.end(), 4294967295); // Starting at COUNT 4294967295
|
||
|
std::vector<pdcp_test_event_t> test2_pdus =
|
||
4 years ago
|
gen_expected_pdus_vector(tst_sdu1, test2_counts, srsran::PDCP_SN_LEN_12, sec_cfg, logger);
|
||
5 years ago
|
pdcp_initial_state test2_init_state = {
|
||
|
.tx_next = 4294967295, .rx_next = 4294967295, .rx_deliv = 4294967295, .rx_reord = 0};
|
||
4 years ago
|
TESTASSERT(test_rx(std::move(test2_pdus), test2_init_state, srsran::PDCP_SN_LEN_12, 1, tst_sdu1, logger) == 0);
|
||
5 years ago
|
}
|
||
|
/*
|
||
|
* RX Test 3: PDCP Entity with SN LEN = 18
|
||
|
* Test In-sequence reception of 262145 packets.
|
||
|
* This tests correct handling of HFN in the case of SN wraparound (SN LEN 18)
|
||
|
*/
|
||
|
{
|
||
|
std::vector<uint32_t> test3_counts(2); // Test two packets
|
||
|
std::iota(test3_counts.begin(), test3_counts.end(), 262144); // Starting at COUNT 262144
|
||
|
std::vector<pdcp_test_event_t> test3_pdus =
|
||
4 years ago
|
gen_expected_pdus_vector(tst_sdu1, test3_counts, srsran::PDCP_SN_LEN_18, sec_cfg, logger);
|
||
5 years ago
|
pdcp_initial_state test3_init_state = {.tx_next = 262144, .rx_next = 262144, .rx_deliv = 262144, .rx_reord = 0};
|
||
4 years ago
|
TESTASSERT(test_rx(std::move(test3_pdus), test3_init_state, srsran::PDCP_SN_LEN_18, 2, tst_sdu1, logger) == 0);
|
||
5 years ago
|
}
|
||
|
|
||
|
/*
|
||
|
* RX Test 4: PDCP Entity with SN LEN = 18
|
||
|
* Test in-sequence reception of 4294967297 packets.
|
||
|
* This tests correct handling of COUNT in the case of [HFN|SN] wraparound
|
||
|
*/
|
||
|
{
|
||
|
std::vector<uint32_t> test4_counts(2); // Test two packets
|
||
|
std::iota(test4_counts.begin(), test4_counts.end(), 4294967295); // Starting at COUNT 4294967295
|
||
|
std::vector<pdcp_test_event_t> test4_pdus =
|
||
4 years ago
|
gen_expected_pdus_vector(tst_sdu1, test4_counts, srsran::PDCP_SN_LEN_18, sec_cfg, logger);
|
||
5 years ago
|
pdcp_initial_state test4_init_state = {
|
||
|
.tx_next = 4294967295, .rx_next = 4294967295, .rx_deliv = 4294967295, .rx_reord = 0};
|
||
4 years ago
|
TESTASSERT(test_rx(std::move(test4_pdus), test4_init_state, srsran::PDCP_SN_LEN_18, 1, tst_sdu1, logger) == 0);
|
||
5 years ago
|
}
|
||
|
|
||
|
/*
|
||
|
* RX Test 5: PDCP Entity with SN LEN = 12
|
||
|
* Test reception of two out-of-order packets, starting at COUNT 0.
|
||
|
*/
|
||
|
{
|
||
|
std::vector<pdcp_test_event_t> test5_pdus;
|
||
|
pdcp_initial_state test5_init_state = {};
|
||
|
|
||
|
// First PDU
|
||
|
pdcp_test_event_t event_pdu1;
|
||
4 years ago
|
event_pdu1.pkt = srsran::make_byte_buffer();
|
||
5 years ago
|
event_pdu1.pkt->append_bytes(pdu1_count0_snlen12, sizeof(pdu1_count0_snlen12));
|
||
|
|
||
|
// Second PDU
|
||
|
pdcp_test_event_t event_pdu2;
|
||
4 years ago
|
event_pdu2.pkt = srsran::make_byte_buffer();
|
||
5 years ago
|
event_pdu2.pkt->append_bytes(pdu2_count1_snlen12, sizeof(pdu2_count1_snlen12));
|
||
|
|
||
|
// Write PDUs out of order (first the pdu with COUNT 1 and COUNT 0 after)
|
||
|
test5_pdus.push_back(std::move(event_pdu2));
|
||
|
test5_pdus.push_back(std::move(event_pdu1));
|
||
4 years ago
|
TESTASSERT(test_rx(std::move(test5_pdus), test5_init_state, srsran::PDCP_SN_LEN_12, 2, tst_sdu2, logger) == 0);
|
||
5 years ago
|
}
|
||
|
|
||
|
/*
|
||
|
* RX Test 6: PDCP Entity with SN LEN = 18
|
||
|
* Test reception of two out-of-order packets, starting at COUNT 0.
|
||
|
*/
|
||
|
{
|
||
|
std::vector<pdcp_test_event_t> test6_pdus;
|
||
|
pdcp_initial_state test6_init_state = {};
|
||
|
|
||
|
// First PDU
|
||
|
pdcp_test_event_t event_pdu1;
|
||
4 years ago
|
event_pdu1.pkt = srsran::make_byte_buffer();
|
||
5 years ago
|
event_pdu1.pkt->append_bytes(pdu1_count0_snlen18, sizeof(pdu1_count0_snlen18));
|
||
|
|
||
|
// Second PDU
|
||
|
pdcp_test_event_t event_pdu2;
|
||
4 years ago
|
event_pdu2.pkt = srsran::make_byte_buffer();
|
||
5 years ago
|
event_pdu2.pkt->append_bytes(pdu2_count1_snlen18, sizeof(pdu2_count1_snlen18));
|
||
|
|
||
|
// Write PDUs out of order (first the pdu with COUNT 1 and COUNT 0 after)
|
||
|
test6_pdus.push_back(std::move(event_pdu2));
|
||
|
test6_pdus.push_back(std::move(event_pdu1));
|
||
4 years ago
|
TESTASSERT(test_rx(std::move(test6_pdus), test6_init_state, srsran::PDCP_SN_LEN_18, 2, tst_sdu2, logger) == 0);
|
||
5 years ago
|
}
|
||
|
|
||
|
/*
|
||
|
* RX Test 7: PDCP Entity with SN LEN = 12
|
||
|
* Test Reception of one out-of-order packet.
|
||
|
*/
|
||
|
{
|
||
|
std::vector<pdcp_test_event_t> test7_pdus;
|
||
|
pdcp_initial_state test7_init_state = {};
|
||
|
|
||
|
// First PDU
|
||
|
pdcp_test_event_t event_pdu1;
|
||
4 years ago
|
event_pdu1.pkt = srsran::make_byte_buffer();
|
||
5 years ago
|
event_pdu1.pkt->append_bytes(pdu2_count1_snlen12, sizeof(pdu2_count1_snlen12));
|
||
|
event_pdu1.ticks = 500;
|
||
|
|
||
|
// Write PDUs out of order (first the pdu with COUNT 1 and COUNT 0 after)
|
||
|
test7_pdus.push_back(std::move(event_pdu1));
|
||
4 years ago
|
TESTASSERT(test_rx(std::move(test7_pdus), test7_init_state, srsran::PDCP_SN_LEN_12, 1, tst_sdu2, logger) == 0);
|
||
5 years ago
|
}
|
||
|
|
||
|
/*
|
||
|
* RX Test 8: PDCP Entity with SN LEN = 12
|
||
|
* Test reception of two duplicate PDUs, with COUNT 0.
|
||
|
*/
|
||
|
{
|
||
|
std::vector<pdcp_test_event_t> test8_pdus;
|
||
|
pdcp_initial_state test8_init_state = {};
|
||
|
|
||
|
// First PDU
|
||
|
pdcp_test_event_t event_pdu1;
|
||
4 years ago
|
event_pdu1.pkt = srsran::make_byte_buffer();
|
||
5 years ago
|
event_pdu1.pkt->append_bytes(pdu1_count0_snlen12, sizeof(pdu1_count0_snlen12));
|
||
|
|
||
|
// Second PDU
|
||
|
pdcp_test_event_t event_pdu2;
|
||
4 years ago
|
event_pdu2.pkt = srsran::make_byte_buffer();
|
||
5 years ago
|
event_pdu2.pkt->append_bytes(pdu1_count0_snlen12, sizeof(pdu1_count0_snlen12));
|
||
|
|
||
|
// Write PDUs out of order (first the pdu with COUNT 1 and COUNT 0 after)
|
||
|
test8_pdus.push_back(std::move(event_pdu1));
|
||
|
test8_pdus.push_back(std::move(event_pdu2));
|
||
4 years ago
|
TESTASSERT(test_rx(std::move(test8_pdus), test8_init_state, srsran::PDCP_SN_LEN_12, 1, tst_sdu1, logger) == 0);
|
||
5 years ago
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
// 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 NR 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);
|
||
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
|
}
|