MAC PCAP move run thread in base class

master
David Rupprecht 4 years ago committed by Andre Puschmann
parent 894e4d3501
commit 9e72d89fa1

@ -28,7 +28,6 @@ public:
private: private:
void write_pdu(srslte::mac_pcap_base::pcap_pdu_t& pdu); void write_pdu(srslte::mac_pcap_base::pcap_pdu_t& pdu);
void run_thread() final;
FILE* pcap_file = nullptr; FILE* pcap_file = nullptr;
uint32_t dlt = 0; // The DLT used for the PCAP file uint32_t dlt = 0; // The DLT used for the PCAP file

@ -91,7 +91,7 @@ protected:
} pcap_pdu_t; } pcap_pdu_t;
virtual void write_pdu(pcap_pdu_t& pdu) = 0; virtual void write_pdu(pcap_pdu_t& pdu) = 0;
virtual void run_thread() = 0; void run_thread() final;
std::mutex mutex; std::mutex mutex;
srslog::basic_logger& logger; srslog::basic_logger& logger;

@ -35,7 +35,6 @@ private:
void write_pdu(srslte::mac_pcap_base::pcap_pdu_t& pdu); void write_pdu(srslte::mac_pcap_base::pcap_pdu_t& pdu);
void write_mac_lte_pdu_to_net(srslte::mac_pcap_base::pcap_pdu_t& pdu); void write_mac_lte_pdu_to_net(srslte::mac_pcap_base::pcap_pdu_t& pdu);
void write_mac_nr_pdu_to_net(srslte::mac_pcap_base::pcap_pdu_t& pdu); void write_mac_nr_pdu_to_net(srslte::mac_pcap_base::pcap_pdu_t& pdu);
void run_thread() final;
srslte::socket_handler_t socket; srslte::socket_handler_t socket;
struct sockaddr_in client_addr; struct sockaddr_in client_addr;

@ -47,25 +47,6 @@ uint32_t mac_pcap::open(std::string filename_, uint32_t ue_id_)
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
void mac_pcap::run_thread()
{
// blocking write until stopped
while (running) {
pcap_pdu_t pdu = queue.wait_pop();
{
std::lock_guard<std::mutex> lock(mutex);
write_pdu(pdu);
}
}
// write remainder of queue
std::lock_guard<std::mutex> lock(mutex);
pcap_pdu_t pdu = {};
while (queue.try_pop(&pdu)) {
write_pdu(pdu);
}
}
uint32_t mac_pcap::close() uint32_t mac_pcap::close()
{ {
{ {

@ -33,6 +33,25 @@ void mac_pcap_base::set_ue_id(uint16_t ue_id_)
ue_id = ue_id_; ue_id = ue_id_;
} }
void mac_pcap_base::run_thread()
{
// blocking write until stopped
while (running) {
pcap_pdu_t pdu = queue.wait_pop();
{
std::lock_guard<std::mutex> lock(mutex);
write_pdu(pdu);
}
}
// write remainder of queue
std::lock_guard<std::mutex> lock(mutex);
pcap_pdu_t pdu = {};
while (queue.try_pop(&pdu)) {
write_pdu(pdu);
}
}
// Function called from PHY worker context, locking not needed as PDU queue is thread-safe // Function called from PHY worker context, locking not needed as PDU queue is thread-safe
void mac_pcap_base::pack_and_queue(uint8_t* payload, void mac_pcap_base::pack_and_queue(uint8_t* payload,
uint32_t payload_len, uint32_t payload_len,

@ -79,25 +79,6 @@ uint32_t mac_pcap_net::close()
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
void mac_pcap_net::run_thread()
{
// blocking write until stopped
while (running) {
pcap_pdu_t pdu = queue.wait_pop();
{
std::lock_guard<std::mutex> lock(mutex);
write_pdu(pdu);
}
}
// write remainder of queue
std::lock_guard<std::mutex> lock(mutex);
pcap_pdu_t pdu = {};
while (queue.try_pop(&pdu)) {
write_pdu(pdu);
}
}
void mac_pcap_net::write_pdu(pcap_pdu_t& pdu) void mac_pcap_net::write_pdu(pcap_pdu_t& pdu)
{ {
if (pdu.pdu != nullptr && socket.is_init()) { if (pdu.pdu != nullptr && socket.is_init()) {

Loading…
Cancel
Save