Skip to content

Commit

Permalink
Add pcap over net support for ue
Browse files Browse the repository at this point in the history
  • Loading branch information
matan1008 committed Oct 8, 2021
1 parent eccf106 commit 69b8d9c
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 1 deletion.
2 changes: 2 additions & 0 deletions srsue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# and at http://www.gnu.org/licenses/.
#

find_package(SCTP REQUIRED)

########################################################################
# Boost is required
########################################################################
Expand Down
3 changes: 3 additions & 0 deletions srsue/hdr/stack/mac/dl_harq.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "demux.h"
#include "dl_sps.h"
#include "srsran/common/mac_pcap.h"
#include "srsran/common/mac_pcap_net.h"
#include "srsran/common/timers.h"

/* Downlink HARQ entity as defined in 5.3.2 of 36.321 */
Expand All @@ -39,6 +40,7 @@ class dl_harq_entity
bool init(mac_interface_rrc::ue_rnti_t* rntis, demux* demux_unit);
void reset();
void start_pcap(srsran::mac_pcap* pcap_);
void start_pcap_net(srsran::mac_pcap_net* pcap_net_);

/***************** PHY->MAC interface for DL processes **************************/
void new_grant_dl(mac_interface_phy_lte::mac_grant_dl_t grant, mac_interface_phy_lte::tb_action_dl_t* action);
Expand Down Expand Up @@ -118,6 +120,7 @@ class dl_harq_entity
demux* demux_unit = nullptr;
srslog::basic_logger& logger;
srsran::mac_pcap* pcap = nullptr;
srsran::mac_pcap_net* pcap_net = nullptr;
mac_interface_rrc::ue_rnti_t* rntis = nullptr;
uint16_t last_temporal_crnti = 0;
int si_window_start = 0;
Expand Down
2 changes: 2 additions & 0 deletions srsue/hdr/stack/mac/mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class mac : public mac_interface_phy_lte,
void process_pdus();

void start_pcap(srsran::mac_pcap* pcap);
void start_pcap_net(srsran::mac_pcap_net* pcap_net_);

// Timer callback interface
void timer_expired(uint32_t timer_id);
Expand Down Expand Up @@ -163,6 +164,7 @@ class mac : public mac_interface_phy_lte,

// pointer to MAC PCAP object
srsran::mac_pcap* pcap = nullptr;
srsran::mac_pcap_net* pcap_net = nullptr;
bool is_first_ul_grant = false;

mac_metrics_t metrics[SRSRAN_MAX_CARRIERS] = {};
Expand Down
3 changes: 3 additions & 0 deletions srsue/hdr/stack/mac/proc_ra.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "demux.h"
#include "mux.h"
#include "srsran/common/mac_pcap.h"
#include "srsran/common/mac_pcap_net.h"
#include "srsran/common/timers.h"
#include "srsran/mac/pdu.h"

Expand Down Expand Up @@ -70,6 +71,7 @@ class ra_proc : public srsran::timer_callback
bool contention_resolution_id_received(uint64_t rx_contention_id);

void start_pcap(srsran::mac_pcap* pcap);
void start_pcap_net(srsran::mac_pcap_net* pcap_net);

bool is_idle() const { return state == IDLE; }

Expand Down Expand Up @@ -142,6 +144,7 @@ class ra_proc : public srsran::timer_callback
srslog::basic_logger& logger;
mux* mux_unit = nullptr;
srsran::mac_pcap* pcap = nullptr;
srsran::mac_pcap_net* pcap_net = nullptr;
rrc_interface_mac* rrc = nullptr;
srsran::ext_task_sched_handle* task_sched = nullptr;
srsran::task_multiqueue::queue_handle task_queue;
Expand Down
3 changes: 3 additions & 0 deletions srsue/hdr/stack/mac/ul_harq.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "proc_ra.h"
#include "srsran/common/interfaces_common.h"
#include "srsran/common/mac_pcap.h"
#include "srsran/common/mac_pcap_net.h"
#include "srsran/common/timers.h"
#include "ul_sps.h"

Expand All @@ -45,6 +46,7 @@ class ul_harq_entity
void set_config(srsran::ul_harq_cfg_t& harq_cfg);

void start_pcap(srsran::mac_pcap* pcap_);
void start_pcap_net(srsran::mac_pcap_net* pcap_net_);

