Fixed issue in computing the SN. Added test for packets received in sequence for PDCP NR. Test is passing now.

master
Pedro Alvarez 6 years ago committed by Andre Puschmann
parent 2104e6bbcf
commit adfe9f950e

@ -119,7 +119,7 @@ inline uint32_t pdcp_entity_base::HFN(uint32_t count)
inline uint32_t pdcp_entity_base::SN(uint32_t count) inline uint32_t pdcp_entity_base::SN(uint32_t count)
{ {
return count & (0xFFFFFFFF >> cfg.sn_len); return count & (0xFFFFFFFF >> (32 -cfg.sn_len));
} }
inline uint32_t pdcp_entity_base::COUNT(uint32_t hfn, uint32_t sn) inline uint32_t pdcp_entity_base::COUNT(uint32_t hfn, uint32_t sn)

@ -122,7 +122,6 @@ void pdcp_entity_nr::write_pdu(unique_byte_buffer_t pdu)
extract_mac(pdu, mac); extract_mac(pdu, mac);
// Calculate RCVD_COUNT // Calculate RCVD_COUNT
printf("%d\n", rcvd_sn);
uint32_t rcvd_hfn, rcvd_count; uint32_t rcvd_hfn, rcvd_count;
if ((int64_t)rcvd_sn < (int64_t)SN(rx_deliv) - (int64_t)window_size) { if ((int64_t)rcvd_sn < (int64_t)SN(rx_deliv) - (int64_t)window_size) {
rcvd_hfn = HFN(rx_deliv) + 1; rcvd_hfn = HFN(rx_deliv) + 1;
@ -143,25 +142,33 @@ void pdcp_entity_nr::write_pdu(unique_byte_buffer_t pdu)
} }
// Check valid rcvd_count // Check valid rcvd_count
if (rcvd_count < rx_deliv /*|| check_received_before() TODO*/) { if (rcvd_count < rx_deliv) {
return; // Invalid count, drop. return; // Invalid count, drop.
} }
// Store PDU in reception buffer // TODO check if PDU has been received
// TODO // TODO Store PDU in reception buffer
// Update RX_NEXT // Update RX_NEXT
if(rcvd_count >= rx_next){ if(rcvd_count >= rx_next){
rx_next = rcvd_count + 1; rx_next = rcvd_count + 1;
} }
// Deliver to upper layers (TODO support in order delivery) // TODO if out-of-order configured, submit to upper layer
if (is_srb()) {
rrc->write_pdu(lcid, std::move(pdu)); if (rcvd_count == rx_deliv) {
} else { // Deliver to upper layers (TODO queueing needs to be implemented)
gw->write_pdu(lcid, std::move(pdu)); if (is_srb()) {
rrc->write_pdu(lcid, std::move(pdu));
} else {
gw->write_pdu(lcid, std::move(pdu));
}
// Update RX_DELIV
rx_deliv = rcvd_count + 1; // TODO needs to be corrected when queueing is implemented
printf("New RX_deliv %d, rcvd_count %d\n", rx_deliv, rcvd_count);
} }
// Not clear how to update RX_DELIV without reception buffer (TODO) // Not clear how to update RX_DELIV without reception buffer (TODO)
// TODO handle reordering timers // TODO handle reordering timers

