From eb1470621a386a43e001357205903956a8fd8e6e Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 11 Oct 2019 12:39:19 +0100 Subject: [PATCH] Added function to generate vector of PDUs --- lib/test/upper/pdcp_nr_test.cc | 92 +++++++++++++++++++--------------- lib/test/upper/pdcp_nr_test.h | 42 ++++++++++------ 2 files changed, 77 insertions(+), 57 deletions(-) diff --git a/lib/test/upper/pdcp_nr_test.cc b/lib/test/upper/pdcp_nr_test.cc index 34f405bc5..1e76b35de 100644 --- a/lib/test/upper/pdcp_nr_test.cc +++ b/lib/test/upper/pdcp_nr_test.cc @@ -19,6 +19,7 @@ * */ #include "pdcp_nr_test.h" +#include // Encryption and Integrity Keys uint8_t k_int[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, @@ -424,60 +425,69 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log) */ int test_rx_all(srslte::byte_buffer_pool* pool, srslte::log* log) { + // Test SDUs + srslte::unique_byte_buffer_t tst_sdu1 = allocate_unique_buffer(*pool); // SDU 1 + tst_sdu1->append_bytes(sdu1, sizeof(sdu1)); + srslte::unique_byte_buffer_t tst_sdu2 = allocate_unique_buffer(*pool); // SDU 2 + 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) */ - TESTASSERT(test_rx_in_sequence(4096, normal_init_state, srslte::PDCP_SN_LEN_12, 4097, pool, log) == 0); + std::vector test1_counts(2); // Test two packets + std::iota(test1_counts.begin(), test1_counts.end(), 4095); // Starting at COUNT 4095 + std::vector test1_exp_pdus = gen_expected_pdus_vector(tst_sdu1, test1_counts, srslte::PDCP_SN_LEN_12, sec_cfg, pool, log); + pdcp_initial_state test1_init_state = {.tx_next = 4095, .rx_next = 4095, .rx_deliv = 4095, .rx_reord = 0}; + TESTASSERT(test_rx_in_sequence(4096, test1_init_state, srslte::PDCP_SN_LEN_12, 2, 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 - * Packet that wraparound should be dropped, so only one packet should be received at the GW. - */ - TESTASSERT(test_rx_in_sequence(4294967296, near_wraparound_init_state, srslte::PDCP_SN_LEN_12, 1, 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 + * Packet that wraparound should be dropped, so only one packet should be received at the GW. + */ + TESTASSERT(test_rx_in_sequence(4294967296, near_wraparound_init_state, srslte::PDCP_SN_LEN_12, 1, 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 (SN LEN 18) - */ - TESTASSERT(test_rx_in_sequence(262144, normal_init_state, srslte::PDCP_SN_LEN_18, 262146, 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 (SN LEN 18) + */ + TESTASSERT(test_rx_in_sequence(262144, normal_init_state, srslte::PDCP_SN_LEN_18, 262146, pool, log) == 0); - /* - * 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 - */ - TESTASSERT(test_rx_in_sequence(4294967296, near_wraparound_init_state, srslte::PDCP_SN_LEN_18, 2, pool, log) == 0); + /* + * 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 + */ + TESTASSERT(test_rx_in_sequence(4294967296, near_wraparound_init_state, srslte::PDCP_SN_LEN_18, 2, pool, log) == 0); - /* - * RX Test 5: PDCP Entity with SN LEN = 12 - * Test Reception of one out-of-order packet. - */ - TESTASSERT(test_rx_out_of_order(normal_init_state, srslte::PDCP_SN_LEN_12, pool, log) == 0); + /* + * RX Test 5: PDCP Entity with SN LEN = 12 + * Test Reception of one out-of-order packet. + */ + TESTASSERT(test_rx_out_of_order(normal_init_state, srslte::PDCP_SN_LEN_12, pool, log) == 0); - /* - * RX Test 6: PDCP Entity with SN LEN = 12 - * Test Reception of one out-of-order packet at COUNT wraparound. - */ - TESTASSERT(test_rx_out_of_order(near_wraparound_init_state, srslte::PDCP_SN_LEN_12, pool, log) == 0); + /* + * RX Test 6: PDCP Entity with SN LEN = 12 + * Test Reception of one out-of-order packet at COUNT wraparound. + */ + TESTASSERT(test_rx_out_of_order(near_wraparound_init_state, 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); + /* + * 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); - /* - * 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(4294967297, srslte::PDCP_SN_LEN_12, pool, log) == 0); - return 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(4294967297, srslte::PDCP_SN_LEN_12, pool, log) == 0); + return 0; } // Setup all tests diff --git a/lib/test/upper/pdcp_nr_test.h b/lib/test/upper/pdcp_nr_test.h index cc5d504e0..64b0820ac 100644 --- a/lib/test/upper/pdcp_nr_test.h +++ b/lib/test/upper/pdcp_nr_test.h @@ -173,14 +173,21 @@ public: srslte::timers timers; }; -// Helper function to generate PDUs -void gen_expected_pdu(srslte::unique_byte_buffer_t in_sdu, - uint32_t count, - srslte::pdcp_config_t cfg, - pdcp_security_cfg sec_cfg, - srslte::log* log, - srslte::byte_buffer_pool* pool) +// Helper function to generate PDUs +srslte::unique_byte_buffer_t gen_expected_pdu(const srslte::unique_byte_buffer_t& in_sdu, + uint32_t count, + uint8_t pdcp_sn_len, + pdcp_security_cfg sec_cfg, + srslte::byte_buffer_pool* pool, + srslte::log* log) { + srslte::pdcp_config_t cfg = {1, + srslte::PDCP_RB_IS_DRB, + srslte::SECURITY_DIRECTION_DOWNLINK, + srslte::SECURITY_DIRECTION_UPLINK, + pdcp_sn_len, + srslte::pdcp_t_reordering_t::ms500}; + pdcp_nr_test_helper pdcp_hlp(cfg, sec_cfg, log); srslte::pdcp_entity_nr* pdcp = &pdcp_hlp.pdcp; rlc_dummy* rlc = &pdcp_hlp.rlc; @@ -189,25 +196,28 @@ void gen_expected_pdu(srslte::unique_byte_buffer_t in_sdu, init_state.tx_next = count; pdcp_hlp.set_pdcp_initial_state(init_state); - // for (uint32_t i = 0; i <= count; ++i) { srslte::unique_byte_buffer_t sdu = srslte::allocate_unique_buffer(*pool); *sdu = *in_sdu; pdcp->write_sdu(std::move(sdu), true); - //} srslte::unique_byte_buffer_t out_pdu = srslte::allocate_unique_buffer(*pool); rlc->get_last_sdu(out_pdu); - print_packet_array(out_pdu); + + return std::move(out_pdu); } // Helper function to generate vector of PDU from a vector of TX_NEXTs for generating expected pdus -void gen_expected_pdus_vector(const std::vector& tx_nexts, - std::vector& pdu_vec, - srslte::byte_buffer_pool* pool) +std::vector gen_expected_pdus_vector(const srslte::unique_byte_buffer_t& in_sdu, + const std::vector& tx_nexts, + uint8_t pdcp_sn_len, + pdcp_security_cfg sec_cfg, + srslte::byte_buffer_pool* pool, + srslte::log* log) { + std::vector pdu_vec; for (uint32_t tx_next : tx_nexts) { - srslte::unique_byte_byffer_t pdu = srslte::allocate_byte_buffer(*pool); - gen_expected_pdu(tx_next, pdu); - pdu_vec.push_back(pdu); + srslte::unique_byte_buffer_t pdu = gen_expected_pdu(in_sdu, tx_next, pdcp_sn_len, sec_cfg, pool, log); + pdu_vec.push_back(std::move(pdu)); } + return pdu_vec; } #endif // SRSLTE_PDCP_NR_TEST_H