/***************** PHY->MAC interface for UL processes **************************/
void new_grant_ul(mac_interface_phy_lte::mac_grant_ul_t grant, mac_interface_phy_lte::tb_action_ul_t* action);
Expand Down Expand Up @@ -103,6 +105,7 @@ class ul_harq_entity

mux* mux_unit = nullptr;
srsran::mac_pcap* pcap = nullptr;
srsran::mac_pcap_net* pcap_net = nullptr;
srslog::basic_logger& logger;

mac_interface_rrc_common::ue_rnti_t* rntis = nullptr;
Expand Down
9 changes: 9 additions & 0 deletions srsue/hdr/stack/ue_stack_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ typedef struct {
std::string filename;
} pcap_args_t;

typedef struct {
bool enable;
std::string client_ip;
std::string bind_ip;
uint16_t client_port;
uint16_t bind_port;
} pcap_net_args_t;

typedef struct {
std::string enable;
pcap_args_t mac_pcap;
pcap_net_args_t mac_pcap_net;
pcap_args_t mac_nr_pcap;
pcap_args_t nas_pcap;
} pkt_trace_args_t;
Expand Down
2 changes: 2 additions & 0 deletions srsue/hdr/stack/ue_stack_lte.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "upper/usim.h"

#include "srsran/common/buffer_pool.h"
#include "srsran/common/mac_pcap_net.h"
#include "srsran/common/multiqueue.h"
#include "srsran/common/string_helpers.h"
#include "srsran/common/task_scheduler.h"
Expand Down Expand Up @@ -206,6 +207,7 @@ class ue_stack_lte final : public ue_stack_base,

// tracing
srsran::mac_pcap mac_pcap;
srsran::mac_pcap_net mac_pcap_net;
srsran::mac_pcap mac_nr_pcap;
srsran::nas_pcap nas_pcap;

Expand Down
3 changes: 2 additions & 1 deletion srsue/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ set(SRSRAN_SOURCES ${SRSRAN_SOURCES} rrc_nr_asn1 ngap_nr_asn1)
target_link_libraries(srsue ${SRSUE_SOURCES}
${SRSRAN_SOURCES}
${CMAKE_THREAD_LIBS_INIT}
${Boost_LIBRARIES})
${Boost_LIBRARIES}
${SCTP_LIBRARIES})

if (RPATH)
set_target_properties(srsue PROPERTIES INSTALL_RPATH ".")
Expand Down
5 changes: 5 additions & 0 deletions srsue/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ static int parse_args(all_args_t* args, int argc, char* argv[])
("pcap.mac_filename", bpo::value<string>(&args->stack.pkt_trace.mac_pcap.filename)->default_value("/tmp/ue_mac.pcap"), "MAC layer capture filename")
("pcap.mac_nr_filename", bpo::value<string>(&args->stack.pkt_trace.mac_nr_pcap.filename)->default_value("/tmp/ue_mac_nr.pcap"), "MAC_NR layer capture filename")
("pcap.nas_filename", bpo::value<string>(&args->stack.pkt_trace.nas_pcap.filename)->default_value("/tmp/ue_nas.pcap"), "NAS layer capture filename")
("pcap.mac_net_enable", bpo::value<bool>(&args->stack.pkt_trace.mac_pcap_net.enable)->default_value(false), "Enable MAC network captures")
("pcap.bind_ip", bpo::value<string>(&args->stack.pkt_trace.mac_pcap_net.bind_ip)->default_value("0.0.0.0"), "Bind IP address for MAC network trace")
("pcap.bind_port", bpo::value<uint16_t>(&args->stack.pkt_trace.mac_pcap_net.bind_port)->default_value(5687), "Bind port for MAC network trace")
("pcap.client_ip", bpo::value<string>(&args->stack.pkt_trace.mac_pcap_net.client_ip)->default_value("127.0.0.1"), "Client IP address for MAC network trace")
("pcap.client_port", bpo::value<uint16_t>(&args->stack.pkt_trace.mac_pcap_net.client_port)->default_value(5847), "Enable MAC network captures")

("gui.enable", bpo::value<bool>(&args->gui.enable)->default_value(false), "Enable GUI plots")