@ -120,6 +120,9 @@ private:
srslte::unique_byte_buffer_t last_pdu; srslte::unique_byte_buffer_t last_pdu;
}; };
/*
* Genric function to test transmission of in-sequence packets
*/
int test_tx(uint32_t n_packets, srslte::unique_byte_buffer_t pdu_exp, 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::pdcp_entity_nr pdcp;
@ -139,7 +142,6 @@ int test_tx(uint32_t n_packets, srslte::unique_byte_buffer_t pdu_exp, srslte::by
memcpy(sdu->msg, sdu1, SDU1_LEN); memcpy(sdu->msg, sdu1, SDU1_LEN);
sdu->N_bytes = SDU1_LEN; sdu->N_bytes = SDU1_LEN;
// Run test // Run test
for (uint32_t i = 0; i < n_packets; ++i) { for (uint32_t i = 0; i < n_packets; ++i) {
// Test SDU // Test SDU
@ -157,52 +159,11 @@ int test_tx(uint32_t n_packets, srslte::unique_byte_buffer_t pdu_exp, srslte::by
} }
return 0; return 0;
} }
/* /*
* Test 2: PDCP Entity RX * TX Test: PDCP Entity with SN LEN = 12 and 18. Tested COUNT = 0, 2048 and 4096
* Configure PDCP entity with EIA2 and EEA2 * PDCP entity configured with EIA2 and EEA2
* TX_NEXT initially at 0.
* Input: {0x80, 0x00, 0x8f, 0xe3, 0xe0, 0xdf 0x82, 0x92}
* Output: {0x18, 0xE2}
*/ */
bool test_rx_basic(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_DOWNLINK, SECURITY_DIRECTION_UPLINK, srslte::PDCP_SN_LEN_12};
rlc_dummy rlc(log);
rrc_dummy rrc(log);
gw_dummy gw(log);
pdcp.init(&rlc, &rrc, &gw, log, 0, cfg);
pdcp.config_security(k_enc, k_int, k_enc, k_int, srslte::CIPHERING_ALGORITHM_ID_128_EEA2, srslte::INTEGRITY_ALGORITHM_ID_128_EIA2);
pdcp.enable_integrity();
pdcp.enable_encryption();
uint8_t mac_exp[4];
srslte::unique_byte_buffer_t pdu = allocate_unique_buffer(*pool);
srslte::unique_byte_buffer_t sdu_exp = allocate_unique_buffer(*pool);
memcpy(pdu->msg, pdu1, PDU1_LEN);
pdu->N_bytes = PDU1_LEN;
memcpy(sdu_exp->msg, sdu1, PDU1_LEN);
sdu_exp->N_bytes = SDU1_LEN;
// Run test
pdcp.write_pdu(std::move(pdu));
// Check integrity check OK
TESTASSERT(gw.rx_count == 1);
// Check decrypting OK
srslte::unique_byte_buffer_t sdu_act = allocate_unique_buffer(*pool);
gw.get_last_pdu(sdu_act);
TESTASSERT(sdu_act->N_bytes == sdu_exp->N_bytes);
for (uint32_t i = 0; i < sdu_exp->N_bytes; ++i) {
TESTASSERT(sdu_act->msg[i] == sdu_exp->msg[i]);
}
return 0;
}
int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log) int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log)
{ {
/* /*
@ -236,20 +197,73 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log)
* Input: {0x18, 0xE2} * Input: {0x18, 0xE2}
* Output: PDCP Header {0x80,0x00}, Ciphered Text {0x97, 0xbe}, MAC-I {0xa3, 0x32, 0xfa, 0x61} * Output: PDCP Header {0x80,0x00}, Ciphered Text {0x97, 0xbe}, MAC-I {0xa3, 0x32, 0xfa, 0x61}
*/ */
srslte::unique_byte_buffer_t ct_tmp = allocate_unique_buffer(*pool);
srslte::security_128_eea2(&(k_enc[16]), 4096, 0, SECURITY_DIRECTION_UPLINK, sdu1, SDU1_LEN, ct_tmp->msg);
log->debug_hex(ct_tmp->msg, SDU1_LEN, "CT");
uint8_t mac[4];
srslte::security_128_eia2(&(k_int[16]), 4096, 0, SECURITY_DIRECTION_UPLINK, sdu1, SDU1_LEN, mac);
log->debug_hex(mac, 4, "MAC");
srslte::unique_byte_buffer_t pdu_exp_sn4096 = allocate_unique_buffer(*pool); srslte::unique_byte_buffer_t pdu_exp_sn4096 = allocate_unique_buffer(*pool);
memcpy(pdu_exp_sn4096->msg, pdu3, PDU3_LEN); memcpy(pdu_exp_sn4096->msg, pdu3, PDU3_LEN);
pdu_exp_sn4096->N_bytes = PDU3_LEN; pdu_exp_sn4096->N_bytes = PDU3_LEN;
TESTASSERT(test_tx(4097, std::move(pdu_exp_sn4096), pool, log) == 0); TESTASSERT(test_tx(4097, std::move(pdu_exp_sn4096), pool, log) == 0);
return 0; return 0;
} }
/*
* RX Test: PDCP Entity with SN LEN = 12 and 18. Tested 4097 packets received without losses.
* PDCP entity configured with EIA2 and EEA2
*/
int test_rx_in_sequence(uint32_t n_packets, srslte::byte_buffer_pool* pool, srslte::log* log)
{
srslte::pdcp_entity_nr pdcp_tx;
srslte::pdcp_entity_nr pdcp_rx;
srslte::srslte_pdcp_config_t cfg_tx = {
1, srslte::PDCP_RB_IS_DRB, SECURITY_DIRECTION_UPLINK, SECURITY_DIRECTION_DOWNLINK, srslte::PDCP_SN_LEN_12};
srslte::srslte_pdcp_config_t cfg_rx = {
1, srslte::PDCP_RB_IS_DRB, SECURITY_DIRECTION_DOWNLINK, SECURITY_DIRECTION_UPLINK, srslte::PDCP_SN_LEN_12};
rlc_dummy rlc_tx(log);
rrc_dummy rrc_tx(log);
gw_dummy gw_tx(log);
rlc_dummy rlc_rx(log);
rrc_dummy rrc_rx(log);
gw_dummy gw_rx(log);
pdcp_tx.init(&rlc_tx, &rrc_tx, &gw_tx, log, 0, cfg_tx);
pdcp_tx.config_security(
k_enc, k_int, k_enc, k_int, srslte::CIPHERING_ALGORITHM_ID_128_EEA2, srslte::INTEGRITY_ALGORITHM_ID_128_EIA2);
pdcp_tx.enable_integrity();
pdcp_tx.enable_encryption();
pdcp_rx.init(&rlc_rx, &rrc_rx, &gw_rx, log, 0, cfg_rx);
pdcp_rx.config_security(
k_enc, k_int, k_enc, k_int, srslte::CIPHERING_ALGORITHM_ID_128_EEA2, srslte::INTEGRITY_ALGORITHM_ID_128_EIA2);
pdcp_rx.enable_integrity();
pdcp_rx.enable_encryption();
srslte::unique_byte_buffer_t sdu_act = allocate_unique_buffer(*pool);
srslte::unique_byte_buffer_t sdu_exp = allocate_unique_buffer(*pool);
memcpy(sdu_exp->msg, sdu1, SDU1_LEN);
sdu_exp->N_bytes = SDU1_LEN;
// Generate test message and
// decript and check matching SDUs
for (uint32_t i = 0; i < n_packets; ++i) {
srslte::unique_byte_buffer_t sdu = allocate_unique_buffer(*pool);
srslte::unique_byte_buffer_t pdu = allocate_unique_buffer(*pool);
memcpy(sdu->msg, sdu_exp->msg, SDU1_LEN);
sdu->N_bytes = SDU1_LEN;
// Generate encripted and integrity protected PDU
pdcp_tx.write_sdu(std::move(sdu), true);
rlc_tx.get_last_sdu(pdu);
pdcp_rx.write_pdu(std::move(pdu));
gw_rx.get_last_pdu(sdu_act);
TESTASSERT(sdu_exp->N_bytes == sdu_act->N_bytes);
for (uint32_t j = 0; j < sdu_act->N_bytes; ++j) {
TESTASSERT(sdu_exp->msg[j] == sdu_act->msg[j]);
}
}
return 0;
}
// Setup all tests // Setup all tests
int run_all_tests(srslte::byte_buffer_pool* pool) int run_all_tests(srslte::byte_buffer_pool* pool)
{ {
@ -259,7 +273,7 @@ int run_all_tests(srslte::byte_buffer_pool* pool)
log.set_hex_limit(128); log.set_hex_limit(128);
TESTASSERT(test_tx_all(pool, &log) == 0); TESTASSERT(test_tx_all(pool, &log) == 0);
TESTASSERT(test_rx_basic(pool, &log) == 0); TESTASSERT(test_rx_in_sequence(4097, pool, &log) == 0);
return 0; return 0;
} }
@ -269,3 +283,13 @@ int main(int argc, char** argv)
run_all_tests(srslte::byte_buffer_pool::get_instance()); run_all_tests(srslte::byte_buffer_pool::get_instance());
srslte::byte_buffer_pool::cleanup(); srslte::byte_buffer_pool::cleanup();
} }
/*
srslte::unique_byte_buffer_t ct_tmp = allocate_unique_buffer(*pool);
srslte::security_128_eea2(&(k_enc[16]), 4096, 0, SECURITY_DIRECTION_UPLINK, sdu1, SDU1_LEN, ct_tmp->msg);
log->debug_hex(ct_tmp->msg, SDU1_LEN, "CT");
uint8_t mac[4];
srslte::security_128_eia2(&(k_int[16]), 4096, 0, SECURITY_DIRECTION_UPLINK, sdu1, SDU1_LEN, mac);
log->debug_hex(mac, 4, "MAC");
*/

Loading…
Cancel
Save