From 4bb99464ed5ae940f61d83cf879a6eb249f1bbc7 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 4 Jul 2019 18:02:34 +0100 Subject: [PATCH] Starting to add PDCP NR tests. --- lib/src/upper/pdcp_entity_nr.cc | 4 +- lib/test/upper/CMakeLists.txt | 4 ++ lib/test/upper/pdcp_nr_test.cc | 102 ++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 lib/test/upper/pdcp_nr_test.cc diff --git a/lib/src/upper/pdcp_entity_nr.cc b/lib/src/upper/pdcp_entity_nr.cc index 39362c1af..9ca3e0e86 100644 --- a/lib/src/upper/pdcp_entity_nr.cc +++ b/lib/src/upper/pdcp_entity_nr.cc @@ -78,10 +78,10 @@ void pdcp_entity_nr::write_sdu(unique_byte_buffer_t sdu, bool blocking) // Integrity protection and ciphering integrity_generate(sdu->msg, sdu->N_bytes - 4, tx_next, &sdu->msg[sdu->N_bytes - 4]); - ciphering_generate(sdu->msg, sdu->N_bytes - 4, tx_next, &sdu->msg[sdu->N_bytes - 4]); + cipher_encrypt(sdu->msg, sdu->N_bytes - 4, tx_next, &sdu->msg[sdu->N_bytes - 4]); // Write PDCP header info - write_header(pdu, tx_next); + //write_header(pdu, tx_next); // Write to lower layers rlc->write_sdu(lcid, std::move(sdu), blocking); diff --git a/lib/test/upper/CMakeLists.txt b/lib/test/upper/CMakeLists.txt index 43e77ce01..a89512b3e 100644 --- a/lib/test/upper/CMakeLists.txt +++ b/lib/test/upper/CMakeLists.txt @@ -51,6 +51,10 @@ add_executable(rlc_common_test rlc_common_test.cc) target_link_libraries(rlc_common_test srslte_upper srslte_phy) add_test(rlc_common_test rlc_common_test) +add_executable(pdcp_nr_test pdcp_nr_test.cc) +target_link_libraries(pdcp_nr_test srslte_upper srslte_common) +add_test(pdcp_nr_test pdcp_nr_test) + ######################################################################## # Option to run command after build (useful for remote builds) ######################################################################## diff --git a/lib/test/upper/pdcp_nr_test.cc b/lib/test/upper/pdcp_nr_test.cc new file mode 100644 index 000000000..dffc2bf14 --- /dev/null +++ b/lib/test/upper/pdcp_nr_test.cc @@ -0,0 +1,102 @@ +/* + * 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/. + * + */ + +#include "srslte/common/log_filter.h" +#include "srslte/upper/pdcp_entity_nr.h" +#include + +#define TESTASSERT(cond) \ + { \ + if (!(cond)) { \ + std::cout << "[" << __FUNCTION__ << "][Line " << __LINE__ << "]: FAIL at " << (#cond) << std::endl; \ + return -1; \ + } \ + } + +// Encription and Integrity Keys +uint8_t 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}; +uint8_t 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}; + +// Test SDUs for tx +uint8_t sdu1[] = {0x18, 0xE2}; +uint32_t SDU1_LEN = 2; + +// fake classes +class rlc_dummy : public srsue::rlc_interface_pdcp +{ +public: + rlc_dummy(srslte::log_filter* log_) : log(log_) {} + +private: + srslte::log_filter* log; +}; + +class rrc_dummy : public srsue::rrc_interface_pdcp +{ +public: + rrc_dummy(srslte::log_filter* log_) : log(log_) {} + +private: + srslte::log_filter* log; +}; + +class gw_dummy : public srsue::gw_interface_pdcp +{ +public: + gw_dummy(srslte::log_filter* log_) : log(log_) {} + +private: + srslte::log_filter* log; +}; + +// Setup all tests +int run_all_tests() +{ + srslte::log_filter log("PDCP NR Test"); + log.set_level(srslte::LOG_LEVEL_DEBUG); + log.set_hex_limit(128); + TESTASSERT(test_tx_basic(&log)); +} + +/* + * Test 1: PDCP Entity TX + */ +bool test_tx_basic(srslte::log_filter* log) +{ + srslte::pdcp_entity_nr pdcp; + srslte::srslte_pdcp_config_nr_t cfg = {0, false, true, SECURITY_DIRECTION_UPLINK, srslte::PDCP_SN_LEN_12}; + + rlc_dummy rlc; + rrc_dummy rrc; + gw_dummy gw; + + pdcp.init(rlc, rrc, gw, log, 0, cfg); + + return true; +} + +int main(int argc, char** argv) +{ + run_all_tests(); + srslte::pool::cleanup(); +}