+ tx_queue->tx_stat.pkts += num_tx;
+ tx_queue->tx_stat.bytes += tx_bytes;
+ tx_queue->tx_stat.err_pkts += i - num_tx;
+
+ return i;
+}
+
+/*
+ * pcap_open_live wrapper function
+ */
+static inline int
+open_iface_live(const char *iface, pcap_t **pcap) {
+ *pcap = pcap_open_live(iface, RTE_ETH_PCAP_SNAPLEN,
+ RTE_ETH_PCAP_PROMISC, RTE_ETH_PCAP_TIMEOUT, errbuf);
+
+ if (*pcap == NULL) {
+ PMD_LOG(ERR, "Couldn't open %s: %s", iface, errbuf);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
+open_single_iface(const char *iface, pcap_t **pcap)
+{
+ if (open_iface_live(iface, pcap) < 0) {
+ PMD_LOG(ERR, "Couldn't open interface %s", iface);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
+open_single_tx_pcap(const char *pcap_filename, pcap_dumper_t **dumper)
+{
+ pcap_t *tx_pcap;
+
+ /*
+ * We need to create a dummy empty pcap_t to use it
+ * with pcap_dump_open(). We create big enough an Ethernet
+ * pcap holder.
+ */
+ tx_pcap = pcap_open_dead_with_tstamp_precision(DLT_EN10MB,
+ RTE_ETH_PCAP_SNAPSHOT_LEN, PCAP_TSTAMP_PRECISION_NANO);
+ if (tx_pcap == NULL) {
+ PMD_LOG(ERR, "Couldn't create dead pcap");
+ return -1;
+ }
+
+ /* The dumper is created using the previous pcap_t reference */
+ *dumper = pcap_dump_open(tx_pcap, pcap_filename);
+ if (*dumper == NULL) {
+ pcap_close(tx_pcap);
+ PMD_LOG(ERR, "Couldn't open %s for writing.",
+ pcap_filename);
+ return -1;
+ }
+
+ pcap_close(tx_pcap);
+ return 0;
+}
+
+static int
+open_single_rx_pcap(const char *pcap_filename, pcap_t **pcap)
+{
+ *pcap = pcap_open_offline(pcap_filename, errbuf);
+ if (*pcap == NULL) {
+ PMD_LOG(ERR, "Couldn't open %s: %s", pcap_filename,
+ errbuf);
+ return -1;
+ }
+
+ return 0;
+}
+
+static uint64_t
+count_packets_in_pcap(pcap_t **pcap, struct pcap_rx_queue *pcap_q)
+{
+ const u_char *packet;
+ struct pcap_pkthdr header;
+ uint64_t pcap_pkt_count = 0;
+
+ while ((packet = pcap_next(*pcap, &header)))
+ pcap_pkt_count++;
+
+ /* The pcap is reopened so it can be used as normal later. */
+ pcap_close(*pcap);
+ *pcap = NULL;
+ open_single_rx_pcap(pcap_q->name, pcap);
+
+ return pcap_pkt_count;