xref: /dpdk/doc/guides/sample_app_ug/ip_reassembly.rst (revision daa02b5cddbb8e11b31d41e2bf7bb1ae64dcae2f)
1..  SPDX-License-Identifier: BSD-3-Clause
2    Copyright(c) 2010-2014 Intel Corporation.
3
4IP Reassembly Sample Application
5================================
6
7The L3 Forwarding application is a simple example of packet processing using the DPDK.
8The application performs L3 forwarding with reassembly for fragmented IPv4 and IPv6 packets.
9
10Overview
11--------
12
13The application demonstrates the use of the DPDK libraries to implement packet forwarding
14with reassembly for IPv4 and IPv6 fragmented packets.
15The initialization and run- time paths are very similar to those of the :doc:`l2_forward_real_virtual`.
16The main difference from the L2 Forwarding sample application is that
17it reassembles fragmented IPv4 and IPv6 packets before forwarding.
18The maximum allowed size of reassembled packet is 9.5 KB.
19
20There 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
26The Longest Prefix Match (LPM for IPv4, LPM6 for IPv6) table is used to store/lookup an outgoing port number,
27associated with that IPv4 address. Any unmatched packets are forwarded to the originating port.
28
29
30Compiling the Application
31-------------------------
32
33To compile the sample application see :doc:`compiling`.
34
35The application is located in the ``ip_reassembly`` sub-directory.
36
37
38Running the Application
39-----------------------
40
41The 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
47where:
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
60To 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
91To 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
97To test the application, flows should be set up in the flow generator that match the values in the
98l3fwd_ipv4_route_array and/or l3fwd_ipv6_route_array table.
99
100Please note that in order to test this application,
101the traffic generator should be generating valid fragmented IP packets.
102For IPv6, the only supported case is when no other extension headers other than
103fragment extension header are present in the packet.
104
105The 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
112The 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
119For example, for the fragmented input IPv4 packet with destination address: 100.10.1.1,
120a reassembled IPv4 packet be sent out from port #0 to the destination address 100.10.1.1
121once all the fragments are collected.
122
123Explanation
124-----------
125
126The following sections provide some explanation of the sample application code.
127As mentioned in the overview section, the initialization and run-time paths are very similar to those of the :doc:`l2_forward_real_virtual`.
128The following sections describe aspects that are specific to the IP reassemble sample application.
129
130IPv4 Fragment Table Initialization
131~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132
133This application uses the rte_ip_frag library. Please refer to Programmer's Guide for more detailed explanation of how to use this library.
134Fragment table maintains information about already received fragments of the packet.
135Each IP packet is uniquely identified by triple <Source IP address>, <Destination IP address>, <ID>.
136To avoid lock contention, each RX queue has its own Fragment Table,
137e.g. the application can't handle the situation when different fragments of the same packet arrive through different RX queues.
138Each 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
146Mempools Initialization
147~~~~~~~~~~~~~~~~~~~~~~~
148
149The reassembly application demands a lot of mbuf's to be allocated.
150At any given time up to (2 \* max_flow_num \* RTE_LIBRTE_IP_FRAG_MAX_FRAGS \* <maximum number of mbufs per packet>)
151can be stored inside Fragment Table waiting for remaining fragments.
152To keep mempool size under reasonable limits and to avoid situation when one RX queue can starve other queues,
153each 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
161Packet Reassembly and Forwarding
162~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
163
164For each input packet, the packet forwarding operation is done by the l3fwd_simple_forward() function.
165If the packet is an IPv4 or IPv6 fragment, then it calls rte_ipv4_reassemble_packet() for IPv4 packets,
166or rte_ipv6_reassemble_packet() for IPv6 packets.
167These functions either return a pointer to valid mbuf that contains reassembled packet,
168or NULL (if the packet can't be reassembled for some reason).
169Then 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
171actual transmit of the packet.
172
173The 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
194If 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),
196then it will free all associated with the packet fragments,
197mark the table entry as invalid and return NULL to the caller.
198
199Debug logging and Statistics Collection
200~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
201
202The RTE_LIBRTE_IP_FRAG_TBL_STAT controls statistics collection for the IP Fragment Table.
203This macro is disabled by default, but it can be enabled by modifying the appropriate line
204in ``config/rte_config.h``.
205To make ip_reassembly print the statistics to the standard output,
206the user must send either an USR1, INT or TERM signal to the process.
207For all of these signals, the ip_reassembly process prints Fragment table statistics for each RX queue,
208plus the INT and TERM will cause process termination as usual.
209