1 .. SPDX-License-Identifier: BSD-3-Clause
2 Copyright(c) 2010-2014 Intel Corporation.
4 Distributor Sample Application
5 ==============================
7 The distributor sample application is a simple example of packet distribution
8 to cores using the Data Plane Development Kit (DPDK).
13 The distributor application performs the distribution of packets that are received
14 on an RX_PORT to different cores. When processed by the cores, the destination
15 port of a packet is the port from the enabled port mask adjacent to the one on
16 which the packet was received, that is, if the first four ports are enabled
17 (port mask 0xf), ports 0 and 1 RX/TX into each other, and ports 2 and 3 RX/TX
20 This application can be used to benchmark performance using the traffic
21 generator as shown in the figure below.
25 .. figure:: img/dist_perf.*
27 Performance Benchmarking Setup (Basic Environment)
29 Compiling the Application
30 -------------------------
32 To compile the sample application see :doc:`compiling`.
34 The application is located in the ``distributor`` sub-directory.
36 Running the Application
37 -----------------------
39 #. The application has a number of command line options:
41 .. code-block:: console
43 ./build/distributor_app [EAL options] -- -p PORTMASK
47 * -p PORTMASK: Hexadecimal bitmask of ports to configure
49 #. To run the application in linuxapp environment with 10 lcores, 4 ports,
52 .. code-block:: console
54 $ ./build/distributor_app -l 1-9,22 -n 4 -- -p f
56 #. Refer to the DPDK Getting Started Guide for general information on running
57 applications and the Environment Abstraction Layer (EAL) options.
62 The distributor application consists of four types of threads: a receive
63 thread (``lcore_rx()``), a distributor thread (``lcore_dist()``), a set of
64 worker threads (``lcore_worker()``), and a transmit thread(``lcore_tx()``).
65 How these threads work together is shown in :numref:`figure_dist_app` below.
66 The ``main()`` function launches threads of these four types. Each thread
67 has a while loop which will be doing processing and which is terminated
68 only upon SIGINT or ctrl+C.
70 The receive thread receives the packets using ``rte_eth_rx_burst()`` and will
71 enqueue them to an rte_ring. The distributor thread will dequeue the packets
72 from the ring and assign them to workers (using ``rte_distributor_process()`` API).
73 This assignment is based on the tag (or flow ID) of the packet - indicated by
74 the hash field in the mbuf. For IP traffic, this field is automatically filled
75 by the NIC with the "usr" hash value for the packet, which works as a per-flow
76 tag. The distributor thread communicates with the worker threads using a
77 cache-line swapping mechanism, passing up to 8 mbuf pointers at a time
78 (one cache line) to each worker.
80 More than one worker thread can exist as part of the application, and these
81 worker threads do simple packet processing by requesting packets from
82 the distributor, doing a simple XOR operation on the input port mbuf field
83 (to indicate the output port which will be used later for packet transmission)
84 and then finally returning the packets back to the distributor thread.
86 The distributor thread will then call the distributor api
87 ``rte_distributor_returned_pkts()`` to get the processed packets, and will enqueue
88 them to another rte_ring for transfer to the TX thread for transmission on the
89 output port. The transmit thread will dequeue the packets from the ring and
90 transmit them on the output port specified in packet mbuf.
92 Users who wish to terminate the running of the application have to press ctrl+C
93 (or send SIGINT to the app). Upon this signal, a signal handler provided
94 in the application will terminate all running threads gracefully and print
95 final statistics to the user.
99 .. figure:: img/dist_app.*
101 Distributor Sample Application Layout
104 Debug Logging Support
105 ---------------------
107 Debug logging is provided as part of the application; the user needs to uncomment
108 the line "#define DEBUG" defined in start of the application in main.c to enable debug logs.
113 The main function will print statistics on the console every second. These
114 statistics include the number of packets enqueued and dequeued at each stage
115 in the application, and also key statistics per worker, including how many
116 packets of each burst size (1-8) were sent to each worker thread.
118 Application Initialization
119 --------------------------
121 Command line parsing is done in the same way as it is done in the L2 Forwarding Sample
122 Application. See :ref:`l2_fwd_app_cmd_arguments`.
124 Mbuf pool initialization is done in the same way as it is done in the L2 Forwarding
125 Sample Application. See :ref:`l2_fwd_app_mbuf_init`.
127 Driver Initialization is done in same way as it is done in the L2 Forwarding Sample
128 Application. See :ref:`l2_fwd_app_dvr_init`.
130 RX queue initialization is done in the same way as it is done in the L2 Forwarding
131 Sample Application. See :ref:`l2_fwd_app_rx_init`.
133 TX queue initialization is done in the same way as it is done in the L2 Forwarding
134 Sample Application. See :ref:`l2_fwd_app_tx_init`.