1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016 Intel Corporation
16 #include <rte_alarm.h>
17 #include <rte_common.h>
18 #include <rte_debug.h>
19 #include <rte_ethdev.h>
20 #include <rte_memory.h>
21 #include <rte_lcore.h>
22 #include <rte_branch_prediction.h>
23 #include <rte_errno.h>
25 #include <rte_kvargs.h>
26 #include <rte_mempool.h>
28 #include <rte_string_fns.h>
29 #include <rte_pdump.h>
31 #define CMD_LINE_OPT_PDUMP "pdump"
32 #define CMD_LINE_OPT_PDUMP_NUM 256
33 #define CMD_LINE_OPT_MULTI "multi"
34 #define CMD_LINE_OPT_MULTI_NUM 257
35 #define PDUMP_PORT_ARG "port"
36 #define PDUMP_PCI_ARG "device_id"
37 #define PDUMP_QUEUE_ARG "queue"
38 #define PDUMP_DIR_ARG "dir"
39 #define PDUMP_RX_DEV_ARG "rx-dev"
40 #define PDUMP_TX_DEV_ARG "tx-dev"
41 #define PDUMP_RING_SIZE_ARG "ring-size"
42 #define PDUMP_MSIZE_ARG "mbuf-size"
43 #define PDUMP_NUM_MBUFS_ARG "total-num-mbufs"
45 #define VDEV_NAME_FMT "net_pcap_%s_%d"
46 #define VDEV_PCAP_ARGS_FMT "tx_pcap=%s"
47 #define VDEV_IFACE_ARGS_FMT "tx_iface=%s"
48 #define TX_STREAM_SIZE 64
50 #define MP_NAME "pdump_pool_%d"
52 #define RX_RING "rx_ring_%d"
53 #define TX_RING "tx_ring_%d"
58 /* Maximum long option length for option parsing. */
59 #define APP_ARG_TCPDUMP_MAX_TUPLES 54
60 #define MBUF_POOL_CACHE_SIZE 250
61 #define TX_DESC_PER_QUEUE 512
62 #define RX_DESC_PER_QUEUE 128
63 #define MBUFS_PER_POOL 65535
64 #define MAX_LONG_OPT_SZ 64
65 #define RING_SIZE 16384
69 /* Maximum delay for exiting after primary process. */
70 #define MONITOR_INTERVAL (500 * 1000)
72 /* true if x is a power of 2 */
73 #define POWEROF2(x) ((((x)-1) & (x)) == 0)
90 static const char * const valid_pdump_arguments[] = {
104 uint64_t dequeue_pkts;
109 struct pdump_tuples {
114 char rx_dev[TX_STREAM_SIZE];
115 char tx_dev[TX_STREAM_SIZE];
117 uint16_t mbuf_data_size;
118 uint32_t total_num_mbufs;
120 /* params for library API call */
122 struct rte_mempool *mp;
123 struct rte_ring *rx_ring;
124 struct rte_ring *tx_ring;
126 /* params for packet dumping */
127 enum pdump_by dump_by_type;
130 enum pcap_stream rx_vdev_stream_type;
131 enum pcap_stream tx_vdev_stream_type;
132 bool single_pdump_dev;
135 struct pdump_stats stats;
136 } __rte_cache_aligned;
137 static struct pdump_tuples pdump_t[APP_ARG_TCPDUMP_MAX_TUPLES];
145 static int num_tuples;
146 static struct rte_eth_conf port_conf_default;
147 static volatile uint8_t quit_signal;
148 static uint8_t multiple_core_capture;
150 /**< display usage */
152 pdump_usage(const char *prgname)
154 printf("usage: %s [EAL options] --"
155 " --["CMD_LINE_OPT_MULTI"]\n"
156 " --"CMD_LINE_OPT_PDUMP" "
157 "'(port=<port id> | device_id=<pci id or vdev name>),"
158 "(queue=<queue_id>),"
159 "(rx-dev=<iface or pcap file> |"
160 " tx-dev=<iface or pcap file>,"
161 "[ring-size=<ring size>default:16384],"
162 "[mbuf-size=<mbuf data size>default:2176],"
163 "[total-num-mbufs=<number of mbufs>default:65535]'\n",
168 parse_device_id(const char *key __rte_unused, const char *value,
171 struct pdump_tuples *pt = extra_args;
173 pt->device_id = strdup(value);
174 pt->dump_by_type = DEVICE_ID;
180 parse_queue(const char *key __rte_unused, const char *value, void *extra_args)
183 struct pdump_tuples *pt = extra_args;
185 if (!strcmp(value, "*"))
186 pt->queue = RTE_PDUMP_ALL_QUEUES;
188 n = strtoul(value, NULL, 10);
189 pt->queue = (uint16_t) n;
195 parse_rxtxdev(const char *key, const char *value, void *extra_args)
198 struct pdump_tuples *pt = extra_args;
200 if (!strcmp(key, PDUMP_RX_DEV_ARG)) {
201 strlcpy(pt->rx_dev, value, sizeof(pt->rx_dev));
202 /* identify the tx stream type for pcap vdev */
203 if (if_nametoindex(pt->rx_dev))
204 pt->rx_vdev_stream_type = IFACE;
205 } else if (!strcmp(key, PDUMP_TX_DEV_ARG)) {
206 strlcpy(pt->tx_dev, value, sizeof(pt->tx_dev));
207 /* identify the tx stream type for pcap vdev */
208 if (if_nametoindex(pt->tx_dev))
209 pt->tx_vdev_stream_type = IFACE;
216 parse_uint_value(const char *key, const char *value, void *extra_args)
225 t = strtoul(value, &end, 10);
227 if (errno != 0 || end[0] != 0 || t < v->min || t > v->max) {
228 printf("invalid value:\"%s\" for key:\"%s\", "
229 "value must be >= %"PRIu64" and <= %"PRIu64"\n",
230 value, key, v->min, v->max);
233 if (!strcmp(key, PDUMP_RING_SIZE_ARG) && !POWEROF2(t)) {
234 printf("invalid value:\"%s\" for key:\"%s\", "
235 "value must be power of 2\n", value, key);
247 parse_pdump(const char *optarg)
249 struct rte_kvargs *kvlist;
250 int ret = 0, cnt1, cnt2;
251 struct pdump_tuples *pt;
252 struct parse_val v = {0};
254 pt = &pdump_t[num_tuples];
256 /* initial check for invalid arguments */
257 kvlist = rte_kvargs_parse(optarg, valid_pdump_arguments);
258 if (kvlist == NULL) {
259 printf("--pdump=\"%s\": invalid argument passed\n", optarg);
263 /* port/device_id parsing and validation */
264 cnt1 = rte_kvargs_count(kvlist, PDUMP_PORT_ARG);
265 cnt2 = rte_kvargs_count(kvlist, PDUMP_PCI_ARG);
266 if (!((cnt1 == 1 && cnt2 == 0) || (cnt1 == 0 && cnt2 == 1))) {
267 printf("--pdump=\"%s\": must have either port or "
268 "device_id argument\n", optarg);
271 } else if (cnt1 == 1) {
273 v.max = RTE_MAX_ETHPORTS-1;
274 ret = rte_kvargs_process(kvlist, PDUMP_PORT_ARG,
275 &parse_uint_value, &v);
278 pt->port = (uint16_t) v.val;
279 pt->dump_by_type = PORT_ID;
280 } else if (cnt2 == 1) {
281 ret = rte_kvargs_process(kvlist, PDUMP_PCI_ARG,
282 &parse_device_id, pt);
287 /* queue parsing and validation */
288 cnt1 = rte_kvargs_count(kvlist, PDUMP_QUEUE_ARG);
290 printf("--pdump=\"%s\": must have queue argument\n", optarg);
294 ret = rte_kvargs_process(kvlist, PDUMP_QUEUE_ARG, &parse_queue, pt);
298 /* rx-dev and tx-dev parsing and validation */
299 cnt1 = rte_kvargs_count(kvlist, PDUMP_RX_DEV_ARG);
300 cnt2 = rte_kvargs_count(kvlist, PDUMP_TX_DEV_ARG);
301 if (cnt1 == 0 && cnt2 == 0) {
302 printf("--pdump=\"%s\": must have either rx-dev or "
303 "tx-dev argument\n", optarg);
306 } else if (cnt1 == 1 && cnt2 == 1) {
307 ret = rte_kvargs_process(kvlist, PDUMP_RX_DEV_ARG,
311 ret = rte_kvargs_process(kvlist, PDUMP_TX_DEV_ARG,
315 /* if captured packets has to send to the same vdev */
316 if (!strcmp(pt->rx_dev, pt->tx_dev))
317 pt->single_pdump_dev = true;
318 pt->dir = RTE_PDUMP_FLAG_RXTX;
319 } else if (cnt1 == 1) {
320 ret = rte_kvargs_process(kvlist, PDUMP_RX_DEV_ARG,
324 pt->dir = RTE_PDUMP_FLAG_RX;
325 } else if (cnt2 == 1) {
326 ret = rte_kvargs_process(kvlist, PDUMP_TX_DEV_ARG,
330 pt->dir = RTE_PDUMP_FLAG_TX;
334 /* ring_size parsing and validation */
335 cnt1 = rte_kvargs_count(kvlist, PDUMP_RING_SIZE_ARG);
338 v.max = RTE_RING_SZ_MASK-1;
339 ret = rte_kvargs_process(kvlist, PDUMP_RING_SIZE_ARG,
340 &parse_uint_value, &v);
343 pt->ring_size = (uint32_t) v.val;
345 pt->ring_size = RING_SIZE;
347 /* mbuf_data_size parsing and validation */
348 cnt1 = rte_kvargs_count(kvlist, PDUMP_MSIZE_ARG);
352 ret = rte_kvargs_process(kvlist, PDUMP_MSIZE_ARG,
353 &parse_uint_value, &v);
356 pt->mbuf_data_size = (uint16_t) v.val;
358 pt->mbuf_data_size = RTE_MBUF_DEFAULT_BUF_SIZE;
360 /* total_num_mbufs parsing and validation */
361 cnt1 = rte_kvargs_count(kvlist, PDUMP_NUM_MBUFS_ARG);
365 ret = rte_kvargs_process(kvlist, PDUMP_NUM_MBUFS_ARG,
366 &parse_uint_value, &v);
369 pt->total_num_mbufs = (uint16_t) v.val;
371 pt->total_num_mbufs = MBUFS_PER_POOL;
376 rte_kvargs_free(kvlist);
380 /* Parse the argument given in the command line of the application */
382 launch_args_parse(int argc, char **argv, char *prgname)
386 static struct option long_option[] = {
387 {CMD_LINE_OPT_PDUMP, 1, 0, CMD_LINE_OPT_PDUMP_NUM},
388 {CMD_LINE_OPT_MULTI, 0, 0, CMD_LINE_OPT_MULTI_NUM},
393 pdump_usage(prgname);
395 /* Parse command line */
396 while ((opt = getopt_long(argc, argv, " ",
397 long_option, &option_index)) != EOF) {
399 case CMD_LINE_OPT_PDUMP_NUM:
400 ret = parse_pdump(optarg);
402 pdump_usage(prgname);
406 case CMD_LINE_OPT_MULTI_NUM:
407 multiple_core_capture = 1;
410 pdump_usage(prgname);
419 monitor_primary(void *arg __rte_unused)
424 if (rte_eal_primary_proc_alive(NULL)) {
425 rte_eal_alarm_set(MONITOR_INTERVAL, monitor_primary, NULL);
429 printf("Primary process is no longer active, exiting...\n");
434 print_pdump_stats(void)
437 struct pdump_tuples *pt;
439 for (i = 0; i < num_tuples; i++) {
440 printf("##### PDUMP DEBUG STATS #####\n");
442 printf(" -packets dequeued: %"PRIu64"\n",
443 pt->stats.dequeue_pkts);
444 printf(" -packets transmitted to vdev: %"PRIu64"\n",
446 printf(" -packets freed: %"PRIu64"\n",
447 pt->stats.freed_pkts);
452 disable_pdump(struct pdump_tuples *pt)
454 if (pt->dump_by_type == DEVICE_ID)
455 rte_pdump_disable_by_deviceid(pt->device_id, pt->queue,
457 else if (pt->dump_by_type == PORT_ID)
458 rte_pdump_disable(pt->port, pt->queue, pt->dir);
462 pdump_rxtx(struct rte_ring *ring, uint16_t vdev_id, struct pdump_stats *stats)
464 /* write input packets of port to vdev for pdump */
465 struct rte_mbuf *rxtx_bufs[BURST_SIZE];
467 /* first dequeue packets from ring of primary process */
468 const uint16_t nb_in_deq = rte_ring_dequeue_burst(ring,
469 (void *)rxtx_bufs, BURST_SIZE, NULL);
470 stats->dequeue_pkts += nb_in_deq;
473 /* then sent on vdev */
474 uint16_t nb_in_txd = rte_eth_tx_burst(
476 0, rxtx_bufs, nb_in_deq);
477 stats->tx_pkts += nb_in_txd;
479 if (unlikely(nb_in_txd < nb_in_deq)) {
480 unsigned int drops = nb_in_deq - nb_in_txd;
482 rte_pktmbuf_free_bulk(&rxtx_bufs[nb_in_txd], drops);
483 stats->freed_pkts += drops;
489 free_ring_data(struct rte_ring *ring, uint16_t vdev_id,
490 struct pdump_stats *stats)
492 while (rte_ring_count(ring))
493 pdump_rxtx(ring, vdev_id, stats);
500 struct pdump_tuples *pt;
502 for (i = 0; i < num_tuples; i++) {
508 rte_ring_free(pt->rx_ring);
509 rte_ring_free(pt->tx_ring);
510 rte_mempool_free(pt->mp);
515 cleanup_pdump_resources(void)
518 struct pdump_tuples *pt;
519 char name[RTE_ETH_NAME_MAX_LEN];
521 /* disable pdump and free the pdump_tuple resources */
522 for (i = 0; i < num_tuples; i++) {
525 /* remove callbacks */
529 * transmit rest of the enqueued packets of the rings on to
530 * the vdev, in order to release mbufs to the mepool.
532 if (pt->dir & RTE_PDUMP_FLAG_RX)
533 free_ring_data(pt->rx_ring, pt->rx_vdev_id, &pt->stats);
534 if (pt->dir & RTE_PDUMP_FLAG_TX)
535 free_ring_data(pt->tx_ring, pt->tx_vdev_id, &pt->stats);
537 /* Remove the vdev(s) created */
538 if (pt->dir & RTE_PDUMP_FLAG_RX) {
539 rte_eth_dev_get_name_by_port(pt->rx_vdev_id, name);
540 rte_eal_hotplug_remove("vdev", name);
543 if (pt->single_pdump_dev)
546 if (pt->dir & RTE_PDUMP_FLAG_TX) {
547 rte_eth_dev_get_name_by_port(pt->tx_vdev_id, name);
548 rte_eal_hotplug_remove("vdev", name);
556 disable_primary_monitor(void)
561 * Cancel monitoring of primary process.
562 * There will be no error if no alarm is set
563 * (in case primary process kill was detected earlier).
565 ret = rte_eal_alarm_cancel(monitor_primary, NULL);
567 printf("Fail to disable monitor:%d\n", ret);
571 signal_handler(int sig_num)
573 if (sig_num == SIGINT) {
574 printf("\n\nSignal %d received, preparing to exit...\n",
581 configure_vdev(uint16_t port_id)
583 struct rte_ether_addr addr;
584 const uint16_t rxRings = 0, txRings = 1;
588 if (!rte_eth_dev_is_valid_port(port_id))
591 ret = rte_eth_dev_configure(port_id, rxRings, txRings,
594 rte_exit(EXIT_FAILURE, "dev config failed\n");
596 for (q = 0; q < txRings; q++) {
597 ret = rte_eth_tx_queue_setup(port_id, q, TX_DESC_PER_QUEUE,
598 rte_eth_dev_socket_id(port_id), NULL);
600 rte_exit(EXIT_FAILURE, "queue setup failed\n");
603 ret = rte_eth_dev_start(port_id);
605 rte_exit(EXIT_FAILURE, "dev start failed\n");
607 ret = rte_eth_macaddr_get(port_id, &addr);
609 rte_exit(EXIT_FAILURE, "macaddr get failed\n");
611 printf("Port %u MAC: %02"PRIx8" %02"PRIx8" %02"PRIx8
612 " %02"PRIx8" %02"PRIx8" %02"PRIx8"\n",
613 port_id, RTE_ETHER_ADDR_BYTES(&addr));
615 ret = rte_eth_promiscuous_enable(port_id);
617 rte_exit(EXIT_FAILURE,
618 "promiscuous mode enable failed: %s\n",
627 create_mp_ring_vdev(void)
631 struct pdump_tuples *pt = NULL;
632 struct rte_mempool *mbuf_pool = NULL;
633 char vdev_name[SIZE];
634 char vdev_args[SIZE];
635 char ring_name[SIZE];
636 char mempool_name[SIZE];
638 for (i = 0; i < num_tuples; i++) {
640 snprintf(mempool_name, SIZE, MP_NAME, i);
641 mbuf_pool = rte_mempool_lookup(mempool_name);
642 if (mbuf_pool == NULL) {
644 mbuf_pool = rte_pktmbuf_pool_create_by_ops(mempool_name,
646 MBUF_POOL_CACHE_SIZE, 0,
648 rte_socket_id(), "ring_mp_mc");
649 if (mbuf_pool == NULL) {
651 rte_exit(EXIT_FAILURE,
652 "Mempool creation failed: %s\n",
653 rte_strerror(rte_errno));
658 if (pt->dir == RTE_PDUMP_FLAG_RXTX) {
659 /* if captured packets has to send to the same vdev */
661 snprintf(ring_name, SIZE, RX_RING, i);
662 pt->rx_ring = rte_ring_create(ring_name, pt->ring_size,
664 if (pt->rx_ring == NULL) {
666 rte_exit(EXIT_FAILURE, "%s:%s:%d\n",
667 rte_strerror(rte_errno),
672 snprintf(ring_name, SIZE, TX_RING, i);
673 pt->tx_ring = rte_ring_create(ring_name, pt->ring_size,
675 if (pt->tx_ring == NULL) {
677 rte_exit(EXIT_FAILURE, "%s:%s:%d\n",
678 rte_strerror(rte_errno),
683 snprintf(vdev_name, sizeof(vdev_name),
684 VDEV_NAME_FMT, RX_STR, i);
685 (pt->rx_vdev_stream_type == IFACE) ?
686 snprintf(vdev_args, sizeof(vdev_args),
687 VDEV_IFACE_ARGS_FMT, pt->rx_dev) :
688 snprintf(vdev_args, sizeof(vdev_args),
689 VDEV_PCAP_ARGS_FMT, pt->rx_dev);
690 if (rte_eal_hotplug_add("vdev", vdev_name,
693 rte_exit(EXIT_FAILURE,
694 "vdev creation failed:%s:%d\n",
697 if (rte_eth_dev_get_port_by_name(vdev_name,
699 rte_eal_hotplug_remove("vdev", vdev_name);
701 rte_exit(EXIT_FAILURE,
702 "cannot find added vdev %s:%s:%d\n",
703 vdev_name, __func__, __LINE__);
705 pt->rx_vdev_id = portid;
708 configure_vdev(pt->rx_vdev_id);
710 if (pt->single_pdump_dev)
711 pt->tx_vdev_id = portid;
713 snprintf(vdev_name, sizeof(vdev_name),
714 VDEV_NAME_FMT, TX_STR, i);
715 (pt->rx_vdev_stream_type == IFACE) ?
716 snprintf(vdev_args, sizeof(vdev_args),
717 VDEV_IFACE_ARGS_FMT, pt->tx_dev) :
718 snprintf(vdev_args, sizeof(vdev_args),
719 VDEV_PCAP_ARGS_FMT, pt->tx_dev);
720 if (rte_eal_hotplug_add("vdev", vdev_name,
723 rte_exit(EXIT_FAILURE,
724 "vdev creation failed:"
725 "%s:%d\n", __func__, __LINE__);
727 if (rte_eth_dev_get_port_by_name(vdev_name,
729 rte_eal_hotplug_remove("vdev",
732 rte_exit(EXIT_FAILURE,
733 "cannot find added vdev %s:%s:%d\n",
734 vdev_name, __func__, __LINE__);
736 pt->tx_vdev_id = portid;
739 configure_vdev(pt->tx_vdev_id);
741 } else if (pt->dir == RTE_PDUMP_FLAG_RX) {
744 snprintf(ring_name, SIZE, RX_RING, i);
745 pt->rx_ring = rte_ring_create(ring_name, pt->ring_size,
747 if (pt->rx_ring == NULL) {
749 rte_exit(EXIT_FAILURE, "%s\n",
750 rte_strerror(rte_errno));
753 snprintf(vdev_name, sizeof(vdev_name),
754 VDEV_NAME_FMT, RX_STR, i);
755 (pt->rx_vdev_stream_type == IFACE) ?
756 snprintf(vdev_args, sizeof(vdev_args),
757 VDEV_IFACE_ARGS_FMT, pt->rx_dev) :
758 snprintf(vdev_args, sizeof(vdev_args),
759 VDEV_PCAP_ARGS_FMT, pt->rx_dev);
760 if (rte_eal_hotplug_add("vdev", vdev_name,
763 rte_exit(EXIT_FAILURE,
764 "vdev creation failed:%s:%d\n",
767 if (rte_eth_dev_get_port_by_name(vdev_name,
769 rte_eal_hotplug_remove("vdev", vdev_name);
771 rte_exit(EXIT_FAILURE,
772 "cannot find added vdev %s:%s:%d\n",
773 vdev_name, __func__, __LINE__);
775 pt->rx_vdev_id = portid;
777 configure_vdev(pt->rx_vdev_id);
778 } else if (pt->dir == RTE_PDUMP_FLAG_TX) {
781 snprintf(ring_name, SIZE, TX_RING, i);
782 pt->tx_ring = rte_ring_create(ring_name, pt->ring_size,
784 if (pt->tx_ring == NULL) {
786 rte_exit(EXIT_FAILURE, "%s\n",
787 rte_strerror(rte_errno));
790 snprintf(vdev_name, sizeof(vdev_name),
791 VDEV_NAME_FMT, TX_STR, i);
792 (pt->tx_vdev_stream_type == IFACE) ?
793 snprintf(vdev_args, sizeof(vdev_args),
794 VDEV_IFACE_ARGS_FMT, pt->tx_dev) :
795 snprintf(vdev_args, sizeof(vdev_args),
796 VDEV_PCAP_ARGS_FMT, pt->tx_dev);
797 if (rte_eal_hotplug_add("vdev", vdev_name,
800 rte_exit(EXIT_FAILURE,
801 "vdev creation failed\n");
803 if (rte_eth_dev_get_port_by_name(vdev_name,
805 rte_eal_hotplug_remove("vdev", vdev_name);
807 rte_exit(EXIT_FAILURE,
808 "cannot find added vdev %s:%s:%d\n",
809 vdev_name, __func__, __LINE__);
811 pt->tx_vdev_id = portid;
814 configure_vdev(pt->tx_vdev_id);
823 struct pdump_tuples *pt;
824 int ret = 0, ret1 = 0;
826 for (i = 0; i < num_tuples; i++) {
828 if (pt->dir == RTE_PDUMP_FLAG_RXTX) {
829 if (pt->dump_by_type == DEVICE_ID) {
830 ret = rte_pdump_enable_by_deviceid(
836 ret1 = rte_pdump_enable_by_deviceid(
842 } else if (pt->dump_by_type == PORT_ID) {
843 ret = rte_pdump_enable(pt->port, pt->queue,
845 pt->rx_ring, pt->mp, NULL);
846 ret1 = rte_pdump_enable(pt->port, pt->queue,
848 pt->tx_ring, pt->mp, NULL);
850 } else if (pt->dir == RTE_PDUMP_FLAG_RX) {
851 if (pt->dump_by_type == DEVICE_ID)
852 ret = rte_pdump_enable_by_deviceid(
855 pt->dir, pt->rx_ring,
857 else if (pt->dump_by_type == PORT_ID)
858 ret = rte_pdump_enable(pt->port, pt->queue,
860 pt->rx_ring, pt->mp, NULL);
861 } else if (pt->dir == RTE_PDUMP_FLAG_TX) {
862 if (pt->dump_by_type == DEVICE_ID)
863 ret = rte_pdump_enable_by_deviceid(
867 pt->tx_ring, pt->mp, NULL);
868 else if (pt->dump_by_type == PORT_ID)
869 ret = rte_pdump_enable(pt->port, pt->queue,
871 pt->tx_ring, pt->mp, NULL);
873 if (ret < 0 || ret1 < 0) {
874 cleanup_pdump_resources();
875 rte_exit(EXIT_FAILURE, "%s\n", rte_strerror(rte_errno));
881 pdump_packets(struct pdump_tuples *pt)
883 if (pt->dir & RTE_PDUMP_FLAG_RX)
884 pdump_rxtx(pt->rx_ring, pt->rx_vdev_id, &pt->stats);
885 if (pt->dir & RTE_PDUMP_FLAG_TX)
886 pdump_rxtx(pt->tx_ring, pt->tx_vdev_id, &pt->stats);
890 dump_packets_core(void *arg)
892 struct pdump_tuples *pt = (struct pdump_tuples *) arg;
894 printf(" core (%u); port %u device (%s) queue %u\n",
895 rte_lcore_id(), pt->port, pt->device_id, pt->queue);
905 get_next_core(unsigned int lcore)
907 lcore = rte_get_next_lcore(lcore, 1, 0);
908 if (lcore == RTE_MAX_LCORE)
909 rte_exit(EXIT_FAILURE,
910 "Max core limit %u reached for packet capture", lcore);
918 unsigned int lcore_id = 0;
920 if (!multiple_core_capture) {
921 printf(" core (%u), capture for (%d) tuples\n",
922 rte_lcore_id(), num_tuples);
924 for (i = 0; i < num_tuples; i++)
925 printf(" - port %u device (%s) queue %u\n",
927 pdump_t[i].device_id,
930 while (!quit_signal) {
931 for (i = 0; i < num_tuples; i++)
932 pdump_packets(&pdump_t[i]);
938 /* check if there enough core */
939 if ((uint32_t)num_tuples >= rte_lcore_count()) {
940 printf("Insufficient cores to run parallel!\n");
944 lcore_id = get_next_core(lcore_id);
946 for (i = 0; i < num_tuples; i++) {
947 rte_eal_remote_launch(dump_packets_core,
948 &pdump_t[i], lcore_id);
949 lcore_id = get_next_core(lcore_id);
951 if (rte_eal_wait_lcore(lcore_id) < 0)
952 rte_exit(EXIT_FAILURE, "failed to wait\n");
961 enable_primary_monitor(void)
965 /* Once primary exits, so will pdump. */
966 ret = rte_eal_alarm_set(MONITOR_INTERVAL, monitor_primary, NULL);
968 printf("Fail to enable monitor:%d\n", ret);
972 main(int argc, char **argv)
978 char n_flag[] = "-n4";
979 char mp_flag[] = "--proc-type=secondary";
980 char *argp[argc + 2];
982 /* catch ctrl-c so we can print on exit */
983 signal(SIGINT, signal_handler);
989 for (i = 1; i < argc; i++)
990 argp[i + 2] = argv[i];
994 diag = rte_eal_init(argc, argp);
996 rte_panic("Cannot init EAL\n");
998 if (rte_eth_dev_count_avail() == 0)
999 rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
1004 /* parse app arguments */
1006 ret = launch_args_parse(argc, argv, argp[0]);
1008 rte_exit(EXIT_FAILURE, "Invalid argument\n");
1011 /* create mempool, ring and vdevs info */
1012 create_mp_ring_vdev();
1014 enable_primary_monitor();
1017 disable_primary_monitor();
1018 cleanup_pdump_resources();
1019 /* dump debug stats */
1020 print_pdump_stats();
1022 ret = rte_eal_cleanup();
1024 printf("Error from rte_eal_cleanup(), %d\n", ret);