ethdev: introduce new tunnel VXLAN-GPE
[dpdk.git] / doc / guides / prog_guide / rte_flow.rst
1 ..  BSD LICENSE
2     Copyright 2016 6WIND S.A.
3     Copyright 2016 Mellanox.
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 6WIND S.A. 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 .. _Generic_flow_API:
32
33 Generic flow API (rte_flow)
34 ===========================
35
36 Overview
37 --------
38
39 This API provides a generic means to configure hardware to match specific
40 ingress or egress traffic, alter its fate and query related counters
41 according to any number of user-defined rules.
42
43 It is named *rte_flow* after the prefix used for all its symbols, and is
44 defined in ``rte_flow.h``.
45
46 - Matching can be performed on packet data (protocol headers, payload) and
47   properties (e.g. associated physical port, virtual device function ID).
48
49 - Possible operations include dropping traffic, diverting it to specific
50   queues, to virtual/physical device functions or ports, performing tunnel
51   offloads, adding marks and so on.
52
53 It is slightly higher-level than the legacy filtering framework which it
54 encompasses and supersedes (including all functions and filter types) in
55 order to expose a single interface with an unambiguous behavior that is
56 common to all poll-mode drivers (PMDs).
57
58 Flow rule
59 ---------
60
61 Description
62 ~~~~~~~~~~~
63
64 A flow rule is the combination of attributes with a matching pattern and a
65 list of actions. Flow rules form the basis of this API.
66
67 Flow rules can have several distinct actions (such as counting,
68 encapsulating, decapsulating before redirecting packets to a particular
69 queue, etc.), instead of relying on several rules to achieve this and having
70 applications deal with hardware implementation details regarding their
71 order.
72
73 Support for different priority levels on a rule basis is provided, for
74 example in order to force a more specific rule to come before a more generic
75 one for packets matched by both. However hardware support for more than a
76 single priority level cannot be guaranteed. When supported, the number of
77 available priority levels is usually low, which is why they can also be
78 implemented in software by PMDs (e.g. missing priority levels may be
79 emulated by reordering rules).
80
81 In order to remain as hardware-agnostic as possible, by default all rules
82 are considered to have the same priority, which means that the order between
83 overlapping rules (when a packet is matched by several filters) is
84 undefined.
85
86 PMDs may refuse to create overlapping rules at a given priority level when
87 they can be detected (e.g. if a pattern matches an existing filter).
88
89 Thus predictable results for a given priority level can only be achieved
90 with non-overlapping rules, using perfect matching on all protocol layers.
91
92 Flow rules can also be grouped, the flow rule priority is specific to the
93 group they belong to. All flow rules in a given group are thus processed
94 either before or after another group.
95
96 Support for multiple actions per rule may be implemented internally on top
97 of non-default hardware priorities, as a result both features may not be
98 simultaneously available to applications.
99
100 Considering that allowed pattern/actions combinations cannot be known in
101 advance and would result in an impractically large number of capabilities to
102 expose, a method is provided to validate a given rule from the current
103 device configuration state.
104
105 This enables applications to check if the rule types they need is supported
106 at initialization time, before starting their data path. This method can be
107 used anytime, its only requirement being that the resources needed by a rule
108 should exist (e.g. a target RX queue should be configured first).
109
110 Each defined rule is associated with an opaque handle managed by the PMD,
111 applications are responsible for keeping it. These can be used for queries
112 and rules management, such as retrieving counters or other data and
113 destroying them.
114
115 To avoid resource leaks on the PMD side, handles must be explicitly
116 destroyed by the application before releasing associated resources such as
117 queues and ports.
118
119 The following sections cover:
120
121 - **Attributes** (represented by ``struct rte_flow_attr``): properties of a
122   flow rule such as its direction (ingress or egress) and priority.
123
124 - **Pattern item** (represented by ``struct rte_flow_item``): part of a
125   matching pattern that either matches specific packet data or traffic
126   properties. It can also describe properties of the pattern itself, such as
127   inverted matching.
128
129 - **Matching pattern**: traffic properties to look for, a combination of any
130   number of items.
131
132 - **Actions** (represented by ``struct rte_flow_action``): operations to
133   perform whenever a packet is matched by a pattern.
134
135 Attributes
136 ~~~~~~~~~~
137
138 Attribute: Group
139 ^^^^^^^^^^^^^^^^
140
141 Flow rules can be grouped by assigning them a common group number. Lower
142 values have higher priority. Group 0 has the highest priority.
143
144 Although optional, applications are encouraged to group similar rules as
145 much as possible to fully take advantage of hardware capabilities
146 (e.g. optimized matching) and work around limitations (e.g. a single pattern
147 type possibly allowed in a given group).
148
149 Note that support for more than a single group is not guaranteed.
150
151 Attribute: Priority
152 ^^^^^^^^^^^^^^^^^^^
153
154 A priority level can be assigned to a flow rule. Like groups, lower values
155 denote higher priority, with 0 as the maximum.
156
157 A rule with priority 0 in group 8 is always matched after a rule with
158 priority 8 in group 0.
159
160 Group and priority levels are arbitrary and up to the application, they do
161 not need to be contiguous nor start from 0, however the maximum number
162 varies between devices and may be affected by existing flow rules.
163
164 If a packet is matched by several rules of a given group for a given
165 priority level, the outcome is undefined. It can take any path, may be
166 duplicated or even cause unrecoverable errors.
167
168 Note that support for more than a single priority level is not guaranteed.
169
170 Attribute: Traffic direction
171 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
172
173 Flow rule patterns apply to inbound and/or outbound traffic.
174
175 In the context of this API, **ingress** and **egress** respectively stand
176 for **inbound** and **outbound** based on the standpoint of the application
177 creating a flow rule.
178
179 There are no exceptions to this definition.
180
181 Several pattern items and actions are valid and can be used in both
182 directions. At least one direction must be specified.
183
184 Specifying both directions at once for a given rule is not recommended but
185 may be valid in a few cases (e.g. shared counters).
186
187 Attribute: Transfer
188 ^^^^^^^^^^^^^^^^^^^
189
190 Instead of simply matching the properties of traffic as it would appear on a
191 given DPDK port ID, enabling this attribute transfers a flow rule to the
192 lowest possible level of any device endpoints found in the pattern.
193
194 When supported, this effectively enables an application to reroute traffic
195 not necessarily intended for it (e.g. coming from or addressed to different
196 physical ports, VFs or applications) at the device level.
197
198 It complements the behavior of some pattern items such as `Item: PHY_PORT`_
199 and is meaningless without them.
200
201 When transferring flow rules, **ingress** and **egress** attributes
202 (`Attribute: Traffic direction`_) keep their original meaning, as if
203 processing traffic emitted or received by the application.
204
205 Pattern item
206 ~~~~~~~~~~~~
207
208 Pattern items fall in two categories:
209
210 - Matching protocol headers and packet data, usually associated with a
211   specification structure. These must be stacked in the same order as the
212   protocol layers to match inside packets, starting from the lowest.
213
214 - Matching meta-data or affecting pattern processing, often without a
215   specification structure. Since they do not match packet contents, their
216   position in the list is usually not relevant.
217
218 Item specification structures are used to match specific values among
219 protocol fields (or item properties). Documentation describes for each item
220 whether they are associated with one and their type name if so.
221
222 Up to three structures of the same type can be set for a given item:
223
224 - ``spec``: values to match (e.g. a given IPv4 address).
225
226 - ``last``: upper bound for an inclusive range with corresponding fields in
227   ``spec``.
228
229 - ``mask``: bit-mask applied to both ``spec`` and ``last`` whose purpose is
230   to distinguish the values to take into account and/or partially mask them
231   out (e.g. in order to match an IPv4 address prefix).
232
233 Usage restrictions and expected behavior:
234
235 - Setting either ``mask`` or ``last`` without ``spec`` is an error.
236
237 - Field values in ``last`` which are either 0 or equal to the corresponding
238   values in ``spec`` are ignored; they do not generate a range. Nonzero
239   values lower than those in ``spec`` are not supported.
240
241 - Setting ``spec`` and optionally ``last`` without ``mask`` causes the PMD
242   to use the default mask defined for that item (defined as
243   ``rte_flow_item_{name}_mask`` constants).
244
245 - Not setting any of them (assuming item type allows it) is equivalent to
246   providing an empty (zeroed) ``mask`` for broad (nonspecific) matching.
247
248 - ``mask`` is a simple bit-mask applied before interpreting the contents of
249   ``spec`` and ``last``, which may yield unexpected results if not used
250   carefully. For example, if for an IPv4 address field, ``spec`` provides
251   *10.1.2.3*, ``last`` provides *10.3.4.5* and ``mask`` provides
252   *255.255.0.0*, the effective range becomes *10.1.0.0* to *10.3.255.255*.
253
254 Example of an item specification matching an Ethernet header:
255
256 .. _table_rte_flow_pattern_item_example:
257
258 .. table:: Ethernet item
259
260    +----------+----------+--------------------+
261    | Field    | Subfield | Value              |
262    +==========+==========+====================+
263    | ``spec`` | ``src``  | ``00:01:02:03:04`` |
264    |          +----------+--------------------+
265    |          | ``dst``  | ``00:2a:66:00:01`` |
266    |          +----------+--------------------+
267    |          | ``type`` | ``0x22aa``         |
268    +----------+----------+--------------------+
269    | ``last`` | unspecified                   |
270    +----------+----------+--------------------+
271    | ``mask`` | ``src``  | ``00:ff:ff:ff:00`` |
272    |          +----------+--------------------+
273    |          | ``dst``  | ``00:00:00:00:ff`` |
274    |          +----------+--------------------+
275    |          | ``type`` | ``0x0000``         |
276    +----------+----------+--------------------+
277
278 Non-masked bits stand for any value (shown as ``?`` below), Ethernet headers
279 with the following properties are thus matched:
280
281 - ``src``: ``??:01:02:03:??``
282 - ``dst``: ``??:??:??:??:01``
283 - ``type``: ``0x????``
284
285 Matching pattern
286 ~~~~~~~~~~~~~~~~
287
288 A pattern is formed by stacking items starting from the lowest protocol
289 layer to match. This stacking restriction does not apply to meta items which
290 can be placed anywhere in the stack without affecting the meaning of the
291 resulting pattern.
292
293 Patterns are terminated by END items.
294
295 Examples:
296
297 .. _table_rte_flow_tcpv4_as_l4:
298
299 .. table:: TCPv4 as L4
300
301    +-------+----------+
302    | Index | Item     |
303    +=======+==========+
304    | 0     | Ethernet |
305    +-------+----------+
306    | 1     | IPv4     |
307    +-------+----------+
308    | 2     | TCP      |
309    +-------+----------+
310    | 3     | END      |
311    +-------+----------+
312
313 |
314
315 .. _table_rte_flow_tcpv6_in_vxlan:
316
317 .. table:: TCPv6 in VXLAN
318
319    +-------+------------+
320    | Index | Item       |
321    +=======+============+
322    | 0     | Ethernet   |
323    +-------+------------+
324    | 1     | IPv4       |
325    +-------+------------+
326    | 2     | UDP        |
327    +-------+------------+
328    | 3     | VXLAN      |
329    +-------+------------+
330    | 4     | Ethernet   |
331    +-------+------------+
332    | 5     | IPv6       |
333    +-------+------------+
334    | 6     | TCP        |
335    +-------+------------+
336    | 7     | END        |
337    +-------+------------+
338
339 |
340
341 .. _table_rte_flow_tcpv4_as_l4_meta:
342
343 .. table:: TCPv4 as L4 with meta items
344
345    +-------+----------+
346    | Index | Item     |
347    +=======+==========+
348    | 0     | VOID     |
349    +-------+----------+
350    | 1     | Ethernet |
351    +-------+----------+
352    | 2     | VOID     |
353    +-------+----------+
354    | 3     | IPv4     |
355    +-------+----------+
356    | 4     | TCP      |
357    +-------+----------+
358    | 5     | VOID     |
359    +-------+----------+
360    | 6     | VOID     |
361    +-------+----------+
362    | 7     | END      |
363    +-------+----------+
364
365 The above example shows how meta items do not affect packet data matching
366 items, as long as those remain stacked properly. The resulting matching
367 pattern is identical to "TCPv4 as L4".
368
369 .. _table_rte_flow_udpv6_anywhere:
370
371 .. table:: UDPv6 anywhere
372
373    +-------+------+
374    | Index | Item |
375    +=======+======+
376    | 0     | IPv6 |
377    +-------+------+
378    | 1     | UDP  |
379    +-------+------+
380    | 2     | END  |
381    +-------+------+
382
383 If supported by the PMD, omitting one or several protocol layers at the
384 bottom of the stack as in the above example (missing an Ethernet
385 specification) enables looking up anywhere in packets.
386
387 It is unspecified whether the payload of supported encapsulations
388 (e.g. VXLAN payload) is matched by such a pattern, which may apply to inner,
389 outer or both packets.
390
391 .. _table_rte_flow_invalid_l3:
392
393 .. table:: Invalid, missing L3
394
395    +-------+----------+
396    | Index | Item     |
397    +=======+==========+
398    | 0     | Ethernet |
399    +-------+----------+
400    | 1     | UDP      |
401    +-------+----------+
402    | 2     | END      |
403    +-------+----------+
404
405 The above pattern is invalid due to a missing L3 specification between L2
406 (Ethernet) and L4 (UDP). Doing so is only allowed at the bottom and at the
407 top of the stack.
408
409 Meta item types
410 ~~~~~~~~~~~~~~~
411
412 They match meta-data or affect pattern processing instead of matching packet
413 data directly, most of them do not need a specification structure. This
414 particularity allows them to be specified anywhere in the stack without
415 causing any side effect.
416
417 Item: ``END``
418 ^^^^^^^^^^^^^
419
420 End marker for item lists. Prevents further processing of items, thereby
421 ending the pattern.
422
423 - Its numeric value is 0 for convenience.
424 - PMD support is mandatory.
425 - ``spec``, ``last`` and ``mask`` are ignored.
426
427 .. _table_rte_flow_item_end:
428
429 .. table:: END
430
431    +----------+---------+
432    | Field    | Value   |
433    +==========+=========+
434    | ``spec`` | ignored |
435    +----------+---------+
436    | ``last`` | ignored |
437    +----------+---------+
438    | ``mask`` | ignored |
439    +----------+---------+
440
441 Item: ``VOID``
442 ^^^^^^^^^^^^^^
443
444 Used as a placeholder for convenience. It is ignored and simply discarded by
445 PMDs.
446
447 - PMD support is mandatory.
448 - ``spec``, ``last`` and ``mask`` are ignored.
449
450 .. _table_rte_flow_item_void:
451
452 .. table:: VOID
453
454    +----------+---------+
455    | Field    | Value   |
456    +==========+=========+
457    | ``spec`` | ignored |
458    +----------+---------+
459    | ``last`` | ignored |
460    +----------+---------+
461    | ``mask`` | ignored |
462    +----------+---------+
463
464 One usage example for this type is generating rules that share a common
465 prefix quickly without reallocating memory, only by updating item types:
466
467 .. _table_rte_flow_item_void_example:
468
469 .. table:: TCP, UDP or ICMP as L4
470
471    +-------+--------------------+
472    | Index | Item               |
473    +=======+====================+
474    | 0     | Ethernet           |
475    +-------+--------------------+
476    | 1     | IPv4               |
477    +-------+------+------+------+
478    | 2     | UDP  | VOID | VOID |
479    +-------+------+------+------+
480    | 3     | VOID | TCP  | VOID |
481    +-------+------+------+------+
482    | 4     | VOID | VOID | ICMP |
483    +-------+------+------+------+
484    | 5     | END                |
485    +-------+--------------------+
486
487 Item: ``INVERT``
488 ^^^^^^^^^^^^^^^^
489
490 Inverted matching, i.e. process packets that do not match the pattern.
491
492 - ``spec``, ``last`` and ``mask`` are ignored.
493
494 .. _table_rte_flow_item_invert:
495
496 .. table:: INVERT
497
498    +----------+---------+
499    | Field    | Value   |
500    +==========+=========+
501    | ``spec`` | ignored |
502    +----------+---------+
503    | ``last`` | ignored |
504    +----------+---------+
505    | ``mask`` | ignored |
506    +----------+---------+
507
508 Usage example, matching non-TCPv4 packets only:
509
510 .. _table_rte_flow_item_invert_example:
511
512 .. table:: Anything but TCPv4
513
514    +-------+----------+
515    | Index | Item     |
516    +=======+==========+
517    | 0     | INVERT   |
518    +-------+----------+
519    | 1     | Ethernet |
520    +-------+----------+
521    | 2     | IPv4     |
522    +-------+----------+
523    | 3     | TCP      |
524    +-------+----------+
525    | 4     | END      |
526    +-------+----------+
527
528 Item: ``PF``
529 ^^^^^^^^^^^^
530
531 Matches traffic originating from (ingress) or going to (egress) the physical
532 function of the current device.
533
534 If supported, should work even if the physical function is not managed by
535 the application and thus not associated with a DPDK port ID.
536
537 - Can be combined with any number of `Item: VF`_ to match both PF and VF
538   traffic.
539 - ``spec``, ``last`` and ``mask`` must not be set.
540
541 .. _table_rte_flow_item_pf:
542
543 .. table:: PF
544
545    +----------+-------+
546    | Field    | Value |
547    +==========+=======+
548    | ``spec`` | unset |
549    +----------+-------+
550    | ``last`` | unset |
551    +----------+-------+
552    | ``mask`` | unset |
553    +----------+-------+
554
555 Item: ``VF``
556 ^^^^^^^^^^^^
557
558 Matches traffic originating from (ingress) or going to (egress) a given
559 virtual function of the current device.
560
561 If supported, should work even if the virtual function is not managed by the
562 application and thus not associated with a DPDK port ID.
563
564 Note this pattern item does not match VF representors traffic which, as
565 separate entities, should be addressed through their own DPDK port IDs.
566
567 - Can be specified multiple times to match traffic addressed to several VF
568   IDs.
569 - Can be combined with a PF item to match both PF and VF traffic.
570 - Default ``mask`` matches any VF ID.
571
572 .. _table_rte_flow_item_vf:
573
574 .. table:: VF
575
576    +----------+----------+---------------------------+
577    | Field    | Subfield | Value                     |
578    +==========+==========+===========================+
579    | ``spec`` | ``id``   | destination VF ID         |
580    +----------+----------+---------------------------+
581    | ``last`` | ``id``   | upper range value         |
582    +----------+----------+---------------------------+
583    | ``mask`` | ``id``   | zeroed to match any VF ID |
584    +----------+----------+---------------------------+
585
586 Item: ``PHY_PORT``
587 ^^^^^^^^^^^^^^^^^^
588
589 Matches traffic originating from (ingress) or going to (egress) a physical
590 port of the underlying device.
591
592 The first PHY_PORT item overrides the physical port normally associated with
593 the specified DPDK input port (port_id). This item can be provided several
594 times to match additional physical ports.
595
596 Note that physical ports are not necessarily tied to DPDK input ports
597 (port_id) when those are not under DPDK control. Possible values are
598 specific to each device, they are not necessarily indexed from zero and may
599 not be contiguous.
600
601 As a device property, the list of allowed values as well as the value
602 associated with a port_id should be retrieved by other means.
603
604 - Default ``mask`` matches any port index.
605
606 .. _table_rte_flow_item_phy_port:
607
608 .. table:: PHY_PORT
609
610    +----------+-----------+--------------------------------+
611    | Field    | Subfield  | Value                          |
612    +==========+===========+================================+
613    | ``spec`` | ``index`` | physical port index            |
614    +----------+-----------+--------------------------------+
615    | ``last`` | ``index`` | upper range value              |
616    +----------+-----------+--------------------------------+
617    | ``mask`` | ``index`` | zeroed to match any port index |
618    +----------+-----------+--------------------------------+
619
620 Item: ``PORT_ID``
621 ^^^^^^^^^^^^^^^^^
622
623 Matches traffic originating from (ingress) or going to (egress) a given DPDK
624 port ID.
625
626 Normally only supported if the port ID in question is known by the
627 underlying PMD and related to the device the flow rule is created against.
628
629 This must not be confused with `Item: PHY_PORT`_ which refers to the
630 physical port of a device, whereas `Item: PORT_ID`_ refers to a ``struct
631 rte_eth_dev`` object on the application side (also known as "port
632 representor" depending on the kind of underlying device).
633
634 - Default ``mask`` matches the specified DPDK port ID.
635
636 .. _table_rte_flow_item_port_id:
637
638 .. table:: PORT_ID
639
640    +----------+----------+-----------------------------+
641    | Field    | Subfield | Value                       |
642    +==========+==========+=============================+
643    | ``spec`` | ``id``   | DPDK port ID                |
644    +----------+----------+-----------------------------+
645    | ``last`` | ``id``   | upper range value           |
646    +----------+----------+-----------------------------+
647    | ``mask`` | ``id``   | zeroed to match any port ID |
648    +----------+----------+-----------------------------+
649
650 Data matching item types
651 ~~~~~~~~~~~~~~~~~~~~~~~~
652
653 Most of these are basically protocol header definitions with associated
654 bit-masks. They must be specified (stacked) from lowest to highest protocol
655 layer to form a matching pattern.
656
657 The following list is not exhaustive, new protocols will be added in the
658 future.
659
660 Item: ``ANY``
661 ^^^^^^^^^^^^^
662
663 Matches any protocol in place of the current layer, a single ANY may also
664 stand for several protocol layers.
665
666 This is usually specified as the first pattern item when looking for a
667 protocol anywhere in a packet.
668
669 - Default ``mask`` stands for any number of layers.
670
671 .. _table_rte_flow_item_any:
672
673 .. table:: ANY
674
675    +----------+----------+--------------------------------------+
676    | Field    | Subfield | Value                                |
677    +==========+==========+======================================+
678    | ``spec`` | ``num``  | number of layers covered             |
679    +----------+----------+--------------------------------------+
680    | ``last`` | ``num``  | upper range value                    |
681    +----------+----------+--------------------------------------+
682    | ``mask`` | ``num``  | zeroed to cover any number of layers |
683    +----------+----------+--------------------------------------+
684
685 Example for VXLAN TCP payload matching regardless of outer L3 (IPv4 or IPv6)
686 and L4 (UDP) both matched by the first ANY specification, and inner L3 (IPv4
687 or IPv6) matched by the second ANY specification:
688
689 .. _table_rte_flow_item_any_example:
690
691 .. table:: TCP in VXLAN with wildcards
692
693    +-------+------+----------+----------+-------+
694    | Index | Item | Field    | Subfield | Value |
695    +=======+======+==========+==========+=======+
696    | 0     | Ethernet                           |
697    +-------+------+----------+----------+-------+
698    | 1     | ANY  | ``spec`` | ``num``  | 2     |
699    +-------+------+----------+----------+-------+
700    | 2     | VXLAN                              |
701    +-------+------------------------------------+
702    | 3     | Ethernet                           |
703    +-------+------+----------+----------+-------+
704    | 4     | ANY  | ``spec`` | ``num``  | 1     |
705    +-------+------+----------+----------+-------+
706    | 5     | TCP                                |
707    +-------+------------------------------------+
708    | 6     | END                                |
709    +-------+------------------------------------+
710
711 Item: ``RAW``
712 ^^^^^^^^^^^^^
713
714 Matches a byte string of a given length at a given offset.
715
716 Offset is either absolute (using the start of the packet) or relative to the
717 end of the previous matched item in the stack, in which case negative values
718 are allowed.
719
720 If search is enabled, offset is used as the starting point. The search area
721 can be delimited by setting limit to a nonzero value, which is the maximum
722 number of bytes after offset where the pattern may start.
723
724 Matching a zero-length pattern is allowed, doing so resets the relative
725 offset for subsequent items.
726
727 - This type does not support ranges (``last`` field).
728 - Default ``mask`` matches all fields exactly.
729
730 .. _table_rte_flow_item_raw:
731
732 .. table:: RAW
733
734    +----------+--------------+-------------------------------------------------+
735    | Field    | Subfield     | Value                                           |
736    +==========+==============+=================================================+
737    | ``spec`` | ``relative`` | look for pattern after the previous item        |
738    |          +--------------+-------------------------------------------------+
739    |          | ``search``   | search pattern from offset (see also ``limit``) |
740    |          +--------------+-------------------------------------------------+
741    |          | ``reserved`` | reserved, must be set to zero                   |
742    |          +--------------+-------------------------------------------------+
743    |          | ``offset``   | absolute or relative offset for ``pattern``     |
744    |          +--------------+-------------------------------------------------+
745    |          | ``limit``    | search area limit for start of ``pattern``      |
746    |          +--------------+-------------------------------------------------+
747    |          | ``length``   | ``pattern`` length                              |
748    |          +--------------+-------------------------------------------------+
749    |          | ``pattern``  | byte string to look for                         |
750    +----------+--------------+-------------------------------------------------+
751    | ``last`` | if specified, either all 0 or with the same values as ``spec`` |
752    +----------+----------------------------------------------------------------+
753    | ``mask`` | bit-mask applied to ``spec`` values with usual behavior        |
754    +----------+----------------------------------------------------------------+
755
756 Example pattern looking for several strings at various offsets of a UDP
757 payload, using combined RAW items:
758
759 .. _table_rte_flow_item_raw_example:
760
761 .. table:: UDP payload matching
762
763    +-------+------+----------+--------------+-------+
764    | Index | Item | Field    | Subfield     | Value |
765    +=======+======+==========+==============+=======+
766    | 0     | Ethernet                               |
767    +-------+----------------------------------------+
768    | 1     | IPv4                                   |
769    +-------+----------------------------------------+
770    | 2     | UDP                                    |
771    +-------+------+----------+--------------+-------+
772    | 3     | RAW  | ``spec`` | ``relative`` | 1     |
773    |       |      |          +--------------+-------+
774    |       |      |          | ``search``   | 1     |
775    |       |      |          +--------------+-------+
776    |       |      |          | ``offset``   | 10    |
777    |       |      |          +--------------+-------+
778    |       |      |          | ``limit``    | 0     |
779    |       |      |          +--------------+-------+
780    |       |      |          | ``length``   | 3     |
781    |       |      |          +--------------+-------+
782    |       |      |          | ``pattern``  | "foo" |
783    +-------+------+----------+--------------+-------+
784    | 4     | RAW  | ``spec`` | ``relative`` | 1     |
785    |       |      |          +--------------+-------+
786    |       |      |          | ``search``   | 0     |
787    |       |      |          +--------------+-------+
788    |       |      |          | ``offset``   | 20    |
789    |       |      |          +--------------+-------+
790    |       |      |          | ``limit``    | 0     |
791    |       |      |          +--------------+-------+
792    |       |      |          | ``length``   | 3     |
793    |       |      |          +--------------+-------+
794    |       |      |          | ``pattern``  | "bar" |
795    +-------+------+----------+--------------+-------+
796    | 5     | RAW  | ``spec`` | ``relative`` | 1     |
797    |       |      |          +--------------+-------+
798    |       |      |          | ``search``   | 0     |
799    |       |      |          +--------------+-------+
800    |       |      |          | ``offset``   | -29   |
801    |       |      |          +--------------+-------+
802    |       |      |          | ``limit``    | 0     |
803    |       |      |          +--------------+-------+
804    |       |      |          | ``length``   | 3     |
805    |       |      |          +--------------+-------+
806    |       |      |          | ``pattern``  | "baz" |
807    +-------+------+----------+--------------+-------+
808    | 6     | END                                    |
809    +-------+----------------------------------------+
810
811 This translates to:
812
813 - Locate "foo" at least 10 bytes deep inside UDP payload.
814 - Locate "bar" after "foo" plus 20 bytes.
815 - Locate "baz" after "bar" minus 29 bytes.
816
817 Such a packet may be represented as follows (not to scale)::
818
819  0                     >= 10 B           == 20 B
820  |                  |<--------->|     |<--------->|
821  |                  |           |     |           |
822  |-----|------|-----|-----|-----|-----|-----------|-----|------|
823  | ETH | IPv4 | UDP | ... | baz | foo | ......... | bar | .... |
824  |-----|------|-----|-----|-----|-----|-----------|-----|------|
825                           |                             |
826                           |<--------------------------->|
827                                       == 29 B
828
829 Note that matching subsequent pattern items would resume after "baz", not
830 "bar" since matching is always performed after the previous item of the
831 stack.
832
833 Item: ``ETH``
834 ^^^^^^^^^^^^^
835
836 Matches an Ethernet header.
837
838 The ``type`` field either stands for "EtherType" or "TPID" when followed by
839 so-called layer 2.5 pattern items such as ``RTE_FLOW_ITEM_TYPE_VLAN``. In
840 the latter case, ``type`` refers to that of the outer header, with the inner
841 EtherType/TPID provided by the subsequent pattern item. This is the same
842 order as on the wire.
843
844 - ``dst``: destination MAC.
845 - ``src``: source MAC.
846 - ``type``: EtherType or TPID.
847 - Default ``mask`` matches destination and source addresses only.
848
849 Item: ``VLAN``
850 ^^^^^^^^^^^^^^
851
852 Matches an 802.1Q/ad VLAN tag.
853
854 The corresponding standard outer EtherType (TPID) values are
855 ``ETHER_TYPE_VLAN`` or ``ETHER_TYPE_QINQ``. It can be overridden by the
856 preceding pattern item.
857
858 - ``tci``: tag control information.
859 - ``inner_type``: inner EtherType or TPID.
860 - Default ``mask`` matches the VID part of TCI only (lower 12 bits).
861
862 Item: ``IPV4``
863 ^^^^^^^^^^^^^^
864
865 Matches an IPv4 header.
866
867 Note: IPv4 options are handled by dedicated pattern items.
868
869 - ``hdr``: IPv4 header definition (``rte_ip.h``).
870 - Default ``mask`` matches source and destination addresses only.
871
872 Item: ``IPV6``
873 ^^^^^^^^^^^^^^
874
875 Matches an IPv6 header.
876
877 Note: IPv6 options are handled by dedicated pattern items.
878
879 - ``hdr``: IPv6 header definition (``rte_ip.h``).
880 - Default ``mask`` matches source and destination addresses only.
881
882 Item: ``ICMP``
883 ^^^^^^^^^^^^^^
884
885 Matches an ICMP header.
886
887 - ``hdr``: ICMP header definition (``rte_icmp.h``).
888 - Default ``mask`` matches ICMP type and code only.
889
890 Item: ``UDP``
891 ^^^^^^^^^^^^^
892
893 Matches a UDP header.
894
895 - ``hdr``: UDP header definition (``rte_udp.h``).
896 - Default ``mask`` matches source and destination ports only.
897
898 Item: ``TCP``
899 ^^^^^^^^^^^^^
900
901 Matches a TCP header.
902
903 - ``hdr``: TCP header definition (``rte_tcp.h``).
904 - Default ``mask`` matches source and destination ports only.
905
906 Item: ``SCTP``
907 ^^^^^^^^^^^^^^
908
909 Matches a SCTP header.
910
911 - ``hdr``: SCTP header definition (``rte_sctp.h``).
912 - Default ``mask`` matches source and destination ports only.
913
914 Item: ``VXLAN``
915 ^^^^^^^^^^^^^^^
916
917 Matches a VXLAN header (RFC 7348).
918
919 - ``flags``: normally 0x08 (I flag).
920 - ``rsvd0``: reserved, normally 0x000000.
921 - ``vni``: VXLAN network identifier.
922 - ``rsvd1``: reserved, normally 0x00.
923 - Default ``mask`` matches VNI only.
924
925 Item: ``E_TAG``
926 ^^^^^^^^^^^^^^^
927
928 Matches an IEEE 802.1BR E-Tag header.
929
930 The corresponding standard outer EtherType (TPID) value is
931 ``ETHER_TYPE_ETAG``. It can be overridden by the preceding pattern item.
932
933 - ``epcp_edei_in_ecid_b``: E-Tag control information (E-TCI), E-PCP (3b),
934   E-DEI (1b), ingress E-CID base (12b).
935 - ``rsvd_grp_ecid_b``: reserved (2b), GRP (2b), E-CID base (12b).
936 - ``in_ecid_e``: ingress E-CID ext.
937 - ``ecid_e``: E-CID ext.
938 - ``inner_type``: inner EtherType or TPID.
939 - Default ``mask`` simultaneously matches GRP and E-CID base.
940
941 Item: ``NVGRE``
942 ^^^^^^^^^^^^^^^
943
944 Matches a NVGRE header (RFC 7637).
945
946 - ``c_k_s_rsvd0_ver``: checksum (1b), undefined (1b), key bit (1b),
947   sequence number (1b), reserved 0 (9b), version (3b). This field must have
948   value 0x2000 according to RFC 7637.
949 - ``protocol``: protocol type (0x6558).
950 - ``tni``: virtual subnet ID.
951 - ``flow_id``: flow ID.
952 - Default ``mask`` matches TNI only.
953
954 Item: ``MPLS``
955 ^^^^^^^^^^^^^^
956
957 Matches a MPLS header.
958
959 - ``label_tc_s_ttl``: label, TC, Bottom of Stack and TTL.
960 - Default ``mask`` matches label only.
961
962 Item: ``GRE``
963 ^^^^^^^^^^^^^
964
965 Matches a GRE header.
966
967 - ``c_rsvd0_ver``: checksum, reserved 0 and version.
968 - ``protocol``: protocol type.
969 - Default ``mask`` matches protocol only.
970
971 Item: ``FUZZY``
972 ^^^^^^^^^^^^^^^
973
974 Fuzzy pattern match, expect faster than default.
975
976 This is for device that support fuzzy match option. Usually a fuzzy match is
977 fast but the cost is accuracy. i.e. Signature Match only match pattern's hash
978 value, but it is possible two different patterns have the same hash value.
979
980 Matching accuracy level can be configured by threshold. Driver can divide the
981 range of threshold and map to different accuracy levels that device support.
982
983 Threshold 0 means perfect match (no fuzziness), while threshold 0xffffffff
984 means fuzziest match.
985
986 .. _table_rte_flow_item_fuzzy:
987
988 .. table:: FUZZY
989
990    +----------+---------------+--------------------------------------------------+
991    | Field    |   Subfield    | Value                                            |
992    +==========+===============+==================================================+
993    | ``spec`` | ``threshold`` | 0 as perfect match, 0xffffffff as fuzziest match |
994    +----------+---------------+--------------------------------------------------+
995    | ``last`` | ``threshold`` | upper range value                                |
996    +----------+---------------+--------------------------------------------------+
997    | ``mask`` | ``threshold`` | bit-mask apply to "spec" and "last"              |
998    +----------+---------------+--------------------------------------------------+
999
1000 Usage example, fuzzy match a TCPv4 packets:
1001
1002 .. _table_rte_flow_item_fuzzy_example:
1003
1004 .. table:: Fuzzy matching
1005
1006    +-------+----------+
1007    | Index | Item     |
1008    +=======+==========+
1009    | 0     | FUZZY    |
1010    +-------+----------+
1011    | 1     | Ethernet |
1012    +-------+----------+
1013    | 2     | IPv4     |
1014    +-------+----------+
1015    | 3     | TCP      |
1016    +-------+----------+
1017    | 4     | END      |
1018    +-------+----------+
1019
1020 Item: ``GTP``, ``GTPC``, ``GTPU``
1021 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1022
1023 Matches a GTPv1 header.
1024
1025 Note: GTP, GTPC and GTPU use the same structure. GTPC and GTPU item
1026 are defined for a user-friendly API when creating GTP-C and GTP-U
1027 flow rules.
1028
1029 - ``v_pt_rsv_flags``: version (3b), protocol type (1b), reserved (1b),
1030   extension header flag (1b), sequence number flag (1b), N-PDU number
1031   flag (1b).
1032 - ``msg_type``: message type.
1033 - ``msg_len``: message length.
1034 - ``teid``: tunnel endpoint identifier.
1035 - Default ``mask`` matches teid only.
1036
1037 Item: ``ESP``
1038 ^^^^^^^^^^^^^
1039
1040 Matches an ESP header.
1041
1042 - ``hdr``: ESP header definition (``rte_esp.h``).
1043 - Default ``mask`` matches SPI only.
1044
1045 Item: ``GENEVE``
1046 ^^^^^^^^^^^^^^^^
1047
1048 Matches a GENEVE header.
1049
1050 - ``ver_opt_len_o_c_rsvd0``: version (2b), length of the options fields (6b),
1051   OAM packet (1b), critical options present (1b), reserved 0 (6b).
1052 - ``protocol``: protocol type.
1053 - ``vni``: virtual network identifier.
1054 - ``rsvd1``: reserved, normally 0x00.
1055 - Default ``mask`` matches VNI only.
1056
1057 Item: ``VXLAN-GPE``
1058 ^^^^^^^^^^^^^^^^^^^
1059
1060 Matches a VXLAN-GPE header (draft-ietf-nvo3-vxlan-gpe-05).
1061
1062 - ``flags``: normally 0x0C (I and P flags).
1063 - ``rsvd0``: reserved, normally 0x0000.
1064 - ``protocol``: protocol type.
1065 - ``vni``: VXLAN network identifier.
1066 - ``rsvd1``: reserved, normally 0x00.
1067 - Default ``mask`` matches VNI only.
1068
1069 Actions
1070 ~~~~~~~
1071
1072 Each possible action is represented by a type. Some have associated
1073 configuration structures. Several actions combined in a list can be assigned
1074 to a flow rule and are performed in order.
1075
1076 They fall in three categories:
1077
1078 - Actions that modify the fate of matching traffic, for instance by dropping
1079   or assigning it a specific destination.
1080
1081 - Actions that modify matching traffic contents or its properties. This
1082   includes adding/removing encapsulation, encryption, compression and marks.
1083
1084 - Actions related to the flow rule itself, such as updating counters or
1085   making it non-terminating.
1086
1087 Flow rules being terminating by default, not specifying any action of the
1088 fate kind results in undefined behavior. This applies to both ingress and
1089 egress.
1090
1091 PASSTHRU, when supported, makes a flow rule non-terminating.
1092
1093 Like matching patterns, action lists are terminated by END items.
1094
1095 Example of action that redirects packets to queue index 10:
1096
1097 .. _table_rte_flow_action_example:
1098
1099 .. table:: Queue action
1100
1101    +-----------+-------+
1102    | Field     | Value |
1103    +===========+=======+
1104    | ``index`` | 10    |
1105    +-----------+-------+
1106
1107 Actions are performed in list order:
1108
1109 .. _table_rte_flow_count_then_drop:
1110
1111 .. table:: Count then drop
1112
1113    +-------+--------+
1114    | Index | Action |
1115    +=======+========+
1116    | 0     | COUNT  |
1117    +-------+--------+
1118    | 1     | DROP   |
1119    +-------+--------+
1120    | 2     | END    |
1121    +-------+--------+
1122
1123 |
1124
1125 .. _table_rte_flow_mark_count_redirect:
1126
1127 .. table:: Mark, count then redirect
1128
1129    +-------+--------+-----------+-------+
1130    | Index | Action | Field     | Value |
1131    +=======+========+===========+=======+
1132    | 0     | MARK   | ``mark``  | 0x2a  |
1133    +-------+--------+-----------+-------+
1134    | 1     | COUNT                      |
1135    +-------+--------+-----------+-------+
1136    | 2     | QUEUE  | ``queue`` | 10    |
1137    +-------+--------+-----------+-------+
1138    | 3     | END                        |
1139    +-------+----------------------------+
1140
1141 |
1142
1143 .. _table_rte_flow_redirect_queue_5:
1144
1145 .. table:: Redirect to queue 5
1146
1147    +-------+--------+-----------+-------+
1148    | Index | Action | Field     | Value |
1149    +=======+========+===========+=======+
1150    | 0     | DROP                       |
1151    +-------+--------+-----------+-------+
1152    | 1     | QUEUE  | ``queue`` | 5     |
1153    +-------+--------+-----------+-------+
1154    | 2     | END                        |
1155    +-------+----------------------------+
1156
1157 In the above example, while DROP and QUEUE must be performed in order, both
1158 have to happen before reaching END. Only QUEUE has a visible effect.
1159
1160 Note that such a list may be thought as ambiguous and rejected on that
1161 basis.
1162
1163 .. _table_rte_flow_redirect_queue_5_3:
1164
1165 .. table:: Redirect to queues 5 and 3
1166
1167    +-------+--------+-----------+-------+
1168    | Index | Action | Field     | Value |
1169    +=======+========+===========+=======+
1170    | 0     | QUEUE  | ``queue`` | 5     |
1171    +-------+--------+-----------+-------+
1172    | 1     | VOID                       |
1173    +-------+--------+-----------+-------+
1174    | 2     | QUEUE  | ``queue`` | 3     |
1175    +-------+--------+-----------+-------+
1176    | 3     | END                        |
1177    +-------+----------------------------+
1178
1179 As previously described, all actions must be taken into account. This
1180 effectively duplicates traffic to both queues. The above example also shows
1181 that VOID is ignored.
1182
1183 Action types
1184 ~~~~~~~~~~~~
1185
1186 Common action types are described in this section. Like pattern item types,
1187 this list is not exhaustive as new actions will be added in the future.
1188
1189 Action: ``END``
1190 ^^^^^^^^^^^^^^^
1191
1192 End marker for action lists. Prevents further processing of actions, thereby
1193 ending the list.
1194
1195 - Its numeric value is 0 for convenience.
1196 - PMD support is mandatory.
1197 - No configurable properties.
1198
1199 .. _table_rte_flow_action_end:
1200
1201 .. table:: END
1202
1203    +---------------+
1204    | Field         |
1205    +===============+
1206    | no properties |
1207    +---------------+
1208
1209 Action: ``VOID``
1210 ^^^^^^^^^^^^^^^^
1211
1212 Used as a placeholder for convenience. It is ignored and simply discarded by
1213 PMDs.
1214
1215 - PMD support is mandatory.
1216 - No configurable properties.
1217
1218 .. _table_rte_flow_action_void:
1219
1220 .. table:: VOID
1221
1222    +---------------+
1223    | Field         |
1224    +===============+
1225    | no properties |
1226    +---------------+
1227
1228 Action: ``PASSTHRU``
1229 ^^^^^^^^^^^^^^^^^^^^
1230
1231 Leaves traffic up for additional processing by subsequent flow rules; makes
1232 a flow rule non-terminating.
1233
1234 - No configurable properties.
1235
1236 .. _table_rte_flow_action_passthru:
1237
1238 .. table:: PASSTHRU
1239
1240    +---------------+
1241    | Field         |
1242    +===============+
1243    | no properties |
1244    +---------------+
1245
1246 Example to copy a packet to a queue and continue processing by subsequent
1247 flow rules:
1248
1249 .. _table_rte_flow_action_passthru_example:
1250
1251 .. table:: Copy to queue 8
1252
1253    +-------+--------+-----------+-------+
1254    | Index | Action | Field     | Value |
1255    +=======+========+===========+=======+
1256    | 0     | PASSTHRU                   |
1257    +-------+--------+-----------+-------+
1258    | 1     | QUEUE  | ``queue`` | 8     |
1259    +-------+--------+-----------+-------+
1260    | 2     | END                        |
1261    +-------+----------------------------+
1262
1263 Action: ``MARK``
1264 ^^^^^^^^^^^^^^^^
1265
1266 Attaches an integer value to packets and sets ``PKT_RX_FDIR`` and
1267 ``PKT_RX_FDIR_ID`` mbuf flags.
1268
1269 This value is arbitrary and application-defined. Maximum allowed value
1270 depends on the underlying implementation. It is returned in the
1271 ``hash.fdir.hi`` mbuf field.
1272
1273 .. _table_rte_flow_action_mark:
1274
1275 .. table:: MARK
1276
1277    +--------+--------------------------------------+
1278    | Field  | Value                                |
1279    +========+======================================+
1280    | ``id`` | integer value to return with packets |
1281    +--------+--------------------------------------+
1282
1283 Action: ``FLAG``
1284 ^^^^^^^^^^^^^^^^
1285
1286 Flags packets. Similar to `Action: MARK`_ without a specific value; only
1287 sets the ``PKT_RX_FDIR`` mbuf flag.
1288
1289 - No configurable properties.
1290
1291 .. _table_rte_flow_action_flag:
1292
1293 .. table:: FLAG
1294
1295    +---------------+
1296    | Field         |
1297    +===============+
1298    | no properties |
1299    +---------------+
1300
1301 Action: ``QUEUE``
1302 ^^^^^^^^^^^^^^^^^
1303
1304 Assigns packets to a given queue index.
1305
1306 .. _table_rte_flow_action_queue:
1307
1308 .. table:: QUEUE
1309
1310    +-----------+--------------------+
1311    | Field     | Value              |
1312    +===========+====================+
1313    | ``index`` | queue index to use |
1314    +-----------+--------------------+
1315
1316 Action: ``DROP``
1317 ^^^^^^^^^^^^^^^^
1318
1319 Drop packets.
1320
1321 - No configurable properties.
1322
1323 .. _table_rte_flow_action_drop:
1324
1325 .. table:: DROP
1326
1327    +---------------+
1328    | Field         |
1329    +===============+
1330    | no properties |
1331    +---------------+
1332
1333 Action: ``COUNT``
1334 ^^^^^^^^^^^^^^^^^
1335
1336 Enables counters for this rule.
1337
1338 These counters can be retrieved and reset through ``rte_flow_query()``, see
1339 ``struct rte_flow_query_count``.
1340
1341 - Counters can be retrieved with ``rte_flow_query()``.
1342 - No configurable properties.
1343
1344 .. _table_rte_flow_action_count:
1345
1346 .. table:: COUNT
1347
1348    +---------------+
1349    | Field         |
1350    +===============+
1351    | no properties |
1352    +---------------+
1353
1354 Query structure to retrieve and reset flow rule counters:
1355
1356 .. _table_rte_flow_query_count:
1357
1358 .. table:: COUNT query
1359
1360    +---------------+-----+-----------------------------------+
1361    | Field         | I/O | Value                             |
1362    +===============+=====+===================================+
1363    | ``reset``     | in  | reset counter after query         |
1364    +---------------+-----+-----------------------------------+
1365    | ``hits_set``  | out | ``hits`` field is set             |
1366    +---------------+-----+-----------------------------------+
1367    | ``bytes_set`` | out | ``bytes`` field is set            |
1368    +---------------+-----+-----------------------------------+
1369    | ``hits``      | out | number of hits for this rule      |
1370    +---------------+-----+-----------------------------------+
1371    | ``bytes``     | out | number of bytes through this rule |
1372    +---------------+-----+-----------------------------------+
1373
1374 Action: ``RSS``
1375 ^^^^^^^^^^^^^^^
1376
1377 Similar to QUEUE, except RSS is additionally performed on packets to spread
1378 them among several queues according to the provided parameters.
1379
1380 Unlike global RSS settings used by other DPDK APIs, unsetting the ``types``
1381 field does not disable RSS in a flow rule. Doing so instead requests safe
1382 unspecified "best-effort" settings from the underlying PMD, which depending
1383 on the flow rule, may result in anything ranging from empty (single queue)
1384 to all-inclusive RSS.
1385
1386 Note: RSS hash result is stored in the ``hash.rss`` mbuf field which
1387 overlaps ``hash.fdir.lo``. Since `Action: MARK`_ sets the ``hash.fdir.hi``
1388 field only, both can be requested simultaneously.
1389
1390 Also, regarding packet encapsulation ``level``:
1391
1392 - ``0`` requests the default behavior. Depending on the packet type, it can
1393   mean outermost, innermost, anything in between or even no RSS.
1394
1395   It basically stands for the innermost encapsulation level RSS can be
1396   performed on according to PMD and device capabilities.
1397
1398 - ``1`` requests RSS to be performed on the outermost packet encapsulation
1399   level.
1400
1401 - ``2`` and subsequent values request RSS to be performed on the specified
1402    inner packet encapsulation level, from outermost to innermost (lower to
1403    higher values).
1404
1405 Values other than ``0`` are not necessarily supported.
1406
1407 Requesting a specific RSS level on unrecognized traffic results in undefined
1408 behavior. For predictable results, it is recommended to make the flow rule
1409 pattern match packet headers up to the requested encapsulation level so that
1410 only matching traffic goes through.
1411
1412 .. _table_rte_flow_action_rss:
1413
1414 .. table:: RSS
1415
1416    +---------------+---------------------------------------------+
1417    | Field         | Value                                       |
1418    +===============+=============================================+
1419    | ``func``      | RSS hash function to apply                  |
1420    +---------------+---------------------------------------------+
1421    | ``level``     | encapsulation level for ``types``           |
1422    +---------------+---------------------------------------------+
1423    | ``types``     | specific RSS hash types (see ``ETH_RSS_*``) |
1424    +---------------+---------------------------------------------+
1425    | ``key_len``   | hash key length in bytes                    |
1426    +---------------+---------------------------------------------+
1427    | ``queue_num`` | number of entries in ``queue``              |
1428    +---------------+---------------------------------------------+
1429    | ``key``       | hash key                                    |
1430    +---------------+---------------------------------------------+
1431    | ``queue``     | queue indices to use                        |
1432    +---------------+---------------------------------------------+
1433
1434 Action: ``PF``
1435 ^^^^^^^^^^^^^^
1436
1437 Directs matching traffic to the physical function (PF) of the current
1438 device.
1439
1440 See `Item: PF`_.
1441
1442 - No configurable properties.
1443
1444 .. _table_rte_flow_action_pf:
1445
1446 .. table:: PF
1447
1448    +---------------+
1449    | Field         |
1450    +===============+
1451    | no properties |
1452    +---------------+
1453
1454 Action: ``VF``
1455 ^^^^^^^^^^^^^^
1456
1457 Directs matching traffic to a given virtual function of the current device.
1458
1459 Packets matched by a VF pattern item can be redirected to their original VF
1460 ID instead of the specified one. This parameter may not be available and is
1461 not guaranteed to work properly if the VF part is matched by a prior flow
1462 rule or if packets are not addressed to a VF in the first place.
1463
1464 See `Item: VF`_.
1465
1466 .. _table_rte_flow_action_vf:
1467
1468 .. table:: VF
1469
1470    +--------------+--------------------------------+
1471    | Field        | Value                          |
1472    +==============+================================+
1473    | ``original`` | use original VF ID if possible |
1474    +--------------+--------------------------------+
1475    | ``id``       | VF ID                          |
1476    +--------------+--------------------------------+
1477
1478 Action: ``PHY_PORT``
1479 ^^^^^^^^^^^^^^^^^^^^
1480
1481 Directs matching traffic to a given physical port index of the underlying
1482 device.
1483
1484 See `Item: PHY_PORT`_.
1485
1486 .. _table_rte_flow_action_phy_port:
1487
1488 .. table:: PHY_PORT
1489
1490    +--------------+-------------------------------------+
1491    | Field        | Value                               |
1492    +==============+=====================================+
1493    | ``original`` | use original port index if possible |
1494    +--------------+-------------------------------------+
1495    | ``index``    | physical port index                 |
1496    +--------------+-------------------------------------+
1497
1498 Action: ``PORT_ID``
1499 ^^^^^^^^^^^^^^^^^^^
1500 Directs matching traffic to a given DPDK port ID.
1501
1502 See `Item: PORT_ID`_.
1503
1504 .. _table_rte_flow_action_port_id:
1505
1506 .. table:: PORT_ID
1507
1508    +--------------+---------------------------------------+
1509    | Field        | Value                                 |
1510    +==============+=======================================+
1511    | ``original`` | use original DPDK port ID if possible |
1512    +--------------+---------------------------------------+
1513    | ``id``       | DPDK port ID                          |
1514    +--------------+---------------------------------------+
1515
1516 Action: ``METER``
1517 ^^^^^^^^^^^^^^^^^
1518
1519 Applies a stage of metering and policing.
1520
1521 The metering and policing (MTR) object has to be first created using the
1522 rte_mtr_create() API function. The ID of the MTR object is specified as
1523 action parameter. More than one flow can use the same MTR object through
1524 the meter action. The MTR object can be further updated or queried using
1525 the rte_mtr* API.
1526
1527 .. _table_rte_flow_action_meter:
1528
1529 .. table:: METER
1530
1531    +--------------+---------------+
1532    | Field        | Value         |
1533    +==============+===============+
1534    | ``mtr_id``   | MTR object ID |
1535    +--------------+---------------+
1536
1537 Action: ``SECURITY``
1538 ^^^^^^^^^^^^^^^^^^^^
1539
1540 Perform the security action on flows matched by the pattern items
1541 according to the configuration of the security session.
1542
1543 This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1544 security protocol headers and IV are fully provided by the application as
1545 specified in the flow pattern. The payload of matching packets is
1546 encrypted on egress, and decrypted and authenticated on ingress.
1547 For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1548 providing full encapsulation and decapsulation of packets in security
1549 protocols. The flow pattern specifies both the outer security header fields
1550 and the inner packet fields. The security session specified in the action
1551 must match the pattern parameters.
1552
1553 The security session specified in the action must be created on the same
1554 port as the flow action that is being specified.
1555
1556 The ingress/egress flow attribute should match that specified in the
1557 security session if the security session supports the definition of the
1558 direction.
1559
1560 Multiple flows can be configured to use the same security session.
1561
1562 .. _table_rte_flow_action_security:
1563
1564 .. table:: SECURITY
1565
1566    +----------------------+--------------------------------------+
1567    | Field                | Value                                |
1568    +======================+======================================+
1569    | ``security_session`` | security session to apply            |
1570    +----------------------+--------------------------------------+
1571
1572 The following is an example of configuring IPsec inline using the
1573 INLINE_CRYPTO security session:
1574
1575 The encryption algorithm, keys and salt are part of the opaque
1576 ``rte_security_session``. The SA is identified according to the IP and ESP
1577 fields in the pattern items.
1578
1579 .. _table_rte_flow_item_esp_inline_example:
1580
1581 .. table:: IPsec inline crypto flow pattern items.
1582
1583    +-------+----------+
1584    | Index | Item     |
1585    +=======+==========+
1586    | 0     | Ethernet |
1587    +-------+----------+
1588    | 1     | IPv4     |
1589    +-------+----------+
1590    | 2     | ESP      |
1591    +-------+----------+
1592    | 3     | END      |
1593    +-------+----------+
1594
1595 .. _table_rte_flow_action_esp_inline_example:
1596
1597 .. table:: IPsec inline flow actions.
1598
1599    +-------+----------+
1600    | Index | Action   |
1601    +=======+==========+
1602    | 0     | SECURITY |
1603    +-------+----------+
1604    | 1     | END      |
1605    +-------+----------+
1606
1607 Negative types
1608 ~~~~~~~~~~~~~~
1609
1610 All specified pattern items (``enum rte_flow_item_type``) and actions
1611 (``enum rte_flow_action_type``) use positive identifiers.
1612
1613 The negative space is reserved for dynamic types generated by PMDs during
1614 run-time. PMDs may encounter them as a result but must not accept negative
1615 identifiers they are not aware of.
1616
1617 A method to generate them remains to be defined.
1618
1619 Planned types
1620 ~~~~~~~~~~~~~
1621
1622 Pattern item types will be added as new protocols are implemented.
1623
1624 Variable headers support through dedicated pattern items, for example in
1625 order to match specific IPv4 options and IPv6 extension headers would be
1626 stacked after IPv4/IPv6 items.
1627
1628 Other action types are planned but are not defined yet. These include the
1629 ability to alter packet data in several ways, such as performing
1630 encapsulation/decapsulation of tunnel headers.
1631
1632 Rules management
1633 ----------------
1634
1635 A rather simple API with few functions is provided to fully manage flow
1636 rules.
1637
1638 Each created flow rule is associated with an opaque, PMD-specific handle
1639 pointer. The application is responsible for keeping it until the rule is
1640 destroyed.
1641
1642 Flows rules are represented by ``struct rte_flow`` objects.
1643
1644 Validation
1645 ~~~~~~~~~~
1646
1647 Given that expressing a definite set of device capabilities is not
1648 practical, a dedicated function is provided to check if a flow rule is
1649 supported and can be created.
1650
1651 .. code-block:: c
1652
1653    int
1654    rte_flow_validate(uint16_t port_id,
1655                      const struct rte_flow_attr *attr,
1656                      const struct rte_flow_item pattern[],
1657                      const struct rte_flow_action actions[],
1658                      struct rte_flow_error *error);
1659
1660 The flow rule is validated for correctness and whether it could be accepted
1661 by the device given sufficient resources. The rule is checked against the
1662 current device mode and queue configuration. The flow rule may also
1663 optionally be validated against existing flow rules and device resources.
1664 This function has no effect on the target device.
1665
1666 The returned value is guaranteed to remain valid only as long as no
1667 successful calls to ``rte_flow_create()`` or ``rte_flow_destroy()`` are made
1668 in the meantime and no device parameter affecting flow rules in any way are
1669 modified, due to possible collisions or resource limitations (although in
1670 such cases ``EINVAL`` should not be returned).
1671
1672 Arguments:
1673
1674 - ``port_id``: port identifier of Ethernet device.
1675 - ``attr``: flow rule attributes.
1676 - ``pattern``: pattern specification (list terminated by the END pattern
1677   item).
1678 - ``actions``: associated actions (list terminated by the END action).
1679 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1680   this structure in case of error only.
1681
1682 Return values:
1683
1684 - 0 if flow rule is valid and can be created. A negative errno value
1685   otherwise (``rte_errno`` is also set), the following errors are defined.
1686 - ``-ENOSYS``: underlying device does not support this functionality.
1687 - ``-EINVAL``: unknown or invalid rule specification.
1688 - ``-ENOTSUP``: valid but unsupported rule specification (e.g. partial
1689   bit-masks are unsupported).
1690 - ``EEXIST``: collision with an existing rule. Only returned if device
1691   supports flow rule collision checking and there was a flow rule
1692   collision. Not receiving this return code is no guarantee that creating
1693   the rule will not fail due to a collision.
1694 - ``ENOMEM``: not enough memory to execute the function, or if the device
1695   supports resource validation, resource limitation on the device.
1696 - ``-EBUSY``: action cannot be performed due to busy device resources, may
1697   succeed if the affected queues or even the entire port are in a stopped
1698   state (see ``rte_eth_dev_rx_queue_stop()`` and ``rte_eth_dev_stop()``).
1699
1700 Creation
1701 ~~~~~~~~
1702
1703 Creating a flow rule is similar to validating one, except the rule is
1704 actually created and a handle returned.
1705
1706 .. code-block:: c
1707
1708    struct rte_flow *
1709    rte_flow_create(uint16_t port_id,
1710                    const struct rte_flow_attr *attr,
1711                    const struct rte_flow_item pattern[],
1712                    const struct rte_flow_action *actions[],
1713                    struct rte_flow_error *error);
1714
1715 Arguments:
1716
1717 - ``port_id``: port identifier of Ethernet device.
1718 - ``attr``: flow rule attributes.
1719 - ``pattern``: pattern specification (list terminated by the END pattern
1720   item).
1721 - ``actions``: associated actions (list terminated by the END action).
1722 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1723   this structure in case of error only.
1724
1725 Return values:
1726
1727 A valid handle in case of success, NULL otherwise and ``rte_errno`` is set
1728 to the positive version of one of the error codes defined for
1729 ``rte_flow_validate()``.
1730
1731 Destruction
1732 ~~~~~~~~~~~
1733
1734 Flow rules destruction is not automatic, and a queue or a port should not be
1735 released if any are still attached to them. Applications must take care of
1736 performing this step before releasing resources.
1737
1738 .. code-block:: c
1739
1740    int
1741    rte_flow_destroy(uint16_t port_id,
1742                     struct rte_flow *flow,
1743                     struct rte_flow_error *error);
1744
1745
1746 Failure to destroy a flow rule handle may occur when other flow rules depend
1747 on it, and destroying it would result in an inconsistent state.
1748
1749 This function is only guaranteed to succeed if handles are destroyed in
1750 reverse order of their creation.
1751
1752 Arguments:
1753
1754 - ``port_id``: port identifier of Ethernet device.
1755 - ``flow``: flow rule handle to destroy.
1756 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1757   this structure in case of error only.
1758
1759 Return values:
1760
1761 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1762
1763 Flush
1764 ~~~~~
1765
1766 Convenience function to destroy all flow rule handles associated with a
1767 port. They are released as with successive calls to ``rte_flow_destroy()``.
1768
1769 .. code-block:: c
1770
1771    int
1772    rte_flow_flush(uint16_t port_id,
1773                   struct rte_flow_error *error);
1774
1775 In the unlikely event of failure, handles are still considered destroyed and
1776 no longer valid but the port must be assumed to be in an inconsistent state.
1777
1778 Arguments:
1779
1780 - ``port_id``: port identifier of Ethernet device.
1781 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1782   this structure in case of error only.
1783
1784 Return values:
1785
1786 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1787
1788 Query
1789 ~~~~~
1790
1791 Query an existing flow rule.
1792
1793 This function allows retrieving flow-specific data such as counters. Data
1794 is gathered by special actions which must be present in the flow rule
1795 definition.
1796
1797 .. code-block:: c
1798
1799    int
1800    rte_flow_query(uint16_t port_id,
1801                   struct rte_flow *flow,
1802                   enum rte_flow_action_type action,
1803                   void *data,
1804                   struct rte_flow_error *error);
1805
1806 Arguments:
1807
1808 - ``port_id``: port identifier of Ethernet device.
1809 - ``flow``: flow rule handle to query.
1810 - ``action``: action type to query.
1811 - ``data``: pointer to storage for the associated query data type.
1812 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1813   this structure in case of error only.
1814
1815 Return values:
1816
1817 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1818
1819 Isolated mode
1820 -------------
1821
1822 The general expectation for ingress traffic is that flow rules process it
1823 first; the remaining unmatched or pass-through traffic usually ends up in a
1824 queue (with or without RSS, locally or in some sub-device instance)
1825 depending on the global configuration settings of a port.
1826
1827 While fine from a compatibility standpoint, this approach makes drivers more
1828 complex as they have to check for possible side effects outside of this API
1829 when creating or destroying flow rules. It results in a more limited set of
1830 available rule types due to the way device resources are assigned (e.g. no
1831 support for the RSS action even on capable hardware).
1832
1833 Given that nonspecific traffic can be handled by flow rules as well,
1834 isolated mode is a means for applications to tell a driver that ingress on
1835 the underlying port must be injected from the defined flow rules only; that
1836 no default traffic is expected outside those rules.
1837
1838 This has the following benefits:
1839
1840 - Applications get finer-grained control over the kind of traffic they want
1841   to receive (no traffic by default).
1842
1843 - More importantly they control at what point nonspecific traffic is handled
1844   relative to other flow rules, by adjusting priority levels.
1845
1846 - Drivers can assign more hardware resources to flow rules and expand the
1847   set of supported rule types.
1848
1849 Because toggling isolated mode may cause profound changes to the ingress
1850 processing path of a driver, it may not be possible to leave it once
1851 entered. Likewise, existing flow rules or global configuration settings may
1852 prevent a driver from entering isolated mode.
1853
1854 Applications relying on this mode are therefore encouraged to toggle it as
1855 soon as possible after device initialization, ideally before the first call
1856 to ``rte_eth_dev_configure()`` to avoid possible failures due to conflicting
1857 settings.
1858
1859 Once effective, the following functionality has no effect on the underlying
1860 port and may return errors such as ``ENOTSUP`` ("not supported"):
1861
1862 - Toggling promiscuous mode.
1863 - Toggling allmulticast mode.
1864 - Configuring MAC addresses.
1865 - Configuring multicast addresses.
1866 - Configuring VLAN filters.
1867 - Configuring Rx filters through the legacy API (e.g. FDIR).
1868 - Configuring global RSS settings.
1869
1870 .. code-block:: c
1871
1872    int
1873    rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
1874
1875 Arguments:
1876
1877 - ``port_id``: port identifier of Ethernet device.
1878 - ``set``: nonzero to enter isolated mode, attempt to leave it otherwise.
1879 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1880   this structure in case of error only.
1881
1882 Return values:
1883
1884 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1885
1886 Verbose error reporting
1887 -----------------------
1888
1889 The defined *errno* values may not be accurate enough for users or
1890 application developers who want to investigate issues related to flow rules
1891 management. A dedicated error object is defined for this purpose:
1892
1893 .. code-block:: c
1894
1895    enum rte_flow_error_type {
1896        RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
1897        RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
1898        RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
1899        RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
1900        RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
1901        RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
1902        RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
1903        RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
1904        RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
1905        RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
1906        RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
1907        RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
1908    };
1909
1910    struct rte_flow_error {
1911        enum rte_flow_error_type type; /**< Cause field and error types. */
1912        const void *cause; /**< Object responsible for the error. */
1913        const char *message; /**< Human-readable error message. */
1914    };
1915
1916 Error type ``RTE_FLOW_ERROR_TYPE_NONE`` stands for no error, in which case
1917 remaining fields can be ignored. Other error types describe the type of the
1918 object pointed by ``cause``.
1919
1920 If non-NULL, ``cause`` points to the object responsible for the error. For a
1921 flow rule, this may be a pattern item or an individual action.
1922
1923 If non-NULL, ``message`` provides a human-readable error message.
1924
1925 This object is normally allocated by applications and set by PMDs in case of
1926 error, the message points to a constant string which does not need to be
1927 freed by the application, however its pointer can be considered valid only
1928 as long as its associated DPDK port remains configured. Closing the
1929 underlying device or unloading the PMD invalidates it.
1930
1931 Helpers
1932 -------
1933
1934 Error initializer
1935 ~~~~~~~~~~~~~~~~~
1936
1937 .. code-block:: c
1938
1939    static inline int
1940    rte_flow_error_set(struct rte_flow_error *error,
1941                       int code,
1942                       enum rte_flow_error_type type,
1943                       const void *cause,
1944                       const char *message);
1945
1946 This function initializes ``error`` (if non-NULL) with the provided
1947 parameters and sets ``rte_errno`` to ``code``. A negative error ``code`` is
1948 then returned.
1949
1950 Caveats
1951 -------
1952
1953 - DPDK does not keep track of flow rules definitions or flow rule objects
1954   automatically. Applications may keep track of the former and must keep
1955   track of the latter. PMDs may also do it for internal needs, however this
1956   must not be relied on by applications.
1957
1958 - Flow rules are not maintained between successive port initializations. An
1959   application exiting without releasing them and restarting must re-create
1960   them from scratch.
1961
1962 - API operations are synchronous and blocking (``EAGAIN`` cannot be
1963   returned).
1964
1965 - There is no provision for reentrancy/multi-thread safety, although nothing
1966   should prevent different devices from being configured at the same
1967   time. PMDs may protect their control path functions accordingly.
1968
1969 - Stopping the data path (TX/RX) should not be necessary when managing flow
1970   rules. If this cannot be achieved naturally or with workarounds (such as
1971   temporarily replacing the burst function pointers), an appropriate error
1972   code must be returned (``EBUSY``).
1973
1974 - PMDs, not applications, are responsible for maintaining flow rules
1975   configuration when stopping and restarting a port or performing other
1976   actions which may affect them. They can only be destroyed explicitly by
1977   applications.
1978
1979 For devices exposing multiple ports sharing global settings affected by flow
1980 rules:
1981
1982 - All ports under DPDK control must behave consistently, PMDs are
1983   responsible for making sure that existing flow rules on a port are not
1984   affected by other ports.
1985
1986 - Ports not under DPDK control (unaffected or handled by other applications)
1987   are user's responsibility. They may affect existing flow rules and cause
1988   undefined behavior. PMDs aware of this may prevent flow rules creation
1989   altogether in such cases.
1990
1991 PMD interface
1992 -------------
1993
1994 The PMD interface is defined in ``rte_flow_driver.h``. It is not subject to
1995 API/ABI versioning constraints as it is not exposed to applications and may
1996 evolve independently.
1997
1998 It is currently implemented on top of the legacy filtering framework through
1999 filter type *RTE_ETH_FILTER_GENERIC* that accepts the single operation
2000 *RTE_ETH_FILTER_GET* to return PMD-specific *rte_flow* callbacks wrapped
2001 inside ``struct rte_flow_ops``.
2002
2003 This overhead is temporarily necessary in order to keep compatibility with
2004 the legacy filtering framework, which should eventually disappear.
2005
2006 - PMD callbacks implement exactly the interface described in `Rules
2007   management`_, except for the port ID argument which has already been
2008   converted to a pointer to the underlying ``struct rte_eth_dev``.
2009
2010 - Public API functions do not process flow rules definitions at all before
2011   calling PMD functions (no basic error checking, no validation
2012   whatsoever). They only make sure these callbacks are non-NULL or return
2013   the ``ENOSYS`` (function not supported) error.
2014
2015 This interface additionally defines the following helper function:
2016
2017 - ``rte_flow_ops_get()``: get generic flow operations structure from a
2018   port.
2019
2020 More will be added over time.
2021
2022 Device compatibility
2023 --------------------
2024
2025 No known implementation supports all the described features.
2026
2027 Unsupported features or combinations are not expected to be fully emulated
2028 in software by PMDs for performance reasons. Partially supported features
2029 may be completed in software as long as hardware performs most of the work
2030 (such as queue redirection and packet recognition).
2031
2032 However PMDs are expected to do their best to satisfy application requests
2033 by working around hardware limitations as long as doing so does not affect
2034 the behavior of existing flow rules.
2035
2036 The following sections provide a few examples of such cases and describe how
2037 PMDs should handle them, they are based on limitations built into the
2038 previous APIs.
2039
2040 Global bit-masks
2041 ~~~~~~~~~~~~~~~~
2042
2043 Each flow rule comes with its own, per-layer bit-masks, while hardware may
2044 support only a single, device-wide bit-mask for a given layer type, so that
2045 two IPv4 rules cannot use different bit-masks.
2046
2047 The expected behavior in this case is that PMDs automatically configure
2048 global bit-masks according to the needs of the first flow rule created.
2049
2050 Subsequent rules are allowed only if their bit-masks match those, the
2051 ``EEXIST`` error code should be returned otherwise.
2052
2053 Unsupported layer types
2054 ~~~~~~~~~~~~~~~~~~~~~~~
2055
2056 Many protocols can be simulated by crafting patterns with the `Item: RAW`_
2057 type.
2058
2059 PMDs can rely on this capability to simulate support for protocols with
2060 headers not directly recognized by hardware.
2061
2062 ``ANY`` pattern item
2063 ~~~~~~~~~~~~~~~~~~~~
2064
2065 This pattern item stands for anything, which can be difficult to translate
2066 to something hardware would understand, particularly if followed by more
2067 specific types.
2068
2069 Consider the following pattern:
2070
2071 .. _table_rte_flow_unsupported_any:
2072
2073 .. table:: Pattern with ANY as L3
2074
2075    +-------+-----------------------+
2076    | Index | Item                  |
2077    +=======+=======================+
2078    | 0     | ETHER                 |
2079    +-------+-----+---------+-------+
2080    | 1     | ANY | ``num`` | ``1`` |
2081    +-------+-----+---------+-------+
2082    | 2     | TCP                   |
2083    +-------+-----------------------+
2084    | 3     | END                   |
2085    +-------+-----------------------+
2086
2087 Knowing that TCP does not make sense with something other than IPv4 and IPv6
2088 as L3, such a pattern may be translated to two flow rules instead:
2089
2090 .. _table_rte_flow_unsupported_any_ipv4:
2091
2092 .. table:: ANY replaced with IPV4
2093
2094    +-------+--------------------+
2095    | Index | Item               |
2096    +=======+====================+
2097    | 0     | ETHER              |
2098    +-------+--------------------+
2099    | 1     | IPV4 (zeroed mask) |
2100    +-------+--------------------+
2101    | 2     | TCP                |
2102    +-------+--------------------+
2103    | 3     | END                |
2104    +-------+--------------------+
2105
2106 |
2107
2108 .. _table_rte_flow_unsupported_any_ipv6:
2109
2110 .. table:: ANY replaced with IPV6
2111
2112    +-------+--------------------+
2113    | Index | Item               |
2114    +=======+====================+
2115    | 0     | ETHER              |
2116    +-------+--------------------+
2117    | 1     | IPV6 (zeroed mask) |
2118    +-------+--------------------+
2119    | 2     | TCP                |
2120    +-------+--------------------+
2121    | 3     | END                |
2122    +-------+--------------------+
2123
2124 Note that as soon as a ANY rule covers several layers, this approach may
2125 yield a large number of hidden flow rules. It is thus suggested to only
2126 support the most common scenarios (anything as L2 and/or L3).
2127
2128 Unsupported actions
2129 ~~~~~~~~~~~~~~~~~~~
2130
2131 - When combined with `Action: QUEUE`_, packet counting (`Action: COUNT`_)
2132   and tagging (`Action: MARK`_ or `Action: FLAG`_) may be implemented in
2133   software as long as the target queue is used by a single rule.
2134
2135 - When a single target queue is provided, `Action: RSS`_ can also be
2136   implemented through `Action: QUEUE`_.
2137
2138 Flow rules priority
2139 ~~~~~~~~~~~~~~~~~~~
2140
2141 While it would naturally make sense, flow rules cannot be assumed to be
2142 processed by hardware in the same order as their creation for several
2143 reasons:
2144
2145 - They may be managed internally as a tree or a hash table instead of a
2146   list.
2147 - Removing a flow rule before adding another one can either put the new rule
2148   at the end of the list or reuse a freed entry.
2149 - Duplication may occur when packets are matched by several rules.
2150
2151 For overlapping rules (particularly in order to use `Action: PASSTHRU`_)
2152 predictable behavior is only guaranteed by using different priority levels.
2153
2154 Priority levels are not necessarily implemented in hardware, or may be
2155 severely limited (e.g. a single priority bit).
2156
2157 For these reasons, priority levels may be implemented purely in software by
2158 PMDs.
2159
2160 - For devices expecting flow rules to be added in the correct order, PMDs
2161   may destroy and re-create existing rules after adding a new one with
2162   a higher priority.
2163
2164 - A configurable number of dummy or empty rules can be created at
2165   initialization time to save high priority slots for later.
2166
2167 - In order to save priority levels, PMDs may evaluate whether rules are
2168   likely to collide and adjust their priority accordingly.
2169
2170 Future evolutions
2171 -----------------
2172
2173 - A device profile selection function which could be used to force a
2174   permanent profile instead of relying on its automatic configuration based
2175   on existing flow rules.
2176
2177 - A method to optimize *rte_flow* rules with specific pattern items and
2178   action types generated on the fly by PMDs. DPDK should assign negative
2179   numbers to these in order to not collide with the existing types. See
2180   `Negative types`_.
2181
2182 - Adding specific egress pattern items and actions as described in
2183   `Attribute: Traffic direction`_.
2184
2185 - Optional software fallback when PMDs are unable to handle requested flow
2186   rules so applications do not have to implement their own.