mirror of https://github.com/PentHertz/srsLTE.git
fix MAC PDU padding with only padding and add test accordingly
This commit is contained in:
parent
2599b1824d
commit
fab75592ec
|
@ -70,11 +70,6 @@ uint8_t* sch_pdu::write_packet()
|
||||||
/* Writes the MAC PDU in the packet, including the MAC headers and CE payload. Section 6.1.2 */
|
/* Writes the MAC PDU in the packet, including the MAC headers and CE payload. Section 6.1.2 */
|
||||||
uint8_t* sch_pdu::write_packet(srslte::log* log_h)
|
uint8_t* sch_pdu::write_packet(srslte::log* log_h)
|
||||||
{
|
{
|
||||||
if (nof_subheaders <= 0 && nof_subheaders < (int)max_subheaders) {
|
|
||||||
log_h->error("Trying to write packet with invalid number of subheaders (nof_subheaders=%d).\n", nof_subheaders);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set padding to remaining length in PDU
|
// set padding to remaining length in PDU
|
||||||
uint32_t num_padding = rem_len;
|
uint32_t num_padding = rem_len;
|
||||||
|
|
||||||
|
@ -128,9 +123,9 @@ uint8_t* sch_pdu::write_packet(srslte::log* log_h)
|
||||||
uint8_t* ptr = buffer_tx->msg;
|
uint8_t* ptr = buffer_tx->msg;
|
||||||
|
|
||||||
// Add single/two byte padding first
|
// Add single/two byte padding first
|
||||||
sch_subh padding;
|
|
||||||
padding.set_padding();
|
|
||||||
for (uint32_t i = 0; i < onetwo_padding; i++) {
|
for (uint32_t i = 0; i < onetwo_padding; i++) {
|
||||||
|
sch_subh padding;
|
||||||
|
padding.set_padding();
|
||||||
padding.write_subheader(&ptr, false);
|
padding.write_subheader(&ptr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,6 +169,11 @@ uint8_t* sch_pdu::write_packet(srslte::log* log_h)
|
||||||
buffer_tx->N_bytes += num_padding;
|
buffer_tx->N_bytes += num_padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print warning if we have padding only
|
||||||
|
if (nof_subheaders <= 0 && nof_subheaders < (int)max_subheaders) {
|
||||||
|
log_h->warning("Writing MAC PDU with padding only (%d B)\n", pdu_len);
|
||||||
|
}
|
||||||
|
|
||||||
/* Sanity check and print if error */
|
/* Sanity check and print if error */
|
||||||
if (log_h) {
|
if (log_h) {
|
||||||
log_h->debug(
|
log_h->debug(
|
||||||
|
|
|
@ -361,6 +361,58 @@ int mac_sch_pdu_pack_test3()
|
||||||
return SRSLTE_SUCCESS;
|
return SRSLTE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test for padding-only MAC PDU
|
||||||
|
int mac_sch_pdu_pack_test4()
|
||||||
|
{
|
||||||
|
static uint8_t tv[] = {0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||||
|
|
||||||
|
srslte::log_filter rlc_log("RLC");
|
||||||
|
rlc_log.set_level(srslte::LOG_LEVEL_DEBUG);
|
||||||
|
rlc_log.set_hex_limit(100000);
|
||||||
|
|
||||||
|
rlc_dummy rlc;
|
||||||
|
|
||||||
|
srslte::log_filter mac_log("MAC");
|
||||||
|
mac_log.set_level(srslte::LOG_LEVEL_DEBUG);
|
||||||
|
mac_log.set_hex_limit(100000);
|
||||||
|
|
||||||
|
const uint32_t pdu_size = 10;
|
||||||
|
srslte::sch_pdu pdu(10);
|
||||||
|
|
||||||
|
byte_buffer_t buffer;
|
||||||
|
pdu.init_tx(&buffer, pdu_size, true);
|
||||||
|
|
||||||
|
TESTASSERT(pdu.rem_size() == pdu_size);
|
||||||
|
TESTASSERT(pdu.get_pdu_len() == pdu_size);
|
||||||
|
TESTASSERT(pdu.get_sdu_space() == pdu_size - 1);
|
||||||
|
TESTASSERT(pdu.get_current_sdu_ptr() == buffer.msg);
|
||||||
|
|
||||||
|
// Try to add SDU
|
||||||
|
TESTASSERT(pdu.new_subh());
|
||||||
|
TESTASSERT(pdu.get()->set_sdu(2, 5, &rlc) == 0);
|
||||||
|
|
||||||
|
// Adding SDU failed, remove subheader again
|
||||||
|
pdu.del_subh();
|
||||||
|
|
||||||
|
// write PDU
|
||||||
|
pdu.write_packet(&mac_log);
|
||||||
|
|
||||||
|
// make sure full PDU has been written
|
||||||
|
TESTASSERT(buffer.N_bytes == pdu_size);
|
||||||
|
|
||||||
|
// log
|
||||||
|
mac_log.info_hex(buffer.msg, buffer.N_bytes, "MAC PDU (%d B):\n", buffer.N_bytes);
|
||||||
|
|
||||||
|
#if HAVE_PCAP
|
||||||
|
pcap_handle->write_ul_crnti(buffer.msg, buffer.N_bytes, 0x1001, true, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// compare with TV
|
||||||
|
TESTASSERT(memcmp(buffer.msg, tv, sizeof(tv)) == 0);
|
||||||
|
|
||||||
|
return SRSLTE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
// Test for checking error cases
|
// Test for checking error cases
|
||||||
int mac_sch_pdu_pack_error_test()
|
int mac_sch_pdu_pack_error_test()
|
||||||
{
|
{
|
||||||
|
@ -463,6 +515,11 @@ int main(int argc, char** argv)
|
||||||
return SRSLTE_ERROR;
|
return SRSLTE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mac_sch_pdu_pack_test4()) {
|
||||||
|
fprintf(stderr, "mac_sch_pdu_pack_test4 failed.\n");
|
||||||
|
return SRSLTE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if (mac_sch_pdu_pack_error_test()) {
|
if (mac_sch_pdu_pack_error_test()) {
|
||||||
fprintf(stderr, "mac_sch_pdu_pack_error_test failed.\n");
|
fprintf(stderr, "mac_sch_pdu_pack_error_test failed.\n");
|
||||||
return SRSLTE_ERROR;
|
return SRSLTE_ERROR;
|
||||||
|
|
Loading…
Reference in New Issue