5767e3fa7a8fb4bd75a32459bb5315c1511fb2b2
[dpdk.git] / doc / guides / sample_app_ug / dist_app.rst
1 ..  BSD LICENSE
2     Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
3     All rights reserved.
4
5     Redistribution and use in source and binary forms, with or without
6     modification, are permitted provided that the following conditions
7     are met:
8
9     * Redistributions of source code must retain the above copyright
10     notice, this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright
12     notice, this list of conditions and the following disclaimer in
13     the documentation and/or other materials provided with the
14     distribution.
15     * Neither the name of Intel Corporation nor the names of its
16     contributors may be used to endorse or promote products derived
17     from this software without specific prior written permission.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22     A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23     OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25     LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 Distributor Sample Application
32 ==============================
33
34 The distributor sample application is a simple example of packet distribution
35 to cores using the Data Plane Development Kit (DPDK).
36
37 Overview
38 --------
39
40 The distributor application performs the distribution of packets that are received
41 on an RX_PORT to different cores. When processed by the cores, the destination
42 port of a packet is the port from the enabled port mask adjacent to the one on
43 which the packet was received, that is, if the first four ports are enabled
44 (port mask 0xf), ports 0 and 1 RX/TX into each other, and ports 2 and 3 RX/TX
45 into each other.
46
47 This application can be used to benchmark performance using the traffic
48 generator as shown in the figure below.
49
50 .. _figure_22:
51
52 **Figure 22. Performance Benchmarking Setup (Basic Environment)**
53
54 |dist_perf|
55
56 Compiling the Application
57 -------------------------
58
59 #.  Go to the sample application directory:
60
61     ..  code-block:: console
62
63         export RTE_SDK=/path/to/rte_sdk
64         cd ${RTE_SDK}/examples/distributor
65
66 #.  Set the target (a default target is used if not specified). For example:
67
68     ..  code-block:: console
69
70         export RTE_TARGET=x86_64-native-linuxapp-gcc
71
72     See the DPDK Getting Started Guide for possible RTE_TARGET values.
73
74 #.  Build the application:
75
76     ..  code-block:: console
77
78         make
79
80 Running the Application
81 -----------------------
82
83 #. The application has a number of command line options:
84
85    ..  code-block:: console
86
87        ./build/distributor_app [EAL options] -- -p PORTMASK
88
89    where,
90
91    *   -p PORTMASK: Hexadecimal bitmask of ports to configure
92
93 #. To run the application in linuxapp environment with 10 lcores, 4 ports,
94    issue the command:
95
96    ..  code-block:: console
97
98        $ ./build/distributor_app -c 0x4003fe -n 4 -- -p f
99
100 #. Refer to the DPDK Getting Started Guide for general information on running
101    applications and the Environment Abstraction Layer (EAL) options.
102
103 Explanation
104 -----------
105
106 The distributor application consists of three types of threads: a receive
107 thread (lcore_rx()), a set of worker threads(locre_worker())
108 and a transmit thread(lcore_tx()). How these threads work together is shown
109 in Fig2 below. The main() function launches  threads of these three types.
110 Each thread has a while loop which will be doing processing and which is
111 terminated only upon SIGINT or ctrl+C. The receive and transmit threads
112 communicate using a software ring (rte_ring structure).
113
114 The receive thread receives the packets using rte_eth_rx_burst() and gives
115 them to  the distributor (using rte_distributor_process() API) which will
116 be called in context of the receive thread itself. The distributor distributes
117 the packets to workers threads based on the tagging of the packet -
118 indicated by the hash field in the mbuf. For IP traffic, this field is
119 automatically filled by the NIC with the "usr" hash value for the packet,
120 which works as a per-flow tag.
121
122 More than one worker thread can exist as part of the application, and these
123 worker threads do simple packet processing by requesting packets from
124 the distributor, doing a simple XOR operation on the input port mbuf field
125 (to indicate the output port which will be used later for packet transmission)
126 and then finally returning the packets back to the distributor in the RX thread.
127
128 Meanwhile, the receive thread will call the distributor api
129 rte_distributor_returned_pkts() to get the packets processed, and will enqueue
130 them to a ring for transfer to the TX thread for transmission on the output port.
131 The transmit thread will dequeue the packets from the ring and transmit them on
132 the output port specified in packet mbuf.
133
134 Users who wish to terminate the running of the application have to press ctrl+C
135 (or send SIGINT to the app). Upon this signal, a signal handler provided
136 in the application will terminate all running threads gracefully and print
137 final statistics to the user.
138
139 .. _figure_23:
140
141 **Figure 23. Distributor Sample Application Layout**
142
143 |dist_app|
144
145 Debug Logging Support
146 ---------------------
147
148 Debug logging is provided as part of the application; the user needs to uncomment
149 the line "#define DEBUG" defined in start of the application in main.c to enable debug logs.
150
151 Statistics
152 ----------
153
154 Upon SIGINT (or) ctrl+C, the print_stats() function displays the count of packets
155 processed at the different stages in the application.
156
157 Application Initialization
158 --------------------------
159
160 Command line parsing is done in the same way as it is done in the L2 Forwarding Sample
161 Application. See Section 9.4.1, "Command Line Arguments".
162
163 Mbuf pool initialization is done in the same way as it is done in the L2 Forwarding
164 Sample Application. See Section 9.4.2, "Mbuf Pool Initialization".
165
166 Driver Initialization is done in same way as it is done in the L2 Forwarding Sample
167 Application. See Section 9.4.3, "Driver Initialization".
168
169 RX queue initialization is done in the same way as it is done in the L2 Forwarding
170 Sample Application. See Section 9.4.4, "RX Queue Initialization".
171
172 TX queue initialization is done in the same way as it is done in the L2 Forwarding
173 Sample Application. See Section 9.4.5, "TX Queue Initialization".
174
175 .. |dist_perf| image:: img/dist_perf.svg
176
177 .. |dist_app| image:: img/dist_app.svg