From 993822a662d0aa916a6d6c76a2ba3a9fa2c03858 Mon Sep 17 00:00:00 2001 From: ismagom Date: Thu, 11 Jun 2015 19:59:06 +0200 Subject: [PATCH] Moved PCAP interface to a separate class. Called PCAP from DL/UL HARQ processes --- srsapps/ue/mac/include/srsapps/ue/mac/demux.h | 6 +-- .../ue/mac/include/srsapps/ue/mac/dl_harq.h | 3 ++ srsapps/ue/mac/include/srsapps/ue/mac/mac.h | 16 ++++---- srsapps/ue/mac/include/srsapps/ue/mac/mux.h | 6 +-- srsapps/ue/mac/include/srsapps/ue/mac/pdu.h | 16 +++----- .../ue/mac/include/srsapps/ue/mac/proc_ra.h | 5 ++- .../ue/mac/include/srsapps/ue/mac/ul_harq.h | 4 ++ srsapps/ue/mac/src/demux.cc | 8 ++-- srsapps/ue/mac/src/dl_harq.cc | 24 ++++++++--- srsapps/ue/mac/src/mac.cc | 31 +++++++------- srsapps/ue/mac/src/mux.cc | 6 +-- srsapps/ue/mac/src/pdu.cc | 40 ++----------------- srsapps/ue/mac/src/proc_ra.cc | 12 +++++- srsapps/ue/mac/src/ul_harq.cc | 10 +++++ srsapps/ue/mac/test/mac_test.cc | 27 +++++++++++-- 15 files changed, 114 insertions(+), 100 deletions(-) diff --git a/srsapps/ue/mac/include/srsapps/ue/mac/demux.h b/srsapps/ue/mac/include/srsapps/ue/mac/demux.h index 3ab286f7c..e5a168ce0 100644 --- a/srsapps/ue/mac/include/srsapps/ue/mac/demux.h +++ b/srsapps/ue/mac/include/srsapps/ue/mac/demux.h @@ -47,7 +47,7 @@ class demux { public: demux(); - void init(phy* phy_h_, log* log_h_, mac_io* mac_io_h_, timers* timers_db_, bool pcap_=false, FILE *pcap_file_=0); + void init(phy* phy_h_, log* log_h_, mac_io* mac_io_h_, timers* timers_db_); void add_sdu_handler(sdu_handler *handler); @@ -72,10 +72,6 @@ private: bool pending_temp_rnti; bool has_pending_contention_resolution_id; - /* Write MAC PDUs to file in PCACP format? */ - bool pcap; - FILE *pcap_file; - phy *phy_h; log *log_h; mac_io *mac_io_h; diff --git a/srsapps/ue/mac/include/srsapps/ue/mac/dl_harq.h b/srsapps/ue/mac/include/srsapps/ue/mac/dl_harq.h index d5744f6e3..0d6e28b98 100644 --- a/srsapps/ue/mac/include/srsapps/ue/mac/dl_harq.h +++ b/srsapps/ue/mac/include/srsapps/ue/mac/dl_harq.h @@ -33,6 +33,7 @@ #include "srsapps/ue/mac/mac_params.h" #include "srsapps/common/timers.h" #include "srsapps/ue/mac/demux.h" +#include "srsapps/ue/mac/mac_pcap.h" #ifndef DLHARQ_H #define DLHARQ_H @@ -59,6 +60,7 @@ public: void reset(); bool is_ack_pending_resolution(); void send_pending_ack_contention_resolution(); + void start_pcap(mac_pcap* pcap); private: @@ -93,6 +95,7 @@ private: demux *demux_unit; srslte::log *log_h; int pending_ack_pid; + mac_pcap *pcap; }; } diff --git a/srsapps/ue/mac/include/srsapps/ue/mac/mac.h b/srsapps/ue/mac/include/srsapps/ue/mac/mac.h index 13bcc2f08..b87d76c1f 100644 --- a/srsapps/ue/mac/include/srsapps/ue/mac/mac.h +++ b/srsapps/ue/mac/include/srsapps/ue/mac/mac.h @@ -45,6 +45,7 @@ #include "srsapps/ue/mac/mux.h" #include "srsapps/ue/mac/demux.h" #include "srsapps/ue/mac/sdu_handler.h" +#include "srsapps/ue/mac/mac_pcap.h" #include "srsapps/common/trace.h" @@ -59,8 +60,8 @@ typedef _Complex float cf_t; class mac : public timer_callback { public: - mac() : timers_db((uint32_t) NOF_MAC_TIMERS), tr_end_time(1024*10), tr_start_time(1024*10) {started=false;} - bool init(phy *phy_h, tti_sync *ttisync, log *log_h, bool pcap_=false); + mac() : timers_db((uint32_t) NOF_MAC_TIMERS), tr_end_time(1024*10), tr_start_time(1024*10) {started=false; pcap = NULL; } + bool init(phy *phy_h, tti_sync *ttisync, log *log_h); void stop(); int get_tti(); void main_radio_loop(); // called after thread creation @@ -90,6 +91,7 @@ public: void write_trace(std::string filename); void timer_expired(uint32_t timer_id); + void start_pcap(mac_pcap* pcap); enum { HARQ_RTT = 0, @@ -150,13 +152,13 @@ private: void setup_timers(); void timeAlignmentTimerExpire(); - /* Write MAC PDUs to file in PCACP format? */ - bool pcap; - FILE *pcap_file; - + // pointer to MAC PCAP object + mac_pcap* pcap; + + // Variables for Execution time Trace trace tr_start_time; trace tr_end_time; - bool tr_enabled; + bool tr_enabled; void tr_log_start(uint32_t tti); void tr_log_end(uint32_t tti); void set_phy_crnti(uint16_t phy_rnti); diff --git a/srsapps/ue/mac/include/srsapps/ue/mac/mux.h b/srsapps/ue/mac/include/srsapps/ue/mac/mux.h index c56764075..530c77d15 100644 --- a/srsapps/ue/mac/include/srsapps/ue/mac/mux.h +++ b/srsapps/ue/mac/include/srsapps/ue/mac/mux.h @@ -47,7 +47,7 @@ class mux public: mux(); void reset(); - void init(log *log_h, mac_io *mac_io_h, bsr_proc *bsr_procedure, bool pcap_=false, FILE *pcap_file_=0); + void init(log *log_h, mac_io *mac_io_h, bsr_proc *bsr_procedure); bool is_pending_ccch_sdu(); bool is_pending_any_sdu(); @@ -97,10 +97,6 @@ private: qbuff pdu_buff; sch_pdu pdu_msg; bool msg3_has_been_transmitted; - - /* Write MAC PDUs to file in PCACP format? */ - bool pcap; - FILE *pcap_file; }; } diff --git a/srsapps/ue/mac/include/srsapps/ue/mac/pdu.h b/srsapps/ue/mac/include/srsapps/ue/mac/pdu.h index 89ea4a9af..7ec65e8e2 100644 --- a/srsapps/ue/mac/include/srsapps/ue/mac/pdu.h +++ b/srsapps/ue/mac/include/srsapps/ue/mac/pdu.h @@ -124,7 +124,7 @@ public: } // Section 6.1.2 - void parse_packet(uint8_t *ptr, FILE *pcap_file=0) { + void parse_packet(uint8_t *ptr) { uint8_t *init_ptr = ptr; nof_subheaders = 0; while(subheaders[nof_subheaders].read_subheader(&ptr)) { @@ -139,7 +139,7 @@ public: return pdu_is_ul; } - virtual bool write_packet(uint8_t *ptr, FILE *pcap_file=0) = 0; + virtual bool write_packet(uint8_t *ptr) = 0; protected: std::vector subheaders; @@ -229,8 +229,7 @@ private: bool F_bit; uint8_t ce_payload[MAX_CE_PAYLOAD_LEN*8]; uint32_t sizeof_ce(uint32_t lcid, bool is_ul); - uint8_t buff_size_table(uint32_t buffer_size); - + uint8_t buff_size_table(uint32_t buffer_size); }; class sch_pdu : public pdu @@ -239,8 +238,8 @@ public: sch_pdu(uint32_t max_rars) : pdu(max_rars) {} - void parse_packet(uint8_t *ptr, FILE *pcap_file=0); - bool write_packet(uint8_t *ptr, FILE *pcap_file=0); + void parse_packet(uint8_t *ptr); + bool write_packet(uint8_t *ptr); bool has_space_ce(uint32_t nbytes); bool has_space_sdu(uint32_t nbytes); bool has_space_sdu(uint32_t nbytes, bool is_first); @@ -251,9 +250,6 @@ public: bool update_space_sdu(uint32_t nbytes); bool update_space_sdu(uint32_t nbytes, bool is_first); void fprint(FILE *stream); -private: - uint8_t pdu_pcap_tmp[1024*64]; - }; @@ -299,7 +295,7 @@ public: bool has_backoff(); uint8_t get_backoff(); - bool write_packet(uint8_t* ptr, FILE *pcap_file=0); + bool write_packet(uint8_t* ptr); void fprint(FILE *stream); private: diff --git a/srsapps/ue/mac/include/srsapps/ue/mac/proc_ra.h b/srsapps/ue/mac/include/srsapps/ue/mac/proc_ra.h index 14aaeccf4..3095e75aa 100644 --- a/srsapps/ue/mac/include/srsapps/ue/mac/proc_ra.h +++ b/srsapps/ue/mac/include/srsapps/ue/mac/proc_ra.h @@ -38,6 +38,7 @@ #include "srsapps/ue/mac/mux.h" #include "srsapps/ue/mac/demux.h" #include "srsapps/ue/mac/pdu.h" +#include "srsapps/ue/mac/mac_pcap.h" #ifndef PROCRA_H #define PROCRA_H @@ -50,7 +51,7 @@ namespace ue { class ra_proc : public proc,timer_callback { public: - ra_proc() : rar_pdu_msg(20) {}; + ra_proc() : rar_pdu_msg(20) {pcap = NULL;}; bool init(mac_params *params_db, phy *phy_h, log *log_h, timers *timers_db, mux *mux_unit, demux *demux_unit); void reset(); @@ -67,6 +68,7 @@ class ra_proc : public proc,timer_callback void timer_expired(uint32_t timer_id); void* run_prach_thread(); + void start_pcap(mac_pcap* pcap); private: void process_timeadv_cmd(uint32_t ta_cmd); @@ -143,6 +145,7 @@ private: timers *timers_db; mux *mux_unit; demux *demux_unit; + mac_pcap *pcap; pthread_t pt_init_prach; pthread_cond_t cond; diff --git a/srsapps/ue/mac/include/srsapps/ue/mac/ul_harq.h b/srsapps/ue/mac/include/srsapps/ue/mac/ul_harq.h index dfc80506f..46aadaf59 100644 --- a/srsapps/ue/mac/include/srsapps/ue/mac/ul_harq.h +++ b/srsapps/ue/mac/include/srsapps/ue/mac/ul_harq.h @@ -32,6 +32,7 @@ #include "srsapps/common/log.h" #include "srsapps/ue/mac/mac_params.h" #include "srsapps/ue/mac/mux.h" +#include "srsapps/ue/mac/mac_pcap.h" #include "srsapps/common/timers.h" #ifndef ULHARQ_H @@ -51,6 +52,7 @@ public: const static uint32_t NOF_HARQ_PROC = 8; static uint32_t pidof(uint32_t tti); + ul_harq_entity() { pcap = NULL; } bool init(srslte_cell_t cell, mac_params *params_db, log *log_h, timers* timers_, mux *mux_unit); void reset(); @@ -58,6 +60,7 @@ public: bool is_sps(uint32_t pid); void run_tti(uint32_t tti, ul_sched_grant *grant, phy *phy_); void run_tti(uint32_t tti, phy *phy_); + void start_pcap(mac_pcap* pcap); private: @@ -102,6 +105,7 @@ private: ul_harq_process proc[NOF_HARQ_PROC]; log *log_h; mac_params *params_db; + mac_pcap *pcap; }; } diff --git a/srsapps/ue/mac/src/demux.cc b/srsapps/ue/mac/src/demux.cc index d1fd7cdf5..36bce0301 100644 --- a/srsapps/ue/mac/src/demux.cc +++ b/srsapps/ue/mac/src/demux.cc @@ -40,14 +40,12 @@ demux::demux() : mac_msg(20),pending_mac_msg(20) sdu_handler_ = NULL; } -void demux::init(phy* phy_h_, log* log_h_, mac_io* mac_io_h_, timers* timers_db_, bool pcap_, FILE *pcap_file_) +void demux::init(phy* phy_h_, log* log_h_, mac_io* mac_io_h_, timers* timers_db_) { phy_h = phy_h_; log_h = log_h_; mac_io_h = mac_io_h_; timers_db = timers_db_; - pcap = pcap_; - pcap_file = pcap_file_; } void demux::add_sdu_handler(sdu_handler* handler) @@ -93,7 +91,7 @@ void demux::push_pdu_temp_crnti(uint8_t *mac_pdu, uint32_t nof_bits) if (!pending_temp_rnti) { // Unpack DLSCH MAC PDU pending_mac_msg.init(nof_bits/8); - pending_mac_msg.parse_packet(mac_pdu, pcap_file); + pending_mac_msg.parse_packet(mac_pdu); //pending_mac_msg.fprint(stdout); // Look for Contention Resolution UE ID @@ -117,7 +115,7 @@ void demux::push_pdu(uint8_t *mac_pdu, uint32_t nof_bits) { // Unpack DLSCH MAC PDU mac_msg.init(nof_bits/8); - mac_msg.parse_packet(mac_pdu, pcap_file); + mac_msg.parse_packet(mac_pdu); //mac_msg.fprint(stdout); process_pdu(&mac_msg); Debug("Normal MAC PDU processed\n"); diff --git a/srsapps/ue/mac/src/dl_harq.cc b/srsapps/ue/mac/src/dl_harq.cc index 5e08fb6d9..11d5940d7 100644 --- a/srsapps/ue/mac/src/dl_harq.cc +++ b/srsapps/ue/mac/src/dl_harq.cc @@ -47,6 +47,7 @@ dl_harq_entity::dl_harq_entity() proc[i].pid = i; } pending_ack_pid = -1; + pcap = NULL; } bool dl_harq_entity::init(srslte_cell_t cell, uint32_t max_payload_len, log* log_h_, timers* timers_, demux *demux_unit_) { @@ -61,6 +62,12 @@ bool dl_harq_entity::init(srslte_cell_t cell, uint32_t max_payload_len, log* log return true; } + +void dl_harq_entity::start_pcap(mac_pcap* pcap_) +{ + pcap = pcap_; +} + bool dl_harq_entity::is_sps(uint32_t pid) { return false; @@ -143,12 +150,16 @@ void dl_harq_entity::dl_harq_process::receive_data(uint32_t tti, srslte::ue::dl_ Info("DL PID %d: TBS=%d, RV=%d, MCS=%d, crc=%s\n", pid, cur_grant.get_tbs(), cur_grant.get_rv(), cur_grant.get_mcs(), ack?"OK":"NOK"); - if (ack) { - // RX OK - if (pid == HARQ_BCCH_PID) { + if (pid == HARQ_BCCH_PID) { + if (ack) { Debug("Delivering PDU=%d bytes to Dissassemble and Demux unit (BCCH)\n", cur_grant.get_tbs()/8); - harq_entity->demux_unit->push_pdu_bcch(payload, cur_grant.get_tbs()); - } else { + harq_entity->demux_unit->push_pdu_bcch(payload, cur_grant.get_tbs()); + } + if (harq_entity->pcap) { + harq_entity->pcap->write_dl_sirnti(payload, cur_grant.get_tbs()/8, ack, tti); + } + } else { + if (ack) { if (cur_grant.is_temp_rnti()) { Debug("Delivering PDU=%d bytes to Dissassemble and Demux unit (Temporal C-RNTI)\n", cur_grant.get_tbs()/8); @@ -158,6 +169,9 @@ void dl_harq_entity::dl_harq_process::receive_data(uint32_t tti, srslte::ue::dl_ harq_entity->demux_unit->push_pdu(payload, cur_grant.get_tbs()); } } + if (harq_entity->pcap) { + harq_entity->pcap->write_dl_crnti(payload, cur_grant.get_tbs()/8, cur_grant.get_rnti(), ack, tti); + } } } else { Warning("DL PID %d: Received duplicate TB. Discarting and retransmitting ACK\n"); diff --git a/srsapps/ue/mac/src/mac.cc b/srsapps/ue/mac/src/mac.cc index ca3bf6ad8..0dc9494ae 100644 --- a/srsapps/ue/mac/src/mac.cc +++ b/srsapps/ue/mac/src/mac.cc @@ -40,29 +40,20 @@ namespace srslte { namespace ue { -bool mac::init(phy *phy_h_, tti_sync* ttisync_, log* log_h_, bool pcap_) +bool mac::init(phy *phy_h_, tti_sync* ttisync_, log* log_h_) { started = false; ttisync = ttisync_; phy_h = phy_h_; log_h = log_h_; - pcap = pcap_; tti = 0; is_synchronized = false; last_temporal_crnti = 0; phy_rnti = 0; - - if(pcap) { - pcap_file = MAC_LTE_PCAP_Open("/tmp/ue_mac.pcap"); - if(!pcap_file) { - Info("Failed to open pcap for writing\n"); - pcap = false; - } - } bsr_procedure.init(log_h, &timers_db, ¶ms_db, &mac_io_lch); - mux_unit.init(log_h, &mac_io_lch, &bsr_procedure, pcap, pcap_file); - demux_unit.init(phy_h, log_h, &mac_io_lch, &timers_db, pcap, pcap_file); + mux_unit.init(log_h, &mac_io_lch, &bsr_procedure); + demux_unit.init(phy_h, log_h, &mac_io_lch, &timers_db); ra_procedure.init(¶ms_db, phy_h, log_h, &timers_db, &mux_unit, &demux_unit); sr_procedure.init(log_h, ¶ms_db, phy_h); reset(); @@ -76,10 +67,6 @@ bool mac::init(phy *phy_h_, tti_sync* ttisync_, log* log_h_, bool pcap_) void mac::stop() { - if (pcap && pcap_file) { - MAC_LTE_PCAP_Close(pcap_file); - printf("Closing MAC PCAP file\n"); - } started = false; pthread_join(mac_thread, NULL); } @@ -93,6 +80,14 @@ int mac::get_tti() } } +void mac::start_pcap(mac_pcap* pcap_) +{ + pcap = pcap_; + dl_harq.start_pcap(pcap); + ul_harq.start_pcap(pcap); + ra_procedure.start_pcap(pcap); +} + void mac::start_trace() { tr_enabled = true; @@ -166,6 +161,10 @@ void mac::main_radio_loop() { // Print MIB srslte_cell_fprint(stdout, &cell, phy_h->get_current_tti()/10); + if (pcap) { + pcap->write_dl_bch(bch_payload, SRSLTE_BCH_PAYLOAD_LEN/8, true, phy_h->get_current_tti()); + } + // Init HARQ for this cell Info("Init UL/DL HARQ\n"); ul_harq.init(cell, ¶ms_db, log_h, &timers_db, &mux_unit); diff --git a/srsapps/ue/mac/src/mux.cc b/srsapps/ue/mac/src/mux.cc index 618160922..fde3eb2aa 100644 --- a/srsapps/ue/mac/src/mux.cc +++ b/srsapps/ue/mac/src/mux.cc @@ -52,13 +52,11 @@ mux::mux() : pdu_msg(20) } } -void mux::init(log *log_h_, mac_io *mac_io_h_, bsr_proc *bsr_procedure_, bool pcap_, FILE *pcap_file_) +void mux::init(log *log_h_, mac_io *mac_io_h_, bsr_proc *bsr_procedure_) { log_h = log_h_; mac_io_h = mac_io_h_; bsr_procedure = bsr_procedure_; - pcap = pcap_; - pcap_file = pcap_file_; } void mux::reset() @@ -287,7 +285,7 @@ bool mux::assemble_pdu(uint32_t pdu_sz_nbits) { //pdu_msg.fprint(stdout); /* Generate MAC PDU and save to buffer */ - if (pdu_msg.write_packet(buff, pcap_file)) { + if (pdu_msg.write_packet(buff)) { pdu_buff.push(pdu_sz_nbits); } else { Error("Writing PDU message to packet\n"); diff --git a/srsapps/ue/mac/src/pdu.cc b/srsapps/ue/mac/src/pdu.cc index d30a803a6..95f606389 100644 --- a/srsapps/ue/mac/src/pdu.cc +++ b/srsapps/ue/mac/src/pdu.cc @@ -30,7 +30,6 @@ #include #include "srsapps/ue/mac/pdu.h" -#include "srsapps/ue/mac/pcap.h" #include "srslte/srslte.h" namespace srslte { @@ -86,25 +85,8 @@ void sch_subh::fprint(FILE* stream) } } -void sch_pdu::parse_packet(uint8_t *ptr, FILE *pcap_file) +void sch_pdu::parse_packet(uint8_t *ptr) { - if(pcap_file) { - MAC_Context_Info_t context = - { - FDD_RADIO, DIRECTION_DOWNLINK, C_RNTI, - 50, /* RNTI */ - 102, /* UEId */ - 0, /* Retx */ - 1, /* CRC Stsatus (i.e. OK) */ - 1, /* Sysframe number */ - 4 /* Subframe number */ - }; - - srslte_bit_unpack_vector(ptr, pdu_pcap_tmp, pdu_len*8); - MAC_LTE_PCAP_WritePDU(pcap_file, &context, pdu_pcap_tmp, pdu_len); - fprintf(stdout, "Wrote DL MAC PDU, len=%d\n", pdu_len); - } - pdu::parse_packet(ptr); // Correct size for last SDU @@ -122,7 +104,7 @@ void sch_pdu::parse_packet(uint8_t *ptr, FILE *pcap_file) } // Section 6.1.2 -bool sch_pdu::write_packet(uint8_t* ptr, FILE *pcap_file) +bool sch_pdu::write_packet(uint8_t* ptr) { uint8_t *init_ptr = ptr; bool last_is_padding = false; @@ -191,22 +173,6 @@ bool sch_pdu::write_packet(uint8_t* ptr, FILE *pcap_file) // Set paddint to zeros (if any) bzero(ptr, rem_len*sizeof(uint8_t)*8); - if(pcap_file) { - MAC_Context_Info_t context = - { - FDD_RADIO, DIRECTION_UPLINK, C_RNTI, - 50, /* RNTI */ - 102, /* UEId */ - 0, /* Retx */ - 1, /* CRC Stsatus (i.e. OK) */ - 1, /* Sysframe number */ - 4 /* Subframe number */ - }; - - srslte_bit_unpack_vector(init_ptr, pdu_pcap_tmp, pdu_len*8); - MAC_LTE_PCAP_WritePDU(pcap_file, &context, pdu_pcap_tmp, pdu_len); - fprintf(stdout, "Wrote UL MAC PDU, len=%d\n", pdu_len); - } } uint32_t sch_pdu::rem_size() { @@ -588,7 +554,7 @@ void rar_pdu::set_backoff(uint8_t bi) } // Section 6.1.5 -bool rar_pdu::write_packet(uint8_t* ptr, FILE *pcap_file) +bool rar_pdu::write_packet(uint8_t* ptr) { // Write Backoff Indicator, if any if (has_backoff_indicator) { diff --git a/srsapps/ue/mac/src/proc_ra.cc b/srsapps/ue/mac/src/proc_ra.cc index 1821b47b5..0405a8bd0 100644 --- a/srsapps/ue/mac/src/proc_ra.cc +++ b/srsapps/ue/mac/src/proc_ra.cc @@ -88,6 +88,11 @@ void ra_proc::reset() { state = IDLE; } +void ra_proc::start_pcap(mac_pcap* pcap_) +{ + pcap = pcap_; +} + void ra_proc::read_params() { // Read initialization parameters @@ -290,7 +295,12 @@ void ra_proc::step_response_reception() { // Decode packet dl_buffer->reset_softbuffer(); - if (dl_buffer->decode_data(&rar_grant, rar_pdu_buffer)) { + bool ack = dl_buffer->decode_data(&rar_grant, rar_pdu_buffer); + if (pcap) { + pcap->write_dl_crnti(payload, rar_grant.get_tbs()/8, ra_rnti, ack, tti); + } + + if (ack) { rDebug("RAR decoded successfully TBS=%d\n", rar_grant.get_tbs()); rar_pdu_msg.init(rar_grant.get_tbs()/8); diff --git a/srsapps/ue/mac/src/ul_harq.cc b/srsapps/ue/mac/src/ul_harq.cc index a964a51b4..05560f89f 100644 --- a/srsapps/ue/mac/src/ul_harq.cc +++ b/srsapps/ue/mac/src/ul_harq.cc @@ -57,6 +57,12 @@ bool ul_harq_entity::init(srslte_cell_t cell, mac_params *params_db_, log *log_h uint32_t ul_harq_entity::pidof(uint32_t tti) { return (uint32_t) tti%NOF_HARQ_PROC; } + +void ul_harq_entity::start_pcap(mac_pcap* pcap_) +{ + pcap = pcap_; +} + void ul_harq_entity::reset() { for (uint32_t i=0;iset_current_tx_nb(current_tx_nb); ul->generate_data(&cur_grant, &softbuffer, pdu_payload); + if (harq_entity->pcap) { + harq_entity->pcap->write_ul_crnti(pdu_payload, cur_grant.get_tbs()/8, cur_grant.get_rnti(), current_tx_nb, tti_tx); + } + current_irv = (current_irv+1)%4; tti_last_tx = tti_tx; if (is_msg3) { diff --git a/srsapps/ue/mac/test/mac_test.cc b/srsapps/ue/mac/test/mac_test.cc index 690ab8ebd..26e142219 100644 --- a/srsapps/ue/mac/test/mac_test.cc +++ b/srsapps/ue/mac/test/mac_test.cc @@ -35,6 +35,7 @@ #include "srsapps/common/tti_sync_cv.h" #include "srsapps/common/log_stdout.h" #include "srsapps/ue/mac/mac.h" +#include "srsapps/ue/mac/mac_pcap.h" @@ -48,6 +49,7 @@ typedef struct { float uhd_tx_gain; int verbose; bool do_trace; + bool do_pcap; }prog_args_t; void args_default(prog_args_t *args) { @@ -57,20 +59,22 @@ void args_default(prog_args_t *args) { args->uhd_tx_gain = -1; args->verbose = 0; args->do_trace = false; + args->do_pcap = false; } void usage(prog_args_t *args, char *prog) { - printf("Usage: %s [gGtv] -f rx_frequency (in Hz) -F tx_frequency (in Hz)\n", prog); + printf("Usage: %s [gGtpv] -f rx_frequency (in Hz) -F tx_frequency (in Hz)\n", prog); printf("\t-g UHD RX gain [Default AGC]\n"); printf("\t-G UHD TX gain [Default same as RX gain (AGC)]\n"); printf("\t-t Enable trace [Default disabled]\n"); + printf("\t-p Enable PCAP capture [Default disabled]\n"); printf("\t-v [increase verbosity, default none]\n"); } void parse_args(prog_args_t *args, int argc, char **argv) { int opt; args_default(args); - while ((opt = getopt(argc, argv, "gGftFv")) != -1) { + while ((opt = getopt(argc, argv, "gGftpFv")) != -1) { switch (opt) { case 'g': args->uhd_rx_gain = atof(argv[optind]); @@ -87,6 +91,9 @@ void parse_args(prog_args_t *args, int argc, char **argv) { case 't': args->do_trace = true; break; + case 'p': + args->do_pcap = true; + break; case 'v': args->verbose++; break; @@ -307,6 +314,7 @@ uint8_t reply[2] = {0x00, 0x04}; srslte::radio_uhd radio_uhd; srslte::ue::phy phy; srslte::ue::mac mac; +srslte::ue::mac_pcap mac_pcap; prog_args_t prog_args; @@ -317,6 +325,9 @@ void sig_int_handler(int signo) phy.write_trace("phy"); mac.write_trace("mac"); } + if (prog_args.do_pcap) { + mac_pcap.close(); + } mac.stop(); exit(0); } @@ -341,13 +352,21 @@ int main(int argc, char *argv[]) } // Capture SIGINT to write traces - signal(SIGINT, sig_int_handler); if (prog_args.do_trace) { + signal(SIGINT, sig_int_handler); //radio_uhd.start_trace(); phy.start_trace(); mac.start_trace(); } + if (prog_args.do_pcap) { + if (!prog_args.do_trace) { + signal(SIGINT, sig_int_handler); + } + mac_pcap.open("/tmp/ue_mac.pcap"); + mac.start_pcap(&mac_pcap); + } + // Init Radio and PHY if (prog_args.uhd_rx_gain > 0 && prog_args.uhd_tx_gain > 0) { radio_uhd.init(); @@ -360,7 +379,7 @@ int main(int argc, char *argv[]) phy.init_agc(&radio_uhd, &ttisync, &phy_log); } // Init MAC - mac.init(&phy, &ttisync, &mac_log, true); + mac.init(&phy, &ttisync, &mac_log); // Set RX freq radio_uhd.set_rx_freq(prog_args.uhd_rx_freq);