1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation.
3 * Copyright(c) 2014 6WIND S.A.
10 #include <sys/socket.h>
11 #include <sys/ioctl.h>
14 #if defined(RTE_EXEC_ENV_FREEBSD)
15 #include <sys/sysctl.h>
16 #include <net/if_dl.h>
21 #include <rte_cycles.h>
22 #include <ethdev_driver.h>
23 #include <ethdev_vdev.h>
24 #include <rte_kvargs.h>
25 #include <rte_malloc.h>
27 #include <rte_bus_vdev.h>
28 #include <rte_string_fns.h>
30 #define RTE_ETH_PCAP_SNAPSHOT_LEN 65535
31 #define RTE_ETH_PCAP_SNAPLEN RTE_ETHER_MAX_JUMBO_FRAME_LEN
32 #define RTE_ETH_PCAP_PROMISC 1
33 #define RTE_ETH_PCAP_TIMEOUT -1
35 #define ETH_PCAP_RX_PCAP_ARG "rx_pcap"
36 #define ETH_PCAP_TX_PCAP_ARG "tx_pcap"
37 #define ETH_PCAP_RX_IFACE_ARG "rx_iface"
38 #define ETH_PCAP_RX_IFACE_IN_ARG "rx_iface_in"
39 #define ETH_PCAP_TX_IFACE_ARG "tx_iface"
40 #define ETH_PCAP_IFACE_ARG "iface"
41 #define ETH_PCAP_PHY_MAC_ARG "phy_mac"
42 #define ETH_PCAP_INFINITE_RX_ARG "infinite_rx"
44 #define ETH_PCAP_ARG_MAXLEN 64
46 #define RTE_PMD_PCAP_MAX_QUEUES 16
48 static char errbuf[PCAP_ERRBUF_SIZE];
49 static struct timeval start_time;
50 static uint64_t start_cycles;
52 static uint8_t iface_idx;
54 static uint64_t timestamp_rx_dynflag;
55 static int timestamp_dynfield_offset = -1;
58 volatile unsigned long pkts;
59 volatile unsigned long bytes;
60 volatile unsigned long err_pkts;
63 struct queue_missed_stat {
64 /* last value retrieved from pcap */
66 /* stores values lost by pcap stop or rollover */
67 unsigned long mnemonic;
68 /* value on last reset */
72 struct pcap_rx_queue {
75 struct rte_mempool *mb_pool;
76 struct queue_stat rx_stat;
77 struct queue_missed_stat missed_stat;
79 char type[ETH_PCAP_ARG_MAXLEN];
81 /* Contains pre-generated packets to be looped through */
82 struct rte_ring *pkts;
85 struct pcap_tx_queue {
88 struct queue_stat tx_stat;
90 char type[ETH_PCAP_ARG_MAXLEN];
93 struct pmd_internals {
94 struct pcap_rx_queue rx_queue[RTE_PMD_PCAP_MAX_QUEUES];
95 struct pcap_tx_queue tx_queue[RTE_PMD_PCAP_MAX_QUEUES];
96 char devargs[ETH_PCAP_ARG_MAXLEN];
97 struct rte_ether_addr eth_addr;
101 unsigned int infinite_rx;
104 struct pmd_process_private {
105 pcap_t *rx_pcap[RTE_PMD_PCAP_MAX_QUEUES];
106 pcap_t *tx_pcap[RTE_PMD_PCAP_MAX_QUEUES];
107 pcap_dumper_t *tx_dumper[RTE_PMD_PCAP_MAX_QUEUES];
111 unsigned int num_of_queue;
112 struct devargs_queue {
113 pcap_dumper_t *dumper;
117 } queue[RTE_PMD_PCAP_MAX_QUEUES];
121 struct pmd_devargs_all {
122 struct pmd_devargs rx_queues;
123 struct pmd_devargs tx_queues;
125 unsigned int is_tx_pcap;
126 unsigned int is_tx_iface;
127 unsigned int is_rx_pcap;
128 unsigned int is_rx_iface;
129 unsigned int infinite_rx;
132 static const char *valid_arguments[] = {
133 ETH_PCAP_RX_PCAP_ARG,
134 ETH_PCAP_TX_PCAP_ARG,
135 ETH_PCAP_RX_IFACE_ARG,
136 ETH_PCAP_RX_IFACE_IN_ARG,
137 ETH_PCAP_TX_IFACE_ARG,
139 ETH_PCAP_PHY_MAC_ARG,
140 ETH_PCAP_INFINITE_RX_ARG,
144 static struct rte_eth_link pmd_link = {
145 .link_speed = ETH_SPEED_NUM_10G,
146 .link_duplex = ETH_LINK_FULL_DUPLEX,
147 .link_status = ETH_LINK_DOWN,
148 .link_autoneg = ETH_LINK_FIXED,
151 RTE_LOG_REGISTER(eth_pcap_logtype, pmd.net.pcap, NOTICE);
153 #define PMD_LOG(level, fmt, args...) \
154 rte_log(RTE_LOG_ ## level, eth_pcap_logtype, \
155 "%s(): " fmt "\n", __func__, ##args)
157 static struct queue_missed_stat*
158 queue_missed_stat_update(struct rte_eth_dev *dev, unsigned int qid)
160 struct pmd_internals *internals = dev->data->dev_private;
161 struct queue_missed_stat *missed_stat =
162 &internals->rx_queue[qid].missed_stat;
163 const struct pmd_process_private *pp = dev->process_private;
164 pcap_t *pcap = pp->rx_pcap[qid];
165 struct pcap_stat stat;
167 if (!pcap || (pcap_stats(pcap, &stat) != 0))
170 /* rollover check - best effort fixup assuming single rollover */
171 if (stat.ps_drop < missed_stat->pcap)
172 missed_stat->mnemonic += UINT_MAX;
173 missed_stat->pcap = stat.ps_drop;
179 queue_missed_stat_on_stop_update(struct rte_eth_dev *dev, unsigned int qid)
181 struct queue_missed_stat *missed_stat =
182 queue_missed_stat_update(dev, qid);
184 missed_stat->mnemonic += missed_stat->pcap;
185 missed_stat->pcap = 0;
189 queue_missed_stat_reset(struct rte_eth_dev *dev, unsigned int qid)
191 struct queue_missed_stat *missed_stat =
192 queue_missed_stat_update(dev, qid);
194 missed_stat->reset = missed_stat->pcap;
195 missed_stat->mnemonic = 0;
199 queue_missed_stat_get(struct rte_eth_dev *dev, unsigned int qid)
201 const struct queue_missed_stat *missed_stat =
202 queue_missed_stat_update(dev, qid);
204 return missed_stat->pcap + missed_stat->mnemonic - missed_stat->reset;
208 eth_pcap_rx_jumbo(struct rte_mempool *mb_pool, struct rte_mbuf *mbuf,
209 const u_char *data, uint16_t data_len)
211 /* Copy the first segment. */
212 uint16_t len = rte_pktmbuf_tailroom(mbuf);
213 struct rte_mbuf *m = mbuf;
215 rte_memcpy(rte_pktmbuf_append(mbuf, len), data, len);
219 while (data_len > 0) {
220 /* Allocate next mbuf and point to that. */
221 m->next = rte_pktmbuf_alloc(mb_pool);
223 if (unlikely(!m->next))
228 /* Headroom is not needed in chained mbufs. */
229 rte_pktmbuf_prepend(m, rte_pktmbuf_headroom(m));
233 /* Copy next segment. */
234 len = RTE_MIN(rte_pktmbuf_tailroom(m), data_len);
235 rte_memcpy(rte_pktmbuf_append(m, len), data, len);
242 return mbuf->nb_segs;
246 eth_pcap_rx_infinite(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
249 struct pcap_rx_queue *pcap_q = queue;
250 uint32_t rx_bytes = 0;
252 if (unlikely(nb_pkts == 0))
255 if (rte_pktmbuf_alloc_bulk(pcap_q->mb_pool, bufs, nb_pkts) != 0)
258 for (i = 0; i < nb_pkts; i++) {
259 struct rte_mbuf *pcap_buf;
260 int err = rte_ring_dequeue(pcap_q->pkts, (void **)&pcap_buf);
264 rte_memcpy(rte_pktmbuf_mtod(bufs[i], void *),
265 rte_pktmbuf_mtod(pcap_buf, void *),
267 bufs[i]->data_len = pcap_buf->data_len;
268 bufs[i]->pkt_len = pcap_buf->pkt_len;
269 bufs[i]->port = pcap_q->port_id;
270 rx_bytes += pcap_buf->data_len;
272 /* Enqueue packet back on ring to allow infinite rx. */
273 rte_ring_enqueue(pcap_q->pkts, pcap_buf);
276 pcap_q->rx_stat.pkts += i;
277 pcap_q->rx_stat.bytes += rx_bytes;
283 eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
286 struct pcap_pkthdr header;
287 struct pmd_process_private *pp;
288 const u_char *packet;
289 struct rte_mbuf *mbuf;
290 struct pcap_rx_queue *pcap_q = queue;
292 uint32_t rx_bytes = 0;
295 pp = rte_eth_devices[pcap_q->port_id].process_private;
296 pcap = pp->rx_pcap[pcap_q->queue_id];
298 if (unlikely(pcap == NULL || nb_pkts == 0))
301 /* Reads the given number of packets from the pcap file one by one
302 * and copies the packet data into a newly allocated mbuf to return.
304 for (i = 0; i < nb_pkts; i++) {
305 /* Get the next PCAP packet */
306 packet = pcap_next(pcap, &header);
307 if (unlikely(packet == NULL))
310 mbuf = rte_pktmbuf_alloc(pcap_q->mb_pool);
311 if (unlikely(mbuf == NULL))
314 if (header.caplen <= rte_pktmbuf_tailroom(mbuf)) {
315 /* pcap packet will fit in the mbuf, can copy it */
316 rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet,
318 mbuf->data_len = (uint16_t)header.caplen;
320 /* Try read jumbo frame into multi mbufs. */
321 if (unlikely(eth_pcap_rx_jumbo(pcap_q->mb_pool,
324 header.caplen) == -1)) {
325 rte_pktmbuf_free(mbuf);
330 mbuf->pkt_len = (uint16_t)header.caplen;
331 *RTE_MBUF_DYNFIELD(mbuf, timestamp_dynfield_offset,
332 rte_mbuf_timestamp_t *) =
333 (uint64_t)header.ts.tv_sec * 1000000 +
335 mbuf->ol_flags |= timestamp_rx_dynflag;
336 mbuf->port = pcap_q->port_id;
339 rx_bytes += header.caplen;
341 pcap_q->rx_stat.pkts += num_rx;
342 pcap_q->rx_stat.bytes += rx_bytes;
348 eth_null_rx(void *queue __rte_unused,
349 struct rte_mbuf **bufs __rte_unused,
350 uint16_t nb_pkts __rte_unused)
355 #define NSEC_PER_SEC 1000000000L
358 calculate_timestamp(struct timeval *ts) {
360 struct timeval cur_time;
362 cycles = rte_get_timer_cycles() - start_cycles;
363 cur_time.tv_sec = cycles / hz;
364 cur_time.tv_usec = (cycles % hz) * NSEC_PER_SEC / hz;
366 ts->tv_sec = start_time.tv_sec + cur_time.tv_sec;
367 ts->tv_usec = start_time.tv_usec + cur_time.tv_usec;
368 if (ts->tv_usec >= NSEC_PER_SEC) {
369 ts->tv_usec -= NSEC_PER_SEC;
375 * Callback to handle writing packets to a pcap file.
378 eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
381 struct rte_mbuf *mbuf;
382 struct pmd_process_private *pp;
383 struct pcap_tx_queue *dumper_q = queue;
385 uint32_t tx_bytes = 0;
386 struct pcap_pkthdr header;
387 pcap_dumper_t *dumper;
388 unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
391 pp = rte_eth_devices[dumper_q->port_id].process_private;
392 dumper = pp->tx_dumper[dumper_q->queue_id];
394 if (dumper == NULL || nb_pkts == 0)
397 /* writes the nb_pkts packets to the previously opened pcap file
399 for (i = 0; i < nb_pkts; i++) {
401 len = caplen = rte_pktmbuf_pkt_len(mbuf);
402 if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
403 len > sizeof(temp_data))) {
404 caplen = sizeof(temp_data);
407 calculate_timestamp(&header.ts);
409 header.caplen = caplen;
410 /* rte_pktmbuf_read() returns a pointer to the data directly
411 * in the mbuf (when the mbuf is contiguous) or, otherwise,
412 * a pointer to temp_data after copying into it.
414 pcap_dump((u_char *)dumper, &header,
415 rte_pktmbuf_read(mbuf, 0, caplen, temp_data));
419 rte_pktmbuf_free(mbuf);
423 * Since there's no place to hook a callback when the forwarding
424 * process stops and to make sure the pcap file is actually written,
425 * we flush the pcap dumper within each burst.
427 pcap_dump_flush(dumper);
428 dumper_q->tx_stat.pkts += num_tx;
429 dumper_q->tx_stat.bytes += tx_bytes;
430 dumper_q->tx_stat.err_pkts += nb_pkts - num_tx;
436 * Callback to handle dropping packets in the infinite rx case.
439 eth_tx_drop(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
442 uint32_t tx_bytes = 0;
443 struct pcap_tx_queue *tx_queue = queue;
445 if (unlikely(nb_pkts == 0))
448 for (i = 0; i < nb_pkts; i++) {
449 tx_bytes += bufs[i]->pkt_len;
450 rte_pktmbuf_free(bufs[i]);
453 tx_queue->tx_stat.pkts += nb_pkts;
454 tx_queue->tx_stat.bytes += tx_bytes;
460 * Callback to handle sending packets through a real NIC.
463 eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
467 struct rte_mbuf *mbuf;
468 struct pmd_process_private *pp;
469 struct pcap_tx_queue *tx_queue = queue;
471 uint32_t tx_bytes = 0;
473 unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN];
476 pp = rte_eth_devices[tx_queue->port_id].process_private;
477 pcap = pp->tx_pcap[tx_queue->queue_id];
479 if (unlikely(nb_pkts == 0 || pcap == NULL))
482 for (i = 0; i < nb_pkts; i++) {
484 len = rte_pktmbuf_pkt_len(mbuf);
485 if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) &&
486 len > sizeof(temp_data))) {
488 "Dropping multi segment PCAP packet. Size (%zd) > max size (%zd).",
489 len, sizeof(temp_data));
490 rte_pktmbuf_free(mbuf);
494 /* rte_pktmbuf_read() returns a pointer to the data directly
495 * in the mbuf (when the mbuf is contiguous) or, otherwise,
496 * a pointer to temp_data after copying into it.
498 ret = pcap_sendpacket(pcap,
499 rte_pktmbuf_read(mbuf, 0, len, temp_data), len);
500 if (unlikely(ret != 0))
504 rte_pktmbuf_free(mbuf);
507 tx_queue->tx_stat.pkts += num_tx;
508 tx_queue->tx_stat.bytes += tx_bytes;
509 tx_queue->tx_stat.err_pkts += i - num_tx;
515 * pcap_open_live wrapper function
518 open_iface_live(const char *iface, pcap_t **pcap) {
519 *pcap = pcap_open_live(iface, RTE_ETH_PCAP_SNAPLEN,
520 RTE_ETH_PCAP_PROMISC, RTE_ETH_PCAP_TIMEOUT, errbuf);
523 PMD_LOG(ERR, "Couldn't open %s: %s", iface, errbuf);
531 open_single_iface(const char *iface, pcap_t **pcap)
533 if (open_iface_live(iface, pcap) < 0) {
534 PMD_LOG(ERR, "Couldn't open interface %s", iface);
542 open_single_tx_pcap(const char *pcap_filename, pcap_dumper_t **dumper)
547 * We need to create a dummy empty pcap_t to use it
548 * with pcap_dump_open(). We create big enough an Ethernet
551 tx_pcap = pcap_open_dead_with_tstamp_precision(DLT_EN10MB,
552 RTE_ETH_PCAP_SNAPSHOT_LEN, PCAP_TSTAMP_PRECISION_NANO);
553 if (tx_pcap == NULL) {
554 PMD_LOG(ERR, "Couldn't create dead pcap");
558 /* The dumper is created using the previous pcap_t reference */
559 *dumper = pcap_dump_open(tx_pcap, pcap_filename);
560 if (*dumper == NULL) {
562 PMD_LOG(ERR, "Couldn't open %s for writing.",
572 open_single_rx_pcap(const char *pcap_filename, pcap_t **pcap)
574 *pcap = pcap_open_offline(pcap_filename, errbuf);
576 PMD_LOG(ERR, "Couldn't open %s: %s", pcap_filename,
585 count_packets_in_pcap(pcap_t **pcap, struct pcap_rx_queue *pcap_q)
587 const u_char *packet;
588 struct pcap_pkthdr header;
589 uint64_t pcap_pkt_count = 0;
591 while ((packet = pcap_next(*pcap, &header)))
594 /* The pcap is reopened so it can be used as normal later. */
597 open_single_rx_pcap(pcap_q->name, pcap);
599 return pcap_pkt_count;
603 eth_dev_start(struct rte_eth_dev *dev)
606 struct pmd_internals *internals = dev->data->dev_private;
607 struct pmd_process_private *pp = dev->process_private;
608 struct pcap_tx_queue *tx;
609 struct pcap_rx_queue *rx;
611 /* Special iface case. Single pcap is open and shared between tx/rx. */
612 if (internals->single_iface) {
613 tx = &internals->tx_queue[0];
614 rx = &internals->rx_queue[0];
616 if (!pp->tx_pcap[0] &&
617 strcmp(tx->type, ETH_PCAP_IFACE_ARG) == 0) {
618 if (open_single_iface(tx->name, &pp->tx_pcap[0]) < 0)
620 pp->rx_pcap[0] = pp->tx_pcap[0];
626 /* If not open already, open tx pcaps/dumpers */
627 for (i = 0; i < dev->data->nb_tx_queues; i++) {
628 tx = &internals->tx_queue[i];
630 if (!pp->tx_dumper[i] &&
631 strcmp(tx->type, ETH_PCAP_TX_PCAP_ARG) == 0) {
632 if (open_single_tx_pcap(tx->name,
633 &pp->tx_dumper[i]) < 0)
635 } else if (!pp->tx_pcap[i] &&
636 strcmp(tx->type, ETH_PCAP_TX_IFACE_ARG) == 0) {
637 if (open_single_iface(tx->name, &pp->tx_pcap[i]) < 0)
642 /* If not open already, open rx pcaps */
643 for (i = 0; i < dev->data->nb_rx_queues; i++) {
644 rx = &internals->rx_queue[i];
646 if (pp->rx_pcap[i] != NULL)
649 if (strcmp(rx->type, ETH_PCAP_RX_PCAP_ARG) == 0) {
650 if (open_single_rx_pcap(rx->name, &pp->rx_pcap[i]) < 0)
652 } else if (strcmp(rx->type, ETH_PCAP_RX_IFACE_ARG) == 0) {
653 if (open_single_iface(rx->name, &pp->rx_pcap[i]) < 0)
659 for (i = 0; i < dev->data->nb_rx_queues; i++)
660 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
662 for (i = 0; i < dev->data->nb_tx_queues; i++)
663 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
665 dev->data->dev_link.link_status = ETH_LINK_UP;
671 * This function gets called when the current port gets stopped.
672 * Is the only place for us to close all the tx streams dumpers.
673 * If not called the dumpers will be flushed within each tx burst.
676 eth_dev_stop(struct rte_eth_dev *dev)
679 struct pmd_internals *internals = dev->data->dev_private;
680 struct pmd_process_private *pp = dev->process_private;
682 /* Special iface case. Single pcap is open and shared between tx/rx. */
683 if (internals->single_iface) {
684 queue_missed_stat_on_stop_update(dev, 0);
685 pcap_close(pp->tx_pcap[0]);
686 pp->tx_pcap[0] = NULL;
687 pp->rx_pcap[0] = NULL;
691 for (i = 0; i < dev->data->nb_tx_queues; i++) {
692 if (pp->tx_dumper[i] != NULL) {
693 pcap_dump_close(pp->tx_dumper[i]);
694 pp->tx_dumper[i] = NULL;
697 if (pp->tx_pcap[i] != NULL) {
698 pcap_close(pp->tx_pcap[i]);
699 pp->tx_pcap[i] = NULL;
703 for (i = 0; i < dev->data->nb_rx_queues; i++) {
704 if (pp->rx_pcap[i] != NULL) {
705 queue_missed_stat_on_stop_update(dev, i);
706 pcap_close(pp->rx_pcap[i]);
707 pp->rx_pcap[i] = NULL;
712 for (i = 0; i < dev->data->nb_rx_queues; i++)
713 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
715 for (i = 0; i < dev->data->nb_tx_queues; i++)
716 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
718 dev->data->dev_link.link_status = ETH_LINK_DOWN;
724 eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
730 eth_dev_info(struct rte_eth_dev *dev,
731 struct rte_eth_dev_info *dev_info)
733 struct pmd_internals *internals = dev->data->dev_private;
735 dev_info->if_index = internals->if_index;
736 dev_info->max_mac_addrs = 1;
737 dev_info->max_rx_pktlen = (uint32_t) -1;
738 dev_info->max_rx_queues = dev->data->nb_rx_queues;
739 dev_info->max_tx_queues = dev->data->nb_tx_queues;
740 dev_info->min_rx_bufsize = 0;
746 eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
749 unsigned long rx_packets_total = 0, rx_bytes_total = 0;
750 unsigned long rx_missed_total = 0;
751 unsigned long tx_packets_total = 0, tx_bytes_total = 0;
752 unsigned long tx_packets_err_total = 0;
753 const struct pmd_internals *internal = dev->data->dev_private;
755 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS &&
756 i < dev->data->nb_rx_queues; i++) {
757 stats->q_ipackets[i] = internal->rx_queue[i].rx_stat.pkts;
758 stats->q_ibytes[i] = internal->rx_queue[i].rx_stat.bytes;
759 rx_packets_total += stats->q_ipackets[i];
760 rx_bytes_total += stats->q_ibytes[i];
761 rx_missed_total += queue_missed_stat_get(dev, i);
764 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS &&
765 i < dev->data->nb_tx_queues; i++) {
766 stats->q_opackets[i] = internal->tx_queue[i].tx_stat.pkts;
767 stats->q_obytes[i] = internal->tx_queue[i].tx_stat.bytes;
768 tx_packets_total += stats->q_opackets[i];
769 tx_bytes_total += stats->q_obytes[i];
770 tx_packets_err_total += internal->tx_queue[i].tx_stat.err_pkts;
773 stats->ipackets = rx_packets_total;
774 stats->ibytes = rx_bytes_total;
775 stats->imissed = rx_missed_total;
776 stats->opackets = tx_packets_total;
777 stats->obytes = tx_bytes_total;
778 stats->oerrors = tx_packets_err_total;
784 eth_stats_reset(struct rte_eth_dev *dev)
787 struct pmd_internals *internal = dev->data->dev_private;
789 for (i = 0; i < dev->data->nb_rx_queues; i++) {
790 internal->rx_queue[i].rx_stat.pkts = 0;
791 internal->rx_queue[i].rx_stat.bytes = 0;
792 queue_missed_stat_reset(dev, i);
795 for (i = 0; i < dev->data->nb_tx_queues; i++) {
796 internal->tx_queue[i].tx_stat.pkts = 0;
797 internal->tx_queue[i].tx_stat.bytes = 0;
798 internal->tx_queue[i].tx_stat.err_pkts = 0;
805 infinite_rx_ring_free(struct rte_ring *pkts)
807 struct rte_mbuf *bufs;
809 while (!rte_ring_dequeue(pkts, (void **)&bufs))
810 rte_pktmbuf_free(bufs);
816 eth_dev_close(struct rte_eth_dev *dev)
819 struct pmd_internals *internals = dev->data->dev_private;
821 PMD_LOG(INFO, "Closing pcap ethdev on NUMA socket %d",
824 rte_free(dev->process_private);
826 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
829 /* Device wide flag, but cleanup must be performed per queue. */
830 if (internals->infinite_rx) {
831 for (i = 0; i < dev->data->nb_rx_queues; i++) {
832 struct pcap_rx_queue *pcap_q = &internals->rx_queue[i];
835 * 'pcap_q->pkts' can be NULL if 'eth_dev_close()'
836 * called before 'eth_rx_queue_setup()' has been called
838 if (pcap_q->pkts == NULL)
841 infinite_rx_ring_free(pcap_q->pkts);
845 if (internals->phy_mac == 0)
846 /* not dynamically allocated, must not be freed */
847 dev->data->mac_addrs = NULL;
853 eth_queue_release(void *q __rte_unused)
858 eth_link_update(struct rte_eth_dev *dev __rte_unused,
859 int wait_to_complete __rte_unused)
865 eth_rx_queue_setup(struct rte_eth_dev *dev,
866 uint16_t rx_queue_id,
867 uint16_t nb_rx_desc __rte_unused,
868 unsigned int socket_id __rte_unused,
869 const struct rte_eth_rxconf *rx_conf __rte_unused,
870 struct rte_mempool *mb_pool)
872 struct pmd_internals *internals = dev->data->dev_private;
873 struct pcap_rx_queue *pcap_q = &internals->rx_queue[rx_queue_id];
875 pcap_q->mb_pool = mb_pool;
876 pcap_q->port_id = dev->data->port_id;
877 pcap_q->queue_id = rx_queue_id;
878 dev->data->rx_queues[rx_queue_id] = pcap_q;
880 if (internals->infinite_rx) {
881 struct pmd_process_private *pp;
882 char ring_name[NAME_MAX];
883 static uint32_t ring_number;
884 uint64_t pcap_pkt_count = 0;
885 struct rte_mbuf *bufs[1];
888 pp = rte_eth_devices[pcap_q->port_id].process_private;
889 pcap = &pp->rx_pcap[pcap_q->queue_id];
891 if (unlikely(*pcap == NULL))
894 pcap_pkt_count = count_packets_in_pcap(pcap, pcap_q);
896 snprintf(ring_name, sizeof(ring_name), "PCAP_RING%" PRIu32,
899 pcap_q->pkts = rte_ring_create(ring_name,
900 rte_align64pow2(pcap_pkt_count + 1), 0,
901 RING_F_SP_ENQ | RING_F_SC_DEQ);
906 /* Fill ring with packets from PCAP file one by one. */
907 while (eth_pcap_rx(pcap_q, bufs, 1)) {
908 /* Check for multiseg mbufs. */
909 if (bufs[0]->nb_segs != 1) {
910 infinite_rx_ring_free(pcap_q->pkts);
912 "Multiseg mbufs are not supported in infinite_rx mode.");
916 rte_ring_enqueue_bulk(pcap_q->pkts,
917 (void * const *)bufs, 1, NULL);
920 if (rte_ring_count(pcap_q->pkts) < pcap_pkt_count) {
921 infinite_rx_ring_free(pcap_q->pkts);
923 "Not enough mbufs to accommodate packets in pcap file. "
924 "At least %" PRIu64 " mbufs per queue is required.",
930 * Reset the stats for this queue since eth_pcap_rx calls above
931 * didn't result in the application receiving packets.
933 pcap_q->rx_stat.pkts = 0;
934 pcap_q->rx_stat.bytes = 0;
941 eth_tx_queue_setup(struct rte_eth_dev *dev,
942 uint16_t tx_queue_id,
943 uint16_t nb_tx_desc __rte_unused,
944 unsigned int socket_id __rte_unused,
945 const struct rte_eth_txconf *tx_conf __rte_unused)
947 struct pmd_internals *internals = dev->data->dev_private;
948 struct pcap_tx_queue *pcap_q = &internals->tx_queue[tx_queue_id];
950 pcap_q->port_id = dev->data->port_id;
951 pcap_q->queue_id = tx_queue_id;
952 dev->data->tx_queues[tx_queue_id] = pcap_q;
958 eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
960 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
966 eth_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
968 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
974 eth_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
976 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
982 eth_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
984 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
989 static const struct eth_dev_ops ops = {
990 .dev_start = eth_dev_start,
991 .dev_stop = eth_dev_stop,
992 .dev_close = eth_dev_close,
993 .dev_configure = eth_dev_configure,
994 .dev_infos_get = eth_dev_info,
995 .rx_queue_setup = eth_rx_queue_setup,
996 .tx_queue_setup = eth_tx_queue_setup,
997 .rx_queue_start = eth_rx_queue_start,
998 .tx_queue_start = eth_tx_queue_start,
999 .rx_queue_stop = eth_rx_queue_stop,
1000 .tx_queue_stop = eth_tx_queue_stop,
1001 .rx_queue_release = eth_queue_release,
1002 .tx_queue_release = eth_queue_release,
1003 .link_update = eth_link_update,
1004 .stats_get = eth_stats_get,
1005 .stats_reset = eth_stats_reset,
1009 add_queue(struct pmd_devargs *pmd, const char *name, const char *type,
1010 pcap_t *pcap, pcap_dumper_t *dumper)
1012 if (pmd->num_of_queue >= RTE_PMD_PCAP_MAX_QUEUES)
1015 pmd->queue[pmd->num_of_queue].pcap = pcap;
1017 pmd->queue[pmd->num_of_queue].dumper = dumper;
1018 pmd->queue[pmd->num_of_queue].name = name;
1019 pmd->queue[pmd->num_of_queue].type = type;
1020 pmd->num_of_queue++;
1025 * Function handler that opens the pcap file for reading a stores a
1026 * reference of it for use it later on.
1029 open_rx_pcap(const char *key, const char *value, void *extra_args)
1031 const char *pcap_filename = value;
1032 struct pmd_devargs *rx = extra_args;
1033 pcap_t *pcap = NULL;
1035 if (open_single_rx_pcap(pcap_filename, &pcap) < 0)
1038 if (add_queue(rx, pcap_filename, key, pcap, NULL) < 0) {
1047 * Opens a pcap file for writing and stores a reference to it
1048 * for use it later on.
1051 open_tx_pcap(const char *key, const char *value, void *extra_args)
1053 const char *pcap_filename = value;
1054 struct pmd_devargs *dumpers = extra_args;
1055 pcap_dumper_t *dumper;
1057 if (open_single_tx_pcap(pcap_filename, &dumper) < 0)
1060 if (add_queue(dumpers, pcap_filename, key, NULL, dumper) < 0) {
1061 pcap_dump_close(dumper);
1069 * Opens an interface for reading and writing
1072 open_rx_tx_iface(const char *key, const char *value, void *extra_args)
1074 const char *iface = value;
1075 struct pmd_devargs *tx = extra_args;
1076 pcap_t *pcap = NULL;
1078 if (open_single_iface(iface, &pcap) < 0)
1081 tx->queue[0].pcap = pcap;
1082 tx->queue[0].name = iface;
1083 tx->queue[0].type = key;
1089 set_iface_direction(const char *iface, pcap_t *pcap,
1090 pcap_direction_t direction)
1092 const char *direction_str = (direction == PCAP_D_IN) ? "IN" : "OUT";
1093 if (pcap_setdirection(pcap, direction) < 0) {
1094 PMD_LOG(ERR, "Setting %s pcap direction %s failed - %s\n",
1095 iface, direction_str, pcap_geterr(pcap));
1098 PMD_LOG(INFO, "Setting %s pcap direction %s\n",
1099 iface, direction_str);
1104 open_iface(const char *key, const char *value, void *extra_args)
1106 const char *iface = value;
1107 struct pmd_devargs *pmd = extra_args;
1108 pcap_t *pcap = NULL;
1110 if (open_single_iface(iface, &pcap) < 0)
1112 if (add_queue(pmd, iface, key, pcap, NULL) < 0) {
1121 * Opens a NIC for reading packets from it
1124 open_rx_iface(const char *key, const char *value, void *extra_args)
1126 int ret = open_iface(key, value, extra_args);
1129 if (strcmp(key, ETH_PCAP_RX_IFACE_IN_ARG) == 0) {
1130 struct pmd_devargs *pmd = extra_args;
1131 unsigned int qid = pmd->num_of_queue - 1;
1133 set_iface_direction(pmd->queue[qid].name,
1134 pmd->queue[qid].pcap,
1142 rx_iface_args_process(const char *key, const char *value, void *extra_args)
1144 if (strcmp(key, ETH_PCAP_RX_IFACE_ARG) == 0 ||
1145 strcmp(key, ETH_PCAP_RX_IFACE_IN_ARG) == 0)
1146 return open_rx_iface(key, value, extra_args);
1152 * Opens a NIC for writing packets to it
1155 open_tx_iface(const char *key, const char *value, void *extra_args)
1157 return open_iface(key, value, extra_args);
1161 select_phy_mac(const char *key __rte_unused, const char *value,
1165 const int phy_mac = atoi(value);
1166 int *enable_phy_mac = extra_args;
1169 *enable_phy_mac = 1;
1175 get_infinite_rx_arg(const char *key __rte_unused,
1176 const char *value, void *extra_args)
1179 const int infinite_rx = atoi(value);
1180 int *enable_infinite_rx = extra_args;
1182 if (infinite_rx > 0)
1183 *enable_infinite_rx = 1;
1189 pmd_init_internals(struct rte_vdev_device *vdev,
1190 const unsigned int nb_rx_queues,
1191 const unsigned int nb_tx_queues,
1192 struct pmd_internals **internals,
1193 struct rte_eth_dev **eth_dev)
1195 struct rte_eth_dev_data *data;
1196 struct pmd_process_private *pp;
1197 unsigned int numa_node = vdev->device.numa_node;
1199 PMD_LOG(INFO, "Creating pcap-backed ethdev on numa socket %d",
1202 pp = (struct pmd_process_private *)
1203 rte_zmalloc(NULL, sizeof(struct pmd_process_private),
1204 RTE_CACHE_LINE_SIZE);
1208 "Failed to allocate memory for process private");
1212 /* reserve an ethdev entry */
1213 *eth_dev = rte_eth_vdev_allocate(vdev, sizeof(**internals));
1218 (*eth_dev)->process_private = pp;
1219 /* now put it all together
1220 * - store queue data in internals,
1221 * - store numa_node info in eth_dev
1222 * - point eth_dev_data to internals
1223 * - and point eth_dev structure to new eth_dev_data structure
1225 *internals = (*eth_dev)->data->dev_private;
1227 * Interface MAC = 02:70:63:61:70:<iface_idx>
1228 * derived from: 'locally administered':'p':'c':'a':'p':'iface_idx'
1229 * where the middle 4 characters are converted to hex.
1231 (*internals)->eth_addr = (struct rte_ether_addr) {
1232 .addr_bytes = { 0x02, 0x70, 0x63, 0x61, 0x70, iface_idx++ }
1234 (*internals)->phy_mac = 0;
1235 data = (*eth_dev)->data;
1236 data->nb_rx_queues = (uint16_t)nb_rx_queues;
1237 data->nb_tx_queues = (uint16_t)nb_tx_queues;
1238 data->dev_link = pmd_link;
1239 data->mac_addrs = &(*internals)->eth_addr;
1240 data->promiscuous = 1;
1241 data->all_multicast = 1;
1242 data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
1245 * NOTE: we'll replace the data element, of originally allocated
1246 * eth_dev so the rings are local per-process
1248 (*eth_dev)->dev_ops = &ops;
1250 strlcpy((*internals)->devargs, rte_vdev_device_args(vdev),
1251 ETH_PCAP_ARG_MAXLEN);
1257 eth_pcap_update_mac(const char *if_name, struct rte_eth_dev *eth_dev,
1258 const unsigned int numa_node)
1260 #if defined(RTE_EXEC_ENV_LINUX)
1263 int if_fd = socket(AF_INET, SOCK_DGRAM, 0);
1268 rte_strscpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name));
1269 if (ioctl(if_fd, SIOCGIFHWADDR, &ifr)) {
1274 mac_addrs = rte_zmalloc_socket(NULL, RTE_ETHER_ADDR_LEN, 0, numa_node);
1280 PMD_LOG(INFO, "Setting phy MAC for %s", if_name);
1281 eth_dev->data->mac_addrs = mac_addrs;
1282 rte_memcpy(eth_dev->data->mac_addrs[0].addr_bytes,
1283 ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
1289 #elif defined(RTE_EXEC_ENV_FREEBSD)
1291 struct if_msghdr *ifm;
1292 struct sockaddr_dl *sdl;
1301 mib[4] = NET_RT_IFLIST;
1302 mib[5] = if_nametoindex(if_name);
1304 if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0)
1310 buf = rte_malloc(NULL, len, 0);
1314 if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
1318 ifm = (struct if_msghdr *)buf;
1319 sdl = (struct sockaddr_dl *)(ifm + 1);
1321 mac_addrs = rte_zmalloc_socket(NULL, RTE_ETHER_ADDR_LEN, 0, numa_node);
1327 PMD_LOG(INFO, "Setting phy MAC for %s", if_name);
1328 eth_dev->data->mac_addrs = mac_addrs;
1329 rte_memcpy(eth_dev->data->mac_addrs[0].addr_bytes,
1330 LLADDR(sdl), RTE_ETHER_ADDR_LEN);
1341 eth_from_pcaps_common(struct rte_vdev_device *vdev,
1342 struct pmd_devargs_all *devargs_all,
1343 struct pmd_internals **internals, struct rte_eth_dev **eth_dev)
1345 struct pmd_process_private *pp;
1346 struct pmd_devargs *rx_queues = &devargs_all->rx_queues;
1347 struct pmd_devargs *tx_queues = &devargs_all->tx_queues;
1348 const unsigned int nb_rx_queues = rx_queues->num_of_queue;
1349 const unsigned int nb_tx_queues = tx_queues->num_of_queue;
1352 if (pmd_init_internals(vdev, nb_rx_queues, nb_tx_queues, internals,
1356 pp = (*eth_dev)->process_private;
1357 for (i = 0; i < nb_rx_queues; i++) {
1358 struct pcap_rx_queue *rx = &(*internals)->rx_queue[i];
1359 struct devargs_queue *queue = &rx_queues->queue[i];
1361 pp->rx_pcap[i] = queue->pcap;
1362 strlcpy(rx->name, queue->name, sizeof(rx->name));
1363 strlcpy(rx->type, queue->type, sizeof(rx->type));
1366 for (i = 0; i < nb_tx_queues; i++) {
1367 struct pcap_tx_queue *tx = &(*internals)->tx_queue[i];
1368 struct devargs_queue *queue = &tx_queues->queue[i];
1370 pp->tx_dumper[i] = queue->dumper;
1371 pp->tx_pcap[i] = queue->pcap;
1372 strlcpy(tx->name, queue->name, sizeof(tx->name));
1373 strlcpy(tx->type, queue->type, sizeof(tx->type));
1380 eth_from_pcaps(struct rte_vdev_device *vdev,
1381 struct pmd_devargs_all *devargs_all)
1383 struct pmd_internals *internals = NULL;
1384 struct rte_eth_dev *eth_dev = NULL;
1385 struct pmd_devargs *rx_queues = &devargs_all->rx_queues;
1386 int single_iface = devargs_all->single_iface;
1387 unsigned int infinite_rx = devargs_all->infinite_rx;
1390 ret = eth_from_pcaps_common(vdev, devargs_all, &internals, ð_dev);
1395 /* store weather we are using a single interface for rx/tx or not */
1396 internals->single_iface = single_iface;
1399 internals->if_index = if_nametoindex(rx_queues->queue[0].name);
1401 /* phy_mac arg is applied only only if "iface" devarg is provided */
1402 if (rx_queues->phy_mac) {
1403 if (eth_pcap_update_mac(rx_queues->queue[0].name,
1404 eth_dev, vdev->device.numa_node) == 0)
1405 internals->phy_mac = 1;
1409 internals->infinite_rx = infinite_rx;
1410 /* Assign rx ops. */
1412 eth_dev->rx_pkt_burst = eth_pcap_rx_infinite;
1413 else if (devargs_all->is_rx_pcap || devargs_all->is_rx_iface ||
1415 eth_dev->rx_pkt_burst = eth_pcap_rx;
1417 eth_dev->rx_pkt_burst = eth_null_rx;
1419 /* Assign tx ops. */
1420 if (devargs_all->is_tx_pcap)
1421 eth_dev->tx_pkt_burst = eth_pcap_tx_dumper;
1422 else if (devargs_all->is_tx_iface || single_iface)
1423 eth_dev->tx_pkt_burst = eth_pcap_tx;
1425 eth_dev->tx_pkt_burst = eth_tx_drop;
1427 rte_eth_dev_probing_finish(eth_dev);
1432 pmd_pcap_probe(struct rte_vdev_device *dev)
1435 struct rte_kvargs *kvlist;
1436 struct pmd_devargs pcaps = {0};
1437 struct pmd_devargs dumpers = {0};
1438 struct rte_eth_dev *eth_dev = NULL;
1439 struct pmd_internals *internal;
1442 struct pmd_devargs_all devargs_all = {
1449 name = rte_vdev_device_name(dev);
1450 PMD_LOG(INFO, "Initializing pmd_pcap for %s", name);
1452 gettimeofday(&start_time, NULL);
1453 start_cycles = rte_get_timer_cycles();
1454 hz = rte_get_timer_hz();
1456 ret = rte_mbuf_dyn_rx_timestamp_register(×tamp_dynfield_offset,
1457 ×tamp_rx_dynflag);
1459 PMD_LOG(ERR, "Failed to register Rx timestamp field/flag");
1463 if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
1464 eth_dev = rte_eth_dev_attach_secondary(name);
1466 PMD_LOG(ERR, "Failed to probe %s", name);
1470 internal = eth_dev->data->dev_private;
1472 kvlist = rte_kvargs_parse(internal->devargs, valid_arguments);
1476 kvlist = rte_kvargs_parse(rte_vdev_device_args(dev),
1483 * If iface argument is passed we open the NICs and use them for
1486 if (rte_kvargs_count(kvlist, ETH_PCAP_IFACE_ARG) == 1) {
1488 ret = rte_kvargs_process(kvlist, ETH_PCAP_IFACE_ARG,
1489 &open_rx_tx_iface, &pcaps);
1493 dumpers.queue[0] = pcaps.queue[0];
1495 ret = rte_kvargs_process(kvlist, ETH_PCAP_PHY_MAC_ARG,
1496 &select_phy_mac, &pcaps.phy_mac);
1500 dumpers.phy_mac = pcaps.phy_mac;
1502 devargs_all.single_iface = 1;
1503 pcaps.num_of_queue = 1;
1504 dumpers.num_of_queue = 1;
1510 * We check whether we want to open a RX stream from a real NIC, a
1511 * pcap file or open a dummy RX stream
1513 devargs_all.is_rx_pcap =
1514 rte_kvargs_count(kvlist, ETH_PCAP_RX_PCAP_ARG) ? 1 : 0;
1515 devargs_all.is_rx_iface =
1516 (rte_kvargs_count(kvlist, ETH_PCAP_RX_IFACE_ARG) +
1517 rte_kvargs_count(kvlist, ETH_PCAP_RX_IFACE_IN_ARG)) ? 1 : 0;
1518 pcaps.num_of_queue = 0;
1520 devargs_all.is_tx_pcap =
1521 rte_kvargs_count(kvlist, ETH_PCAP_TX_PCAP_ARG) ? 1 : 0;
1522 devargs_all.is_tx_iface =
1523 rte_kvargs_count(kvlist, ETH_PCAP_TX_IFACE_ARG) ? 1 : 0;
1524 dumpers.num_of_queue = 0;
1526 if (devargs_all.is_rx_pcap) {
1528 * We check whether we want to infinitely rx the pcap file.
1530 unsigned int infinite_rx_arg_cnt = rte_kvargs_count(kvlist,
1531 ETH_PCAP_INFINITE_RX_ARG);
1533 if (infinite_rx_arg_cnt == 1) {
1534 ret = rte_kvargs_process(kvlist,
1535 ETH_PCAP_INFINITE_RX_ARG,
1536 &get_infinite_rx_arg,
1537 &devargs_all.infinite_rx);
1540 PMD_LOG(INFO, "infinite_rx has been %s for %s",
1541 devargs_all.infinite_rx ? "enabled" : "disabled",
1544 } else if (infinite_rx_arg_cnt > 1) {
1545 PMD_LOG(WARNING, "infinite_rx has not been enabled since the "
1546 "argument has been provided more than once "
1550 ret = rte_kvargs_process(kvlist, ETH_PCAP_RX_PCAP_ARG,
1551 &open_rx_pcap, &pcaps);
1552 } else if (devargs_all.is_rx_iface) {
1553 ret = rte_kvargs_process(kvlist, NULL,
1554 &rx_iface_args_process, &pcaps);
1555 } else if (devargs_all.is_tx_iface || devargs_all.is_tx_pcap) {
1558 /* Count number of tx queue args passed before dummy rx queue
1559 * creation so a dummy rx queue can be created for each tx queue
1561 unsigned int num_tx_queues =
1562 (rte_kvargs_count(kvlist, ETH_PCAP_TX_PCAP_ARG) +
1563 rte_kvargs_count(kvlist, ETH_PCAP_TX_IFACE_ARG));
1565 PMD_LOG(INFO, "Creating null rx queue since no rx queues were provided.");
1567 /* Creating a dummy rx queue for each tx queue passed */
1568 for (i = 0; i < num_tx_queues; i++)
1569 ret = add_queue(&pcaps, "dummy_rx", "rx_null", NULL,
1572 PMD_LOG(ERR, "Error - No rx or tx queues provided");
1579 * We check whether we want to open a TX stream to a real NIC,
1580 * a pcap file, or drop packets on tx
1582 if (devargs_all.is_tx_pcap) {
1583 ret = rte_kvargs_process(kvlist, ETH_PCAP_TX_PCAP_ARG,
1584 &open_tx_pcap, &dumpers);
1585 } else if (devargs_all.is_tx_iface) {
1586 ret = rte_kvargs_process(kvlist, ETH_PCAP_TX_IFACE_ARG,
1587 &open_tx_iface, &dumpers);
1591 PMD_LOG(INFO, "Dropping packets on tx since no tx queues were provided.");
1593 /* Add 1 dummy queue per rxq which counts and drops packets. */
1594 for (i = 0; i < pcaps.num_of_queue; i++)
1595 ret = add_queue(&dumpers, "dummy_tx", "tx_drop", NULL,
1603 if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
1604 struct pmd_process_private *pp;
1607 internal = eth_dev->data->dev_private;
1608 pp = (struct pmd_process_private *)
1610 sizeof(struct pmd_process_private),
1611 RTE_CACHE_LINE_SIZE);
1615 "Failed to allocate memory for process private");
1620 eth_dev->dev_ops = &ops;
1621 eth_dev->device = &dev->device;
1623 /* setup process private */
1624 for (i = 0; i < pcaps.num_of_queue; i++)
1625 pp->rx_pcap[i] = pcaps.queue[i].pcap;
1627 for (i = 0; i < dumpers.num_of_queue; i++) {
1628 pp->tx_dumper[i] = dumpers.queue[i].dumper;
1629 pp->tx_pcap[i] = dumpers.queue[i].pcap;
1632 eth_dev->process_private = pp;
1633 eth_dev->rx_pkt_burst = eth_pcap_rx;
1634 if (devargs_all.is_tx_pcap)
1635 eth_dev->tx_pkt_burst = eth_pcap_tx_dumper;
1637 eth_dev->tx_pkt_burst = eth_pcap_tx;
1639 rte_eth_dev_probing_finish(eth_dev);
1643 devargs_all.rx_queues = pcaps;
1644 devargs_all.tx_queues = dumpers;
1646 ret = eth_from_pcaps(dev, &devargs_all);
1649 rte_kvargs_free(kvlist);
1655 pmd_pcap_remove(struct rte_vdev_device *dev)
1657 struct rte_eth_dev *eth_dev = NULL;
1662 eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
1663 if (eth_dev == NULL)
1664 return 0; /* port already released */
1666 eth_dev_close(eth_dev);
1667 rte_eth_dev_release_port(eth_dev);
1672 static struct rte_vdev_driver pmd_pcap_drv = {
1673 .probe = pmd_pcap_probe,
1674 .remove = pmd_pcap_remove,
1677 RTE_PMD_REGISTER_VDEV(net_pcap, pmd_pcap_drv);
1678 RTE_PMD_REGISTER_ALIAS(net_pcap, eth_pcap);
1679 RTE_PMD_REGISTER_PARAM_STRING(net_pcap,
1680 ETH_PCAP_RX_PCAP_ARG "=<string> "
1681 ETH_PCAP_TX_PCAP_ARG "=<string> "
1682 ETH_PCAP_RX_IFACE_ARG "=<ifc> "
1683 ETH_PCAP_RX_IFACE_IN_ARG "=<ifc> "
1684 ETH_PCAP_TX_IFACE_ARG "=<ifc> "
1685 ETH_PCAP_IFACE_ARG "=<ifc> "
1686 ETH_PCAP_PHY_MAC_ARG "=<int>"
1687 ETH_PCAP_INFINITE_RX_ARG "=<0|1>");