Added test for more TX packets in PDCP NR. Tests passing for TX_NEXT = 0, 2048 and 4096

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

@ -169,6 +169,13 @@ void pdcp_entity_nr::write_pdu(unique_byte_buffer_t pdu)
void pdcp_entity_nr::read_data_header(const unique_byte_buffer_t& pdu, uint32_t *rcvd_sn)
{
// Check PDU is long enough to extract header
if(pdu->N_bytes <= cfg.hdr_len_bytes){
log->error("PDU too small to extract header\n");
return;
}
// Extract RCVD_SN
uint16_t rcvd_sn_16 = 0;
switch (cfg.sn_len) {
case PDCP_SN_LEN_12:
@ -181,6 +188,8 @@ void pdcp_entity_nr::read_data_header(const unique_byte_buffer_t& pdu, uint32_t
default:
log->error("Cannot extract RCVD_SN, invalid SN length configured: %d\n", cfg.sn_len);
}
// Discard header
pdu->msg += cfg.hdr_len_bytes;
pdu->N_bytes -= cfg.hdr_len_bytes;
return;
@ -188,7 +197,7 @@ void pdcp_entity_nr::read_data_header(const unique_byte_buffer_t& pdu, uint32_t
void pdcp_entity_nr::write_data_header(const srslte::unique_byte_buffer_t& sdu, uint32_t count)
{
// Check enough space for header
// Add room for header
if (cfg.hdr_len_bytes > sdu->get_headroom()) {
log->error("Not enough space to add header\n");
return;
@ -196,6 +205,7 @@ void pdcp_entity_nr::write_data_header(const srslte::unique_byte_buffer_t& sdu,
sdu->msg -= cfg.hdr_len_bytes;
sdu->N_bytes += cfg.hdr_len_bytes;
// Add SN
switch (cfg.sn_len) {
case PDCP_SN_LEN_12:
srslte::uint16_to_uint8(0x0FFF & count, sdu->msg);
@ -212,27 +222,27 @@ void pdcp_entity_nr::write_data_header(const srslte::unique_byte_buffer_t& sdu,
}
}
void pdcp_entity_nr::extract_mac(const unique_byte_buffer_t &sdu, uint8_t* mac)
void pdcp_entity_nr::extract_mac(const unique_byte_buffer_t &pdu, uint8_t* mac)
{
// Check enough space for MAC
if (sdu->N_bytes < 4) {
if (pdu->N_bytes < 4) {
log->error("PDU too small to extract MAC-I\n");
return;
}
// Extract MAC
memcpy(mac, &sdu->msg[sdu->N_bytes - 4], 4);
sdu->N_bytes -= 4;
memcpy(mac, &pdu->msg[pdu->N_bytes - 4], 4);
pdu->N_bytes -= 4;
}
void pdcp_entity_nr::append_mac(const unique_byte_buffer_t &sdu, uint8_t* mac)
{
// Check enough space for MAC
if (sdu->N_bytes + 4 > sdu->get_tailroom()) {
log->error("Not enough space to add MAC-I\n");
return;
}
// Append MAC
memcpy(&sdu->msg[sdu->N_bytes], mac, 4);
sdu->N_bytes += 4;

@ -47,7 +47,12 @@ uint32_t SDU1_LEN = 2;
uint8_t pdu1[] = {0x80, 0x00, 0x8f, 0xe3, 0xe0, 0xdf, 0x82, 0x92};
uint32_t PDU1_LEN = 8;
// fake classes
uint8_t pdu2[] = {0x88, 0x00, 0x8d, 0x2c, 0x47, 0x5e, 0xb1, 0x5b};
uint32_t PDU2_LEN = 8;
uint8_t pdu3[] = {0x80, 0x00, 0x97, 0xbe, 0xa3, 0x32, 0xfa, 0x61};
uint32_t PDU3_LEN = 8;
// dummy classes
class rlc_dummy : public srsue::rlc_interface_pdcp
{
public:
@ -205,7 +210,7 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log)
* 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}
* 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);
@ -217,23 +222,31 @@ int test_tx_all(srslte::byte_buffer_pool* pool, srslte::log* log)
* 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}
* Output: PDCP Header {0x88, 0x00}, Ciphered Text {0x8d, 0x2c}, MAC-I {0x47, 0x5e, 0xb1, 0x5b}
*/
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);
memcpy(pdu_exp_sn2048->msg, pdu2, PDU2_LEN);
pdu_exp_sn2048->N_bytes = PDU2_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}
* 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);
memcpy(pdu_exp_sn4096->msg, pdu1, PDU1_LEN);
pdu_exp_sn4096->N_bytes = PDU1_LEN;
memcpy(pdu_exp_sn4096->msg, pdu3, PDU3_LEN);
pdu_exp_sn4096->N_bytes = PDU3_LEN;
TESTASSERT(test_tx(4097, std::move(pdu_exp_sn4096), pool, log) == 0);
return 0;
}

Loading…
Cancel
Save