test_pcap: add function description

This commit is contained in:
Andre Puschmann 2021-07-26 17:23:38 +02:00
parent 8ef7ab536f
commit 4915dc9642
2 changed files with 48 additions and 25 deletions

View File

@ -13,21 +13,59 @@
#ifndef SRSRAN_TEST_PCAP_H
#define SRSRAN_TEST_PCAP_H
#if HAVE_PCAP
/**
* @brief Helper class for tests that wish to dump RRC, PDCP or MAC SDUs into PCAP files in order to inspect them with
* Wireshark.
*
* Depending on the layer of interest, the class adds the protocol header for the layers below so that Wireshark can
* disect them. For RRC for example, both PDCP and RLC AM dummy headers are added.
*
* There is an EUTRA and NR version for the helper methods.
*
*/
#include "srsran/common/mac_pcap.h"
#include "srsran/mac/mac_sch_pdu_nr.h"
static std::unique_ptr<srsran::mac_pcap> pcap_handle = nullptr;
#define PCAP_CRNTI (0x1001)
#define PCAP_TTI (666)
#endif
namespace srsran {
int write_mac_sdu_nr(const uint32_t lcid, const uint8_t* payload, const uint32_t len);
int write_rlc_am_sdu_nr(const uint32_t lcid, const uint8_t* payload, const uint32_t len)
/**
* @brief Writes a MAC SDU of a gives LCID for NR
*
* @param lcid The logical channel ID of the SDU
* @param payload Pointer to payload
* @param len Length
* @return int
*/
int write_mac_sdu_nr(const uint32_t lcid, const uint8_t* payload, const uint32_t len)
{
if (pcap_handle) {
byte_buffer_t tx_buffer;
srsran::mac_sch_pdu_nr tx_pdu;
tx_pdu.init_tx(&tx_buffer, len + 10);
tx_pdu.add_sdu(lcid, payload, len);
tx_pdu.pack();
pcap_handle->write_dl_crnti_nr(tx_buffer.msg, tx_buffer.N_bytes, PCAP_CRNTI, 0, PCAP_TTI);
return SRSRAN_SUCCESS;
}
return SRSRAN_ERROR;
}
/**
* @brief Writes a PDCP SDU (e.g. RRC DL-DCCH PDU)
*
* Both PDCP and RLC AM header (dummy for SN=0) are added.
*
* @param lcid The logical channel ID of the SDU
* @param payload Pointer to payload
* @param len Length
* @return int
*/
int write_pdcp_sdu_nr(const uint32_t lcid, const uint8_t* payload, const uint32_t len)
{
#if HAVE_PCAP
if (pcap_handle) {
byte_buffer_t mac_sdu;
// Add dummy RLC AM PDU header
@ -43,23 +81,6 @@ int write_rlc_am_sdu_nr(const uint32_t lcid, const uint8_t* payload, const uint3
mac_sdu.N_bytes += len;
return write_mac_sdu_nr(lcid, mac_sdu.msg, mac_sdu.N_bytes);
}
#endif // HAVE_PCAP
return SRSRAN_ERROR;
}
int write_mac_sdu_nr(const uint32_t lcid, const uint8_t* payload, const uint32_t len)
{
#if HAVE_PCAP
if (pcap_handle) {
byte_buffer_t tx_buffer;
srsran::mac_sch_pdu_nr tx_pdu;
tx_pdu.init_tx(&tx_buffer, len + 10);
tx_pdu.add_sdu(lcid, payload, len);
tx_pdu.pack();
pcap_handle->write_dl_crnti_nr(tx_buffer.msg, tx_buffer.N_bytes, PCAP_CRNTI, 0, PCAP_TTI);
return SRSRAN_SUCCESS;
}
#endif // HAVE_PCAP
return SRSRAN_ERROR;
}

View File

@ -16,8 +16,10 @@
#define JSON_OUTPUT 0
#define HAVE_PCAP 0
#define HAVE_PCAP 1
#if HAVE_PCAP
#include "srsran/common/test_pcap.h"
#endif
using namespace asn1;
using namespace asn1::rrc_nr;
@ -705,7 +707,7 @@ int test_cell_group_config()
packed_dcch.size(),
json_writer3.to_string().c_str());
srsran::write_rlc_am_sdu_nr(1, packed_dcch.data(), packed_dcch.size());
srsran::write_pdcp_sdu_nr(1, packed_dcch.data(), packed_dcch.size());
#endif
return SRSRAN_SUCCESS;