Expand Down
13 changes: 13 additions & 0 deletions srsue/src/stack/mac/dl_harq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ void dl_harq_entity::start_pcap(srsran::mac_pcap* pcap_)
pcap = pcap_;
}

void dl_harq_entity::start_pcap_net(srsran::mac_pcap_net* pcap_net_)
{
pcap_net = pcap_net_;
}

void dl_harq_entity::set_si_window_start(int si_window_start_)
{
si_window_start = si_window_start_;
Expand Down Expand Up @@ -321,13 +326,21 @@ void dl_harq_entity::dl_harq_process::dl_tb_process::tb_decoded(mac_interface_ph
harq_entity->pcap->write_dl_sirnti(
payload_buffer_ptr, cur_grant.tb[tid].tbs, ack, cur_grant.tti, harq_entity->cc_idx);
}
if (harq_entity->pcap_net) {
harq_entity->pcap_net->write_dl_sirnti(
payload_buffer_ptr, cur_grant.tb[tid].tbs, ack, cur_grant.tti, harq_entity->cc_idx);
}
Debug("Delivering PDU=%d bytes to Dissassemble and Demux unit (BCCH)", cur_grant.tb[tid].tbs);
harq_entity->demux_unit->push_pdu_bcch(payload_buffer_ptr, cur_grant.tb[tid].tbs);
} else {
if (harq_entity->pcap) {
harq_entity->pcap->write_dl_crnti(
payload_buffer_ptr, cur_grant.tb[tid].tbs, cur_grant.rnti, ack, cur_grant.tti, harq_entity->cc_idx);
}
if (harq_entity->pcap_net) {
harq_entity->pcap_net->write_dl_crnti(
payload_buffer_ptr, cur_grant.tb[tid].tbs, cur_grant.rnti, ack, cur_grant.tti, harq_entity->cc_idx);
}
if (cur_grant.rnti == harq_entity->rntis->temp_rnti) {
Debug("Delivering PDU=%d bytes to Dissassemble and Demux unit (Temporal C-RNTI)", cur_grant.tb[tid].tbs);
harq_entity->demux_unit->push_pdu_temp_crnti(payload_buffer_ptr, cur_grant.tb[tid].tbs);
Expand Down
32 changes: 32 additions & 0 deletions srsue/src/stack/mac/mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ void mac::start_pcap(srsran::mac_pcap* pcap_)
ra_procedure.start_pcap(pcap);
}

void mac::start_pcap_net(srsran::mac_pcap_net* pcap_net_)
{
pcap_net = pcap_net_;
for (auto& r : dl_harq) {
if (r != nullptr) {
r->start_pcap_net(pcap_net);
}
}
for (auto& r : ul_harq) {
if (r != nullptr) {
r->start_pcap_net(pcap_net);
}
}
ra_procedure.start_pcap_net(pcap_net);
}

// TODO: Change the function name and implement reconfiguration as in specs
// Implement Section 5.8
void mac::reconfiguration(const uint32_t& cc_idx, const bool& enable)
Expand Down Expand Up @@ -260,6 +276,10 @@ void mac::set_ho_rnti(uint16_t crnti, uint16_t target_pci)
if (pcap) {
pcap->set_ue_id(target_pci);
}

if (pcap_net) {
pcap_net->set_ue_id(target_pci);
}
}

uint16_t mac::get_ul_sched_rnti(uint32_t tti)
Expand Down Expand Up @@ -357,6 +377,10 @@ void mac::bch_decoded_ok(uint32_t cc_idx, uint8_t* payload, uint32_t len)
if (pcap) {
pcap->write_dl_bch(payload, len, true, phy_h->get_current_tti(), cc_idx);
}

if (pcap_net) {
pcap_net->write_dl_bch(payload, len, true, phy_h->get_current_tti(), cc_idx);
}
}

void mac::mch_decoded(uint32_t len, bool crc)
Expand Down Expand Up @@ -385,6 +409,10 @@ void mac::mch_decoded(uint32_t len, bool crc)
pcap->write_dl_mch(mch_payload_buffer, len, true, phy_h->get_current_tti(), 0);
}

if (pcap_net) {
pcap_net->write_dl_mch(mch_payload_buffer, len, true, phy_h->get_current_tti(), 0);
}

