From 7f98101f30f92ff8b6cf1d4423af1ca5631e4b8f Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 16 May 2022 15:09:10 +0100 Subject: [PATCH] lib,pdcp_nr: fix rx unit tests --- lib/src/pdcp/pdcp_entity_nr.cc | 9 ++++++++- lib/test/pdcp/pdcp_nr_test.h | 4 ++-- lib/test/pdcp/pdcp_nr_test_rx.cc | 25 ++++++++++++++++++++----- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/src/pdcp/pdcp_entity_nr.cc b/lib/src/pdcp/pdcp_entity_nr.cc index b568d1561..ac72095ab 100644 --- a/lib/src/pdcp/pdcp_entity_nr.cc +++ b/lib/src/pdcp/pdcp_entity_nr.cc @@ -176,10 +176,16 @@ void pdcp_entity_nr::write_pdu(unique_byte_buffer_t pdu) srsran_direction_text[integrity_direction], srsran_direction_text[encryption_direction]); + if (rx_overflow) { + logger.warning("Rx PDCP COUNTs have overflowed. Discarding SDU."); + return; + } + // Sanity check if (pdu->N_bytes <= cfg.hdr_len_bytes) { return; } + logger.debug("Rx PDCP state - RX_NEXT=%u, RX_DELIV=%u, RX_REORD=%u", rx_next, rx_deliv, rx_reord); // Extract RCVD_SN from header uint32_t rcvd_sn = read_data_header(pdu); @@ -195,7 +201,7 @@ void pdcp_entity_nr::write_pdu(unique_byte_buffer_t pdu) } rcvd_count = COUNT(rcvd_hfn, rcvd_sn); - logger.debug("RCVD_HFN=%u, RCVD_SN=%u, RCVD_COUNT=%u", rcvd_hfn, rcvd_sn, rcvd_count); + logger.debug("Estimated RCVD_HFN=%u, RCVD_SN=%u, RCVD_COUNT=%u", rcvd_hfn, rcvd_sn, rcvd_count); // TS 38.323, section 5.8: Deciphering // The data unit that is ciphered is the MAC-I and the @@ -265,6 +271,7 @@ void pdcp_entity_nr::write_pdu(unique_byte_buffer_t pdu) rx_reord = rx_next; reordering_timer.run(); } + logger.debug("Rx PDCP state - RX_NEXT=%u, RX_DELIV=%u, RX_REORD=%u", rx_next, rx_deliv, rx_reord); } // Notification of delivery/failure diff --git a/lib/test/pdcp/pdcp_nr_test.h b/lib/test/pdcp/pdcp_nr_test.h index 40aa89674..a852287b2 100644 --- a/lib/test/pdcp/pdcp_nr_test.h +++ b/lib/test/pdcp/pdcp_nr_test.h @@ -67,8 +67,8 @@ uint8_t pdu1_count262144_snlen18[] = {0x80, 0x00, 0x00, 0xc2, 0x47, 0xc2, 0x uint8_t pdu1_count4294967295_snlen18[] = {0x83, 0xff, 0xff, 0x1e, 0x47, 0x78, 0xb8, 0x7a, 0x9f}; // 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}; +uint8_t pdu2_count1_snlen12[] = {0x80, 0x01, 0x5e, 0x3d, 0x70, 0x6a, 0xa4, 0x90}; +uint8_t pdu2_count1_snlen18[] = {0x80, 0x00, 0x01, 0x5e, 0x3d, 0x93, 0xfe, 0xcc, 0x2e}; // This is the normal initial state. All state variables are set to zero pdcp_initial_state normal_init_state = {}; diff --git a/lib/test/pdcp/pdcp_nr_test_rx.cc b/lib/test/pdcp/pdcp_nr_test_rx.cc index 3f5397f3a..cdccf5653 100644 --- a/lib/test/pdcp/pdcp_nr_test_rx.cc +++ b/lib/test/pdcp/pdcp_nr_test_rx.cc @@ -49,7 +49,7 @@ int test_rx(std::vector events, } // Test if the number of RX packets - TESTASSERT(gw_rx->rx_count == n_sdus_exp); + TESTASSERT_EQ(gw_rx->rx_count, n_sdus_exp); srsran::unique_byte_buffer_t sdu_act = srsran::make_byte_buffer(); gw_rx->get_last_pdu(sdu_act); TESTASSERT(compare_two_packets(sdu_exp, sdu_act) == 0); @@ -74,7 +74,9 @@ int test_rx_all(srslog::basic_logger& logger) * This tests correct handling of HFN in the case of SN wraparound (SN LEN 12) */ { - std::vector test1_counts(2); // Test two packets + auto& test_logger = srslog::fetch_basic_logger("TESTER "); + srsran::test_delimit_logger delimiter("RX COUNT [4095,4096], 12 bit SN"); + std::vector test1_counts(2); // Test two packets std::iota(test1_counts.begin(), test1_counts.end(), 4095); // Starting at COUNT 4095 std::vector test1_pdus = gen_expected_pdus_vector(tst_sdu1, test1_counts, srsran::PDCP_SN_LEN_12, sec_cfg, logger); @@ -88,7 +90,9 @@ int test_rx_all(srslog::basic_logger& logger) * Packet that wraparound should be dropped, so only one packet should be received at the GW. */ { - std::vector test2_counts(2); // Test two packets + auto& test_logger = srslog::fetch_basic_logger("TESTER "); + srsran::test_delimit_logger delimiter("RX COUNT [4294967295,0], 12 bit SN"); + std::vector test2_counts(2); // Test two packets std::iota(test2_counts.begin(), test2_counts.end(), 4294967295); // Starting at COUNT 4294967295 std::vector test2_pdus = gen_expected_pdus_vector(tst_sdu1, test2_counts, srsran::PDCP_SN_LEN_12, sec_cfg, logger); @@ -102,7 +106,9 @@ int test_rx_all(srslog::basic_logger& logger) * This tests correct handling of HFN in the case of SN wraparound (SN LEN 18) */ { - std::vector test3_counts(2); // Test two packets + auto& test_logger = srslog::fetch_basic_logger("TESTER "); + srsran::test_delimit_logger delimiter("RX COUNT [262144,262145], 12 bit SN"); + std::vector test3_counts(2); // Test two packets std::iota(test3_counts.begin(), test3_counts.end(), 262144); // Starting at COUNT 262144 std::vector test3_pdus = gen_expected_pdus_vector(tst_sdu1, test3_counts, srsran::PDCP_SN_LEN_18, sec_cfg, logger); @@ -116,7 +122,9 @@ int test_rx_all(srslog::basic_logger& logger) * This tests correct handling of COUNT in the case of [HFN|SN] wraparound */ { - std::vector test4_counts(2); // Test two packets + auto& test_logger = srslog::fetch_basic_logger("TESTER "); + srsran::test_delimit_logger delimiter("RX COUNT [4294967295,4294967296], 18 bit SN"); + std::vector test4_counts(2); // Test two packets std::iota(test4_counts.begin(), test4_counts.end(), 4294967295); // Starting at COUNT 4294967295 std::vector test4_pdus = gen_expected_pdus_vector(tst_sdu1, test4_counts, srsran::PDCP_SN_LEN_18, sec_cfg, logger); @@ -130,6 +138,8 @@ int test_rx_all(srslog::basic_logger& logger) * Test reception of two out-of-order packets, starting at COUNT 0. */ { + auto& test_logger = srslog::fetch_basic_logger("TESTER "); + srsran::test_delimit_logger delimiter("RX out-of-order COUNT [1,0], 12 bit SN"); std::vector test5_pdus; pdcp_initial_state test5_init_state = {}; @@ -154,6 +164,8 @@ int test_rx_all(srslog::basic_logger& logger) * Test reception of two out-of-order packets, starting at COUNT 0. */ { + auto& test_logger = srslog::fetch_basic_logger("TESTER "); + srsran::test_delimit_logger delimiter("RX out-of-order COUNT [1,0], 18 bit SN"); std::vector test6_pdus; pdcp_initial_state test6_init_state = {}; @@ -178,6 +190,8 @@ int test_rx_all(srslog::basic_logger& logger) * Test Reception of one out-of-order packet. */ { + auto& test_logger = srslog::fetch_basic_logger("TESTER "); + srsran::test_delimit_logger delimiter("RX out-of-order COUNT [1,0] t_reordering expired, 12 bit SN"); std::vector test7_pdus; pdcp_initial_state test7_init_state = {}; @@ -197,6 +211,7 @@ int test_rx_all(srslog::basic_logger& logger) * Test reception of two duplicate PDUs, with COUNT 0. */ { + srsran::test_delimit_logger delimiter("RX duplicate COUNTs [0,0], 12 bit SN"); std::vector test8_pdus; pdcp_initial_state test8_init_state = {};