New upstream version 18.02
[deb_dpdk.git] / doc / guides / sample_app_ug / dist_app.rst
1 ..  SPDX-License-Identifier: BSD-3-Clause
2     Copyright(c) 2010-2014 Intel Corporation.
3
4 Distributor Sample Application
5 ==============================
6
7 The distributor sample application is a simple example of packet distribution
8 to cores using the Data Plane Development Kit (DPDK).
9
10 Overview
11 --------
12
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
18 into each other.
19
20 This application can be used to benchmark performance using the traffic
21 generator as shown in the figure below.
22
23 .. _figure_dist_perf:
24
25 .. figure:: img/dist_perf.*
26
27    Performance Benchmarking Setup (Basic Environment)
28
29 Compiling the Application
30 -------------------------
31
32 To compile the sample application see :doc:`compiling`.
33
34 The application is located in the ``distributor`` sub-directory.
35
36 Running the Application
37 -----------------------
38
39 #. The application has a number of command line options:
40
41    ..  code-block:: console
42
43        ./build/distributor_app [EAL options] -- -p PORTMASK
44
45    where,
46
47    *   -p PORTMASK: Hexadecimal bitmask of ports to configure
48
49 #. To run the application in linuxapp environment with 10 lcores, 4 ports,
50    issue the command:
51
52    ..  code-block:: console
53
54        $ ./build/distributor_app -l 1-9,22 -n 4 -- -p f
55
56 #. Refer to the DPDK Getting Started Guide for general information on running
57    applications and the Environment Abstraction Layer (EAL) options.
58
59 Explanation
60 -----------
61
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.
69
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.
79
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.
85
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.
91
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.
96
97 .. _figure_dist_app:
98
99 .. figure:: img/dist_app.*
100
101    Distributor Sample Application Layout
102
103
104 Debug Logging Support
105 ---------------------
106
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.
109
110 Statistics
111 ----------
112
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.
117
118 Application Initialization
119 --------------------------
120
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`.
123
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`.
126
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`.
129
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`.
132
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`.