metrics[0].rx_brate += len * 8;
} else {
metrics[0].rx_errors++;
Expand Down Expand Up @@ -418,6 +446,10 @@ void mac::tb_decoded(uint32_t cc_idx, mac_grant_dl_t grant, bool ack[SRSRAN_MAX_
if (pcap) {
pcap->write_dl_pch(pch_payload_buffer, grant.tb[0].tbs, true, grant.tti, cc_idx);
}

if (pcap_net) {
pcap_net->write_dl_pch(pch_payload_buffer, grant.tb[0].tbs, true, grant.tti, cc_idx);
}
} else {
// Assert DL HARQ entity
if (dl_harq.at(cc_idx) == nullptr) {
Expand Down
9 changes: 9 additions & 0 deletions srsue/src/stack/mac/proc_ra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ void ra_proc::start_pcap(srsran::mac_pcap* pcap_)
pcap = pcap_;
}

void ra_proc::start_pcap_net(srsran::mac_pcap_net* pcap_net_)
{
pcap_net = pcap_net_;
}

// RRC calls to set a new PRACH configuration.
// The configuration is applied by initialization() function.
void ra_proc::set_config(srsran::rach_cfg_t& rach_cfg_)
Expand Down Expand Up @@ -377,6 +382,10 @@ void ra_proc::tb_decoded_ok(const uint8_t cc_idx, const uint32_t tti)
pcap->write_dl_ranti(rar_pdu_buffer, rar_grant_nbytes, ra_rnti, true, tti, cc_idx);
}

if (pcap_net) {
pcap_net->write_dl_ranti(rar_pdu_buffer, rar_grant_nbytes, ra_rnti, true, tti, cc_idx);
}

rar_pdu_msg.init_rx(rar_grant_nbytes);
if (rar_pdu_msg.parse_packet(rar_pdu_buffer) != SRSRAN_SUCCESS) {
rError("Error decoding RAR PDU");
Expand Down
14 changes: 14 additions & 0 deletions srsue/src/stack/mac/ul_harq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ void ul_harq_entity::start_pcap(srsran::mac_pcap* pcap_)
pcap = pcap_;
}

void ul_harq_entity::start_pcap_net(srsran::mac_pcap_net* pcap_net_)
{
pcap_net = pcap_net_;
}

/***************** PHY->MAC interface for UL processes **************************/
void ul_harq_entity::new_grant_ul(mac_interface_phy_lte::mac_grant_ul_t grant,
mac_interface_phy_lte::tb_action_ul_t* action)
Expand Down Expand Up @@ -272,6 +277,15 @@ void ul_harq_entity::ul_harq_process::new_grant_ul(mac_interface_phy_lte::mac_gr
}
harq_entity->pcap->write_ul_crnti(pdu_ptr, grant.tb.tbs, rnti, get_nof_retx(), grant.tti_tx, harq_entity->cc_idx);
}
if (harq_entity->pcap_net) {
uint16_t rnti;
if (grant.rnti == harq_entity->rntis->temp_rnti && harq_entity->rntis->temp_rnti) {
rnti = harq_entity->rntis->temp_rnti;
} else {
rnti = harq_entity->rntis->crnti;
}
harq_entity->pcap_net->write_ul_crnti(pdu_ptr, grant.tb.tbs, rnti, get_nof_retx(), grant.tti_tx, harq_entity->cc_idx);
}
} else if (has_grant()) {
// Non-Adaptive Re-Tx
generate_retx(grant, action);
Expand Down
8 changes: 8 additions & 0 deletions srsue/src/stack/ue_stack_lte.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ int ue_stack_lte::init(const stack_args_t& args_)
}
}

if (args.pkt_trace.mac_pcap_net.enable) {
mac_pcap_net.open(args.pkt_trace.mac_pcap_net.client_ip,
args.pkt_trace.mac_pcap_net.bind_ip,
args.pkt_trace.mac_pcap_net.client_port,
args.pkt_trace.mac_pcap_net.bind_port);
mac.start_pcap_net(&mac_pcap_net);
}

// Init USIM first to allow early exit in case reader couldn't be found
usim = usim_base::get_instance(&args.usim, usim_logger);
if (usim->init(&args.usim)) {
Expand Down

0 comments on commit 69b8d9c

Please sign in to comment.