From 8511fca9404ce422e682444aa52a2d572bf7783c Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 14 Oct 2019 17:39:02 +0100 Subject: [PATCH] Clang-formated to prepare for PR --- lib/include/srslte/common/common.h | 14 +- lib/include/srslte/common/interfaces_common.h | 64 +++-- lib/include/srslte/upper/pdcp_entity_nr.h | 3 +- lib/src/upper/pdcp_entity_nr.cc | 24 +- lib/test/upper/pdcp_nr_test.cc | 249 +++++++++--------- lib/test/upper/pdcp_nr_test.h | 25 +- 6 files changed, 187 insertions(+), 192 deletions(-) diff --git a/lib/include/srslte/common/common.h b/lib/include/srslte/common/common.h index 83bea8dbe..2fd9d6dbf 100644 --- a/lib/include/srslte/common/common.h +++ b/lib/include/srslte/common/common.h @@ -34,13 +34,13 @@ DEFINES *******************************************************************************/ -#define SRSLTE_UE_CATEGORY 4 +#define SRSLTE_UE_CATEGORY 4 -#define SRSLTE_N_SRB 3 -#define SRSLTE_N_DRB 8 +#define SRSLTE_N_SRB 3 +#define SRSLTE_N_DRB 8 #define SRSLTE_N_RADIO_BEARERS 11 -#define SRSLTE_N_MCH_LCIDS 32 +#define SRSLTE_N_MCH_LCIDS 32 #define TX_DELAY 4 #define MSG3_DELAY_MS 2 // Delay added to TX_DELAY @@ -56,7 +56,7 @@ #define TTI_RX_ACK(tti) (TTI_ADD(tti, FDD_HARQ_DELAY_MS + TX_DELAY)) #define TTIMOD_SZ 20 -#define TTIMOD(tti) (tti%TTIMOD_SZ) +#define TTIMOD(tti) (tti % TTIMOD_SZ) #define PHICH_MAX_SF 6 // Maximum PHICH in a subframe (1 in FDD, > 1 in TDD, see table 9.1.2-1 36.213) @@ -65,7 +65,7 @@ // Cat 4 UE - Max number of DL-SCH transport block bits received within a TTI // 3GPP 36.306 v15.4.0 Table 4.1.1 for Category 11 with 2 layers and 256QAM #define SRSLTE_MAX_TBSIZE_BITS 97896 -#define SRSLTE_BUFFER_HEADER_OFFSET 1020 +#define SRSLTE_BUFFER_HEADER_OFFSET 1020 #define SRSLTE_MAX_BUFFER_SIZE_BITS (SRSLTE_MAX_TBSIZE_BITS + SRSLTE_BUFFER_HEADER_OFFSET) #define SRSLTE_MAX_BUFFER_SIZE_BYTES (SRSLTE_MAX_TBSIZE_BITS / 8 + SRSLTE_BUFFER_HEADER_OFFSET) @@ -172,7 +172,7 @@ public: #endif } - void append_bytes(uint8_t *buf, uint32_t size) + void append_bytes(uint8_t* buf, uint32_t size) { memcpy(&msg[N_bytes], buf, size); N_bytes += size; diff --git a/lib/include/srslte/common/interfaces_common.h b/lib/include/srslte/common/interfaces_common.h index f89100d70..604b131de 100644 --- a/lib/include/srslte/common/interfaces_common.h +++ b/lib/include/srslte/common/interfaces_common.h @@ -22,8 +22,8 @@ #ifndef SRSLTE_INTERFACES_COMMON_H #define SRSLTE_INTERFACES_COMMON_H -#include "srslte/common/timers.h" #include "srslte/common/security.h" +#include "srslte/common/timers.h" #include namespace srslte { @@ -60,9 +60,7 @@ typedef struct { class srslte_gw_config_t { public: - srslte_gw_config_t(uint32_t lcid_ = 0) - :lcid(lcid_) - {} + srslte_gw_config_t(uint32_t lcid_ = 0) : lcid(lcid_) {} uint32_t lcid; }; @@ -79,33 +77,33 @@ const uint8_t PDCP_SN_LEN_18 = 18; typedef enum { PDCP_RB_IS_SRB, PDCP_RB_IS_DRB } pdcp_rb_type_t; enum class pdcp_t_reordering_t { - ms0 = 0, - ms1 = 1, - ms2 = 2, - ms4 = 4, - ms5 = 5, - ms8 = 8, - ms10 = 10, - ms15 = 15, - ms20 = 20, - ms30 = 30, - ms40 = 40, - ms50 = 50, - ms60 = 60, - ms80 = 80, - ms100 = 100, - ms120 = 120, - ms140 = 140, - ms160 = 160, - ms180 = 180, - ms200 = 200, - ms220 = 220, - ms240 = 240, - ms260 = 260, - ms280 = 280, - ms300 = 300, - ms500 = 500, - ms750 = 750, + ms0 = 0, + ms1 = 1, + ms2 = 2, + ms4 = 4, + ms5 = 5, + ms8 = 8, + ms10 = 10, + ms15 = 15, + ms20 = 20, + ms30 = 30, + ms40 = 40, + ms50 = 50, + ms60 = 60, + ms80 = 80, + ms100 = 100, + ms120 = 120, + ms140 = 140, + ms160 = 160, + ms180 = 180, + ms200 = 200, + ms220 = 220, + ms240 = 240, + ms260 = 260, + ms280 = 280, + ms300 = 300, + ms500 = 500, + ms750 = 750, ms1000 = 1000, ms1250 = 1250, ms1500 = 1500, @@ -153,9 +151,9 @@ public: class read_pdu_interface { public: - virtual int read_pdu(uint32_t lcid, uint8_t *payload, uint32_t requested_bytes) = 0; + virtual int read_pdu(uint32_t lcid, uint8_t* payload, uint32_t requested_bytes) = 0; }; -} +} // namespace srslte #endif // SRSLTE_INTERFACES_COMMON_H diff --git a/lib/include/srslte/upper/pdcp_entity_nr.h b/lib/include/srslte/upper/pdcp_entity_nr.h index 48ab06d5a..6eef88e1d 100644 --- a/lib/include/srslte/upper/pdcp_entity_nr.h +++ b/lib/include/srslte/upper/pdcp_entity_nr.h @@ -108,12 +108,13 @@ private: /* * Timer callbacks */ -// Reordering callback (t-Reordering) +// Reordering callback (t-Reordering) class pdcp_entity_nr::reordering_callback : public timer_callback { public: reordering_callback(pdcp_entity_nr* parent_) { parent = parent_; }; virtual void timer_expired(uint32_t timer_id) final; + private: pdcp_entity_nr* parent; }; diff --git a/lib/src/upper/pdcp_entity_nr.cc b/lib/src/upper/pdcp_entity_nr.cc index 53731cd2d..3e969cf37 100644 --- a/lib/src/upper/pdcp_entity_nr.cc +++ b/lib/src/upper/pdcp_entity_nr.cc @@ -88,7 +88,7 @@ void pdcp_entity_nr::write_sdu(unique_byte_buffer_t sdu, bool blocking) return; } if (tx_next + 1 == 0) { - tx_overflow = true; + tx_overflow = true; } // Start discard timer TODO @@ -169,7 +169,7 @@ void pdcp_entity_nr::write_pdu(unique_byte_buffer_t pdu) // Check if PDU has been received if (reorder_queue.find(rcvd_count) != reorder_queue.end()) { - return; // PDU already present, drop. + return; // PDU already present, drop. } // Store PDU in reception buffer @@ -188,10 +188,10 @@ void pdcp_entity_nr::write_pdu(unique_byte_buffer_t pdu) } // Handle reordering timers - if(reordering_timer->is_running() and rx_deliv >= rx_reord){ + if (reordering_timer->is_running() and rx_deliv >= rx_reord) { reordering_timer->stop(); reordering_timer->reset(); - } + } if (not reordering_timer->is_running() and rx_deliv < rx_next) { rx_reord = rx_next; @@ -293,9 +293,8 @@ void pdcp_entity_nr::append_mac(const unique_byte_buffer_t& sdu, uint8_t* mac) void pdcp_entity_nr::deliver_all_consecutive_counts() { for (std::map::iterator it = reorder_queue.begin(); - it != reorder_queue.end() && it->first == rx_deliv; - reorder_queue.erase(it++)) - { + it != reorder_queue.end() && it->first == rx_deliv; + reorder_queue.erase(it++)) { log->debug("Delivering SDU with RCVD_COUNT %" PRIu32 "\n", it->first); // Check RX_DELIV overflow @@ -304,15 +303,14 @@ void pdcp_entity_nr::deliver_all_consecutive_counts() return; } if (rx_deliv + 1 == 0) { - rx_overflow = true; + rx_overflow = true; } // Pass PDCP SDU to the next layers pass_to_upper_layers(std::move(it->second)); // Update RX_DELIV - rx_deliv = rx_deliv + 1; - + rx_deliv = rx_deliv + 1; } } @@ -324,14 +322,14 @@ void pdcp_entity_nr::reordering_callback::timer_expired(uint32_t timer_id) for (std::map::iterator it = parent->reorder_queue.begin(); it != parent->reorder_queue.end() && it->first < parent->rx_reord; parent->reorder_queue.erase(it++)) { - // Deliver to upper layers - parent->pass_to_upper_layers(std::move(it->second)); + // Deliver to upper layers + parent->pass_to_upper_layers(std::move(it->second)); } // Deliver all PDCP SDU(s) consecutivly associeted COUNT value(s) starting from RX_REORD parent->deliver_all_consecutive_counts(); - if (parent->rx_deliv < parent->rx_next){ + if (parent->rx_deliv < parent->rx_next) { parent->rx_reord = parent->rx_next; parent->reordering_timer->run(); } diff --git a/lib/test/upper/pdcp_nr_test.cc b/lib/test/upper/pdcp_nr_test.cc index e1b8280dd..5e4259805 100644 --- a/lib/test/upper/pdcp_nr_test.cc +++ b/lib/test/upper/pdcp_nr_test.cc @@ -37,25 +37,23 @@ pdcp_security_cfg sec_cfg = { srslte::CIPHERING_ALGORITHM_ID_128_EEA2, }; - // Test SDUs for tx uint8_t sdu1[] = {0x18, 0xe2}; uint8_t sdu2[] = {0xde, 0xad}; // Test PDUs for rx (generated from SDU1) -uint8_t pdu1_count0_snlen12[] = {0x80, 0x00, 0x8f, 0xe3, 0xe0, 0xdf, 0x82, 0x92}; -uint8_t pdu1_count2048_snlen12[] = {0x88, 0x00, 0x8d, 0x2c, 0x47, 0x5e, 0xb1, 0x5b}; -uint8_t pdu1_count4096_snlen12[] = {0x80, 0x00, 0x97, 0xbe, 0xa3, 0x32, 0xfa, 0x61}; +uint8_t pdu1_count0_snlen12[] = {0x80, 0x00, 0x8f, 0xe3, 0xe0, 0xdf, 0x82, 0x92}; +uint8_t pdu1_count2048_snlen12[] = {0x88, 0x00, 0x8d, 0x2c, 0x47, 0x5e, 0xb1, 0x5b}; +uint8_t pdu1_count4096_snlen12[] = {0x80, 0x00, 0x97, 0xbe, 0xa3, 0x32, 0xfa, 0x61}; uint8_t pdu1_count4294967295_snlen12[] = {0x8f, 0xff, 0x1e, 0x47, 0xe6, 0x86, 0x28, 0x6c}; -uint8_t pdu1_count0_snlen18[] = {0x80, 0x00, 0x00, 0x8f, 0xe3, 0xe0, 0xdf, 0x82, 0x92}; -uint8_t pdu1_count131072_snlen18[] = {0x82, 0x00, 0x00, 0x15, 0x01, 0xf4, 0xb0, 0xfc, 0xc5}; -uint8_t pdu1_count262144_snlen18[] = {0x80, 0x00, 0x00, 0xc2, 0x47, 0xa8, 0xdd, 0xc0, 0x73}; +uint8_t pdu1_count0_snlen18[] = {0x80, 0x00, 0x00, 0x8f, 0xe3, 0xe0, 0xdf, 0x82, 0x92}; +uint8_t pdu1_count131072_snlen18[] = {0x82, 0x00, 0x00, 0x15, 0x01, 0xf4, 0xb0, 0xfc, 0xc5}; +uint8_t pdu1_count262144_snlen18[] = {0x80, 0x00, 0x00, 0xc2, 0x47, 0xa8, 0xdd, 0xc0, 0x73}; uint8_t pdu1_count4294967295_snlen18[] = {0x83, 0xff, 0xff, 0x1e, 0x47, 0xe6, 0x86, 0x28, 0x6c}; // Test PDUs for rx (generated from SDU2) uint8_t pdu2_count1_snlen12[] = {0x80, 0x01, 0x5e, 0x3d, 0x64, 0xaf, 0xac, 0x7c}; - // This is the normal initial state. All state variables are set to zero pdcp_initial_state normal_init_state = {}; @@ -75,7 +73,7 @@ int test_tx(uint32_t n_packets, srslte::byte_buffer_pool* pool, srslte::log* log) { - srslte::pdcp_config_t cfg = {1, + srslte::pdcp_config_t cfg = {1, srslte::PDCP_RB_IS_DRB, srslte::SECURITY_DIRECTION_UPLINK, srslte::SECURITY_DIRECTION_DOWNLINK, @@ -116,7 +114,7 @@ int test_rx_in_sequence(std::vector pdus, { - srslte::pdcp_config_t cfg_rx = {1, + srslte::pdcp_config_t cfg_rx = {1, srslte::PDCP_RB_IS_DRB, srslte::SECURITY_DIRECTION_DOWNLINK, srslte::SECURITY_DIRECTION_UPLINK, @@ -137,13 +135,13 @@ int test_rx_in_sequence(std::vector pdus, for (srslte::unique_byte_buffer_t& pdu : pdus) { srslte::unique_byte_buffer_t sdu = allocate_unique_buffer(*pool); sdu->append_bytes(sdu_exp->msg, sdu_exp->N_bytes); - + // Decript and integrity check the PDU pdcp_rx->write_pdu(std::move(pdu)); gw_rx->get_last_pdu(sdu_act); // Check if resulting SDU matches original SDU - TESTASSERT(compare_two_packets(sdu_exp,sdu_act) == 0); + TESTASSERT(compare_two_packets(sdu_exp, sdu_act) == 0); } // Test if the number of RX packets @@ -154,17 +152,20 @@ int test_rx_in_sequence(std::vector pdus, /* * Genric function to test reception of a single out-of-order packet */ -int test_rx_out_of_order(pdcp_initial_state init_state, uint8_t pdcp_sn_len, srslte::byte_buffer_pool* pool, srslte::log* log) +int test_rx_out_of_order(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, + srslte::pdcp_config_t cfg_tx = {1, srslte::PDCP_RB_IS_DRB, srslte::SECURITY_DIRECTION_UPLINK, srslte::SECURITY_DIRECTION_DOWNLINK, pdcp_sn_len, srslte::pdcp_t_reordering_t::ms500}; - srslte::pdcp_config_t cfg_rx = {1, + srslte::pdcp_config_t cfg_rx = {1, srslte::PDCP_RB_IS_DRB, srslte::SECURITY_DIRECTION_DOWNLINK, srslte::SECURITY_DIRECTION_UPLINK, @@ -181,7 +182,7 @@ int test_rx_out_of_order(pdcp_initial_state init_state, uint8_t pdcp_sn_len, srs pdcp_hlp_tx.set_pdcp_initial_state(init_state); pdcp_hlp_rx.set_pdcp_initial_state(init_state); - + // Allocate buffers for later comparison. srslte::unique_byte_buffer_t sdu_act = allocate_unique_buffer(*pool); srslte::unique_byte_buffer_t sdu_exp = allocate_unique_buffer(*pool); @@ -201,7 +202,7 @@ int test_rx_out_of_order(pdcp_initial_state init_state, uint8_t pdcp_sn_len, srs srslte::unique_byte_buffer_t tx_pdu_out2 = allocate_unique_buffer(*pool); rlc_tx->get_last_sdu(tx_pdu_out2); - + // Write PDUs out-of-order into rx entity to see if re-ordering is OK. pdcp_rx->write_pdu(std::move(tx_pdu_out2)); pdcp_rx->write_pdu(std::move(tx_pdu_out1)); @@ -221,7 +222,7 @@ int test_rx_out_of_order(pdcp_initial_state init_state, uint8_t pdcp_sn_len, srs */ int test_rx_out_of_order_timeout(uint8_t pdcp_sn_len, srslte::byte_buffer_pool* pool, srslte::log* log) { - srslte::pdcp_config_t cfg_rx = {1, + srslte::pdcp_config_t cfg_rx = {1, srslte::PDCP_RB_IS_DRB, srslte::SECURITY_DIRECTION_DOWNLINK, srslte::SECURITY_DIRECTION_UPLINK, @@ -248,7 +249,7 @@ int test_rx_out_of_order_timeout(uint8_t pdcp_sn_len, srslte::byte_buffer_pool* TESTASSERT(gw_rx->rx_count == 0); // Trigger timer - for (uint16_t i = 0; i < 500; ++i){ + for (uint16_t i = 0; i < 500; ++i) { timers->step_all(); } @@ -272,7 +273,7 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log) * Input: {0x18, 0xE2} * Output: PDCP Header {0x80, 0x00}, Ciphered Text {0x8f, 0xe3}, MAC-I {0xe0, 0xdf, 0x82, 0x92} */ - n_packets = 1; + n_packets = 1; srslte::unique_byte_buffer_t pdu_exp_count0_len12 = allocate_unique_buffer(*pool); pdu_exp_count0_len12->append_bytes(pdu1_count0_snlen12, sizeof(pdu1_count0_snlen12)); TESTASSERT(test_tx(n_packets, @@ -289,7 +290,7 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log) * Input: {0x18, 0xE2} * Output: PDCP Header {0x88, 0x00}, Ciphered Text {0x8d, 0x2c}, MAC-I {0x47, 0x5e, 0xb1, 0x5b} */ - n_packets = 2049; + n_packets = 2049; srslte::unique_byte_buffer_t pdu_exp_count2048_len12 = allocate_unique_buffer(*pool); pdu_exp_count2048_len12->append_bytes(pdu1_count2048_snlen12, sizeof(pdu1_count2048_snlen12)); TESTASSERT(test_tx(n_packets, @@ -306,7 +307,7 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log) * Input: {0x18, 0xE2} * Output: PDCP Header {0x80,0x00}, Ciphered Text {0x97, 0xbe}, MAC-I {0xa3, 0x32, 0xfa, 0x61} */ - n_packets = 4097; + n_packets = 4097; srslte::unique_byte_buffer_t pdu_exp_count4096_len12 = allocate_unique_buffer(*pool); pdu_exp_count4096_len12->append_bytes(pdu1_count4096_snlen12, sizeof(pdu1_count4096_snlen12)); TESTASSERT(test_tx(n_packets, @@ -323,7 +324,7 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log) * Input: {0x18, 0xE2} * Output: PDCP Header {0x80, 0x80, 0x00}, Ciphered Text {0x8f, 0xe3}, MAC-I {0xe0, 0xdf, 0x82, 0x92} */ - n_packets = 1; + n_packets = 1; srslte::unique_byte_buffer_t pdu_exp_count0_len18 = allocate_unique_buffer(*pool); pdu_exp_count0_len18->append_bytes(pdu1_count0_snlen18, sizeof(pdu1_count0_snlen18)); TESTASSERT(test_tx(n_packets, @@ -373,7 +374,7 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log) * Test TX at COUNT wraparound. * Should print a warning and drop all packets after wraparound. */ - n_packets = 5; + n_packets = 5; srslte::unique_byte_buffer_t pdu_exp_count4294967295_len12 = allocate_unique_buffer(*pool); pdu_exp_count4294967295_len12->append_bytes(pdu1_count4294967295_snlen12, sizeof(pdu1_count4294967295_snlen12)); TESTASSERT(test_tx(n_packets, @@ -389,7 +390,7 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log) * Test TX at COUNT wraparound. * Should print a warning and drop all packets after wraparound. */ - n_packets = 5; + n_packets = 5; srslte::unique_byte_buffer_t pdu_exp_count4294967295_len18 = allocate_unique_buffer(*pool); pdu_exp_count4294967295_len18->append_bytes(pdu1_count4294967295_snlen18, sizeof(pdu1_count4294967295_snlen18)); TESTASSERT(test_tx(n_packets, @@ -408,112 +409,108 @@ 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)); + // 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) */ - { - 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, 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(std::move(test1_pdus), 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. - */ - { - 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, srslte::PDCP_SN_LEN_12, sec_cfg, pool, log); - pdcp_initial_state test2_init_state = { - .tx_next = 4294967295, .rx_next = 4294967295, .rx_deliv = 4294967295, .rx_reord = 0}; - TESTASSERT(test_rx_in_sequence(std::move(test2_pdus), test2_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) - */ - { - 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, srslte::PDCP_SN_LEN_18, sec_cfg, pool, log); - pdcp_initial_state test3_init_state = {.tx_next = 262144, .rx_next = 262144, .rx_deliv = 262144, .rx_reord = 0}; - TESTASSERT(test_rx_in_sequence(std::move(test3_pdus), test3_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 - */ - { - 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, srslte::PDCP_SN_LEN_18, sec_cfg, pool, log); - pdcp_initial_state test4_init_state = {.tx_next = 4294967295, .rx_next = 4294967295, .rx_deliv = 4294967295, .rx_reord = 0}; - TESTASSERT(test_rx_in_sequence(std::move(test4_pdus), test4_init_state, srslte::PDCP_SN_LEN_18, 1, pool, log) == - 0); - } - - /* - * RX Test 5: PDCP Entity with SN LEN = 12 - * Test reception of two out-of-order packets, starting at COUNT 0. - */ - { - std::vector test5_pdus; - pdcp_initial_state test5_init_state = {}; - srslte::unique_byte_buffer_t pdu1 = srslte::allocate_unique_buffer(*pool); - srslte::unique_byte_buffer_t pdu2 = srslte::allocate_unique_buffer(*pool); - pdu1->append_bytes(pdu1_count0_snlen12, sizeof(pdu1_count0_snlen12)); - pdu2->append_bytes(pdu2_count1_snlen12, sizeof(pdu2_count1_snlen12)); - test5_pdus.push_back(std::move(pdu2)); - test5_pdus.push_back(std::move(pdu1)); - TESTASSERT(test_rx_in_sequence(std::move(test5_pdus), test5_init_state, srslte::PDCP_SN_LEN_12, 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 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(4294967297, srslte::PDCP_SN_LEN_12, pool, log) == 0); - return 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_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(std::move(test1_pdus), 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. + */ + { + 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, srslte::PDCP_SN_LEN_12, sec_cfg, pool, log); + pdcp_initial_state test2_init_state = { + .tx_next = 4294967295, .rx_next = 4294967295, .rx_deliv = 4294967295, .rx_reord = 0}; + TESTASSERT(test_rx_in_sequence(std::move(test2_pdus), test2_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) + */ + { + 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, srslte::PDCP_SN_LEN_18, sec_cfg, pool, log); + pdcp_initial_state test3_init_state = {.tx_next = 262144, .rx_next = 262144, .rx_deliv = 262144, .rx_reord = 0}; + TESTASSERT(test_rx_in_sequence(std::move(test3_pdus), test3_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 + */ + { + 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, srslte::PDCP_SN_LEN_18, sec_cfg, pool, log); + pdcp_initial_state test4_init_state = { + .tx_next = 4294967295, .rx_next = 4294967295, .rx_deliv = 4294967295, .rx_reord = 0}; + TESTASSERT(test_rx_in_sequence(std::move(test4_pdus), test4_init_state, srslte::PDCP_SN_LEN_18, 1, pool, log) == 0); + } + + /* + * RX Test 5: PDCP Entity with SN LEN = 12 + * Test reception of two out-of-order packets, starting at COUNT 0. + */ + { + std::vector test5_pdus; + pdcp_initial_state test5_init_state = {}; + srslte::unique_byte_buffer_t pdu1 = srslte::allocate_unique_buffer(*pool); + srslte::unique_byte_buffer_t pdu2 = srslte::allocate_unique_buffer(*pool); + pdu1->append_bytes(pdu1_count0_snlen12, sizeof(pdu1_count0_snlen12)); + pdu2->append_bytes(pdu2_count1_snlen12, sizeof(pdu2_count1_snlen12)); + test5_pdus.push_back(std::move(pdu2)); + test5_pdus.push_back(std::move(pdu1)); + TESTASSERT(test_rx_in_sequence(std::move(test5_pdus), test5_init_state, srslte::PDCP_SN_LEN_12, 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 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(4294967297, srslte::PDCP_SN_LEN_12, pool, log) == 0); + return 0; } // Setup all tests @@ -524,7 +521,7 @@ int run_all_tests(srslte::byte_buffer_pool* pool) log.set_level(srslte::LOG_LEVEL_DEBUG); log.set_hex_limit(128); - //TESTASSERT(test_tx_all(pool, &log) == 0); + // TESTASSERT(test_tx_all(pool, &log) == 0); TESTASSERT(test_rx_all(pool, &log) == 0); // Helpers for generating expected PDUs diff --git a/lib/test/upper/pdcp_nr_test.h b/lib/test/upper/pdcp_nr_test.h index 93a165eaf..551d249b2 100644 --- a/lib/test/upper/pdcp_nr_test.h +++ b/lib/test/upper/pdcp_nr_test.h @@ -45,19 +45,20 @@ int compare_two_packets(const srslte::unique_byte_buffer_t& msg1, const srslte:: return 0; } -void print_packet_array(const srslte::unique_byte_buffer_t &msg){ +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]); + for (uint64_t i = 0; i < msg->N_bytes; ++i) { + printf("0x%02x, ", msg->msg[i]); } printf("\n};\n"); } struct pdcp_security_cfg { - uint8_t *k_int_rrc; - uint8_t *k_enc_rrc; - uint8_t *k_int_up; - uint8_t *k_enc_up; + 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; }; @@ -88,7 +89,7 @@ public: rx_count++; } - uint64_t rx_count = 0; + uint64_t rx_count = 0; private: srslte::log* log; @@ -109,7 +110,6 @@ public: 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 @@ -142,7 +142,7 @@ private: * Helper classes to reduce copy / pasting in setting up tests */ -// PDCP helper to setup PDCP + Dummy +// PDCP helper to setup PDCP + Dummy class pdcp_nr_test_helper { public: @@ -159,7 +159,8 @@ public: pdcp.enable_encryption(); } - void set_pdcp_initial_state(pdcp_initial_state init_state) { + 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); @@ -193,7 +194,7 @@ srslte::unique_byte_buffer_t gen_expected_pdu(const srslte::unique_byte_buffer_t rlc_dummy* rlc = &pdcp_hlp.rlc; pdcp_initial_state init_state = {}; - init_state.tx_next = count; + init_state.tx_next = count; pdcp_hlp.set_pdcp_initial_state(init_state); srslte::unique_byte_buffer_t sdu = srslte::allocate_unique_buffer(*pool);