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.
175 lines
7.1 KiB
C
175 lines
7.1 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
|
*
|
||
|
*/
|
||
|
|
||
4 years ago
|
#ifndef SRSRAN_PDCP_NR_TEST_H
|
||
|
#define SRSRAN_PDCP_NR_TEST_H
|
||
5 years ago
|
|
||
5 years ago
|
#include "pdcp_base_test.h"
|
||
4 years ago
|
#include "srsran/test/ue_test_interfaces.h"
|
||
|
#include "srsran/upper/pdcp_entity_nr.h"
|
||
5 years ago
|
|
||
5 years ago
|
struct pdcp_initial_state {
|
||
|
uint32_t tx_next;
|
||
|
uint32_t rx_next;
|
||
|
uint32_t rx_deliv;
|
||
|
uint32_t rx_reord;
|
||
|
};
|
||
|
|
||
5 years ago
|
// Helper struct to hold a packet and the number of clock
|
||
|
// ticks to run after writing the packet to test timeouts.
|
||
|
struct pdcp_test_event_t {
|
||
4 years ago
|
srsran::unique_byte_buffer_t pkt;
|
||
5 years ago
|
uint32_t ticks = 0;
|
||
|
};
|
||
|
|
||
5 years ago
|
/*
|
||
|
* Constant definitions that are common to multiple tests
|
||
|
*/
|
||
|
// Encryption and Integrity Keys
|
||
5 years ago
|
std::array<uint8_t, 32> k_int = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,
|
||
|
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20, 0x21,
|
||
|
0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30, 0x31};
|
||
|
std::array<uint8_t, 32> k_enc = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,
|
||
|
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20, 0x21,
|
||
|
0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30, 0x31};
|
||
5 years ago
|
|
||
|
// Security Configuration, common to all tests.
|
||
4 years ago
|
srsran::as_security_config_t sec_cfg = {
|
||
5 years ago
|
k_int,
|
||
|
k_enc,
|
||
|
k_int,
|
||
|
k_enc,
|
||
4 years ago
|
srsran::INTEGRITY_ALGORITHM_ID_128_EIA2,
|
||
|
srsran::CIPHERING_ALGORITHM_ID_128_EEA2,
|
||
5 years ago
|
};
|
||
|
|
||
|
// Test SDUs for tx
|
||
|
uint8_t sdu1[] = {0x18, 0xe2};
|
||
|
uint8_t sdu2[] = {0xde, 0xad};
|
||
|
|
||
|
// Test PDUs for rx (generated from SDU1)
|
||
|
uint8_t pdu1_count0_snlen12[] = {0x80, 0x00, 0x8f, 0xe3, 0xe0, 0xdf, 0x82, 0x92};
|
||
|
uint8_t pdu1_count2048_snlen12[] = {0x88, 0x00, 0x8d, 0x2c, 0x47, 0x5e, 0xb1, 0x5b};
|
||
|
uint8_t pdu1_count4096_snlen12[] = {0x80, 0x00, 0x97, 0xbe, 0xa3, 0x32, 0xfa, 0x61};
|
||
|
uint8_t pdu1_count4294967295_snlen12[] = {0x8f, 0xff, 0x1e, 0x47, 0xe6, 0x86, 0x28, 0x6c};
|
||
|
uint8_t pdu1_count0_snlen18[] = {0x80, 0x00, 0x00, 0x8f, 0xe3, 0xe0, 0xdf, 0x82, 0x92};
|
||
|
uint8_t pdu1_count131072_snlen18[] = {0x82, 0x00, 0x00, 0x15, 0x01, 0xf4, 0xb0, 0xfc, 0xc5};
|
||
|
uint8_t pdu1_count262144_snlen18[] = {0x80, 0x00, 0x00, 0xc2, 0x47, 0xa8, 0xdd, 0xc0, 0x73};
|
||
|
uint8_t pdu1_count4294967295_snlen18[] = {0x83, 0xff, 0xff, 0x1e, 0x47, 0xe6, 0x86, 0x28, 0x6c};
|
||
|
|
||
|
// Test PDUs for rx (generated from SDU2)
|
||
|
uint8_t pdu2_count1_snlen12[] = {0x80, 0x01, 0x5e, 0x3d, 0x64, 0xaf, 0xac, 0x7c};
|
||
|
uint8_t pdu2_count1_snlen18[] = {0x80, 0x00, 0x01, 0x5e, 0x3d, 0x64, 0xaf, 0xac, 0x7c};
|
||
|
|
||
|
// This is the normal initial state. All state variables are set to zero
|
||
|
pdcp_initial_state normal_init_state = {};
|
||
|
|
||
|
// Some tests regarding COUNT wraparound take really long.
|
||
|
// This puts the PCDC state closer to wraparound quickly.
|
||
5 years ago
|
pdcp_initial_state near_wraparound_init_state = {.tx_next = 4294967295,
|
||
|
.rx_next = 4294967295,
|
||
|
.rx_deliv = 4294967295,
|
||
|
.rx_reord = 0};
|
||
5 years ago
|
|
||
5 years ago
|
/*
|
||
|
* Helper classes to reduce copy / pasting in setting up tests
|
||
|
*/
|
||
5 years ago
|
// PDCP helper to setup PDCP + Dummy
|
||
5 years ago
|
class pdcp_nr_test_helper
|
||
|
{
|
||
|
public:
|
||
4 years ago
|
pdcp_nr_test_helper(srsran::pdcp_config_t cfg, srsran::as_security_config_t sec_cfg_, srslog::basic_logger& logger) :
|
||
4 years ago
|
rlc(logger), rrc(logger), gw(logger), pdcp(&rlc, &rrc, &gw, &stack.task_sched, logger, 0)
|
||
5 years ago
|
{
|
||
4 years ago
|
pdcp.configure(cfg);
|
||
5 years ago
|
pdcp.config_security(sec_cfg_);
|
||
4 years ago
|
pdcp.enable_integrity(srsran::DIRECTION_TXRX);
|
||
|
pdcp.enable_encryption(srsran::DIRECTION_TXRX);
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
void set_pdcp_initial_state(pdcp_initial_state init_state)
|
||
|
{
|
||
5 years ago
|
pdcp.set_tx_next(init_state.tx_next);
|
||
|
pdcp.set_rx_next(init_state.rx_next);
|
||
|
pdcp.set_rx_deliv(init_state.rx_deliv);
|
||
|
pdcp.set_rx_reord(init_state.rx_reord);
|
||
|
}
|
||
|
|
||
5 years ago
|
rlc_dummy rlc;
|
||
|
rrc_dummy rrc;
|
||
|
gw_dummy gw;
|
||
|
srsue::stack_test_dummy stack;
|
||
4 years ago
|
srsran::pdcp_entity_nr pdcp;
|
||
5 years ago
|
};
|
||
5 years ago
|
|
||
5 years ago
|
// Helper function to generate PDUs
|
||
4 years ago
|
srsran::unique_byte_buffer_t gen_expected_pdu(const srsran::unique_byte_buffer_t& in_sdu,
|
||
5 years ago
|
uint32_t count,
|
||
|
uint8_t pdcp_sn_len,
|
||
4 years ago
|
srsran::as_security_config_t sec_cfg,
|
||
4 years ago
|
srslog::basic_logger& logger)
|
||
5 years ago
|
{
|
||
4 years ago
|
srsran::pdcp_config_t cfg = {1,
|
||
|
srsran::PDCP_RB_IS_DRB,
|
||
|
srsran::SECURITY_DIRECTION_UPLINK,
|
||
|
srsran::SECURITY_DIRECTION_DOWNLINK,
|
||
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(cfg, sec_cfg, logger);
|
||
4 years ago
|
srsran::pdcp_entity_nr* pdcp = &pdcp_hlp.pdcp;
|
||
5 years ago
|
rlc_dummy* rlc = &pdcp_hlp.rlc;
|
||
5 years ago
|
|
||
5 years ago
|
pdcp_initial_state init_state = {};
|
||
5 years ago
|
init_state.tx_next = count;
|
||
5 years ago
|
pdcp_hlp.set_pdcp_initial_state(init_state);
|
||
|
|
||
4 years ago
|
srsran::unique_byte_buffer_t sdu = srsran::make_byte_buffer();
|
||
5 years ago
|
*sdu = *in_sdu;
|
||
5 years ago
|
pdcp->write_sdu(std::move(sdu));
|
||
4 years ago
|
srsran::unique_byte_buffer_t out_pdu = srsran::make_byte_buffer();
|
||
5 years ago
|
rlc->get_last_sdu(out_pdu);
|
||
5 years ago
|
|
||
5 years ago
|
return out_pdu;
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
// Helper function to generate vector of PDU from a vector of TX_NEXTs for generating expected pdus
|
||
4 years ago
|
std::vector<pdcp_test_event_t> gen_expected_pdus_vector(const srsran::unique_byte_buffer_t& in_sdu,
|
||
5 years ago
|
const std::vector<uint32_t>& tx_nexts,
|
||
|
uint8_t pdcp_sn_len,
|
||
4 years ago
|
srsran::as_security_config_t sec_cfg_,
|
||
4 years ago
|
srslog::basic_logger& logger)
|
||
5 years ago
|
{
|
||
5 years ago
|
std::vector<pdcp_test_event_t> pdu_vec;
|
||
5 years ago
|
for (uint32_t tx_next : tx_nexts) {
|
||
5 years ago
|
pdcp_test_event_t event;
|
||
4 years ago
|
event.pkt = gen_expected_pdu(in_sdu, tx_next, pdcp_sn_len, sec_cfg_, logger);
|
||
5 years ago
|
event.ticks = 0;
|
||
|
pdu_vec.push_back(std::move(event));
|
||
5 years ago
|
}
|
||
5 years ago
|
return pdu_vec;
|
||
5 years ago
|
}
|
||
5 years ago
|
|
||
4 years ago
|
#endif // SRSRAN_PDCP_NR_TEST_H
|