vhost: add power monitor API
[dpdk.git] / doc / guides / sample_app_ug / ip_reassembly.rst
1 ..  SPDX-License-Identifier: BSD-3-Clause
2     Copyright(c) 2010-2014 Intel Corporation.
3
4 IP Reassembly Sample Application
5 ================================
6
7 The L3 Forwarding application is a simple example of packet processing using the DPDK.
8 The application performs L3 forwarding with reassembly for fragmented IPv4 and IPv6 packets.
9
10 Overview
11 --------
12
13 The application demonstrates the use of the DPDK libraries to implement packet forwarding
14 with reassembly for IPv4 and IPv6 fragmented packets.
15 The initialization and run- time paths are very similar to those of the :doc:`l2_forward_real_virtual`.
16 The main difference from the L2 Forwarding sample application is that
17 it reassembles fragmented IPv4 and IPv6 packets before forwarding.
18 The maximum allowed size of reassembled packet is 9.5 KB.
19
20 There are two key differences from the L2 Forwarding sample application:
21
22 *   The first difference is that the forwarding decision is taken based on information read from the input packet's IP header.
23
24 *   The second difference is that the application differentiates between IP and non-IP traffic by means of offload flags.
25
26 The Longest Prefix Match (LPM for IPv4, LPM6 for IPv6) table is used to store/lookup an outgoing port number,
27 associated with that IPv4 address. Any unmatched packets are forwarded to the originating port.
28
29
30 Compiling the Application
31 -------------------------
32
33 To compile the sample application see :doc:`compiling`.
34
35 The application is located in the ``ip_reassembly`` sub-directory.
36
37
38 Running the Application
39 -----------------------
40
41 The application has a number of command line options:
42
43 .. code-block:: console
44
45     ./<build_dir>/examples/dpdk-ip_reassembly [EAL options] -- -p PORTMASK [-q NQ] [--maxflows=FLOWS>] [--flowttl=TTL[(s|ms)]]
46
47 where:
48
49 *   -p PORTMASK: Hexadecimal bitmask of ports to configure
50
51 *   -q NQ: Number of RX queues per lcore
52
53 *   --maxflows=FLOWS: determines maximum number of active fragmented flows (1-65535). Default value: 4096.
54
55 *   --flowttl=TTL[(s|ms)]: determines maximum Time To Live for fragmented packet.
56     If all fragments of the packet wouldn't appear within given time-out,
57     then they are considered as invalid and will be dropped.
58     Valid range is 1ms - 3600s. Default value: 1s.
59
60 To run the example in linux environment with 2 lcores (2,4) over 2 ports(0,2) with 1 RX queue per lcore:
61
62 .. code-block:: console
63
64     ./<build_dir>/examples/dpdk-ip_reassembly -l 2,4 -n 3 -- -p 5
65     EAL: coremask set to 14
66     EAL: Detected lcore 0 on socket 0
67     EAL: Detected lcore 1 on socket 1
68     EAL: Detected lcore 2 on socket 0
69     EAL: Detected lcore 3 on socket 1
70     EAL: Detected lcore 4 on socket 0
71     ...
72
73     Initializing port 0 on lcore 2... Address:00:1B:21:76:FA:2C, rxq=0 txq=2,0 txq=4,1
74     done: Link Up - speed 10000 Mbps - full-duplex
75     Skipping disabled port 1
76     Initializing port 2 on lcore 4... Address:00:1B:21:5C:FF:54, rxq=0 txq=2,0 txq=4,1
77     done: Link Up - speed 10000 Mbps - full-duplex
78     Skipping disabled port 3IP_FRAG: Socket 0: adding route 100.10.0.0/16 (port 0)
79     IP_RSMBL: Socket 0: adding route 100.20.0.0/16 (port 1)
80     ...
81
82     IP_RSMBL: Socket 0: adding route 0101:0101:0101:0101:0101:0101:0101:0101/48 (port 0)
83     IP_RSMBL: Socket 0: adding route 0201:0101:0101:0101:0101:0101:0101:0101/48 (port 1)
84     ...
85
86     IP_RSMBL: entering main loop on lcore 4
87     IP_RSMBL: -- lcoreid=4 portid=2
88     IP_RSMBL: entering main loop on lcore 2
89     IP_RSMBL: -- lcoreid=2 portid=0
90
91 To run the example in linux environment with 1 lcore (4) over 2 ports(0,2) with 2 RX queues per lcore:
92
93 .. code-block:: console
94
95     ./<build_dir>/examples/dpdk-ip_reassembly -l 4 -n 3 -- -p 5 -q 2
96
97 To test the application, flows should be set up in the flow generator that match the values in the
98 l3fwd_ipv4_route_array and/or l3fwd_ipv6_route_array table.
99
100 Please note that in order to test this application,
101 the traffic generator should be generating valid fragmented IP packets.
102 For IPv6, the only supported case is when no other extension headers other than
103 fragment extension header are present in the packet.
104
105 The default l3fwd_ipv4_route_array table is:
106
107 .. literalinclude:: ../../../examples/ip_reassembly/main.c
108     :language: c
109     :start-after: Default l3fwd_ipv4_route_array table. 8<
110     :end-before: >8 End of default l3fwd_ipv4_route_array table.
111
112 The default l3fwd_ipv6_route_array table is:
113
114 .. literalinclude:: ../../../examples/ip_reassembly/main.c
115     :language: c
116     :start-after: Default l3fwd_ipv6_route_array table. 8<
117     :end-before: >8 End of default l3fwd_ipv6_route_array table.
118
119 For example, for the fragmented input IPv4 packet with destination address: 100.10.1.1,
120 a reassembled IPv4 packet be sent out from port #0 to the destination address 100.10.1.1
121 once all the fragments are collected.
122
123 Explanation
124 -----------
125
126 The following sections provide some explanation of the sample application code.
127 As mentioned in the overview section, the initialization and run-time paths are very similar to those of the :doc:`l2_forward_real_virtual`.
128 The following sections describe aspects that are specific to the IP reassemble sample application.
129
130 IPv4 Fragment Table Initialization
131 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132
133 This application uses the rte_ip_frag library. Please refer to Programmer's Guide for more detailed explanation of how to use this library.
134 Fragment table maintains information about already received fragments of the packet.
135 Each IP packet is uniquely identified by triple <Source IP address>, <Destination IP address>, <ID>.
136 To avoid lock contention, each RX queue has its own Fragment Table,
137 e.g. the application can't handle the situation when different fragments of the same packet arrive through different RX queues.
138 Each table entry can hold information about packet consisting of up to RTE_LIBRTE_IP_FRAG_MAX_FRAGS fragments.
139
140 .. literalinclude:: ../../../examples/ip_reassembly/main.c
141     :language: c
142     :start-after: Each table entry holds information about packet fragmentation. 8<
143     :end-before: >8 End of holding packet fragmentation.
144     :dedent: 1
145
146 Mempools Initialization
147 ~~~~~~~~~~~~~~~~~~~~~~~
148
149 The reassembly application demands a lot of mbuf's to be allocated.
150 At any given time up to (2 \* max_flow_num \* RTE_LIBRTE_IP_FRAG_MAX_FRAGS \* <maximum number of mbufs per packet>)
151 can be stored inside Fragment Table waiting for remaining fragments.
152 To keep mempool size under reasonable limits and to avoid situation when one RX queue can starve other queues,
153 each RX queue uses its own mempool.
154
155 .. literalinclude:: ../../../examples/ip_reassembly/main.c
156     :language: c
157     :start-after: mbufs stored int the gragment table. 8<
158     :end-before: >8 End of mbufs stored int the fragmentation table.
159     :dedent: 1
160
161 Packet Reassembly and Forwarding
162 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
163
164 For each input packet, the packet forwarding operation is done by the l3fwd_simple_forward() function.
165 If the packet is an IPv4 or IPv6 fragment, then it calls rte_ipv4_reassemble_packet() for IPv4 packets,
166 or rte_ipv6_reassemble_packet() for IPv6 packets.
167 These functions either return a pointer to valid mbuf that contains reassembled packet,
168 or NULL (if the packet can't be reassembled for some reason).
169 Then l3fwd_simple_forward() continues with the code for the packet forwarding decision
170 (that is, the identification of the output interface for the packet) and
171 actual transmit of the packet.
172
173 The rte_ipv4_reassemble_packet() or rte_ipv6_reassemble_packet() are responsible for:
174
175 #.  Searching the Fragment Table for entry with packet's <IP Source Address, IP Destination Address, Packet ID>
176
177 #.  If the entry is found, then check if that entry already timed-out.
178     If yes, then free all previously received fragments,
179     and remove information about them from the entry.
180
181 #.  If no entry with such key is found, then try to create a new one by one of two ways:
182
183     #.  Use as empty entry
184
185     #.  Delete a timed-out entry, free mbufs associated with it mbufs and store a new entry with specified key in it.
186
187 #.  Update the entry with new fragment information and check
188     if a packet can be reassembled (the packet's entry contains all fragments).
189
190     #.  If yes, then, reassemble the packet, mark table's entry as empty and return the reassembled mbuf to the caller.
191
192     #.  If no, then just return a NULL to the caller.
193
194 If at any stage of packet processing a reassembly function encounters an error
195 (can't insert new entry into the Fragment table, or invalid/timed-out fragment),
196 then it will free all associated with the packet fragments,
197 mark the table entry as invalid and return NULL to the caller.
198
199 Debug logging and Statistics Collection
200 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
201
202 The RTE_LIBRTE_IP_FRAG_TBL_STAT controls statistics collection for the IP Fragment Table.
203 This macro is disabled by default, but it can be enabled by modifying the appropriate line
204 in ``config/rte_config.h``.
205 To make ip_reassembly print the statistics to the standard output,
206 the user must send either an USR1, INT or TERM signal to the process.
207 For all of these signals, the ip_reassembly process prints Fragment table statistics for each RX queue,
208 plus the INT and TERM will cause process termination as usual.