From 1d56fa6308f9ed4db22afb695cd01e82002a129e Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 9 Oct 2019 15:24:19 +0100 Subject: [PATCH] Improved speed of tests for COUNT wraparound, by setting the PDCP initial state. --- lib/include/srslte/upper/pdcp_entity_nr.h | 3 ++ lib/src/upper/pdcp_entity_base.cc | 8 ++-- lib/src/upper/pdcp_entity_nr.cc | 4 +- lib/test/upper/pdcp_nr_test.cc | 48 +++++++++++++++-------- lib/test/upper/pdcp_nr_test.h | 14 +++++++ 5 files changed, 54 insertions(+), 23 deletions(-) diff --git a/lib/include/srslte/upper/pdcp_entity_nr.h b/lib/include/srslte/upper/pdcp_entity_nr.h index 759b5dcdb..4e7a8839d 100644 --- a/lib/include/srslte/upper/pdcp_entity_nr.h +++ b/lib/include/srslte/upper/pdcp_entity_nr.h @@ -114,6 +114,9 @@ private: pdcp_entity_nr* parent; }; +/* + * Helpers + */ inline void pdcp_entity_nr::pass_to_upper_layers(unique_byte_buffer_t sdu) { if (is_srb()) { diff --git a/lib/src/upper/pdcp_entity_base.cc b/lib/src/upper/pdcp_entity_base.cc index 7e9c2993b..31f3c151a 100644 --- a/lib/src/upper/pdcp_entity_base.cc +++ b/lib/src/upper/pdcp_entity_base.cc @@ -86,7 +86,7 @@ void pdcp_entity_base::integrity_generate(uint8_t* msg, uint32_t msg_len, uint32 break; } - log->debug("Integrity gen input: COUNT %d, Bearer ID %d, Direction %s\n", + log->debug("Integrity gen input: COUNT %" PRIu32 ", Bearer ID %d, Direction %s\n", count, cfg.bearer_id, (cfg.tx_direction == SECURITY_DIRECTION_DOWNLINK ? "Downlink" : "Uplink")); @@ -123,7 +123,7 @@ bool pdcp_entity_base::integrity_verify(uint8_t* msg, uint32_t msg_len, uint32_t break; } - log->debug("Integrity check input: COUNT %d, Bearer ID %d, Direction %s\n", + log->debug("Integrity check input: COUNT %" PRIu32 ", Bearer ID %d, Direction %s\n", count, cfg.bearer_id, cfg.rx_direction == SECURITY_DIRECTION_DOWNLINK ? "Downlink" : "Uplink"); @@ -158,7 +158,7 @@ void pdcp_entity_base::cipher_encrypt(uint8_t* msg, uint32_t msg_len, uint32_t c k_enc = k_up_enc; } - log->debug("Cipher encrypt input: COUNT: %d, Bearer ID: %d, Direction %s\n", + log->debug("Cipher encrypt input: COUNT: %" PRIu32 ", Bearer ID: %d, Direction %s\n", count, cfg.bearer_id, cfg.tx_direction == SECURITY_DIRECTION_DOWNLINK ? "Downlink" : "Uplink"); @@ -197,7 +197,7 @@ void pdcp_entity_base::cipher_decrypt(uint8_t* ct, uint32_t ct_len, uint32_t cou k_enc = k_up_enc; } - log->debug("Cipher decrypt input: COUNT: %d, Bearer ID: %d, Direction %s\n", + log->debug("Cipher decrypt input: COUNT: %" PRIu32 ", Bearer ID: %d, Direction %s\n", count, cfg.bearer_id, (cfg.rx_direction == SECURITY_DIRECTION_DOWNLINK) ? "Downlink" : "Uplink"); diff --git a/lib/src/upper/pdcp_entity_nr.cc b/lib/src/upper/pdcp_entity_nr.cc index 98765e7d1..c292c59a1 100644 --- a/lib/src/upper/pdcp_entity_nr.cc +++ b/lib/src/upper/pdcp_entity_nr.cc @@ -140,7 +140,7 @@ void pdcp_entity_nr::write_pdu(unique_byte_buffer_t pdu) } rcvd_count = COUNT(rcvd_hfn, rcvd_sn); - log->debug("RCVD_SN %d, RCVD_COUNT %d\n", rcvd_sn, rcvd_count); + log->debug("RCVD_SN %" PRIu32 ", RCVD_COUNT %" PRIu32 "\n", rcvd_sn, rcvd_count); // Decripting cipher_decrypt(pdu->msg, pdu->N_bytes, rcvd_count, pdu->msg); @@ -285,7 +285,7 @@ void pdcp_entity_nr::deliver_all_consecutive_counts() it != reorder_queue.end() && it->first == rx_deliv; reorder_queue.erase(it++)) { - log->debug("Delivering SDU with RCVD_COUNT %d\n", it->first); + log->debug("Delivering SDU with RCVD_COUNT %" PRIu32 "\n", it->first); // Pass PDCP SDU to the next layers pass_to_upper_layers(std::move(it->second)); diff --git a/lib/test/upper/pdcp_nr_test.cc b/lib/test/upper/pdcp_nr_test.cc index 0b04a95a1..7cd6d7321 100644 --- a/lib/test/upper/pdcp_nr_test.cc +++ b/lib/test/upper/pdcp_nr_test.cc @@ -26,6 +26,7 @@ uint8_t k_int[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0 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}; +// Security Configuration, common to all tests. pdcp_security_cfg sec_cfg = { k_int, k_enc, @@ -98,7 +99,7 @@ int test_tx(uint32_t n_packets, /* * Genric function to test reception of in-sequence packets */ -int test_rx_in_sequence(uint64_t n_packets, uint8_t pdcp_sn_len, srslte::byte_buffer_pool* pool, srslte::log* log) +int test_rx_in_sequence(uint64_t tx_next_max, const pdcp_initial_state &init_state, uint8_t pdcp_sn_len, srslte::byte_buffer_pool* pool, srslte::log* log) { srslte::pdcp_config_t cfg_tx = {1, @@ -123,12 +124,15 @@ int test_rx_in_sequence(uint64_t n_packets, uint8_t pdcp_sn_len, srslte::byte_bu srslte::pdcp_entity_nr* pdcp_rx = &pdcp_hlp_rx.pdcp; gw_dummy* gw_rx = &pdcp_hlp_rx.gw; + pdcp_hlp_tx.set_pdcp_initial_state(init_state); + pdcp_hlp_rx.set_pdcp_initial_state(init_state); + srslte::unique_byte_buffer_t sdu_act = allocate_unique_buffer(*pool); srslte::unique_byte_buffer_t sdu_exp = allocate_unique_buffer(*pool); sdu_exp->append_bytes(sdu1, sizeof(sdu1)); // Generate test message and encript/decript SDU. Check match with original SDU - for (uint64_t i = 0; i < n_packets; ++i) { + for (uint64_t i = init_state.tx_next; i <= tx_next_max; ++i) { srslte::unique_byte_buffer_t sdu = allocate_unique_buffer(*pool); srslte::unique_byte_buffer_t pdu = allocate_unique_buffer(*pool); sdu->append_bytes(sdu_exp->msg, sdu_exp->N_bytes); @@ -466,39 +470,49 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log) */ int test_rx_all(srslte::byte_buffer_pool* pool, srslte::log* log) { + // 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. + pdcp_initial_state near_wraparound_init_state = { + .tx_next = 4294967295, .rx_next = 4294967295, .rx_deliv = 4294967295, .rx_reord = 0}; + /* * 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 */ - TESTASSERT(test_rx_in_sequence(4097, srslte::PDCP_SN_LEN_12, pool, log) == 0); + //TESTASSERT(test_rx_in_sequence(4096, normal_init_state, srslte::PDCP_SN_LEN_12, pool, log) == 0); /* * 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 */ - // // TESTASSERT(test_rx_in_sequence(4294967297, srslte::PDCP_SN_LEN_12, pool, &log) == 0); + //pdcp_initial_state test2_init_state = {}; + TESTASSERT(test_rx_in_sequence(4294967296, near_wraparound_init_state, srslte::PDCP_SN_LEN_12, pool, log) == 0); /* * 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 */ - TESTASSERT(test_rx_in_sequence(262145, srslte::PDCP_SN_LEN_18, pool, log) == 0); + pdcp_initial_state test3_init_state = {}; + //TESTASSERT(test_rx_in_sequence(262145, normal_init_state, srslte::PDCP_SN_LEN_18, pool, log) == 0); /* * RX Test 4: PDCP Entity with SN LEN = 12 * Test Reception of one out-of-order packet. */ //TESTASSERT(test_rx_out_of_order(srslte::PDCP_SN_LEN_12, pool, log) == 0); - TESTASSERT(test_rx_out_of_order(2, srslte::PDCP_SN_LEN_12, pool, log) == 0); + //TESTASSERT(test_rx_out_of_order(2, srslte::PDCP_SN_LEN_12, pool, log) == 0); /* * RX Test 5: PDCP Entity with SN LEN = 12 * Test timeout of t-Reordering when one packet is lost. */ - TESTASSERT(test_rx_out_of_order_timeout(srslte::PDCP_SN_LEN_12, pool, log) == 0); + //TESTASSERT(test_rx_out_of_order_timeout(srslte::PDCP_SN_LEN_12, pool, log) == 0); /* * RX Test 5: PDCP Entity with SN LEN = 12 @@ -516,17 +530,17 @@ int run_all_tests(srslte::byte_buffer_pool* pool) log.set_hex_limit(128); // Helpers for generating expected PDUs - srslte::unique_byte_buffer_t sdu = srslte::allocate_unique_buffer(*pool); - sdu->append_bytes(sdu1, sizeof(sdu1)); - srslte::pdcp_config_t cfg_tx = {1, - srslte::PDCP_RB_IS_DRB, - srslte::SECURITY_DIRECTION_UPLINK, - srslte::SECURITY_DIRECTION_DOWNLINK, - srslte::PDCP_SN_LEN_18, - srslte::pdcp_t_reordering_t::ms500}; - gen_expected_pdu(std::move(sdu), 0, cfg_tx, sec_cfg, &log, pool); + // srslte::unique_byte_buffer_t sdu = srslte::allocate_unique_buffer(*pool); + // sdu->append_bytes(sdu1, sizeof(sdu1)); + // srslte::pdcp_config_t cfg_tx = {1, + // srslte::PDCP_RB_IS_DRB, + // srslte::SECURITY_DIRECTION_UPLINK, + // srslte::SECURITY_DIRECTION_DOWNLINK, + // srslte::PDCP_SN_LEN_18, + // srslte::pdcp_t_reordering_t::ms500}; + //gen_expected_pdu(std::move(sdu), 0, cfg_tx, sec_cfg, &log, pool); //TESTASSERT(test_tx_all(pool, &log) == 0); - //TESTASSERT(test_rx_all(pool, &log) == 0); + TESTASSERT(test_rx_all(pool, &log) == 0); return 0; } diff --git a/lib/test/upper/pdcp_nr_test.h b/lib/test/upper/pdcp_nr_test.h index 91e152753..5db303e7f 100644 --- a/lib/test/upper/pdcp_nr_test.h +++ b/lib/test/upper/pdcp_nr_test.h @@ -62,6 +62,13 @@ struct pdcp_security_cfg { srslte::CIPHERING_ALGORITHM_ID_ENUM enc_algo; }; +struct pdcp_initial_state { + uint32_t tx_next; + uint32_t rx_next; + uint32_t rx_deliv; + uint32_t rx_reord; +}; + // dummy classes class rlc_dummy : public srsue::rlc_interface_pdcp { @@ -149,6 +156,13 @@ public: pdcp.enable_encryption(); } + void set_pdcp_initial_state(pdcp_initial_state init_state) { + 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); + } + srslte::pdcp_entity_nr pdcp; rlc_dummy rlc; rrc_dummy rrc;