From ecd164ed658c44e39399d9171c33c2420872b436 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 17 Jul 2019 17:54:24 +0100 Subject: [PATCH] Starting to add more tx tests to PDCP NR tests. --- lib/src/upper/pdcp_entity_nr.cc | 8 +++-- lib/test/upper/pdcp_nr_test.cc | 63 +++++++++++++++++++++++++-------- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/lib/src/upper/pdcp_entity_nr.cc b/lib/src/upper/pdcp_entity_nr.cc index cdd1c6fb4..ae68e836e 100644 --- a/lib/src/upper/pdcp_entity_nr.cc +++ b/lib/src/upper/pdcp_entity_nr.cc @@ -89,6 +89,10 @@ void pdcp_entity_nr::write_sdu(unique_byte_buffer_t sdu, bool blocking) // Append MAC-I append_mac(sdu, mac); + // Increment TX_NEXT + tx_next++; + + // Check if PDCP is associated with more than on RLC entity TODO // Write to lower layers rlc->write_sdu(lcid, std::move(sdu), blocking); } @@ -194,14 +198,14 @@ void pdcp_entity_nr::write_data_header(const srslte::unique_byte_buffer_t& sdu, switch (cfg.sn_len) { case PDCP_SN_LEN_12: - srslte::uint16_to_uint8(0x3F & count, sdu->msg); + srslte::uint16_to_uint8(0x0FFF & count, sdu->msg); if (is_drb()) { sdu->msg[0] |= 0x80; // On DRB Data PDUs we must set the D flag. } break; case PDCP_SN_LEN_18: sdu->msg[0] = 0x80; // Data PDU and SN 18 implies DRB, D flag must be present - *sdu->msg = count & 0x3F; + *sdu->msg = count & 0x0FFF; break; default: log->error("Invalid SN length configuration: %d bits\n", cfg.sn_len); diff --git a/lib/test/upper/pdcp_nr_test.cc b/lib/test/upper/pdcp_nr_test.cc index 1fc298953..45a649406 100644 --- a/lib/test/upper/pdcp_nr_test.cc +++ b/lib/test/upper/pdcp_nr_test.cc @@ -115,14 +115,7 @@ private: srslte::unique_byte_buffer_t last_pdu; }; -/* - * Test 1: PDCP Entity TX - * Configure PDCP entity with EIA2 and EEA2 - * TX_NEXT initially at 0. - * Input: {0x18, 0xE2} - * Output: PDCP Header {0x80,0x00}, Ciphered Text {0x8f, 0xe3}, MAC-I {0xe0, 0xdf, 0x82, 0x92} - */ -int test_tx_basic(srslte::byte_buffer_pool* pool, srslte::log* log) +int test_tx(uint32_t n_packets, srslte::unique_byte_buffer_t pdu_exp, srslte::byte_buffer_pool* pool, srslte::log* log) { srslte::pdcp_entity_nr pdcp; srslte::srslte_pdcp_config_t cfg = {1, srslte::PDCP_RB_IS_DRB, SECURITY_DIRECTION_UPLINK, SECURITY_DIRECTION_DOWNLINK, srslte::PDCP_SN_LEN_12}; @@ -141,13 +134,15 @@ int test_tx_basic(srslte::byte_buffer_pool* pool, srslte::log* log) memcpy(sdu->msg, sdu1, SDU1_LEN); sdu->N_bytes = SDU1_LEN; - // Expected PDCP PDU - srslte::unique_byte_buffer_t pdu_exp = allocate_unique_buffer(*pool); - memcpy(pdu_exp->msg, pdu1, PDU1_LEN); - pdu_exp->N_bytes = PDU1_LEN; // Run test - pdcp.write_sdu(std::move(sdu), true); + for (uint32_t i = 0; i < n_packets; ++i) { + // Test SDU + srslte::unique_byte_buffer_t sdu = allocate_unique_buffer(*pool); + memcpy(sdu->msg, sdu1, SDU1_LEN); + sdu->N_bytes = SDU1_LEN; + pdcp.write_sdu(std::move(sdu), true); + } srslte::unique_byte_buffer_t pdu_act = allocate_unique_buffer(*pool); rlc.get_last_sdu(pdu_act); @@ -157,7 +152,6 @@ int test_tx_basic(srslte::byte_buffer_pool* pool, srslte::log* log) } return 0; } - /* * Test 2: PDCP Entity RX * Configure PDCP entity with EIA2 and EEA2 @@ -204,6 +198,45 @@ bool test_rx_basic(srslte::byte_buffer_pool* pool, srslte::log* log) return 0; } +int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log) +{ + /* + * TX Test 1: PDCP Entity with SN LEN = 12 + * PDCP entity configured with EIA2 and EEA2 + * TX_NEXT = 0. + * Input: {0x18, 0xE2} + * Output: PDCP Header {0x80,0x00}, Ciphered Text {0x8f, 0xe3}, MAC-I {0xe0, 0xdf, 0x82, 0x92} + */ + srslte::unique_byte_buffer_t pdu_exp_sn0 = allocate_unique_buffer(*pool); + memcpy(pdu_exp_sn0->msg, pdu1, PDU1_LEN); + pdu_exp_sn0->N_bytes = PDU1_LEN; + TESTASSERT(test_tx(1, std::move(pdu_exp_sn0), pool, log) == 0); + + /* + * TX Test 2: PDCP Entity with SN LEN = 12 + * PDCP entity configured with EIA2 and EEA2 + * TX_NEXT = 2048. + * Input: {0x18, 0xE2} + * Output: PDCP Header {0x80,0x00}, Ciphered Text {0x8f, 0xe3}, MAC-I {0xe0, 0xdf, 0x82, 0x92} + */ + srslte::unique_byte_buffer_t pdu_exp_sn2048 = allocate_unique_buffer(*pool); + memcpy(pdu_exp_sn2048->msg, pdu1, PDU1_LEN); + pdu_exp_sn2048->N_bytes = PDU1_LEN; + //TESTASSERT(test_tx(2049, std::move(pdu_exp_sn2048), pool, log) == 0); + + /* + * TX Test 3: PDCP Entity with SN LEN = 12 + * PDCP entity configured with EIA2 and EEA2 + * TX_NEXT = 4096. + * Input: {0x18, 0xE2} + * Output: PDCP Header {0x80,0x00}, Ciphered Text {0x8f, 0xe3}, MAC-I {0xe0, 0xdf, 0x82, 0x92} + */ + srslte::unique_byte_buffer_t pdu_exp_sn4096 = allocate_unique_buffer(*pool); + memcpy(pdu_exp_sn4096->msg, pdu1, PDU1_LEN); + pdu_exp_sn4096->N_bytes = PDU1_LEN; + TESTASSERT(test_tx(4097, std::move(pdu_exp_sn4096), pool, log) == 0); + return 0; +} // Setup all tests int run_all_tests(srslte::byte_buffer_pool* pool) { @@ -212,7 +245,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_basic(pool, &log) == 0); + TESTASSERT(test_tx_all(pool, &log) == 0); TESTASSERT(test_rx_basic(pool, &log) == 0); return 0; }