From b841859220f00ae27906ef5454b7721758f23804 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Tue, 18 Feb 2020 15:32:44 +0000 Subject: [PATCH] Moved pdcp test functionality to a common header. Fixed linking issue in 5GNR PDCP --- lib/include/srslte/upper/pdcp_entity_nr.h | 6 - lib/test/upper/pdcp_base_test.h | 149 ++++++++++++++++++++++ lib/test/upper/pdcp_nr_test.h | 123 +----------------- 3 files changed, 150 insertions(+), 128 deletions(-) create mode 100644 lib/test/upper/pdcp_base_test.h diff --git a/lib/include/srslte/upper/pdcp_entity_nr.h b/lib/include/srslte/upper/pdcp_entity_nr.h index b7f5f4f68..3cb4c0645 100644 --- a/lib/include/srslte/upper/pdcp_entity_nr.h +++ b/lib/include/srslte/upper/pdcp_entity_nr.h @@ -85,12 +85,6 @@ private: std::map reorder_queue; timer_handler::unique_timer reordering_timer; - // Packing/Unpacking Helper functions - uint32_t read_data_header(const unique_byte_buffer_t& sdu); - void write_data_header(const unique_byte_buffer_t& sdu, uint32_t sn); - void extract_mac(const unique_byte_buffer_t& sdu, uint8_t* mac); - void append_mac(const unique_byte_buffer_t& sdu, uint8_t* mac); - // Pass to Upper Layers Helper function void deliver_all_consecutive_counts(); void pass_to_upper_layers(unique_byte_buffer_t pdu); diff --git a/lib/test/upper/pdcp_base_test.h b/lib/test/upper/pdcp_base_test.h new file mode 100644 index 000000000..0bc116e48 --- /dev/null +++ b/lib/test/upper/pdcp_base_test.h @@ -0,0 +1,149 @@ +/* + * Copyright 2013-2019 Software Radio Systems Limited + * + * This file is part of srsLTE. + * + * srsLTE is free software: you can redistribute it and/or modify + * 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. + * + * srsLTE is distributed in the hope that it will be useful, + * 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. + * + * 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/. + * + */ + +#ifndef SRSLTE_PDCP_BASE_TEST_H +#define SRSLTE_PDCP_BASE_TEST_H + +#include "srslte/common/buffer_pool.h" +#include "srslte/common/log_filter.h" +#include "srslte/common/security.h" +#include "srslte/interfaces/ue_interfaces.h" +#include + +/* + * Functions and macros for comparisions + */ +#define TESTASSERT(cond) \ + { \ + if (!(cond)) { \ + std::cout << "[" << __FUNCTION__ << "][Line " << __LINE__ << "]: FAIL at " << (#cond) << std::endl; \ + return -1; \ + } \ + } + +int compare_two_packets(const srslte::unique_byte_buffer_t& msg1, const srslte::unique_byte_buffer_t& msg2) +{ + TESTASSERT(msg1->N_bytes == msg2->N_bytes); + for (uint32_t i = 0; i < msg1->N_bytes; ++i) { + TESTASSERT(msg1->msg[i] == msg2->msg[i]); + } + return 0; +} + +/* + * Definition of helpful structs for testing + */ +struct pdcp_security_cfg { + uint8_t* k_int_rrc; + uint8_t* k_enc_rrc; + uint8_t* k_int_up; + uint8_t* k_enc_up; + srslte::INTEGRITY_ALGORITHM_ID_ENUM int_algo; + srslte::CIPHERING_ALGORITHM_ID_ENUM enc_algo; +}; + +/* + * Dummy classes + */ +class rlc_dummy : public srsue::rlc_interface_pdcp +{ +public: + rlc_dummy(srslte::log* log_) : log(log_) {} + + void get_last_sdu(const srslte::unique_byte_buffer_t& pdu) + { + memcpy(pdu->msg, last_pdcp_pdu->msg, last_pdcp_pdu->N_bytes); + pdu->N_bytes = last_pdcp_pdu->N_bytes; + return; + } + void write_sdu(uint32_t lcid, srslte::unique_byte_buffer_t sdu, bool blocking = true) + { + log->info_hex(sdu->msg, sdu->N_bytes, "RLC SDU"); + last_pdcp_pdu.swap(sdu); + rx_count++; + } + void discard_sdu(uint32_t lcid, uint32_t discard_sn) + { + log->info("Notifing RLC to discard SDU (SN=%u)\n", discard_sn); + discard_count++; + log->info("Discard_count=%" PRIu64 "\n", discard_count); + } + + uint64_t rx_count = 0; + uint64_t discard_count = 0; + +private: + srslte::log* log; + srslte::unique_byte_buffer_t last_pdcp_pdu; + + bool rb_is_um(uint32_t lcid) { return false; } +}; + +class rrc_dummy : public srsue::rrc_interface_pdcp +{ +public: + rrc_dummy(srslte::log* log_) {} + + void write_pdu(uint32_t lcid, srslte::unique_byte_buffer_t pdu) {} + void write_pdu_bcch_bch(srslte::unique_byte_buffer_t pdu) {} + void write_pdu_bcch_dlsch(srslte::unique_byte_buffer_t pdu) {} + void write_pdu_pcch(srslte::unique_byte_buffer_t pdu) {} + void write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu) {} + + std::string get_rb_name(uint32_t lcid) { return "None"; } +}; + +class gw_dummy : public srsue::gw_interface_pdcp +{ +public: + gw_dummy(srslte::log* log_) : log(log_) {} + + void write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu) {} + uint32_t rx_count = 0; + + void get_last_pdu(const srslte::unique_byte_buffer_t& pdu) + { + memcpy(pdu->msg, last_pdu->msg, last_pdu->N_bytes); + pdu->N_bytes = last_pdu->N_bytes; + return; + } + void write_pdu(uint32_t lcid, srslte::unique_byte_buffer_t pdu) + { + log->info_hex(pdu->msg, pdu->N_bytes, "GW PDU"); + rx_count++; + last_pdu.swap(pdu); + } + +private: + srslte::log* log; + srslte::unique_byte_buffer_t last_pdu; +}; + +// Helper to print packets +void print_packet_array(const srslte::unique_byte_buffer_t& msg) +{ + printf("uint8_t msg[] = {\n"); + for (uint64_t i = 0; i < msg->N_bytes; ++i) { + printf("0x%02x, ", msg->msg[i]); + } + printf("\n};\n"); +} +#endif // SRSLTE_PDCP_BASE_TEST_H diff --git a/lib/test/upper/pdcp_nr_test.h b/lib/test/upper/pdcp_nr_test.h index 8d958a0a9..bb050a71a 100644 --- a/lib/test/upper/pdcp_nr_test.h +++ b/lib/test/upper/pdcp_nr_test.h @@ -22,43 +22,8 @@ #ifndef SRSLTE_PDCP_NR_TEST_H #define SRSLTE_PDCP_NR_TEST_H -#include "srslte/common/buffer_pool.h" -#include "srslte/common/log_filter.h" -#include "srslte/common/security.h" +#include "pdcp_base_test.h" #include "srslte/upper/pdcp_entity_nr.h" -#include - -/* - * Functions and macros for comparisions - */ -#define TESTASSERT(cond) \ - { \ - if (!(cond)) { \ - std::cout << "[" << __FUNCTION__ << "][Line " << __LINE__ << "]: FAIL at " << (#cond) << std::endl; \ - return -1; \ - } \ - } - -int compare_two_packets(const srslte::unique_byte_buffer_t& msg1, const srslte::unique_byte_buffer_t& msg2) -{ - TESTASSERT(msg1->N_bytes == msg2->N_bytes); - for (uint32_t i = 0; i < msg1->N_bytes; ++i) { - TESTASSERT(msg1->msg[i] == msg2->msg[i]); - } - return 0; -} - -/* - * Definition of helpful structs for testing - */ -struct pdcp_security_cfg { - uint8_t* k_int_rrc; - uint8_t* k_enc_rrc; - uint8_t* k_int_up; - uint8_t* k_enc_up; - srslte::INTEGRITY_ALGORITHM_ID_ENUM int_algo; - srslte::CIPHERING_ALGORITHM_ID_ENUM enc_algo; -}; struct pdcp_initial_state { uint32_t tx_next; @@ -121,83 +86,6 @@ pdcp_initial_state near_wraparound_init_state = {.tx_next = 4294967295, .rx_deliv = 4294967295, .rx_reord = 0}; -/* - * Dummy classes - */ -class rlc_dummy : public srsue::rlc_interface_pdcp -{ -public: - rlc_dummy(srslte::log* log_) : log(log_) {} - - void get_last_sdu(const srslte::unique_byte_buffer_t& pdu) - { - memcpy(pdu->msg, last_pdcp_pdu->msg, last_pdcp_pdu->N_bytes); - pdu->N_bytes = last_pdcp_pdu->N_bytes; - return; - } - void write_sdu(uint32_t lcid, srslte::unique_byte_buffer_t sdu, bool blocking = true) - { - log->info_hex(sdu->msg, sdu->N_bytes, "RLC SDU"); - last_pdcp_pdu.swap(sdu); - rx_count++; - } - void discard_sdu(uint32_t lcid, uint32_t discard_sn) - { - log->info("Notifing RLC to discard SDU (SN=%u)\n", discard_sn); - discard_count++; - log->info("Discard_count=%" PRIu64 "\n", discard_count); - } - - uint64_t rx_count = 0; - uint64_t discard_count = 0; - -private: - srslte::log* log; - srslte::unique_byte_buffer_t last_pdcp_pdu; - - bool rb_is_um(uint32_t lcid) { return false; } -}; - -class rrc_dummy : public srsue::rrc_interface_pdcp -{ -public: - rrc_dummy(srslte::log* log_) {} - - void write_pdu(uint32_t lcid, srslte::unique_byte_buffer_t pdu) {} - void write_pdu_bcch_bch(srslte::unique_byte_buffer_t pdu) {} - void write_pdu_bcch_dlsch(srslte::unique_byte_buffer_t pdu) {} - void write_pdu_pcch(srslte::unique_byte_buffer_t pdu) {} - void write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu) {} - - std::string get_rb_name(uint32_t lcid) { return "None"; } -}; - -class gw_dummy : public srsue::gw_interface_pdcp -{ -public: - gw_dummy(srslte::log* log_) : log(log_) {} - - void write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu) {} - uint32_t rx_count = 0; - - void get_last_pdu(const srslte::unique_byte_buffer_t& pdu) - { - memcpy(pdu->msg, last_pdu->msg, last_pdu->N_bytes); - pdu->N_bytes = last_pdu->N_bytes; - return; - } - void write_pdu(uint32_t lcid, srslte::unique_byte_buffer_t pdu) - { - log->info_hex(pdu->msg, pdu->N_bytes, "GW PDU"); - rx_count++; - last_pdu.swap(pdu); - } - -private: - srslte::log* log; - srslte::unique_byte_buffer_t last_pdu; -}; - /* * Helper classes to reduce copy / pasting in setting up tests */ @@ -285,13 +173,4 @@ std::vector gen_expected_pdus_vector(const srslte::unique_byt return pdu_vec; } -// Helper to print packets -void print_packet_array(const srslte::unique_byte_buffer_t& msg) -{ - printf("uint8_t msg[] = {\n"); - for (uint64_t i = 0; i < msg->N_bytes; ++i) { - printf("0x%02x, ", msg->msg[i]); - } - printf("\n};\n"); -} #endif // SRSLTE_PDCP_NR_TEST_H